From c021be76f9825e4726d346c3d7a2424e79e4e3bc Mon Sep 17 00:00:00 2001 From: RumbleBBU Date: Fri, 9 Nov 2012 10:51:32 +0000 Subject: [PATCH] More preliminary work for the quest worlds. --- .gitattributes | 1 + res/quest/world/worlds.txt | 1 + src/main/java/forge/model/FModel.java | 6 +- .../java/forge/quest/data/QuestWorld.java | 84 +++++++++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 res/quest/world/worlds.txt diff --git a/.gitattributes b/.gitattributes index 0c641127838..e545402da4a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12363,6 +12363,7 @@ res/quest/themes/Vigilance[!!-~]Meekstone[!!-~]W.thm -text res/quest/themes/White.thm -text res/quest/themes/Wolves[!!-~]WG.thm -text res/quest/themes/Zombies[!!-~]B.thm -text +res/quest/world/worlds.txt -text res/reprintSetInfo.py svneol=native#text/x-python res/sealed/ArabianExtended.sealed -text res/sealed/RtRGuildAzorius.sealed -text diff --git a/res/quest/world/worlds.txt b/res/quest/world/worlds.txt new file mode 100644 index 00000000000..5dd455ce6a8 --- /dev/null +++ b/res/quest/world/worlds.txt @@ -0,0 +1 @@ +Index:1|Name:Shandalar|Dir:shandalar|Sets:2ED, ARN, ATQ, 3ED, LEG, DRK, FEM, 4ED, ICE, CHR, HML, ALL|Banned:Chaos Orb; Falling Star \ No newline at end of file diff --git a/src/main/java/forge/model/FModel.java b/src/main/java/forge/model/FModel.java index b26e2184d2e..b3266913db2 100644 --- a/src/main/java/forge/model/FModel.java +++ b/src/main/java/forge/model/FModel.java @@ -47,6 +47,7 @@ import forge.properties.ForgeProps; import forge.properties.NewConstants; import forge.quest.QuestController; import forge.quest.data.QuestPreferences; +import forge.quest.data.QuestWorld; import forge.util.FileUtil; import forge.util.HttpUtil; import forge.util.IStorageView; @@ -95,9 +96,7 @@ public enum FModel { private final IStorageView fatPacks; private final IStorageView blocks; private final IStorageView fantasyBlocks; - - - + private final IStorageView worlds; /** * Constructor. @@ -144,6 +143,7 @@ public enum FModel { this.fatPacks = new StorageView(new FatPackData.Reader("res/blockdata/fatpacks.txt")); this.blocks = new StorageView(new CardBlock.Reader("res/blockdata/blocks.txt", editions)); this.fantasyBlocks = new StorageView(new CardBlock.Reader("res/blockdata/fantasyblocks.txt", editions)); + this.worlds = new StorageView(new QuestWorld.Reader("res/quest/world/worlds.txt")); this.match = new MatchController(); // TODO - there's got to be a better place for this...oblivion? diff --git a/src/main/java/forge/quest/data/QuestWorld.java b/src/main/java/forge/quest/data/QuestWorld.java index b9de09df991..105c4e9db05 100644 --- a/src/main/java/forge/quest/data/QuestWorld.java +++ b/src/main/java/forge/quest/data/QuestWorld.java @@ -17,6 +17,14 @@ */ package forge.quest.data; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import com.google.common.base.Function; + +import forge.util.StorageReaderFile; + /** * This function holds the "world info" for the current quest. * @@ -80,4 +88,80 @@ public class QuestWorld { public GameFormatQuest getFormat() { return format; } + + /** + * FN_GET_NAME for reader. + */ + public static final Function FN_GET_NAME = new Function() { + + public String apply(QuestWorld arg1) { + return arg1.getName(); + } + }; + + /** + * Class for reading world definitions. + */ + public static class Reader extends StorageReaderFile { + + /** + * TODO: Write javadoc for Constructor. + * @param file0 + * @param keySelector0 + */ + public Reader(String file0) { + super(file0, QuestWorld.FN_GET_NAME); + } + + /* (non-Javadoc) + * @see forge.util.StorageReaderFile#read(java.lang.String) + */ + @Override + protected QuestWorld read(String line) { + System.out.println("Reading quest worlds 3..."); + String useName = null; + String useDir = null; + int useIdx = 0; + GameFormatQuest useFormat = null; + + final List sets = new ArrayList(); + final List bannedCards = new ArrayList(); // if both empty, no format + + final String[] sParts = line.trim().split("\\|"); + + for (final String sPart : sParts) { + final String[] kv = sPart.split(":", 2); + final String key = kv[0].toLowerCase(); + if ("index".equals(key)) { + useIdx = new Integer(kv[1]); + } else if ("name".equals(key)) { + useName = kv[1]; + } else if ("dir".equals(key)) { + useDir = kv[1]; + } else if ("sets".equals(key)) { + sets.addAll(Arrays.asList(kv[1].split(", "))); + } else if ("banned".equals(key)) { + bannedCards.addAll(Arrays.asList(kv[1].split("; "))); + } + } + if (useIdx < 1) { + throw new RuntimeException("Illegal index " + useIdx + "! Check worlds.txt file"); + } + else if (useName == null) { + throw new RuntimeException("World " + useIdx + " must have a name! Check worlds.txt file"); + } + else if (useDir == null) { + throw new RuntimeException("World '" + useName + "' must have a directory! Check worlds.txt file"); + } + + if (!sets.isEmpty() || bannedCards.isEmpty()) { + useFormat = new GameFormatQuest(useName, sets, bannedCards); + } + // System.out.println("Creating quest world " + useName + " (index " + useIdx + ", dir: " + useDir); + // if (useFormat != null) { System.out.println("SETS: " + sets + "\nBANNED: " + bannedCards); } + return new QuestWorld(useIdx, useName, useDir, useFormat); + + } + + } }