sort the contents of a properties file when saved.
parent
0141375baf
commit
293418923a
|
@ -8,6 +8,7 @@ import magic.model.MagicDuel;
|
|||
import magic.model.DuelPlayerConfig;
|
||||
import magic.model.player.PlayerProfile;
|
||||
import magic.model.player.PlayerProfiles;
|
||||
import magic.utility.SortedProperties;
|
||||
|
||||
public class DuelConfig {
|
||||
|
||||
|
@ -115,7 +116,7 @@ public class DuelConfig {
|
|||
|
||||
public void load() {
|
||||
final File configFile = MagicDuel.getLatestDuelFile();
|
||||
final Properties properties = configFile.exists() ? FileIO.toProp(configFile) : new Properties();
|
||||
final Properties properties = configFile.exists() ? FileIO.toProp(configFile) : new SortedProperties();
|
||||
load(properties, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import magic.ui.duel.animation.AnimationFx;
|
|||
import magic.ui.message.MessageStyle;
|
||||
import magic.ui.prefs.ImageSizePresets;
|
||||
import magic.utility.MagicFileSystem;
|
||||
import magic.utility.SortedProperties;
|
||||
|
||||
public class GeneralConfig {
|
||||
|
||||
|
@ -659,7 +660,7 @@ public class GeneralConfig {
|
|||
}
|
||||
|
||||
public void save() {
|
||||
final Properties properties=new Properties();
|
||||
final Properties properties=new SortedProperties();
|
||||
save(properties);
|
||||
try { //save config
|
||||
FileIO.toFile(getConfigFile(), properties, "General configuration");
|
||||
|
|
|
@ -3,13 +3,11 @@ package magic.game.state;
|
|||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeSet;
|
||||
import magic.utility.MagicFileSystem;
|
||||
import magic.utility.MagicSystem;
|
||||
import magic.utility.SortedProperties;
|
||||
|
||||
public final class GameStateFileWriter {
|
||||
private GameStateFileWriter() {}
|
||||
|
@ -20,7 +18,7 @@ public final class GameStateFileWriter {
|
|||
private static final String PROP_StartPlayerIndex = "startPlayerIndex";
|
||||
|
||||
public static void createSaveGameFile(final GameState gameState, final File aFile) {
|
||||
final Properties properties = getNewSortedProperties();
|
||||
final Properties properties = new SortedProperties();
|
||||
setGameProperties(properties, gameState);
|
||||
setAllPlayerProperties(properties, gameState);
|
||||
savePropertyFile(properties, aFile);
|
||||
|
@ -79,14 +77,4 @@ public final class GameStateFileWriter {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static Properties getNewSortedProperties() {
|
||||
return new Properties() {
|
||||
@Override
|
||||
public synchronized Enumeration<Object> keys() {
|
||||
return Collections.enumeration(new TreeSet<>(super.keySet()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,10 +4,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeSet;
|
||||
import magic.data.DeckGenerators;
|
||||
import magic.utility.DeckUtils;
|
||||
import magic.data.DuelConfig;
|
||||
|
@ -17,6 +14,7 @@ import magic.utility.FileIO;
|
|||
import magic.utility.MagicFileSystem.DataPath;
|
||||
import magic.utility.MagicFileSystem;
|
||||
import magic.utility.MagicSystem;
|
||||
import magic.utility.SortedProperties;
|
||||
|
||||
public class MagicDuel {
|
||||
|
||||
|
@ -200,7 +198,7 @@ public class MagicDuel {
|
|||
}
|
||||
|
||||
public void save(final File file) {
|
||||
final Properties properties = getNewSortedProperties();
|
||||
final Properties properties = new SortedProperties();
|
||||
save(properties);
|
||||
try {
|
||||
FileIO.toFile(file, properties, "Duel");
|
||||
|
@ -209,16 +207,6 @@ public class MagicDuel {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private Properties getNewSortedProperties() {
|
||||
return new Properties() {
|
||||
@Override
|
||||
public synchronized Enumeration<Object> keys() {
|
||||
return Collections.enumeration(new TreeSet<>(super.keySet()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void load(final Properties properties) {
|
||||
duelConfig.load(properties, true);
|
||||
gameNr=Integer.parseInt(properties.getProperty(GAME,"1"));
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Properties;
|
|||
import magic.ai.MagicAIImpl;
|
||||
import magic.translate.StringContext;
|
||||
import magic.translate.UiString;
|
||||
import magic.utility.SortedProperties;
|
||||
|
||||
public class AiProfile extends PlayerProfile {
|
||||
|
||||
|
@ -72,7 +73,7 @@ public class AiProfile extends PlayerProfile {
|
|||
|
||||
@Override
|
||||
public void save() {
|
||||
final Properties properties = new Properties();
|
||||
final Properties properties = new SortedProperties();
|
||||
properties.setProperty(KEY_EXTRA_LIFE, String.valueOf(getExtraLife()));
|
||||
properties.setProperty(KEY_AI_LEVEL, String.valueOf(getAiLevel()));
|
||||
properties.setProperty(KEY_AI_TYPE, getAiType().name());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package magic.model.player;
|
||||
|
||||
import java.util.Properties;
|
||||
import magic.utility.SortedProperties;
|
||||
|
||||
public class HumanProfile extends PlayerProfile {
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class HumanProfile extends PlayerProfile {
|
|||
|
||||
@Override
|
||||
public void save() {
|
||||
saveProperties(new Properties());
|
||||
saveProperties(new SortedProperties());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.UUID;
|
|||
import magic.utility.FileIO;
|
||||
import magic.utility.MagicFileSystem;
|
||||
import magic.utility.MagicFileSystem.DataPath;
|
||||
import magic.utility.SortedProperties;
|
||||
|
||||
public abstract class PlayerProfile {
|
||||
|
||||
|
@ -78,7 +79,7 @@ public abstract class PlayerProfile {
|
|||
|
||||
protected Properties loadPlayerProperties() {
|
||||
final File propertiesFile = new File(getProfilePath().resolve("player.profile").toString());
|
||||
final Properties properties = propertiesFile.exists() ? FileIO.toProp(propertiesFile) : new Properties();
|
||||
final Properties properties = propertiesFile.exists() ? FileIO.toProp(propertiesFile) : new SortedProperties();
|
||||
playerName = properties.getProperty("playerName", "");
|
||||
return properties;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import magic.model.MagicDeck;
|
|||
import magic.model.MagicGame;
|
||||
import magic.model.MagicPlayer;
|
||||
import magic.utility.FileIO;
|
||||
import magic.utility.SortedProperties;
|
||||
|
||||
public class PlayerStatistics {
|
||||
|
||||
|
@ -88,7 +89,7 @@ public class PlayerStatistics {
|
|||
|
||||
private void loadStats() {
|
||||
final File statsFile = new File(statsFilePath.toString());
|
||||
final Properties properties = statsFile.exists() ? FileIO.toProp(statsFile) : new Properties();
|
||||
final Properties properties = statsFile.exists() ? FileIO.toProp(statsFile) : new SortedProperties();
|
||||
gamesPlayed = Integer.parseInt(properties.getProperty(GAMES_PLAYED,"0"));
|
||||
gamesWon = Integer.parseInt(properties.getProperty(GAMES_WON,"0"));
|
||||
gamesConceded = Integer.parseInt(properties.getProperty(GAMES_CONCEDED,"0"));
|
||||
|
@ -106,7 +107,7 @@ public class PlayerStatistics {
|
|||
|
||||
public void save() {
|
||||
|
||||
final Properties properties = new Properties();
|
||||
final Properties properties = new SortedProperties();
|
||||
properties.setProperty(GAMES_PLAYED, String.valueOf(gamesPlayed));
|
||||
properties.setProperty(GAMES_WON, String.valueOf(gamesWon));
|
||||
properties.setProperty(GAMES_CONCEDED, String.valueOf(gamesConceded));
|
||||
|
|
|
@ -54,7 +54,7 @@ public class FileIO {
|
|||
}
|
||||
|
||||
public static Properties toProp(final File aFile) {
|
||||
Properties properties = new Properties();
|
||||
Properties properties = new SortedProperties();
|
||||
try {
|
||||
properties = toProp(new FileInputStream(aFile));
|
||||
} catch (final IOException ex) {
|
||||
|
@ -64,7 +64,7 @@ public class FileIO {
|
|||
}
|
||||
|
||||
public static Properties toProp(final InputStream ins) {
|
||||
final Properties properties = new Properties();
|
||||
final Properties properties = new SortedProperties();
|
||||
try {
|
||||
properties.load(new BufferedReader(new InputStreamReader(ins, UTF8)));
|
||||
} catch (final IOException ex) {
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package magic.utility;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class SortedProperties extends Properties {
|
||||
@Override
|
||||
public synchronized Enumeration<Object> keys() {
|
||||
return Collections.enumeration(new TreeSet<>(super.keySet()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue