diff --git a/.gitattributes b/.gitattributes
index 1d450218c94..d2b0a0c188d 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -9754,8 +9754,8 @@ src/main/java/forge/card/trigger/Trigger_TurnFaceUp.java svneol=native#text/plai
src/main/java/forge/card/trigger/Trigger_Unequip.java svneol=native#text/plain
src/main/java/forge/card/trigger/Trigger_Untaps.java svneol=native#text/plain
src/main/java/forge/card/trigger/package-info.java svneol=native#text/plain
-src/main/java/forge/deck/Deck.java -text
-src/main/java/forge/deck/DeckManager.java -text
+src/main/java/forge/deck/Deck.java svneol=native#text/plain
+src/main/java/forge/deck/DeckManager.java svneol=native#text/plain
src/main/java/forge/deck/DownloadDeck.java svneol=native#text/plain
src/main/java/forge/deck/generate/Generate2ColorDeck.java svneol=native#text/plain
src/main/java/forge/deck/generate/Generate3ColorDeck.java svneol=native#text/plain
@@ -9783,7 +9783,6 @@ src/main/java/forge/gui/ListChooser.java svneol=native#text/plain
src/main/java/forge/gui/MultiLineLabel.java svneol=native#text/plain
src/main/java/forge/gui/MultiLineLabelUI.java svneol=native#text/plain
src/main/java/forge/gui/MultiPhaseProgressMonitorWithETA.java svneol=native#text/plain
-src/main/java/forge/gui/SelectablePanel.java -text
src/main/java/forge/gui/deckeditor/CardPanelBase.java -text
src/main/java/forge/gui/deckeditor/CardPanelHeavy.java -text
src/main/java/forge/gui/deckeditor/CardPanelLite.java -text
@@ -9832,10 +9831,6 @@ src/main/java/forge/properties/NewConstants.java svneol=native#text/plain
src/main/java/forge/properties/Preferences.java svneol=native#text/plain
src/main/java/forge/properties/SavePreferencesListener.java svneol=native#text/plain
src/main/java/forge/properties/package-info.java svneol=native#text/plain
-src/main/java/forge/quest/data/DeckSingleBattle.java svneol=native#text/plain
-src/main/java/forge/quest/data/DeckSingleQuest.java svneol=native#text/plain
-src/main/java/forge/quest/data/ManagerBattle.java svneol=native#text/plain
-src/main/java/forge/quest/data/ManagerQuest.java -text
src/main/java/forge/quest/data/QuestBattleManager.java svneol=native#text/plain
src/main/java/forge/quest/data/QuestBoosterPack.java svneol=native#text/plain
src/main/java/forge/quest/data/QuestData.java svneol=native#text/plain
@@ -9867,11 +9862,8 @@ src/main/java/forge/quest/data/pet/QuestPetManager.java svneol=native#text/plain
src/main/java/forge/quest/data/pet/QuestPetPlant.java svneol=native#text/plain
src/main/java/forge/quest/data/pet/QuestPetWolf.java svneol=native#text/plain
src/main/java/forge/quest/data/pet/package-info.java svneol=native#text/plain
-src/main/java/forge/quest/gui/PanelSingleBattle.java -text
-src/main/java/forge/quest/gui/PanelSingleQuest.java -text
src/main/java/forge/quest/gui/QuestAbstractPanel.java svneol=native#text/plain
src/main/java/forge/quest/gui/QuestFrame.java svneol=native#text/plain
-src/main/java/forge/quest/gui/QuestMainPanel.java svneol=native#text/plain
src/main/java/forge/quest/gui/QuestOptions.java svneol=native#text/plain
src/main/java/forge/quest/gui/bazaar/QuestBazaarItem.java svneol=native#text/plain
src/main/java/forge/quest/gui/bazaar/QuestBazaarPanel.java svneol=native#text/plain
@@ -9940,6 +9932,7 @@ src/test/java/forge/GuiWinLoseTest.java svneol=native#text/plain
src/test/java/forge/PanelTest.java svneol=native#text/plain
src/test/java/forge/PhaseTest.java svneol=native#text/plain
src/test/java/forge/ReadBoosterPackTest.java svneol=native#text/plain
+src/test/java/forge/ReadQuestAssignmentTest.java svneol=native#text/plain
src/test/java/forge/RunTest.java svneol=native#text/plain
src/test/java/forge/TinyTest.java svneol=native#text/plain
src/test/java/forge/card/cardFactory/CardFactoryTest.java svneol=native#text/plain
diff --git a/src/main/java/forge/AllZone.java b/src/main/java/forge/AllZone.java
index 3f7f2ef3ea1..41fe213057a 100644
--- a/src/main/java/forge/AllZone.java
+++ b/src/main/java/forge/AllZone.java
@@ -17,7 +17,6 @@ import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.quest.data.QuestMatchState;
import forge.quest.data.QuestData;
-import forge.quest.data.DeckSingleQuest;
/**
* Please use public getters and setters instead of direct field access.
@@ -41,9 +40,9 @@ public final class AllZone implements NewConstants {
/** Global questData. */
private static forge.quest.data.QuestData questData = null;
-
- /** Global currentQuest. */
- private static forge.quest.data.DeckSingleQuest currentQuest = null;
+
+ /** Global QuestAssignment. */
+ private static Quest_Assignment questAssignment = null;
/** Constant NAME_CHANGER. */
private static final NameChanger NAME_CHANGER = new NameChanger();
@@ -130,25 +129,25 @@ public final class AllZone implements NewConstants {
public static void setQuestData(final QuestData questData0) {
questData = questData0;
}
-
+
/**
- *
getCurrentQuest.
+ *getQuestAssignment.
* - * @return a {@link forge.quest.data.QuestData} object. - * + * @return a {@link forge.Quest_Assignment} object. + * @since 1.0.15 */ - public static forge.quest.data.DeckSingleQuest getCurrentQuest() { - return currentQuest; + public static Quest_Assignment getQuestAssignment() { + return questAssignment; } /** - *setCurrentQuest.
+ *setQuestAssignment.
* - * @param a DeckSingleQuest object. - * + * @param assignment a {@link forge.Quest_Assignment} object. + * @since 1.0.15 */ - public static void setCurrentQuest(final DeckSingleQuest qq) { - currentQuest = qq; + public static void setQuestAssignment(final Quest_Assignment assignment) { + questAssignment = assignment; } /** diff --git a/src/main/java/forge/deck/Deck.java b/src/main/java/forge/deck/Deck.java index 323aae97065..f5bbaf5aaf1 100644 --- a/src/main/java/forge/deck/Deck.java +++ b/src/main/java/forge/deck/Deck.java @@ -1,392 +1,346 @@ -package forge.deck; - -import forge.Constant; -import forge.card.CardDb; -import forge.card.CardPool; -import forge.card.CardPoolView; -import forge.card.CardPrinted; - -import java.io.Serializable; -import java.util.*; - -/** - *Deck class.
- * - * @author Forge - * @version $Id: Deck.java 10183 2011-09-02 22:51:47Z Max mtg $ - */ -public final class Deck implements ComparableNAME="Name" */
- public static final String NAME = "Name";
- /** Constant DECK_TYPE="Deck Type" */
- public static final String DECK_TYPE = "Deck Type";
- /** Constant COMMENT="Comment" */
- public static final String COMMENT = "Comment";
- /** Constant DESCRIPTION="Description" */
- public static final String DESCRIPTION = "Description";
- /** Constant DIFFICULTY="Difficulty" */
- public static final String DIFFICULTY = "Difficulty";
-
-
- //gameType is from Constant.GameType, like Constant.GameType.Regular
- /**
- * Constructor for Deck.
- */ - public Deck() { - main = new CardPool(); - sideboard = new CardPool(); - humanExtraCards = new CardPool(); - aiExtraCards = new CardPool(); - } - - /** - *Constructor for Deck.
- * - * @param deckType a {@link java.lang.String} object. - * @param main a {@link java.util.List} object. - * @param sideboard a {@link java.util.List} object. - * @param name a {@link java.lang.String} object. - */ - public Deck(String deckType, ListConstructor for Deck.
- * - * @param type a {@link java.lang.String} object. - */ - public Deck(final String type) { - this(); - setDeckType(type); - } - - /** - *Getter for the field main.
Getter for the field sideboard.
Getter for the field humanExtraCards.
Getter for the field aiExtraCards.
getDeckType.
- * - * @return a {@link java.lang.String} object. - */ - public String getDeckType() { - return metadata.get(DECK_TYPE); - } - - //can only call this method ONCE - /** - *setDeckType.
- * - * @param deckType a {@link java.lang.String} object. - */ - void setDeckType(String deckType) { - if (this.getDeckType() != null) { - throw new IllegalStateException( - "Deck : setDeckType() error, deck type has already been set"); - } - - if (!Constant.GameType.GameTypes.contains(deckType)) { - throw new RuntimeException( - "Deck : setDeckType() error, invalid deck type - " + deckType); - } - - metadata.put(DECK_TYPE, deckType); - } - - /** - *setName.
- * - * @param s a {@link java.lang.String} object. - */ - public void setName(String s) { - metadata.put(NAME, s); - } - - /** - *getName.
- * - * @return a {@link java.lang.String} object. - */ - public String getName() { - return metadata.get(NAME); - } - - /** - *setComment.
- * - * @param comment a {@link java.lang.String} object. - */ - public void setComment(String comment) { - metadata.put(COMMENT, comment); - } - - /** - *getComment.
- * - * @return a {@link java.lang.String} object. - */ - public String getComment() { - return metadata.get(COMMENT); - - } - - /** - *addMain.
- * - * @param cardName a {@link java.lang.String} object. - */ - public void addMain(final String cardName) { addMain(CardDb.instance().getCard(cardName)); } - public void addMain(final CardPrinted card) { main.add(card); } - public void addMain(final CardPoolView list) { main.addAll(list); } - public void removeMain(final CardPrinted card) { main.remove(card); } - public void removeMain(final CardPrinted card, final int amount) { main.remove(card, amount); } - public int countMain() { return main.countAll(); } - - /** - *addSideboard.
- * - * @param cardName a {@link java.lang.String} object. - */ - public final void addSideboard(final String cardName) { addSideboard(CardDb.instance().getCard(cardName)); } - public final void addSideboard(final CardPrinted card) { sideboard.add(card); } - public final void addSideboard(final CardPrinted card, final int amount) { sideboard.add(card, amount); } - public final void addSideboard(final CardPoolView cards) { sideboard.addAll(cards); } - - /** - *countSideboard.
- * - * @return a int. - */ - public int countSideboard() { - return sideboard.countAll(); - } - - /** - *removeSideboard.
- * - * @param index a int. - * @return a {@link java.lang.String} object. - */ - public void removeFromSideboard(CardPrinted card) { - sideboard.remove(card); - } - - /** - *addHumanExtraCards.
- * - * @param cardName a {@link java.lang.String} object. - */ - public void addHumanExtraCards(final String cardName) { addHumanExtraCards(CardDb.instance().getCard(cardName)); } - public void addHumanExtraCards(final CardPrinted card) { humanExtraCards.add(card); } - public void addHumanExtraCards(final CardPoolView list) { humanExtraCards.addAll(list); } - public void removeHumanExtraCards(final CardPrinted card) { humanExtraCards.remove(card); } - public void removeHumanExtraCards(final CardPrinted card, final int amount) { humanExtraCards.remove(card, amount); } - public int countHumanExtraCards() { return main.countAll(); } - - /** - *addAIExtraCards.
- * - * @param cardName a {@link java.lang.String} object. - */ - public void addAIExtraCards(final String cardName) { addAIExtraCards(CardDb.instance().getCard(cardName)); } - public void addAIExtraCards(final CardPrinted card) { aiExtraCards.add(card); } - public void addAIExtraCards(final CardPoolView list) { aiExtraCards.addAll(list); } - public void removeAIExtraCards(final CardPrinted card) { aiExtraCards.remove(card); } - public void removeAIExtraCards(final CardPrinted card, final int amount) { aiExtraCards.remove(card, amount); } - public int countAIExtraCards() { return aiExtraCards.countAll(); } - - /** - *isDraft.
- * - * @return a boolean. - */ - public boolean isDraft() { - return getDeckType().equals(Constant.GameType.Draft); - } - - /** - *isSealed.
- * - * @return a boolean. - */ - public boolean isSealed() { - return getDeckType().equals(Constant.GameType.Sealed); - } - - /** - *isRegular.
- * - * @return a boolean. - */ - public boolean isRegular() { - return getDeckType().equals(Constant.GameType.Constructed); - } - - /** - *hashCode.
- * - * @return a int. - */ - public int hashCode() { - return getName().hashCode(); - } - - /** {@inheritDoc} */ - @Override - public String toString() { - return getName(); - } - - - // The setters and getters below are for Quest decks - /** - *setDifficulty.
- * - * @param s a {@link java.lang.String} object. - */ - public void setDifficulty(String s) { - metadata.put(DIFFICULTY, s); - } - - /** - *getDifficulty.
- * - * @return a {@link java.lang.String} object. - */ - public String getDifficulty() { - return metadata.get(DIFFICULTY); - } - - /** - *setDescription.
- * - * @param s a {@link java.lang.String} object. - */ - public void setDescription(String s) { - metadata.put(DESCRIPTION, s); - } - - /** - *getDescription.
- * - * @return a {@link java.lang.String} object. - */ - public String getDescription() { - return metadata.get(DESCRIPTION); - } - - /** - *compareTo.
- * - * @param d a {@link forge.deck.Deck} object. - * @return a int. - */ - public int compareTo(Deck d) { - return getName().compareTo(d.getName()); - } - - /** {@inheritDoc} */ - public boolean equals(Object o) { - if (o instanceof Deck) { - Deck d = (Deck) o; - return getName().equals(d.getName()); - } - return false; - } - - /** - *Getter for the field metadata.
Getter for the field metadata.
addMetaData.
- * - * @param key a {@link java.lang.String} object. - * @param value a {@link java.lang.String} object. - */ - public void addMetaData(String key, String value) { - metadata.put(key, value); - } - - public void clearSideboard() { - sideboard.clear(); - } - - public void clearMain() { - main.clear(); - - } - -} +package forge.deck; + +import forge.Constant; +import forge.card.CardDb; +import forge.card.CardPool; +import forge.card.CardPoolView; +import forge.card.CardPrinted; + +import java.io.Serializable; +import java.util.*; + +/** + *Deck class.
+ * + * @author Forge + * @version $Id$ + */ +public final class Deck implements ComparableNAME="Name" */
+ public static final String NAME = "Name";
+ /** Constant DECK_TYPE="Deck Type" */
+ public static final String DECK_TYPE = "Deck Type";
+ /** Constant COMMENT="Comment" */
+ public static final String COMMENT = "Comment";
+ /** Constant DESCRIPTION="Description" */
+ public static final String DESCRIPTION = "Description";
+ /** Constant DIFFICULTY="Difficulty" */
+ public static final String DIFFICULTY = "Difficulty";
+
+
+ //gameType is from Constant.GameType, like Constant.GameType.Regular
+ /**
+ * Constructor for Deck.
+ */ + public Deck() { + main = new CardPool(); + sideboard = new CardPool(); + } + + /** + *Constructor for Deck.
+ * + * @param deckType a {@link java.lang.String} object. + * @param main a {@link java.util.List} object. + * @param sideboard a {@link java.util.List} object. + * @param name a {@link java.lang.String} object. + */ + public Deck(String deckType, ListConstructor for Deck.
+ * + * @param type a {@link java.lang.String} object. + */ + public Deck(final String type) { + this(); + setDeckType(type); + } + + /** + *Getter for the field main.
Getter for the field sideboard.
getDeckType.
+ * + * @return a {@link java.lang.String} object. + */ + public String getDeckType() { + return metadata.get(DECK_TYPE); + } + + //can only call this method ONCE + /** + *setDeckType.
+ * + * @param deckType a {@link java.lang.String} object. + */ + void setDeckType(String deckType) { + if (this.getDeckType() != null) { + throw new IllegalStateException( + "Deck : setDeckType() error, deck type has already been set"); + } + + if (!Constant.GameType.GameTypes.contains(deckType)) { + throw new RuntimeException( + "Deck : setDeckType() error, invalid deck type - " + deckType); + } + + metadata.put(DECK_TYPE, deckType); + } + + /** + *setName.
+ * + * @param s a {@link java.lang.String} object. + */ + public void setName(String s) { + metadata.put(NAME, s); + } + + /** + *getName.
+ * + * @return a {@link java.lang.String} object. + */ + public String getName() { + return metadata.get(NAME); + } + + /** + *setComment.
+ * + * @param comment a {@link java.lang.String} object. + */ + public void setComment(String comment) { + metadata.put(COMMENT, comment); + } + + /** + *getComment.
+ * + * @return a {@link java.lang.String} object. + */ + public String getComment() { + return metadata.get(COMMENT); + + } + + /** + *addMain.
+ * + * @param cardName a {@link java.lang.String} object. + */ + public void addMain(final String cardName) { addMain(CardDb.instance().getCard(cardName)); } + public void addMain(final CardPrinted card) { main.add(card); } + public void addMain(final CardPoolView list) { main.addAll(list); } + public void removeMain(final CardPrinted card) { main.remove(card); } + public void removeMain(final CardPrinted card, final int amount) { main.remove(card, amount); } + public int countMain() { return main.countAll(); } + + /** + *addSideboard.
+ * + * @param cardName a {@link java.lang.String} object. + */ + public final void addSideboard(final String cardName) { addSideboard(CardDb.instance().getCard(cardName)); } + public final void addSideboard(final CardPrinted card) { sideboard.add(card); } + public final void addSideboard(final CardPrinted card, final int amount) { sideboard.add(card, amount); } + public final void addSideboard(final CardPoolView cards) { sideboard.addAll(cards); } + + /** + *countSideboard.
+ * + * @return a int. + */ + public int countSideboard() { + return sideboard.countAll(); + } + + /** + *removeSideboard.
+ * + * @param index a int. + * @return a {@link java.lang.String} object. + */ + public void removeFromSideboard(CardPrinted card) { + sideboard.remove(card); + } + + /** + *isDraft.
+ * + * @return a boolean. + */ + public boolean isDraft() { + return getDeckType().equals(Constant.GameType.Draft); + } + + /** + *isSealed.
+ * + * @return a boolean. + */ + public boolean isSealed() { + return getDeckType().equals(Constant.GameType.Sealed); + } + + /** + *isRegular.
+ * + * @return a boolean. + */ + public boolean isRegular() { + return getDeckType().equals(Constant.GameType.Constructed); + } + + /** + *hashCode.
+ * + * @return a int. + */ + public int hashCode() { + return getName().hashCode(); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return getName(); + } + + + // The setters and getters below are for Quest decks + /** + *setDifficulty.
+ * + * @param s a {@link java.lang.String} object. + */ + public void setDifficulty(String s) { + metadata.put(DIFFICULTY, s); + } + + /** + *getDifficulty.
+ * + * @return a {@link java.lang.String} object. + */ + public String getDifficulty() { + return metadata.get(DIFFICULTY); + } + + /** + *setDescription.
+ * + * @param s a {@link java.lang.String} object. + */ + public void setDescription(String s) { + metadata.put(DESCRIPTION, s); + } + + /** + *getDescription.
+ * + * @return a {@link java.lang.String} object. + */ + public String getDescription() { + return metadata.get(DESCRIPTION); + } + + /** + *compareTo.
+ * + * @param d a {@link forge.deck.Deck} object. + * @return a int. + */ + public int compareTo(Deck d) { + return getName().compareTo(d.getName()); + } + + /** {@inheritDoc} */ + public boolean equals(Object o) { + if (o instanceof Deck) { + Deck d = (Deck) o; + return getName().equals(d.getName()); + } + return false; + } + + /** + *Getter for the field metadata.
Getter for the field metadata.
addMetaData.
+ * + * @param key a {@link java.lang.String} object. + * @param value a {@link java.lang.String} object. + */ + public void addMetaData(String key, String value) { + metadata.put(key, value); + } + + public void clearSideboard() { + sideboard.clear(); + } + + public void clearMain() { + main.clear(); + + } + +} diff --git a/src/main/java/forge/deck/DeckManager.java b/src/main/java/forge/deck/DeckManager.java index 2e88721a471..fd2de901ca1 100644 --- a/src/main/java/forge/deck/DeckManager.java +++ b/src/main/java/forge/deck/DeckManager.java @@ -1,533 +1,487 @@ -package forge.deck; - - -import forge.Card; -import forge.Constant; -import forge.card.CardPrinted; -import forge.error.ErrorViewer; -import forge.quest.data.QuestUtil; - -import java.io.*; -import java.util.*; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.lang3.StringUtils; - -import static java.lang.Integer.parseInt; -import static java.lang.String.format; -import static java.util.Arrays.asList; - - -//reads and writeDeck Deck objects -/** - *DeckManager class.
- * - * @author Forge - * @version $Id: DeckManager.java 10146 2011-09-01 18:11:00Z Max mtg $ - */ -public class DeckManager { - /** ConstantBDKFileFilter */
- private static FilenameFilter BDKFileFilter = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".bdk");
- }
- };
-
- /** Constant DCKFileFilter */
- private static FilenameFilter DCKFileFilter = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".dck");
- }
- };
-
-
- private File deckDir;
- MapConstructor for DeckManager.
- * - * @param deckDir a {@link java.io.File} object. - */ - public DeckManager(File deckDir) { - if (deckDir == null) { - throw new IllegalArgumentException("No deck directory specified"); - } - try { - this.deckDir = deckDir; - - if (deckDir.isFile()) { - throw new IOException("Not a directory"); - } else { - deckDir.mkdirs(); - if (!deckDir.isDirectory()) { - throw new IOException("Directory can't be created"); - } - this.deckMap = new HashMapisUnique.
- * - * @param deckName a {@link java.lang.String} object. - * @return a boolean. - */ - public boolean isUnique(String deckName) { - return !deckMap.containsKey(deckName); - } - - /** - *isUniqueDraft.
- * - * @param deckName a {@link java.lang.String} object. - * @return a boolean. - */ - public boolean isUniqueDraft(String deckName) { - return !draftMap.keySet().contains(deckName); - } - - /** - *getDeck.
- * - * @param deckName a {@link java.lang.String} object. - * @return a {@link forge.deck.Deck} object. - */ - public Deck getDeck(String deckName) { - return deckMap.get(deckName); - } - - - /** - *addDeck.
- * - * @param deck a {@link forge.deck.Deck} object. - */ - public void addDeck(Deck deck) { - if (deck.getDeckType().equals(Constant.GameType.Draft)) { - throw new RuntimeException( - "DeckManager : addDeck() error, deck type is Draft"); - } - - deckMap.put(deck.getName(), deck); - } - - /** - *deleteDeck.
- * - * @param deckName a {@link java.lang.String} object. - */ - public void deleteDeck(String deckName) { - deckMap.remove(deckName); - } - - /** - *getDraftDeck.
- * - * @param deckName a {@link java.lang.String} object. - * @return an array of {@link forge.deck.Deck} objects. - */ - public Deck[] getDraftDeck(String deckName) { - if (!draftMap.containsKey(deckName)) { - throw new RuntimeException( - "DeckManager : getDraftDeck() error, deck name not found - " + deckName); - } - - return draftMap.get(deckName); - } - - /** - *addDraftDeck.
- * - * @param deck an array of {@link forge.deck.Deck} objects. - */ - public void addDraftDeck(Deck[] deck) { - checkDraftDeck(deck); - - draftMap.put(deck[0].toString(), deck); - } - - /** - *deleteDraftDeck.
- * - * @param deckName a {@link java.lang.String} object. - */ - public void deleteDraftDeck(String deckName) { - if (!draftMap.containsKey(deckName)) { - throw new RuntimeException( - "DeckManager : deleteDraftDeck() error, deck name not found - " + deckName); - } - - draftMap.remove(deckName); - } - - /** - *checkDraftDeck.
- * - * @param deck an array of {@link forge.deck.Deck} objects. - */ - private void checkDraftDeck(Deck[] deck) { - if (deck == null || deck.length != 8 || deck[0].getName().equals("") - || (!deck[0].getDeckType().equals(Constant.GameType.Draft))) { - throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck"); - } - } - - - /** - *getDecks.
- * - * @return a {@link java.util.Collection} object. - */ - public CollectiongetDraftDecks.
- * - * @return a {@link java.util.Map} object. - */ - public Mapclose.
- */ - public void close() { - writeAllDecks(); - } - - - /** - *readAllDecks.
- */ - public void readAllDecks() { - deckMap.clear(); - draftMap.clear(); - - File[] files; - - files = deckDir.listFiles(DCKFileFilter); - for (File file : files) { - Deck newDeck = readDeck(file); - deckMap.put(newDeck.getName(), newDeck); - } - - files = deckDir.listFiles(BDKFileFilter); - for (File file : files) { - Deck[] d = new Deck[8]; - - for (int i = 0; i < d.length; i++) { - d[i] = readDeck(new File(file, i + ".dck")); - } - - draftMap.put(d[0].getName(), d); - } - } - - /** - *readDeck.
- * - * @param deckFile a {@link java.io.File} object. - * @return a {@link forge.deck.Deck} object. - */ - public static Deck readDeck(File deckFile) { - - ListreadDeckOld.
- * - * @param iterator a {@link java.util.ListIterator} object. - * @return a {@link forge.deck.Deck} object. - */ - private static Deck readDeckOld(ListIteratoraddCardList.
- * - * @param lineIterator a {@link java.util.ListIterator} object. - * @param d a {@link forge.deck.Deck} object. - */ - private static void addCardList(ListIteratorderiveFileName.
- * - * @param deckName a {@link java.lang.String} object. - * @return a {@link java.lang.String} object. - */ - private String deriveFileName(String deckName) { - //skips all but the listed characters - return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", ""); - } - - /** - *writeAllDecks.
- */ - public void writeAllDecks() { - try { - //store the files that do exist - ListwriteDeck.
- * - * @param d a {@link forge.deck.Deck} object. - * @param out a {@link java.io.BufferedWriter} object. - * @throws java.io.IOException if any. - */ - private static void writeDeck(Deck d, BufferedWriter out) throws IOException { - out.write("[metadata]\n"); - - for (Entrycount.
- * - * @param src a {@link java.util.List} object. - * @return a {@link java.util.Map} object. - */ - private static MapwriteDeck.
- * - * @param d a {@link forge.deck.Deck} object. - * @param f a {@link java.io.File} object. - */ - public static void writeDeck(Deck d, File f) { - try { - BufferedWriter writer = new BufferedWriter(new FileWriter(f)); - writeDeck(d, writer); - - writer.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - - } - -} +package forge.deck; + + +import forge.Constant; +import forge.card.CardPrinted; +import forge.error.ErrorViewer; + +import java.io.*; +import java.util.*; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.lang3.StringUtils; + +import static java.lang.Integer.parseInt; +import static java.lang.String.format; +import static java.util.Arrays.asList; + + +//reads and writeDeck Deck objects +/** + *DeckManager class.
+ * + * @author Forge + * @version $Id$ + */ +public class DeckManager { + /** ConstantBDKFileFilter */
+ private static FilenameFilter BDKFileFilter = new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".bdk");
+ }
+ };
+
+ /** Constant DCKFileFilter */
+ private static FilenameFilter DCKFileFilter = new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".dck");
+ }
+ };
+
+
+ private File deckDir;
+ MapConstructor for DeckManager.
+ * + * @param deckDir a {@link java.io.File} object. + */ + public DeckManager(File deckDir) { + if (deckDir == null) { + throw new IllegalArgumentException("No deck directory specified"); + } + try { + this.deckDir = deckDir; + + if (deckDir.isFile()) { + throw new IOException("Not a directory"); + } else { + deckDir.mkdirs(); + if (!deckDir.isDirectory()) { + throw new IOException("Directory can't be created"); + } + this.deckMap = new HashMapisUnique.
+ * + * @param deckName a {@link java.lang.String} object. + * @return a boolean. + */ + public boolean isUnique(String deckName) { + return !deckMap.containsKey(deckName); + } + + /** + *isUniqueDraft.
+ * + * @param deckName a {@link java.lang.String} object. + * @return a boolean. + */ + public boolean isUniqueDraft(String deckName) { + return !draftMap.keySet().contains(deckName); + } + + /** + *getDeck.
+ * + * @param deckName a {@link java.lang.String} object. + * @return a {@link forge.deck.Deck} object. + */ + public Deck getDeck(String deckName) { + return deckMap.get(deckName); + } + + + /** + *addDeck.
+ * + * @param deck a {@link forge.deck.Deck} object. + */ + public void addDeck(Deck deck) { + if (deck.getDeckType().equals(Constant.GameType.Draft)) { + throw new RuntimeException( + "DeckManager : addDeck() error, deck type is Draft"); + } + + deckMap.put(deck.getName(), deck); + } + + /** + *deleteDeck.
+ * + * @param deckName a {@link java.lang.String} object. + */ + public void deleteDeck(String deckName) { + deckMap.remove(deckName); + } + + /** + *getDraftDeck.
+ * + * @param deckName a {@link java.lang.String} object. + * @return an array of {@link forge.deck.Deck} objects. + */ + public Deck[] getDraftDeck(String deckName) { + if (!draftMap.containsKey(deckName)) { + throw new RuntimeException( + "DeckManager : getDraftDeck() error, deck name not found - " + deckName); + } + + return draftMap.get(deckName); + } + + /** + *addDraftDeck.
+ * + * @param deck an array of {@link forge.deck.Deck} objects. + */ + public void addDraftDeck(Deck[] deck) { + checkDraftDeck(deck); + + draftMap.put(deck[0].toString(), deck); + } + + /** + *deleteDraftDeck.
+ * + * @param deckName a {@link java.lang.String} object. + */ + public void deleteDraftDeck(String deckName) { + if (!draftMap.containsKey(deckName)) { + throw new RuntimeException( + "DeckManager : deleteDraftDeck() error, deck name not found - " + deckName); + } + + draftMap.remove(deckName); + } + + /** + *checkDraftDeck.
+ * + * @param deck an array of {@link forge.deck.Deck} objects. + */ + private void checkDraftDeck(Deck[] deck) { + if (deck == null || deck.length != 8 || deck[0].getName().equals("") + || (!deck[0].getDeckType().equals(Constant.GameType.Draft))) { + throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck"); + } + } + + + /** + *getDecks.
+ * + * @return a {@link java.util.Collection} object. + */ + public CollectiongetDraftDecks.
+ * + * @return a {@link java.util.Map} object. + */ + public Mapclose.
+ */ + public void close() { + writeAllDecks(); + } + + + /** + *readAllDecks.
+ */ + public void readAllDecks() { + deckMap.clear(); + draftMap.clear(); + + File[] files; + + files = deckDir.listFiles(DCKFileFilter); + for (File file : files) { + Deck newDeck = readDeck(file); + deckMap.put(newDeck.getName(), newDeck); + } + + files = deckDir.listFiles(BDKFileFilter); + for (File file : files) { + Deck[] d = new Deck[8]; + + for (int i = 0; i < d.length; i++) { + d[i] = readDeck(new File(file, i + ".dck")); + } + + draftMap.put(d[0].getName(), d); + } + } + + /** + *readDeck.
+ * + * @param deckFile a {@link java.io.File} object. + * @return a {@link forge.deck.Deck} object. + */ + public static Deck readDeck(File deckFile) { + + ListreadDeckOld.
+ * + * @param iterator a {@link java.util.ListIterator} object. + * @return a {@link forge.deck.Deck} object. + */ + private static Deck readDeckOld(ListIteratoraddCardList.
+ * + * @param lineIterator a {@link java.util.ListIterator} object. + * @param d a {@link forge.deck.Deck} object. + */ + private static void addCardList(ListIteratorderiveFileName.
+ * + * @param deckName a {@link java.lang.String} object. + * @return a {@link java.lang.String} object. + */ + private String deriveFileName(String deckName) { + //skips all but the listed characters + return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", ""); + } + + /** + *writeAllDecks.
+ */ + public void writeAllDecks() { + try { + //store the files that do exist + ListwriteDeck.
+ * + * @param d a {@link forge.deck.Deck} object. + * @param out a {@link java.io.BufferedWriter} object. + * @throws java.io.IOException if any. + */ + private static void writeDeck(Deck d, BufferedWriter out) throws IOException { + out.write("[metadata]\n"); + + for (Entrycount.
+ * + * @param src a {@link java.util.List} object. + * @return a {@link java.util.Map} object. + */ + private static MapwriteDeck.
+ * + * @param d a {@link forge.deck.Deck} object. + * @param f a {@link java.io.File} object. + */ + public static void writeDeck(Deck d, File f) { + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(f)); + writeDeck(d, writer); + + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + +} diff --git a/src/main/java/forge/gui/SelectablePanel.java b/src/main/java/forge/gui/SelectablePanel.java deleted file mode 100644 index 5af89c1013c..00000000000 --- a/src/main/java/forge/gui/SelectablePanel.java +++ /dev/null @@ -1,43 +0,0 @@ -package forge.gui; - -import java.awt.Color; - -import javax.swing.JPanel; - - -/** - *SelectablePanel
- * VIEW - Standard selectable JPanel used for many places in the GUI. - * - */ -@SuppressWarnings("serial") -public abstract class SelectablePanel extends JPanel { - - private boolean selected = false; - protected Color backgroundColor = this.getBackground(); - - /** - *Getter for the field selected
Setter for the field selected
DeckSingleBattle
- * MODEL - Assembles and stores information from a battle deck. - * - * @author Forge - * @version $Id$ - */ -public class DeckSingleBattle { - private String deckName; - private String displayName; - private String diff; - private String desc; - private String iconFilename; - private ImageIcon icon; - private Deck deckObj; - - /** - *Constructor for DeckSingleBattle.
- * - * @param {@link java.lang.String} storing name of AI deck for this battle - */ - public DeckSingleBattle(Deck d) { - // Get deck object and properties for this opponent. - this.deckObj = d; - this.deckName = d.getName(); - this.displayName = deckObj.getMetadata("DisplayName"); - this.diff = deckObj.getMetadata("Difficulty"); - this.desc = deckObj.getMetadata("Description"); - this.iconFilename = deckObj.getMetadata("Icon"); - - // Default icon - this.icon = GuiUtils.getIconFromFile(displayName + ".jpg"); - - // If non-default icon defined, use it. Any filetype accepted. - if(!iconFilename.equals("")) { - this.icon = GuiUtils.getIconFromFile(iconFilename); - } - } - - /** - *getDifficulty()
- * Retrieve rated difficulty of this battle deck. - * - * @return {@link java.lang.String} - */ - public String getDifficulty() { - return this.diff; - } - - /** - *getDescription()
- * Retrieve description of this battle deck. - * - * @return {@link java.lang.String} - */ - public String getDescription() { - return this.desc; - } - - /** - *getDisplayName()
- * Retrieve display name of this battle deck. - * - * @return {@link java.lang.String} - */ - public String getDisplayName() { - return this.displayName; - } - - /** - *getDeckName()
- * Retrieve file name of this battle deck. - * - * @return {@link java.lang.String} - */ - public String getDeckName() { - return this.deckName; - } - - /** - *getIconFilename()
- * Retrieve file name of preferred icon - * - * @return {@link java.lang.String} - */ - public String getIconFilename() { - return this.iconFilename; - } - - /** - *getDeck()
- * Retrieve this battle deck. - * - * @return {@link java.lang.String} - */ - public Deck getDeck() { - return this.deckObj; - } - - /** - *getIcon()
- * Retrieve the icon used with this battle deck. - * - * @return {@link java.lang.String} - */ - public ImageIcon getIcon() { - return this.icon; - } - -} diff --git a/src/main/java/forge/quest/data/DeckSingleQuest.java b/src/main/java/forge/quest/data/DeckSingleQuest.java deleted file mode 100644 index 238fa6196a5..00000000000 --- a/src/main/java/forge/quest/data/DeckSingleQuest.java +++ /dev/null @@ -1,272 +0,0 @@ -package forge.quest.data; - -import java.util.ArrayList; -import java.util.List; - -import javax.swing.ImageIcon; - -import com.google.code.jyield.Generator; -import com.google.code.jyield.YieldUtils; - -import forge.AllZone; -import forge.Card; -import forge.Constant; -import forge.card.CardPrinted; -import forge.card.CardRarity; -import forge.deck.Deck; -import forge.gui.GuiUtils; - -/** - *DeckSingleQuest
- * MODEL - Assembles and stores information from a quest deck. - * - * @author Forge - * @version $Id$ - */ -public class DeckSingleQuest { - private String deckName; - private String displayName; - private String diff; - private String desc; - private String iconFilename; - private String cardReward; - - private int creditsReward; - private int numberWinsRequired; - private int AILife; - private int id; - - private boolean repeatable; - private ImageIcon icon; - private Deck deckObj; - - /** - *Constructor for DeckSingleQuest
- * - * @param {@link java.lang.String} storing name of AI deck for this quest - */ - public DeckSingleQuest(Deck d) { - // Get deck object and properties for this opponent. - this.deckObj = d; - this.deckName = d.getName(); - this.id = Integer.parseInt(deckObj.getMetadata("ID")); - this.displayName = deckObj.getMetadata("DisplayName"); - this.diff = deckObj.getMetadata("Difficulty"); - this.desc = deckObj.getMetadata("Description"); - this.iconFilename = deckObj.getMetadata("Icon"); - this.cardReward = deckObj.getMetadata("CardReward"); - this.creditsReward = Integer.parseInt(deckObj.getMetadata("CreditsReward")); - this.numberWinsRequired = Integer.parseInt(deckObj.getMetadata("NumberWinsRequired")); - this.AILife = Integer.parseInt(deckObj.getMetadata("AILife")); - - // Default icon - this.icon = GuiUtils.getIconFromFile(displayName + ".jpg"); - - // If non-default icon defined, use it. Any filetype accepted. - if(!iconFilename.equals("")) { - this.icon = GuiUtils.getIconFromFile(iconFilename); - } - - // Repeatability test - if(deckObj.getMetadata("Repeatable").equals("true")) { - this.repeatable = true; - } - else { - this.repeatable = false; - } - - } - - /** - *getID()
- * Retrieve ID number of this quest deck for recordkeeping. - * - * @return {@link java.lang.int} - */ - public int getID() { - return this.id; - } - - /** - *getDifficulty()
- * Retrieve rated difficulty of this quest deck. - * - * @return {@link java.lang.String} - */ - public String getDifficulty() { - return this.diff; - } - - /** - *getDescription()
- * Retrieve description of this quest deck. - * - * @return {@link java.lang.String} - */ - public String getDescription() { - return this.desc; - } - - /** - *getDisplayName()
- * Retrieve display name of this quest deck. - * - * @return {@link java.lang.String} - */ - public String getDisplayName() { - return this.displayName; - } - - /** - *getDeckName()
- * Retrieve file name of this quest deck. - * - * @return {@link java.lang.String} - */ - public String getDeckName() { - return this.deckName; - } - - /** - *getCardReward()
- * Retrieve cards rewarded after a win with this quest deck. - * - * @return {@link java.lang.String} - */ - private String getCardReward() { - return this.cardReward; - } - - /** - *getCardRewardList()
- * Retrieve cards rewarded after a win with this quest deck. - * - * @return String[] - */ - public ListgetNumberWinsRequired()
- * Retrieve number of wins required to play against this quest deck. - * - * @return {@link java.lang.int} - */ - public int getNumberWinsRequired() { - return this.numberWinsRequired; - } - - /** - *getAILife()
- * Retrieve starting value of life for the AI playing this quest deck. - * - * @return {@link java.lang.int} - */ - public int getAILife() { - return this.AILife; - } - - /** - *getCreditsReward()
- * Retrieve number of credits rewarded after a win against this quest deck. - * - * @return {@link java.lang.int} - */ - public int getCreditsReward() { - return this.creditsReward; - } - - /** - *getDeck()
- * Retrieve this quest deck. - * - * @return {@link forge.deck.Deck} - */ - public Deck getDeck() { - return this.deckObj; - } - - /** - *getIconFilename()
- * Retrieve file name of preferred icon - * - * @return {@link java.lang.String} - */ - public String getIconFilename() { - return this.iconFilename; - } - - /** - *getIcon()
- * Retrieve the icon used with this quest deck. - * - * @return {@link javax.swing.ImageIcon} - */ - public ImageIcon getIcon() { - return this.icon; - } - - /** - *getRepeatable.
- * Retrieve boolean indicating if this quest is repeatable. - * - */ - public boolean getRepeatable() { - return this.repeatable; - } - -} diff --git a/src/main/java/forge/quest/data/ManagerBattle.java b/src/main/java/forge/quest/data/ManagerBattle.java deleted file mode 100644 index 4cb3579693d..00000000000 --- a/src/main/java/forge/quest/data/ManagerBattle.java +++ /dev/null @@ -1,237 +0,0 @@ -package forge.quest.data; - -import forge.AllZone; -import forge.FileUtil; -import forge.deck.Deck; -import forge.deck.DeckManager; -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - -import java.io.File; -import java.util.*; - -/** - *QuestBattleManager
- * MODEL - Provides static methods to accomplish two key tasks: - * 1. Stores various AI difficulty decks and generates opponent list based on quest record. - * - * 2. Can instantiate a DeckSingleBattle for each opponent in the list. - * - * @author Forge - * @version $Id$ - */ - -// This could be combined with BattleManager and moved into QuestUtil. -public class ManagerBattle { - /** ConstantaiDecks */
- private static transient MapeasyAIDecks */
- private static transient ListmediumAIDecks */
- private static transient ListhardAIDecks */
- private static transient ListveryHardAIDecks */
- private static transient ListremoveAIDeck.
- * Removes a deck object stored in the - *{@link forge.quest.gui.main.aiDecks} map. - * - * @param deckName a {@link java.lang.String} object. - */ - public static void removeAIDeck(String deckName) { - aiDecks.remove(deckName); - } - - /** - *addAIDeck.
- * Adds a deck object stored in the - *{@link forge.quest.gui.main.aiDecks} map. - * - * @param d a {@link forge.deck.Deck} object. - */ - public static void addAIDeck(Deck d) { - aiDecks.put(d.getName(), d); - } - - /** - *getAIDeckFromMap.
- * Returns a deck object stored in the - *{@link forge.quest.gui.main.aiDecks} map. - * - * @param deckName a {@link java.lang.String} object. - * @return a {@link forge.deck.Deck} object. - */ - public static Deck getAIDeckFromMap(String deckName) { - if (!aiDecks.containsKey(deckName)) { - ErrorViewer.showError(new Exception(), - "QuestData : getAIDeckFromMap(String deckName) error, deck name not found - %s", deckName); - } - - return aiDecks.get(deckName); - } - - /** - *getAIDeckNames.
- * Returns a list of decks stored in the - * {@link forge.quest.gui.main.aiDecks} map. - * - * @return a {@link java.util.List} object. - */ - public static ListgetDeckFromFile.
- * Returns a deck object built from a file name. - * Req'd because NewConstants.QUEST.DECKS must be used. - * - * @param deckName a {@link java.lang.String} object. - * @return a {@link forge.deck.Deck} object. - */ - public static Deck getAIDeckFromFile(String deckName) { - final File file = ForgeProps.getFile(NewConstants.QUEST.DECKS); - final DeckManager manager = new DeckManager(file); - return manager.getDeck(deckName); - } - - /** - *getOpponent.
- * - * Poorly named; AllZoneUtil already has a method called getOpponents. - * ????? Mechanics of this still a mystery ????? - * - * @param aiDeck a {@link java.util.List} object. - * @param number a int. - * @return a {@link java.lang.String} object. - */ - public static String getOpponent(ListgenerateBattles.
- * Generates an array of new opponents based on current win conditions. - * - * @return an array of {@link java.lang.String} objects. - */ - public static String[] generateBattles() { - int index = AllZone.getQuestData().getDifficultyIndex(); - - if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForMediumAI(index)) { - return new String[]{ - getOpponent(easyAIDecks, 0), - getOpponent(easyAIDecks, 1), - getOpponent(easyAIDecks, 2)}; - } - - if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForMediumAI(index)) { - return new String[]{ - getOpponent(easyAIDecks, 0), - getOpponent(mediumAIDecks, 0), - getOpponent(mediumAIDecks, 1)}; - } - - if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForHardAI(index)) { - return new String[]{ - getOpponent(mediumAIDecks, 0), - getOpponent(mediumAIDecks, 1), - getOpponent(mediumAIDecks, 2)}; - } - - if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForHardAI(index)) { - return new String[]{ - getOpponent(mediumAIDecks, 0), - getOpponent(hardAIDecks, 0), - getOpponent(hardAIDecks, 1)}; - } - - if (AllZone.getQuestData().getWin() >= QuestPreferences.getWinsForVeryHardAI(index)) { - return new String[]{ - getOpponent(hardAIDecks, 0), - getOpponent(hardAIDecks, 1), - getOpponent(veryHardAIDecks, 0)}; - } - - return new String[]{ - getOpponent(hardAIDecks, 0), - getOpponent(hardAIDecks, 1), - getOpponent(hardAIDecks, 2)}; - } // End generateBattles() - - /** - *readFile.
- * A reader util for accessing the AI deck list text files. - * - * @param file a {@link java.io.File} object. - * @param aiDecks a {@link java.util.List} object. - * @return a {@link java.util.List} object. - */ - private static ListgetBattles.
- * - * Returns list of DeckSingleBattle objects storing data - * of the battles currently available. - * - * @return a {@link java.util.List} object. - */ - public static ListManagerQuest
- * MODEL - Provides static methods to work with quest-related tasks. - * - */ - -// This could be combined with BattleManager and moved into QuestUtil? -public class ManagerQuest { - /** - *getQuests
- * - * Returns list of DeckSingleQuest objects storing data - * of the quests currently available. - * - * @return a {@link java.util.List} object. - */ - - public static ListgetDeckFromFile.
- * Returns a deck object built from a file name. - * Req'd because NewConstants.QUEST.DECKS must be used. - * - * @param deckName a {@link java.lang.String} object. - * @return a {@link forge.deck.Deck} object. - */ - public static Deck getAIDeckFromFile(String deckName) { - final File file = ForgeProps.getFile(NewConstants.QUEST.DECKS); - final DeckManager manager = new DeckManager(file); - return manager.getDeck(deckName); - } -} diff --git a/src/main/java/forge/quest/data/QuestUtil.java b/src/main/java/forge/quest/data/QuestUtil.java index 528e2547b25..7a885a75ce7 100644 --- a/src/main/java/forge/quest/data/QuestUtil.java +++ b/src/main/java/forge/quest/data/QuestUtil.java @@ -1,15 +1,12 @@ package forge.quest.data; -import java.util.List; -import java.util.Map.Entry; - import forge.*; -import forge.card.CardPoolView; -import forge.card.CardPrinted; +import forge.card.CardRarity; + +import java.util.ArrayList; /** *QuestUtil class.
- * General utility class for quest tasks. * * @author Forge * @version $Id$ @@ -22,43 +19,41 @@ public class QuestUtil { * @param qd a {@link forge.quest.data.QuestData} object. * @return a {@link forge.CardList} object. */ - public static CardList getAIExtraCards(QuestData qd) { + public static CardList getComputerCreatures(final QuestData qd) { return new CardList(); } - + /** *getComputerCreatures.
- * Assembles extra cards computer will have in play. * * @param qd a {@link forge.quest.data.QuestData} object. * @param qa a {@link forge.Quest_Assignment} object. * @return a {@link forge.CardList} object. */ - public static CardList getAIExtraCards(QuestData qd, DeckSingleQuest sq) { + public static CardList getComputerCreatures(final QuestData qd, Quest_Assignment qa) { CardList list = new CardList(); - if (sq != null) { - CardPoolView compCards = sq.getDeck().getAIExtraCards(); + if (qa != null) { + ArrayListgetHumanPlantAndPet.
- * Starts up empty list of extra cards for human. - * Adds plant and pet as appropriate. * * @param qd a {@link forge.quest.data.QuestData} object. * @return a {@link forge.CardList} object. */ - public static CardList getHumanExtraCards(QuestData qd) { - System.out.println("LOOKATME"); + public static CardList getHumanPlantAndPet(final QuestData qd) { CardList list = new CardList(); if (qd.getPetManager().shouldPetBeUsed()) { @@ -74,115 +69,38 @@ public class QuestUtil { /** *getHumanPlantAndPet.
- * Checks for plant and pet, then adds extra cards for human from quest deck. - * Assembles extra cards human will have in play. * * @param qd a {@link forge.quest.data.QuestData} object. - * @param qq a DeckSingleQuest object. + * @param qa a {@link forge.Quest_Assignment} object. * @return a {@link forge.CardList} object. */ - public static CardList getHumanExtraCards(QuestData qd, DeckSingleQuest sq) { - CardList list = getHumanExtraCards(qd); + public static CardList getHumanPlantAndPet(final QuestData qd, Quest_Assignment qa) { + CardList list = getHumanPlantAndPet(qd); - /*if (sq != null) { - ListextraCardBuilder.
- * Assembles card objects for extra cards and tokens for AI and human. - * - * @param String card name - * @return Card object. - */ - public static Card extraCardBuilder(String s) { - Card c = null; - int i; - - if(s.substring(0,5).equals("TOKEN")) { - String[] tokenProps = s.split("\\|"); - - if(tokenProps.length < 6) { - System.err.println("QuestUtil > extraCardBuilder() reports an " + - "incomplete token in the current deck.\n"+ - "Token should follow the form:\n"+ - "TOKEN|color|attack|defense|name|type|type...\n"+ - "For example: TOKEN|G|0|1|sheep|Creature"); - return c; - } - else { - c = new Card(); - - c.setManaCost("0"); - c.addColor(tokenProps[1]); - c.setBaseAttack(Integer.parseInt(tokenProps[2])); - c.setBaseDefense(Integer.parseInt(tokenProps[3])); - - // Uppercase each word in name - StringBuilder name = new StringBuilder(tokenProps[4]); - i = 0; - do { - name.replace(i, i + 1, name.substring(i,i + 1).toUpperCase()); - i = name.indexOf(" ", i) + 1; - } while (i > 0 && i < name.length()); - c.setName(name.toString()); - - i = 4; - while(iPanelSingleBattle
- * VIEW - A selectable panel for battles available in Quest mode. - * - */ -@SuppressWarnings("serial") -public class PanelSingleBattle extends SelectablePanel { - - private final DeckSingleBattle battle; - - public PanelSingleBattle(DeckSingleBattle b) { - battle = b; - final JPanel centerPanel = new JPanel(); - - this.setLayout(new BorderLayout(5, 5)); - - // Icon stuff - JLabel iconLabel; - - if (battle.getIcon() == null) { - iconLabel = new JLabel(GuiUtils.getEmptyIcon(40, 40)); - } else { - iconLabel = new JLabel(GuiUtils.getResizedIcon(battle.getIcon(), 40, 40)); - } - - iconLabel.setBorder(new LineBorder(Color.BLACK)); - iconLabel.setAlignmentY(TOP_ALIGNMENT); - - JPanel iconPanel = new JPanel(new BorderLayout()); - iconPanel.setOpaque(false); - iconPanel.add(iconLabel, BorderLayout.NORTH); - this.add(iconPanel, BorderLayout.WEST); - - centerPanel.setOpaque(false); - centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); - this.add(centerPanel, BorderLayout.CENTER); - - JPanel centerTopPanel = new JPanel(); - centerTopPanel.setOpaque(false); - centerTopPanel.setAlignmentX(LEFT_ALIGNMENT); - centerTopPanel.setLayout(new BoxLayout(centerTopPanel, BoxLayout.X_AXIS)); - - JLabel nameLabel = new JLabel(battle.getDisplayName()); - GuiUtils.setFontSize(nameLabel, 20); - nameLabel.setAlignmentY(BOTTOM_ALIGNMENT); - centerTopPanel.add(nameLabel); - - GuiUtils.addExpandingHorizontalSpace(centerTopPanel); - - JLabel difficultyLabel = new JLabel(battle.getDifficulty()); - difficultyLabel.setAlignmentY(BOTTOM_ALIGNMENT); - centerTopPanel.add(difficultyLabel); - centerPanel.add(centerTopPanel); - - GuiUtils.addGap(centerPanel); - - JLabel descriptionLabel = new JLabel(battle.getDescription()); - descriptionLabel.setAlignmentX(LEFT_ALIGNMENT); - centerPanel.add(descriptionLabel); - - this.setMaximumSize(new Dimension(Integer.MAX_VALUE, 80)); - this.setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(5, 5, 5, 5))); - } - - /** - *getIconFilename()
- * Retrieves filename of icon used in this panel's display. - * - * @return - */ - public String getIconFilename() { - return this.battle.getIconFilename(); - } - - /** - *getQuest()
- * - * @return the DeckSingleBattle model associated with this panel. - */ - public DeckSingleBattle getBattle() { - return this.battle; - } -} diff --git a/src/main/java/forge/quest/gui/PanelSingleQuest.java b/src/main/java/forge/quest/gui/PanelSingleQuest.java deleted file mode 100644 index b4f119ca457..00000000000 --- a/src/main/java/forge/quest/gui/PanelSingleQuest.java +++ /dev/null @@ -1,110 +0,0 @@ -package forge.quest.gui; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; - -import javax.swing.BoxLayout; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EmptyBorder; -import javax.swing.border.LineBorder; - -import forge.gui.GuiUtils; -import forge.gui.SelectablePanel; -import forge.quest.data.DeckSingleQuest; - -/** - *PanelSingleQuest
- * VIEW - A selectable panel for quests available in Quest mode. - * - */ -@SuppressWarnings("serial") -public class PanelSingleQuest extends SelectablePanel { - - private final DeckSingleQuest quest; - - public PanelSingleQuest(DeckSingleQuest q) { - quest = q; - final JPanel centerPanel = new JPanel(); - - this.setLayout(new BorderLayout(5, 5)); - - JLabel iconLabel; - - if (quest.getIcon() == null) { - iconLabel = new JLabel(GuiUtils.getEmptyIcon(40, 40)); - } else { - iconLabel = new JLabel(GuiUtils.getResizedIcon(quest.getIcon(), 40, 40)); - } - - iconLabel.setBorder(new LineBorder(Color.BLACK)); - iconLabel.setAlignmentY(TOP_ALIGNMENT); - - JPanel iconPanel = new JPanel(new BorderLayout()); - iconPanel.setOpaque(false); - iconPanel.add(iconLabel, BorderLayout.NORTH); - this.add(iconPanel, BorderLayout.WEST); - - centerPanel.setOpaque(false); - centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); - this.add(centerPanel, BorderLayout.CENTER); - - JPanel centerTopPanel = new JPanel(); - centerTopPanel.setOpaque(false); - centerTopPanel.setAlignmentX(LEFT_ALIGNMENT); - centerTopPanel.setLayout(new BoxLayout(centerTopPanel, BoxLayout.X_AXIS)); - - JLabel nameLabel = new JLabel(quest.getDisplayName()); - GuiUtils.setFontSize(nameLabel, 20); - nameLabel.setAlignmentY(BOTTOM_ALIGNMENT); - centerTopPanel.add(nameLabel); - - GuiUtils.addExpandingHorizontalSpace(centerTopPanel); - - JLabel difficultyLabel = new JLabel(quest.getDifficulty()); - difficultyLabel.setAlignmentY(BOTTOM_ALIGNMENT); - centerTopPanel.add(difficultyLabel); - centerPanel.add(centerTopPanel); - - GuiUtils.addGap(centerPanel); - - JLabel descriptionLabel = new JLabel(quest.getDescription()); - descriptionLabel.setAlignmentX(LEFT_ALIGNMENT); - centerPanel.add(descriptionLabel); - - // Temporarily removed; no meaning yet (all quests repeat anyway) - /*JLabel repeatabilityLabel; - if (quest.getRepeatable()) { - repeatabilityLabel = new JLabel("This quest is repeatable"); - } else { - repeatabilityLabel = new JLabel("This quest is not repeatable"); - } - - GuiUtils.addGap(centerPanel); - centerPanel.add(repeatabilityLabel);*/ - - this.setMaximumSize(new Dimension(Integer.MAX_VALUE, 80)); - this.setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(5, 5, 5, 5))); - } - - /** - *getIconFilename()
- * Retrieves filename of icon used in this panel's display. - * - * @return - */ - public String getIconFilename() { - return this.quest.getIconFilename(); - } - - /** - *getQuest()
- * - * @return the DeckSingleQuest model associated with this panel. - */ - public DeckSingleQuest getQuest() { - return this.quest; - } -} diff --git a/src/main/java/forge/quest/gui/QuestFrame.java b/src/main/java/forge/quest/gui/QuestFrame.java index 0fad3534028..d72750139ce 100644 --- a/src/main/java/forge/quest/gui/QuestFrame.java +++ b/src/main/java/forge/quest/gui/QuestFrame.java @@ -3,6 +3,7 @@ package forge.quest.gui; import forge.AllZone; import forge.gui.GuiUtils; import forge.quest.gui.bazaar.QuestBazaarPanel; +import forge.quest.gui.main.QuestMainPanel; import forge.view.swing.OldGuiNewGame; import javax.swing.*; diff --git a/src/main/java/forge/quest/gui/QuestMainPanel.java b/src/main/java/forge/quest/gui/QuestMainPanel.java deleted file mode 100644 index 02f19dcddea..00000000000 --- a/src/main/java/forge/quest/gui/QuestMainPanel.java +++ /dev/null @@ -1,819 +0,0 @@ -package forge.quest.gui; - - -import forge.*; -import forge.deck.Deck; -import forge.gui.GuiUtils; -import forge.gui.SelectablePanel; -import forge.gui.deckeditor.DeckEditorQuest; -import forge.gui.deckeditor.DeckEditorShop; -import forge.quest.data.DeckSingleBattle; -import forge.quest.data.ManagerBattle; -import forge.quest.data.QuestData; -import forge.quest.data.DeckSingleQuest; -import forge.quest.data.ManagerQuest; -import forge.quest.data.item.QuestItemZeppelin; - -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import javax.swing.border.EtchedBorder; -import javax.swing.border.TitledBorder; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.*; -import java.util.List; - - -/** - *QuestMainPanel class.
- * VIEW - handler for main screen of Quest GUI. - * - * @author Forge - * @version $Id$ - */ -public class QuestMainPanel extends QuestAbstractPanel { - /** ConstantserialVersionUID=6142934729724012402L */
- private static final long serialVersionUID = 6142934729724012402L;
-
- private forge.quest.data.QuestData questData;
-
- JLabel creditsLabel = new JLabel();
- JLabel lifeLabel = new JLabel();
- JLabel statsLabel = new JLabel();
- JLabel titleLabel = new JLabel();
- JLabel nextQuestLabel = new JLabel();
-
- JComboBox petComboBox = new JComboBox();
- JComboBox deckComboBox = new JComboBox();
-
- JButton questButton = new JButton("Quests");
- JButton playButton = new JButton("Play");
-
- private SelectablePanel lastPanelSelected;
-
- JPanel nextMatchPanel = new JPanel();
- CardLayout nextMatchLayout;
-
- boolean isShowingQuests = false;
- private JCheckBox devModeCheckBox = new JCheckBox("Developer Mode");
- //private JCheckBox newGUICheckbox = new JCheckBox("Use new UI", true);
- private JCheckBox smoothLandCheckBox = new JCheckBox("Adjust AI Land");
- private JCheckBox petCheckBox = new JCheckBox("Summon Pet");
-
- private JCheckBox plantBox = new JCheckBox("Summon Plant");
- /** Constant NO_DECKS_AVAILABLE="No decks available" */
- private static final String NO_DECKS_AVAILABLE = "No decks available";
- /** Constant BATTLES="Battles" */
- private static final String BATTLES = "Battles";
- /** Constant QUESTS="Quests" */
- private static final String QUESTS = "Quests";
-
- //TODO: Make this ordering permanent
- /** Constant lastUsedDeck="//TODO: Make this ordering permanent" */
- private static String lastUsedDeck;
- private JButton zeppelinButton = new JButton("LaunchConstructor for QuestMainPanel.
- * - * @param mainFrame a {@link forge.quest.gui.QuestFrame} object. - */ - public QuestMainPanel(QuestFrame mainFrame) { - super(mainFrame); - questData = AllZone.getQuestData(); - - initUI(); - } - - /** - *initUI.
- */ - private void initUI() { - refresh(); - this.setLayout(new BorderLayout(5, 5)); - JPanel centerPanel = new JPanel(new BorderLayout()); - this.add(centerPanel, BorderLayout.CENTER); - - JPanel northPanel = createStatusPanel(); - this.add(northPanel, BorderLayout.NORTH); - - JPanel eastPanel = createSidePanel(); - this.add(eastPanel, BorderLayout.EAST); - - JPanel matchSettingsPanel = createMatchSettingsPanel(); - centerPanel.add(matchSettingsPanel, BorderLayout.SOUTH); - - centerPanel.add(nextMatchPanel, BorderLayout.CENTER); - this.setBorder(new EmptyBorder(5, 5, 5, 5)); - - } - - /** - *createStatusPanel.
- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createStatusPanel() { - JPanel northPanel = new JPanel(); - JLabel modeLabel; - JLabel difficultyLabel;//Create labels at the top - titleLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 28)); - titleLabel.setAlignmentX(LEFT_ALIGNMENT); - northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS)); - northPanel.add(titleLabel); - - northPanel.add(Box.createVerticalStrut(5)); - - JPanel statusPanel = new JPanel(); - statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); - statusPanel.setAlignmentX(LEFT_ALIGNMENT); - - modeLabel = new JLabel(questData.getMode()); - statusPanel.add(modeLabel); - statusPanel.add(Box.createHorizontalGlue()); - - difficultyLabel = new JLabel(questData.getDifficulty()); - statusPanel.add(difficultyLabel); - statusPanel.add(Box.createHorizontalGlue()); - - statusPanel.add(statsLabel); - - northPanel.add(statusPanel); - return northPanel; - } - - /** - *createSidePanel.
- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createSidePanel() { - JPanel panel = new JPanel(); - JPanel optionsPanel; //Create options checkbox list - optionsPanel = createOptionsPanel(); - - ListcreateOptionsPanel.
- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createOptionsPanel() { - JPanel optionsPanel; - optionsPanel = new JPanel(); - optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS)); - - //optionsPanel.add(this.newGUICheckbox); - optionsPanel.add(Box.createVerticalStrut(5)); - optionsPanel.add(this.smoothLandCheckBox); - optionsPanel.add(Box.createVerticalStrut(5)); - optionsPanel.add(this.devModeCheckBox); - optionsPanel.setBorder(new TitledBorder(new EtchedBorder(), "Options")); - return optionsPanel; - } - - /** - *createMatchSettingsPanel.
- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createMatchSettingsPanel() { - - JPanel matchPanel = new JPanel(); - matchPanel.setLayout(new BoxLayout(matchPanel, BoxLayout.Y_AXIS)); - - JPanel deckPanel = new JPanel(); - deckPanel.setLayout(new BoxLayout(deckPanel, BoxLayout.X_AXIS)); - - JLabel deckLabel = new JLabel("Use Deck"); - deckPanel.add(deckLabel); - GuiUtils.addGap(deckPanel); - - this.deckComboBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - playButton.setEnabled(canGameBeLaunched()); - lastUsedDeck = (String) deckComboBox.getSelectedItem(); - } - }); - - deckPanel.add(this.deckComboBox); - GuiUtils.addGap(deckPanel); - - JButton editDeckButton = new JButton("Deck Editor"); - editDeckButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - showDeckEditor(); - } - }); - deckPanel.add(editDeckButton); - deckPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, deckPanel.getPreferredSize().height)); - deckPanel.setAlignmentX(LEFT_ALIGNMENT); - matchPanel.add(deckPanel); - - - GuiUtils.addGap(matchPanel); - - if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { - JPanel fantasyPanel = new JPanel(); - fantasyPanel.setLayout(new BorderLayout()); - - JPanel petPanel = new JPanel(); - petPanel.setLayout(new BoxLayout(petPanel, BoxLayout.X_AXIS)); - - this.petCheckBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - if (petCheckBox.isSelected()) { - questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); - } else { - questData.getPetManager().setSelectedPet(null); - } - - petComboBox.setEnabled(petCheckBox.isSelected()); - } - }); - - petPanel.add(this.petCheckBox); - GuiUtils.addGap(petPanel); - this.petComboBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - if (petCheckBox.isSelected()) { - questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); - } else { - questData.getPetManager().setSelectedPet(null); - } - } - }); - this.petComboBox.setMaximumSize( - new Dimension(Integer.MAX_VALUE, - (int) this.petCheckBox.getPreferredSize().getHeight())); - petPanel.add(this.petComboBox); - - this.plantBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - questData.getPetManager().usePlant = plantBox.isSelected(); - } - }); - - GuiUtils.addGap(petPanel, 10); - petPanel.add(this.plantBox); - petPanel.setMaximumSize(petPanel.getPreferredSize()); - petPanel.setAlignmentX(LEFT_ALIGNMENT); - - fantasyPanel.add(petPanel, BorderLayout.WEST); - - zeppelinButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - questData.randomizeOpponents(); - refreshNextMatchPanel(); - QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); - zeppelin.setZeppelinUsed(true); - zeppelinButton.setEnabled(false); - } - }); - - zeppelinButton.setMaximumSize(zeppelinButton.getPreferredSize()); - zeppelinPanel.setLayout(new BorderLayout()); - - fantasyPanel.add(zeppelinPanel, BorderLayout.EAST); - fantasyPanel.setAlignmentX(Component.LEFT_ALIGNMENT); - matchPanel.add(fantasyPanel); - } - return matchPanel; - } - - /** - *createBattlePanel
- * Returns a JPanel containing PanelSingleBattle instances for each battle. - * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createBattlePanel() { - JPanel pan = new JPanel(); - pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS)); - pan.setBorder(new TitledBorder(new EtchedBorder(), "Available Battles")); - PanelSingleBattle pb; - - ListcreateQuestPanel.
- * Returns a JPanel containing PanelSingleQuest instances for each battle. - * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createQuestPanel() { - JPanel pan = new JPanel(); - pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS)); - pan.setBorder(new TitledBorder(new EtchedBorder(), "Available Quests")); - PanelSingleQuest pq; - - Listrefresh.
- */ - void refresh() { - AllZone.getQuestData().saveData(); - - devModeCheckBox.setSelected(Constant.Runtime.DevMode[0]); - smoothLandCheckBox.setSelected(Constant.Runtime.Smooth[0]); - //newGUICheckbox.setSelected(OldGuiNewGame.preferences.newGui); - - creditsLabel.setText(" " + questData.getCredits()); - statsLabel.setText(questData.getWin() + " wins / " + questData.getLost() + " losses"); - titleLabel.setText(questData.getRank()); - - //copy lastUsedDeck as removal triggers selection change. - String lastUsedDeck = QuestMainPanel.lastUsedDeck; - deckComboBox.removeAllItems(); - - if (questData.getDeckNames().size() > 0) { - deckComboBox.setEnabled(true); - - ListrefreshNextMatchPanel.
- */ - private void refreshNextMatchPanel() { - nextMatchPanel.removeAll(); - nextMatchLayout = new CardLayout(); - nextMatchPanel.setLayout(nextMatchLayout); - nextMatchPanel.add(createBattlePanel(), BATTLES); - nextMatchPanel.add(createQuestPanel(), QUESTS); - if (isShowingQuests) { - this.nextMatchLayout.show(nextMatchPanel, QUESTS); - } else { - this.nextMatchLayout.show(nextMatchPanel, BATTLES); - } - } - - /** - *nextQuestInWins.
- * - * @return a int. - */ - private int nextQuestInWins() { - - // Number of wins was 25, lowereing the number to 20 to help short term questers. - if (questData.getWin() < 20) { - return 20 - questData.getWin(); - } - - // The int mul has been lowered by one, should face special opps more frequently. - int questsPlayed = questData.getQuestsPlayed(); - int mul = 5; - - if (questData.getInventory().hasItem("Zeppelin")) { - mul = 3; - } else if (questData.getInventory().hasItem("Map")) { - mul = 4; - } - - int delta = (questsPlayed * mul) - questData.getWin(); - - return (delta > 0) ? delta : 0; - } - - - /** - *showDeckEditor.
- */ - void showDeckEditor() { - Command exit = new Command() { - private static final long serialVersionUID = -5110231879431074581L; - - public void execute() { - //saves all deck data - AllZone.getQuestData().saveData(); - - new QuestFrame(); - } - }; - - DeckEditorQuest g = new DeckEditorQuest(); - - g.show(exit); - g.setVisible(true); - mainFrame.dispose(); - }//deck editor button - - /** - *showBazaar.
- */ - void showBazaar() { - mainFrame.showBazaarPane(); - } - - /** - *showCardShop.
- */ - void showCardShop() { - Command exit = new Command() { - private static final long serialVersionUID = 8567193482568076362L; - - public void execute() { - //saves all deck data - AllZone.getQuestData().saveData(); - - new QuestFrame(); - } - }; - - DeckEditorShop g = new DeckEditorShop(questData); - - g.show(exit); - g.setVisible(true); - - this.mainFrame.dispose(); - - }//card shop button - - /** - *launchGame.
- */ - private void launchGame() { - //TODO: This is a temporary hack to see if the image cache affects the heap usage significantly. - ImageCache.clear(); - - QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); - zeppelin.setZeppelinUsed(false); - questData.randomizeOpponents(); - - String humanDeckName = (String) deckComboBox.getSelectedItem(); - Deck humanDeck = questData.getDeck(humanDeckName); - Constant.Runtime.HumanDeck[0] = humanDeck; - moveDeckToTop(humanDeckName); - - Constant.Quest.oppIconName[0] = getMatchIcon(); - - // Dev Mode occurs before Display - Constant.Runtime.DevMode[0] = devModeCheckBox.isSelected(); - - //DO NOT CHANGE THIS ORDER, GuiDisplay needs to be created before cards are added - //if (newGUICheckbox.isSelected()) { - AllZone.setDisplay(new GuiDisplay4()); - //} else { - // AllZone.setDisplay(new GuiDisplay3()); - //} - - //OldGuiNewGame.preferences.newGui = newGUICheckbox.isSelected(); - - Constant.Runtime.Smooth[0] = smoothLandCheckBox.isSelected(); - - AllZone.getMatchState().reset(); - if (isShowingQuests) { - setupQuest(humanDeck); - } else { - setupBattle(humanDeck); - } - - AllZone.getQuestData().saveData(); - - AllZone.getDisplay().setVisible(true); - mainFrame.dispose(); - } - - - /** - *setupBattle.
- * - * @param humanDeck a {@link forge.deck.Deck} object. - */ - void setupBattle(Deck humanDeck) { - Deck computer = ((PanelSingleBattle) lastPanelSelected).getBattle().getDeck(); - Constant.Runtime.ComputerDeck[0] = computer; - - AllZone.getGameAction().newGame(humanDeck, computer, forge.quest.data.QuestUtil.getHumanExtraCards(questData), - new CardList(), questData.getLife(), 20, null); - } - - /** - *setupQuest.
- * - * @param humanDeck a {@link forge.deck.Deck} object. - */ - private void setupQuest(Deck humanDeck) { - DeckSingleQuest selectedQuest = ((PanelSingleQuest) lastPanelSelected).getQuest(); - AllZone.setCurrentQuest(selectedQuest); - - Deck computerDeck = ManagerBattle.getAIDeckFromFile("quest" + selectedQuest.getID()); - Constant.Runtime.ComputerDeck[0] = computerDeck; - - int extraLife = 0; - - if (questData.getInventory().getItemLevel("Gear") == 2) { - extraLife = 3; - } - - AllZone.getGameAction().newGame(humanDeck, computerDeck, - forge.quest.data.QuestUtil.getHumanExtraCards(questData, selectedQuest), new CardList(), - questData.getLife() + extraLife, selectedQuest.getAILife(), selectedQuest); - - } - - /** - *getMatchIcon.
- * - * @return a {@link java.lang.String} object. - */ - String getMatchIcon() { - String oppIconName; - - if (isShowingQuests) { - PanelSingleQuest selectedQuest = (PanelSingleQuest) lastPanelSelected; - oppIconName = selectedQuest.getIconFilename(); - } else { - PanelSingleBattle selectedBattle = (PanelSingleBattle) lastPanelSelected; - oppIconName = selectedBattle.getIconFilename(); - } - return oppIconName; - } - - /** - *toggleBattleQuest.
- * Toggles view between battle and quest screen. - */ - void toggleBattleQuest() { - if (isShowingQuests) { - isShowingQuests = false; - questButton.setText("Quests"); - } else { - isShowingQuests = true; - questButton.setText("Battles"); - } - - if (lastPanelSelected != null) { - lastPanelSelected.setSelected(false); - } - - lastPanelSelected = null; - - refresh(); - } - - /** - *SelectionAdapter
- * Handles (de)selection of various SelectablePanel instances using lastPanelSelected field. - * Also toggles launch button after (de)selection. - * - */ - class SelectionAdapter extends MouseAdapter { - SelectablePanel targetPanel; - - SelectionAdapter(SelectablePanel sp) { - super(); - this.targetPanel = sp; - } - - @Override - public void mouseClicked(MouseEvent mouseEvent) { - // Deselect previous - if (lastPanelSelected != null) { - lastPanelSelected.setSelected(false); - } - - targetPanel.setSelected(true); - - lastPanelSelected = targetPanel; - playButton.setEnabled(canGameBeLaunched()); - } - - } - - /** - *moveDeckToTop.
- * - * @param humanDeckName a {@link java.lang.String} object. - */ - private void moveDeckToTop(String humanDeckName) { - QuestMainPanel.lastUsedDeck = humanDeckName; - } - - - /** - *canGameBeLaunched.
- * - * @return a boolean. - */ - boolean canGameBeLaunched() { - return !(NO_DECKS_AVAILABLE.equals(deckComboBox.getSelectedItem()) || lastPanelSelected == null); - } - - /** {@inheritDoc} */ - @Override - public void refreshState() { - this.refresh(); - } - -} diff --git a/src/test/java/forge/ReadQuestAssignmentTest.java b/src/test/java/forge/ReadQuestAssignmentTest.java new file mode 100644 index 00000000000..9e426d40bbd --- /dev/null +++ b/src/test/java/forge/ReadQuestAssignmentTest.java @@ -0,0 +1,41 @@ +package forge; + +import forge.error.ErrorViewer; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; +import org.testng.annotations.Test; + +/** + * Created by IntelliJ IDEA. + * User: dhudson + */ +@Test(groups = {"UnitTest"}, timeOut = 1000) +public class ReadQuestAssignmentTest implements NewConstants { + /** + * + * + */ + @Test(groups = {"UnitTest", "fast"}, timeOut = 1000) + public void ReadQuestAssignmentTest1() { + try { + ReadQuest_Assignment read = new ReadQuest_Assignment(ForgeProps.getFile(QUEST.QUESTS), null); + + javax.swing.SwingUtilities.invokeAndWait(read); + // read.run(); + + Quest_Assignment qa[] = new Quest_Assignment[read.allQuests.size()]; + read.allQuests.toArray(qa); + for (int i = 0; i < qa.length; i++) { + System.out.println(qa[i].getId()); + System.out.println(qa[i].getName()); + System.out.println(qa[i].getDesc()); + System.out.println(qa[i].getDifficulty()); + System.out.println(qa[i].isRepeatable()); + System.out.println(qa[i].getRequiredNumberWins()); + } + } catch (Exception ex) { + ErrorViewer.showError(ex); + System.out.println("Error reading file " + ex); + } + } +}