From 4837bb574091610b4d795b18f2044ad7de21eb35 Mon Sep 17 00:00:00 2001 From: Agetian Date: Mon, 13 Jan 2014 08:54:04 +0000 Subject: [PATCH] - Support distinction between cards with different card art indexes in the deck editors (the card index is now saved to .dck file and loaded from there if available). - Remove a Singleton call from Match that was necessary to randomize card art (will be unsupported later and will not be necessary anyway once the true support is fully implemented). - (WIP) Automatically randomize card art for cards that do not have the art index specified; for now only works for basic lands that were generated randomly (e.g. in random Constructed decks). Limited mode (sealed decks, draft decks, quest mode generated pool, quest mode spell shop) support for generating cards with different card art will hopefully follow soon. --- .../src/main/java/forge/card/CardDb.java | 42 +++++++++++-------- forge-core/src/main/java/forge/deck/Deck.java | 1 + .../deck/generation/DeckGeneratorBase.java | 4 +- forge-gui/src/main/java/forge/game/Match.java | 9 +--- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/forge-core/src/main/java/forge/card/CardDb.java b/forge-core/src/main/java/forge/card/CardDb.java index ed47905402b..b65f4b246e5 100644 --- a/forge-core/src/main/java/forge/card/CardDb.java +++ b/forge-core/src/main/java/forge/card/CardDb.java @@ -44,6 +44,7 @@ import forge.util.Aggregates; import forge.util.CollectionSuppliers; import forge.util.Lang; import forge.util.MyRandom; +import java.util.Arrays; public final class CardDb implements ICardDatabase { public final static String foilSuffix = "+"; @@ -118,21 +119,25 @@ public final class CardDb implements ICardDatabase { } /** - * Splits cardname into Name and set whenever deck line reads as name|set. + * Splits cardname into name, set and art index whenever deck line reads as name|set|artindex. */ - private static ImmutablePair splitCardName(final String name) { + private static List splitCardName(final String name) { String cardName = name; // .trim() ? - final int pipePos = cardName.indexOf('|'); + String[] cardNameElems = cardName.split("\\|"); - if (pipePos >= 0) { - final String setName = cardName.substring(pipePos + 1).trim(); - cardName = cardName.substring(0, pipePos); - // only if set is not blank try to load it - if (StringUtils.isNotBlank(setName) && !"???".equals(setName)) { - return new ImmutablePair(cardName, setName); + final String actualCardName = cardNameElems[0]; + String setName = null; + String artIndex = "-1"; + if (cardNameElems.length > 1) { + if (StringUtils.isNotBlank(cardNameElems[1]) && !"???".equals(cardNameElems[1])) { + setName = cardNameElems[1]; + } + if (cardNameElems.length > 2) { + artIndex = cardNameElems[2]; } } - return new ImmutablePair(cardName, null); + + return Arrays.asList(actualCardName, setName, artIndex); } private boolean isFoil(final String cardName) { @@ -163,11 +168,12 @@ public final class CardDb implements ICardDatabase { final boolean isFoil = this.isFoil(cardName0); final String cardName = isFoil ? this.removeFoilSuffix(cardName0) : cardName0; - final ImmutablePair nameWithSet = CardDb.splitCardName(cardName); + final List splitName = CardDb.splitCardName(cardName); + + final PaperCard res = splitName.get(1) == null + ? ( fromLastSet ? this.uniqueCardsByName.get(splitName.get(0)) : tryGetCard(splitName.get(0), Aggregates.random(this.allCardsByName.get(splitName.get(0))).getEdition(), -1)) + : tryGetCard(splitName.get(0), splitName.get(1), Integer.parseInt(splitName.get(2))); - final PaperCard res = nameWithSet.right == null - ? ( fromLastSet ? this.uniqueCardsByName.get(nameWithSet.left) : Aggregates.random(this.allCardsByName.get(nameWithSet.left)) ) - : tryGetCard(nameWithSet.left, nameWithSet.right); return null != res && isFoil ? getFoiled(res) : res; } @@ -175,13 +181,13 @@ public final class CardDb implements ICardDatabase { public PaperCard tryGetCardPrintedByDate(final String name0, final boolean fromLatestSet, final Date printedBefore) { final boolean isFoil = this.isFoil(name0); final String cardName = isFoil ? this.removeFoilSuffix(name0) : name0; - final ImmutablePair nameWithSet = CardDb.splitCardName(cardName); + final List splitName = CardDb.splitCardName(cardName); PaperCard res = null; - if (null != nameWithSet.right) // set explicitly requested, should return card from it and disregard the date - res = tryGetCard(nameWithSet.left, nameWithSet.right); + if (null != splitName.get(1)) // set explicitly requested, should return card from it and disregard the date + res = tryGetCard(splitName.get(0), splitName.get(1), Integer.parseInt(splitName.get(2))); else { - Collection cards = this.allCardsByName.get(nameWithSet.left); // cards are sorted by datetime desc + Collection cards = this.allCardsByName.get(splitName.get(0)); // cards are sorted by datetime desc int idxRightSet = 0; for (PaperCard card : cards) { if (editions.get(card.getEdition()).getDate().after(printedBefore)) diff --git a/forge-core/src/main/java/forge/deck/Deck.java b/forge-core/src/main/java/forge/deck/Deck.java index 6a47202056d..a81cc1ae566 100644 --- a/forge-core/src/main/java/forge/deck/Deck.java +++ b/forge-core/src/main/java/forge/deck/Deck.java @@ -228,6 +228,7 @@ public class Deck extends DeckBase implements Iterable stackOfCards : section) { final PaperCard cp = stackOfCards.getKey(); for (int i = 0; i < stackOfCards.getValue(); i++) { - - // apply random art for cards with multiple pictures (basic lands, etc.) - currently always enabled - // TODO: implement true distinction between cards with different art (in deck editor, match, etc.) - PaperCard cpi = Singletons.getMagicDb().getCommonCards().getCard(cp.getName(), cp.getEdition(), -1); - if ( cp.isFoil() ) - cpi = Singletons.getMagicDb().getCommonCards().getFoiled(cpi); - - final Card card = cpi == null ? Card.fromPaperCard(cp, player) : Card.fromPaperCard(cpi, player); + final Card card = Card.fromPaperCard(cp, player); // Assign card-specific foiling or random foiling on approximately 1:20 cards if enabled if (cp.isFoil() || (canRandomFoil && MyRandom.percentTrue(5))) {