mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
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:
@@ -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<CardInSet> 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<CardInSet> cardsInSet = e.getCardInSet(cardName); // empty collection if not present
|
||||
List<CardInSet> cardsInSet = ed.getCardInSet(cardName); // empty collection if not present
|
||||
for (CardInSet cis : cardsInSet) {
|
||||
addSetCard(e, cis, cr);
|
||||
addSetCard(ed, cis, cr);
|
||||
reIndexNecessary = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user