diff --git a/forge-gui-mobile/src/forge/adventure/util/CardUtil.java b/forge-gui-mobile/src/forge/adventure/util/CardUtil.java index 95735027514..f25b3ba451b 100644 --- a/forge-gui-mobile/src/forge/adventure/util/CardUtil.java +++ b/forge-gui-mobile/src/forge/adventure/util/CardUtil.java @@ -809,6 +809,11 @@ public class CardUtil { return generateBoosterPackAsDeck(edition); } + private static PaperCard getReplacement(String missingCard, String replacementCard) { + System.err.println(missingCard + " : Not found in the database.\nReplacement card: " + replacementCard); + return FModel.getMagicDb().getCommonCards().getCard(replacementCard); + } + public static PaperCard getCardByName(String cardName) { List validCards; //Faster to ask the CardDB for a card name than it is to search the pool. @@ -817,6 +822,10 @@ public class CardUtil { else validCards = FModel.getMagicDb().getCommonCards().getUniqueCardsNoAlt(cardName); + if (validCards.isEmpty()) { + return getReplacement(cardName, "Wastes"); + } + return validCards.get(Current.world().getRandom().nextInt(validCards.size())); } @@ -828,7 +837,7 @@ public class CardUtil { .filter(input -> input.getEdition().equals(edition)).collect(Collectors.toList()); if (validCards.isEmpty()) { - System.err.println("Unexpected behavior: tried to call getCardByNameAndEdition for card " + cardName + " from the edition " + edition + ", but didn't find it in the DB. A random existing instance will be returned."); + System.err.println("Unexpected behavior: tried to call getCardByNameAndEdition for card " + cardName + " from the edition " + edition + ", but didn't find it in the DB. A random existing instance will be returned if found."); return getCardByName(cardName); } diff --git a/forge-gui/src/main/java/forge/deck/DeckImportController.java b/forge-gui/src/main/java/forge/deck/DeckImportController.java index dbf89e11c2f..08065936d82 100644 --- a/forge-gui/src/main/java/forge/deck/DeckImportController.java +++ b/forge-gui/src/main/java/forge/deck/DeckImportController.java @@ -22,6 +22,7 @@ import org.apache.commons.lang3.tuple.Pair; import java.text.DateFormatSymbols; import java.util.*; import java.util.function.Function; +import java.util.stream.Collectors; public class DeckImportController { public enum ImportBehavior { @@ -516,7 +517,9 @@ public class DeckImportController { PaperCard card = token.getCard(); String cardName = card.getName(); CardPool substitutes = availableInventory.getFilteredPool(c -> c.getName().equals(cardName)); - List> sortedSubstitutes = StreamUtil.stream(substitutes).sorted(Comparator.comparingInt(Map.Entry::getValue)).toList(); + // Stream.toList() is only supported on Android 14 and above ref: https://developer.android.com/reference/java/util/stream/Stream#toList() + // use Collectors.toList() to support Android 8 to 13.... + List> sortedSubstitutes = StreamUtil.stream(substitutes).sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList()); int neededQuantity = token.getQuantity(); for(Token found : replacementList) { //If there's an item in the replacement list already it means we've already found some of the needed copies.