unify preference handling

remove a good bit of cruft
This commit is contained in:
myk
2013-03-08 09:58:27 +00:00
parent f7bfa50343
commit c1bf5c18b1
372 changed files with 2144 additions and 34676 deletions

View File

@@ -156,7 +156,7 @@ public enum FControl {
// Preload quest data if present
final File dirQuests = new File(NewConstants.QUEST_SAVE_DIR);
final String questname = Singletons.getModel().getQuestPreferences().getPreference(QPref.CURRENT_QUEST);
final String questname = Singletons.getModel().getQuestPreferences().getPref(QPref.CURRENT_QUEST);
final File data = new File(dirQuests.getPath(), questname);
if (data.exists()) {
Singletons.getModel().getQuest().load(QuestDataIO.loadData(data));

View File

@@ -47,7 +47,7 @@ public class CardCollections {
this.constructed = new StorageImmediatelySerialized<Deck>(new DeckSerializer(new File(NewConstants.DECK_CONSTRUCTED_DIR), true));
this.draft = new StorageImmediatelySerialized<DeckGroup>(new DeckGroupSerializer(new File(NewConstants.DECK_DRAFT_DIR)));
this.sealed = new StorageImmediatelySerialized<DeckGroup>(new DeckGroupSerializer(new File(NewConstants.DECK_SEALED_DIR)));
this.cube = new StorageImmediatelySerialized<Deck>(new DeckSerializer(new File(NewConstants.DECK_CUBE_DIR.defaultLoc)));
this.cube = new StorageImmediatelySerialized<Deck>(new DeckSerializer(new File(NewConstants.DECK_CUBE_DIR)));
this.scheme = new StorageImmediatelySerialized<Deck>(new DeckSerializer(new File(NewConstants.DECK_SCHEME_DIR)));
this.plane = new StorageImmediatelySerialized<Deck>(new DeckSerializer(new File(NewConstants.DECK_PLANE_DIR)));

View File

@@ -33,6 +33,7 @@ import org.apache.commons.lang3.tuple.Pair;
import forge.deck.Deck;
import forge.deck.DeckGroup;
import forge.game.player.PlayerType;
import forge.properties.NewConstants;
import forge.util.FileSection;
import forge.util.FileUtil;
import forge.util.storage.IStorage;
@@ -62,7 +63,7 @@ public class OldDeckParser {
*/
public OldDeckParser(final IStorage<Deck> constructed2, final IStorage<DeckGroup> draft2,
final IStorage<DeckGroup> sealed2, final IStorage<Deck> cube2) {
this.deckDir = new File("res/decks");
this.deckDir = new File(NewConstants.DECK_BASE_DIR);
this.sealed = sealed2;
this.constructed = constructed2;
this.cube = cube2;

View File

@@ -32,7 +32,7 @@ public class GuiDownloadPrices extends GuiDownloader {
@Override
protected ArrayList<DownloadObject> getNeededImages() {
final File f = new File(NewConstants.QUEST_CARD_PRICE_FILE.userPrefLoc);
final File f = new File(NewConstants.QUEST_CARD_PRICE_FILE);
return Lists.newArrayList(new DownloadObject(NewConstants.URL_PRICE_DOWNLOAD, f));
}
}

View File

@@ -358,7 +358,6 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
while ((len = in.read(buf)) != -1) {
// user cancelled
if (this.cancel) {
conn.disconnect();
in.close();
out.flush();
out.close();
@@ -371,7 +370,6 @@ public abstract class GuiDownloader extends DefaultBoundedRangeModel implements
out.write(buf, 0, len);
} // while - read and write file
conn.disconnect();
in.close();
out.flush();
out.close();

View File

@@ -131,8 +131,7 @@ public enum CSubmenuQuestData implements ICDoc {
// If there are quests available, force select.
if (arrQuests.size() > 0) {
final String questname = Singletons.getModel().getQuestPreferences()
.getPreference(QPref.CURRENT_QUEST);
final String questname = Singletons.getModel().getQuestPreferences().getPref(QPref.CURRENT_QUEST);
// Attempt to select previous quest.
if (arrQuests.get(questname) != null) {
@@ -282,7 +281,7 @@ public enum CSubmenuQuestData implements ICDoc {
Singletons.getModel().getQuest().save();
// Save in preferences.
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_QUEST, questName + ".dat");
Singletons.getModel().getQuestPreferences().setPref(QPref.CURRENT_QUEST, questName + ".dat");
Singletons.getModel().getQuestPreferences().save();
update();
@@ -294,7 +293,7 @@ public enum CSubmenuQuestData implements ICDoc {
.getLstQuests().getSelectedQuest());
// Save in preferences.
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_QUEST,
Singletons.getModel().getQuestPreferences().setPref(QPref.CURRENT_QUEST,
Singletons.getModel().getQuest().getName() + ".dat");
Singletons.getModel().getQuestPreferences().save();

View File

@@ -32,7 +32,7 @@ public enum CSubmenuQuestDecks implements ICDoc {
@Override
public void execute() {
currentDeck = VSubmenuQuestDecks.SINGLETON_INSTANCE.getLstDecks().getSelectedDeck();
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_DECK, currentDeck.toString());
Singletons.getModel().getQuestPreferences().setPref(QPref.CURRENT_DECK, currentDeck.toString());
Singletons.getModel().getQuestPreferences().save();
}
};
@@ -72,7 +72,7 @@ public enum CSubmenuQuestDecks implements ICDoc {
currentDeck = null;
if (hasQuest) {
final String cd = Singletons.getModel().getQuestPreferences().getPreference(QPref.CURRENT_DECK);
final String cd = Singletons.getModel().getQuestPreferences().getPref(QPref.CURRENT_DECK);
for (Deck d : qData.getMyDecks()) {
if (d.getName() != null && d.getName().equals(cd)) {
@@ -90,10 +90,10 @@ public enum CSubmenuQuestDecks implements ICDoc {
view.getLstDecks().setDeleteCommand(cmdDeckDelete);
if (view.getLstDecks().getSelectedDeck() != null) {
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_DECK, view.getLstDecks().getSelectedDeck().getName());
Singletons.getModel().getQuestPreferences().setPref(QPref.CURRENT_DECK, view.getLstDecks().getSelectedDeck().getName());
}
else {
Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_DECK, QPref.CURRENT_DECK.getDefault());
Singletons.getModel().getQuestPreferences().setPref(QPref.CURRENT_DECK, QPref.CURRENT_DECK.getDefault());
}
SwingUtilities.invokeLater(new Runnable() {

View File

@@ -59,8 +59,8 @@ public enum CSubmenuQuestPrefs implements ICDoc {
}
break;
case BOOSTER_COMMONS:
temp1 = prefs.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
temp2 = prefs.getPreferenceInt(QPref.BOOSTER_RARES);
temp1 = prefs.getPrefInt(QPref.BOOSTER_UNCOMMONS);
temp2 = prefs.getPrefInt(QPref.BOOSTER_RARES);
if (temp1 + temp2 + val > 15) {
showError(i0, "Booster packs must have maximum 15 cards.");
@@ -68,8 +68,8 @@ public enum CSubmenuQuestPrefs implements ICDoc {
}
break;
case BOOSTER_UNCOMMONS:
temp1 = prefs.getPreferenceInt(QPref.BOOSTER_COMMONS);
temp2 = prefs.getPreferenceInt(QPref.BOOSTER_RARES);
temp1 = prefs.getPrefInt(QPref.BOOSTER_COMMONS);
temp2 = prefs.getPrefInt(QPref.BOOSTER_RARES);
if (temp1 + temp2 + val > 15) {
showError(i0, "Booster packs must have maximum 15 cards.");
@@ -77,8 +77,8 @@ public enum CSubmenuQuestPrefs implements ICDoc {
}
break;
case BOOSTER_RARES:
temp1 = prefs.getPreferenceInt(QPref.BOOSTER_COMMONS);
temp2 = prefs.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
temp1 = prefs.getPrefInt(QPref.BOOSTER_COMMONS);
temp2 = prefs.getPrefInt(QPref.BOOSTER_UNCOMMONS);
if (temp1 + temp2 + val > 15) {
showError(i0, "Booster packs must have maximum 15 cards.");
@@ -118,7 +118,7 @@ public enum CSubmenuQuestPrefs implements ICDoc {
break;
}
prefs.setPreference(i0.getQPref(), i0.getText());
prefs.setPref(i0.getQPref(), i0.getText());
prefs.save();
i0.setPreviousText(i0.getText());
}

View File

@@ -266,8 +266,8 @@ public class QuestPreferencesHandler extends JPanel {
this.setCaretColor(clrText);
this.setBackground(clrHover);
this.setHorizontalAlignment(SwingConstants.CENTER);
this.setText(prefs.getPreference(qpref));
this.setPreviousText(prefs.getPreference(qpref));
this.setText(prefs.getPref(qpref));
this.setPreviousText(prefs.getPref(qpref));
this.addMouseListener(new MouseAdapter() {
@Override
@@ -345,8 +345,8 @@ public class QuestPreferencesHandler extends JPanel {
}
break;
case BOOSTER_COMMONS:
temp1 = prefs.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
temp2 = prefs.getPreferenceInt(QPref.BOOSTER_RARES);
temp1 = prefs.getPrefInt(QPref.BOOSTER_UNCOMMONS);
temp2 = prefs.getPrefInt(QPref.BOOSTER_RARES);
if (temp1 + temp2 + val > 15) {
showError(i0, "Booster packs must have maximum 15 cards.");
@@ -354,8 +354,8 @@ public class QuestPreferencesHandler extends JPanel {
}
break;
case BOOSTER_UNCOMMONS:
temp1 = prefs.getPreferenceInt(QPref.BOOSTER_COMMONS);
temp2 = prefs.getPreferenceInt(QPref.BOOSTER_RARES);
temp1 = prefs.getPrefInt(QPref.BOOSTER_COMMONS);
temp2 = prefs.getPrefInt(QPref.BOOSTER_RARES);
if (temp1 + temp2 + val > 15) {
showError(i0, "Booster packs must have maximum 15 cards.");
@@ -363,8 +363,8 @@ public class QuestPreferencesHandler extends JPanel {
}
break;
case BOOSTER_RARES:
temp1 = prefs.getPreferenceInt(QPref.BOOSTER_COMMONS);
temp2 = prefs.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
temp1 = prefs.getPrefInt(QPref.BOOSTER_COMMONS);
temp2 = prefs.getPrefInt(QPref.BOOSTER_UNCOMMONS);
if (temp1 + temp2 + val > 15) {
showError(i0, "Booster packs must have maximum 15 cards.");
@@ -404,7 +404,7 @@ public class QuestPreferencesHandler extends JPanel {
break;
}
prefs.setPreference(i0.getQPref(), i0.getText());
prefs.setPref(i0.getQPref(), i0.getText());
prefs.save();
i0.setPreviousText(i0.getText());
}

View File

@@ -218,7 +218,7 @@ public class SSubmenuQuestUtil {
if (Singletons.getModel().getQuest().getAssets() != null) {
d = Singletons.getModel().getQuest().getMyDecks().get(
Singletons.getModel().getQuestPreferences().getPreference(QPref.CURRENT_DECK));
Singletons.getModel().getQuestPreferences().getPref(QPref.CURRENT_DECK));
}
return d;

View File

@@ -399,8 +399,8 @@ public enum VSubmenuQuestPrefs implements IVSubmenu<CSubmenuQuestPrefs> {
this.setCaretColor(clrText);
this.setBackground(clrHover);
this.setHorizontalAlignment(SwingConstants.CENTER);
this.setText(prefs.getPreference(qpref));
this.setPreviousText(prefs.getPreference(qpref));
this.setText(prefs.getPref(qpref));
this.setPreviousText(prefs.getPref(qpref));
this.addMouseListener(new MouseAdapter() {
@Override

View File

@@ -65,6 +65,7 @@ import forge.quest.QuestEvent;
import forge.quest.QuestEventChallenge;
import forge.quest.bazaar.QuestItemType;
import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestPreferences.DifficultyPrefs;
import forge.quest.data.QuestPreferences.QPref;
import forge.util.MyRandom;
@@ -209,7 +210,7 @@ public class QuestWinLose extends ControlWinLose {
// Grant booster on a win, or on a loss in easy mode
if (this.wonMatch || difficulty == 0) {
final int outcome = this.wonMatch ? wins : qData.getAchievements().getLost();
if ((outcome % Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.WINS_BOOSTER, qData.getAchievements().getDifficulty())) == 0) {
if ((outcome % Singletons.getModel().getQuestPreferences().getPrefInt(DifficultyPrefs.WINS_BOOSTER, qData.getAchievements().getDifficulty())) == 0) {
this.awardBooster();
}
}
@@ -261,7 +262,7 @@ public class QuestWinLose extends ControlWinLose {
*/
@Override
public final void actionOnQuit() {
final int x = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.PENALTY_LOSS);
final int x = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.PENALTY_LOSS);
// Record win/loss in quest data
if (this.wonMatch) {
@@ -327,7 +328,7 @@ public class QuestWinLose extends ControlWinLose {
int credEstates = 0;
// Basic win bonus
final int base = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.REWARDS_BASE);
final int base = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.REWARDS_BASE);
double multiplier = 1;
String diff = qEvent.getDifficulty();
@@ -344,7 +345,7 @@ public class QuestWinLose extends ControlWinLose {
}
credBase += (int) ((base * multiplier) + (Double.parseDouble(Singletons.getModel().getQuestPreferences()
.getPreference(QPref.REWARDS_WINS_MULTIPLIER)) * qData.getAchievements().getWin()));
.getPref(QPref.REWARDS_WINS_MULTIPLIER)) * qData.getAchievements().getWin()));
sb.append(diff + " opponent: " + credBase + " credits.<br>");
// Gameplay bonuses (for each game win)
@@ -399,7 +400,7 @@ public class QuestWinLose extends ControlWinLose {
// Mulligan to zero
final int cntCardsHumanStartedWith = humanRating.getOpeningHandSize();
final int mulliganReward = Singletons.getModel().getQuestPreferences()
.getPreferenceInt(QPref.REWARDS_MULLIGAN0);
.getPrefInt(QPref.REWARDS_MULLIGAN0);
if (0 == cntCardsHumanStartedWith) {
credGameplay += mulliganReward;
@@ -432,8 +433,8 @@ public class QuestWinLose extends ControlWinLose {
// Undefeated bonus
if (hasNeverLost) {
credUndefeated += Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.REWARDS_UNDEFEATED);
final int reward = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.REWARDS_UNDEFEATED);
credUndefeated += Singletons.getModel().getQuestPreferences().getPrefInt(QPref.REWARDS_UNDEFEATED);
final int reward = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.REWARDS_UNDEFEATED);
sb.append(String.format("You have not lost once! " + "Bonus: %d credits.<br>", reward));
}
@@ -548,7 +549,7 @@ public class QuestWinLose extends ControlWinLose {
if (qData.getFormat() == null) {
final List<GameFormat> formats = new ArrayList<GameFormat>();
String preferredFormat = Singletons.getModel().getQuestPreferences().getPreference(QPref.BOOSTER_FORMAT);
String preferredFormat = Singletons.getModel().getQuestPreferences().getPref(QPref.BOOSTER_FORMAT);
GameFormat pref = null;
for (GameFormat f : Singletons.getModel().getFormats()) {
@@ -563,7 +564,7 @@ public class QuestWinLose extends ControlWinLose {
ch.show(pref);
final GameFormat selected = ch.getSelectedValue();
Singletons.getModel().getQuestPreferences().setPreference(QPref.BOOSTER_FORMAT, selected.toString());
Singletons.getModel().getQuestPreferences().setPref(QPref.BOOSTER_FORMAT, selected.toString());
cardsWon = qData.getCards().addCards(selected.getFilterPrinted());
@@ -733,7 +734,7 @@ public class QuestWinLose extends ControlWinLose {
}
private void penalizeLoss() {
final int x = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.PENALTY_LOSS);
final int x = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.PENALTY_LOSS);
this.icoTemp = QuestWinLose.getResizedIcon(FSkin.getIcon(FSkin.QuestIcons.ICO_HEART), 0.5);
this.lblTemp1 = new TitleLabel("Gameplay Results");
@@ -777,17 +778,17 @@ public class QuestWinLose extends ControlWinLose {
QuestPreferences qp = Singletons.getModel().getQuestPreferences();
if (null == whyAiLost) {
// Felidar, Helix Pinnacle, etc.
return qp.getPreferenceInt(QPref.REWARDS_ALTERNATIVE);
return qp.getPrefInt(QPref.REWARDS_ALTERNATIVE);
}
switch (whyAiLost) {
case LifeReachedZero:
return 0; // nothing special here, ordinary kill
case Milled:
return qp.getPreferenceInt(QPref.REWARDS_MILLED);
return qp.getPrefInt(QPref.REWARDS_MILLED);
case Poisoned:
return qp.getPreferenceInt(QPref.REWARDS_POISON);
return qp.getPrefInt(QPref.REWARDS_POISON);
case SpellEffect: // Door to Nothingness, etc.
return qp.getPreferenceInt(QPref.REWARDS_ALTERNATIVE);
return qp.getPrefInt(QPref.REWARDS_ALTERNATIVE);
default:
return 0;
}
@@ -806,13 +807,13 @@ public class QuestWinLose extends ControlWinLose {
int credits;
if (iTurn == 1) {
credits = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.REWARDS_TURN1);
credits = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.REWARDS_TURN1);
} else if (iTurn <= 5) {
credits = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.REWARDS_TURN5);
credits = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.REWARDS_TURN5);
} else if (iTurn <= 10) {
credits = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.REWARDS_TURN10);
credits = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.REWARDS_TURN10);
} else if (iTurn <= 15) {
credits = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.REWARDS_TURN15);
credits = Singletons.getModel().getQuestPreferences().getPrefInt(QPref.REWARDS_TURN15);
} else {
credits = 0;
}

View File

@@ -103,7 +103,7 @@ public enum FModel {
// Fire up log file and exception handling
ExceptionHandler.registerErrorHandling();
final File logFile = new File("forge.log");
final File logFile = new File(NewConstants.LOG_FILE);
final boolean deleteSucceeded = logFile.delete();
if (logFile.exists() && !deleteSucceeded && (logFile.length() != 0)) {
@@ -148,7 +148,7 @@ public enum FModel {
// Loads all cards (using progress bar).
GuiUtils.checkEDT("CardFactory$constructor", false);
final CardStorageReader reader = new CardStorageReader(NewConstants.CARD_DATA_DIR.defaultLoc, true);
final CardStorageReader reader = new CardStorageReader(NewConstants.CARD_DATA_DIR, true);
try {
// this fills in our map of card names to Card instances.
CardDb.setup(reader.loadCards());

View File

@@ -17,13 +17,7 @@
*/
package forge.properties;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import forge.Constant;
import forge.Constant.Preferences;
@@ -31,98 +25,84 @@ import forge.gui.home.EMenuItem;
import forge.gui.match.VMatchUI;
import forge.gui.match.nonsingleton.VField;
import forge.gui.match.views.VDev;
import forge.util.FileUtil;
/**
* Holds default preference values in an enum.
* Loads preferred values when instantiated.
* If a requested value is not present, default is returned.
*
* @author Forge
* @version $Id$
*/
public class ForgePreferences {
private Map<FPref, String> preferenceValues;
public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
/**
* Preference identifiers, and their default values.
* When this class is instantiated, these enum values are used
* in a map that is populated with the current preferences
* from the text file.
*/
public enum FPref { /** */
UI_USE_OLD ("false"), /** */
UI_RANDOM_FOIL ("false"), /** */
UI_SMOOTH_LAND ("false"), /** */
UI_AVATARS ("0,1"), /** */
UI_CARD_OVERLAY ("true"), /** */
UI_UPLOAD_DRAFT ("false"), /** */
UI_SCALE_LARGER ("true"), /** */
UI_MAX_STACK ("3"), /** */
UI_STACK_OFFSET ("tiny"), /** */
UI_CARD_SIZE ("small"), /** */
UI_BUGZ_NAME (""), /** */
UI_BUGZ_PWD (""), /** */
UI_ANTE ("false"), /** */
UI_MANABURN("false"), /** */
UI_SKIN ("default"), /** */
UI_PREFERRED_AVATARS_ONLY ("false"), /** */
UI_TARGETING_OVERLAY ("false"), /** */
UI_ENABLE_SOUNDS ("true"), /** */
UI_RANDOM_CARD_ART ("false"), /** */
public static enum FPref {
UI_USE_OLD ("false"),
UI_RANDOM_FOIL ("false"),
UI_SMOOTH_LAND ("false"),
UI_AVATARS ("0,1"),
UI_CARD_OVERLAY ("true"),
UI_UPLOAD_DRAFT ("false"),
UI_SCALE_LARGER ("true"),
UI_MAX_STACK ("3"),
UI_STACK_OFFSET ("tiny"),
UI_CARD_SIZE ("small"),
UI_BUGZ_NAME (""),
UI_BUGZ_PWD (""),
UI_ANTE ("false"),
UI_MANABURN("false"),
UI_SKIN ("default"),
UI_PREFERRED_AVATARS_ONLY ("false"),
UI_TARGETING_OVERLAY ("false"),
UI_ENABLE_SOUNDS ("true"),
UI_RANDOM_CARD_ART ("false"),
SUBMENU_CURRENTMENU (EMenuItem.CONSTRUCTED.toString()), /** */
SUBMENU_SANCTIONED ("false"), /** */
SUBMENU_GAUNTLET ("false"), /** */
SUBMENU_VARIANT ("false"), /** */
SUBMENU_QUEST ("false"), /** */
SUBMENU_SETTINGS ("false"), /** */
SUBMENU_UTILITIES ("false"), /** */
SUBMENU_CURRENTMENU (EMenuItem.CONSTRUCTED.toString()),
SUBMENU_SANCTIONED ("false"),
SUBMENU_GAUNTLET ("false"),
SUBMENU_VARIANT ("false"),
SUBMENU_QUEST ("false"),
SUBMENU_SETTINGS ("false"),
SUBMENU_UTILITIES ("false"),
ENFORCE_DECK_LEGALITY ("true"), /** */
ENFORCE_DECK_LEGALITY ("true"),
DEV_MODE_ENABLED ("false"), /** */
DEV_MILLING_LOSS ("true"), /** */
DEV_UNLIMITED_LAND ("false"), /** */
DEV_MODE_ENABLED ("false"),
DEV_MILLING_LOSS ("true"),
DEV_UNLIMITED_LAND ("false"),
DECKGEN_SINGLETONS ("false"), /** */
DECKGEN_ARTIFACTS ("false"), /** */
DECKGEN_NOSMALL ("false"), /** */
DECKGEN_SINGLETONS ("false"),
DECKGEN_ARTIFACTS ("false"),
DECKGEN_NOSMALL ("false"),
PHASE_AI_UPKEEP ("true"), /** */
PHASE_AI_DRAW ("true"), /** */
PHASE_AI_MAIN1 ("true"), /** */
PHASE_AI_BEGINCOMBAT ("true"), /** */
PHASE_AI_DECLAREATTACKERS ("true"), /** */
PHASE_AI_DECLAREBLOCKERS ("true"), /** */
PHASE_AI_FIRSTSTRIKE ("true"), /** */
PHASE_AI_COMBATDAMAGE ("true"), /** */
PHASE_AI_ENDCOMBAT ("true"), /** */
PHASE_AI_MAIN2 ("true"), /** */
PHASE_AI_EOT ("true"), /** */
PHASE_AI_CLEANUP ("true"), /** */
PHASE_AI_UPKEEP ("true"),
PHASE_AI_DRAW ("true"),
PHASE_AI_MAIN1 ("true"),
PHASE_AI_BEGINCOMBAT ("true"),
PHASE_AI_DECLAREATTACKERS ("true"),
PHASE_AI_DECLAREBLOCKERS ("true"),
PHASE_AI_FIRSTSTRIKE ("true"),
PHASE_AI_COMBATDAMAGE ("true"),
PHASE_AI_ENDCOMBAT ("true"),
PHASE_AI_MAIN2 ("true"),
PHASE_AI_EOT ("true"),
PHASE_AI_CLEANUP ("true"),
PHASE_HUMAN_UPKEEP ("true"), /** */
PHASE_HUMAN_DRAW ("true"), /** */
PHASE_HUMAN_MAIN1 ("true"), /** */
PHASE_HUMAN_BEGINCOMBAT ("true"), /** */
PHASE_HUMAN_DECLAREATTACKERS ("true"), /** */
PHASE_HUMAN_DECLAREBLOCKERS ("true"), /** */
PHASE_HUMAN_FIRSTSTRIKE ("true"), /** */
PHASE_HUMAN_COMBATDAMAGE ("true"), /** */
PHASE_HUMAN_ENDCOMBAT ("true"), /** */
PHASE_HUMAN_MAIN2 ("true"), /** */
PHASE_HUMAN_EOT ("true"), /** */
PHASE_HUMAN_CLEANUP ("true"), /** */
PHASE_HUMAN_UPKEEP ("true"),
PHASE_HUMAN_DRAW ("true"),
PHASE_HUMAN_MAIN1 ("true"),
PHASE_HUMAN_BEGINCOMBAT ("true"),
PHASE_HUMAN_DECLAREATTACKERS ("true"),
PHASE_HUMAN_DECLAREBLOCKERS ("true"),
PHASE_HUMAN_FIRSTSTRIKE ("true"),
PHASE_HUMAN_COMBATDAMAGE ("true"),
PHASE_HUMAN_ENDCOMBAT ("true"),
PHASE_HUMAN_MAIN2 ("true"),
PHASE_HUMAN_EOT ("true"),
PHASE_HUMAN_CLEANUP ("true"),
SHORTCUT_SHOWSTACK ("83"), /** */
SHORTCUT_SHOWCOMBAT ("67"), /** */
SHORTCUT_SHOWCONSOLE ("76"), /** */
SHORTCUT_SHOWPLAYERS ("80"), /** */
SHORTCUT_SHOWDEV ("68"), /** */
SHORTCUT_CONCEDE ("17"), /** */
SHORTCUT_ENDTURN ("69"), /** */
SHORTCUT_ALPHASTRIKE ("65"), /** */
SHORTCUT_SHOWSTACK ("83"),
SHORTCUT_SHOWCOMBAT ("67"),
SHORTCUT_SHOWCONSOLE ("76"),
SHORTCUT_SHOWPLAYERS ("80"),
SHORTCUT_SHOWDEV ("68"),
SHORTCUT_CONCEDE ("17"),
SHORTCUT_ENDTURN ("69"),
SHORTCUT_ALPHASTRIKE ("65"),
SHORTCUT_SHOWTARGETING ("84");
private final String strDefaultVal;
@@ -138,42 +118,23 @@ public class ForgePreferences {
}
}
/** */
public enum CardSizeType {
/** */
public static enum CardSizeType {
tiny, smaller, small, medium, large, huge
}
/** */
public enum StackOffsetType {
/** */
public static enum StackOffsetType {
tiny, small, medium, large
}
/** */
public enum HomeMenus {
/** */
public static enum HomeMenus {
constructed, draft, sealed, quest, settings, utilities
}
/** Instantiates a ForgePreferences object. */
public ForgePreferences() {
preferenceValues = new HashMap<FPref, String>();
List<String> lines = FileUtil.readFile(NewConstants.MAIN_PREFERENCES_FILE.userPrefLoc);
for (String line : lines) {
if (line.startsWith("#") || (line.length() == 0)) {
continue;
}
final String[] split = line.split("=");
if (split.length == 2) {
this.setPref(split[0], split[1]);
} else if (split.length == 1 && line.endsWith("=")) {
this.setPref(split[0], "");
}
}
super(NewConstants.MAIN_PREFS_FILE);
}
/**
@@ -262,97 +223,20 @@ public class ForgePreferences {
//Singletons.getView().getViewMatch().setLayoutParams(this.getPref(FPref.UI_LAYOUT_PARAMS));
}
/** Saves prefs map to file. */
public void save() {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(NewConstants.MAIN_PREFERENCES_FILE.userPrefLoc));
for (FPref key : FPref.values()) {
writer.write(key + "=" + getPref(key));
writer.newLine();
}
writer.flush();
writer.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
protected FPref[] getEnumValues() {
return FPref.values();
}
/** */
public void reset() {
this.preferenceValues.clear();
}
/**
* DUE TO BE DEPRECATED:
* Transition code between preference manager for v1.2.2 and v1.2.3.
* (string-based vs. enum-based)
*
* @param s0 &emsp; {@link java.lang.String} identifier of preference
* @param s1 &emsp; {@link java.lang.String} value
*/
public void setPref(String s0, String s1) {
protected FPref valueOf(String name) {
try {
preferenceValues.put(FPref.valueOf(s0), s1);
return FPref.valueOf(name);
}
catch (Exception e) {
return null;
}
}
/**
* @param q0 &emsp; {@link forge.properties.ForgePreferences.FPref}
* @param s0 &emsp; {@link java.lang.String} value
*/
public void setPref(FPref q0, String s0) {
preferenceValues.put(q0, s0);
}
/**
*
* TODO: Write javadoc for this method.
* @param q0 FPref
* @param val boolean
*/
public void setPref(FPref q0, boolean val) {
setPref(q0, String.valueOf(val));
}
/**
* Returns a non-difficulty-indexed preference value.
*
* @param fp0 &emsp; {@link forge.quest.data.ForgePreferences.FPref}
* @return String
*/
public String getPref(FPref fp0) {
String val;
val = preferenceValues.get(fp0);
if (val == null) { val = fp0.getDefault(); }
return val;
}
/**
* Returns a non-difficulty-indexed preference value, as an int.
*
* @param fp0 &emsp; {@link forge.quest.data.ForgePreferences.FPref}
* @return int
*/
public int getPrefInt(FPref fp0) {
return Integer.parseInt(getPref(fp0));
}
/**
* Returns a non-difficulty-indexed preference value, as a boolean.
*
* @param fp0 &emsp; {@link forge.quest.data.ForgePreferences.FPref}
* @return boolean
*/
public boolean getPrefBoolean(FPref fp0) {
return Boolean.parseBoolean(getPref(fp0));
protected String getPrefDefault(FPref key) {
return key.getDefault();
}
}

View File

@@ -17,31 +17,13 @@
*/
package forge.properties;
import java.util.List;
import com.google.common.collect.Lists;
public final class NewConstants {
public static final String PROFILE_FILE = "forge.profile.properties";
public static final String PROFILE_TEMPLATE_FILE = PROFILE_FILE + ".example";
// data tree roots
private static final String _USER_DIR;
private static final String _CACHE_DIR;
static {
ForgeProfileProperties profileProps = new ForgeProfileProperties(PROFILE_FILE);
_USER_DIR = profileProps.userDir;
_CACHE_DIR = profileProps.cacheDir;
}
private static final String _RES_ROOT = "res/";
private static final String _DEFAULTS_DIR = _RES_ROOT + "defaults/";
private static final String _QUEST_DIR = _RES_ROOT + "quest/";
private static final String _USER_PREFS_DIR = _USER_DIR + "preferences/";
private static final String _USER_QUEST_DIR = _USER_DIR + "quest/";
private static final String _DB_DIR = _CACHE_DIR + "db/";
// data that is only in the program dir
private static final String _RES_ROOT = "res/";
private static final String _QUEST_DIR = _RES_ROOT + "quest/";
public static final String IMAGE_LIST_TOKENS_FILE = _RES_ROOT + "token-images.txt";
public static final String IMAGE_LIST_QUEST_OPPONENT_ICONS_FILE = _QUEST_DIR + "quest-opponent-icons.txt";
public static final String IMAGE_LIST_QUEST_PET_SHOP_ICONS_FILE = _QUEST_DIR + "quest-pet-shop-icons.txt";
@@ -55,52 +37,62 @@ public final class NewConstants {
public static final String DRAFT_RANKINGS_FILE = _RES_ROOT + "draft/rankings.txt";
public static final String PRICES_BOOSTER_FILE = _QUEST_DIR + "booster-prices.txt";
public static final String BAZAAR_FILE = _QUEST_DIR + "bazaar/index.xml";
public static final String CARD_DATA_DIR = _RES_ROOT + "cardsfolder/";
public static final String DECK_CUBE_DIR = _RES_ROOT + "cube";
public static final String QUEST_WORLD_DIR = _QUEST_DIR + "worlds/";
public static final String QUEST_PRECON_DIR = _QUEST_DIR + "precons/";
public static final String CARD_DATA_PETS_DIR = _QUEST_DIR + "bazaar/";
public static final String DEFAULT_DUELS_DIR = _QUEST_DIR + "duels";
public static final String DEFAULT_CHALLENGES_DIR = _QUEST_DIR + "challenges";
// data tree roots
private static final String _USER_DIR;
private static final String _CACHE_DIR;
static {
ForgeProfileProperties profileProps = new ForgeProfileProperties(PROFILE_FILE);
_USER_DIR = profileProps.userDir;
_CACHE_DIR = profileProps.cacheDir;
}
// data that is only in the profile dirs
private static final String _USER_QUEST_DIR = _USER_DIR + "quest/";
private static final String _USER_PREFS_DIR = _USER_DIR + "preferences/";
public static final String LOG_FILE = _USER_DIR + "forge.log";
public static final String DECK_BASE_DIR = _USER_DIR + "decks/";
public static final String DECK_CONSTRUCTED_DIR = DECK_BASE_DIR + "constructed/";
public static final String DECK_DRAFT_DIR = DECK_BASE_DIR + "draft/";
public static final String DECK_SEALED_DIR = DECK_BASE_DIR + "sealed/";
public static final String DECK_SCHEME_DIR = DECK_BASE_DIR + "scheme/";
public static final String DECK_PLANE_DIR = DECK_BASE_DIR + "planar/";
public static final String QUEST_SAVE_DIR = _USER_QUEST_DIR + "saves/";
public static final String MAIN_PREFS_FILE = _USER_PREFS_DIR + "forge.preferences";
public static final String QUEST_PREFS_FILE = _USER_PREFS_DIR + "quest.preferences";
// data that has defaults in the program dir but overrides/additions in the user dir
public static final FileLocation MAIN_PREFERENCES_FILE = new FileLocation(_DEFAULTS_DIR, _USER_PREFS_DIR, "forge.preferences");
private static final String _DEFAULTS_DIR = _RES_ROOT + "defaults/";
public static final FileLocation EDITOR_PREFERENCES_FILE = new FileLocation(_DEFAULTS_DIR, _USER_PREFS_DIR, "editor.preferences");
public static final FileLocation QUEST_PREFERENCES_FILE = new FileLocation(_DEFAULTS_DIR, _USER_PREFS_DIR, "quest.preferences");
public static final FileLocation HOME_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, _USER_PREFS_DIR, "home.xml");
public static final FileLocation MATCH_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, _USER_PREFS_DIR, "match.xml");
public static final FileLocation EDITOR_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, _USER_PREFS_DIR, "editor.xml");
public static final FileLocation HOME_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, _USER_PREFS_DIR, "home.xml");
public static final FileLocation MATCH_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, _USER_PREFS_DIR, "match.xml");
public static final FileLocation EDITOR_LAYOUT_FILE = new FileLocation(_DEFAULTS_DIR, _USER_PREFS_DIR, "editor.xml");
public static final FileLocation QUEST_CARD_PRICE_FILE = new FileLocation(_DEFAULTS_DIR, _DB_DIR, "all-prices.txt");
public static final FileLocation CARD_DATA_DIR = new FileLocation(_RES_ROOT, _USER_DIR, "cardsfolder/");
public static final FileLocation DECK_CUBE_DIR = new FileLocation(_DEFAULTS_DIR, _USER_DIR, "cube");
public static final FileLocation QUEST_WORLD_DIR = new FileLocation(_QUEST_DIR, _USER_QUEST_DIR, "worlds/");
public static final FileLocation QUEST_PRECON_DIR = new FileLocation(_QUEST_DIR, _USER_QUEST_DIR, "precons/");
// data that is only in the user dir
public static final String DECK_CONSTRUCTED_DIR = _USER_DIR + "constructed/";
public static final String DECK_DRAFT_DIR = _USER_DIR + "draft/";
public static final String DECK_SEALED_DIR = _USER_DIR + "sealed/";
public static final String DECK_SCHEME_DIR = _USER_DIR + "scheme/";
public static final String DECK_PLANE_DIR = _USER_DIR + "plane/";
public static final String QUEST_SAVE_DIR = _USER_DIR + "quest/saves";
// data that is only in the cached dir
public static final String CACHE_CARD_PICS_DIR = _CACHE_DIR + "pics/cards/";
public static final String CACHE_TOKEN_PICS_DIR = _CACHE_DIR + "pics/tokens/";
public static final String CACHE_ICON_PICS_DIR = _CACHE_DIR + "pics/icons/";
public static final String CACHE_BOOSTER_PICS_DIR = _CACHE_DIR + "pics/boosters/";
public static final String CACHE_FATPACK_PICS_DIR = _CACHE_DIR + "pics/fatpacks/";
public static final String CACHE_PRECON_PICS_DIR = _CACHE_DIR + "pics/precons/";
public static final String CACHE_TOURNAMENTPACK_PICS_DIR = _CACHE_DIR + "pics/tournamentpacks/";
private static final String _DB_DIR = _CACHE_DIR + "db/";
private static final String _PICS_DIR = _CACHE_DIR + "pics/";
public static final String CACHE_CARD_PICS_DIR = _PICS_DIR + "cards/";
public static final String CACHE_TOKEN_PICS_DIR = _PICS_DIR + "tokens/";
public static final String CACHE_ICON_PICS_DIR = _PICS_DIR + "icons/";
public static final String CACHE_BOOSTER_PICS_DIR = _PICS_DIR + "boosters/";
public static final String CACHE_FATPACK_PICS_DIR = _PICS_DIR + "fatpacks/";
public static final String CACHE_PRECON_PICS_DIR = _PICS_DIR + "precons/";
public static final String CACHE_TOURNAMENTPACK_PICS_DIR = _PICS_DIR + "tournamentpacks/";
public static final String CACHE_MORPH_IMAGE_FILE = CACHE_TOKEN_PICS_DIR + "morph.jpg";
public static final String QUEST_CARD_PRICE_FILE = _DB_DIR + "all-prices.txt";
public static final List<String> PROFILE_DIRS = Lists.newArrayList(
public static final String[] PROFILE_DIRS = {
_USER_PREFS_DIR,
_DB_DIR,
CARD_DATA_DIR.userPrefLoc,
DECK_CUBE_DIR.userPrefLoc,
QUEST_WORLD_DIR.userPrefLoc,
QUEST_PRECON_DIR.userPrefLoc,
DECK_CONSTRUCTED_DIR,
DECK_DRAFT_DIR,
DECK_SEALED_DIR,
@@ -113,7 +105,7 @@ public final class NewConstants {
CACHE_BOOSTER_PICS_DIR,
CACHE_FATPACK_PICS_DIR,
CACHE_PRECON_PICS_DIR,
CACHE_TOURNAMENTPACK_PICS_DIR);
CACHE_TOURNAMENTPACK_PICS_DIR };
// URLs
private static final String _URL_CARDFORGE = "http://cardforge.org";

View File

@@ -0,0 +1,114 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* 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.properties;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import forge.util.FileUtil;
/**
* Holds default preference values in an enum.
* Loads preferred values when instantiated.
* If a requested value is not present, default is returned.
*/
public abstract class PreferencesStore<T extends Enum<?>> {
private final Map<T, String> preferenceValues = new HashMap<T, String>();
private final String filename;
public PreferencesStore(String filename0) {
filename = filename0;
List<String> lines = FileUtil.readFile(filename);
for (String line : lines) {
line = line.trim();
if (line.startsWith("#") || (line.isEmpty())) {
continue;
}
String[] split = line.split("=");
T pref = valueOf(split[0]);
if (null == pref) {
System.out.println("unknown preference: " + line);
continue;
}
if (split.length == 2) {
this.setPref(pref, split[1]);
} else if (split.length == 1 && line.endsWith("=")) {
this.setPref(pref, "");
}
}
}
protected abstract T[] getEnumValues();
protected abstract T valueOf(String name);
protected abstract String getPrefDefault(T key);
public final void save() {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(filename));
for (T key : getEnumValues()) {
writer.write(key + "=" + getPref(key));
writer.newLine();
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (null != writer) {
try { writer.close(); }
catch (IOException e) { System.out.println("error while closing " + filename); }
}
}
}
public final void reset() {
this.preferenceValues.clear();
}
public final void setPref(T q0, String s0) {
preferenceValues.put(q0, s0);
}
public final void setPref(T q0, boolean val) {
setPref(q0, String.valueOf(val));
}
public final String getPref(T fp0) {
String val;
val = preferenceValues.get(fp0);
if (val == null) { val = getPrefDefault(fp0); }
return val;
}
public final int getPrefInt(T fp0) {
return Integer.parseInt(getPref(fp0));
}
public final boolean getPrefBoolean(T fp0) {
return Boolean.parseBoolean(getPref(fp0));
}
}

View File

@@ -34,7 +34,7 @@ import forge.quest.data.GameFormatQuest;
import forge.quest.data.QuestAchievements;
import forge.quest.data.QuestAssets;
import forge.quest.data.QuestData;
import forge.quest.data.QuestPreferences.QPref;
import forge.quest.data.QuestPreferences.DifficultyPrefs;
import forge.quest.io.PreconReader;
import forge.util.storage.IStorage;
import forge.util.storage.IStorageView;
@@ -168,7 +168,7 @@ public class QuestController {
*/
public static IStorageView<PreconDeck> getPrecons() {
if (null == preconManager) {
preconManager = new StorageView<PreconDeck>(new PreconReader(new File(NewConstants.QUEST_PRECON_DIR.defaultLoc)));
preconManager = new StorageView<PreconDeck>(new PreconReader(new File(NewConstants.QUEST_PRECON_DIR)));
}
return QuestController.preconManager;
@@ -236,7 +236,7 @@ public class QuestController {
this.myCards.setupNewGameCardPool(filter, difficulty);
}
this.getAssets().setCredits(Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.STARTING_CREDITS, difficulty));
this.getAssets().setCredits(Singletons.getModel().getQuestPreferences().getPrefInt(DifficultyPrefs.STARTING_CREDITS, difficulty));
}
@@ -411,7 +411,7 @@ public class QuestController {
*/
public QuestPetStorage getPetsStorage() {
if (this.pets == null) {
this.pets = new QuestPetStorage(new File(NewConstants.CARD_DATA_PETS_DIR));
this.pets = new QuestPetStorage(new File(NewConstants.BAZAAR_FILE));
}
return this.pets;

View File

@@ -34,7 +34,7 @@ import forge.deck.io.DeckSerializer;
import forge.quest.bazaar.QuestItemType;
import forge.quest.data.QuestAchievements;
import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestPreferences.QPref;
import forge.quest.data.QuestPreferences.DifficultyPrefs;
import forge.util.FileSection;
import forge.util.FileUtil;
@@ -168,23 +168,23 @@ public class QuestEventManager {
final int index = qCtrl.getAchievements().getDifficulty();
final List<QuestEventDuel> duelOpponents = new ArrayList<QuestEventDuel>();
if (cntWins < qpref.getPreferenceInt(QPref.WINS_MEDIUMAI, index)) {
if (cntWins < qpref.getPrefInt(DifficultyPrefs.WINS_MEDIUMAI, index)) {
_addDuel(duelOpponents, QuestEventDifficulty.EASY, 0);
_addDuel(duelOpponents, QuestEventDifficulty.EASY, 1);
_addDuel(duelOpponents, QuestEventDifficulty.EASY, 2);
} else if (cntWins == qpref.getPreferenceInt(QPref.WINS_MEDIUMAI, index)) {
} else if (cntWins == qpref.getPrefInt(DifficultyPrefs.WINS_MEDIUMAI, index)) {
_addDuel(duelOpponents, QuestEventDifficulty.EASY, 0);
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 0);
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 1);
} else if (cntWins < qpref.getPreferenceInt(QPref.WINS_HARDAI, index)) {
} else if (cntWins < qpref.getPrefInt(DifficultyPrefs.WINS_HARDAI, index)) {
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 0);
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 1);
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 2);
} else if (cntWins == qpref.getPreferenceInt(QPref.WINS_HARDAI, index)) {
} else if (cntWins == qpref.getPrefInt(DifficultyPrefs.WINS_HARDAI, index)) {
_addDuel(duelOpponents, QuestEventDifficulty.MEDIUM, 0);
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 0);
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 1);
} else if (cntWins < qpref.getPreferenceInt(QPref.WINS_EXPERTAI, index)) {
} else if (cntWins < qpref.getPrefInt(DifficultyPrefs.WINS_EXPERTAI, index)) {
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 0);
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 1);
_addDuel(duelOpponents, QuestEventDifficulty.HARD, 2);

View File

@@ -48,6 +48,7 @@ import forge.quest.bazaar.QuestItemType;
import forge.quest.data.GameFormatQuest;
import forge.quest.data.QuestAssets;
import forge.quest.data.QuestPreferences;
import forge.quest.data.QuestPreferences.DifficultyPrefs;
import forge.quest.data.QuestPreferences.QPref;
import forge.util.Aggregates;
import forge.util.MyRandom;
@@ -143,9 +144,9 @@ public final class QuestUtilCards {
* @return the array list
*/
public ArrayList<CardPrinted> addCards(final Predicate<CardPrinted> fSets) {
final int nCommon = this.qpref.getPreferenceInt(QPref.BOOSTER_COMMONS);
final int nUncommon = this.qpref.getPreferenceInt(QPref.BOOSTER_UNCOMMONS);
final int nRare = this.qpref.getPreferenceInt(QPref.BOOSTER_RARES);
final int nCommon = this.qpref.getPrefInt(QPref.BOOSTER_COMMONS);
final int nUncommon = this.qpref.getPrefInt(QPref.BOOSTER_UNCOMMONS);
final int nRare = this.qpref.getPrefInt(QPref.BOOSTER_RARES);
final ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>();
Predicate<CardPrinted> predCommons = Predicates.and(fSets, IPaperCard.Predicates.Presets.IS_COMMON);
@@ -235,9 +236,9 @@ public final class QuestUtilCards {
* the idx difficulty
*/
public void setupNewGameCardPool(final Predicate<CardPrinted> filter, final int idxDifficulty) {
final int nC = this.qpref.getPreferenceInt(QPref.STARTING_COMMONS, idxDifficulty);
final int nU = this.qpref.getPreferenceInt(QPref.STARTING_UNCOMMONS, idxDifficulty);
final int nR = this.qpref.getPreferenceInt(QPref.STARTING_RARES, idxDifficulty);
final int nC = this.qpref.getPrefInt(DifficultyPrefs.STARTING_COMMONS, idxDifficulty);
final int nU = this.qpref.getPrefInt(DifficultyPrefs.STARTING_UNCOMMONS, idxDifficulty);
final int nR = this.qpref.getPrefInt(DifficultyPrefs.STARTING_RARES, idxDifficulty);
this.addAllCards(BoosterUtils.getQuestStarterDeck(filter, nC, nU, nR));
}
@@ -525,12 +526,12 @@ public final class QuestUtilCards {
int nLevel = this.qc.getAchievements().getLevel();
// Preferences
final int startPacks = this.qpref.getPreferenceInt(QPref.SHOP_STARTING_PACKS);
final int winsForPack = this.qpref.getPreferenceInt(QPref.SHOP_WINS_FOR_ADDITIONAL_PACK);
final int maxPacks = this.qpref.getPreferenceInt(QPref.SHOP_MAX_PACKS);
final int common = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_COMMON);
final int uncommon = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_UNCOMMON);
final int rare = this.qpref.getPreferenceInt(QPref.SHOP_SINGLES_RARE);
final int startPacks = this.qpref.getPrefInt(QPref.SHOP_STARTING_PACKS);
final int winsForPack = this.qpref.getPrefInt(QPref.SHOP_WINS_FOR_ADDITIONAL_PACK);
final int maxPacks = this.qpref.getPrefInt(QPref.SHOP_MAX_PACKS);
final int common = this.qpref.getPrefInt(QPref.SHOP_SINGLES_COMMON);
final int uncommon = this.qpref.getPrefInt(QPref.SHOP_SINGLES_UNCOMMON);
final int rare = this.qpref.getPrefInt(QPref.SHOP_SINGLES_RARE);
final int levelPacks = nLevel > 0 ? startPacks / nLevel : startPacks;
final int winPacks = this.qc.getAchievements().getWin() / winsForPack;

View File

@@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import forge.Singletons;
import forge.quest.data.QuestPreferences.QPref;
import forge.quest.data.QuestPreferences.DifficultyPrefs;
/**
* TODO: Write javadoc for this type.
@@ -128,7 +128,7 @@ public class QuestAchievements {
* @return the level
*/
public int getLevel() {
final int winsToLvlUp = Singletons.getModel().getQuestPreferences().getPreferenceInt(QPref.WINS_RANKUP, difficulty);
final int winsToLvlUp = Singletons.getModel().getQuestPreferences().getPrefInt(DifficultyPrefs.WINS_RANKUP, difficulty);
return this.win / winsToLvlUp;
}
// Wins & Losses

View File

@@ -167,12 +167,12 @@ public class QuestAssets {
*/
public QuestAssets(GameFormatQuest useFormat) {
final QuestPreferences prefs = Singletons.getModel().getQuestPreferences();
int snowLands = prefs.getPreferenceInt(QPref.STARTING_SNOW_LANDS);
int snowLands = prefs.getPrefInt(QPref.STARTING_SNOW_LANDS);
if (useFormat != null && !useFormat.hasSnowLands()) {
snowLands = 0;
}
final ItemPoolView<CardPrinted> lands = QuestUtilCards.generateBasicLands(
prefs.getPreferenceInt(QPref.STARTING_BASIC_LANDS), snowLands, useFormat);
prefs.getPrefInt(QPref.STARTING_BASIC_LANDS), snowLands, useFormat);
this.getCardPool().addAll(lands);
}

View File

@@ -17,35 +17,17 @@
*/
package forge.quest.data;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import forge.properties.NewConstants;
import forge.util.FileUtil;
import forge.properties.PreferencesStore;
/**
* Holds default preference values in an enum. Loads preferred values when
* instantiated. If a requested value is not present, default is returned.
*
* @author Forge
* @version $Id$
*/
@SuppressWarnings("serial")
public class QuestPreferences implements Serializable {
private final Map<QPref, String> preferenceValues;
public class QuestPreferences extends PreferencesStore<QuestPreferences.QPref> implements Serializable {
/**
* Preference identifiers, and their default values. When this class is
* instantiated, these enum values are used in a map that is populated with
* the current preferences from the text file.
* Preference identifiers, and their default values.
*/
public enum QPref {
public static enum QPref {
// How many of each rarity comes in a won booster pack
BOOSTER_COMMONS("11"),
@@ -89,35 +71,30 @@ public class QuestPreferences implements Serializable {
STARTING_SNOW_LANDS("5"),
// Commons in your starting pool, by difficulty
STARTING_COMMONS("DIFFICULTY_INDEX_REQD"),
STARTING_COMMONS_EASY("82"),
STARTING_COMMONS_MEDIUM("80"),
STARTING_COMMONS_HARD("78"),
STARTING_COMMONS_EXPERT("76"),
// Uncommons in your starting pool, by difficulty
STARTING_UNCOMMONS("DIFFICULTY_INDEX_REQD"),
STARTING_UNCOMMONS_EASY("40"),
STARTING_UNCOMMONS_MEDIUM("36"),
STARTING_UNCOMMONS_HARD("32"),
STARTING_UNCOMMONS_EXPERT("28"),
// Rares in your starting pool, by difficulty
STARTING_RARES("DIFFICULTY_INDEX_REQD"),
STARTING_RARES_EASY("20"),
STARTING_RARES_MEDIUM("18"),
STARTING_RARES_HARD("16"),
STARTING_RARES_EXPERT("15"),
// Credits you start the quest with, by difficulty
STARTING_CREDITS("DIFFICULTY_INDEX_REQD"),
STARTING_CREDITS_EASY("250"),
STARTING_CREDITS_MEDIUM("200"),
STARTING_CREDITS_HARD("150"),
STARTING_CREDITS_EXPERT("100"),
// Matches won per booster award, by difficulty
WINS_BOOSTER("DIFFICULTY_INDEX_REQD"),
WINS_BOOSTER_EASY("1"),
WINS_BOOSTER_MEDIUM("1"),
WINS_BOOSTER_HARD("2"),
@@ -125,28 +102,24 @@ public class QuestPreferences implements Serializable {
// Matches won per increased rank, by difficulty
// Rank affects how many packs are opened for singles in the spell shop
WINS_RANKUP("DIFFICULTY_INDEX_REQD"),
WINS_RANKUP_EASY("3"),
WINS_RANKUP_MEDIUM("4"),
WINS_RANKUP_HARD("5"),
WINS_RANKUP_EXPERT("6"),
// Matches won to unlock Medium Opponents, by difficulty
WINS_MEDIUMAI("DIFFICULTY_INDEX_REQD"),
WINS_MEDIUMAI_EASY("10"),
WINS_MEDIUMAI_MEDIUM("9"),
WINS_MEDIUMAI_HARD("8"),
WINS_MEDIUMAI_EXPERT("7"),
// Matches won to unlock Hard Opponents, by difficulty
WINS_HARDAI("DIFFICULTY_INDEX_REQD"),
WINS_HARDAI_EASY("20"),
WINS_HARDAI_MEDIUM("18"),
WINS_HARDAI_HARD("16"),
WINS_HARDAI_EXPERT("14"),
// Matches won to unlock Expert Opponents, by difficulty
WINS_EXPERTAI("DIFFICULTY_INDEX_REQD"),
WINS_EXPERTAI_EASY("40"),
WINS_EXPERTAI_MEDIUM("36"),
WINS_EXPERTAI_HARD("32"),
@@ -187,130 +160,47 @@ public class QuestPreferences implements Serializable {
}
}
public static enum DifficultyPrefs {
STARTING_COMMONS,
STARTING_UNCOMMONS,
STARTING_RARES,
STARTING_CREDITS,
WINS_BOOSTER,
WINS_RANKUP,
WINS_MEDIUMAI,
WINS_HARDAI,
WINS_EXPERTAI
}
/** Instantiates a QuestPreferences object. */
public QuestPreferences() {
this.preferenceValues = new HashMap<QPref, String>();
List<String> lines = FileUtil.readFile(NewConstants.QUEST_PREFERENCES_FILE.defaultLoc);
for (String line : lines) {
if (line.startsWith("#") || (line.length() == 0)) {
continue;
}
final String[] split = line.split("=");
if (split.length == 2) {
this.setPreference(split[0], split[1]);
}
}
super(NewConstants.QUEST_PREFS_FILE);
}
/** Saves prefs map to file. */
public void save() {
BufferedWriter writer = null;
protected QPref[] getEnumValues() {
return QPref.values();
}
protected QPref valueOf(String name) {
try {
writer = new BufferedWriter(new FileWriter(NewConstants.QUEST_PREFERENCES_FILE.defaultLoc));
for (final QPref key : QPref.values()) {
if (key.getDefault().equals("DIFFICULTY_INDEX_REQD")) {
writer.newLine();
continue;
}
writer.write(key + "=" + this.getPreference(key));
writer.newLine();
}
writer.flush();
writer.close();
} catch (final FileNotFoundException ex) {
ex.printStackTrace();
} catch (final IOException ex) {
ex.printStackTrace();
return QPref.valueOf(name);
}
catch (Exception e) {
return null;
}
}
/**
* Reset.
*/
public void reset() {
this.preferenceValues.clear();
}
/**
* DUE TO BE DEPRECATED: Transition code between preference manager for
* v1.2.2 and v1.2.3. (string-based vs. enum-based)
*
* @param s0
* &emsp; {@link java.lang.String} identifier of preference
* @param s1
* &emsp; {@link java.lang.String} value
*/
public void setPreference(final String s0, final String s1) {
try {
this.preferenceValues.put(QPref.valueOf(s0), s1);
} catch (final Exception e) {
}
}
/**
* Sets the preference.
*
* @param q0
* &emsp; {@link forge.quest.data.QuestPreferences.QPref}
* @param s0
* &emsp; {@link java.lang.String} value
*/
public void setPreference(final QPref q0, final String s0) {
this.preferenceValues.put(q0, s0);
}
/**
* Returns a non-difficulty-indexed preference value.
*
* @param qp0
* &emsp; {@link forge.quest.data.QuestPreferences.QPref}
* @return String
*/
public String getPreference(final QPref qp0) {
String val;
if (qp0.getDefault().equals("DIFFICULTY_INDEX_REQD")) {
// This error indicates that this is a preference
// value which is different based on difficulty.
// A difficulty index must be passed to determine
// which value is appropriate for this setting.
// To do this, use getPreference(QPref, int).
try {
throw new Exception();
} catch (final Exception e1) {
e1.printStackTrace();
}
}
val = this.preferenceValues.get(qp0);
if (val == null) {
val = qp0.getDefault();
}
return val;
protected String getPrefDefault(QPref key) {
return key.getDefault();
}
/**
* Returns a preference value according to a difficulty index.
*
* @param qp0
* &emsp; {@link forge.quest.data.QuestPreferences.QPref}
* @param i0
* &emsp; int difficulty index
* @return String
*/
public String getPreference(final QPref qp0, final int i0) {
String val;
String newQPref = qp0.toString();
QPref q;
public String getPref(DifficultyPrefs pref, int difficultyIndex) {
String newQPref = pref.toString();
switch (i0) {
switch (difficultyIndex) {
case 0:
newQPref += "_EASY";
break;
@@ -327,54 +217,27 @@ public class QuestPreferences implements Serializable {
try {
throw new Exception();
} catch (final Exception e1) {
System.err.println("Difficulty index (" + i0 + ") out of bounds! ");
System.err.println("Difficulty index out of bounds: " + difficultyIndex);
e1.printStackTrace();
}
}
q = QPref.valueOf(newQPref);
val = this.preferenceValues.get(q);
if (val == null) {
val = q.getDefault();
}
return val;
}
/**
* Returns a non-difficulty-indexed preference value, as an int.
*
* @param qp0
* &emsp; {@link forge.quest.data.QuestPreferences.QPref}
* @return int
*/
public int getPreferenceInt(final QPref qp0) {
return Integer.parseInt(this.getPreference(qp0));
return getPref(QPref.valueOf(newQPref));
}
/**
* Returns a difficulty-indexed preference value, as an int.
*
* @param qp0
* &emsp; {@link forge.quest.data.QuestPreferences.QPref}
* @param i0
* &emsp; int difficulty index
* @return int
*/
public int getPreferenceInt(final QPref qp0, final int i0) {
return Integer.parseInt(this.getPreference(qp0, i0));
public int getPrefInt(DifficultyPrefs pref, int difficultyIndex) {
return Integer.parseInt(this.getPref(pref, difficultyIndex));
}
/**
* Gets the difficulty.
*
* @param i
* &emsp; int
* @return String
*/
public static String getDifficulty(final int i) {
public static String getDifficulty(int difficultyIndex) {
String s;
switch (i) {
switch (difficultyIndex) {
case 1:
s = "EASY";
break;

View File

@@ -58,7 +58,7 @@ public class ReadPriceList {
* </p>
*/
private void setup() {
this.priceMap = this.readFile(NewConstants.QUEST_CARD_PRICE_FILE.defaultLoc);
this.priceMap = this.readFile(NewConstants.QUEST_CARD_PRICE_FILE);
this.priceMap.putAll(this.readFile(NewConstants.PRICES_BOOSTER_FILE));
} // setup()