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

View File

@@ -125,8 +125,8 @@ public class QuestDataIO {
break;
case 1:
// card names are stored as plain text - need to read them from there
break;
default:
break;
}
@@ -223,10 +223,16 @@ public class QuestDataIO {
CardPool result = new CardPool();
while (reader.hasMoreChildren()) {
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);
String sCnt = reader.getAttribute("n");
int cnt = StringUtils.isNumeric(sCnt) ? Integer.parseInt(sCnt) : 1;
result.add(cp, cnt);
}
reader.moveUp();
}
return result;

View File

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