Constants moved to better places

This commit is contained in:
Maxmtg
2012-10-02 07:55:58 +00:00
parent 3d732706eb
commit 5b4dc3fbd5
15 changed files with 35 additions and 84 deletions

View File

@@ -20,7 +20,6 @@ package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import forge.game.GameType;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
@@ -50,57 +49,14 @@ public final class Constant {
} }
public static class Runtime { public static class Runtime {
/** The skin name. */
private static String skinName = "default";
/** The game type. */
private static GameType gameType = GameType.Constructed;
/** The Constant NetConn. */ /** The Constant NetConn. */
public static final boolean[] NET_CONN = new boolean[1]; public static boolean NET_CONN = false;
/** The Constant width. */ /** The Constant width. */
public static final int[] WIDTH = { 300 }; public static final int WIDTH = 300;
/** The Constant height. */ /** The Constant height. */
public static final int[] HEIGHT = new int[1]; public static final int HEIGHT = 0;
/**
* Gets the game type.
*
* @return the gameType
*/
public static GameType getGameType() {
return Runtime.gameType;
}
/**
* Sets the game type.
*
* @param gameType0
* the gameType to set
*/
public static void setGameType(final GameType gameType0) {
Runtime.gameType = gameType0;
}
/**
* Gets the skin name.
*
* @return the skin name
*/
public static String getSkinName() {
return Runtime.skinName;
}
/**
* Sets the skin name.
*
* @param skinName the new skin name
*/
public static void setSkinName(final String skinName) {
Runtime.skinName = skinName;
}
} }
/** /**
@@ -127,8 +83,7 @@ public final class Constant {
public static final String COLORLESS = "colorless"; public static final String COLORLESS = "colorless";
// color order "wubrg" // color order "wubrg"
/** The Colors. */ /** The Colors. */
public static final String[] COLORS = { Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN, public static final String[] COLORS = { Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN, Color.COLORLESS };
Color.COLORLESS };
/** The only colors. */ /** The only colors. */
public static final String[] ONLY_COLORS = { Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN }; public static final String[] ONLY_COLORS = { Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN };
@@ -140,9 +95,6 @@ public final class Constant {
public static final String[] MANA_COLORS = { Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN, public static final String[] MANA_COLORS = { Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN,
Color.COLORLESS, Color.SNOW }; Color.COLORLESS, Color.SNOW };
/** The loaded. */
public static final boolean[] LOADED = { false };
/** The Basic lands. */ /** The Basic lands. */
public static final String[] BASIC_LANDS = { "Plains", "Island", "Swamp", "Mountain", "Forest" }; public static final String[] BASIC_LANDS = { "Plains", "Island", "Swamp", "Mountain", "Forest" };
} }

View File

