mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
carddb and manaparser less related to mtg-data.txt and support alternative sources of data.
This commit is contained in:
@@ -2,6 +2,7 @@ package forge.card;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -10,16 +11,13 @@ import java.util.Map.Entry;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Card;
|
||||
import forge.FileUtil;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
|
||||
/**
|
||||
* <p>CardOracleDatabase class.</p>
|
||||
* <p>CardDb class.</p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: CardOracleDatabase.java 9708 2011-08-09 19:34:12Z jendave $
|
||||
* @version $Id: CardDb.java 9708 2011-08-09 19:34:12Z jendave $
|
||||
*/
|
||||
public final class CardDb {
|
||||
private static volatile CardDb onlyInstance = null; // 'volatile' keyword makes this working
|
||||
@@ -46,8 +44,10 @@ public final class CardDb {
|
||||
|
||||
|
||||
private CardDb() {
|
||||
List<String> mtgDataLines = FileUtil.readFile(ForgeProps.getFile(NewConstants.MTG_DATA));
|
||||
MtgDataParser parser = new MtgDataParser(mtgDataLines);
|
||||
this(new MtgDataParser()); // I wish cardname.txt parser was be here.
|
||||
}
|
||||
|
||||
private CardDb(final Iterator<CardRules> parser) {
|
||||
while (parser.hasNext()) {
|
||||
addNewCard(parser.next());
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
/**
|
||||
* <p>CardManaCost class.</p>
|
||||
*
|
||||
@@ -15,7 +13,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
* @version $Id: CardManaCost.java 9708 2011-08-09 19:34:12Z jendave $
|
||||
*/
|
||||
|
||||
|
||||
public final class CardManaCost implements Comparable<CardManaCost> {
|
||||
private final List<CardManaCostShard> shards = new ArrayList<CardManaCostShard>();
|
||||
private final int genericCost;
|
||||
@@ -35,7 +32,10 @@ public final class CardManaCost implements Comparable<CardManaCost> {
|
||||
public static final CardManaCost empty = new CardManaCost();
|
||||
|
||||
public CardManaCost(final String cost) {
|
||||
ParserMtgData parser = new ParserMtgData(cost);
|
||||
this(new ParserMtgData(cost));
|
||||
}
|
||||
|
||||
public CardManaCost(final ManaParser parser) {
|
||||
if (!parser.hasNext()) {
|
||||
throw new RuntimeException("Empty manacost passed to parser (this should have been handled before)");
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public final class CardManaCost implements Comparable<CardManaCost> {
|
||||
CardManaCostShard shard = parser.next();
|
||||
if (shard != null) { shards.add(shard); } // null is OK - that was generic mana
|
||||
}
|
||||
genericCost = parser.getColorlessCost(); // collect generic mana here
|
||||
genericCost = parser.getTotalColorlessCost(); // collect generic mana here
|
||||
stringValue = getSimpleString();
|
||||
}
|
||||
|
||||
@@ -93,7 +93,12 @@ public final class CardManaCost implements Comparable<CardManaCost> {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
public class ParserMtgData implements Iterator<CardManaCostShard> {
|
||||
public interface ManaParser extends Iterator<CardManaCostShard>
|
||||
{
|
||||
int getTotalColorlessCost();
|
||||
}
|
||||
|
||||
public static class ParserMtgData implements ManaParser {
|
||||
private final String cost;
|
||||
|
||||
private int nextBracket;
|
||||
@@ -107,7 +112,7 @@ public final class CardManaCost implements Comparable<CardManaCost> {
|
||||
colorlessCost = 0;
|
||||
}
|
||||
|
||||
public int getColorlessCost() {
|
||||
public int getTotalColorlessCost() {
|
||||
if ( hasNext() ) {
|
||||
throw new RuntimeException("Colorless cost should be obtained after iteration is complete");
|
||||
}
|
||||
|
||||
@@ -6,11 +6,17 @@ import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.FileUtil;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
public final class MtgDataParser implements Iterator<CardRules> {
|
||||
|
||||
private Iterator<String> it;
|
||||
public MtgDataParser(final Iterable<String> data) {
|
||||
it = data.iterator();
|
||||
private final List<String> mtgDataLines;
|
||||
public MtgDataParser() {
|
||||
mtgDataLines = FileUtil.readFile(ForgeProps.getFile(NewConstants.MTG_DATA));
|
||||
it = mtgDataLines.iterator();
|
||||
skipSetList();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user