mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
re-arranged deck serialization code to make it more "symmetric": the what is serialized somewhere tends to be de-serialized in the same class
This commit is contained in:
@@ -354,6 +354,27 @@ public final class CardDb implements ICardDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StringBuilder appendCardToStringBuilder(PaperCard card, StringBuilder sb) {
|
||||||
|
final boolean hasBadSetInfo = "???".equals(card.getEdition()) || StringUtils.isBlank(card.getEdition());
|
||||||
|
sb.append(card.getName());
|
||||||
|
|
||||||
|
if (!hasBadSetInfo) {
|
||||||
|
int artCount = getArtCount(card.getName(), card.getEdition());
|
||||||
|
sb.append(CardDb.NameSetSeparator).append(card.getEdition());
|
||||||
|
if (artCount > 1) {
|
||||||
|
sb.append(CardDb.NameSetSeparator).append(card.getArtIndex()); // indexes start at 1 to match image file name conventions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(card.isFoil()) {
|
||||||
|
sb.append(CardDb.foilSuffix);
|
||||||
|
}
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String cardToString(PaperCard pc) {
|
||||||
|
return appendCardToStringBuilder(pc, new StringBuilder()).toString();
|
||||||
|
}
|
||||||
|
|
||||||
private final Editor editor = new Editor();
|
private final Editor editor = new Editor();
|
||||||
public Editor getEditor() { return editor; }
|
public Editor getEditor() { return editor; }
|
||||||
public class Editor {
|
public class Editor {
|
||||||
|
|||||||
@@ -17,16 +17,21 @@
|
|||||||
*/
|
*/
|
||||||
package forge.deck;
|
package forge.deck;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
import forge.card.CardDb;
|
import forge.card.CardDb;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.ItemPool;
|
import forge.util.ItemPool;
|
||||||
|
import forge.util.ItemPoolSorter;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,6 +98,8 @@ public class CardPool extends ItemPool<PaperCard> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all from a List of CardPrinted.
|
* Add all from a List of CardPrinted.
|
||||||
*
|
*
|
||||||
@@ -163,4 +170,28 @@ public class CardPool extends ItemPool<PaperCard> {
|
|||||||
}
|
}
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toCardList(String separator) {
|
||||||
|
List<Entry<PaperCard, Integer>> main2sort = Lists.newArrayList(this);
|
||||||
|
Collections.sort(main2sort, ItemPoolSorter.BY_NAME_THEN_SET);
|
||||||
|
final CardDb commonDb = StaticData.instance().getCommonCards();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
boolean isFirst = true;
|
||||||
|
|
||||||
|
for (final Entry<PaperCard, Integer> e : main2sort) {
|
||||||
|
if(!isFirst)
|
||||||
|
sb.append(separator);
|
||||||
|
else
|
||||||
|
isFirst = false;
|
||||||
|
|
||||||
|
CardDb db = e.getKey().getRules().isVariant() ? commonDb : StaticData.instance().getVariantCards();
|
||||||
|
sb.append(e.getValue()).append(" ");
|
||||||
|
db.appendCardToStringBuilder(e.getKey(), sb);
|
||||||
|
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,37 +17,21 @@
|
|||||||
*/
|
*/
|
||||||
package forge.deck;
|
package forge.deck;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
|
|
||||||
import forge.card.CardDb;
|
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
import forge.card.CardDb.SetPreference;
|
import forge.card.CardDb.SetPreference;
|
||||||
import forge.deck.io.DeckFileHeader;
|
|
||||||
import forge.deck.io.DeckSerializer;
|
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.item.IPaperCard;
|
|
||||||
import forge.util.FileSection;
|
|
||||||
import forge.util.FileUtil;
|
|
||||||
import forge.util.ItemPool;
|
|
||||||
import forge.util.ItemPoolSorter;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -126,6 +110,10 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void putSection(DeckSection section, CardPool pool) {
|
||||||
|
this.parts.put(section, pool);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.deck.DeckBase#cloneFieldsTo(forge.deck.DeckBase)
|
* @see forge.deck.DeckBase#cloneFieldsTo(forge.deck.DeckBase)
|
||||||
*/
|
*/
|
||||||
@@ -150,78 +138,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
return new Deck(name0);
|
return new Deck(name0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* From file.
|
|
||||||
*
|
|
||||||
* @param deckFile the deck file
|
|
||||||
* @return the deck
|
|
||||||
*/
|
|
||||||
public static Deck fromFile(final File deckFile) {
|
|
||||||
return Deck.fromSections(FileSection.parseSections(FileUtil.readFile(deckFile)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* From sections.
|
|
||||||
*
|
|
||||||
* @param sections the sections
|
|
||||||
* @return the deck
|
|
||||||
*/
|
|
||||||
public static Deck fromSections(final Map<String, List<String>> sections) {
|
|
||||||
return Deck.fromSections(sections, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* From sections.
|
|
||||||
*
|
|
||||||
* @param sections the sections
|
|
||||||
* @param canThrowExtendedErrors the can throw extended errors
|
|
||||||
* @return the deck
|
|
||||||
*/
|
|
||||||
public static Deck fromSections(final Map<String, List<String>> sections, final boolean canThrowExtendedErrors) {
|
|
||||||
if (sections == null || sections.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final DeckFileHeader dh = DeckSerializer.readDeckMetadata(sections, canThrowExtendedErrors);
|
|
||||||
if (dh == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Deck d = new Deck(dh.getName());
|
|
||||||
d.setComment(dh.getComment());
|
|
||||||
d.tags.addAll(dh.getTags());
|
|
||||||
|
|
||||||
boolean hasExplicitlySpecifiedSet = false;
|
|
||||||
|
|
||||||
for (Entry<String, List<String>> s : sections.entrySet()) {
|
|
||||||
DeckSection sec = DeckSection.smartValueOf(s.getKey());
|
|
||||||
if (sec == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(String k : s.getValue())
|
|
||||||
if ( k.indexOf(CardDb.NameSetSeparator) > 0 )
|
|
||||||
hasExplicitlySpecifiedSet = true;
|
|
||||||
|
|
||||||
CardPool pool = CardPool.fromCardList(s.getValue());
|
|
||||||
// I used to store planes and schemes under sideboard header, so this will assign them to a correct section
|
|
||||||
IPaperCard sample = pool.get(0);
|
|
||||||
if (sample != null && ( sample.getRules().getType().isPlane() || sample.getRules().getType().isPhenomenon())) {
|
|
||||||
sec = DeckSection.Planes;
|
|
||||||
}
|
|
||||||
if (sample != null && sample.getRules().getType().isScheme()) {
|
|
||||||
sec = DeckSection.Schemes;
|
|
||||||
}
|
|
||||||
|
|
||||||
d.parts.put(sec, pool);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasExplicitlySpecifiedSet) {
|
|
||||||
d.convertByXitaxMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void convertByXitaxMethod() {
|
public void convertByXitaxMethod() {
|
||||||
CardEdition earliestSet = StaticData.instance().getEditions().getEarliestEditionWithAllCards(getAllCardsInASinglePool());
|
CardEdition earliestSet = StaticData.instance().getEditions().getEarliestEditionWithAllCards(getAllCardsInASinglePool());
|
||||||
@@ -259,63 +176,6 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> writeCardPool(final ItemPool<PaperCard> pool) {
|
|
||||||
List<Entry<PaperCard, Integer>> main2sort = Lists.newArrayList(pool);
|
|
||||||
Collections.sort(main2sort, ItemPoolSorter.BY_NAME_THEN_SET);
|
|
||||||
final List<String> out = new ArrayList<String>();
|
|
||||||
for (final Entry<PaperCard, Integer> e : main2sort) {
|
|
||||||
out.add(serializeSingleCard(e.getKey(), e.getValue()));
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String serializeSingleCard(PaperCard card, Integer n) {
|
|
||||||
final boolean hasBadSetInfo = "???".equals(card.getEdition()) || StringUtils.isBlank(card.getEdition());
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append(n).append(" ").append(card.getName());
|
|
||||||
|
|
||||||
if (!hasBadSetInfo) {
|
|
||||||
int artCount = StaticData.instance().getCommonCards().getArtCount(card.getName(), card.getEdition());
|
|
||||||
|
|
||||||
sb.append("|").append(card.getEdition());
|
|
||||||
|
|
||||||
if (artCount > 1) {
|
|
||||||
sb.append("|").append(card.getArtIndex()); // indexes start at 1 to match image file name conventions
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(card.isFoil()) {
|
|
||||||
sb.append(CardDb.foilSuffix);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* writeDeck.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @return the list
|
|
||||||
*/
|
|
||||||
public List<String> save() {
|
|
||||||
final List<String> out = new ArrayList<String>();
|
|
||||||
out.add(String.format("[metadata]"));
|
|
||||||
|
|
||||||
out.add(String.format("%s=%s", DeckFileHeader.NAME, this.getName().replaceAll("\n", "")));
|
|
||||||
// these are optional
|
|
||||||
if (this.getComment() != null) {
|
|
||||||
out.add(String.format("%s=%s", DeckFileHeader.COMMENT, this.getComment().replaceAll("\n", "")));
|
|
||||||
}
|
|
||||||
if (!this.getTags().isEmpty()) {
|
|
||||||
out.add(String.format("%s=%s", DeckFileHeader.TAGS, StringUtils.join(getTags(), DeckFileHeader.TAGS_SEPARATOR)));
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Entry<DeckSection, CardPool> s : parts.entrySet()) {
|
|
||||||
out.add(String.format("[%s]", s.getKey().toString()));
|
|
||||||
out.addAll(Deck.writeCardPool(s.getValue()));
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Function<Deck, String> FN_NAME_SELECTOR = new Function<Deck, String>() {
|
public static final Function<Deck, String> FN_NAME_SELECTOR = new Function<Deck, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String apply(Deck arg1) {
|
public String apply(Deck arg1) {
|
||||||
|
|||||||
@@ -19,13 +19,19 @@ package forge.deck.io;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import forge.card.CardDb;
|
||||||
|
import forge.deck.CardPool;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
|
import forge.deck.DeckSection;
|
||||||
|
import forge.item.IPaperCard;
|
||||||
import forge.util.FileSection;
|
import forge.util.FileSection;
|
||||||
import forge.util.FileSectionManual;
|
import forge.util.FileSectionManual;
|
||||||
import forge.util.FileUtil;
|
import forge.util.FileUtil;
|
||||||
@@ -56,13 +62,91 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
|
|||||||
return name.endsWith(FILE_EXTENSION);
|
return name.endsWith(FILE_EXTENSION);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static void writeDeck(final Deck d, final File f) {
|
|
||||||
FileUtil.writeFile(f, d.save());
|
public static void writeDeck(final Deck d, final File f) {
|
||||||
|
FileUtil.writeFile(f, serializeDeck(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(final Deck unit) {
|
public void save(final Deck unit) {
|
||||||
FileUtil.writeFile(this.makeFileFor(unit), unit.save());
|
writeDeck(unit, this.makeFileFor(unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> serializeDeck(Deck d) {
|
||||||
|
final List<String> out = new ArrayList<String>();
|
||||||
|
out.add(String.format("[metadata]"));
|
||||||
|
|
||||||
|
out.add(String.format("%s=%s", DeckFileHeader.NAME, d.getName().replaceAll("\n", "")));
|
||||||
|
// these are optional
|
||||||
|
if (d.getComment() != null) {
|
||||||
|
out.add(String.format("%s=%s", DeckFileHeader.COMMENT, d.getComment().replaceAll("\n", "")));
|
||||||
|
}
|
||||||
|
if (!d.getTags().isEmpty()) {
|
||||||
|
out.add(String.format("%s=%s", DeckFileHeader.TAGS, StringUtils.join(d.getTags(), DeckFileHeader.TAGS_SEPARATOR)));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(Entry<DeckSection, CardPool> s : d) {
|
||||||
|
out.add(String.format("[%s]", s.getKey().toString()));
|
||||||
|
out.add(s.getValue().toCardList(System.getProperty("line.separator")));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Deck fromFile(final File deckFile) {
|
||||||
|
return fromSections(FileSection.parseSections(FileUtil.readFile(deckFile)), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Deck fromSections(final Map<String, List<String>> sections) {
|
||||||
|
return fromSections(sections, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static Deck fromSections(final Map<String, List<String>> sections, final boolean canThrowExtendedErrors) {
|
||||||
|
if (sections == null || sections.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final DeckFileHeader dh = DeckSerializer.readDeckMetadata(sections, canThrowExtendedErrors);
|
||||||
|
if (dh == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Deck d = new Deck(dh.getName());
|
||||||
|
d.setComment(dh.getComment());
|
||||||
|
d.getTags().addAll(dh.getTags());
|
||||||
|
|
||||||
|
boolean hasExplicitlySpecifiedSet = false;
|
||||||
|
|
||||||
|
for (Entry<String, List<String>> s : sections.entrySet()) {
|
||||||
|
DeckSection sec = DeckSection.smartValueOf(s.getKey());
|
||||||
|
if (sec == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String k : s.getValue())
|
||||||
|
if ( k.indexOf(CardDb.NameSetSeparator) > 0 )
|
||||||
|
hasExplicitlySpecifiedSet = true;
|
||||||
|
|
||||||
|
CardPool pool = CardPool.fromCardList(s.getValue());
|
||||||
|
// I used to store planes and schemes under sideboard header, so this will assign them to a correct section
|
||||||
|
IPaperCard sample = pool.get(0);
|
||||||
|
if (sample != null && ( sample.getRules().getType().isPlane() || sample.getRules().getType().isPhenomenon())) {
|
||||||
|
sec = DeckSection.Planes;
|
||||||
|
}
|
||||||
|
if (sample != null && sample.getRules().getType().isScheme()) {
|
||||||
|
sec = DeckSection.Schemes;
|
||||||
|
}
|
||||||
|
|
||||||
|
d.putSection(sec, pool);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasExplicitlySpecifiedSet) {
|
||||||
|
d.convertByXitaxMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,7 +161,7 @@ public static void writeDeck(final Deck d, final File f) {
|
|||||||
@Override
|
@Override
|
||||||
protected Deck read(final File file) {
|
protected Deck read(final File file) {
|
||||||
final Map<String, List<String>> sections = FileSection.parseSections(FileUtil.readFile(file));
|
final Map<String, List<String>> sections = FileSection.parseSections(FileUtil.readFile(file));
|
||||||
Deck result = Deck.fromSections(sections, true);
|
Deck result = fromSections(sections, true);
|
||||||
|
|
||||||
if (moveWronglyNamedDecks) {
|
if (moveWronglyNamedDecks) {
|
||||||
adjustFileLocation(file, result);
|
adjustFileLocation(file, result);
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public class PreconDeck implements InventoryItemFromSet {
|
|||||||
String description = kv.get("Description");
|
String description = kv.get("Description");
|
||||||
String deckEdition = kv.get("set");
|
String deckEdition = kv.get("set");
|
||||||
String set = deckEdition == null || StaticData.instance().getEditions().get(deckEdition.toUpperCase()) == null ? "n/a" : deckEdition;
|
String set = deckEdition == null || StaticData.instance().getEditions().get(deckEdition.toUpperCase()) == null ? "n/a" : deckEdition;
|
||||||
PreconDeck result = new PreconDeck(Deck.fromSections(sections), set, description);
|
PreconDeck result = new PreconDeck(DeckSerializer.fromSections(sections), set, description);
|
||||||
result.imageFilename = imageFilename;
|
result.imageFilename = imageFilename;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import com.google.common.collect.ImmutableList;
|
|||||||
|
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.DeckGroup;
|
import forge.deck.DeckGroup;
|
||||||
import forge.util.FileUtil;
|
|
||||||
import forge.util.IItemSerializer;
|
import forge.util.IItemSerializer;
|
||||||
import forge.util.storage.StorageReaderFolder;
|
import forge.util.storage.StorageReaderFolder;
|
||||||
|
|
||||||
@@ -59,10 +58,10 @@ public class DeckGroupSerializer extends StorageReaderFolder<DeckGroup> implemen
|
|||||||
public void save(final DeckGroup unit) {
|
public void save(final DeckGroup unit) {
|
||||||
final File f = this.makeFileFor(unit);
|
final File f = this.makeFileFor(unit);
|
||||||
f.mkdir();
|
f.mkdir();
|
||||||
FileUtil.writeFile(new File(f, this.humanDeckFile), unit.getHumanDeck().save());
|
DeckSerializer.writeDeck(unit.getHumanDeck(), new File(f, this.humanDeckFile));
|
||||||
final List<Deck> aiDecks = unit.getAiDecks();
|
final List<Deck> aiDecks = unit.getAiDecks();
|
||||||
for (int i = 1; i <= aiDecks.size(); i++) {
|
for (int i = 1; i <= aiDecks.size(); i++) {
|
||||||
FileUtil.writeFile(new File(f, "ai-" + i + ".dck"), aiDecks.get(i - 1).save());
|
DeckSerializer.writeDeck(aiDecks.get(i - 1), new File(f, "ai-" + i + ".dck"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +71,7 @@ public class DeckGroupSerializer extends StorageReaderFolder<DeckGroup> implemen
|
|||||||
@Override
|
@Override
|
||||||
protected final DeckGroup read(final File file) {
|
protected final DeckGroup read(final File file) {
|
||||||
|
|
||||||
final Deck human = Deck.fromFile(new File(file, this.humanDeckFile));
|
final Deck human = DeckSerializer.fromFile(new File(file, this.humanDeckFile));
|
||||||
if (null == human) {
|
if (null == human) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -85,7 +84,7 @@ public class DeckGroupSerializer extends StorageReaderFolder<DeckGroup> implemen
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
d.addAiDeck(Deck.fromFile(theFile));
|
d.addAiDeck(DeckSerializer.fromFile(theFile));
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,12 +130,12 @@ public class OldDeckParser {
|
|||||||
private void convertDrafts() {
|
private void convertDrafts() {
|
||||||
for (final File f : this.deckDir.listFiles(OldDeckParser.BDK_FILE_FILTER)) {
|
for (final File f : this.deckDir.listFiles(OldDeckParser.BDK_FILE_FILTER)) {
|
||||||
boolean gotError = false;
|
boolean gotError = false;
|
||||||
final Deck human = Deck.fromFile(new File(f, "0.dck"));
|
final Deck human = DeckSerializer.fromFile(new File(f, "0.dck"));
|
||||||
final DeckGroup d = new DeckGroup(human.getName());
|
final DeckGroup d = new DeckGroup(human.getName());
|
||||||
d.setHumanDeck(human);
|
d.setHumanDeck(human);
|
||||||
|
|
||||||
for (int i = 1; i < DeckGroupSerializer.MAX_DRAFT_PLAYERS; i++) {
|
for (int i = 1; i < DeckGroupSerializer.MAX_DRAFT_PLAYERS; i++) {
|
||||||
final Deck nextAi = Deck.fromFile(new File(f, i + ".dck"));
|
final Deck nextAi = DeckSerializer.fromFile(new File(f, i + ".dck"));
|
||||||
if (nextAi == null) {
|
if (nextAi == null) {
|
||||||
gotError = true;
|
gotError = true;
|
||||||
break;
|
break;
|
||||||
@@ -176,7 +176,7 @@ public class OldDeckParser {
|
|||||||
|
|
||||||
if (dh.isCustomPool()) {
|
if (dh.isCustomPool()) {
|
||||||
try {
|
try {
|
||||||
this.cube.add(Deck.fromSections(sections));
|
this.cube.add(DeckSerializer.fromSections(sections));
|
||||||
importedOk = true;
|
importedOk = true;
|
||||||
}
|
}
|
||||||
catch (final NoSuchElementException ex) {
|
catch (final NoSuchElementException ex) {
|
||||||
@@ -196,7 +196,7 @@ public class OldDeckParser {
|
|||||||
switch (dh.getDeckType()) {
|
switch (dh.getDeckType()) {
|
||||||
case Constructed:
|
case Constructed:
|
||||||
try {
|
try {
|
||||||
this.constructed.add(Deck.fromSections(sections));
|
this.constructed.add(DeckSerializer.fromSections(sections));
|
||||||
importedOk = true;
|
importedOk = true;
|
||||||
} catch (final NoSuchElementException ex) {
|
} catch (final NoSuchElementException ex) {
|
||||||
if (!allowDeleteUnsupportedConstructed) {
|
if (!allowDeleteUnsupportedConstructed) {
|
||||||
@@ -219,7 +219,7 @@ public class OldDeckParser {
|
|||||||
stored = ImmutablePair.of(new DeckGroup(name), MutablePair.of((File) null, (File) null));
|
stored = ImmutablePair.of(new DeckGroup(name), MutablePair.of((File) null, (File) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
final Deck deck = Deck.fromSections(sections);
|
final Deck deck = DeckSerializer.fromSections(sections);
|
||||||
if (dh.isIntendedForAi()) {
|
if (dh.isIntendedForAi()) {
|
||||||
stored.getLeft().addAiDeck(deck);
|
stored.getLeft().addAiDeck(deck);
|
||||||
stored.getRight().setRight(f);
|
stored.getRight().setRight(f);
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
|
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.ColorSet;
|
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
import forge.game.player.RegisteredPlayer;
|
import forge.game.player.RegisteredPlayer;
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ public enum CCurrentDeck implements ICDoc {
|
|||||||
try {
|
try {
|
||||||
((DeckController<DeckBase>) CDeckEditorUI.SINGLETON_INSTANCE
|
((DeckController<DeckBase>) CDeckEditorUI.SINGLETON_INSTANCE
|
||||||
.getCurrentEditorController().getDeckController())
|
.getCurrentEditorController().getDeckController())
|
||||||
.setModel(Deck.fromFile(file));
|
.setModel(DeckSerializer.fromFile(file));
|
||||||
|
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
BugReporter.reportException(ex);
|
BugReporter.reportException(ex);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.google.common.base.Supplier;
|
|||||||
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
|
import forge.deck.io.DeckSerializer;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.GameLogEntry;
|
import forge.game.GameLogEntry;
|
||||||
import forge.game.GameRules;
|
import forge.game.GameRules;
|
||||||
@@ -120,7 +121,7 @@ public enum FServer {
|
|||||||
private Deck deckFromCommandLineParameter(String deckname) {
|
private Deck deckFromCommandLineParameter(String deckname) {
|
||||||
int dotpos = deckname.lastIndexOf('.');
|
int dotpos = deckname.lastIndexOf('.');
|
||||||
if(dotpos > 0 && dotpos == deckname.length()-4)
|
if(dotpos > 0 && dotpos == deckname.length()-4)
|
||||||
return Deck.fromFile(new File(deckname));
|
return DeckSerializer.fromFile(new File(deckname));
|
||||||
return Singletons.getModel().getDecks().getConstructed().get(deckname);
|
return Singletons.getModel().getDecks().getConstructed().get(deckname);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import forge.ImageKeys;
|
import forge.ImageKeys;
|
||||||
import forge.deck.Deck;
|
|
||||||
import forge.deck.io.DeckSerializer;
|
import forge.deck.io.DeckSerializer;
|
||||||
import forge.properties.NewConstants;
|
import forge.properties.NewConstants;
|
||||||
import forge.quest.QuestEventChallenge;
|
import forge.quest.QuestEventChallenge;
|
||||||
@@ -50,7 +49,7 @@ public class QuestChallengeReader extends StorageReaderFolder<QuestEventChalleng
|
|||||||
String humanDeck = sectionQuest.get("HumanDeck", null);
|
String humanDeck = sectionQuest.get("HumanDeck", null);
|
||||||
if (humanDeck != null) {
|
if (humanDeck != null) {
|
||||||
File humanFile = new File(NewConstants.DEFAULT_CHALLENGES_DIR, humanDeck); // Won't work in other worlds!
|
File humanFile = new File(NewConstants.DEFAULT_CHALLENGES_DIR, humanDeck); // Won't work in other worlds!
|
||||||
qc.setHumanDeck(Deck.fromFile(humanFile));
|
qc.setHumanDeck(DeckSerializer.fromFile(humanFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common properties
|
// Common properties
|
||||||
@@ -62,7 +61,7 @@ public class QuestChallengeReader extends StorageReaderFolder<QuestEventChalleng
|
|||||||
qc.setIconImageKey(ImageKeys.ICON_PREFIX + sectionMeta.get("Icon"));
|
qc.setIconImageKey(ImageKeys.ICON_PREFIX + sectionMeta.get("Icon"));
|
||||||
|
|
||||||
// Deck
|
// Deck
|
||||||
qc.setEventDeck(Deck.fromSections(contents));
|
qc.setEventDeck(DeckSerializer.fromSections(contents));
|
||||||
return qc;
|
return qc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import forge.ImageKeys;
|
import forge.ImageKeys;
|
||||||
import forge.deck.Deck;
|
|
||||||
import forge.deck.io.DeckSerializer;
|
import forge.deck.io.DeckSerializer;
|
||||||
import forge.quest.QuestEvent;
|
import forge.quest.QuestEvent;
|
||||||
import forge.quest.QuestEventDifficulty;
|
import forge.quest.QuestEventDifficulty;
|
||||||
@@ -36,7 +35,7 @@ public class QuestDuelReader extends StorageReaderFolder<QuestEventDuel> {
|
|||||||
qc.setIconImageKey(ImageKeys.ICON_PREFIX + sectionMeta.get("Icon"));
|
qc.setIconImageKey(ImageKeys.ICON_PREFIX + sectionMeta.get("Icon"));
|
||||||
|
|
||||||
// Deck
|
// Deck
|
||||||
qc.setEventDeck(Deck.fromSections(contents));
|
qc.setEventDeck(DeckSerializer.fromSections(contents));
|
||||||
return qc;
|
return qc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user