Updated CardArtPreference Constants value

Also, the CardArtPreference Enum now includes a new methods that allows seamless recognition (and instantiation) of corresponding enum value from Forge Preference - also with backward compatibility.
This commit is contained in:
leriomaggio
2021-07-09 20:20:52 +01:00
parent 2d3d67176a
commit 7664937c93
5 changed files with 34 additions and 26 deletions

View File

@@ -53,10 +53,10 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
private List<String> filtered;
public enum CardArtPreference {
LatestArtAllEditions(false, true),
LatestArtExcludedPromoAndOnlineEditions(true, true),
OldArtAllEditions(false, false),
OldArtExcludedPromoAndOnlineEditions(true, false);
LATEST_ART_ALL_EDITIONS(false, true),
LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY(true, true),
ORIGINAL_ART_ALL_EDITIONS(false, false),
ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY(true, false);
final boolean filterSets;
final boolean latestFirst;
@@ -72,15 +72,33 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
}
public static String[] getPreferences(){
return new String[]{"Latest Art (All Editions)",
"Latest Art (Excluded Promo And Online Editions)",
"Old Art (All Editions)",
"Old Art (Excluded Promo And Online Editions)"};
return new String[]{"Latest Card Art (All Editions)",
"Latest Card Art (Core, Expansions and Reprint Only)",
"Original Card Art (All Editions)",
"Original Card Art (Core, Expansions and Reprint Only)"};
}
public static CardArtPreference fromForgePreference(final String preference){
String prefLabel = preference.trim().toLowerCase();
if (prefLabel.contains("latest")){
if (prefLabel.contains("core"))
return LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY;
return LATEST_ART_ALL_EDITIONS;
}
if (prefLabel.contains("old") || prefLabel.contains("original") || prefLabel.contains("earliest")){
if (prefLabel.contains("core"))
return ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY;
return ORIGINAL_ART_ALL_EDITIONS;
}
return LATEST_ART_ALL_EDITIONS; // DEFAULT fall back
}
}
// Placeholder to setup default art Preference - to be moved from Static Data!
private CardArtPreference defaultCardArtPreference;
private static final CardArtPreference DEFAULT_ART_PREFERENCE = CardArtPreference.LATEST_ART_ALL_EDITIONS;
public static class CardRequest {
public String cardName;
@@ -385,17 +403,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
public CardArtPreference getCardArtPreference(){ return this.defaultCardArtPreference; }
public void setCardArtPreference(String artPreference){
artPreference = artPreference.replaceAll("[\\s\\(\\)]", "");
CardArtPreference cardArtPreference = null;
try{
cardArtPreference = CardArtPreference.valueOf(artPreference);
} catch (IllegalArgumentException ex){
cardArtPreference = CardArtPreference.LatestArtAllEditions; // default
}
finally {
if (cardArtPreference != null)
this.defaultCardArtPreference = cardArtPreference;
}
this.defaultCardArtPreference = CardArtPreference.fromForgePreference(artPreference);
}
/*

View File

@@ -797,12 +797,12 @@ public final class CardEdition implements Comparable<CardEdition> {
public CardEdition getEarliestEditionWithAllCards(CardPool cards) {
Set<String> minEditions = new HashSet<>();
CardArtPreference strictness = CardArtPreference.OldArtExcludedPromoAndOnlineEditions;
CardArtPreference strictness = CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY;
for (Entry<PaperCard, Integer> k : cards) {
PaperCard cp = StaticData.instance().getCommonCards().getCardFromEditions(k.getKey().getName(), strictness);
if( cp == null && strictness == CardArtPreference.OldArtExcludedPromoAndOnlineEditions) {
strictness = CardArtPreference.OldArtAllEditions; // card is not found in core and expansions only (probably something CMD or C13)
if( cp == null && strictness == CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY) {
strictness = CardArtPreference.ORIGINAL_ART_ALL_EDITIONS; // card is not found in core and expansions only (probably something CMD or C13)
cp = StaticData.instance().getCommonCards().getCardFromEditions(k.getKey().getName(), strictness);
}
if ( cp == null )

View File

@@ -113,10 +113,10 @@ public class DeckRecognizer {
useLastSet = null;
}
else if (onlyCoreAndExp) {
useLastSet = CardArtPreference.LatestArtExcludedPromoAndOnlineEditions;
useLastSet = CardArtPreference.LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY;
}
else {
useLastSet = CardArtPreference.LatestArtAllEditions;
useLastSet = CardArtPreference.LATEST_ART_ALL_EDITIONS;
}
this.db = db;
}

View File

@@ -6368,7 +6368,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
return cp == null ? StaticData.instance().getCommonCards().getCard(name, set) : cp;
}
cp = StaticData.instance().getVariantCards().getCard(name);
return cp == null ? StaticData.instance().getCommonCards().getCardFromEditions(name, CardArtPreference.LatestArtAllEditions) : cp;
return cp == null ? StaticData.instance().getCommonCards().getCardFromEditions(name, CardArtPreference.LATEST_ART_ALL_EDITIONS) : cp;
}
/**

View File

@@ -1703,7 +1703,7 @@ public class CardProperty {
} else if (property.startsWith("set")) {
final String setCode = property.substring(3, 6);
final PaperCard setCard = StaticData.instance().getCommonCards().getCardFromEditions(card.getName(),
CardDb.CardArtPreference.OldArtAllEditions);
CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS);
if (!setCard.getEdition().equals(setCode)) {
return false;
}