mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Merge branch 'master' into 'master'
Skip loading filtered card See merge request core-developers/forge!4342
This commit is contained in:
@@ -79,16 +79,30 @@ public class StaticData {
|
|||||||
this.customEditions = new CardEdition.Collection(new CardEdition.Reader(new File(customEditionsFolder)));
|
this.customEditions = new CardEdition.Collection(new CardEdition.Reader(new File(customEditionsFolder)));
|
||||||
this.prefferedArt = prefferedArt;
|
this.prefferedArt = prefferedArt;
|
||||||
lastInstance = this;
|
lastInstance = this;
|
||||||
|
List<String> funnyCards = new ArrayList<>();
|
||||||
|
List<String> filtered = new ArrayList<>();
|
||||||
|
|
||||||
{
|
{
|
||||||
final Map<String, CardRules> regularCards = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
final Map<String, CardRules> regularCards = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
final Map<String, CardRules> variantsCards = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
final Map<String, CardRules> variantsCards = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
final Map<String, CardRules> customizedCards = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
final Map<String, CardRules> customizedCards = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
|
||||||
|
for (CardEdition e : editions) {
|
||||||
|
if (e.getType() == CardEdition.Type.FUNNY || e.getBorderColor() == CardEdition.BorderColor.SILVER) {
|
||||||
|
for (CardEdition.CardInSet cis : e.getAllCardsInSet()) {
|
||||||
|
funnyCards.add(cis.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (CardRules card : cardReader.loadCards()) {
|
for (CardRules card : cardReader.loadCards()) {
|
||||||
if (null == card) continue;
|
if (null == card) continue;
|
||||||
|
|
||||||
final String cardName = card.getName();
|
final String cardName = card.getName();
|
||||||
|
|
||||||
|
if (!loadNonLegalCards && !card.getType().isBasicLand() && funnyCards.contains(cardName))
|
||||||
|
filtered.add(cardName);
|
||||||
|
|
||||||
if (card.isVariant()) {
|
if (card.isVariant()) {
|
||||||
variantsCards.put(cardName, card);
|
variantsCards.put(cardName, card);
|
||||||
} else {
|
} else {
|
||||||
@@ -104,15 +118,18 @@ public class StaticData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!filtered.isEmpty()) {
|
||||||
|
Collections.sort(filtered);
|
||||||
|
}
|
||||||
|
|
||||||
commonCards = new CardDb(regularCards, editions);
|
commonCards = new CardDb(regularCards, editions);
|
||||||
variantCards = new CardDb(variantsCards, editions);
|
variantCards = new CardDb(variantsCards, editions);
|
||||||
customCards = new CardDb(customizedCards, customEditions);
|
customCards = new CardDb(customizedCards, customEditions);
|
||||||
|
|
||||||
//must initialize after establish field values for the sake of card image logic
|
//must initialize after establish field values for the sake of card image logic
|
||||||
commonCards.initialize(false, false, enableUnknownCards, loadNonLegalCards);
|
commonCards.initialize(false, false, enableUnknownCards, filtered);
|
||||||
variantCards.initialize(false, false, enableUnknownCards, loadNonLegalCards);
|
variantCards.initialize(false, false, enableUnknownCards, filtered);
|
||||||
customCards.initialize(false, false, enableUnknownCards, loadNonLegalCards);
|
customCards.initialize(false, false, enableUnknownCards, filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ import forge.util.TextUtil;
|
|||||||
public final class CardDb implements ICardDatabase, IDeckGenPool {
|
public final class CardDb implements ICardDatabase, IDeckGenPool {
|
||||||
public final static String foilSuffix = "+";
|
public final static String foilSuffix = "+";
|
||||||
public final static char NameSetSeparator = '|';
|
public final static char NameSetSeparator = '|';
|
||||||
private boolean loadNonLegalCards = true;
|
|
||||||
|
|
||||||
// need this to obtain cardReference by name+set+artindex
|
// need this to obtain cardReference by name+set+artindex
|
||||||
private final ListMultimap<String, PaperCard> allCardsByName = Multimaps.newListMultimap(new TreeMap<>(String.CASE_INSENSITIVE_ORDER), CollectionSuppliers.arrayLists());
|
private final ListMultimap<String, PaperCard> allCardsByName = Multimaps.newListMultimap(new TreeMap<>(String.CASE_INSENSITIVE_ORDER), CollectionSuppliers.arrayLists());
|
||||||
@@ -69,6 +68,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
private final Map<String, Integer> artIds = new HashMap<>();
|
private final Map<String, Integer> artIds = new HashMap<>();
|
||||||
|
|
||||||
private final CardEdition.Collection editions;
|
private final CardEdition.Collection editions;
|
||||||
|
private List<String> filtered;
|
||||||
|
|
||||||
public enum SetPreference {
|
public enum SetPreference {
|
||||||
Latest(false),
|
Latest(false),
|
||||||
@@ -157,19 +157,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ListMultimap<String, PaperCard> getAllCardsByName() {
|
private ListMultimap<String, PaperCard> getAllCardsByName() {
|
||||||
if (loadNonLegalCards)
|
return allCardsByName;
|
||||||
return allCardsByName;
|
|
||||||
return Multimaps.filterKeys(allCardsByName, new Predicate<String>() {
|
|
||||||
@Override
|
|
||||||
public boolean apply(String s) {
|
|
||||||
PaperCard pc = getUniqueByName(s);
|
|
||||||
if (pc != null) {
|
|
||||||
if (checkNonLegal(pc))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSetCard(CardEdition e, CardInSet cis, CardRules cr) {
|
private void addSetCard(CardEdition e, CardInSet cis, CardRules cr) {
|
||||||
@@ -199,12 +187,12 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
reIndex();
|
reIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(boolean logMissingPerEdition, boolean logMissingSummary, boolean enableUnknownCards, boolean loadNonLegalCards) {
|
public void initialize(boolean logMissingPerEdition, boolean logMissingSummary, boolean enableUnknownCards, List<String> filtered) {
|
||||||
|
this.filtered = filtered;
|
||||||
Set<String> allMissingCards = new LinkedHashSet<>();
|
Set<String> allMissingCards = new LinkedHashSet<>();
|
||||||
List<String> missingCards = new ArrayList<>();
|
List<String> missingCards = new ArrayList<>();
|
||||||
CardEdition upcomingSet = null;
|
CardEdition upcomingSet = null;
|
||||||
Date today = new Date();
|
Date today = new Date();
|
||||||
this.loadNonLegalCards = loadNonLegalCards;
|
|
||||||
|
|
||||||
for (CardEdition e : editions.getOrderedEditions()) {
|
for (CardEdition e : editions.getOrderedEditions()) {
|
||||||
boolean coreOrExpSet = e.getType() == CardEdition.Type.CORE || e.getType() == CardEdition.Type.EXPANSION;
|
boolean coreOrExpSet = e.getType() == CardEdition.Type.CORE || e.getType() == CardEdition.Type.EXPANSION;
|
||||||
@@ -264,6 +252,15 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addCard(PaperCard paperCard) {
|
public void addCard(PaperCard paperCard) {
|
||||||
|
if (filtered.contains(paperCard.getName())) {
|
||||||
|
//TODO: Funny cards (filtered) may have real cards (except basic lands which is excluded)
|
||||||
|
//This is needed since Concentrate is a real card and DS0 set (Drake Stone) has Concentrate card
|
||||||
|
if (paperCard.getEdition().equalsIgnoreCase("DS0") && paperCard.getName().equalsIgnoreCase("Concentrate"))
|
||||||
|
return;
|
||||||
|
else if (!paperCard.getName().equalsIgnoreCase("Concentrate"))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
allCardsByName.put(paperCard.getName(), paperCard);
|
allCardsByName.put(paperCard.getName(), paperCard);
|
||||||
|
|
||||||
if (paperCard.getRules().getSplitType() == CardSplitType.None) { return; }
|
if (paperCard.getRules().getSplitType() == CardSplitType.None) { return; }
|
||||||
@@ -282,21 +279,10 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
uniqueCardsByName.clear();
|
uniqueCardsByName.clear();
|
||||||
for (Entry<String, Collection<PaperCard>> kv : getAllCardsByName().asMap().entrySet()) {
|
for (Entry<String, Collection<PaperCard>> kv : getAllCardsByName().asMap().entrySet()) {
|
||||||
PaperCard pc = getFirstWithImage(kv.getValue());
|
PaperCard pc = getFirstWithImage(kv.getValue());
|
||||||
if (checkNonLegal(pc))
|
|
||||||
continue;
|
|
||||||
uniqueCardsByName.put(kv.getKey(), pc);
|
uniqueCardsByName.put(kv.getKey(), pc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkNonLegal(PaperCard pc) {
|
|
||||||
try {
|
|
||||||
if (!loadNonLegalCards && (editions.get(pc.getEdition()).getType() == CardEdition.Type.FUNNY || editions.get(pc.getEdition()).getBorderColor() == CardEdition.BorderColor.SILVER))
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private static PaperCard getFirstWithImage(final Collection<PaperCard> cards) {
|
private static PaperCard getFirstWithImage(final Collection<PaperCard> cards) {
|
||||||
//NOTE: this is written this way to avoid checking final card in list
|
//NOTE: this is written this way to avoid checking final card in list
|
||||||
final Iterator<PaperCard> iterator = cards.iterator();
|
final Iterator<PaperCard> iterator = cards.iterator();
|
||||||
@@ -588,8 +574,6 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
public boolean apply(Entry<String, PaperCard> e) {
|
public boolean apply(Entry<String, PaperCard> e) {
|
||||||
if (e == null)
|
if (e == null)
|
||||||
return false;
|
return false;
|
||||||
if (checkNonLegal(e.getValue()))
|
|
||||||
return false;
|
|
||||||
return e.getKey().equals(e.getValue().getName());
|
return e.getKey().equals(e.getValue().getName());
|
||||||
}
|
}
|
||||||
}).values();
|
}).values();
|
||||||
@@ -616,8 +600,6 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
return Multimaps.filterEntries(getAllCardsByName(), new Predicate<Entry<String, PaperCard>>() {
|
return Multimaps.filterEntries(getAllCardsByName(), new Predicate<Entry<String, PaperCard>>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Entry<String, PaperCard> entry) {
|
public boolean apply(Entry<String, PaperCard> entry) {
|
||||||
if (checkNonLegal(entry.getValue()))
|
|
||||||
return false;
|
|
||||||
return entry.getKey().equals(entry.getValue().getName());
|
return entry.getKey().equals(entry.getValue().getName());
|
||||||
}
|
}
|
||||||
}).values();
|
}).values();
|
||||||
@@ -654,8 +636,6 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
|
|||||||
return Lists.newArrayList(Multimaps.filterEntries(getAllCardsByName(), new Predicate<Entry<String, PaperCard>>() {
|
return Lists.newArrayList(Multimaps.filterEntries(getAllCardsByName(), new Predicate<Entry<String, PaperCard>>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Entry<String, PaperCard> entry) {
|
public boolean apply(Entry<String, PaperCard> entry) {
|
||||||
if (checkNonLegal(entry.getValue()))
|
|
||||||
return false;
|
|
||||||
return entry.getKey().equals(entry.getValue().getName());
|
return entry.getKey().equals(entry.getValue().getName());
|
||||||
}
|
}
|
||||||
}).get(getName(cardName)));
|
}).get(getName(cardName)));
|
||||||
|
|||||||
Reference in New Issue
Block a user