@@ -280,10 +280,10 @@ public class ImageCache {
private static boolean isExpectedSize(final String key, final BufferedImage image) { private static boolean isExpectedSize(final String key, final BufferedImage image) {
if (key.endsWith(ImageCache.NORMAL)) { if (key.endsWith(ImageCache.NORMAL)) {
// normal // normal
return (image.getWidth() == Constant.Runtime.WIDTH[0]) && (image.getHeight() == Constant.Runtime.HEIGHT[0]); return (image.getWidth() == Constant.Runtime.WIDTH) && (image.getHeight() == Constant.Runtime.HEIGHT);
} else if (key.endsWith(ImageCache.TAPPED)) { } else if (key.endsWith(ImageCache.TAPPED)) {
// tapped // tapped
return (image.getWidth() == Constant.Runtime.HEIGHT[0]) && (image.getHeight() == Constant.Runtime.WIDTH[0]); return (image.getWidth() == Constant.Runtime.HEIGHT) && (image.getHeight() == Constant.Runtime.WIDTH);
} else { } else {
// original & full is never wrong // original & full is never wrong
return true; return true;
@@ -316,8 +316,8 @@ public class ImageCache {
private static BufferedImage getNormalSizeImage(final BufferedImage original) { private static BufferedImage getNormalSizeImage(final BufferedImage original) {
final int srcWidth = original.getWidth(); final int srcWidth = original.getWidth();
final int srcHeight = original.getHeight(); final int srcHeight = original.getHeight();
final int tgtWidth = Constant.Runtime.WIDTH[0]; final int tgtWidth = Constant.Runtime.WIDTH;
final int tgtHeight = Constant.Runtime.HEIGHT[0]; final int tgtHeight = Constant.Runtime.HEIGHT;
if ((srcWidth == tgtWidth) && (srcHeight == tgtHeight)) { if ((srcWidth == tgtWidth) && (srcHeight == tgtHeight)) {
return original; return original;
@@ -359,8 +359,8 @@ public class ImageCache {
* int srcWidth = original.getWidth(); int srcHeight = * int srcWidth = original.getWidth(); int srcHeight =
* original.getHeight(); * original.getHeight();
*/ */
final int tgtWidth = Constant.Runtime.WIDTH[0]; final int tgtWidth = Constant.Runtime.WIDTH;
final int tgtHeight = Constant.Runtime.HEIGHT[0]; final int tgtHeight = Constant.Runtime.HEIGHT;
final AffineTransform at = new AffineTransform(); final AffineTransform at = new AffineTransform();
// at.scale((double) tgtWidth / srcWidth, (double) tgtHeight / // at.scale((double) tgtWidth / srcWidth, (double) tgtHeight /

View File

@@ -19,7 +19,6 @@ import forge.CardListUtil;
import forge.CardPredicates.Presets; import forge.CardPredicates.Presets;
import forge.CardPredicates; import forge.CardPredicates;
import forge.CardUtil; import forge.CardUtil;
import forge.Constant;
import forge.Constant.Preferences; import forge.Constant.Preferences;
import forge.GameAction; import forge.GameAction;
import forge.Singletons; import forge.Singletons;
@@ -136,7 +135,7 @@ public class GameNew {
// friendliness // friendliness
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL)
&& Constant.Runtime.getGameType().equals(GameType.Constructed); && Singletons.getModel().getMatchState().getGameType().equals(GameType.Constructed);
final Random generator = MyRandom.getRandom(); final Random generator = MyRandom.getRandom();
final ArrayList<String> hAnteRemoved = new ArrayList<String>(); final ArrayList<String> hAnteRemoved = new ArrayList<String>();

View File

@@ -22,7 +22,6 @@ import javax.swing.SwingWorker;
import java.util.List; import java.util.List;
import forge.AllZone; import forge.AllZone;
import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.deck.Deck; import forge.deck.Deck;
import forge.game.GameNew; import forge.game.GameNew;
@@ -162,7 +161,7 @@ public class GauntletMini {
public Object doInBackground() { public Object doInBackground() {
Constant.Runtime.setGameType(gauntletType); Singletons.getModel().getMatchState().setGameType(gauntletType);
GameNew.newGame(AllZone.getHumanPlayer().getDeck(), AllZone.getComputerPlayer().getDeck()); GameNew.newGame(AllZone.getHumanPlayer().getDeck(), AllZone.getComputerPlayer().getDeck());

View File

@@ -13,7 +13,6 @@ import org.apache.commons.lang3.StringUtils;
import forge.AllZone; import forge.AllZone;
import forge.Command; import forge.Command;
import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.control.FControl; import forge.control.FControl;
import forge.deck.Deck; import forge.deck.Deck;
@@ -234,7 +233,7 @@ public class SSubmenuQuestUtil {
public Object doInBackground() { public Object doInBackground() {
AllZone.getHumanPlayer().setDeck(SSubmenuQuestUtil.getCurrentDeck()); AllZone.getHumanPlayer().setDeck(SSubmenuQuestUtil.getCurrentDeck());
AllZone.getComputerPlayer().setDeck(event.getEventDeck()); AllZone.getComputerPlayer().setDeck(event.getEventDeck());
Constant.Runtime.setGameType(GameType.Quest); Singletons.getModel().getMatchState().setGameType(GameType.Quest);
qData.getChallengesManager().randomizeOpponents(); qData.getChallengesManager().randomizeOpponents();
qData.getDuelsManager().randomizeOpponents(); qData.getDuelsManager().randomizeOpponents();

View File

@@ -25,7 +25,6 @@ import org.apache.commons.lang3.ArrayUtils;
import forge.AllZone; import forge.AllZone;
import forge.Command; import forge.Command;
import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.deck.Deck; import forge.deck.Deck;
import forge.deck.generate.Generate2ColorDeck; import forge.deck.generate.Generate2ColorDeck;
@@ -349,7 +348,7 @@ public enum CSubmenuConstructed implements ICDoc {
AllZone.getComputerPlayer().setDeck( AllZone.getComputerPlayer().setDeck(
generateDeck(VSubmenuConstructed.SINGLETON_INSTANCE.getLstAIDecks(), PlayerType.COMPUTER)); generateDeck(VSubmenuConstructed.SINGLETON_INSTANCE.getLstAIDecks(), PlayerType.COMPUTER));
Constant.Runtime.setGameType(GameType.Constructed); Singletons.getModel().getMatchState().setGameType(GameType.Constructed);
if (AllZone.getHumanPlayer().getDeck() != null && AllZone.getComputerPlayer().getDeck() != null) { if (AllZone.getHumanPlayer().getDeck() != null && AllZone.getComputerPlayer().getDeck() != null) {
GameNew.newGame(AllZone.getHumanPlayer().getDeck(), AllZone.getComputerPlayer().getDeck()); GameNew.newGame(AllZone.getHumanPlayer().getDeck(), AllZone.getComputerPlayer().getDeck());

View File

@@ -12,7 +12,6 @@ import javax.swing.SwingWorker;
import forge.AllZone; import forge.AllZone;
import forge.Command; import forge.Command;
import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.control.FControl; import forge.control.FControl;
import forge.deck.Deck; import forge.deck.Deck;
@@ -209,7 +208,7 @@ public enum CSubmenuDraft implements ICDoc {
throw new IllegalStateException("Draft: Computer deck is null!"); throw new IllegalStateException("Draft: Computer deck is null!");
} }
Constant.Runtime.setGameType(GameType.Draft); Singletons.getModel().getMatchState().setGameType(GameType.Draft);
GameNew.newGame(AllZone.getHumanPlayer().getDeck(), AllZone.getComputerPlayer().getDeck()); GameNew.newGame(AllZone.getHumanPlayer().getDeck(), AllZone.getComputerPlayer().getDeck());
return null; return null;
} }

View File

@@ -27,7 +27,6 @@ import javax.swing.ImageIcon;
import forge.AllZone; import forge.AllZone;
import forge.Card; import forge.Card;
import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.game.GameType; import forge.game.GameType;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
@@ -75,7 +74,7 @@ public enum CMatchUI implements CardContainer {
for (int i = 0; i < views.length; i++) { for (int i = 0; i < views.length; i++) {
final Image img; final Image img;
// Update AI quest icon // Update AI quest icon
if (i != 1 && Constant.Runtime.getGameType() == GameType.Quest) { if (i != 1 && Singletons.getModel().getMatchState().getGameType() == GameType.Quest) {
String filename = ForgeProps.getFile(NewConstants.IMAGE_ICON) + File.separator; String filename = ForgeProps.getFile(NewConstants.IMAGE_ICON) + File.separator;
if (strAvatarIcon != null) { if (strAvatarIcon != null) {

View File

@@ -9,7 +9,6 @@ import javax.swing.JButton;
import forge.AllZone; import forge.AllZone;
import forge.Card; import forge.Card;
import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.control.FControl; import forge.control.FControl;
import forge.deck.Deck; import forge.deck.Deck;
@@ -89,7 +88,7 @@ public class ControlWinLose {
*/ */
public void startNextRound() { public void startNextRound() {
boolean isAnte = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ANTE); boolean isAnte = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ANTE);
GameType gameType = Constant.Runtime.getGameType(); GameType gameType = Singletons.getModel().getMatchState().getGameType();
Deck hDeck = AllZone.getHumanPlayer().getDeck(); Deck hDeck = AllZone.getHumanPlayer().getDeck();
Deck cDeck = AllZone.getComputerPlayer().getDeck(); Deck cDeck = AllZone.getComputerPlayer().getDeck();

View File

@@ -11,7 +11,6 @@ import javax.swing.SwingConstants;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import forge.AllZone; import forge.AllZone;
import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.game.GameType; import forge.game.GameType;
import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseHandler;
@@ -55,11 +54,11 @@ public class ViewWinLose {
// Control of the win/lose is handled differently for various game modes. // Control of the win/lose is handled differently for various game modes.
ControlWinLose control; ControlWinLose control;
if (Constant.Runtime.getGameType() == GameType.Quest) { if (Singletons.getModel().getMatchState().getGameType() == GameType.Quest) {
control = new QuestWinLoseHandler(this); control = new QuestWinLoseHandler(this);
} }
else if ((Constant.Runtime.getGameType() == GameType.Sealed) else if (Singletons.getModel().getMatchState().getGameType() == GameType.Sealed
|| (Constant.Runtime.getGameType() == GameType.Draft && AllZone.getGauntlet().getGauntletDraft())) { || (Singletons.getModel().getMatchState().getGameType() == GameType.Draft && AllZone.getGauntlet().getGauntletDraft())) {
control = new GauntletWinLose(this); control = new GauntletWinLose(this);
} }

View File

@@ -21,7 +21,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import forge.Command; import forge.Command;
import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.gui.GuiInput; import forge.gui.GuiInput;
import forge.gui.framework.ICDoc; import forge.gui.framework.ICDoc;
@@ -86,7 +85,7 @@ public enum CMessage implements ICDoc {
/** Updates counter label in message area. */ /** Updates counter label in message area. */
public void updateGameInfo() { public void updateGameInfo() {
VMessage.SINGLETON_INSTANCE.getLblGames().setText( VMessage.SINGLETON_INSTANCE.getLblGames().setText(
Constant.Runtime.getGameType().toString() + ": Game #" Singletons.getModel().getMatchState().getGameType().toString() + ": Game #"
+ (Singletons.getModel().getMatchState().getGamesPlayedCount() + 1) + (Singletons.getModel().getMatchState().getGamesPlayedCount() + 1)
+ " of " + Singletons.getModel().getMatchState().getGamesPerMatch() + " of " + Singletons.getModel().getMatchState().getGamesPerMatch()
+ ", turn " + Singletons.getModel().getGameSummary().getLastTurnNumber()); + ", turn " + Singletons.getModel().getGameSummary().getLastTurnNumber());

View File

@@ -26,6 +26,7 @@ import forge.AllZone;
import forge.Card; import forge.Card;
import forge.game.GameSummary; import forge.game.GameSummary;
import forge.game.GameType;
import forge.item.CardDb; import forge.item.CardDb;
import forge.item.CardPrinted; import forge.item.CardPrinted;
@@ -213,4 +214,13 @@ public class FMatchState {
this.antesWon.clear(); this.antesWon.clear();
this.antesLost.clear(); this.antesLost.clear();
} }
private GameType gameType = GameType.Constructed;
public GameType getGameType() {
return gameType;
}
public void setGameType(final GameType gameType0) {
gameType = gameType0;
}
} }

View File

@@ -148,7 +148,7 @@ public enum FModel {
// Set gameplay preferences and constants // Set gameplay preferences and constants
final HttpUtil pinger = new HttpUtil(); final HttpUtil pinger = new HttpUtil();
final String url = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/draftAI/ping.php"; final String url = ForgeProps.getProperty(NewConstants.CARDFORGE_URL) + "/draftAI/ping.php";
Constant.Runtime.NET_CONN[0] = (pinger.getURL(url).equals("pong") ? true : false); Constant.Runtime.NET_CONN = (pinger.getURL(url).equals("pong") ? true : false);
this.setBuildInfo(new BuildInfo()); this.setBuildInfo(new BuildInfo());
FModel.loadDynamicGamedata(); FModel.loadDynamicGamedata();
@@ -231,10 +231,8 @@ public enum FModel {
if (!Constant.Keywords.LOADED[0]) { if (!Constant.Keywords.LOADED[0]) {
final List<String> nskwListFile = FileUtil.readFile("res/gamedata/NonStackingKWList.txt"); final List<String> nskwListFile = FileUtil.readFile("res/gamedata/NonStackingKWList.txt");
if (nskwListFile.size() > 1) { if (nskwListFile.size() > 1) {
for (int i = 0; i < nskwListFile.size(); i++) { for (String s : nskwListFile) {
final String s = nskwListFile.get(i);
if (s.length() > 1) { if (s.length() > 1) {
Constant.Keywords.NON_STACKING_LIST.add(s); Constant.Keywords.NON_STACKING_LIST.add(s);
} }

View File

@@ -251,7 +251,7 @@ public class ForgePreferences {
final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
Preferences.DEV_MODE = this.getPrefBoolean(FPref.DEV_MODE_ENABLED); Preferences.DEV_MODE = this.getPrefBoolean(FPref.DEV_MODE_ENABLED);
Preferences.UPLOAD_DRAFT = (Constant.Runtime.NET_CONN[0] ? this.getPrefBoolean(FPref.UI_UPLOAD_DRAFT) : false); Preferences.UPLOAD_DRAFT = Constant.Runtime.NET_CONN && this.getPrefBoolean(FPref.UI_UPLOAD_DRAFT);
// AI field is at index [0] // AI field is at index [0]
fieldViews.get(0).getLblUpkeep().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_UPKEEP)); fieldViews.get(0).getLblUpkeep().setEnabled(this.getPrefBoolean(FPref.PHASE_AI_UPKEEP));

View File

@@ -62,7 +62,7 @@ public abstract class CardPanelContainer extends JPanel {
*/ */
private int cardWidthMin = 50; private int cardWidthMin = 50;
private int cardWidthMax = Constant.Runtime.WIDTH[0]; private int cardWidthMax = Constant.Runtime.WIDTH;
/** /**
* *
*/ */