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_ALL_EDITIONS(false, false),
ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY(true, false); ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY(true, false);
final boolean filterSets; public final boolean filterSets;
final boolean latestFirst; public final boolean latestFirst;
CardArtPreference(boolean filterIrregularSets, boolean latestSetFirst) { CardArtPreference(boolean filterIrregularSets, boolean latestSetFirst) {
filterSets = filterIrregularSets; filterSets = filterIrregularSets;
@@ -70,30 +70,6 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
if (ed == null) return false; if (ed == null) return false;
return !filterSets || ed.getType() == Type.CORE || ed.getType() == Type.EXPANSION || ed.getType() == Type.REPRINT; 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! // Placeholder to setup default art Preference - to be moved from Static Data!
@@ -398,9 +374,24 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
} }
public CardArtPreference getCardArtPreference(){ return this.defaultCardArtPreference; } public CardArtPreference getCardArtPreference(){ return this.defaultCardArtPreference; }
public void setCardArtPreference(String artPreference){ public void setCardArtPreference(boolean latestArt, boolean coreExpansionOnly){
this.defaultCardArtPreference = CardArtPreference.fromForgePreference(artPreference); 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);
}
/* /*
* ====================== * ======================

View File

@@ -67,13 +67,6 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
private final String counterspellPrintedBeforeEternalMasters = "2016-06-09"; // One day before Eternal Masters release private final String counterspellPrintedBeforeEternalMasters = "2016-06-09"; // One day before Eternal Masters release
private final String[] counterspellLatestBeforeEternalMasters = {"TPR", "7ED"}; private final String[] counterspellLatestBeforeEternalMasters = {"TPR", "7ED"};
// CardArt Preferences Fixture
public static final String ORIGINAL_CARDART_PREFERENCE = "Original Art (All Editions)";
public static final String LATEST_CARDART_PREFERENCE = "Latest Art (All Editions)";
public static final String ORIGINAL_CORE_EXP_ONLY_CARDART_PREFERENCE = "Original Art (Core, Expansions, and Reprint only)";
public static final String LATEST_CORE_EXP_ONLY_CARDART_PREFERENCE = "Latest Art (Core, Expansions, and Reprint only)";
@BeforeMethod @BeforeMethod
public void setup(){ public void setup(){
StaticData data = FModel.getMagicDb(); StaticData data = FModel.getMagicDb();
@@ -994,7 +987,7 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
// Now with setting preferences - so going with default cardArt preference. // Now with setting preferences - so going with default cardArt preference.
this.cardDb.setCardArtPreference(LATEST_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(true, false);
counterSpellCard = this.cardDb.getCardFromEditions(cardNameCounterspell, beforeMaster25Date); counterSpellCard = this.cardDb.getCardFromEditions(cardNameCounterspell, beforeMaster25Date);
assertEquals(counterSpellCard.getName(), cardNameCounterspell); assertEquals(counterSpellCard.getName(), cardNameCounterspell);
assertEquals(counterSpellCard.getEdition(), counterspellLatestBeforeMasters25[0]); assertEquals(counterSpellCard.getEdition(), counterspellLatestBeforeMasters25[0]);
@@ -1003,7 +996,7 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
assertEquals(counterSpellCard.getName(), cardNameCounterspell); assertEquals(counterSpellCard.getName(), cardNameCounterspell);
assertEquals(counterSpellCard.getEdition(), counterspellLatestBeforeEternalMasters[0]); assertEquals(counterSpellCard.getEdition(), counterspellLatestBeforeEternalMasters[0]);
this.cardDb.setCardArtPreference(LATEST_CORE_EXP_ONLY_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(true, true);
counterSpellCard = this.cardDb.getCardFromEditions(cardNameCounterspell, beforeMaster25Date); counterSpellCard = this.cardDb.getCardFromEditions(cardNameCounterspell, beforeMaster25Date);
assertEquals(counterSpellCard.getName(), cardNameCounterspell); assertEquals(counterSpellCard.getName(), cardNameCounterspell);
assertEquals(counterSpellCard.getEdition(), counterspellLatestBeforeMasters25[1]); assertEquals(counterSpellCard.getEdition(), counterspellLatestBeforeMasters25[1]);
@@ -1013,7 +1006,7 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
assertEquals(counterSpellCard.getEdition(), counterspellLatestBeforeEternalMasters[1]); assertEquals(counterSpellCard.getEdition(), counterspellLatestBeforeEternalMasters[1]);
// restore default // restore default
this.cardDb.setCardArtPreference(LATEST_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(true, false);
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
} }
@@ -1057,14 +1050,14 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
assertEquals(httCard.getEdition(), newFrameHymnToTourachEdition); assertEquals(httCard.getEdition(), newFrameHymnToTourachEdition);
// Changing default value for default card art preference // Changing default value for default card art preference
this.cardDb.setCardArtPreference(ORIGINAL_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(false, false);
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS);
httCard = this.cardDb.getCardFromEditions(cardNameHymnToTourach, null, null); httCard = this.cardDb.getCardFromEditions(cardNameHymnToTourach, null, null);
assertNotNull(httCard); assertNotNull(httCard);
assertEquals(httCard.getName(), cardNameHymnToTourach); assertEquals(httCard.getName(), cardNameHymnToTourach);
assertEquals(httCard.getEdition(), oldFrameHymnToTourachEdition); assertEquals(httCard.getEdition(), oldFrameHymnToTourachEdition);
// restore default // restore default
this.cardDb.setCardArtPreference(LATEST_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(true, false);
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
} }
@@ -1076,12 +1069,12 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
assertEquals(shivanDragonCard.getEdition(), newFrameShivanDragonEdition); assertEquals(shivanDragonCard.getEdition(), newFrameShivanDragonEdition);
// Try changing the policy // Try changing the policy
this.cardDb.setCardArtPreference(ORIGINAL_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(false, false);
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS);
shivanDragonCard = this.cardDb.getCardFromEditions(cardNameShivanDragon); shivanDragonCard = this.cardDb.getCardFromEditions(cardNameShivanDragon);
assertEquals(shivanDragonCard.getEdition(), oldFrameShivanDragonEdition); assertEquals(shivanDragonCard.getEdition(), oldFrameShivanDragonEdition);
// restore default // restore default
this.cardDb.setCardArtPreference(LATEST_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(true, false);
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
} }
@@ -1103,12 +1096,12 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
assertEquals(httCard.getEdition(), newFrameHymnToTourachEdition); assertEquals(httCard.getEdition(), newFrameHymnToTourachEdition);
// Try changing the policy // Try changing the policy
this.cardDb.setCardArtPreference(ORIGINAL_CORE_EXP_ONLY_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(false, true);
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY);
httCard = this.cardDb.getCardFromEditions(cardNameHymnToTourach); httCard = this.cardDb.getCardFromEditions(cardNameHymnToTourach);
assertEquals(httCard.getEdition(), oldFrameHymnToTourachEditionNoPromo); assertEquals(httCard.getEdition(), oldFrameHymnToTourachEditionNoPromo);
// restore default // restore default
this.cardDb.setCardArtPreference(LATEST_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(true, false);
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
} }
@@ -1209,17 +1202,36 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
@Test @Test
public void testSetCardArtPreference() { public void testSetCardArtPreference() {
// First Off try and see if using constants returned by CardArtPreference.getPreferences will work // First Off try and see if using constants returned by CardArtPreference.getPreferences will work
String[] preferenceNames = CardDb.CardArtPreference.getPreferences();
CardDb.CardArtPreference[] prefs = {CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS, CardDb.CardArtPreference[] prefs = {CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS,
CardDb.CardArtPreference.LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY, CardDb.CardArtPreference.LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY,
CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS, CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS,
CardDb.CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY}; CardDb.CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY};
for (int i = 0; i < 4; i++){ for (int i = 0; i < 4; i++){
this.cardDb.setCardArtPreference(preferenceNames[i]); boolean latest = prefs[i].latestFirst;
boolean coreExpFilter = prefs[i].filterSets;
this.cardDb.setCardArtPreference(latest, coreExpFilter);
assertEquals(this.cardDb.getCardArtPreference(), prefs[i]); assertEquals(this.cardDb.getCardArtPreference(), prefs[i]);
} }
// Test different wording // Test different wording and Legacy Options (esp. for legacy w/ Mobile)
// LEGACY OPTIONS
this.cardDb.setCardArtPreference("LatestCoreExp");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY);
this.cardDb.setCardArtPreference("Earliest");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS);
this.cardDb.setCardArtPreference("EarliestCoreExp");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY);
this.cardDb.setCardArtPreference("Latest");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
this.cardDb.setCardArtPreference("Random");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
// DIFFERENT WORDINGS
this.cardDb.setCardArtPreference("Earliest Editions"); this.cardDb.setCardArtPreference("Earliest Editions");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS);
@@ -1227,7 +1239,7 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY);
this.cardDb.setCardArtPreference("Old Card Frame"); this.cardDb.setCardArtPreference("Old Card Frame");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
this.cardDb.setCardArtPreference("Latest Editions"); this.cardDb.setCardArtPreference("Latest Editions");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
@@ -1238,6 +1250,18 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
this.cardDb.setCardArtPreference("Latest (All Editions)"); this.cardDb.setCardArtPreference("Latest (All Editions)");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
this.cardDb.setCardArtPreference("LATEST_ART_ALL_EDITIONS");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
this.cardDb.setCardArtPreference("ORIGINAL_ART_ALL_EDITIONS");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS);
this.cardDb.setCardArtPreference("LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY);
this.cardDb.setCardArtPreference("ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY");
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY);
// Test non existing option // Test non existing option
this.cardDb.setCardArtPreference("Non existing option"); this.cardDb.setCardArtPreference("Non existing option");
// default goes to Latest Art All Editions // default goes to Latest Art All Editions
@@ -1246,7 +1270,7 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
@Test @Test
public void testSnowCoveredBasicLandsWithCartArtPreference(){ public void testSnowCoveredBasicLandsWithCartArtPreference(){
this.cardDb.setCardArtPreference(LATEST_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(true, false);
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
String snowCoveredLand = "Snow-Covered Island"; String snowCoveredLand = "Snow-Covered Island";
@@ -1255,13 +1279,17 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
assertEquals(landCard.getName(), snowCoveredLand); assertEquals(landCard.getName(), snowCoveredLand);
assertEquals(landCard.getEdition(), "KHM"); assertEquals(landCard.getEdition(), "KHM");
this.cardDb.setCardArtPreference(LATEST_CORE_EXP_ONLY_CARDART_PREFERENCE); this.cardDb.setCardArtPreference(true, true);
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY); assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_CORE_EXPANSIONS_REPRINT_ONLY);
landCard = this.cardDb.getCard(snowCoveredLand); landCard = this.cardDb.getCard(snowCoveredLand);
assertNotNull(landCard); assertNotNull(landCard);
assertEquals(landCard.getName(), snowCoveredLand); assertEquals(landCard.getName(), snowCoveredLand);
assertEquals(landCard.getEdition(), "KHM"); assertEquals(landCard.getEdition(), "KHM");
// reset default
this.cardDb.setCardArtPreference(true, false);
assertEquals(this.cardDb.getCardArtPreference(), CardDb.CardArtPreference.LATEST_ART_ALL_EDITIONS);
} }
@Test(enabled = false) @Test(enabled = false)