No more cards.txt - now a card-per-file under /res/cardsfolder/

This commit is contained in:
jendave
2011-08-06 06:16:16 +00:00
parent 5bc8d5bb6a
commit 658b8a0381
4 changed files with 97 additions and 57 deletions

View File

@@ -19,7 +19,8 @@ public class AllZone implements NewConstants {
public static EndOfTurn EndOfTurn = new EndOfTurn(); public static EndOfTurn EndOfTurn = new EndOfTurn();
public static EndOfCombat EndOfCombat = new EndOfCombat(); public static EndOfCombat EndOfCombat = new EndOfCombat();
public static final CardFactory CardFactory = new CardFactory(ForgeProps.getFile(CARDS)); //public static final CardFactory CardFactory = new CardFactory(ForgeProps.getFile(CARDS));
public static final CardFactory CardFactory = new CardFactory(ForgeProps.getFile(CARDSFOLDER));
public static final Phase Phase = new Phase(); public static final Phase Phase = new Phase();
public static final MagicStack Stack = new MagicStack(); public static final MagicStack Stack = new MagicStack();

View File

@@ -86,7 +86,8 @@ public class CardFactory implements NewConstants {
private void readCards(File file) { private void readCards(File file) {
map.clear(); map.clear();
ReadCard read = new ReadCard(ForgeProps.getFile(CARDS)); //ReadCard read = new ReadCard(ForgeProps.getFile(CARDS));
ReadCard read = new ReadCard(ForgeProps.getFile(CARDSFOLDER));
try { try {
read.run(); read.run();
// javax.swing.SwingUtilities.invokeAndWait(read); // javax.swing.SwingUtilities.invokeAndWait(read);
@@ -2947,6 +2948,7 @@ public class CardFactory implements NewConstants {
} }
} // etbDestoryTgt } // etbDestoryTgt
// Generic destroy all card // Generic destroy all card
if(hasKeyword(card, "spDestroyAll") != -1) { if(hasKeyword(card, "spDestroyAll") != -1) {
int n = hasKeyword(card, "spDestroyAll"); int n = hasKeyword(card, "spDestroyAll");

View File

@@ -2,6 +2,7 @@ package forge;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@@ -12,6 +13,7 @@ import forge.properties.NewConstants;
public class ReadCard implements Runnable, NewConstants { public class ReadCard implements Runnable, NewConstants {
private BufferedReader in; private BufferedReader in;
private String fileList[];
private ArrayList<Card> allCards = new ArrayList<Card>(); private ArrayList<Card> allCards = new ArrayList<Card>();
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Exception {
@@ -50,70 +52,104 @@ public class ReadCard implements Runnable, NewConstants {
throw new RuntimeException("ReadCard : constructor error -- file not found -- filename is " throw new RuntimeException("ReadCard : constructor error -- file not found -- filename is "
+ file.getAbsolutePath()); + file.getAbsolutePath());
if (!file.isDirectory())
throw new RuntimeException("ReadCard : constructor error -- not a direcotry -- "
+ file.getAbsolutePath());
fileList = file.list();
//makes the checked exception, into an unchecked runtime exception //makes the checked exception, into an unchecked runtime exception
try { //try {
in = new BufferedReader(new FileReader(file)); // in = new BufferedReader(new FileReader(file));
} catch(Exception ex) { //} catch(Exception ex) {
ErrorViewer.showError(ex, "File \"%s\" not found", file.getAbsolutePath()); // ErrorViewer.showError(ex, "File \"%s\" not found", file.getAbsolutePath());
throw new RuntimeException("ReadCard : constructor error -- file not found -- filename is " // throw new RuntimeException("ReadCard : constructor error -- file not found -- filename is "
+ file.getPath()); // + file.getPath());
} //}
}//ReadCard() }//ReadCard()
public void run() { public void run() {
Card c; Card c = null;
String s = readLine();
ArrayList<String> cardNames = new ArrayList<String>(); ArrayList<String> cardNames = new ArrayList<String>();
int linenum = 1; File fl = null;
for (int i=0; i<fileList.length; i++)
{
try {
fl = new File("res/cardsfolder/" + fileList[i]);
in = new BufferedReader(new FileReader(fl));
} catch(Exception ex) {
ErrorViewer.showError(ex, "File \"%s\" exception", fl.getAbsolutePath());
throw new RuntimeException("ReadCard : run error -- file exception -- filename is "
+ fl.getPath());
}
while(!s.equals("End")) {
c = new Card(); c = new Card();
if(s.equals("")) throw new RuntimeException("ReadCard : run() reading error, cardname is blank! Line: " + Integer.toString(linenum));
linenum += 4;
c.setName(s);
//for debugging String s = readLine();
//System.out.println(c.getName()); while (!s.equals("End"))
{
if (s.startsWith("Name:"))
{
String t = s.substring(5);
//System.out.println(s);
if (cardNames.contains(t))
{
System.out.println("ReadCard:run() error - duplicate card name: " + t);
throw new RuntimeException("ReadCard:run() error - duplicate card name: " + t);
}
else
c.setName(t);
}
else if (s.startsWith("ManaCost:"))
{
String t = s.substring(9);
//System.out.println(s);
if (!t.equals("no cost"))
c.setManaCost(t);
}
s = readLine(); else if (s.startsWith("Types:"))
if(!s.equals("no cost")) c.setManaCost(s); addTypes(c, s.substring(6));
s = readLine(); else if (s.startsWith("Text:"))
addTypes(c, s); {
String t = s.substring(5);
if (!t.equals("no text"));
c.setText(t);
}
s = readLine(); else if (s.startsWith("PT:"))
if(!s.equals("no text")) c.setText(s); {
String t = s.substring(3);
s = readLine(); String pt[] = t.split("/");
if(c.isCreature()) { int att = Integer.parseInt(pt[0]);
int def = Integer.parseInt(pt[1]);
//System.out.println("Creature name:" + c.getName());
int n = s.indexOf("/");
int att = Integer.parseInt(s.substring(0, n));
int def = Integer.parseInt(s.substring(n + 1));
c.setBaseAttack(att); c.setBaseAttack(att);
c.setBaseDefense(def); c.setBaseDefense(def);
s = readLine();
linenum++;
} }
while(!s.equals("")) { else if (s.startsWith("K:"))
c.addIntrinsicKeyword(s); {
s = readLine(); String t = s.substring(2);
linenum++; c.addIntrinsicKeyword(t);
} }
s = readLine();
linenum++;
if(cardNames.contains(c.getName())) { s = readLine();
System.out.println("ReadCard:run() error - duplicate card name: " + c.getName()); } // while !End
throw new RuntimeException("ReadCard:run() error - duplicate card name: " + c.getName());
}
cardNames.add(c.getName()); cardNames.add(c.getName());
allCards.add(c); allCards.add(c);
try {
in.close();
} catch (IOException ex) {
ErrorViewer.showError(ex, "File \"%s\" exception", fl.getAbsolutePath());
throw new RuntimeException("ReadCard : run error -- file exception -- filename is "
+ fl.getPath());
} }
}
}//run() }//run()
private void addTypes(Card c, String types) { private void addTypes(Card c, String types) {

View File

@@ -57,6 +57,7 @@ public interface NewConstants {
public static final String CARD_PICTURES_OTHER = "card-pictures_other"; public static final String CARD_PICTURES_OTHER = "card-pictures_other";
public static final String CARD_PICTURES_TOKEN_HQ = "card-pictures_token_hq"; public static final String CARD_PICTURES_TOKEN_HQ = "card-pictures_token_hq";
public static final String CARDS = "cards"; public static final String CARDS = "cards";
public static final String CARDSFOLDER = "cardsfolder";
public static final String REMOVED = "removed-cards"; public static final String REMOVED = "removed-cards";
public static final String NAME_MUTATOR = "name-mutator"; public static final String NAME_MUTATOR = "name-mutator";