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 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 MagicStack Stack = new MagicStack();

View File

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

View File

@@ -2,6 +2,7 @@ package forge;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
@@ -12,6 +13,7 @@ import forge.properties.NewConstants;
public class ReadCard implements Runnable, NewConstants {
private BufferedReader in;
private String fileList[];
private ArrayList<Card> allCards = new ArrayList<Card>();
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 "
+ 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
try {
in = new BufferedReader(new FileReader(file));
} catch(Exception ex) {
ErrorViewer.showError(ex, "File \"%s\" not found", file.getAbsolutePath());
throw new RuntimeException("ReadCard : constructor error -- file not found -- filename is "
+ file.getPath());
}
//try {
// in = new BufferedReader(new FileReader(file));
//} catch(Exception ex) {
// ErrorViewer.showError(ex, "File \"%s\" not found", file.getAbsolutePath());
// throw new RuntimeException("ReadCard : constructor error -- file not found -- filename is "
// + file.getPath());
//}
}//ReadCard()
public void run() {
Card c;
String s = readLine();
ArrayList<String> cardNames = new ArrayList<String>();
int linenum = 1;
while(!s.equals("End")) {
Card c = null;
ArrayList<String> cardNames = new ArrayList<String>();
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());
}
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
//System.out.println(c.getName());
String s = readLine();
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);
}
else if (s.startsWith("Types:"))
addTypes(c, s.substring(6));
else if (s.startsWith("Text:"))
{
String t = s.substring(5);
if (!t.equals("no text"));
c.setText(t);
}
else if (s.startsWith("PT:"))
{
String t = s.substring(3);
String pt[] = t.split("/");
int att = Integer.parseInt(pt[0]);
int def = Integer.parseInt(pt[1]);
c.setBaseAttack(att);
c.setBaseDefense(def);
}
else if (s.startsWith("K:"))
{
String t = s.substring(2);
c.addIntrinsicKeyword(t);
}
s = readLine();
} // while !End
s = readLine();
if(!s.equals("no cost")) c.setManaCost(s);
s = readLine();
addTypes(c, s);
s = readLine();
if(!s.equals("no text")) c.setText(s);
s = readLine();
if(c.isCreature()) {
//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.setBaseDefense(def);
s = readLine();
linenum++;
}
while(!s.equals("")) {
c.addIntrinsicKeyword(s);
s = readLine();
linenum++;
}
s = readLine();
linenum++;
if(cardNames.contains(c.getName())) {
System.out.println("ReadCard:run() error - duplicate card name: " + c.getName());
throw new RuntimeException("ReadCard:run() error - duplicate card name: " + c.getName());
}
cardNames.add(c.getName());
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()
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_TOKEN_HQ = "card-pictures_token_hq";
public static final String CARDS = "cards";
public static final String CARDSFOLDER = "cardsfolder";
public static final String REMOVED = "removed-cards";
public static final String NAME_MUTATOR = "name-mutator";