New methods (w. tests) to setup card art preferences

CardDb now includes a more refined mechanism to set up values for CardArt Preference.

These methods do now support the proper setup for legacy values and string values (as supported previously in mobile version).
Moreover, new methods are now defined to support the new (separated) pair of settings as integrated into the Desktop App.
This commit is contained in:
leriomaggio
2021-07-23 07:45:59 +01:00
parent 6be921c1a2
commit 89bdb79d03
2 changed files with 69 additions and 50 deletions

View File

@@ -58,8 +58,8 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
ORIGINAL_ART_ALL_EDITIONS(false, false),
ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY(true, false);
final boolean filterSets;
final boolean latestFirst;
public final boolean filterSets;
public final boolean latestFirst;
CardArtPreference(boolean filterIrregularSets, boolean latestSetFirst) {
filterSets = filterIrregularSets;
@@ -70,30 +70,6 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
if (ed == null) return false;
return !filterSets || ed.getType() == Type.CORE || ed.getType() == Type.EXPANSION || ed.getType() == Type.REPRINT;
}
public static String[] getPreferences(){
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!
@@ -398,10 +374,25 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
}
public CardArtPreference getCardArtPreference(){ return this.defaultCardArtPreference; }
public void setCardArtPreference(String artPreference){
this.defaultCardArtPreference = CardArtPreference.fromForgePreference(artPreference);
public void setCardArtPreference(boolean latestArt, boolean coreExpansionOnly){
if (coreExpansionOnly){
this.defaultCardArtPreference = latestArt ? CardArtPreference.LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY : CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY;
} else {
this.defaultCardArtPreference = latestArt ? CardArtPreference.LATEST_ART_ALL_EDITIONS : CardArtPreference.ORIGINAL_ART_ALL_EDITIONS;
}
}
public void setCardArtPreference(String artPreference){
artPreference = artPreference.toLowerCase().trim();
boolean isLatest = artPreference.contains("latest");
// additional check in case of unrecognised values wrt. to legacy opts
if (!artPreference.contains("original") && !artPreference.contains("earliest"))
isLatest = true; // this must be default
boolean hasFilter = artPreference.contains("core");
this.setCardArtPreference(isLatest, hasFilter);
}
/*
* ======================
* 1. CARD LOOKUP METHODS