Lonely preference settings moved out of FModel into loadPreferences with the rest of the preference settings.

This commit is contained in:
Doublestrike
2012-01-22 08:56:32 +00:00
parent 4ef4bdcaf7
commit 2fa2f27899
6 changed files with 23 additions and 43 deletions

View File

@@ -67,19 +67,19 @@ public class ControlTabber extends MyObservable {
this.view.getLblMilling().setEnabled(false); this.view.getLblMilling().setEnabled(false);
} }
if (Singletons.getModel().getPreferences().getHandView()) { if (Singletons.getModel().getPreferences().isHandView()) {
this.view.getLblHandView().setEnabled(true); this.view.getLblHandView().setEnabled(true);
} else { } else {
this.view.getLblHandView().setEnabled(false); this.view.getLblHandView().setEnabled(false);
} }
if (Singletons.getModel().getPreferences().getLibraryView()) { if (Singletons.getModel().getPreferences().isLibraryView()) {
this.view.getLblLibraryView().setEnabled(true); this.view.getLblLibraryView().setEnabled(true);
} else { } else {
this.view.getLblLibraryView().setEnabled(false); this.view.getLblLibraryView().setEnabled(false);
} }
if (Singletons.getModel().getPreferences().getUnlimitedLand()) { if (Singletons.getModel().getPreferences().isUnlimitedLand()) {
this.view.getLblUnlimitedLands().setEnabled(true); this.view.getLblUnlimitedLands().setEnabled(true);
} else { } else {
this.view.getLblUnlimitedLands().setEnabled(false); this.view.getLblUnlimitedLands().setEnabled(false);

View File

@@ -25,7 +25,6 @@ import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.ArrayList; import java.util.ArrayList;
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
import arcane.util.MultiplexOutputStream; import arcane.util.MultiplexOutputStream;
import forge.AllZone; import forge.AllZone;
import forge.ComputerAIGeneral; import forge.ComputerAIGeneral;
@@ -60,19 +59,14 @@ 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.
* *
* @param theMonitor
* a progress monitor (from the View) that shows the progress of
* the model's initialization.
*
* @throws FileNotFoundException * @throws FileNotFoundException
* if we could not find or write to the log file. * if we could not find or write to the log file.
*/ */
public FModel(final BraidsProgressMonitor theMonitor) throws FileNotFoundException { public FModel() throws FileNotFoundException {
// Fire up log file // Fire up log file
final File logFile = new File("forge.log"); final File logFile = new File("forge.log");
final boolean deleteSucceeded = logFile.delete(); final boolean deleteSucceeded = logFile.delete();
@@ -92,7 +86,6 @@ public class FModel {
try { try {
this.setPreferences(new ForgePreferences("forge.preferences")); this.setPreferences(new ForgePreferences("forge.preferences"));
} catch (final Exception exn) { } catch (final Exception exn) {
// Log.error("Error loading preferences: " + exn); // Log.error("Error loading preferences: " + exn);
throw new RuntimeException(exn); throw new RuntimeException(exn);
} }
@@ -101,25 +94,11 @@ public class FModel {
AllZone.setInputControl(new InputControl(FModel.this)); AllZone.setInputControl(new InputControl(FModel.this));
AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral())); AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral()));
// TODO these should be set along with others all at the same time, not
// here
Constant.Runtime.MILL[0] = this.preferences.isMillingLossCondition();
Constant.Runtime.DEV_MODE[0] = this.preferences.isDeveloperMode();
Constant.Runtime.UPLOAD_DRAFT[0] = this.preferences.isUploadDraftAI();
Constant.Runtime.RANDOM_FOIL[0] = this.preferences.isRandCFoil();
// ///////
// Instantiate pinger // Set gameplay preferences and constants
// TODO is this in the right place?
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")) { Constant.Runtime.NET_CONN[0] = (pinger.getURL(url).equals("pong") ? true : false);
http = true;
Constant.Runtime.NET_CONN[0] = true;
} else {
http = false;
Constant.Runtime.UPLOAD_DRAFT[0] = false;
}
this.setBuildInfo(new BuildInfo()); this.setBuildInfo(new BuildInfo());
FModel.loadDynamicGamedata(); FModel.loadDynamicGamedata();
@@ -268,11 +247,6 @@ public class FModel {
} }
} }
/** @return boolean */
public final boolean isHTTP() {
return http;
}
/** @return {@link forge.model.BuildInfo} */ /** @return {@link forge.model.BuildInfo} */
public final BuildInfo getBuildInfo() { public final BuildInfo getBuildInfo() {
return this.buildInfo; return this.buildInfo;

View File

@@ -300,7 +300,7 @@ public class ForgePreferences {
} }
/** @return boolean */ /** @return boolean */
public boolean getHandView() { public boolean isHandView() {
return Boolean.parseBoolean(prefs.get("dev.hand.view")); return Boolean.parseBoolean(prefs.get("dev.hand.view"));
} }
@@ -310,7 +310,7 @@ public class ForgePreferences {
} }
/** @return boolean */ /** @return boolean */
public boolean getLibraryView() { public boolean isLibraryView() {
return Boolean.parseBoolean(prefs.get("dev.library.view")); return Boolean.parseBoolean(prefs.get("dev.library.view"));
} }
@@ -320,7 +320,7 @@ public class ForgePreferences {
} }
/** @return boolean */ /** @return boolean */
public boolean getUnlimitedLand() { public boolean isUnlimitedLand() {
return Boolean.parseBoolean(prefs.get("dev.unlimited.land")); return Boolean.parseBoolean(prefs.get("dev.unlimited.land"));
} }

