From 8768900cf888246f348bd311cfd76dc13bbc12a4 Mon Sep 17 00:00:00 2001 From: leriomaggio Date: Sat, 28 Aug 2021 18:29:07 +0100 Subject: [PATCH] FIX cardDb bug for lazy card loading when issuing a request with a non-existing set code. Code FIX + Test Now the implementation in CardDb will automatically try to get the card with that name from an existing edition --- forge-core/src/main/java/forge/card/CardDb.java | 10 ++++------ .../java/forge/card/CardDbTestLazyCardLoading.java | 9 ++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/forge-core/src/main/java/forge/card/CardDb.java b/forge-core/src/main/java/forge/card/CardDb.java index 0e0a05e731d..998593fa468 100644 --- a/forge-core/src/main/java/forge/card/CardDb.java +++ b/forge-core/src/main/java/forge/card/CardDb.java @@ -238,7 +238,8 @@ public final class CardDb implements ICardDatabase, IDeckGenPool { System.out.println("[LOG]: (Lazy) Loading Card: " + cardName); rulesByName.put(cardName, cr); boolean reIndexNecessary = false; - if ((setCode == null) || setCode.length() == 0 || setCode.equals(CardEdition.UNKNOWN.getCode())) { + CardEdition ed = editions.get(setCode); + if (ed == null || ed.equals(CardEdition.UNKNOWN)) { // look for all possible editions for (CardEdition e : editions) { List cardsInSet = e.getCardInSet(cardName); // empty collection if not present @@ -248,12 +249,9 @@ public final class CardDb implements ICardDatabase, IDeckGenPool { } } } else { - CardEdition e = editions.get(setCode); - if (e == null) - return; // wrong set code - nothing we can do here! - List cardsInSet = e.getCardInSet(cardName); // empty collection if not present + List cardsInSet = ed.getCardInSet(cardName); // empty collection if not present for (CardInSet cis : cardsInSet) { - addSetCard(e, cis, cr); + addSetCard(ed, cis, cr); reIndexNecessary = true; } } diff --git a/forge-gui-desktop/src/test/java/forge/card/CardDbTestLazyCardLoading.java b/forge-gui-desktop/src/test/java/forge/card/CardDbTestLazyCardLoading.java index 5f6710dffba..2ca5b7b828a 100644 --- a/forge-gui-desktop/src/test/java/forge/card/CardDbTestLazyCardLoading.java +++ b/forge-gui-desktop/src/test/java/forge/card/CardDbTestLazyCardLoading.java @@ -94,8 +94,8 @@ public class CardDbTestLazyCardLoading extends ForgeCardMockTestCase { public void tesLoadAndGetUnsupportedCardHavingWrongSetCode(){ String cardName = "Dominating Licid"; String wrongSetCode = "AA"; - String expectedSetCode = CardEdition.UNKNOWN.getCode(); - CardRarity expectedCardRarity = CardRarity.Unknown; + String expectedSetCode = "EXO"; // Exodus + CardRarity expectedCardRarity = CardRarity.Rare; PaperCard dominatingLycidCard = this.cardDb.getCard(cardName); assertNull(dominatingLycidCard); @@ -104,11 +104,6 @@ public class CardDbTestLazyCardLoading extends ForgeCardMockTestCase { FModel.getMagicDb().attemptToLoadCard(cardName, wrongSetCode); dominatingLycidCard = this.cardDb.getCard(cardName); - assertNull(dominatingLycidCard); // card still not found - - // Resorting to Unsupported Card Request - String cardRequest = CardDb.CardRequest.compose(cardName, wrongSetCode); - dominatingLycidCard = this.cardDb.createUnsupportedCard(cardRequest); assertNotNull(dominatingLycidCard); assertEquals(dominatingLycidCard.getName(), cardName); assertEquals(dominatingLycidCard.getEdition(), expectedSetCode);