|
From: Brett L. <wak...@us...> - 2011-07-21 17:01:49
|
rails/common/parser/Tag.java | 3 ---
1 file changed, 3 deletions(-)
New commits:
commit 6b7255acdcdfd3217884ae2701975166df7350b8
Author: Brett Lentz <bl...@cl...>
Date: Thu Jul 21 09:58:42 2011 -0700
Tag: simplify conditional logic.
This is really a spurious commit to test Egit.
diff --git a/rails/common/parser/Tag.java b/rails/common/parser/Tag.java
index 22c3c0a..7a7d46e 100644
--- a/rails/common/parser/Tag.java
+++ b/rails/common/parser/Tag.java
@@ -326,9 +326,6 @@ public class Tag {
break;
}
}
- }
-
- if (optionValue == null) {
// Take the default value
GameOption go = GameOption.getByName(name);
optionValue = go != null ? go.getDefaultValue() : "";
|
|
From: Brett L. <wak...@us...> - 2011-07-21 17:34:15
|
rails/common/parser/Tag.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit a7948aad7f7b2010df2988b1076919342d6cb2d8
Author: Brett Lentz <bre...@gm...>
Date: Thu Jul 21 10:29:22 2011 -0700
Tag: ignore null gameOptions.
diff --git a/rails/common/parser/Tag.java b/rails/common/parser/Tag.java
index 7a7d46e..a1aa913 100644
--- a/rails/common/parser/Tag.java
+++ b/rails/common/parser/Tag.java
@@ -320,7 +320,7 @@ public class Tag {
// For backwards compatibility: search for an extended name
if (optionValue == null) {
for (String optName : gameOptions.keySet()) {
- if (optName.startsWith(name)) {
+ if (optName != null && optName.startsWith(name)) {
optionValue = gameOptions.get(optName);
log.warn("Option name "+name+" replaced by "+optName);
break;
|
|
From: Erik V. <ev...@us...> - 2011-07-22 18:35:25
|
rails/common/parser/Tag.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
New commits:
commit 91ed37d10a7c65408b8a23007a0601e6491bb51d
Author: Erik Vos <eri...@xs...>
Date: Fri Jul 22 20:34:29 2011 +0200
Reverted Tag change, added some comments
diff --git a/rails/common/parser/Tag.java b/rails/common/parser/Tag.java
index a1aa913..ed1c334 100644
--- a/rails/common/parser/Tag.java
+++ b/rails/common/parser/Tag.java
@@ -318,6 +318,7 @@ public class Tag {
String optionValue = gameOptions.get(name);
// For backwards compatibility: search for an extended name
+ // TODO OBSOLETE??
if (optionValue == null) {
for (String optName : gameOptions.keySet()) {
if (optName != null && optName.startsWith(name)) {
@@ -326,7 +327,10 @@ public class Tag {
break;
}
}
- // Take the default value
+ }
+
+ // If not assigned in the previous step, take the default value
+ if (optionValue == null) {
GameOption go = GameOption.getByName(name);
optionValue = go != null ? go.getDefaultValue() : "";
log.warn("GameOption " + name + "=" + value
|
|
From: Erik V. <ev...@us...> - 2011-07-22 18:59:57
|
rails/common/parser/Tag.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
New commits:
commit 505fb03f5041aa14be1d8e772d3b02aff870f2d5
Author: Erik Vos <eri...@xs...>
Date: Fri Jul 22 20:59:27 2011 +0200
Added comments to explain option name shortening code.
diff --git a/rails/common/parser/Tag.java b/rails/common/parser/Tag.java
index ed1c334..712e5b6 100644
--- a/rails/common/parser/Tag.java
+++ b/rails/common/parser/Tag.java
@@ -318,9 +318,15 @@ public class Tag {
String optionValue = gameOptions.get(name);
// For backwards compatibility: search for an extended name
- // TODO OBSOLETE??
+ /* This applies to parametrized options, such as "UnlimitedTopTrains".
+ * It parametrized with a parameter "D" to allow display as "Unlimited D-trains"
+ * and still remaining generic.
+ * Parametrization means that the actual name is UnlimitedTopTrains_D,
+ * for instance in saved files, and so the name must be shortened to find a match.
+ */
if (optionValue == null) {
for (String optName : gameOptions.keySet()) {
+ // startsWith is a shortcut, perhaps it should be matches(name+"_.*").
if (optName != null && optName.startsWith(name)) {
optionValue = gameOptions.get(optName);
log.warn("Option name "+name+" replaced by "+optName);
|
|
From: Stefan F. <ste...@us...> - 2011-08-25 19:55:41
|
rails/common/parser/GameOption.java | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
New commits:
commit 8f7435c4885f0976d4cad7504a5915848a4cf56a
Author: Stefan Frey <ste...@we...>
Date: Thu Aug 25 21:58:00 2011 +0200
Removed Bill Rosgen fix for GameOption. Was unnecessary due to fix of
Adam Badura.
diff --git a/rails/common/parser/GameOption.java b/rails/common/parser/GameOption.java
index aa893df..395203c 100644
--- a/rails/common/parser/GameOption.java
+++ b/rails/common/parser/GameOption.java
@@ -60,10 +60,7 @@ public class GameOption {
}
public String getName() {
- if (parametrisedName != null)
- return parametrisedName;
-
- return name;
+ return parametrisedName;
}
public String getLocalisedName() {
|
|
From: Stefan F. <ste...@us...> - 2012-02-27 09:45:46
|
rails/common/ConfigProfile.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
New commits:
commit 2b479e4cb646082b36e1936071a88eadf5d1f701
Author: Stefan Frey <ste...@we...>
Date: Mon Feb 27 10:45:30 2012 +0100
fix that makes all user profiles final
diff --git a/rails/common/ConfigProfile.java b/rails/common/ConfigProfile.java
index 3ad6f20..2651ce2 100644
--- a/rails/common/ConfigProfile.java
+++ b/rails/common/ConfigProfile.java
@@ -134,7 +134,8 @@ public final class ConfigProfile {
}
boolean isFinal() {
- if (!loaded) return true;
+ if (!loaded && type == Type.USER) return true;
+
if (Util.hasValue(properties.getProperty(FINAL_KEY))) {
return Util.parseBoolean(properties.getProperty(FINAL_KEY));
}
|
|
From: Stefan F. <ste...@us...> - 2012-02-27 10:00:32
|
rails/common/Config.java | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
New commits:
commit 954bbd4b1d2f4c90fe4105fb68dfe743df83c260
Author: Stefan Frey <ste...@we...>
Date: Mon Feb 27 11:00:03 2012 +0100
another fix: forgot to commit config
diff --git a/rails/common/Config.java b/rails/common/Config.java
new file mode 100644
index 0000000..bce5142
--- /dev/null
+++ b/rails/common/Config.java
@@ -0,0 +1,47 @@
+package rails.common;
+
+import rails.game.GameManager;
+import rails.util.Util;
+
+/**
+ * Proxy class to the ConfigManager
+ */
+
+public class Config {
+
+ /**
+ * Configuration option (default value is empty string)
+ */
+ public static String get(String key) {
+ return ConfigManager.getInstance().getValue(key, "");
+ }
+
+ /**
+ * Configuration option with default value
+ */
+ public static String get(String key, String defaultValue) {
+ return ConfigManager.getInstance().getValue(key, defaultValue);
+ }
+
+ /**
+ * Configuration option: First tries to return {key}.{appendix}, if undefined returns {key}
+ */
+ public static String getSpecific(String key, String appendix) {
+ String value = get(key + "." + appendix);
+ if (Util.hasValue(value)) {
+ return value;
+ } else {
+ return get(key);
+ }
+ }
+
+ /**
+ * Configuration option: First tries to return {key}.{gameName}, if undefined returns {key}
+ */
+ public static String getGameSpecific(String key) {
+ return getSpecific(key, GameManager.getInstance().getGameName());
+ }
+
+
+
+}
|
|
From: Stefan F. <ste...@us...> - 2012-02-29 22:39:01
|
rails/common/ConfigProfile.java | 9 +++++++++
1 file changed, 9 insertions(+)
New commits:
commit 8b7e4d8addfe0a24f021fe7ae13a910a44ebe783
Author: Stefan Frey <ste...@we...>
Date: Wed Feb 29 23:38:20 2012 +0100
added cli option for command line option
diff --git a/rails/common/ConfigProfile.java b/rails/common/ConfigProfile.java
index 2651ce2..dda3d13 100644
--- a/rails/common/ConfigProfile.java
+++ b/rails/common/ConfigProfile.java
@@ -41,7 +41,12 @@ public final class ConfigProfile {
// predefined default profiles
private static final String ROOT_PROFILE = "root";
private static final String TEST_PROFILE = "test";
+
+ // the profile selected at the start ...
private static final String STANDARD_PROFILE = "pbem";
+ // ... unless a cli option has been set
+ private static final String STANDARD_CLI_OPTION ="profile";
+
// file that stores the list of predefined profiles
private static final String LIST_OF_PROFILES = "LIST_OF_PROFILES";
@@ -102,6 +107,10 @@ public final class ConfigProfile {
}
static ConfigProfile getDefault() {
+ String profile = System.getProperty(STANDARD_CLI_OPTION);
+ if (Util.hasValue(profile) && profiles.containsKey(profile)) {
+ return profiles.get(profile);
+ }
return profiles.get(STANDARD_PROFILE);
}
|
|
From: Erik V. <ev...@us...> - 2012-03-13 14:41:28
|
rails/common/ConfigProfile.java | 115 +++++++++++++++++++---------------------
1 file changed, 57 insertions(+), 58 deletions(-)
New commits:
commit 089e86da5284d15b956862b8de9ba9df3ba3b3b3
Author: Erik Vos <eri...@xs...>
Date: Tue Mar 13 15:40:04 2012 +0100
Fixed Config.profile.SetParent() so it no longer crashes if parent is null.
diff --git a/rails/common/ConfigProfile.java b/rails/common/ConfigProfile.java
index c6bcb7d..ca418d3 100644
--- a/rails/common/ConfigProfile.java
+++ b/rails/common/ConfigProfile.java
@@ -2,10 +2,7 @@ package rails.common;
import java.io.File;
import java.io.FilenameFilter;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOCase;
@@ -22,13 +19,13 @@ import rails.util.Util;
public final class ConfigProfile implements Comparable<ConfigProfile> {
protected static Logger log =
- Logger.getLogger(ConfigProfile.class.getPackage().getName());
-
+ Logger.getLogger(ConfigProfile.class.getPackage().getName());
+
// available profile types
public enum Type {SYSTEM(0), PREDEFINED(1), USER(2);
- private Integer sort; Type(int sort) {this.sort = sort;}
+ private Integer sort; Type(int sort) {this.sort = sort;}
};
-
+
// Filename extension of profiles
public static final String PROFILE_EXTENSION = ".rails_profile";
private static final String PREDEFINED_EXTENSION = ".predefined";
@@ -38,57 +35,57 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
private static final String PROFILE_FOLDER = "profiles/";
// predefined inside jar
private static final String PREDEFINED_FOLDER = "data/profiles/";
-
+
// predefined default profiles
private static final String ROOT_PROFILE = "root";
private static final String TEST_PROFILE = "test";
-
+
// the profile selected at the start ...
private static final String STANDARD_PROFILE = "pbem";
// ... unless a cli option has been set
private static final String CLI_AND_RECENT_OPTION ="profile";
-
-
+
+
// file that stores the list of predefined profiles
private static final String LIST_OF_PROFILES = "LIST_OF_PROFILES";
-
+
// property key of predefined profile in user profile
private static final String PARENT_KEY = "profile.parent";
private static final String FINAL_KEY = "profile.final";
// map of all profiles
- private static final Map<String, ConfigProfile> profiles = new HashMap<String, ConfigProfile>();
-
+ private static final Map<String, ConfigProfile> profiles = new HashMap<String, ConfigProfile>();
+
// root profile
private static ConfigProfile root;
-
+
// profile type
private final Type type;
-
+
// profile name
private final String name;
// profile properties
private final Properties properties = new Properties();
-
+
// profile loaded
private boolean loaded = false;
-
+
// profile parent
private ConfigProfile parent = null;
-
+
static void loadRoot() {
root = new ConfigProfile(Type.SYSTEM, ROOT_PROFILE);
root.load();
}
-
+
static ConfigProfile loadTest() {
ConfigProfile test = new ConfigProfile(Type.SYSTEM, TEST_PROFILE);
test.load();
return test;
}
-
+
static void readPredefined() {
Properties list = new Properties();
String filePath = PREDEFINED_FOLDER + LIST_OF_PROFILES;
@@ -97,7 +94,7 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
new ConfigProfile(Type.PREDEFINED, name);
}
}
-
+
static void readUser() {
File userFolder = SystemOS.get().getConfigurationFolder(PROFILE_FOLDER, false);
if (userFolder == null) return;
@@ -106,30 +103,30 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
new ConfigProfile(Type.USER, FilenameUtils.getBaseName(fileName));
}
}
-
+
static ConfigProfile getStartProfile() {
// first checks cli
String profile = System.getProperty(CLI_AND_RECENT_OPTION);
if (Util.hasValue(profile) && profiles.containsKey(profile)) {
return profiles.get(profile);
- }
+ }
// second check recent
profile = Config.getRecent(CLI_AND_RECENT_OPTION);
if (Util.hasValue(profile) && profiles.containsKey(profile)) {
return profiles.get(profile);
- }
+ }
// third return standard profile
return profiles.get(STANDARD_PROFILE);
}
-
+
static ConfigProfile getProfile(String name) {
return profiles.get(name);
}
-
+
static Collection<ConfigProfile> getProfiles() {
return profiles.values();
}
-
+
private ConfigProfile(Type type, String name) {
this.type = type;
this.name = name;
@@ -137,34 +134,36 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
profiles.put(name, this);
}
}
-
+
public Type getType() {
return type;
}
-
+
public String getName() {
return name;
}
-
+
boolean isLoaded() {
return loaded;
}
-
+
boolean isFinal() {
if (!loaded && type == Type.USER) return true;
-
+
if (Util.hasValue(properties.getProperty(FINAL_KEY))) {
return Util.parseBoolean(properties.getProperty(FINAL_KEY));
}
return false;
}
-
+
ConfigProfile setParent(ConfigProfile parent) {
- this.parent = parent;
- properties.setProperty(PARENT_KEY, parent.getName());
+ if (parent != null) {
+ this.parent = parent;
+ properties.setProperty(PARENT_KEY, parent.getName());
+ }
return this;
}
-
+
private ConfigProfile setParent(String name) {
return setParent(profiles.get(name));
}
@@ -172,7 +171,7 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
ConfigProfile getParent() {
return parent;
}
-
+
String getProperty(String key) {
if (this == root || properties.containsKey(key)) {
return properties.getProperty(key);
@@ -180,7 +179,7 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
return parent.getProperty(key);
}
}
-
+
void setProperty(String key, String value) {
if (!parent.getProperty(key).equals(value)) {
properties.setProperty(key, value);
@@ -188,8 +187,8 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
properties.remove(key);
}
}
-
-
+
+
void makeActive(){
// check if is already loaded
if (!isLoaded()) {
@@ -201,13 +200,13 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
ConfigProfile deriveUserProfile(String name) {
ConfigProfile newProfile = new ConfigProfile(Type.USER, name);
-
+
ConfigProfile reference;
if (isFinal()) {
// set reference for final to the own parent
reference = parent;
- } else {
- // otherwise to this
+ } else {
+ // otherwise to this
reference = this;
}
newProfile.setParent(reference);
@@ -218,16 +217,16 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
newProfile.setProperty(key, properties.getProperty(key));
}
}
-
+
return newProfile;
}
-
+
boolean load() {
// loaded is set independent of success
loaded = true;
// ... the same for clearing the current selection
properties.clear();
-
+
// loading
boolean result;
if (type == Type.USER) {
@@ -244,21 +243,21 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
if (parent == null) {
setParent(root);
}
-
- // set save directory to the working directory for predefined values
+
+ // set save directory to the working directory for predefined values
// TODO: This is a hack as workaround to be replaced in the future
if (type == Type.PREDEFINED && !Util.hasValue(properties.getProperty("save.directory"))) {
properties.put("save.directory", System.getProperty("user.dir"));
}
-
+
// check if parent has been loaded, otherwise load parent
if (!parent.isLoaded()) {
result = result && parent.load();
}
-
+
return result;
}
-
+
private boolean loadUser() {
File folder = SystemOS.get().getConfigurationFolder(PROFILE_FOLDER, false);
if (folder == null) {
@@ -266,9 +265,9 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
} else {
File profile = new File(folder, name + PROFILE_EXTENSION);
return Util.loadProperties(properties, profile);
- }
+ }
}
-
+
private boolean loadResource(){
String filePath = null;
switch(type) {
@@ -281,13 +280,13 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
}
return Util.loadPropertiesFromResource(properties, filePath);
}
-
+
boolean store() {
if (type != Type.USER) return false;
loaded = true;
File folder = SystemOS.get().getConfigurationFolder(PROFILE_FOLDER, true);
if (folder == null) {
- return false;
+ return false;
} else {
File profile = new File(folder, name + PROFILE_EXTENSION);
return Util.storeProperties(properties, profile);
@@ -295,7 +294,7 @@ public final class ConfigProfile implements Comparable<ConfigProfile> {
}
private int compare(ConfigProfile a, ConfigProfile b) {
- if (a.type.sort != b.type.sort) {
+ if (a.type.sort != b.type.sort) {
return a.type.sort.compareTo(b.type.sort);
} else {
return a.getName().compareTo(b.getName());
|