View File

@@ -317,6 +317,14 @@ public class GuiTopLevel extends JFrame implements Display, CardContainer {
final ForgePreferences fp = Singletons.getModel().getPreferences(); final ForgePreferences fp = Singletons.getModel().getPreferences();
final List<ViewField> fieldViews = this.control.getMatchController().getView().getFieldViews(); final List<ViewField> fieldViews = this.control.getMatchController().getView().getFieldViews();
Constant.Runtime.MILL[0] = fp.isMillingLossCondition();
Constant.Runtime.DEV_MODE[0] = fp.isDeveloperMode();
Constant.Runtime.UPLOAD_DRAFT[0] = fp.isUploadDraftAI();
Constant.Runtime.RANDOM_FOIL[0] = fp.isRandCFoil();
Constant.Runtime.HANDVIEW[0] = fp.isHandView();
Constant.Runtime.LIBRARYVIEW[0] = fp.isLibraryView();
Constant.Runtime.UPLOAD_DRAFT[0] = (Constant.Runtime.NET_CONN[0] ? fp.isUploadDraftAI() : false);
// AI field is at index [0] // AI field is at index [0]
fieldViews.get(0).getLblUpkeep().setEnabled(fp.isShowPhase("phase.ai.upkeep")); fieldViews.get(0).getLblUpkeep().setEnabled(fp.isShowPhase("phase.ai.upkeep"));
fieldViews.get(0).getLblDraw().setEnabled(fp.isShowPhase("phase.ai.draw")); fieldViews.get(0).getLblDraw().setEnabled(fp.isShowPhase("phase.ai.draw"));
@@ -353,11 +361,9 @@ public class GuiTopLevel extends JFrame implements Display, CardContainer {
* <p> * <p>
* savePrefs. * savePrefs.
* </p> * </p>
* Required by Display interface. Due to be deprecated: will be handled by * Required by Display interface. Due to be deprecated: should be in FModel.
* ControlMatchUI. Also, this functionality is already performed elsewhere * Also, this functionality is already performed elsewhere
* in the code base. Furthermore, there's a strong possibility this will * in the code base.
* need bo be broken down and can't be in one place - e.g. keyboard
* shortcuts are saved after they're edited.
* *
* @return a boolean. * @return a boolean.
*/ */

View File

@@ -44,7 +44,7 @@ public final class Main {
public static void main(final String[] args) { public static void main(final String[] args) {
ExceptionHandler.registerErrorHandling(); ExceptionHandler.registerErrorHandling();
try { try {
final FModel model = new FModel(null); final FModel model = new FModel();
final FSkin skin = new FSkin(model.getPreferences().getSkin()); final FSkin skin = new FSkin(model.getPreferences().getSkin());
final FView view = new FView(skin); final FView view = new FView(skin);

View File

@@ -25,7 +25,7 @@ public class FModelTest {
*/ */
@BeforeTest @BeforeTest
public final void setUp() throws FileNotFoundException { public final void setUp() throws FileNotFoundException {
this.model = new FModel(null); this.model = new FModel();
} }
/** /**
@@ -63,7 +63,7 @@ public class FModelTest {
System.err.println("log test"); System.err.println("log test");
this.model = new FModel(null); this.model = new FModel();
Assert.assertNotNull(this.model, "model is not null"); Assert.assertNotNull(this.model, "model is not null");
} }