diff --git a/src/main/java/com/seibel/lod/core/config/ConfigAnnotations.java b/src/main/java/com/seibel/lod/core/config/ConfigAnnotations.java index ed320f9f9..c3ca18eae 100644 --- a/src/main/java/com/seibel/lod/core/config/ConfigAnnotations.java +++ b/src/main/java/com/seibel/lod/core/config/ConfigAnnotations.java @@ -21,7 +21,10 @@ public class ConfigAnnotations { } - /** Makes text (looks like @Entry but doesn't save and has no button) */ + /** + * Makes text (looks like normal entry but doesn't save and has no button) + * Accepts string and the text is the value + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Comment diff --git a/src/main/java/com/seibel/lod/core/config/ConfigBase.java b/src/main/java/com/seibel/lod/core/config/ConfigBase.java index f8d6551c9..a78e581b6 100644 --- a/src/main/java/com/seibel/lod/core/config/ConfigBase.java +++ b/src/main/java/com/seibel/lod/core/config/ConfigBase.java @@ -25,7 +25,7 @@ public class ConfigBase { Double Float Byte - Map or MultiOption + Map */ public static final List> acceptableInputs = new ArrayList<>(); private static void addAcceptableInputs() { diff --git a/src/main/java/com/seibel/lod/core/config/ConfigEntry.java b/src/main/java/com/seibel/lod/core/config/ConfigEntry.java index b5bf8c3a6..498979996 100644 --- a/src/main/java/com/seibel/lod/core/config/ConfigEntry.java +++ b/src/main/java/com/seibel/lod/core/config/ConfigEntry.java @@ -12,6 +12,7 @@ public class ConfigEntry { public String name; // This should only be set once in the init private T value; + private T defaultValue; private String comment; private T min; private T max; @@ -20,12 +21,19 @@ public class ConfigEntry { /** Creates the entry */ private ConfigEntry(T value, String comment, T min, T max, boolean show) { this.value = value; + this.defaultValue = value; this.comment = comment; this.min = min; this.max = max; this.show = show; } + + /** Gets the default value of the option */ + public T getDefaultValue() { + return this.defaultValue; + } + /** Gets the value */ public T get() { return this.value; diff --git a/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java b/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java index 16217adaa..eebe0882d 100644 --- a/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java +++ b/src/main/java/com/seibel/lod/core/config/file/ConfigFileHandling.java @@ -24,6 +24,7 @@ public class ConfigFileHandling { public static final Path ConfigPath = SingletonHandler.get(IMinecraftWrapper.class).getGameDirectory().toPath().resolve("config").resolve(ModInfo.NAME+".toml"); public static final CommentedFileConfig config = CommentedFileConfig.builder(ConfigPath.toFile()).autosave().build(); + /** Saves the config to the file */ public static void saveToFile() { if (!Files.exists(ConfigPath)) try { @@ -40,8 +41,9 @@ public class ConfigFileHandling { config.close(); } - + /** Loads the config from the file */ public static void loadFromFile() { + // Attempt to load the file and if it fails then save config to file try { if (Files.exists(ConfigPath)) config.load(); @@ -54,6 +56,7 @@ public class ConfigFileHandling { return; } + // Load all the entries for (ConfigEntry entry : ConfigBase.entries) { createComment(entry, config); loadEntry(entry, config); @@ -62,11 +65,13 @@ public class ConfigFileHandling { config.close(); } + // Save an entry when only given the entry public static void saveEntry(ConfigEntry entry) { loadConfig(config); saveEntry(entry, config); config.close(); } + // Save an entry @SuppressWarnings("unchecked") public static void saveEntry(ConfigEntry entry, CommentedFileConfig workConfig) { if (!entry.get().getClass().isAssignableFrom(HashMap.class)) { @@ -75,13 +80,15 @@ public class ConfigFileHandling { workConfig.set(entry.getNameWCategory(), getStringFromHashMap((HashMap) entry.get())); } } + + // Loads an entry when only given the entry public static void loadEntry(ConfigEntry entry) { loadConfig(config); loadEntry(entry, config); config.close(); } - + // Loads an entry @SuppressWarnings("unchecked") // Suppress due to its always safe. (I think. See reasons below.) public static void loadEntry(ConfigEntry entry, CommentedFileConfig workConfig) { if (workConfig.contains(entry.getNameWCategory())) { @@ -102,11 +109,13 @@ public class ConfigFileHandling { } } + // Creates the comment for an entry when only given the entry public static void createComment(ConfigEntry entry) { loadConfig(config); createComment(entry, config); config.close(); } + // Creates a comment for an entry public static void createComment(ConfigEntry entry, CommentedFileConfig workConfig) { workConfig.setComment(entry.getNameWCategory(), entry.getComment()); } @@ -131,7 +140,7 @@ public class ConfigFileHandling { - // Stuff for converting HashMap's and String's + // Stuff for converting HashMap's and String's (uses json) public static String getStringFromHashMap(HashMap item) { JSONObject jsonObject = new JSONObject(); @@ -141,9 +150,8 @@ public class ConfigFileHandling { return jsonObject.toJSONString(); } - - public static HashMap getHashMapFromString(String s) { - HashMap map = new HashMap<>(); + public static HashMap getHashMapFromString(String s) { + HashMap map = new HashMap<>(); JSONObject jsonObject = null; try { @@ -153,7 +161,7 @@ public class ConfigFileHandling { } for (int i = 0; i < jsonObject.keySet().toArray().length; i++) { - map.put((String) jsonObject.keySet().toArray()[i], (type) jsonObject.get(jsonObject.keySet().toArray()[i])); + map.put((String) jsonObject.keySet().toArray()[i], (T) jsonObject.get(jsonObject.keySet().toArray()[i])); } return map; } diff --git a/src/main/java/com/seibel/lod/core/wrapperInterfaces/AbstractScreen.java b/src/main/java/com/seibel/lod/core/config/gui/AbstractScreen.java similarity index 56% rename from src/main/java/com/seibel/lod/core/wrapperInterfaces/AbstractScreen.java rename to src/main/java/com/seibel/lod/core/config/gui/AbstractScreen.java index 3fd7c8d64..692a6f9ee 100644 --- a/src/main/java/com/seibel/lod/core/wrapperInterfaces/AbstractScreen.java +++ b/src/main/java/com/seibel/lod/core/config/gui/AbstractScreen.java @@ -1,7 +1,7 @@ -package com.seibel.lod.core.wrapperInterfaces; +package com.seibel.lod.core.config.gui; /** - * The bace for all screens + * The base for all screens * * @author coolGi */ @@ -10,13 +10,16 @@ public abstract class AbstractScreen { public int height; public int mouseX = 0; public int mouseY = 0; + /** Weather it should close when you press the escape key */ public boolean shouldCloseOnEsc = true; + /** Called once when the screen is opened */ public abstract void init(); + /** Called every frame */ public abstract void render(float delta); public void tick() {} - + /** What happens when the user closes the screen*/ public void onClose() {} } diff --git a/src/main/java/com/seibel/lod/core/config/gui/ConfigScreen.java b/src/main/java/com/seibel/lod/core/config/gui/ConfigScreen.java index 7d174804c..36ab84575 100644 --- a/src/main/java/com/seibel/lod/core/config/gui/ConfigScreen.java +++ b/src/main/java/com/seibel/lod/core/config/gui/ConfigScreen.java @@ -1,10 +1,7 @@ package com.seibel.lod.core.config.gui; -import com.seibel.lod.core.wrapperInterfaces.AbstractScreen; - /** * @author coolGi2007 - * @author leetom? */ public class ConfigScreen extends AbstractScreen { @Override @@ -14,6 +11,11 @@ public class ConfigScreen extends AbstractScreen { @Override public void render(float delta) { - System.out.println(delta); + System.out.println("Updated config screen with the delta of " + delta); + } + + @Override + public void tick() { + System.out.println("Ticked"); } }