Constant.preferences

This commit is contained in:
Maxmtg
2012-10-02 06:59:52 +00:00
parent 293d4d584d
commit 789e16ff25
14 changed files with 76 additions and 93 deletions

View File

@@ -41,6 +41,20 @@ public final class Constant {
/**
* The Class Runtime.
*/
public static class Preferences {
/** The Constant Mill. */
public static boolean MILL;
/** The Constant DevMode. */
// one for normal mode, one for quest mode
public static boolean DEV_MODE;
/** The Constant UpldDrft. */
public static boolean UPLOAD_DRAFT;
/** The Constant RndCFoil. */
public static boolean RANDOM_FOIL;
}
public static class Runtime {
/** The Constant HumanDeck. */
@@ -58,34 +72,15 @@ public final class Constant {
/** The Constant Smooth. */
public static final boolean[] SMOOTH = new boolean[1];
/** The Constant Mill. */
public static final boolean[] MILL = new boolean[1];
/** The Constant DevMode. */
// one for normal mode, one for quest mode
public static final boolean[] DEV_MODE = new boolean[1];
/** The Constant NetConn. */
public static final boolean[] NET_CONN = new boolean[1];
/** The Constant UpldDrft. */
public static final boolean[] UPLOAD_DRAFT = new boolean[1];
/** The Constant RndCFoil. */
public static final boolean[] RANDOM_FOIL = new boolean[1];
/** The Constant width. */
public static final int[] WIDTH = { 300 };
/** The Constant height. */
public static final int[] HEIGHT = new int[1];
/** The Constant stackSize. */
public static final int[] STACK_SIZE = new int[1];
/** The Constant stackOffset. */
public static final int[] STACK_OFFSET = new int[1];
/**
* Gets the game type.
*

View File

@@ -47,7 +47,6 @@ import forge.game.player.ComputerUtil;
import forge.game.player.Player;
import forge.game.zone.ZoneType;
import forge.gui.GuiChoose;
import forge.gui.GuiUtils;
import forge.util.MyRandom;
/**

View File

@@ -19,7 +19,6 @@ import forge.card.cost.Cost;
import forge.card.spellability.Ability;
import forge.card.spellability.AbilityActivated;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.SpellPermanent;
import forge.card.spellability.Target;
import forge.control.input.Input;
import forge.game.player.Player;

View File

@@ -22,7 +22,6 @@ import java.util.List;
import javax.swing.JOptionPane;
import com.esotericsoftware.minlog.Log;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
@@ -51,7 +50,6 @@ import forge.card.spellability.AbilityStatic;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.SpellPermanent;
import forge.card.spellability.Target;
import forge.card.trigger.Trigger;
import forge.control.input.Input;
import forge.game.player.Player;
import forge.game.zone.PlayerZone;

View File

@@ -20,6 +20,7 @@ import forge.CardPredicates.Presets;
import forge.CardPredicates;
import forge.CardUtil;
import forge.Constant;
import forge.Constant.Preferences;
import forge.GameAction;
import forge.Singletons;
import forge.control.FControl;
@@ -68,6 +69,7 @@ public class GameNew {
public static void newGame(final Deck humanDeck, final Deck computerDeck, final List<Card> humanStart,
final List<Card> computerStart, final int humanLife, final int computerLife, String iconEnemy) {
Singletons.getControl().changeState(FControl.MATCH_SCREEN);
CMatchUI.SINGLETON_INSTANCE.initMatch(iconEnemy);
GameNew.newGameCleanup();
@@ -133,7 +135,7 @@ public class GameNew {
CMessage.SINGLETON_INSTANCE.updateGameInfo();
// friendliness
final boolean canRandomFoil = Constant.Runtime.RANDOM_FOIL[0]
final boolean canRandomFoil = Preferences.RANDOM_FOIL
&& Constant.Runtime.getGameType().equals(GameType.Constructed);
final Random generator = MyRandom.getRandom();
@@ -336,7 +338,7 @@ public class GameNew {
if (Singletons.getModel().getMatchState().getGamesPlayedCount() != 0) { return; }
// Update mouse events in case of dev mode toggle
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
// TODO restore this functionality!!!
//VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(true);
final List<VField> allFields = VMatchUI.SINGLETON_INSTANCE.getFieldViews();

View File

@@ -32,7 +32,7 @@ import com.google.common.base.Function;
import forge.Card;
import forge.Constant;
import forge.Constant.Preferences;
import forge.Singletons;
import forge.card.BoosterGenerator;
import forge.card.CardBlock;
@@ -340,7 +340,7 @@ public final class BoosterDraft implements IBoosterDraft {
+ " - booster pack = " + thisBooster);
}
if (Constant.Runtime.UPLOAD_DRAFT[0]) {
if (Preferences.UPLOAD_DRAFT) {
for (int i = 0; i < thisBooster.size(); i++) {
final CardPrinted cc = thisBooster.get(i);
final String cnBk = cc.getName() + "|" + cc.getEdition();
@@ -370,7 +370,7 @@ public final class BoosterDraft implements IBoosterDraft {
/** This will upload drafting picks to cardforge HQ. */
@Override
public void finishedDrafting() {
if (Constant.Runtime.UPLOAD_DRAFT[0]) {
if (Preferences.UPLOAD_DRAFT) {
if (this.draftPicks.size() > 1) {
final ArrayList<String> outDraftData = new ArrayList<String>();

View File

@@ -29,6 +29,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Constant;
import forge.Constant.Preferences;
import forge.card.CardColor;
import forge.card.CardRulesPredicates;
import forge.card.CardRules;
@@ -74,7 +75,7 @@ public class BoosterDraftAI {
* @return a {@link forge.CardList} object.
*/
public CardPrinted choose(final List<CardPrinted> chooseFrom, final int player) {
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Player[" + player + "] pack: " + chooseFrom.toString());
}
@@ -134,7 +135,7 @@ public class BoosterDraftAI {
}
}
}
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Player[" + player + "] Color1: " + this.playerColors.get(player).getColor1());
if (!this.playerColors.get(player).getColor2().equals("none")) {
System.out.println("Player[" + player + "] Color2: "
@@ -192,7 +193,7 @@ public class BoosterDraftAI {
}
}
}
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Player[" + player + "] Color2: " + this.playerColors.get(player).getColor2());
}
}
@@ -306,7 +307,7 @@ public class BoosterDraftAI {
final Deck[] out = new Deck[this.deck.size()];
for (int i = 0; i < this.deck.size(); i++) {
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Deck[" + i + "]");
}

View File

@@ -17,7 +17,7 @@ import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Constant;
import forge.Constant.Preferences;
import forge.card.CardColor;
import forge.card.CardManaCost;
import forge.card.CardRulesPredicates;
@@ -135,7 +135,7 @@ public class LimitedDeck {
deckList.add(c);
getAiPlayables().remove(c);
landsNeeded--;
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Low CMC:" + c.getName());
}
}
@@ -167,7 +167,7 @@ public class LimitedDeck {
result.getMain().add(deckList);
result.getSideboard().add(aiPlayables);
result.getSideboard().add(availableList);
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
debugFinalDeck();
}
return result;
@@ -290,7 +290,7 @@ public class LimitedDeck {
final float p = (float) clrCnts[i].getCount() / (float) totalColor;
final int nLand = (int) (landsNeeded * p); // desired truncation
// to int
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Basics[" + clrCnts[i].getColor() + "]: " + clrCnts[i].getCount() + "/"
+ totalColor + " = " + p + " = " + nLand);
}
@@ -313,7 +313,7 @@ public class LimitedDeck {
deckList.add(cp);
landsNeeded--;
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("AddBasics: " + cp.getName());
}
}
@@ -391,7 +391,7 @@ public class LimitedDeck {
//
// lands = getAiPlayables().getType("Land");
//
// if (Constant.Runtime.DEV_MODE[0]) {
// if (Constant.Runtime.DEV_MODE) {
// System.out.println("Land:" + c.getName());
// }
// }
@@ -410,7 +410,7 @@ public class LimitedDeck {
deckList.add(bean.getValue());
aiPlayables.remove(bean.getValue());
nCards--;
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Random[" + nCards + "]:" + bean.getValue().getName() + "("
+ bean.getValue().getCard().getManaCost() + ")");
}
@@ -434,7 +434,7 @@ public class LimitedDeck {
deckList.add(cardToAdd);
num--;
getAiPlayables().remove(cardToAdd);
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Others[" + num + "]:" + cardToAdd.getName() + " ("
+ cardToAdd.getCard().getManaCost() + ")");
}
@@ -461,7 +461,7 @@ public class LimitedDeck {
DeckHints hints = cardToAdd.getCard().getDeckHints();
Iterable<CardPrinted> onColor = Iterables.filter(aiPlayables, Predicates.compose(hasColor, CardPrinted.FN_GET_RULES));
List<CardPrinted> comboCards = hints.filter(onColor);
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Found " + comboCards.size() + " cards for " + cardToAdd.getName());
}
for (Pair<Double, CardPrinted> comboBean : rankCards(comboCards)) {
@@ -509,7 +509,7 @@ public class LimitedDeck {
comboCards.addAll(hints.filter(deckList));
}
if (comboCards.isEmpty()) {
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("No combo cards found for " + card.getName() + ", removing it.");
}
it.remove();
@@ -520,7 +520,7 @@ public class LimitedDeck {
numOthers++;
}
} else {
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Found " + comboCards.size() + " cards for " + card.getName());
}
}
@@ -554,7 +554,7 @@ public class LimitedDeck {
deckList.add(c);
num--;
getAiPlayables().remove(c);
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Creature[" + num + "]:" + c.getName() + " (" + c.getCard().getManaCost() + ")");
}
num = addDeckHintsCards(c, num);
@@ -618,12 +618,12 @@ public class LimitedDeck {
num--;
getAiPlayables().remove(c);
creatureCosts.put(cmc, creatureCosts.get(cmc) + 1);
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println("Creature[" + num + "]:" + c.getName() + " (" + c.getCard().getManaCost() + ")");
}
num = addDeckHintsCards(c, num);
} else {
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println(c.getName() + " not added because CMC " + c.getCard().getManaCost().getCMC()
+ " has " + currentAtCmc + " already.");
}

View File

@@ -38,6 +38,7 @@ import forge.CardListUtil;
import forge.CardPredicates;
import forge.CardUtil;
import forge.Constant;
import forge.Constant.Preferences;
import forge.GameActionUtil;
import forge.GameEntity;
import forge.Singletons;
@@ -1303,9 +1304,8 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
AllZone.getTriggerHandler().runTrigger(TriggerType.Drawn, runParams);
}
// lose:
else if (!Constant.Runtime.DEV_MODE[0] || Constant.Runtime.MILL[0]) {
// if devMode is off, or canLoseByDecking is Enabled, run Lose
// Condition
else if (!Preferences.DEV_MODE || Preferences.MILL) {
// if devMode is off, or canLoseByDecking is Enabled, run Lose condition
if (!this.cantLose()) {
this.loseConditionMet(GameLossReason.Milled, null);
Singletons.getModel().getGameAction().checkStateEffects();
@@ -1322,7 +1322,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* @return the zone
*/
public final PlayerZone getZone(final ZoneType zone) {
return this.zones.get(zone);
return zone == ZoneType.Stack ? AllZone.getStackZone() : this.zones.get(zone);
}
/**
@@ -1334,8 +1334,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* @return a List<Card> with all the cards currently in requested zone
*/
public final List<Card> getCardsIn(final ZoneType zone) {
final List<Card> cards = zone == ZoneType.Stack ? AllZone.getStackZone().getCards() : this.getZone(zone).getCards();
return new ArrayList<Card>(cards);
return this.getZone(zone).getCards();
}
/**
@@ -1355,9 +1354,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* @return the cards include phasing in
*/
public final List<Card> getCardsIncludePhasingIn(final ZoneType zone) {
final List<Card> cards = zone == ZoneType.Stack ? AllZone.getStackZone().getCards() : this.getZone(zone)
.getCards(false);
return new ArrayList<Card>(cards);
return this.getZone(zone).getCards(false);
}
/**
@@ -1371,7 +1368,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* @return a List<Card> with all the cards currently in requested zone
*/
public final List<Card> getCardsIn(final ZoneType zone, final int n) {
return new ArrayList<Card>(this.getZone(zone).getCards(n));
return this.getZone(zone).getCards(n);
}
/**
@@ -1381,7 +1378,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* the zones
* @return a List<Card> with all the cards currently in requested zones
*/
public final List<Card> getCardsIn(final List<ZoneType> zones) {
public final List<Card> getCardsIn(final Iterable<ZoneType> zones) {
final List<Card> result = new ArrayList<Card>();
for (final ZoneType z : zones) {
if (z == ZoneType.Stack) {
@@ -1431,18 +1428,13 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
*/
protected final List<Card> getDredge() {
final List<Card> dredge = new ArrayList<Card>();
final List<Card> cl = this.getCardsIn(ZoneType.Graveyard);
for (final Card c : cl) {
final ArrayList<String> kw = c.getKeyword();
for (int i = 0; i < kw.size(); i++) {
if (kw.get(i).toString().startsWith("Dredge")) {
if (this.getCardsIn(ZoneType.Library).size() >= this.getDredgeNumber(c)) {
int cntLibrary = this.getCardsIn(ZoneType.Library).size();
for (final Card c : this.getCardsIn(ZoneType.Graveyard)) {
int nDr = getDredgeNumber(c);
if ( nDr > 0 && cntLibrary >= nDr) {
dredge.add(c);
}
}
}
}
return dredge;
} // hasDredge()
@@ -1456,18 +1448,13 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
* @return a int.
*/
protected final int getDredgeNumber(final Card c) {
final ArrayList<String> a = c.getKeyword();
for (int i = 0; i < a.size(); i++) {
if (a.get(i).toString().startsWith("Dredge")) {
final String s = a.get(i).toString();
for (String s : c.getKeyword()) {
if (s.startsWith("Dredge")) {
return Integer.parseInt("" + s.charAt(s.length() - 1));
}
}
final StringBuilder sb = new StringBuilder();
sb.append("Input_Draw : getDredgeNumber() card doesn't have dredge - ").append(c.getName());
throw new RuntimeException(sb.toString());
return 0;
// throw new RuntimeException("Input_Draw : getDredgeNumber() card doesn't have dredge - " + c.getName());
} // getDredgeNumber()
/**
@@ -1836,7 +1823,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
public final boolean canPlayLand() {
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.DEV_UNLIMITED_LAND)
&& this.isHuman()
&& Constant.Runtime.DEV_MODE[0]) {
&& Preferences.DEV_MODE) {
return PhaseHandler.canCastSorcery(this);
}

View File

@@ -9,6 +9,7 @@ import org.apache.commons.lang3.text.WordUtils;
import forge.Command;
import forge.Constant;
import forge.Constant.Preferences;
import forge.Singletons;
import forge.control.RestartUtil;
import forge.gui.framework.ICDoc;
@@ -74,7 +75,7 @@ public enum CSubmenuPreferences implements ICDoc {
public void itemStateChanged(final ItemEvent arg0) {
final boolean toggle = view.getCbDevMode().isSelected();
prefs.setPref(FPref.DEV_MODE_ENABLED, String.valueOf(toggle));
Constant.Runtime.DEV_MODE[0] = toggle;
Preferences.DEV_MODE = toggle;
prefs.save();
}
});
@@ -111,7 +112,7 @@ public enum CSubmenuPreferences implements ICDoc {
public void itemStateChanged(final ItemEvent arg0) {
final boolean toggle = view.getCbUploadDraft().isSelected();
prefs.setPref(FPref.UI_UPLOAD_DRAFT , String.valueOf(toggle));
Constant.Runtime.UPLOAD_DRAFT[0] = toggle;
Preferences.UPLOAD_DRAFT = toggle;
prefs.save();
}
});
@@ -131,7 +132,7 @@ public enum CSubmenuPreferences implements ICDoc {
public void itemStateChanged(final ItemEvent arg0) {
final boolean toggle = view.getCbRandomFoil().isSelected();
prefs.setPref(FPref.UI_RANDOM_FOIL, String.valueOf(toggle));
Constant.Runtime.RANDOM_FOIL[0] = toggle;
Preferences.RANDOM_FOIL = toggle;
prefs.save();
}
});

View File

@@ -35,6 +35,7 @@ import forge.Card;
import forge.Command;
import forge.Constant;
import forge.Constant.Preferences;
import forge.Singletons;
import forge.card.cardfactory.CardFactoryUtil;
import forge.control.input.Input;
@@ -326,7 +327,7 @@ public class CField implements ICDoc {
if (!CField.this.player.isComputer()) {
new ZoneAction(CField.this.player.getZone(ZoneType.Hand), HumanHand.BASE)
.actionPerformed(null);
} else if (Constant.Runtime.DEV_MODE[0]
} else if (Preferences.DEV_MODE
|| CField.this.player.hasKeyword("Play with your hand revealed.")) {
new ZoneAction(CField.this.player.getZone(ZoneType.Hand), ComputerHand.BASE)
.actionPerformed(null);
@@ -373,7 +374,7 @@ public class CField implements ICDoc {
/** */
private void libraryAction() {
if (!Constant.Runtime.DEV_MODE[0]) { return; }
if (!Preferences.DEV_MODE) { return; }
if (!CField.this.player.isComputer()) {
new ZoneAction(CField.this.player.getZone(ZoneType.Library), HumanLibrary.BASE)

View File

@@ -27,6 +27,7 @@ import java.util.List;
import forge.AllZone;
import forge.Constant;
import forge.Constant.Preferences;
import forge.GameAction;
import forge.Singletons;
import forge.card.BoosterData;
@@ -138,7 +139,7 @@ public enum FModel {
this.fantasyBlocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/fantasyblocks.txt", editions));
// TODO - there's got to be a better place for this...oblivion?
Constant.Runtime.DEV_MODE[0] = this.preferences.getPrefBoolean(FPref.DEV_MODE_ENABLED);
Preferences.DEV_MODE = this.preferences.getPrefBoolean(FPref.DEV_MODE_ENABLED);
// Instantiate AI
AllZone.setInputControl(new InputControl(FModel.this));

View File

@@ -33,6 +33,7 @@ import java.util.List;
import java.util.Map;
import forge.Constant;
import forge.Constant.Preferences;
import forge.gui.home.EMenuItem;
import forge.gui.match.VMatchUI;
import forge.gui.match.nonsingleton.VField;
@@ -237,9 +238,9 @@ public class ForgePreferences {
this.setPref(FPref.PHASE_HUMAN_CLEANUP, String.valueOf(fieldViews.get(1).getLblCleanup().getEnabled()));
final VDev v = VDev.SINGLETON_INSTANCE;
Constant.Runtime.MILL[0] = v.getLblMilling().getEnabled();
Preferences.MILL = v.getLblMilling().getEnabled();
this.setPref(FPref.DEV_MILLING_LOSS, String.valueOf(Constant.Runtime.MILL[0]));
this.setPref(FPref.DEV_MILLING_LOSS, String.valueOf(Preferences.MILL));
this.setPref(FPref.DEV_UNLIMITED_LAND, String.valueOf(v.getLblUnlimitedLands().getEnabled()));
}
@@ -250,12 +251,10 @@ public class ForgePreferences {
public void actuateMatchPreferences() {
final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
Constant.Runtime.MILL[0] = this.getPrefBoolean(FPref.DEV_MILLING_LOSS);
Constant.Runtime.DEV_MODE[0] = this.getPrefBoolean(FPref.DEV_MODE_ENABLED);
Constant.Runtime.UPLOAD_DRAFT[0] = this.getPrefBoolean(FPref.UI_UPLOAD_DRAFT);
Constant.Runtime.RANDOM_FOIL[0] = this.getPrefBoolean(FPref.UI_RANDOM_FOIL);
Constant.Runtime.UPLOAD_DRAFT[0] = (Constant.Runtime.NET_CONN[0] ? this.getPrefBoolean(FPref.UI_UPLOAD_DRAFT)
: false);
Preferences.MILL = this.getPrefBoolean(FPref.DEV_MILLING_LOSS);
Preferences.DEV_MODE = this.getPrefBoolean(FPref.DEV_MODE_ENABLED);
Preferences.RANDOM_FOIL = this.getPrefBoolean(FPref.UI_RANDOM_FOIL);
Preferences.UPLOAD_DRAFT = (Constant.Runtime.NET_CONN[0] ? this.getPrefBoolean(FPref.UI_UPLOAD_DRAFT) : false);
// AI field is at index [0]
fieldViews.get(0).getLblUpkeep().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_UPKEEP));

View File

@@ -27,7 +27,7 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import forge.Constant;
import forge.Constant.Preferences;
/**
* <p>
@@ -149,7 +149,7 @@ public class HttpUtil {
} catch (final IOException e) {
return;
}
if (Constant.Runtime.DEV_MODE[0]) {
if (Preferences.DEV_MODE) {
System.out.println(response.toString());
}
}