renamed cardSet to cardEdition (to avoid using 'set' word - too many things can be called a set)

also probably broken QuestEventManager :D
FileSection now initializes outside of cycle a regexp to parse lines (this is some 25% faster)
This commit is contained in:
Maxmtg
2012-02-20 22:40:03 +00:00
parent 49834380e4
commit 36a040b440
23 changed files with 179 additions and 73 deletions

1
.gitattributes vendored
View File

@@ -11374,6 +11374,7 @@ src/main/java/forge/util/Base64Coder.java svneol=native#text/plain
src/main/java/forge/util/CopyFiles.java svneol=native#text/plain src/main/java/forge/util/CopyFiles.java svneol=native#text/plain
src/main/java/forge/util/FileFinder.java svneol=native#text/plain src/main/java/forge/util/FileFinder.java svneol=native#text/plain
src/main/java/forge/util/FileSection.java -text src/main/java/forge/util/FileSection.java -text
src/main/java/forge/util/FileStorageReader.java -text
src/main/java/forge/util/FileUtil.java svneol=native#text/plain src/main/java/forge/util/FileUtil.java svneol=native#text/plain
src/main/java/forge/util/FolderMap.java svneol=native#text/plain src/main/java/forge/util/FolderMap.java svneol=native#text/plain
src/main/java/forge/util/FolderMapView.java -text src/main/java/forge/util/FolderMapView.java -text

View File

