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
This commit is contained in:
leriomaggio
2021-08-28 18:29:07 +01:00
parent a7d1e7398a
commit 8768900cf8
2 changed files with 6 additions and 13 deletions

View File

@@ -238,7 +238,8 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
System.out.println("[LOG]: (Lazy) Loading Card: " + cardName); System.out.println("[LOG]: (Lazy) Loading Card: " + cardName);
rulesByName.put(cardName, cr); rulesByName.put(cardName, cr);
boolean reIndexNecessary = false; 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 // look for all possible editions
for (CardEdition e : editions) { for (CardEdition e : editions) {
List<CardInSet> cardsInSet = e.getCardInSet(cardName); // empty collection if not present List<CardInSet> cardsInSet = e.getCardInSet(cardName); // empty collection if not present
@@ -248,12 +249,9 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
} }
} }
} else { } else {
CardEdition e = editions.get(setCode); List<CardInSet> cardsInSet = ed.getCardInSet(cardName); // empty collection if not present
if (e == null)
return; // wrong set code - nothing we can do here!
List<CardInSet> cardsInSet = e.getCardInSet(cardName); // empty collection if not present
for (CardInSet cis : cardsInSet) { for (CardInSet cis : cardsInSet) {
addSetCard(e, cis, cr); addSetCard(ed, cis, cr);
reIndexNecessary = true; reIndexNecessary = true;
} }
} }

View File

@@ -94,8 +94,8 @@ public class CardDbTestLazyCardLoading extends ForgeCardMockTestCase {
public void tesLoadAndGetUnsupportedCardHavingWrongSetCode(){ public void tesLoadAndGetUnsupportedCardHavingWrongSetCode(){
String cardName = "Dominating Licid"; String cardName = "Dominating Licid";
String wrongSetCode = "AA"; String wrongSetCode = "AA";
String expectedSetCode = CardEdition.UNKNOWN.getCode(); String expectedSetCode = "EXO"; // Exodus
CardRarity expectedCardRarity = CardRarity.Unknown; CardRarity expectedCardRarity = CardRarity.Rare;
PaperCard dominatingLycidCard = this.cardDb.getCard(cardName); PaperCard dominatingLycidCard = this.cardDb.getCard(cardName);
assertNull(dominatingLycidCard); assertNull(dominatingLycidCard);
@@ -104,11 +104,6 @@ public class CardDbTestLazyCardLoading extends ForgeCardMockTestCase {
FModel.getMagicDb().attemptToLoadCard(cardName, wrongSetCode); FModel.getMagicDb().attemptToLoadCard(cardName, wrongSetCode);
dominatingLycidCard = this.cardDb.getCard(cardName); 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); assertNotNull(dominatingLycidCard);
assertEquals(dominatingLycidCard.getName(), cardName); assertEquals(dominatingLycidCard.getName(), cardName);
assertEquals(dominatingLycidCard.getEdition(), expectedSetCode); assertEquals(dominatingLycidCard.getEdition(), expectedSetCode);