mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Whitespace cleanup
This commit is contained in:
@@ -21,90 +21,83 @@ import forge.util.storage.StorageBase;
|
||||
* @author Max
|
||||
*/
|
||||
public class StaticData {
|
||||
private final CardDb commonCards;
|
||||
private final CardDb variantCards;
|
||||
private final CardEdition.Collection editions;
|
||||
private final IStorage<SealedProduct.Template> boosters;
|
||||
private final IStorage<SealedProduct.Template> specialBoosters;
|
||||
private final IStorage<SealedProduct.Template> tournaments;
|
||||
private final IStorage<FatPack.Template> fatPacks;
|
||||
private final IStorage<PrintSheet> printSheets;
|
||||
|
||||
private final CardDb commonCards;
|
||||
private final CardDb variantCards;
|
||||
private final CardEdition.Collection editions;
|
||||
private final IStorage<SealedProduct.Template> boosters;
|
||||
private final IStorage<SealedProduct.Template> specialBoosters;
|
||||
private final IStorage<SealedProduct.Template> tournaments;
|
||||
private final IStorage<FatPack.Template> fatPacks;
|
||||
private final IStorage<PrintSheet> printSheets;
|
||||
private static StaticData lastInstance = null;
|
||||
|
||||
private static StaticData lastInstance = null;
|
||||
public StaticData(ICardStorageReader reader, String editionFolder, String blockDataFolder) {
|
||||
this.editions = new CardEdition.Collection(new CardEdition.Reader(new File(editionFolder)));
|
||||
lastInstance = this;
|
||||
|
||||
final Map<String, CardRules> regularCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
|
||||
final Map<String, CardRules> variantsCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
|
||||
public StaticData(ICardStorageReader reader, String editionFolder, String blockDataFolder) {
|
||||
this.editions = new CardEdition.Collection(new CardEdition.Reader(new File(editionFolder)));
|
||||
lastInstance = this;
|
||||
List<CardRules> rules = reader.loadCards();
|
||||
for (CardRules card : rules) {
|
||||
if (null == card) continue;
|
||||
|
||||
final Map<String, CardRules> regularCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
|
||||
final Map<String, CardRules> variantsCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
|
||||
final String cardName = card.getName();
|
||||
if ( card.isVariant() ) {
|
||||
variantsCards.put(cardName, card);
|
||||
}
|
||||
else {
|
||||
regularCards.put(cardName, card);
|
||||
}
|
||||
}
|
||||
|
||||
commonCards = new CardDb(regularCards, editions, false);
|
||||
variantCards = new CardDb(variantsCards, editions, false);
|
||||
|
||||
List<CardRules> rules = reader.loadCards();
|
||||
for (CardRules card : rules) {
|
||||
if (null == card) continue;
|
||||
|
||||
final String cardName = card.getName();
|
||||
if ( card.isVariant() )
|
||||
variantsCards.put(cardName, card);
|
||||
else
|
||||
regularCards.put(cardName, card);
|
||||
}
|
||||
|
||||
commonCards = new CardDb(regularCards, editions, false);
|
||||
variantCards = new CardDb(variantsCards, editions, false);
|
||||
this.boosters = new StorageBase<SealedProduct.Template>("Boosters", editions.getBoosterGenerator());
|
||||
this.specialBoosters = new StorageBase<SealedProduct.Template>("Special boosters", new SealedProduct.Template.Reader(new File(blockDataFolder, "boosters-special.txt")));
|
||||
this.tournaments = new StorageBase<SealedProduct.Template>("Starter sets", new SealedProduct.Template.Reader(new File(blockDataFolder, "starters.txt")));
|
||||
this.fatPacks = new StorageBase<FatPack.Template>("Fat packs", new FatPack.Template.Reader("res/blockdata/fatpacks.txt"));
|
||||
this.printSheets = new StorageBase<PrintSheet>("Special print runs", new PrintSheet.Reader(new File(blockDataFolder, "printsheets.txt")));
|
||||
}
|
||||
|
||||
public final static StaticData instance() {
|
||||
return lastInstance;
|
||||
}
|
||||
|
||||
this.boosters = new StorageBase<SealedProduct.Template>("Boosters", editions.getBoosterGenerator());
|
||||
this.specialBoosters = new StorageBase<SealedProduct.Template>("Special boosters", new SealedProduct.Template.Reader(new File(blockDataFolder, "boosters-special.txt")));
|
||||
this.tournaments = new StorageBase<SealedProduct.Template>("Starter sets", new SealedProduct.Template.Reader(new File(blockDataFolder, "starters.txt")));
|
||||
this.fatPacks = new StorageBase<FatPack.Template>("Fat packs", new FatPack.Template.Reader("res/blockdata/fatpacks.txt"));
|
||||
this.printSheets = new StorageBase<PrintSheet>("Special print runs", new PrintSheet.Reader(new File(blockDataFolder, "printsheets.txt")));
|
||||
}
|
||||
|
||||
public final static StaticData instance() {
|
||||
return lastInstance;
|
||||
}
|
||||
|
||||
|
||||
public final CardEdition.Collection getEditions() {
|
||||
return this.editions;
|
||||
}
|
||||
public final CardEdition.Collection getEditions() {
|
||||
return this.editions;
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.item.FatPackTemplate}> */
|
||||
public IStorage<FatPack.Template> getFatPacks() {
|
||||
return fatPacks;
|
||||
}
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.item.FatPackTemplate}> */
|
||||
public IStorage<FatPack.Template> getFatPacks() {
|
||||
return fatPacks;
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
|
||||
public final IStorage<SealedProduct.Template> getTournamentPacks() {
|
||||
return tournaments;
|
||||
}
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
|
||||
public final IStorage<SealedProduct.Template> getTournamentPacks() {
|
||||
return tournaments;
|
||||
}
|
||||
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
|
||||
public final IStorage<SealedProduct.Template> getBoosters() {
|
||||
return boosters;
|
||||
}
|
||||
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
|
||||
public final IStorage<SealedProduct.Template> getBoosters() {
|
||||
return boosters;
|
||||
}
|
||||
|
||||
public final IStorage<SealedProduct.Template> getSpecialBoosters() {
|
||||
return specialBoosters;
|
||||
}
|
||||
public final IStorage<SealedProduct.Template> getSpecialBoosters() {
|
||||
return specialBoosters;
|
||||
}
|
||||
|
||||
public IStorage<PrintSheet> getPrintSheets() {
|
||||
return printSheets;
|
||||
}
|
||||
public IStorage<PrintSheet> getPrintSheets() {
|
||||
return printSheets;
|
||||
}
|
||||
|
||||
public CardDb getCommonCards() {
|
||||
return commonCards;
|
||||
}
|
||||
|
||||
public CardDb getCommonCards() {
|
||||
return commonCards;
|
||||
}
|
||||
|
||||
|
||||
public CardDb getVariantCards() {
|
||||
return variantCards;
|
||||
}
|
||||
|
||||
public CardDb getVariantCards() {
|
||||
return variantCards;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
|
||||
import forge.card.CardEdition.CardInSet;
|
||||
import forge.deck.CardPool;
|
||||
import forge.item.PaperCard;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.CollectionSuppliers;
|
||||
@@ -54,12 +53,11 @@ public final class CardDb implements ICardDatabase {
|
||||
private final Multimap<String, PaperCard> allCardsByName = Multimaps.newListMultimap(new TreeMap<String,Collection<PaperCard>>(String.CASE_INSENSITIVE_ORDER), CollectionSuppliers.<PaperCard>arrayLists());
|
||||
private final Map<String, PaperCard> uniqueCardsByName = new TreeMap<String, PaperCard>(String.CASE_INSENSITIVE_ORDER);
|
||||
private final Map<String, CardRules> rulesByName;
|
||||
|
||||
|
||||
private final List<PaperCard> allCards = new ArrayList<PaperCard>();
|
||||
private final List<PaperCard> roAllCards = Collections.unmodifiableList(allCards);
|
||||
private final List<PaperCard> roAllCards = Collections.unmodifiableList(allCards);
|
||||
private final Collection<PaperCard> roUniqueCards = Collections.unmodifiableCollection(uniqueCardsByName.values());
|
||||
private final CardEdition.Collection editions;
|
||||
|
||||
|
||||
public CardDb(Map<String, CardRules> rules, CardEdition.Collection editions0, boolean logMissingCards) {
|
||||
this.rulesByName = rules;
|
||||
@@ -72,14 +70,14 @@ public final class CardDb implements ICardDatabase {
|
||||
String lastCardName = null;
|
||||
int artIdx = 0;
|
||||
for(CardEdition.CardInSet cis : e.getCards()) {
|
||||
if ( cis.name.equals(lastCardName) )
|
||||
if ( cis.name.equals(lastCardName) )
|
||||
artIdx++;
|
||||
else {
|
||||
artIdx = 0;
|
||||
lastCardName = cis.name;
|
||||
}
|
||||
CardRules cr = rulesByName.get(lastCardName);
|
||||
if( cr != null )
|
||||
if( cr != null )
|
||||
addCard(new PaperCard(cr, e.getCode(), cis.rarity, artIdx));
|
||||
else if (worthLogging)
|
||||
missingCards.add(cis.name);
|
||||
@@ -94,7 +92,7 @@ public final class CardDb implements ICardDatabase {
|
||||
missingCards.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(CardRules cr : rulesByName.values()) {
|
||||
if( !allCardsByName.containsKey(cr.getName()) )
|
||||
{
|
||||
@@ -102,7 +100,7 @@ public final class CardDb implements ICardDatabase {
|
||||
addCard(new PaperCard(cr, CardEdition.UNKNOWN.getCode(), CardRarity.Special, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
reIndex();
|
||||
}
|
||||
|
||||
@@ -155,7 +153,7 @@ public final class CardDb implements ICardDatabase {
|
||||
public PaperCard tryGetCard(final String cardName0) {
|
||||
return tryGetCard(cardName0, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PaperCard tryGetCard(final String cardName0, boolean fromLastSet) {
|
||||
if (null == cardName0) {
|
||||
@@ -164,23 +162,23 @@ public final class CardDb implements ICardDatabase {
|
||||
|
||||
final boolean isFoil = this.isFoil(cardName0);
|
||||
final String cardName = isFoil ? this.removeFoilSuffix(cardName0) : cardName0;
|
||||
|
||||
|
||||
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(cardName);
|
||||
|
||||
final PaperCard res = nameWithSet.right == null
|
||||
? ( fromLastSet ? this.uniqueCardsByName.get(nameWithSet.left) : Aggregates.random(this.allCardsByName.get(nameWithSet.left)) )
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
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<String, String> nameWithSet = CardDb.splitCardName(cardName);
|
||||
|
||||
|
||||
PaperCard res = null;
|
||||
if (null != nameWithSet.right) // set explicitly requested, should return card from it and disregard the date
|
||||
if (null != nameWithSet.right) // set explicitly requested, should return card from it and disregard the date
|
||||
res = tryGetCard(nameWithSet.left, nameWithSet.right);
|
||||
else {
|
||||
Collection<PaperCard> cards = this.allCardsByName.get(nameWithSet.left); // cards are sorted by datetime desc
|
||||
@@ -196,13 +194,12 @@ public final class CardDb implements ICardDatabase {
|
||||
|
||||
return null != res && isFoil ? getFoiled(res) : res;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PaperCard tryGetCard(final String cardName, String setName) {
|
||||
return tryGetCard(cardName, setName, -1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PaperCard tryGetCard(final String cardName0, String setName, int index) {
|
||||
final boolean isFoil = this.isFoil(cardName0);
|
||||
@@ -212,7 +209,7 @@ public final class CardDb implements ICardDatabase {
|
||||
if ( null == cards ) return null;
|
||||
|
||||
CardEdition edition = editions.get(setName);
|
||||
if ( null == edition )
|
||||
if ( null == edition )
|
||||
return tryGetCard(cardName, true); // set not found, try to get the same card from just any set.
|
||||
String effectiveSet = edition.getCode();
|
||||
|
||||
@@ -227,7 +224,7 @@ public final class CardDb implements ICardDatabase {
|
||||
|
||||
if (cnt == 0 ) return null;
|
||||
result = cnt == 1 ? candidates[0] : candidates[MyRandom.getRandom().nextInt(cnt)];
|
||||
} else
|
||||
} else
|
||||
for( PaperCard pc : cards ) {
|
||||
if( pc.getEdition().equalsIgnoreCase(effectiveSet) && index == pc.getArtIndex() ) {
|
||||
result = pc;
|
||||
@@ -237,7 +234,7 @@ public final class CardDb implements ICardDatabase {
|
||||
if ( result == null ) return null;
|
||||
return isFoil ? getFoiled(result) : result;
|
||||
}
|
||||
|
||||
|
||||
public PaperCard getFoiled(PaperCard card0) {
|
||||
// Here - I am still unsure if there should be a cache Card->Card from unfoiled to foiled, to avoid creation of N instances of single plains
|
||||
return new PaperCard(card0.getRules(), card0.getEdition(), card0.getRarity(), card0.getArtIndex(), true);
|
||||
@@ -252,17 +249,17 @@ public final class CardDb implements ICardDatabase {
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMaxPrintCount(String cardName) {
|
||||
int max = -1;
|
||||
for( PaperCard pc : allCardsByName.get(cardName) ) {
|
||||
if ( max < pc.getArtIndex() )
|
||||
if ( max < pc.getArtIndex() )
|
||||
max = pc.getArtIndex();
|
||||
}
|
||||
return max + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Single fetch
|
||||
@Override
|
||||
public PaperCard getCard(final String name) {
|
||||
@@ -279,8 +276,7 @@ public final class CardDb implements ICardDatabase {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public PaperCard getCardPrintedByDate(final String name0, final boolean fromLatestSet, Date printedBefore ) {
|
||||
// Sometimes they read from decks things like "CardName|Set" - but we
|
||||
@@ -290,8 +286,8 @@ public final class CardDb implements ICardDatabase {
|
||||
throw new NoSuchElementException(String.format("Card '%s' released before %s not found in our database.", name0, printedBefore.toString()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Advanced fetch by name+set
|
||||
@Override
|
||||
public PaperCard getCard(final String name, final String set) {
|
||||
@@ -300,7 +296,6 @@ public final class CardDb implements ICardDatabase {
|
||||
|
||||
@Override
|
||||
public PaperCard getCard(final String name, final String set, final int artIndex) {
|
||||
|
||||
final PaperCard result = tryGetCard(name, set, artIndex);
|
||||
if (null == result) {
|
||||
final String message = String.format("Asked for '%s' from '%s' #%d: db didn't find that copy.", name, set, artIndex);
|
||||
@@ -329,7 +324,7 @@ public final class CardDb implements ICardDatabase {
|
||||
public Predicate<? super PaperCard> wasPrintedInSets(List<String> setCodes) {
|
||||
return new PredicateExistsInSets(setCodes);
|
||||
}
|
||||
|
||||
|
||||
private class PredicateExistsInSets implements Predicate<PaperCard> {
|
||||
private final List<String> sets;
|
||||
|
||||
@@ -340,20 +335,20 @@ public final class CardDb implements ICardDatabase {
|
||||
@Override
|
||||
public boolean apply(final PaperCard subject) {
|
||||
Collection<PaperCard> cc = allCardsByName.get(subject.getName());
|
||||
for(PaperCard c : cc)
|
||||
if (sets.contains(c.getEdition()))
|
||||
for(PaperCard c : cc)
|
||||
if (sets.contains(c.getEdition()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final Editor editor = new Editor();
|
||||
public Editor getEditor() { return editor; }
|
||||
public class Editor {
|
||||
private boolean immediateReindex = true;
|
||||
public CardRules putCard(CardRules rules) { return putCard(rules, null); /* will use data from editions folder */ }
|
||||
public CardRules putCard(CardRules rules, List<Pair<String, CardRarity>> whenItWasPrinted){ // works similarly to Map<K,V>, returning prev. value
|
||||
String cardName = rules.getName();
|
||||
String cardName = rules.getName();
|
||||
CardRules result = rulesByName.put(cardName, rules);
|
||||
// 1. generate all paper cards from edition data we have (either explicit, or found in res/editions, or add to unknown edition)
|
||||
List<PaperCard> paperCards = new ArrayList<PaperCard>();
|
||||
@@ -389,7 +384,7 @@ public final class CardDb implements ICardDatabase {
|
||||
// 3. reindex can be temporary disabled and run after the whole batch of rules is added to db.
|
||||
if(immediateReindex)
|
||||
reIndex();
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
public void removeCard(String name) {
|
||||
@@ -404,7 +399,7 @@ public final class CardDb implements ICardDatabase {
|
||||
}
|
||||
}
|
||||
public void rebuildIndex() { reIndex(); }
|
||||
|
||||
|
||||
public boolean isImmediateReindex() {
|
||||
return immediateReindex;
|
||||
}
|
||||
@@ -412,5 +407,4 @@ public final class CardDb implements ICardDatabase {
|
||||
this.immediateReindex = immediateReindex;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
//private final Map<String, CardInSet> setsPrinted = new TreeMap<String, CardInSet>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
private CardAiHints aiHints;
|
||||
|
||||
|
||||
private ColorSet colorIdentity = null;
|
||||
|
||||
private CardRules(ICardFace[] faces, CardSplitType altMode, CardAiHints cah) {
|
||||
@@ -48,29 +48,29 @@ public final class CardRules implements ICardCharacteristics {
|
||||
mainPart = faces[0];
|
||||
otherPart = faces[1];
|
||||
aiHints = cah;
|
||||
|
||||
|
||||
//System.out.print(faces[0].getName());
|
||||
|
||||
|
||||
// for (Entry<String, CardInSet> cs : sets.entrySet()) {
|
||||
// if( CardRulesReader.editions.get(cs.getKey()) != null )
|
||||
// setsPrinted.put(cs.getKey(), cs.getValue());
|
||||
// }
|
||||
//
|
||||
// if ( setsPrinted.isEmpty() ) {
|
||||
// System.err.println(getName() + " was not assigned any set.");
|
||||
// if ( setsPrinted.isEmpty() ) {
|
||||
// System.err.println(getName() + " was not assigned any set.");
|
||||
// setsPrinted.put(CardEdition.UNKNOWN.getCode(), new CardInSet(CardRarity.Common, 1) );
|
||||
// }
|
||||
//
|
||||
//
|
||||
//Calculate Color Identity
|
||||
byte colMask = calculateColorIdentity(mainPart);
|
||||
|
||||
|
||||
if(otherPart != null)
|
||||
{
|
||||
colMask |= calculateColorIdentity(otherPart);
|
||||
}
|
||||
}
|
||||
colorIdentity = ColorSet.fromMask(colMask);
|
||||
}
|
||||
|
||||
|
||||
private byte calculateColorIdentity(ICardFace face)
|
||||
{
|
||||
byte res = face.getColor().getColor();
|
||||
@@ -156,7 +156,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
public ColorSet getColor() {
|
||||
switch(splitType.getAggregationMethod()) {
|
||||
case COMBINE:
|
||||
return ColorSet.fromMask(mainPart.getColor().getColor() | otherPart.getColor().getColor());
|
||||
return ColorSet.fromMask(mainPart.getColor().getColor() | otherPart.getColor().getColor());
|
||||
default:
|
||||
return mainPart.getColor();
|
||||
}
|
||||
@@ -172,7 +172,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
public String getOracleText() {
|
||||
switch(splitType.getAggregationMethod()) {
|
||||
case COMBINE:
|
||||
return mainPart.getOracleText() + "\r\n\r\n" + otherPart.getOracleText();
|
||||
return mainPart.getOracleText() + "\r\n\r\n" + otherPart.getOracleText();
|
||||
default:
|
||||
return mainPart.getOracleText();
|
||||
}
|
||||
@@ -220,12 +220,11 @@ public final class CardRules implements ICardCharacteristics {
|
||||
public final List<String> getAbilities() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public ColorSet getColorIdentity() {
|
||||
return colorIdentity;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** Instantiates class, reads a card. For batch operations better create you own reader instance. */
|
||||
public static CardRules fromScript(Iterable<String> script) {
|
||||
Reader crr = new Reader();
|
||||
@@ -233,24 +232,23 @@ public final class CardRules implements ICardCharacteristics {
|
||||
crr.parseLine(line);
|
||||
}
|
||||
return crr.getCard();
|
||||
}
|
||||
}
|
||||
|
||||
// Reads cardname.txt
|
||||
public static class Reader {
|
||||
// fields to build
|
||||
// fields to build
|
||||
private CardFace[] faces = new CardFace[] { null, null };
|
||||
private String[] pictureUrl = new String[] { null, null };
|
||||
private int curFace = 0;
|
||||
private CardSplitType altMode = CardSplitType.None;
|
||||
private String handLife = null;
|
||||
|
||||
private String handLife = null;
|
||||
|
||||
// fields to build CardAiHints
|
||||
private boolean removedFromAIDecks = false;
|
||||
private boolean removedFromRandomDecks = false;
|
||||
private DeckHints hints = null;
|
||||
private DeckHints needs = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reset all fields to parse next card (to avoid allocating new CardRulesReader N times)
|
||||
*/
|
||||
@@ -260,16 +258,16 @@ public final class CardRules implements ICardCharacteristics {
|
||||
this.faces[1] = null;
|
||||
this.pictureUrl[0] = null;
|
||||
this.pictureUrl[1] = null;
|
||||
|
||||
|
||||
this.handLife = null;
|
||||
this.altMode = CardSplitType.None;
|
||||
|
||||
|
||||
this.removedFromAIDecks = false;
|
||||
this.removedFromRandomDecks = false;
|
||||
this.needs = null;
|
||||
this.hints = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the card.
|
||||
*
|
||||
@@ -285,7 +283,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
result.setVanguardProperties(handLife);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public final CardRules readCard(final Iterable<String> script) {
|
||||
this.reset();
|
||||
for (String line : script) {
|
||||
@@ -296,8 +294,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
}
|
||||
return this.getCard();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parses the line.
|
||||
*
|
||||
@@ -308,7 +305,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
int colonPos = line.indexOf(':');
|
||||
String key = colonPos > 0 ? line.substring(0, colonPos) : line;
|
||||
String value = colonPos > 0 ? line.substring(1+colonPos).trim() : null;
|
||||
|
||||
|
||||
switch(key.charAt(0)) {
|
||||
case 'A':
|
||||
if ("A".equals(key))
|
||||
@@ -320,7 +317,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
this.curFace = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'C':
|
||||
if ("Colors".equals(key)) {
|
||||
// This is forge.card.CardColor not forge.CardColor.
|
||||
@@ -329,7 +326,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
this.faces[this.curFace].setColor(newCol);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'D':
|
||||
if ("DeckHints".equals(key)) {
|
||||
hints = new DeckHints(value);
|
||||
@@ -337,67 +334,66 @@ public final class CardRules implements ICardCharacteristics {
|
||||
needs = new DeckHints(value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'H':
|
||||
if ("HandLifeModifier".equals(key)) {
|
||||
handLife = value;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'K':
|
||||
if ("K".equals(key)) {
|
||||
this.faces[this.curFace].addKeyword(value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'L':
|
||||
if ("Loyalty".equals(key)) {
|
||||
this.faces[this.curFace].setInitialLoyalty(Integer.valueOf(value));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'M':
|
||||
if ("ManaCost".equals(key)) {
|
||||
this.faces[this.curFace].setManaCost("no cost".equals(value) ? ManaCost.NO_COST
|
||||
this.faces[this.curFace].setManaCost("no cost".equals(value) ? ManaCost.NO_COST
|
||||
: new ManaCost(new ManaCostParser(value)));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'N':
|
||||
if ("Name".equals(key)) {
|
||||
this.faces[this.curFace] = new CardFace(value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'O':
|
||||
if ("Oracle".equals(key)) {
|
||||
this.faces[this.curFace].setOracleText(value);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'P':
|
||||
if ("PT".equals(key)) {
|
||||
this.faces[this.curFace].setPtText(value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'R':
|
||||
if ("R".equals(key)) {
|
||||
this.faces[this.curFace].addReplacementEffect(value);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'S':
|
||||
if ("S".equals(key)) {
|
||||
this.faces[this.curFace].addStaticAbility(value);
|
||||
} else if ( "SVar".equals(key) ) {
|
||||
if ( null == value ) throw new IllegalArgumentException("SVar has no variable name");
|
||||
|
||||
|
||||
colonPos = value.indexOf(':');
|
||||
String variable = colonPos > 0 ? value.substring(0, colonPos) : value;
|
||||
value = colonPos > 0 ? value.substring(1+colonPos) : null;
|
||||
|
||||
|
||||
if ( "RemAIDeck".equals(variable) ) {
|
||||
this.removedFromAIDecks = "True".equalsIgnoreCase(value);
|
||||
} else if ( "RemRandomDeck".equals(variable) ) {
|
||||
@@ -412,7 +408,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
// deprecated
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'T':
|
||||
if ("T".equals(key)) {
|
||||
this.faces[this.curFace].addTrigger(value);
|
||||
@@ -423,21 +419,20 @@ public final class CardRules implements ICardCharacteristics {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class ParserCardnameTxtManaCost.
|
||||
*/
|
||||
private static class ManaCostParser implements IParserManaCost {
|
||||
private final StringTokenizer st;
|
||||
private final StringTokenizer st;
|
||||
private int colorlessCost;
|
||||
|
||||
|
||||
public ManaCostParser(final String cost) {
|
||||
st = new StringTokenizer(cost, " ");
|
||||
this.colorlessCost = 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final int getTotalColorlessCost() {
|
||||
if (this.hasNext()) {
|
||||
@@ -445,7 +440,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
}
|
||||
return this.colorlessCost;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
@@ -455,7 +450,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
public final boolean hasNext() {
|
||||
return st.hasMoreTokens();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
@@ -463,7 +458,6 @@ public final class CardRules implements ICardCharacteristics {
|
||||
*/
|
||||
@Override
|
||||
public final ManaCostShard next() {
|
||||
|
||||
final String unparsed = st.nextToken();
|
||||
// System.out.println(unparsed);
|
||||
try {
|
||||
@@ -472,10 +466,10 @@ public final class CardRules implements ICardCharacteristics {
|
||||
return null;
|
||||
}
|
||||
catch (NumberFormatException nex) { }
|
||||
|
||||
|
||||
return ManaCostShard.parseNonGeneric(unparsed);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getEdition() {
|
||||
return this.edition;
|
||||
@@ -80,15 +80,11 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
return this.rarity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// @Override
|
||||
// public String getImageKey() {
|
||||
// return getImageLocator(getImageName(), getArtIndex(), true, false);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getItemType() {
|
||||
return "Card";
|
||||
@@ -108,12 +104,12 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
public String apply(final PaperCard from) {
|
||||
return from.getName();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
public PaperCard(final CardRules c, final String edition0, final CardRarity rare, final int index) {
|
||||
this(c, edition0, rare, index, false);
|
||||
}
|
||||
|
||||
|
||||
public PaperCard(final CardRules c, final String edition0, final CardRarity rare, final int index, final boolean foil) {
|
||||
if ( edition0 == null || c == null || rare == null )
|
||||
throw new IllegalArgumentException("Cannot create card without rules, edition or rarity");
|
||||
@@ -178,7 +174,6 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
|
||||
// return String.format("%s|%s", name, cardSet);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user