@@ -8354,7 +8354,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
public final String getMostRecentSet() { public final String getMostRecentSet() {
return CardDb.instance().getCard(this.getName()).getSet(); return CardDb.instance().getCard(this.getName()).getEdition();
} }
/** /**

View File

@@ -696,8 +696,8 @@ public final class CardUtil {
* @return the string * @return the string
*/ */
public static String buildFilename(final CardPrinted card) { public static String buildFilename(final CardPrinted card) {
final int maxIndex = card.getCard().getSetInfo(card.getSet()).getCopiesCount(); final int maxIndex = card.getCard().getSetInfo(card.getEdition()).getCopiesCount();
return CardUtil.buildFilename(card.getName(), card.getSet(), card.getArtIndex(), maxIndex, false); return CardUtil.buildFilename(card.getName(), card.getEdition(), card.getArtIndex(), maxIndex, false);
} }
/** /**
@@ -710,8 +710,8 @@ public final class CardUtil {
* @return the string * @return the string
*/ */
public static String buildFilename(final CardPrinted card, final String nameToUse) { public static String buildFilename(final CardPrinted card, final String nameToUse) {
final int maxIndex = card.getCard().getSetInfo(card.getSet()).getCopiesCount(); final int maxIndex = card.getCard().getSetInfo(card.getEdition()).getCopiesCount();
return CardUtil.buildFilename(nameToUse, card.getSet(), card.getArtIndex(), maxIndex, false); return CardUtil.buildFilename(nameToUse, card.getEdition(), card.getArtIndex(), maxIndex, false);
} }
private static String buildFilename(final String cardName, final String setName, final int artIndex, private static String buildFilename(final String cardName, final String setName, final int artIndex,

View File

@@ -70,7 +70,7 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
protected final void addCardToList(final ArrayList<DownloadObject> cList, final CardPrinted c, final String cardName) { protected final void addCardToList(final ArrayList<DownloadObject> cList, final CardPrinted c, final String cardName) {
final String urlBase = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/fpics/"; final String urlBase = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/fpics/";
final String setCode3 = c.getSet(); final String setCode3 = c.getEdition();
final CardEdition thisSet = AllZone.getEditions().getEditionByCode(setCode3); final CardEdition thisSet = AllZone.getEditions().getEditionByCode(setCode3);
final String setCode2 = thisSet.getCode2(); final String setCode2 = thisSet.getCode2();
@@ -107,7 +107,7 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
final ArrayList<DownloadObject> cList = new ArrayList<DownloadObject>(); final ArrayList<DownloadObject> cList = new ArrayList<DownloadObject>();
for (final CardPrinted c : CardDb.instance().getAllCards()) { for (final CardPrinted c : CardDb.instance().getAllCards()) {
final String setCode3 = c.getSet(); final String setCode3 = c.getEdition();
if (StringUtils.isBlank(setCode3) || "???".equals(setCode3)) { if (StringUtils.isBlank(setCode3) || "???".equals(setCode3)) {
continue; // we don't want cards from unknown sets continue; // we don't want cards from unknown sets
} }

View File

@@ -203,11 +203,11 @@ public class Deck extends DeckBase implements Serializable, IHasName {
final List<String> out = new ArrayList<String>(); final List<String> out = new ArrayList<String>();
for (final Entry<CardPrinted, Integer> e : main2sort) { for (final Entry<CardPrinted, Integer> e : main2sort) {
final CardPrinted card = e.getKey(); final CardPrinted card = e.getKey();
final boolean hasBadSetInfo = "???".equals(card.getSet()) || StringUtils.isBlank(card.getSet()); final boolean hasBadSetInfo = "???".equals(card.getEdition()) || StringUtils.isBlank(card.getEdition());
if (hasBadSetInfo) { if (hasBadSetInfo) {
out.add(String.format("%d %s", e.getValue(), card.getName())); out.add(String.format("%d %s", e.getValue(), card.getName()));
} else { } else {
out.add(String.format("%d %s|%s", e.getValue(), card.getName(), card.getSet())); out.add(String.format("%d %s|%s", e.getValue(), card.getName(), card.getEdition()));
} }
} }
return out; return out;

View File

@@ -126,9 +126,9 @@ public class GameNew {
for (int i = 0; i < stackOfCards.getValue(); i++) { for (int i = 0; i < stackOfCards.getValue(); i++) {
final Card card = c.getCard(cardPrinted.getName(), AllZone.getHumanPlayer()); final Card card = c.getCard(cardPrinted.getName(), AllZone.getHumanPlayer());
card.setCurSetCode(cardPrinted.getSet()); card.setCurSetCode(cardPrinted.getEdition());
final int cntVariants = cardPrinted.getCard().getSetInfo(cardPrinted.getSet()).getCopiesCount(); final int cntVariants = cardPrinted.getCard().getSetInfo(cardPrinted.getEdition()).getCopiesCount();
if (cntVariants > 1) { if (cntVariants > 1) {
card.setRandomPicture(generator.nextInt(cntVariants - 1) + 1); card.setRandomPicture(generator.nextInt(cntVariants - 1) + 1);
} }
@@ -168,9 +168,9 @@ public class GameNew {
for (int i = 0; i < stackOfCards.getValue(); i++) { for (int i = 0; i < stackOfCards.getValue(); i++) {
final Card card = c.getCard(cardPrinted.getName(), AllZone.getComputerPlayer()); final Card card = c.getCard(cardPrinted.getName(), AllZone.getComputerPlayer());
card.setCurSetCode(cardPrinted.getSet()); card.setCurSetCode(cardPrinted.getEdition());
final int cntVariants = cardPrinted.getCard().getSetInfo(cardPrinted.getSet()).getCopiesCount(); final int cntVariants = cardPrinted.getCard().getSetInfo(cardPrinted.getEdition()).getCopiesCount();
if (cntVariants > 1) { if (cntVariants > 1) {
card.setRandomPicture(generator.nextInt(cntVariants - 1) + 1); card.setRandomPicture(generator.nextInt(cntVariants - 1) + 1);
} }

View File

@@ -89,7 +89,7 @@ public final class BoosterDraft implements IBoosterDraft {
this.packs.add(picker); this.packs.add(picker);
} }
IBoosterDraft.LAND_SET_CODE[0] = CardDb.instance().getCard("Plains").getSet(); IBoosterDraft.LAND_SET_CODE[0] = CardDb.instance().getCard("Plains").getEdition();
break; break;
case Block: // Draft from cards by block or set case Block: // Draft from cards by block or set
@@ -326,7 +326,7 @@ public final class BoosterDraft implements IBoosterDraft {
if (Constant.Runtime.UPLOAD_DRAFT[0]) { if (Constant.Runtime.UPLOAD_DRAFT[0]) {
for (int i = 0; i < thisBooster.size(); i++) { for (int i = 0; i < thisBooster.size(); i++) {
final CardPrinted cc = thisBooster.get(i); final CardPrinted cc = thisBooster.get(i);
final String cnBk = cc.getName() + "|" + cc.getSet(); final String cnBk = cc.getName() + "|" + cc.getEdition();
float pickValue = 0; float pickValue = 0;
if (cc.equals(c)) { if (cc.equals(c)) {

View File

@@ -75,7 +75,7 @@ public class SealedDeck {
this.packs.add(picker); this.packs.add(picker);
} }
this.getLandSetCode()[0] = CardDb.instance().getCard("Plains").getSet(); this.getLandSetCode()[0] = CardDb.instance().getCard("Plains").getEdition();
} else if (sealedType.equals("Block")) { } else if (sealedType.equals("Block")) {
final Object o = GuiUtils.getChoice("Choose Block", AllZone.getEditions().getBlocks().toArray()); final Object o = GuiUtils.getChoice("Choose Block", AllZone.getEditions().getBlocks().toArray());

View File

@@ -218,7 +218,7 @@ public class CardListViewer {
} }
if (null == this.cache[row]) { if (null == this.cache[row]) {
final Card card = AllZone.getCardFactory().getCard(cp.getName(), null); final Card card = AllZone.getCardFactory().getCard(cp.getName(), null);
card.setCurSetCode(cp.getSet()); card.setCurSetCode(cp.getEdition());
card.setImageFilename(CardUtil.buildFilename(card)); card.setImageFilename(CardUtil.buildFilename(card));
this.cache[row] = card; this.cache[row] = card;
} }

View File

@@ -276,7 +276,7 @@ public class DeckImport extends JDialog {
switch (token.getType()) { switch (token.getType()) {
case KnownCard: case KnownCard:
return String.format("<div class='knowncard'>%s * %s [%s] %s</div>", token.getNumber(), token.getCard() return String.format("<div class='knowncard'>%s * %s [%s] %s</div>", token.getNumber(), token.getCard()
.getName(), token.getCard().getSet(), token.getCard().isFoil() ? "<i>foil</i>" : ""); .getName(), token.getCard().getEdition(), token.getCard().isFoil() ? "<i>foil</i>" : "");
case UnknownCard: case UnknownCard:
return String.format("<div class='unknowncard'>%s * %s</div>", token.getNumber(), token.getText()); return String.format("<div class='unknowncard'>%s * %s</div>", token.getNumber(), token.getText());
case SectionName: case SectionName:

View File

@@ -55,12 +55,12 @@ public abstract class PresetColumns {
} }
private static CardEdition toSetCmp(final InventoryItem i) { private static CardEdition toSetCmp(final InventoryItem i) {
return i instanceof InventoryItemFromSet ? AllZone.getEditions().getEditionByCode(((InventoryItemFromSet) i).getSet()) return i instanceof InventoryItemFromSet ? AllZone.getEditions().getEditionByCode(((InventoryItemFromSet) i).getEdition())
: CardEdition.UNKNOWN; : CardEdition.UNKNOWN;
} }
private static String toSetStr(final InventoryItem i) { private static String toSetStr(final InventoryItem i) {
return i instanceof InventoryItemFromSet ? ((InventoryItemFromSet) i).getSet() : "n/a"; return i instanceof InventoryItemFromSet ? ((InventoryItemFromSet) i).getEdition() : "n/a";
} }
private static Integer toAiCmp(final InventoryItem i) { private static Integer toAiCmp(final InventoryItem i) {

View File

@@ -116,7 +116,7 @@ public class CardPanelLite extends CardPanelBase {
} else { } else {
if (card instanceof BoosterPack) { if (card instanceof BoosterPack) {
final BoosterPack booster = (BoosterPack) card; final BoosterPack booster = (BoosterPack) card;
final CardEdition set = AllZone.getEditions().getEditionByCodeOrThrow(booster.getSet()); final CardEdition set = AllZone.getEditions().getEditionByCodeOrThrow(booster.getEdition());
final String tpl = "%s booster pack.%n%nContains %d cards.%n%nBuy it to reveal the cards and add them to your inventory."; final String tpl = "%s booster pack.%n%nContains %d cards.%n%nBuy it to reveal the cards and add them to your inventory.";
this.description.setText(String.format(tpl, set.getName(), set.getBoosterData().getTotal())); this.description.setText(String.format(tpl, set.getName(), set.getBoosterData().getTotal()));
} else if (card instanceof PreconDeck) { } else if (card instanceof PreconDeck) {

View File

@@ -77,7 +77,7 @@ public class BoosterPack implements InventoryItemFromSet {
* @return String * @return String
*/ */
@Override @Override
public final String getSet() { public final String getEdition() {
return this.cardSet.getCode(); return this.cardSet.getCode();
} }

View File

@@ -392,10 +392,10 @@ public final class CardDb {
// Find card with maximal set index // Find card with maximal set index
result = namedCards.get(0); result = namedCards.get(0);
int resIndex = AllZone.getEditions().getEditionByCode((result).getSet()).getIndex(); int resIndex = AllZone.getEditions().getEditionByCode((result).getEdition()).getIndex();
for (final CardPrinted card : namedCards) { for (final CardPrinted card : namedCards) {
final int thisIndex = AllZone.getEditions().getEditionByCode((card).getSet()).getIndex(); final int thisIndex = AllZone.getEditions().getEditionByCode((card).getEdition()).getIndex();
if (thisIndex > resIndex) { if (thisIndex > resIndex) {
result = card; result = card;
resIndex = thisIndex; resIndex = thisIndex;

View File

@@ -46,7 +46,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
// These fields are kinda PK for PrintedCard // These fields are kinda PK for PrintedCard
private final String name; private final String name;
private final String cardSet; private final String edition;
private final int artIndex; private final int artIndex;
private final boolean foiled; private final boolean foiled;
@@ -88,8 +88,8 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
* @return String * @return String
*/ */
@Override @Override
public String getSet() { public String getEdition() {
return this.cardSet; return this.edition;
} }
/** /**
@@ -171,10 +171,10 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
}; };
// Constructor is private. All non-foiled instances are stored in CardDb // Constructor is private. All non-foiled instances are stored in CardDb
private CardPrinted(final CardRules c, final String set, final CardRarity rare, final int index, final boolean foil) { private CardPrinted(final CardRules c, final String edition0, final CardRarity rare, final int index, final boolean foil) {
this.card = c; this.card = c;
this.name = c.getName(); this.name = c.getName();
this.cardSet = set; this.edition = edition0;
this.artIndex = index; this.artIndex = index;
this.foiled = foil; this.foiled = foil;
this.rarity = rare; this.rarity = rare;
@@ -187,7 +187,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
* *
* @param c * @param c
* the c * the c
* @param set * @param edition
* the set * the set
* @param rare * @param rare
* the rare * the rare
@@ -195,8 +195,8 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
* the index * the index
* @return the card printed * @return the card printed
*/ */
static CardPrinted build(final CardRules c, final String set, final CardRarity rare, final int index) { static CardPrinted build(final CardRules c, final String edition, final CardRarity rare, final int index) {
return new CardPrinted(c, set, rare, index, false); return new CardPrinted(c, edition, rare, index, false);
} }
/* foiled don't need to stay in CardDb's structures, so u'r free to create */ /* foiled don't need to stay in CardDb's structures, so u'r free to create */
@@ -208,7 +208,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
* @return the card printed * @return the card printed
*/ */
public static CardPrinted makeFoiled(final CardPrinted c) { public static CardPrinted makeFoiled(final CardPrinted c) {
return new CardPrinted(c.card, c.cardSet, c.rarity, c.artIndex, true); return new CardPrinted(c.card, c.edition, c.rarity, c.artIndex, true);
} }
// Want this class to be a key for HashTable // Want this class to be a key for HashTable
@@ -233,7 +233,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
if (!this.name.equals(other.name)) { if (!this.name.equals(other.name)) {
return false; return false;
} }
if (!this.cardSet.equals(other.cardSet)) { if (!this.edition.equals(other.edition)) {
return false; return false;
} }
if ((other.foiled != this.foiled) || (other.artIndex != this.artIndex)) { if ((other.foiled != this.foiled) || (other.artIndex != this.artIndex)) {
@@ -250,7 +250,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
final int code = (this.nameLcase.hashCode() * 11) + (this.cardSet.hashCode() * 59) + (this.artIndex * 2); final int code = (this.nameLcase.hashCode() * 11) + (this.edition.hashCode() * 59) + (this.artIndex * 2);
if (this.foiled) { if (this.foiled) {
return code + 1; return code + 1;
} }
@@ -277,7 +277,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
public Card toForgeCard() { public Card toForgeCard() {
final Card c = AllZone.getCardFactory().getCard(this.name, null); final Card c = AllZone.getCardFactory().getCard(this.name, null);
if (c != null) { if (c != null) {
c.setCurSetCode(this.getSet()); c.setCurSetCode(this.getEdition());
c.setRandomPicture(this.artIndex + 1); c.setRandomPicture(this.artIndex + 1);
c.setImageFilename(this.getImageFilename()); c.setImageFilename(this.getImageFilename());
if (c.isFlip()) { if (c.isFlip()) {
@@ -307,7 +307,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
return nameCmp; return nameCmp;
} }
// TODO compare sets properly // TODO compare sets properly
return this.cardSet.compareTo(o.cardSet); return this.edition.compareTo(o.edition);
} }
/** /**
@@ -414,7 +414,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
@Override @Override
public boolean isTrue(final CardPrinted card) { public boolean isTrue(final CardPrinted card) {
return this.sets.contains(card.cardSet) == this.mustContain; return this.sets.contains(card.edition) == this.mustContain;
} }
public PredicateSets(final List<String> wantSets, final boolean shouldContain) { public PredicateSets(final List<String> wantSets, final boolean shouldContain) {

View File

@@ -44,5 +44,5 @@ public interface InventoryItemFromSet extends InventoryItem {
* *
* @return the sets the * @return the sets the
*/ */
String getSet(); String getEdition();
} }

View File

@@ -120,7 +120,7 @@ public class PreconDeck implements InventoryItemFromSet {
* @see forge.item.InventoryItemFromSet#getSet() * @see forge.item.InventoryItemFromSet#getSet()
*/ */
@Override @Override
public String getSet() { public String getEdition() {
return this.set; return this.set;
} }

View File

@@ -273,7 +273,7 @@ public class QuestDataIO {
protected void write(final CardPrinted cref, final Integer count, final HierarchicalStreamWriter writer) { protected void write(final CardPrinted cref, final Integer count, final HierarchicalStreamWriter writer) {
writer.startNode("card"); writer.startNode("card");
writer.addAttribute("c", cref.getName()); writer.addAttribute("c", cref.getName());
writer.addAttribute("s", cref.getSet()); writer.addAttribute("s", cref.getEdition());
if (cref.isFoil()) { if (cref.isFoil()) {
writer.addAttribute("foil", "1"); writer.addAttribute("foil", "1");
} }
@@ -286,7 +286,7 @@ public class QuestDataIO {
protected void write(final BoosterPack booster, final Integer count, final HierarchicalStreamWriter writer) { protected void write(final BoosterPack booster, final Integer count, final HierarchicalStreamWriter writer) {
writer.startNode("booster"); writer.startNode("booster");
writer.addAttribute("s", booster.getSet()); writer.addAttribute("s", booster.getEdition());
writer.addAttribute("n", count.toString()); writer.addAttribute("n", count.toString());
writer.endNode(); writer.endNode();
} }

View File

@@ -21,8 +21,11 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
import org.apache.commons.lang3.StringUtils;
import forge.AllZone; import forge.AllZone;
import forge.Singletons; import forge.Singletons;
import forge.deck.Deck; import forge.deck.Deck;
@@ -31,6 +34,7 @@ import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.quest.data.QuestPreferences.QPref; import forge.quest.data.QuestPreferences.QPref;
import forge.util.FileUtil; import forge.util.FileUtil;
import forge.util.SectionUtil;
/** /**
* <p> * <p>
@@ -72,28 +76,25 @@ public class QuestEventManager {
this.allDuels = new ArrayList<QuestDuel>(); this.allDuels = new ArrayList<QuestDuel>();
this.allChallenges = new ArrayList<QuestChallenge>(); this.allChallenges = new ArrayList<QuestChallenge>();
List<String> contents;
QuestEvent tempEvent; QuestEvent tempEvent;
final File[] allFiles = ForgeProps.getFile(NewConstants.Quest.DECKS).listFiles(DeckSerializer.DCK_FILE_FILTER); final File[] allFiles = ForgeProps.getFile(NewConstants.Quest.DECKS).listFiles(DeckSerializer.DCK_FILE_FILTER);
for (final File f : allFiles) { for (final File f : allFiles) {
contents = FileUtil.readFile(f); Map<String, List<String>> contents = SectionUtil.parseSections(FileUtil.readFile(f));
if (contents.get(0).trim().equals("[quest]")) { if (contents.containsKey("quest")) {
tempEvent = new QuestChallenge(); tempEvent = readChallenge(contents.get("quest"));
this.assembleChallengeUniquedata(contents, (QuestChallenge) tempEvent);
this.allChallenges.add((QuestChallenge) tempEvent); this.allChallenges.add((QuestChallenge) tempEvent);
} // End if([quest]) } // End if([quest])
else { else {
tempEvent = new QuestDuel(); tempEvent = readDuel(contents.get("metadata"));
this.assembleDuelUniquedata(contents, (QuestDuel) tempEvent);
this.allDuels.add((QuestDuel) tempEvent); this.allDuels.add((QuestDuel) tempEvent);
} }
// Assemble metadata (may not be necessary later) and deck object. // Assemble metadata (may not be necessary later) and deck object.
this.assembleEventMetadata(contents, tempEvent); this.readMetadata(contents.get("metadata"), tempEvent);
tempEvent.setEventDeck(Deck.fromLines(contents)); tempEvent.setEventDeck(Deck.fromSections(contents));
} // End for(allFiles) } // End for(allFiles)
this.assembleDuelDifficultyLists(); this.assembleDuelDifficultyLists();
@@ -125,17 +126,12 @@ public class QuestEventManager {
* @param contents * @param contents
* @param qd * @param qd
*/ */
private void assembleDuelUniquedata(final List<String> contents, final QuestDuel qd) { private QuestDuel readDuel(final List<String> contents) {
final QuestDuel qd = new QuestDuel();
int eqpos; int eqpos;
String key, value; String key, value;
for (final String s : contents) { for (final String s : contents) {
if (s.equals("[metadata]")) {
break;
}
if (s.equals("[duel]")) {
continue;
}
if (s.equals("")) { if (s.equals("")) {
continue; continue;
} }
@@ -151,6 +147,7 @@ public class QuestEventManager {
qd.setName(value); qd.setName(value);
} }
} }
return qd;
} }
/** /**
@@ -162,19 +159,14 @@ public class QuestEventManager {
* @param contents * @param contents
* @param qc * @param qc
*/ */
private void assembleChallengeUniquedata(final List<String> contents, final QuestChallenge qc) { private QuestChallenge readChallenge(final List<String> contents) {
int eqpos; int eqpos;
String key, value; String key, value;
final QuestChallenge qc = new QuestChallenge();
// Unique properties // Unique properties
for (final String s : contents) { for (final String s : contents) {
if (s.equals("[metadata]")) { if (StringUtils.isBlank(s)) {
break;
}
if (s.equals("[quest]")) {
continue;
}
if (s.equals("")) {
continue; continue;
} }
@@ -224,6 +216,7 @@ public class QuestEventManager {
qc.setCardRewardList(QuestUtil.generateCardRewardList(value)); qc.setCardRewardList(QuestUtil.generateCardRewardList(value));
} }
} }
return qc;
} }
/** /**
@@ -235,7 +228,7 @@ public class QuestEventManager {
* @param contents * @param contents
* @param qe * @param qe
*/ */
private void assembleEventMetadata(final List<String> contents, final QuestEvent qe) { private void readMetadata(final List<String> contents, final QuestEvent qe) {
int eqpos; int eqpos;
String key, value; String key, value;

View File

@@ -2,6 +2,7 @@ package forge.util;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.regex.Pattern;
/** /**
* TODO: Write javadoc for this type. * TODO: Write javadoc for this type.
@@ -13,11 +14,24 @@ public class FileSection {
private FileSection() {} private FileSection() {}
public static FileSection parse(Iterable<String> lines, String kvSeparator) { public static FileSection parse(String line, String kvSeparator, String pairSeparator) {
String[] pairs = line.split(Pattern.quote(pairSeparator));
Pattern splitter = Pattern.compile(Pattern.quote(kvSeparator));
FileSection result = new FileSection(); FileSection result = new FileSection();
for (final String dd : pairs) {
final String[] v = splitter.split(dd, 2);
result.lines.put(v[0], v.length > 1 ? v[1].trim() : "");
}
return result;
}
public static FileSection parse(Iterable<String> lines, String kvSeparator) {
FileSection result = new FileSection();
Pattern splitter = Pattern.compile(Pattern.quote(kvSeparator));
for (final String dd : lines) { for (final String dd : lines) {
final String[] v = dd.split(kvSeparator, 2); final String[] v = splitter.split(dd, 2);
result.lines.put(v[0], v.length > 1 ? v[1].trim() : ""); result.lines.put(v[0], v.length > 1 ? v[1].trim() : "");
} }

View File

@@ -0,0 +1,98 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Nate
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.util;
import java.io.File;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.JOptionPane;
import net.slightlymagic.braids.util.lambda.Lambda1;
import org.apache.commons.lang3.StringUtils;
/**
* TODO: Write javadoc for this type.
*
*/
public abstract class FileStorageReader<T extends IHasName> implements IItemReader<T> {
private final File file;
public FileStorageReader(File file0) {
file = file0;
}
// only accepts numbers, letters or dashes up to 20 characters in length
/**
*
* Clean deck name.
*
* @param in
* a String
* @return a String
*/
@Override
public Map<String, T> readAll() {
final Map<String, T> result = new TreeMap<String, T>();
final ArrayList<String> fData = FileUtil.readFile(file);
Lambda1<Boolean, String> filter = getLineFilter();
for (final String s : fData) {
if (!filter.apply(s)) {
continue;
}
T item = read(s);
if ( null == item ) {
String msg = "An object stored in " + file.getPath() + " failed to load.\nPlease submit this as a bug with the mentioned file attached.";
JOptionPane.showMessageDialog(null, msg); // This becomes bugged if uncommented, but i need these messages to debug other peoples decks // Max Mtg
continue;
}
result.put( item.getName(), item );
}
return result;
}
/**
* TODO: Write javadoc for this method.
* @param file
* @return
*/
protected abstract T read(String line);
protected Lambda1<Boolean, String> getLineFilter() {
return new Lambda1<Boolean, String>() {
@Override
public Boolean apply(String arg1) {
return !StringUtils.isBlank(arg1) && !arg1.trim().startsWith("#");
}
};
}
}

View File

@@ -120,7 +120,7 @@ public class QuestWinLoseCardViewer extends FPanel {
} }
if (null == this.cache[row]) { if (null == this.cache[row]) {
final Card card = AllZone.getCardFactory().getCard(cp.getName(), null); final Card card = AllZone.getCardFactory().getCard(cp.getName(), null);
card.setCurSetCode(cp.getSet()); card.setCurSetCode(cp.getEdition());
card.setImageFilename(CardUtil.buildFilename(card)); card.setImageFilename(CardUtil.buildFilename(card));
this.cache[row] = card; this.cache[row] = card;
} }

View File

@@ -109,7 +109,7 @@ public class CardViewer extends JPanel {
} }
if (null == this.cache[row]) { if (null == this.cache[row]) {
final Card card = AllZone.getCardFactory().getCard(cp.getName(), null); final Card card = AllZone.getCardFactory().getCard(cp.getName(), null);
card.setCurSetCode(cp.getSet()); card.setCurSetCode(cp.getEdition());
card.setImageFilename(CardUtil.buildFilename(card)); card.setImageFilename(CardUtil.buildFilename(card));
this.cache[row] = card; this.cache[row] = card;
} }