added support for older format of quest saves (a method for deserialization of CardPool)

since color names are lowercases, I used constants from forge for their names.
This commit is contained in:
Maxmtg
2011-09-02 09:34:31 +00:00
parent 030998fe18
commit 67cf33d550
3 changed files with 24 additions and 17 deletions

View File

@@ -1,5 +1,7 @@
package forge.card; package forge.card;
import forge.Constant;
/** /**
* <p>CardColor class.</p> * <p>CardColor class.</p>
* *
@@ -36,9 +38,7 @@ public final class CardColor implements Comparable<CardColor> {
public boolean isEqual(final byte color) { return color == myColor; } public boolean isEqual(final byte color) { return color == myColor; }
@Override @Override
public int compareTo(final CardColor other) { public int compareTo(final CardColor other) { return orderWeight - other.orderWeight; }
return orderWeight - other.orderWeight;
}
// Presets // Presets
public boolean hasWhite() { return hasAnyColor(WHITE); } public boolean hasWhite() { return hasAnyColor(WHITE); }
@@ -56,12 +56,12 @@ public final class CardColor implements Comparable<CardColor> {
@Override @Override
public String toString() { public String toString() {
switch (myColor) { switch (myColor) {
case 0: return "colorless"; case 0: return Constant.Color.Colorless;
case WHITE: return "white"; // Constant.Color.White; case WHITE: return Constant.Color.White;
case BLUE: return "blue"; // Constant.Color.Blue; case BLUE: return Constant.Color.Blue;
case BLACK: return "black"; // Constant.Color.Black; case BLACK: return Constant.Color.Black;
case RED: return "red"; // Constant.Color.Red; case RED: return Constant.Color.Red;
case GREEN: return "green"; // Constant.Color.Green; case GREEN: return Constant.Color.Green;
default: return "multi"; default: return "multi";
} }
} }

View File

@@ -125,8 +125,8 @@ public class QuestDataIO {
break; break;
case 1: case 1:
// card names are stored as plain text - need to read them from there break;
default:
break; break;
} }
@@ -223,10 +223,16 @@ public class QuestDataIO {
CardPool result = new CardPool(); CardPool result = new CardPool();
while (reader.hasMoreChildren()) { while (reader.hasMoreChildren()) {
reader.moveDown(); reader.moveDown();
String nodename = reader.getNodeName();
if("string".equals(nodename)) {
CardPrinted cp = CardDb.instance().getCard(reader.getValue());
result.add(cp);
} else { // new format
CardPrinted cp = readCardPrinted(reader); CardPrinted cp = readCardPrinted(reader);
String sCnt = reader.getAttribute("n"); String sCnt = reader.getAttribute("n");
int cnt = StringUtils.isNumeric(sCnt) ? Integer.parseInt(sCnt) : 1; int cnt = StringUtils.isNumeric(sCnt) ? Integer.parseInt(sCnt) : 1;
result.add(cp, cnt); result.add(cp, cnt);
}
reader.moveUp(); reader.moveUp();
} }
return result; return result;

View File

@@ -14,6 +14,7 @@ import forge.quest.data.bazaar.QuestStallPurchasable;
public abstract class QuestPetAbstract implements QuestStallPurchasable { public abstract class QuestPetAbstract implements QuestStallPurchasable {
int level; int level;
private int maxLevel; private int maxLevel;
// transient here ?
private String name; private String name;
private String description; private String description;