New format for SetInfo lines, to convert card scripts either run 'assignSetInfo.py' or wait for upcoming cardfolder commits

This commit is contained in:
Maxmtg
2013-03-04 13:55:21 +00:00
parent 89617bf760
commit bcf5a007ae
2 changed files with 31 additions and 32 deletions

View File

@@ -19,6 +19,7 @@ package forge.card;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
@@ -32,7 +33,8 @@ import forge.card.mana.ManaCost;
* @version $Id: CardRules.java 9708 2011-08-09 19:34:12Z jendave $
*/
public final class CardRules implements ICardCharacteristics {
private final static EditionCollection editions = new EditionCollection(); // create a copy here, Singletons.model... is not initialized yet.
private final CardSplitType splitType;
private final ICardFace mainPart;
private final ICardFace otherPart;
@@ -48,8 +50,14 @@ public final class CardRules implements ICardCharacteristics {
mainPart = faces[0];
otherPart = faces[1];
aiHints = cah;
setsPrinted.putAll(sets);
//System.out.print(faces[0].getName());
for (Entry<String, CardInSet> cs : sets.entrySet()) {
if( editions.get(cs.getKey()) != null )
setsPrinted.put(cs.getKey(), cs.getValue());
}
if ( setsPrinted.isEmpty() ) {
System.err.println(getName() + " was not assigned any set.");
setsPrinted.put(CardEdition.UNKNOWN.getCode(), new CardInSet(CardRarity.Common, 1) );

View File

@@ -221,8 +221,7 @@ public class CardRulesReader {
} else
this.faces[curFace].addSVar(variable, value);
} else if ("SetInfo".equals(key)) {
if ( curFace == 0 )
CardRulesReader.parseSetInfoLine(value, sets);
parseSetInfoLine(value);
}
break;
@@ -247,41 +246,33 @@ public class CardRulesReader {
* @param setsData
* the current mapping of set names to CardInSet instances
*/
private static void parseSetInfoLine(final String value, final Map<String, CardInSet> setsData) {
final int setCodeIx = 0;
final int rarityIx = 1;
final int numPicIx = 3;
private void parseSetInfoLine(final String value) {
// Sample SetInfo line:
// SetInfo:POR|Land|http://magiccards.info/scans/en/po/203.jpg|4
// SetInfo:POR Land x4
final String[] pieces = value.split("\\|");
if (pieces.length <= rarityIx) {
throw new RuntimeException("SetInfo line <<" + value + ">> has insufficient pieces");
int i = 0;
String setCode = null;
String txtRarity = "Common";
String txtCount = "x1";
StringTokenizer stt = new StringTokenizer(value, " ");
while(stt.hasMoreTokens()) {
if( i == 0 ) setCode = stt.nextToken();
if( i == 1 ) txtRarity = stt.nextToken();
if( i == 2 ) txtCount = stt.nextToken();
i++;
}
final String setCode = pieces[setCodeIx];
final String txtRarity = pieces[rarityIx];
// pieces[2] is the magiccards.info URL for illustration #1, which we do
// not need.
int numIllustrations = 1;
if (setsData.containsKey(setCode)) {
int numIllustrations = 1;
if ( i > 2 )
numIllustrations = Integer.parseInt(txtCount.substring(1));
if (sets.containsKey(setCode)) {
System.err.print(faces[0].getName());
throw new RuntimeException("Found multiple SetInfo lines for set code <<" + setCode + ">>");
}
if (pieces.length > numPicIx) {
try {
numIllustrations = Integer.parseInt(pieces[numPicIx]);
} catch (final NumberFormatException nfe) {
throw new RuntimeException("Fourth item of SetInfo is not an integer in <<" + value + ">>");
}
if (numIllustrations < 1) {
throw new RuntimeException("Fourth item of SetInfo is not a positive integer, but" + numIllustrations);
}
}
CardRarity rarity = null;
if ("Land".equals(txtRarity)) {
@@ -302,7 +293,7 @@ public class CardRulesReader {
final CardInSet cardInSet = new CardInSet(rarity, numIllustrations);
setsData.put(setCode, cardInSet);
sets.put(setCode, cardInSet);
}
/**