mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Further semantic organization of FModel.
Main is now free of any non-essential calls and methods. FView now free of all non-view-related calls and methods.
This commit is contained in:
@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
|
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
|
||||||
import arcane.util.MultiplexOutputStream;
|
import arcane.util.MultiplexOutputStream;
|
||||||
@@ -30,6 +31,8 @@ import forge.AllZone;
|
|||||||
import forge.ComputerAIGeneral;
|
import forge.ComputerAIGeneral;
|
||||||
import forge.ComputerAIInput;
|
import forge.ComputerAIInput;
|
||||||
import forge.Constant;
|
import forge.Constant;
|
||||||
|
import forge.ConstantStringArrayList;
|
||||||
|
import forge.FileUtil;
|
||||||
import forge.HttpUtil;
|
import forge.HttpUtil;
|
||||||
import forge.gui.input.InputControl;
|
import forge.gui.input.InputControl;
|
||||||
import forge.properties.ForgePreferences;
|
import forge.properties.ForgePreferences;
|
||||||
@@ -56,6 +59,7 @@ public class FModel {
|
|||||||
/** The preferences. */
|
/** The preferences. */
|
||||||
private ForgePreferences preferences;
|
private ForgePreferences preferences;
|
||||||
private FGameState gameState;
|
private FGameState gameState;
|
||||||
|
private final boolean http;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -109,12 +113,132 @@ public class FModel {
|
|||||||
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";
|
||||||
if (pinger.getURL(url).equals("pong")) {
|
if (pinger.getURL(url).equals("pong")) {
|
||||||
|
http = true;
|
||||||
Constant.Runtime.NET_CONN[0] = true;
|
Constant.Runtime.NET_CONN[0] = true;
|
||||||
} else {
|
} else {
|
||||||
|
http = false;
|
||||||
Constant.Runtime.UPLOAD_DRAFT[0] = false;
|
Constant.Runtime.UPLOAD_DRAFT[0] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setBuildInfo(new BuildInfo());
|
this.setBuildInfo(new BuildInfo());
|
||||||
|
FModel.loadDynamicGamedata();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load dynamic gamedata.
|
||||||
|
*/
|
||||||
|
public static void loadDynamicGamedata() {
|
||||||
|
if (!Constant.CardTypes.LOADED[0]) {
|
||||||
|
final ArrayList<String> typeListFile = FileUtil.readFile("res/gamedata/TypeLists.txt");
|
||||||
|
|
||||||
|
ArrayList<String> tList = null;
|
||||||
|
|
||||||
|
Constant.CardTypes.CARD_TYPES[0] = new ConstantStringArrayList();
|
||||||
|
Constant.CardTypes.SUPER_TYPES[0] = new ConstantStringArrayList();
|
||||||
|
Constant.CardTypes.BASIC_TYPES[0] = new ConstantStringArrayList();
|
||||||
|
Constant.CardTypes.LAND_TYPES[0] = new ConstantStringArrayList();
|
||||||
|
Constant.CardTypes.CREATURE_TYPES[0] = new ConstantStringArrayList();
|
||||||
|
Constant.CardTypes.INSTANT_TYPES[0] = new ConstantStringArrayList();
|
||||||
|
Constant.CardTypes.SORCERY_TYPES[0] = new ConstantStringArrayList();
|
||||||
|
Constant.CardTypes.ENCHANTMENT_TYPES[0] = new ConstantStringArrayList();
|
||||||
|
Constant.CardTypes.ARTIFACT_TYPES[0] = new ConstantStringArrayList();
|
||||||
|
Constant.CardTypes.WALKER_TYPES[0] = new ConstantStringArrayList();
|
||||||
|
|
||||||
|
if (typeListFile.size() > 0) {
|
||||||
|
for (int i = 0; i < typeListFile.size(); i++) {
|
||||||
|
final String s = typeListFile.get(i);
|
||||||
|
|
||||||
|
if (s.equals("[CardTypes]")) {
|
||||||
|
tList = Constant.CardTypes.CARD_TYPES[0].getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (s.equals("[SuperTypes]")) {
|
||||||
|
tList = Constant.CardTypes.SUPER_TYPES[0].getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (s.equals("[BasicTypes]")) {
|
||||||
|
tList = Constant.CardTypes.BASIC_TYPES[0].getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (s.equals("[LandTypes]")) {
|
||||||
|
tList = Constant.CardTypes.LAND_TYPES[0].getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (s.equals("[CreatureTypes]")) {
|
||||||
|
tList = Constant.CardTypes.CREATURE_TYPES[0].getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (s.equals("[InstantTypes]")) {
|
||||||
|
tList = Constant.CardTypes.INSTANT_TYPES[0].getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (s.equals("[SorceryTypes]")) {
|
||||||
|
tList = Constant.CardTypes.SORCERY_TYPES[0].getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (s.equals("[EnchantmentTypes]")) {
|
||||||
|
tList = Constant.CardTypes.ENCHANTMENT_TYPES[0].getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (s.equals("[ArtifactTypes]")) {
|
||||||
|
tList = Constant.CardTypes.ARTIFACT_TYPES[0].getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (s.equals("[WalkerTypes]")) {
|
||||||
|
tList = Constant.CardTypes.WALKER_TYPES[0].getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (s.length() > 1) {
|
||||||
|
tList.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Constant.CardTypes.LOADED[0] = true;
|
||||||
|
/*
|
||||||
|
* if (Constant.Runtime.DevMode[0]) {
|
||||||
|
* System.out.println(Constant.CardTypes.cardTypes[0].list);
|
||||||
|
* System.out.println(Constant.CardTypes.superTypes[0].list);
|
||||||
|
* System.out.println(Constant.CardTypes.basicTypes[0].list);
|
||||||
|
* System.out.println(Constant.CardTypes.landTypes[0].list);
|
||||||
|
* System.out.println(Constant.CardTypes.creatureTypes[0].list);
|
||||||
|
* System.out.println(Constant.CardTypes.instantTypes[0].list);
|
||||||
|
* System.out.println(Constant.CardTypes.sorceryTypes[0].list);
|
||||||
|
* System.out.println(Constant.CardTypes.enchantmentTypes[0].list);
|
||||||
|
* System.out.println(Constant.CardTypes.artifactTypes[0].list);
|
||||||
|
* System.out.println(Constant.CardTypes.walkerTypes[0].list); }
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Constant.Keywords.LOADED[0]) {
|
||||||
|
final ArrayList<String> nskwListFile = FileUtil.readFile("res/gamedata/NonStackingKWList.txt");
|
||||||
|
|
||||||
|
Constant.Keywords.NON_STACKING_LIST[0] = new ConstantStringArrayList();
|
||||||
|
|
||||||
|
if (nskwListFile.size() > 1) {
|
||||||
|
for (int i = 0; i < nskwListFile.size(); i++) {
|
||||||
|
final String s = nskwListFile.get(i);
|
||||||
|
if (s.length() > 1) {
|
||||||
|
Constant.Keywords.NON_STACKING_LIST[0].getList().add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Constant.Keywords.LOADED[0] = true;
|
||||||
|
/*
|
||||||
|
* if (Constant.Runtime.DevMode[0]) {
|
||||||
|
* System.out.println(Constant.Keywords.NonStackingList[0].list); }
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if (!Constant.Color.loaded[0]) { ArrayList<String> lcListFile =
|
||||||
|
* FileUtil.readFile("res/gamedata/LandColorList");
|
||||||
|
*
|
||||||
|
* if (lcListFile.size() > 1) { for (int i=0; i<lcListFile.size(); i++)
|
||||||
|
* { String s = lcListFile.get(i); if (s.length() > 1)
|
||||||
|
* Constant.Color.LandColor[0].map.add(s); } }
|
||||||
|
* Constant.Keywords.loaded[0] = true; if (Constant.Runtime.DevMode[0])
|
||||||
|
* { System.out.println(Constant.Keywords.NonStackingList[0].list); } }
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,49 +267,32 @@ public class FModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return boolean */
|
||||||
* Getter for buildInfo.
|
public final boolean isHTTP() {
|
||||||
*
|
return http;
|
||||||
* @return the buildInfo
|
}
|
||||||
*/
|
|
||||||
|
/** @return {@link forge.model.BuildInfo} */
|
||||||
public final BuildInfo getBuildInfo() {
|
public final BuildInfo getBuildInfo() {
|
||||||
return this.buildInfo;
|
return this.buildInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @param bi0   {@link forge.model.BuildInfo} */
|
||||||
* Setter for buildInfo.
|
protected final void setBuildInfo(final BuildInfo bi0) {
|
||||||
*
|
this.buildInfo = bi0;
|
||||||
* @param neoBuildInfo
|
|
||||||
* the buildInfo to set
|
|
||||||
*/
|
|
||||||
protected final void setBuildInfo(final BuildInfo neoBuildInfo) {
|
|
||||||
this.buildInfo = neoBuildInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return {@link forge.properties.ForgePreferences} */
|
||||||
* Gets the preferences.
|
|
||||||
*
|
|
||||||
* @return the preferences
|
|
||||||
*/
|
|
||||||
public final ForgePreferences getPreferences() {
|
public final ForgePreferences getPreferences() {
|
||||||
return this.preferences;
|
return this.preferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @param fp0 {@link forge.properties.ForgePreferences} */
|
||||||
* Sets the preferences.
|
public final void setPreferences(final ForgePreferences fp0) {
|
||||||
*
|
this.preferences = fp0;
|
||||||
* @param neoPreferences
|
|
||||||
* the preferences to set
|
|
||||||
*/
|
|
||||||
public final void setPreferences(final ForgePreferences neoPreferences) {
|
|
||||||
this.preferences = neoPreferences;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return {@link forge.model.FGameState} */
|
||||||
* Getter for gameState.
|
|
||||||
*
|
|
||||||
* @return the game state
|
|
||||||
*/
|
|
||||||
public final FGameState getGameState() {
|
public final FGameState getGameState() {
|
||||||
return this.gameState;
|
return this.gameState;
|
||||||
}
|
}
|
||||||
@@ -193,7 +300,7 @@ public class FModel {
|
|||||||
/**
|
/**
|
||||||
* Create and return a new game state.
|
* Create and return a new game state.
|
||||||
*
|
*
|
||||||
* @return a fresh game state
|
* @return a fresh {@link forge.model.FGameState}
|
||||||
*/
|
*/
|
||||||
public final FGameState resetGameState() {
|
public final FGameState resetGameState() {
|
||||||
this.gameState = new FGameState();
|
this.gameState = new FGameState();
|
||||||
|
|||||||
@@ -17,11 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package forge.view;
|
package forge.view;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import forge.Constant;
|
|
||||||
import forge.ConstantStringArrayList;
|
|
||||||
import forge.FileUtil;
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.error.ErrorViewer;
|
import forge.error.ErrorViewer;
|
||||||
import forge.error.ExceptionHandler;
|
import forge.error.ExceptionHandler;
|
||||||
@@ -41,7 +36,7 @@ public final class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main method for Forge's swing application view.
|
* Main method for Forge.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args
|
||||||
* an array of {@link java.lang.String} objects.
|
* an array of {@link java.lang.String} objects.
|
||||||
@@ -56,135 +51,13 @@ public final class Main {
|
|||||||
Singletons.setModel(model);
|
Singletons.setModel(model);
|
||||||
Singletons.setView(view);
|
Singletons.setView(view);
|
||||||
|
|
||||||
// Need this soon after card factory is loaded
|
// Instantiate FGameState for TriggerHandler on card objects created in preloader.
|
||||||
Main.loadDynamicGamedata();
|
|
||||||
|
|
||||||
// TODO this code should go elsewhere, like wherever we start a new
|
|
||||||
// game.
|
|
||||||
// It is only here to maintain semantic equality with the current
|
|
||||||
// code base.
|
|
||||||
model.resetGameState();
|
model.resetGameState();
|
||||||
|
|
||||||
|
// Start splash frame.
|
||||||
view.initialize();
|
view.initialize();
|
||||||
} catch (final Throwable exn) {
|
} catch (final Throwable exn) {
|
||||||
ErrorViewer.showError(exn);
|
ErrorViewer.showError(exn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load dynamic gamedata.
|
|
||||||
*/
|
|
||||||
public static void loadDynamicGamedata() {
|
|
||||||
if (!Constant.CardTypes.LOADED[0]) {
|
|
||||||
final ArrayList<String> typeListFile = FileUtil.readFile("res/gamedata/TypeLists.txt");
|
|
||||||
|
|
||||||
ArrayList<String> tList = null;
|
|
||||||
|
|
||||||
Constant.CardTypes.CARD_TYPES[0] = new ConstantStringArrayList();
|
|
||||||
Constant.CardTypes.SUPER_TYPES[0] = new ConstantStringArrayList();
|
|
||||||
Constant.CardTypes.BASIC_TYPES[0] = new ConstantStringArrayList();
|
|
||||||
Constant.CardTypes.LAND_TYPES[0] = new ConstantStringArrayList();
|
|
||||||
Constant.CardTypes.CREATURE_TYPES[0] = new ConstantStringArrayList();
|
|
||||||
Constant.CardTypes.INSTANT_TYPES[0] = new ConstantStringArrayList();
|
|
||||||
Constant.CardTypes.SORCERY_TYPES[0] = new ConstantStringArrayList();
|
|
||||||
Constant.CardTypes.ENCHANTMENT_TYPES[0] = new ConstantStringArrayList();
|
|
||||||
Constant.CardTypes.ARTIFACT_TYPES[0] = new ConstantStringArrayList();
|
|
||||||
Constant.CardTypes.WALKER_TYPES[0] = new ConstantStringArrayList();
|
|
||||||
|
|
||||||
if (typeListFile.size() > 0) {
|
|
||||||
for (int i = 0; i < typeListFile.size(); i++) {
|
|
||||||
final String s = typeListFile.get(i);
|
|
||||||
|
|
||||||
if (s.equals("[CardTypes]")) {
|
|
||||||
tList = Constant.CardTypes.CARD_TYPES[0].getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (s.equals("[SuperTypes]")) {
|
|
||||||
tList = Constant.CardTypes.SUPER_TYPES[0].getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (s.equals("[BasicTypes]")) {
|
|
||||||
tList = Constant.CardTypes.BASIC_TYPES[0].getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (s.equals("[LandTypes]")) {
|
|
||||||
tList = Constant.CardTypes.LAND_TYPES[0].getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (s.equals("[CreatureTypes]")) {
|
|
||||||
tList = Constant.CardTypes.CREATURE_TYPES[0].getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (s.equals("[InstantTypes]")) {
|
|
||||||
tList = Constant.CardTypes.INSTANT_TYPES[0].getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (s.equals("[SorceryTypes]")) {
|
|
||||||
tList = Constant.CardTypes.SORCERY_TYPES[0].getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (s.equals("[EnchantmentTypes]")) {
|
|
||||||
tList = Constant.CardTypes.ENCHANTMENT_TYPES[0].getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (s.equals("[ArtifactTypes]")) {
|
|
||||||
tList = Constant.CardTypes.ARTIFACT_TYPES[0].getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (s.equals("[WalkerTypes]")) {
|
|
||||||
tList = Constant.CardTypes.WALKER_TYPES[0].getList();
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (s.length() > 1) {
|
|
||||||
tList.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Constant.CardTypes.LOADED[0] = true;
|
|
||||||
/*
|
|
||||||
* if (Constant.Runtime.DevMode[0]) {
|
|
||||||
* System.out.println(Constant.CardTypes.cardTypes[0].list);
|
|
||||||
* System.out.println(Constant.CardTypes.superTypes[0].list);
|
|
||||||
* System.out.println(Constant.CardTypes.basicTypes[0].list);
|
|
||||||
* System.out.println(Constant.CardTypes.landTypes[0].list);
|
|
||||||
* System.out.println(Constant.CardTypes.creatureTypes[0].list);
|
|
||||||
* System.out.println(Constant.CardTypes.instantTypes[0].list);
|
|
||||||
* System.out.println(Constant.CardTypes.sorceryTypes[0].list);
|
|
||||||
* System.out.println(Constant.CardTypes.enchantmentTypes[0].list);
|
|
||||||
* System.out.println(Constant.CardTypes.artifactTypes[0].list);
|
|
||||||
* System.out.println(Constant.CardTypes.walkerTypes[0].list); }
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Constant.Keywords.LOADED[0]) {
|
|
||||||
final ArrayList<String> nskwListFile = FileUtil.readFile("res/gamedata/NonStackingKWList.txt");
|
|
||||||
|
|
||||||
Constant.Keywords.NON_STACKING_LIST[0] = new ConstantStringArrayList();
|
|
||||||
|
|
||||||
if (nskwListFile.size() > 1) {
|
|
||||||
for (int i = 0; i < nskwListFile.size(); i++) {
|
|
||||||
final String s = nskwListFile.get(i);
|
|
||||||
if (s.length() > 1) {
|
|
||||||
Constant.Keywords.NON_STACKING_LIST[0].getList().add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Constant.Keywords.LOADED[0] = true;
|
|
||||||
/*
|
|
||||||
* if (Constant.Runtime.DevMode[0]) {
|
|
||||||
* System.out.println(Constant.Keywords.NonStackingList[0].list); }
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if (!Constant.Color.loaded[0]) { ArrayList<String> lcListFile =
|
|
||||||
* FileUtil.readFile("res/gamedata/LandColorList");
|
|
||||||
*
|
|
||||||
* if (lcListFile.size() > 1) { for (int i=0; i<lcListFile.size(); i++)
|
|
||||||
* { String s = lcListFile.get(i); if (s.length() > 1)
|
|
||||||
* Constant.Color.LandColor[0].map.add(s); } }
|
|
||||||
* Constant.Keywords.loaded[0] = true; if (Constant.Runtime.DevMode[0])
|
|
||||||
* { System.out.println(Constant.Keywords.NonStackingList[0].list); } }
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ import forge.CardList;
|
|||||||
import forge.card.cardfactory.CardFactoryInterface;
|
import forge.card.cardfactory.CardFactoryInterface;
|
||||||
import forge.card.cardfactory.LazyCardFactory;
|
import forge.card.cardfactory.LazyCardFactory;
|
||||||
import forge.card.cardfactory.PreloadingCardFactory;
|
import forge.card.cardfactory.PreloadingCardFactory;
|
||||||
|
import forge.model.FModel;
|
||||||
import forge.properties.ForgeProps;
|
import forge.properties.ForgeProps;
|
||||||
import forge.properties.NewConstants;
|
import forge.properties.NewConstants;
|
||||||
import forge.view.Main;
|
|
||||||
|
|
||||||
//import net.slightlymagic.braids.testng.BraidsAssertFunctions;
|
//import net.slightlymagic.braids.testng.BraidsAssertFunctions;
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ public class CardFactoryTest {
|
|||||||
*/
|
*/
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public final void setUp() {
|
public final void setUp() {
|
||||||
Main.loadDynamicGamedata();
|
FModel.loadDynamicGamedata();
|
||||||
this.factory = new LazyCardFactory(ForgeProps.getFile(NewConstants.CARDSFOLDER));
|
this.factory = new LazyCardFactory(ForgeProps.getFile(NewConstants.CARDSFOLDER));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user