mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-14 01:38:13 +00:00
from list to set
This commit is contained in:
@@ -28,6 +28,7 @@ import forge.deck.generation.IDeckGenPool;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.PaperCard;
|
||||
import forge.util.CollectionSuppliers;
|
||||
import forge.util.CollectionUtil;
|
||||
import forge.util.Lang;
|
||||
import forge.util.TextUtil;
|
||||
import forge.util.lang.LangEnglish;
|
||||
@@ -91,13 +92,13 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
public int artIndex;
|
||||
public boolean isFoil;
|
||||
public String collectorNumber;
|
||||
public List<String> colorID;
|
||||
public Set<String> colorID;
|
||||
|
||||
private CardRequest(String name, String edition, int artIndex, boolean isFoil, String collectorNumber) {
|
||||
this(name, edition, artIndex, isFoil, collectorNumber, null);
|
||||
}
|
||||
|
||||
private CardRequest(String name, String edition, int artIndex, boolean isFoil, String collectorNumber, List<String> colorID) {
|
||||
private CardRequest(String name, String edition, int artIndex, boolean isFoil, String collectorNumber, Set<String> colorID) {
|
||||
cardName = name;
|
||||
this.edition = edition;
|
||||
this.artIndex = artIndex;
|
||||
@@ -132,7 +133,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
return requestInfo + NameSetSeparator + artIndex;
|
||||
}
|
||||
|
||||
public static String compose(String cardName, String setCode, int artIndex, List<String> colorID) {
|
||||
public static String compose(String cardName, String setCode, int artIndex, Set<String> colorID) {
|
||||
String requestInfo = compose(cardName, setCode);
|
||||
artIndex = Math.max(artIndex, IPaperCard.DEFAULT_ART_INDEX);
|
||||
String cid = colorID == null ? "" : NameSetSeparator +
|
||||
@@ -235,7 +236,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
int artIndex = artPos > 0 ? Integer.parseInt(info[artPos]) : IPaperCard.NO_ART_INDEX; // default: no art index
|
||||
String collectorNumber = cNrPos > 0 ? info[cNrPos].substring(1, info[cNrPos].length() - 1) : IPaperCard.NO_COLLECTOR_NUMBER;
|
||||
String setCode = setPos > 0 ? info[setPos] : null;
|
||||
List<String> colorID = clrPos > 0 ? Arrays.stream(info[clrPos].substring(1).split(colorIDPrefix)).collect(Collectors.toList()) : null;
|
||||
Set<String> colorID = clrPos > 0 ? Arrays.stream(info[clrPos].substring(1).split(colorIDPrefix)).collect(Collectors.toSet()) : null;
|
||||
if (setCode != null && setCode.equals(CardEdition.UNKNOWN.getCode())) { // ???
|
||||
setCode = null;
|
||||
}
|
||||
@@ -597,7 +598,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaperCard getCard(final String cardName, String setCode, int artIndex, List<String> colorID) {
|
||||
public PaperCard getCard(final String cardName, String setCode, int artIndex, Set<String> colorID) {
|
||||
String reqInfo = CardRequest.compose(cardName, setCode, artIndex, colorID);
|
||||
CardRequest request = CardRequest.fromString(reqInfo);
|
||||
return tryGetCard(request);
|
||||
@@ -663,7 +664,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaperCard getCardFromSet(String cardName, CardEdition edition, int artIndex, String collectorNumber, boolean isFoil, List<String> colorID) {
|
||||
public PaperCard getCardFromSet(String cardName, CardEdition edition, int artIndex, String collectorNumber, boolean isFoil, Set<String> colorID) {
|
||||
if (edition == null || cardName == null) // preview cards
|
||||
return null; // No cards will be returned
|
||||
|
||||
@@ -741,7 +742,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaperCard getCardFromEditions(final String cardInfo, final CardArtPreference artPreference, int artIndex, List<String> colorID) {
|
||||
public PaperCard getCardFromEditions(final String cardInfo, final CardArtPreference artPreference, int artIndex, Set<String> colorID) {
|
||||
return this.tryToGetCardFromEditions(cardInfo, artPreference, artIndex, null, false, null, colorID);
|
||||
}
|
||||
|
||||
@@ -823,7 +824,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
}
|
||||
|
||||
private PaperCard tryToGetCardFromEditions(String cardInfo, CardArtPreference artPreference, int artIndex,
|
||||
Date releaseDate, boolean releasedBeforeFlag, Predicate<PaperCard> filter, List<String> colorID){
|
||||
Date releaseDate, boolean releasedBeforeFlag, Predicate<PaperCard> filter, Set<String> colorID){
|
||||
if (cardInfo == null)
|
||||
return null;
|
||||
final CardRequest cr = CardRequest.fromString(cardInfo);
|
||||
@@ -891,7 +892,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||
if (acceptedEditions.size() > 1) {
|
||||
Collections.sort(acceptedEditions); // CardEdition correctly sort by (release) date
|
||||
if (artPref.latestFirst)
|
||||
Collections.reverse(acceptedEditions); // newest editions first
|
||||
CollectionUtil.reverse(acceptedEditions); // newest editions first
|
||||
}
|
||||
|
||||
final Iterator<CardEdition> editionIterator = acceptedEditions.iterator();
|
||||
|
||||
@@ -7,6 +7,7 @@ import forge.item.PaperCard;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ICardDatabase extends Iterable<PaperCard> {
|
||||
/**
|
||||
@@ -50,21 +51,21 @@ public interface ICardDatabase extends Iterable<PaperCard> {
|
||||
// [NEW Methods] Including the card CollectorNumber as criterion for DB lookup
|
||||
PaperCard getCard(String cardName, String edition, String collectorNumber);
|
||||
PaperCard getCard(String cardName, String edition, int artIndex, String collectorNumber);
|
||||
PaperCard getCard(String cardName, String edition, int artIndex, List<String> colorID);
|
||||
PaperCard getCard(String cardName, String edition, int artIndex, Set<String> colorID);
|
||||
|
||||
// 2. Card Lookup from a single Expansion Set
|
||||
PaperCard getCardFromSet(String cardName, CardEdition edition, boolean isFoil); // NOT yet used, included for API symmetry
|
||||
PaperCard getCardFromSet(String cardName, CardEdition edition, String collectorNumber, boolean isFoil);
|
||||
PaperCard getCardFromSet(String cardName, CardEdition edition, int artIndex, boolean isFoil);
|
||||
PaperCard getCardFromSet(String cardName, CardEdition edition, int artIndex, String collectorNumber, boolean isFoil);
|
||||
PaperCard getCardFromSet(String cardName, CardEdition edition, int artIndex, String collectorNumber, boolean isFoil, List<String> colorID);
|
||||
PaperCard getCardFromSet(String cardName, CardEdition edition, int artIndex, String collectorNumber, boolean isFoil, Set<String> colorID);
|
||||
|
||||
// 3. Card lookup based on CardArtPreference Selection Policy
|
||||
PaperCard getCardFromEditions(String cardName, CardArtPreference artPreference);
|
||||
PaperCard getCardFromEditions(String cardName, CardArtPreference artPreference, Predicate<PaperCard> filter);
|
||||
PaperCard getCardFromEditions(String cardName, CardArtPreference artPreference, int artIndex);
|
||||
PaperCard getCardFromEditions(String cardName, CardArtPreference artPreference, int artIndex, Predicate<PaperCard> filter);
|
||||
PaperCard getCardFromEditions(String cardName, CardArtPreference artPreference, int artIndex, List<String> colorID);
|
||||
PaperCard getCardFromEditions(String cardName, CardArtPreference artPreference, int artIndex, Set<String> colorID);
|
||||
|
||||
// 4. Specialised Card Lookup on CardArtPreference Selection and Release Date
|
||||
PaperCard getCardFromEditionsReleasedBefore(String cardName, CardArtPreference artPreference, Date releaseDate);
|
||||
|
||||
@@ -72,7 +72,7 @@ public class CardPool extends ItemPool<PaperCard> {
|
||||
public void add(String cardName, String setCode, int artIndex, final int amount) {
|
||||
this.add(cardName, setCode, artIndex, amount, false, null);
|
||||
}
|
||||
public void add(String cardName, String setCode, int artIndex, final int amount, boolean addAny, List<String> colorID) {
|
||||
public void add(String cardName, String setCode, int artIndex, final int amount, boolean addAny, Set<String> colorID) {
|
||||
Map<String, CardDb> dbs = StaticData.instance().getAvailableDatabases();
|
||||
PaperCard paperCard = null;
|
||||
String selectedDbName = "";
|
||||
|
||||
@@ -234,7 +234,7 @@ public interface IPaperCard extends InventoryItem, Serializable {
|
||||
String getEdition();
|
||||
String getCollectorNumber();
|
||||
String getFunctionalVariant();
|
||||
List<String> getColorID();
|
||||
Set<String> getColorID();
|
||||
int getArtIndex();
|
||||
boolean isFoil();
|
||||
boolean isToken();
|
||||
|
||||
@@ -29,6 +29,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A lightweight version of a card that matches real-world cards, to use outside of games (eg. inventory, decks, trade).
|
||||
@@ -56,7 +58,7 @@ public class PaperCard implements Comparable<IPaperCard>, InventoryItemFromSet,
|
||||
private final boolean foil;
|
||||
private Boolean hasImage;
|
||||
private final boolean noSell;
|
||||
private List<String> colorID;
|
||||
private Set<String> colorID;
|
||||
private String sortableName;
|
||||
private final String functionalVariant;
|
||||
|
||||
@@ -88,7 +90,7 @@ public class PaperCard implements Comparable<IPaperCard>, InventoryItemFromSet,
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getColorID() {
|
||||
public Set<String> getColorID() {
|
||||
return colorID;
|
||||
}
|
||||
|
||||
@@ -163,7 +165,7 @@ public class PaperCard implements Comparable<IPaperCard>, InventoryItemFromSet,
|
||||
this.artIndex, this.foil, String.valueOf(collectorNumber), this.artist, this.functionalVariant, false);
|
||||
return sellable;
|
||||
}
|
||||
public PaperCard getSpireVersion(List<String> colors) {
|
||||
public PaperCard getSpireVersion(Set<String> colors) {
|
||||
return new PaperCard(this.rules, this.edition, this.rarity,
|
||||
this.artIndex, this.foil, String.valueOf(collectorNumber), this.artist, this.functionalVariant, false, colors);
|
||||
}
|
||||
@@ -205,7 +207,7 @@ public class PaperCard implements Comparable<IPaperCard>, InventoryItemFromSet,
|
||||
|
||||
public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0,
|
||||
final int artIndex0, final boolean foil0, final String collectorNumber0,
|
||||
final String artist0, final String functionalVariant, final boolean noSell0, final List<String> spires) {
|
||||
final String artist0, final String functionalVariant, final boolean noSell0, final Set<String> colorID0) {
|
||||
if (rules0 == null || edition0 == null || rarity0 == null) {
|
||||
throw new IllegalArgumentException("Cannot create card without rules, edition or rarity");
|
||||
}
|
||||
@@ -222,7 +224,7 @@ public class PaperCard implements Comparable<IPaperCard>, InventoryItemFromSet,
|
||||
sortableName = TextUtil.toSortableName(CardTranslation.getTranslatedName(rules0.getName()));
|
||||
this.functionalVariant = functionalVariant != null ? functionalVariant : IPaperCard.NO_FUNCTIONAL_VARIANT;
|
||||
noSell = noSell0;
|
||||
colorID = spires;
|
||||
colorID = colorID0;
|
||||
}
|
||||
|
||||
public static PaperCard FAKE_CARD = new PaperCard(CardRules.getUnsupportedCardNamed("Fake Card"), "Fake Edition", CardRarity.Common);
|
||||
@@ -249,6 +251,9 @@ public class PaperCard implements Comparable<IPaperCard>, InventoryItemFromSet,
|
||||
}
|
||||
if (!getCollectorNumber().equals(other.getCollectorNumber()))
|
||||
return false;
|
||||
// colorID can be NULL
|
||||
if (getColorID() != other.getColorID())
|
||||
return false;
|
||||
return (other.foil == foil) && (other.artIndex == artIndex);
|
||||
}
|
||||
|
||||
@@ -261,7 +266,7 @@ public class PaperCard implements Comparable<IPaperCard>, InventoryItemFromSet,
|
||||
public int hashCode() {
|
||||
final int code = (name.hashCode() * 11) + (edition.hashCode() * 59) +
|
||||
(artIndex * 2) + (getCollectorNumber().hashCode() * 383);
|
||||
final int id = colorID == null ? 0 : colorID.hashCode();
|
||||
final int id = Optional.ofNullable(colorID).map(Set::hashCode).orElse(0);
|
||||
if (foil) {
|
||||
return code + id + 1;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package forge.item;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import forge.card.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -154,7 +155,7 @@ public class PaperToken implements InventoryItemFromSet, IPaperCard {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getColorID() {
|
||||
public Set<String> getColorID() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -573,7 +573,7 @@ public class GameAction {
|
||||
}
|
||||
|
||||
if (c.hasChosenColorSpire()) {
|
||||
copied.setChosenColorID(ImmutableList.copyOf(c.getChosenColorID()));
|
||||
copied.setChosenColorID(ImmutableSet.copyOf(c.getChosenColorID()));
|
||||
}
|
||||
|
||||
// update state for view
|
||||
@@ -2236,7 +2236,7 @@ public class GameAction {
|
||||
Localizer.getInstance().getMessage("lblChooseNColors", Lang.getNumeral(2));
|
||||
SpellAbility sa = new SpellAbility.EmptySa(ApiType.ChooseColor, c, takesAction);
|
||||
sa.putParam("AILogic", "MostProminentInComputerDeck");
|
||||
List<String> chosenColors = takesAction.getController().chooseColors(prompt, sa, 2, 2, colorChoices);
|
||||
Set<String> chosenColors = new HashSet<>(takesAction.getController().chooseColors(prompt, sa, 2, 2, colorChoices));
|
||||
c.setChosenColorID(chosenColors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
|
||||
private String chosenType2 = "";
|
||||
private List<String> notedTypes = new ArrayList<>();
|
||||
private List<String> chosenColors;
|
||||
private List<String> chosenColorID;
|
||||
private Set<String> chosenColorID;
|
||||
private List<String> chosenName = new ArrayList<>();
|
||||
private Integer chosenNumber;
|
||||
private Player chosenPlayer;
|
||||
@@ -2121,13 +2121,13 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars, ITr
|
||||
public boolean hasChosenColor(String s) {
|
||||
return chosenColors != null && chosenColors.contains(s);
|
||||
}
|
||||
public final List<String> getChosenColorID() {
|
||||
public final Set<String> getChosenColorID() {
|
||||
if (chosenColorID == null) {
|
||||
return Lists.newArrayList();
|
||||
return Sets.newHashSet();
|
||||
}
|
||||
return chosenColorID;
|
||||
}
|
||||
public final void setChosenColorID(final List<String> s) {
|
||||
public final void setChosenColorID(final Set<String> s) {
|
||||
chosenColorID = s;
|
||||
view.updateChosenColorID(this);
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ public class CardView extends GameEntityView {
|
||||
void updateChosenColors(Card c) {
|
||||
set(TrackableProperty.ChosenColors, c.getChosenColors());
|
||||
}
|
||||
public List<String> getChosenColorID() {
|
||||
public Set<String> getChosenColorID() {
|
||||
return get(TrackableProperty.ChosenColorID);
|
||||
}
|
||||
void updateChosenColorID(Card c) {
|
||||
|
||||
@@ -67,7 +67,7 @@ public enum TrackableProperty {
|
||||
ChosenType2(TrackableTypes.StringType),
|
||||
NotedTypes(TrackableTypes.StringListType),
|
||||
ChosenColors(TrackableTypes.StringListType),
|
||||
ChosenColorID(TrackableTypes.StringListType),
|
||||
ChosenColorID(TrackableTypes.StringSetType),
|
||||
ChosenCards(TrackableTypes.CardViewCollectionType),
|
||||
ChosenNumber(TrackableTypes.StringType),
|
||||
StoredRolls(TrackableTypes.StringListType),
|
||||
|
||||
@@ -20,8 +20,11 @@ package forge.screens.deckeditor.controllers;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JPopupMenu;
|
||||
@@ -586,7 +589,7 @@ public abstract class ACEditorBase<TItem extends InventoryItem, TModel extends D
|
||||
return;
|
||||
|
||||
GuiUtils.addMenuItem(menu, label, null, () -> {
|
||||
List<String> colors = GuiChoose.getChoices(localizer.getMessage("lblChooseNColors", Lang.getNumeral(2)), 2, 2, MagicColor.Constant.ONLY_COLORS);
|
||||
Set<String> colors = new HashSet<>(GuiChoose.getChoices(localizer.getMessage("lblChooseNColors", Lang.getNumeral(2)), 2, 2, MagicColor.Constant.ONLY_COLORS));
|
||||
// make an updated version
|
||||
PaperCard updated = existingCard.getSpireVersion(colors);
|
||||
// remove *quantity* instances of existing card
|
||||
|
||||
@@ -1845,11 +1845,11 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
||||
if ("Cryptic Spires".equalsIgnoreCase(card.getCardName())) {
|
||||
menu.addItem(new FMenuItem(Forge.getLocalizer().getMessage("lblColorIdentity"), Forge.hdbuttons ? FSkinImage.HDPREFERENCE : FSkinImage.SETTINGS, e -> {
|
||||
//sort options so current option is on top and selected by default
|
||||
List<String> colorChoices = new ArrayList<>(MagicColor.Constant.ONLY_COLORS);
|
||||
Set<String> colorChoices = new HashSet<>(MagicColor.Constant.ONLY_COLORS);
|
||||
GuiChoose.getChoices(Forge.getLocalizer().getMessage("lblChooseAColor", Lang.getNumeral(2)), 2, 2, colorChoices, new Callback<>() {
|
||||
@Override
|
||||
public void run(List<String> result) {
|
||||
addCard(card.getSpireVersion(result));
|
||||
addCard(card.getSpireVersion(new HashSet<>(result)));
|
||||
removeCard(card);
|
||||
}
|
||||
});
|
||||
@@ -1897,11 +1897,11 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
||||
if ("Cryptic Spires".equalsIgnoreCase(card.getCardName())) {
|
||||
menu.addItem(new FMenuItem(Forge.getLocalizer().getMessage("lblColorIdentity"), Forge.hdbuttons ? FSkinImage.HDPREFERENCE : FSkinImage.SETTINGS, e -> {
|
||||
//sort options so current option is on top and selected by default
|
||||
List<String> colorChoices = new ArrayList<>(MagicColor.Constant.ONLY_COLORS);
|
||||
Set<String> colorChoices = new HashSet<>(MagicColor.Constant.ONLY_COLORS);
|
||||
GuiChoose.getChoices(Forge.getLocalizer().getMessage("lblChooseAColor", Lang.getNumeral(2)), 2, 2, colorChoices, new Callback<>() {
|
||||
@Override
|
||||
public void run(List<String> result) {
|
||||
addCard(card.getSpireVersion(result));
|
||||
addCard(card.getSpireVersion(new HashSet<>(result)));
|
||||
removeCard(card);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user