Re-add to carddb the integration with CardPreferences on Mobile version

On Mobile Forge Port (only) there is the possibility to set a preferred art for a card, from card catalog.
Once a card art is selected, it will always be returned for that specific art whenever no other specific edition is specified.
This commit adds changes to cardDb setPreferredArtMethod (API) and CardRequest.fromString to work with any preferred art (if any).

CardRequests reflects this change by adding another (private) constructor which expects to create a CardRequest from a preferredArt entry in the form of (CardName|SetCode|ArtIndex)
This commit is contained in:
leriomaggio
2021-09-10 14:09:25 +01:00
parent 9d235924ec
commit 27ab4c35a3
2 changed files with 30 additions and 12 deletions

View File

@@ -192,23 +192,25 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
cardName = cardName.substring(0, cardName.length() - foilSuffix.length());
isFoil = true;
}
String preferredArt = artPrefs.get(cardName);
if (preferredArt != null) { //account for preferred art if needed
CardRequest request = fromPreferredArtEntry(preferredArt, isFoil);
if (request != null) // otherwise, simply discard it and go on.
return request;
System.err.println(String.format("[LOG]: Faulty Entry in Preferred Art for Card %s - Please check!", cardName));
}
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 setName = setPos > 0 ? info[setPos] : null;
if (setName != null && setName.equals(CardEdition.UNKNOWN.getCode())) { // ???
setName = null;
String setCode = setPos > 0 ? info[setPos] : null;
if (setCode != null && setCode.equals(CardEdition.UNKNOWN.getCode())) { // ???
setCode = null;
}
if (setCode == null) {
String preferredArt = artPrefs.get(cardName);
if (preferredArt != null) { //account for preferred art if needed
CardRequest request = fromPreferredArtEntry(preferredArt, isFoil);
if (request != null) // otherwise, simply discard it and go on.
return request;
System.err.println(String.format("[LOG]: Faulty Entry in Preferred Art for Card %s - Please check!", cardName));
}
}
// finally, check whether any between artIndex and CollectorNumber has been set
if (collectorNumber.equals(IPaperCard.NO_COLLECTOR_NUMBER) && artIndex == IPaperCard.NO_ART_INDEX)
artIndex = IPaperCard.DEFAULT_ART_INDEX;
return new CardRequest(cardName, setName, artIndex, isFoil, collectorNumber);
return new CardRequest(cardName, setCode, artIndex, isFoil, collectorNumber);
}
}

View File

@@ -2102,7 +2102,7 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
}
@Test void testCardPreferenceSetReturnsAlwaysTheSelectedArtNoMatterTheRequest(){
@Test void testThatWithCardPreferenceSetAndNoRequestForSpecificEditionAlwaysReturnsPreferredArt(){
String cardRequest = CardDb.CardRequest.compose("Island", "MIR", 3);
PaperCard islandCard = this.cardDb.getCard(cardRequest);
assertNotNull(islandCard);
@@ -2118,8 +2118,24 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
assertNotNull(islandCard);
// Now card should be from the preferred art no matter the request
assertEquals(islandCard.getName(), "Island");
assertEquals(islandCard.getEdition(), "TMP");
assertEquals(islandCard.getArtIndex(), 1);
// Now just asking for an Island
islandCard = this.cardDb.getCard("Island");
assertNotNull(islandCard);
assertEquals(islandCard.getName(), "Island");
assertEquals(islandCard.getEdition(), "MIR");
assertEquals(islandCard.getArtIndex(), 3);
// Now asking for a foiled island - I will get the one from preferred art - but foiled
cardRequest = CardDb.CardRequest.compose("Island", true);
islandCard = this.cardDb.getCard(cardRequest);
assertNotNull(islandCard);
assertEquals(islandCard.getName(), "Island");
assertEquals(islandCard.getEdition(), "MIR");
assertEquals(islandCard.getArtIndex(), 3);
assertTrue(islandCard.isFoil());
}
}