mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Fix so conquest can load
This commit is contained in:
@@ -4,17 +4,20 @@ import forge.deck.Deck;
|
|||||||
import forge.deck.generation.DeckGenPool;
|
import forge.deck.generation.DeckGenPool;
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
|
import forge.model.FModel;
|
||||||
import forge.planarconquest.ConquestPlane.Region;
|
import forge.planarconquest.ConquestPlane.Region;
|
||||||
|
import forge.util.XmlReader;
|
||||||
import forge.util.XmlWriter;
|
import forge.util.XmlWriter;
|
||||||
import forge.util.XmlWriter.IXmlWritable;
|
import forge.util.XmlWriter.IXmlWritable;
|
||||||
|
|
||||||
public class ConquestCommander implements InventoryItem, IXmlWritable {
|
public class ConquestCommander implements InventoryItem, IXmlWritable {
|
||||||
private final PaperCard card;
|
private final PaperCard card;
|
||||||
private final Deck deck;
|
|
||||||
private final ConquestRecord record;
|
private final ConquestRecord record;
|
||||||
private final ConquestPlane originPlane;
|
private final ConquestPlane originPlane;
|
||||||
private final String originRegionName;
|
private final String originRegionName;
|
||||||
|
|
||||||
|
private Deck deck;
|
||||||
|
|
||||||
public ConquestCommander(PaperCard card0) {
|
public ConquestCommander(PaperCard card0) {
|
||||||
this(card0, new Deck(card0.getName()));
|
this(card0, new Deck(card0.getName()));
|
||||||
}
|
}
|
||||||
@@ -22,9 +25,12 @@ public class ConquestCommander implements InventoryItem, IXmlWritable {
|
|||||||
this(card0, ConquestUtil.generateDeck(card0, cardPool0, forAi));
|
this(card0, ConquestUtil.generateDeck(card0, cardPool0, forAi));
|
||||||
}
|
}
|
||||||
private ConquestCommander(PaperCard card0, Deck deck0) {
|
private ConquestCommander(PaperCard card0, Deck deck0) {
|
||||||
|
this(card0, deck0, new ConquestRecord());
|
||||||
|
}
|
||||||
|
private ConquestCommander(PaperCard card0, Deck deck0, ConquestRecord record0) {
|
||||||
card = card0;
|
card = card0;
|
||||||
deck = deck0;
|
deck = deck0;
|
||||||
record = new ConquestRecord();
|
record = record0;
|
||||||
|
|
||||||
//determine origin of commander
|
//determine origin of commander
|
||||||
ConquestPlane originPlane0 = null;
|
ConquestPlane originPlane0 = null;
|
||||||
@@ -45,6 +51,15 @@ public class ConquestCommander implements InventoryItem, IXmlWritable {
|
|||||||
originRegionName = originRegionName0;
|
originRegionName = originRegionName0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConquestCommander(XmlReader xml) {
|
||||||
|
this(xml.read("card", FModel.getMagicDb().getCommonCards()), null, xml.read("record", ConquestRecord.class));
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void saveToXml(XmlWriter xml) {
|
||||||
|
xml.write("card", card);
|
||||||
|
xml.write("record", record);
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return card.getName();
|
return card.getName();
|
||||||
}
|
}
|
||||||
@@ -66,6 +81,12 @@ public class ConquestCommander implements InventoryItem, IXmlWritable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Deck getDeck() {
|
public Deck getDeck() {
|
||||||
|
if (deck == null) { //if deck not yet initialized, attempt to load deck file
|
||||||
|
deck = FModel.getConquest().getDecks().get(card.getName());
|
||||||
|
if (deck == null) {
|
||||||
|
deck = new Deck(card.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
return deck;
|
return deck;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,10 +116,4 @@ public class ConquestCommander implements InventoryItem, IXmlWritable {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return card.getName();
|
return card.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveToXml(XmlWriter xml) {
|
|
||||||
xml.write("card", card);
|
|
||||||
xml.write("record", record);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,9 +93,9 @@ public final class ConquestData {
|
|||||||
try {
|
try {
|
||||||
XmlReader xml = new XmlReader(xmlFilename);
|
XmlReader xml = new XmlReader(xmlFilename);
|
||||||
CardDb cardDb = FModel.getMagicDb().getCommonCards();
|
CardDb cardDb = FModel.getMagicDb().getCommonCards();
|
||||||
planeswalker = xml.read("planeswalker", planeswalker, cardDb);
|
planeswalker = xml.read("planeswalker", cardDb);
|
||||||
aetherShards = xml.read("aetherShards", aetherShards);
|
aetherShards = xml.read("aetherShards", aetherShards);
|
||||||
currentLocation = xml.read("currentLocation", currentLocation, ConquestLocation.class);
|
currentLocation = xml.read("currentLocation", ConquestLocation.class);
|
||||||
xml.read("unlockedCards", unlockedCards, cardDb);
|
xml.read("unlockedCards", unlockedCards, cardDb);
|
||||||
xml.read("newCards", newCards, cardDb);
|
xml.read("newCards", newCards, cardDb);
|
||||||
xml.read("commanders", commanders, ConquestCommander.class);
|
xml.read("commanders", commanders, ConquestCommander.class);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class ConquestLocation implements IXmlWritable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConquestLocation(XmlReader xml) {
|
public ConquestLocation(XmlReader xml) {
|
||||||
plane = xml.read("plane", ConquestPlane.class);
|
plane = xml.read("plane", ConquestPlane.Alara);
|
||||||
regionIndex = xml.read("regionIndex", 0);
|
regionIndex = xml.read("regionIndex", 0);
|
||||||
row = xml.read("row", 0);
|
row = xml.read("row", 0);
|
||||||
col = xml.read("col", 0);
|
col = xml.read("col", 0);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class ConquestPlaneData implements IXmlWritable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConquestPlaneData(XmlReader xml) {
|
public ConquestPlaneData(XmlReader xml) {
|
||||||
plane = xml.read("plane", ConquestPlane.class);
|
plane = xml.read("plane", ConquestPlane.Alara);
|
||||||
eventResults = new ConquestRecord[plane.getEventCount()];
|
eventResults = new ConquestRecord[plane.getEventCount()];
|
||||||
xml.read("eventResults", eventResults, ConquestRecord.class);
|
xml.read("eventResults", eventResults, ConquestRecord.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,12 +37,6 @@ public class XmlReader {
|
|||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
public <E extends Enum<E>> E read(String key, Class<E> enumType) {
|
|
||||||
if (currentElement.hasAttribute(key)) {
|
|
||||||
return Enum.valueOf(enumType, currentElement.getAttribute(key));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
public int read(String key, int defaultValue) {
|
public int read(String key, int defaultValue) {
|
||||||
if (currentElement.hasAttribute(key)) {
|
if (currentElement.hasAttribute(key)) {
|
||||||
return Integer.parseInt(currentElement.getAttribute(key));
|
return Integer.parseInt(currentElement.getAttribute(key));
|
||||||
@@ -61,26 +55,26 @@ public class XmlReader {
|
|||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
public PaperCard read(String key, PaperCard defaultValue, CardDb cardDb) {
|
public PaperCard read(String key, CardDb cardDb) {
|
||||||
paperCardBuilder.setup(this, cardDb);
|
paperCardBuilder.setup(this, cardDb);
|
||||||
return read(key, defaultValue, paperCardBuilder);
|
return parseChildElements(key, paperCardBuilder);
|
||||||
}
|
}
|
||||||
public <T extends Collection<PaperCard>> void read(String key, T collectionToLoad, CardDb cardDb) {
|
public <T extends Collection<PaperCard>> void read(String key, T collectionToLoad, CardDb cardDb) {
|
||||||
paperCardBuilder.setup(this, cardDb);
|
paperCardBuilder.setup(this, cardDb);
|
||||||
read(key, collectionToLoad, null, paperCardBuilder);
|
parseChildElements(key, collectionToLoad, null, paperCardBuilder);
|
||||||
}
|
}
|
||||||
public <T extends Collection<PaperCard>> T read(String key, Class<T> collectionType, CardDb cardDb) {
|
public <T extends Collection<PaperCard>> T read(String key, Class<T> collectionType, CardDb cardDb) {
|
||||||
paperCardBuilder.setup(this, cardDb);
|
paperCardBuilder.setup(this, cardDb);
|
||||||
return read(key, null, collectionType, paperCardBuilder);
|
return parseChildElements(key, null, collectionType, paperCardBuilder);
|
||||||
}
|
}
|
||||||
public <T extends IXmlWritable> T read(String key, T defaultValue, Class<T> type) {
|
public <T extends IXmlWritable> T read(String key, Class<T> type) {
|
||||||
return read(key, defaultValue, new GenericBuilder<T>(type));
|
return parseChildElements(key, new GenericBuilder<T>(type));
|
||||||
}
|
}
|
||||||
public <V extends IXmlWritable, T extends Collection<V>> void read(String key, T collectionToLoad, Class<V> elementType) {
|
public <V extends IXmlWritable, T extends Collection<V>> void read(String key, T collectionToLoad, Class<V> elementType) {
|
||||||
read(key, collectionToLoad, null, new GenericBuilder<V>(elementType));
|
parseChildElements(key, collectionToLoad, null, new GenericBuilder<V>(elementType));
|
||||||
}
|
}
|
||||||
public <V extends IXmlWritable, T extends Collection<V>> T read(String key, Class<T> collectionType, Class<V> elementType) {
|
public <V extends IXmlWritable, T extends Collection<V>> T read(String key, Class<T> collectionType, Class<V> elementType) {
|
||||||
return read(key, null, collectionType, new GenericBuilder<V>(elementType));
|
return parseChildElements(key, null, collectionType, new GenericBuilder<V>(elementType));
|
||||||
}
|
}
|
||||||
public <V extends IXmlWritable> void read(final String key, final V[] array, final Class<V> elementType) {
|
public <V extends IXmlWritable> void read(final String key, final V[] array, final Class<V> elementType) {
|
||||||
parseChildElements(key, new Evaluator<Void>() {
|
parseChildElements(key, new Evaluator<Void>() {
|
||||||
@@ -135,16 +129,28 @@ public class XmlReader {
|
|||||||
|
|
||||||
/* Private helper methods */
|
/* Private helper methods */
|
||||||
|
|
||||||
private <T> T read(String key, T defaultValue, final Evaluator<T> builder) {
|
private <T> T parseChildElements(String findKey, Evaluator<T> handler) {
|
||||||
T result = parseChildElements(key, builder);
|
Element parentElement = currentElement;
|
||||||
if (result == null) {
|
NodeList childNodes = currentElement.getChildNodes();
|
||||||
result = defaultValue;
|
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||||
}
|
Node node = childNodes.item(i);
|
||||||
|
if (node instanceof Element) {
|
||||||
|
Element element = (Element)node;
|
||||||
|
if (findKey == null || element.getTagName().equals(findKey)) {
|
||||||
|
currentElement = (Element)node;
|
||||||
|
T result = handler.evaluate();
|
||||||
|
currentElement = parentElement;
|
||||||
|
if (findKey != null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private <V, T extends Collection<V>> T read(String key, final T collectionToLoad, final Class<T> collectionType, final Evaluator<V> builder) {
|
private <V, T extends Collection<V>> T parseChildElements(String key, final T collectionToLoad, final Class<T> collectionType, final Evaluator<V> builder) {
|
||||||
return read(key, collectionToLoad, new Evaluator<T>() {
|
T result = parseChildElements(key, new Evaluator<T>() {
|
||||||
@Override
|
@Override
|
||||||
public T evaluate() {
|
public T evaluate() {
|
||||||
final T result;
|
final T result;
|
||||||
@@ -173,27 +179,11 @@ public class XmlReader {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (result == null) {
|
||||||
|
result = collectionToLoad;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> T parseChildElements(String findKey, Evaluator<T> handler) {
|
|
||||||
Element parentElement = currentElement;
|
|
||||||
NodeList childNodes = currentElement.getChildNodes();
|
|
||||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
|
||||||
Node node = childNodes.item(i);
|
|
||||||
if (node instanceof Element) {
|
|
||||||
Element element = (Element)node;
|
|
||||||
if (findKey == null || element.getTagName().equals(findKey)) {
|
|
||||||
currentElement = (Element)node;
|
|
||||||
T result = handler.evaluate();
|
|
||||||
currentElement = parentElement;
|
|
||||||
if (findKey != null) {
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final PaperCardBuilder paperCardBuilder = new PaperCardBuilder();
|
private static final PaperCardBuilder paperCardBuilder = new PaperCardBuilder();
|
||||||
private static class PaperCardBuilder extends Evaluator<PaperCard> {
|
private static class PaperCardBuilder extends Evaluator<PaperCard> {
|
||||||
|
|||||||
Reference in New Issue
Block a user