From 27ab4c35a3ae2e6ad4b1c9e16f42598a3ea27472 Mon Sep 17 00:00:00 2001 From: leriomaggio Date: Fri, 10 Sep 2021 14:09:25 +0100 Subject: [PATCH] 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) --- .../src/main/java/forge/card/CardDb.java | 24 ++++++++++--------- .../test/java/forge/card/CardDbTestCase.java | 18 +++++++++++++- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/forge-core/src/main/java/forge/card/CardDb.java b/forge-core/src/main/java/forge/card/CardDb.java index b401c6646b5..15d4687e32d 100644 --- a/forge-core/src/main/java/forge/card/CardDb.java +++ b/forge-core/src/main/java/forge/card/CardDb.java @@ -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); } } diff --git a/forge-gui-desktop/src/test/java/forge/card/CardDbTestCase.java b/forge-gui-desktop/src/test/java/forge/card/CardDbTestCase.java index 27f57f0c570..e11464623ae 100644 --- a/forge-gui-desktop/src/test/java/forge/card/CardDbTestCase.java +++ b/forge-gui-desktop/src/test/java/forge/card/CardDbTestCase.java @@ -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()); } }