From 7f2251732ea8e476ad26107e4f5510e044a8116c Mon Sep 17 00:00:00 2001 From: Matthew Cech Date: Sat, 2 Nov 2019 19:13:26 -0800 Subject: [PATCH] = Configs updating --- src/core/Config.java | 1 + src/core/ConfigGlobals.java | 68 ++++++++++++++++++++++++ src/core/ConfigItem.java | 6 +-- src/core/LocCommands.java | 4 +- src/dataStructures/KittyStartupMode.java | 18 +++++++ 5 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 src/core/ConfigGlobals.java create mode 100644 src/dataStructures/KittyStartupMode.java diff --git a/src/core/Config.java b/src/core/Config.java index c76c9c2..96b29bc 100644 --- a/src/core/Config.java +++ b/src/core/Config.java @@ -28,6 +28,7 @@ public class Config sections = new Vector(); // Add all sections + sections.add(new ConfigGlobals()); sections.add(new LocCommands()); sections.add(new LocStrings()); sections.add(new CommandEnabler()); diff --git a/src/core/ConfigGlobals.java b/src/core/ConfigGlobals.java new file mode 100644 index 0000000..f7b7ce7 --- /dev/null +++ b/src/core/ConfigGlobals.java @@ -0,0 +1,68 @@ +package core; + +import java.util.ArrayList; +import java.util.List; + +import dataStructures.KittyStartupMode; +import utils.GlobalLog; + +// Want to add a single item to the config file? This is where that lives. +public class ConfigGlobals implements IConfigSection +{ + // Defined const variables + public static final String header = "Globals"; + public static ConfigGlobals instance; + + + // A pile of variables being manually tracked/serialized to the config file + private static final String startupStyleKey = "mode"; + private KittyStartupMode startupStyleValue = KittyStartupMode.Development; + + // Constructor + public ConfigGlobals() + { + if(instance == null) + instance = this; + else + GlobalLog.error("Attempted to initialize a second config globals! Probably don't do this!"); + } + + @Override + public String getSectionTitle() + { + return header; + } + + public static KittyStartupMode getStartupMode() + { + return instance.startupStyleValue; + } + + @Override + public void consume(List pairs) + { + for(int i = 0; i < pairs.size(); ++i) + { + String key = pairs.get(i).key; + String value = pairs.get(i).value; + + // Parse startup style + if(key.equalsIgnoreCase(startupStyleKey)) + { + startupStyleValue = KittyStartupMode.Development; + + if(value.equalsIgnoreCase(KittyStartupMode.Release.getValue())) + startupStyleValue = KittyStartupMode.Release; + } + } + } + + @Override + public List produce() + { + List items = new ArrayList(); + items.add(new ConfigItem(getSectionTitle(), startupStyleKey, startupStyleValue.getValue())); + + return items; + } +} diff --git a/src/core/ConfigItem.java b/src/core/ConfigItem.java index 7f556d2..75e8bad 100644 --- a/src/core/ConfigItem.java +++ b/src/core/ConfigItem.java @@ -6,9 +6,9 @@ import utils.StringUtils; // perform any parsing past naming columns, and just holds the raw data. public class ConfigItem { - public String type; - public String key; - public String value; + public String type; // The section this specific key/value pair belongs to. This almost certainly will appear in multiple places. + public String key; // A unique key for a given lookup value for the specified section. Keys, within sections, are unique. + public String value; // The value assocaited with the key. public static final int items = 3; public static final String[] header = {"Type","Key","Value"}; diff --git a/src/core/LocCommands.java b/src/core/LocCommands.java index 30d071e..2d446e7 100644 --- a/src/core/LocCommands.java +++ b/src/core/LocCommands.java @@ -11,7 +11,7 @@ import dataStructures.Pair; public class LocCommands extends BaseLocFile implements IConfigSection { // Defined const variables - public static final String HeaderName = "Localized Commands"; + public static final String header = "Localized Commands"; public static final String function = "LocCommands.stub"; // Instance @@ -20,7 +20,7 @@ public class LocCommands extends BaseLocFile implements IConfigSection // Constructor public LocCommands() { - super(HeaderName, function); + super(header, function); GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName()); diff --git a/src/dataStructures/KittyStartupMode.java b/src/dataStructures/KittyStartupMode.java new file mode 100644 index 0000000..3d9e67d --- /dev/null +++ b/src/dataStructures/KittyStartupMode.java @@ -0,0 +1,18 @@ +package dataStructures; + +public enum KittyStartupMode +{ + Development("dev"), Release("release"); + + private final String value; + private KittyStartupMode(String value) + { + this.value = value; + } + + public String getValue() + { + return value; + } +} +