From: Dr. M. B. <neu...@us...> - 2012-04-12 07:30:50
|
LocalisedText.properties | 10 buildRails.xml | 8 data/1830/Game.xml | 4 data/1830/Map.xml | 8 data/1830/TileSet.xml | 1 data/1830/Tiles.xml | 5 data/1835/Game.xml | 3 data/1856/Map.xml | 2 data/1856/TileSet.xml | 1 data/1856/Tiles.xml | 6 data/18AL/Game.xml | 1 data/18EU/Map.xml | 2 data/18EU/TileSet.xml | 1 data/18EU/Tiles.xml | 6 data/18Kaas/Game.xml | 6 data/18TN/Game.xml | 1 data/Properties.xml | 1 data/profiles/LIST_OF_PROFILES | 1 data/profiles/ORDocking.predefined | 2 data/profiles/hotseat.predefined | 4 data/profiles/pbem.predefined | 6 data/profiles/prettyUI.predefined | 2 data/profiles/root | 3 rails/common/ConfigManager.java | 13 rails/common/ConfigProfile.java | 152 + rails/game/GameManager.java | 52 rails/game/GameManagerI.java | 4 rails/game/PublicCompany.java | 12 rails/game/TrainManager.java | 2 rails/game/specific/_1835/ElsasModifier.java | 46 rails/game/specific/_18EU/StockRound_18EU.java | 8 rails/ui/swing/ConfigWindow.java | 131 - rails/ui/swing/GameSetupWindow.java | 17 rails/ui/swing/GameStatus.java | 74 rails/ui/swing/GameUIManager.java | 72 rails/ui/swing/GridPanel.java | 33 rails/ui/swing/ORUIManager.java | 9 rails/ui/swing/StartRoundWindow.java | 97 rails/ui/swing/StatusWindow.java | 8 rails/ui/swing/WindowSettings.java | 5 rails/ui/swing/elements/DockingFrame.java | 13 rails/ui/swing/elements/RailsIcon.java | 1 rails/util/GameFileIO.java | 5 readme.txt | 78 test/data/bugs/18EU_layhomeHex.rails |binary test/data/bugs/18EU_layhomeHex.report | 1592 +++++++++++++++ test/data/test/1835_PRHasTwoExcessTrains.report | 2283 +++++++++++----------- test/data/test/1835_PR_3rdTrain.report | 2207 ++++++++++----------- test/data/test/1835_SwapPresForDoubleShare.report | 700 +++--- version.number | 4 50 files changed, 4817 insertions(+), 2885 deletions(-) New commits: commit fc60c8de9d6c6a30611152b8d0cad63133f6f776 Merge: 84ccccb 82d4e5c Author: Martin <dr....@t-...> Date: Thu Apr 12 09:30:00 2012 +0200 Merge remote branch 'origin/rails1.7.x' into specific_1880 Conflicts: rails/common/ConfigProfile.java rails/game/TrainManager.java readme.txt test/data/test/1835_PRHasTwoExcessTrains.report test/data/test/1835_PR_3rdTrain.report version.number diff --cc buildRails.xml index aca719d,3af31a6..d626a97 --- a/buildRails.xml +++ b/buildRails.xml @@@ -166,7 -164,7 +166,7 @@@ </exec> <exec executable="scp" dir="./" failonerror="true"> <arg value="readme.txt"/> - <arg value="${sf.user},rails@${sf.uri}${sf.filedir}${version}/"/> + <arg value="${sf.user}@${sf.uri}${sf.filedir}${version}/"/> </exec> </target> --</project> ++</project> diff --cc rails/common/ConfigProfile.java index ca418d3,2fb7762..ecc8bb7 --- a/rails/common/ConfigProfile.java +++ b/rails/common/ConfigProfile.java @@@ -2,7 -2,12 +2,16 @@@ package rails.common import java.io.File; import java.io.FilenameFilter; ++<<<<<<< HEAD +import java.util.*; ++======= + import java.util.ArrayList; + import java.util.Collection; + import java.util.HashMap; + import java.util.List; + import java.util.Map; + import java.util.Properties; ++>>>>>>> refs/remotes/origin/rails1.7.x import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOCase; @@@ -103,26 -108,33 +112,34 @@@ public final class ConfigProfile implem 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); - } ++ + ConfigProfile profile = getProfile(System.getProperty(CLI_AND_RECENT_OPTION)); + if (profile != null) { + return profile; + } // second check recent - profile = Config.getRecent(CLI_AND_RECENT_OPTION); - if (Util.hasValue(profile) && profiles.containsKey(profile)) { - return profiles.get(profile); - } + profile = getProfile(Config.getRecent(CLI_AND_RECENT_OPTION)); + if (profile != null) { + return profile; + } // third return standard profile - return profiles.get(STANDARD_PROFILE); + profile = getProfile(STANDARD_PROFILE); + if (profile != null) { + return profile; + } + // last return root + return root; } - + static ConfigProfile getProfile(String name) { + if (name == null) return null; + if (name.equals(ROOT_PROFILE)) return root; return profiles.get(name); } - + static Collection<ConfigProfile> getProfiles() { return profiles.values(); } @@@ -146,54 -158,53 +163,53 @@@ boolean isLoaded() { return loaded; } - + boolean isFinal() { - if (!loaded && type == Type.USER) return true; - + ensureLoad(); + if (Util.hasValue(properties.getProperty(FINAL_KEY))) { return Util.parseBoolean(properties.getProperty(FINAL_KEY)); } return false; } - + ConfigProfile setParent(ConfigProfile parent) { - if (parent != null) { - this.parent = parent; - properties.setProperty(PARENT_KEY, parent.getName()); - } + ensureLoad(); + this.parent = parent; + properties.setProperty(PARENT_KEY, parent.getName()); return this; } - + private ConfigProfile setParent(String name) { - return setParent(profiles.get(name)); + return setParent(getProfile(name)); } ConfigProfile getParent() { + ensureLoad(); return parent; } - + String getProperty(String key) { - if (this == root || properties.containsKey(key)) { + ensureLoad(); + if (this == parent || properties.containsKey(key)) { return properties.getProperty(key); } else { return parent.getProperty(key); } } - + void setProperty(String key, String value) { - if (!parent.getProperty(key).equals(value)) { - properties.setProperty(key, value); - } else { + ensureLoad(); + if (parent.getProperty(key) != null && parent.getProperty(key).equals(value)) { properties.remove(key); + } else { + properties.setProperty(key, value); } } - - + + void makeActive(){ - // check if is already loaded - if (!isLoaded()) { - load(); - } + ensureLoad(); // and store it to recent Config.storeRecent(CLI_AND_RECENT_OPTION, getName()); } @@@ -221,6 -236,12 +241,12 @@@ return newProfile; } + private void ensureLoad() { + if (loaded == false) { + load(); + } + } - ++ boolean load() { // loaded is set independent of success loaded = true; @@@ -280,17 -302,77 +307,79 @@@ } return Util.loadPropertiesFromResource(properties, filePath); } + - boolean store() { - if (type != Type.USER) return false; - loaded = true; + + private File getFile() { ++ File folder = SystemOS.get().getConfigurationFolder(PROFILE_FOLDER, true); if (folder == null) { + return null; + } else { + return new File(folder, name + PROFILE_EXTENSION); + } + } + + /** + * stores profile + * @return true if save was successful + */ + boolean store() { + if (type != Type.USER) return false; + + File file = getFile(); + if (file != null) { + return Util.storeProperties(properties, file); + } else { return false; + } + } + + private List<ConfigProfile> getChildren() { + List<ConfigProfile> children = new ArrayList<ConfigProfile>(); + for (ConfigProfile profile:profiles.values()) { + if (profile.getParent() == this) { + children.add(profile); + } + } + return children; + } + + /** + * delete profile (including deleting the saved file and removing from the map of profiles) + * @return true if deletion was successful + */ + boolean delete() { + // cannot delete parents + if (type != Type.USER) return false; + + // delete profile file + boolean result; + File file = getFile(); + if (file != null) { + if (file.delete()) { + profiles.remove(this.name); + result = true; + } else { + result = false; + } } else { - File profile = new File(folder, name + PROFILE_EXTENSION); - return Util.storeProperties(properties, profile); + result = false; + } + + + if (result) { + // and reassign and save children + for (ConfigProfile child:getChildren()) { + child.setParent(parent); + // and transfer (directly stored) properties + for (Object key:properties.keySet()) { + child.setProperty((String)key, (String)properties.get(key)); + } + child.store(); + } } + return result; + } private int compare(ConfigProfile a, ConfigProfile b) { diff --cc rails/game/TrainManager.java index cfa95f8,b99b128..454f6e9 --- a/rails/game/TrainManager.java +++ b/rails/game/TrainManager.java @@@ -1,1 -1,1 +1,1 @@@ - /* $Header: /Users/blentz/rails_rcs/cvs/18xx/rails/game/TrainManager.java,v 1.28 2010/04/21 21:25:50 evos Exp $ */ package rails.game; import java.util.*; import org.apache.log4j.Logger; import rails.common.LocalText; import rails.common.parser.ConfigurableComponentI; import rails.common.parser.ConfigurationException; import rails.common.parser.Tag; import rails.game.move.ObjectMove; import rails.game.state.BooleanState; import rails.game.state.IntegerState; public class TrainManager implements ConfigurableComponentI { // Static attributes protected List<TrainType> lTrainTypes = new ArrayList<TrainType>(); protected Map<String, TrainType> mTrainTypes = new HashMap<String, TrainType>(); protected List<TrainCertificateType> trainCertTypes = new ArrayList<TrainCertificateType>(); protected Map<String, TrainCertificateType> trainCertTypeMap = new HashMap<String, TrainCertificateType>(); protected Map<String, TrainI> trainMap = new HashMap<String, TrainI>(); protected Map<TrainCertificateType, List<TrainI>> trainsPerCertType = new HashMap<TrainCertificateType, List<TrainI>>(); protected TrainType defaultType = null; // Only required locally and in ChoiceType private boolean removeTrain = false; // Dynamic attributes protected IntegerState newTypeIndex; protected Map<String, Integer> lastIndexPerType = new HashMap<String, Integer>(); protected boolean trainsHaveRusted = false; protected boolean phaseHasChanged = false; protected boolean trainAvailabilityChanged = false; protected List<PublicCompanyI> companiesWithExcessTrains; protected GameManagerI gameManager = null; protected Bank bank = null; /** Required for the sell-train-to-foreigners feature of some games */ protected BooleanState anyTrainBought = new BooleanState ("AnyTrainBought", false); // Triggered phase changes protected Map<TrainCertificateType, Map<Integer, |