From aad5111d45a66d943f0bcbe885ccb28249441d11 Mon Sep 17 00:00:00 2001
From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>
Date: Tue, 26 Apr 2022 20:35:35 +0200
Subject: config system rewrite
---
.../oneconfig/config/interfaces/BasicOption.java | 78 ++++++++++++++++
.../oneconfig/config/interfaces/Config.java | 101 +++++++++------------
.../oneconfig/config/interfaces/Option.java | 78 ----------------
3 files changed, 121 insertions(+), 136 deletions(-)
create mode 100644 src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java
delete mode 100644 src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java
(limited to 'src/main/java/io/polyfrost/oneconfig/config/interfaces')
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java
new file mode 100644
index 0000000..42c826e
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java
@@ -0,0 +1,78 @@
+package io.polyfrost.oneconfig.config.interfaces;
+
+import java.lang.reflect.Field;
+
+@SuppressWarnings({"unused"})
+public abstract class BasicOption {
+ protected final Field field;
+ protected final String name;
+ protected final String description;
+ public final int size;
+
+ /**
+ * Initialize option
+ *
+ * @param field variable attached to option (null for category)
+ * @param name name of option
+ * @param description description of option
+ * @param size size of option, 0 for single column, 1 for double.
+ */
+ public BasicOption(Field field, String name, String description, int size) {
+ this.field = field;
+ this.name = name;
+ this.description = description;
+ this.size = size;
+ if (field != null) field.setAccessible(true);
+ }
+
+ /**
+ * @param object Java object to set the variable to
+ */
+ protected void set(Object object) throws IllegalAccessException {
+ if (field == null) return;
+ field.set(null, object);
+ }
+
+ /**
+ * @return value of variable as Java object
+ */
+ protected Object get() throws IllegalAccessException {
+ if (field == null) return null;
+ return field.get(null);
+ }
+
+ /**
+ * @return height of option to align other options accordingly
+ */
+ public abstract int getHeight();
+
+ /**
+ * Function that gets called when drawing option
+ *
+ * @param vg NanoVG context
+ * @param x x position
+ * @param y y position
+ * @param mouseX x position of mouse
+ * @param mouseY y position of mouse
+ */
+ public abstract void draw(long vg, int x, int y, int mouseX, int mouseY);
+
+ /**
+ * Function that gets called when mouse is clicked
+ *
+ * @param mouseX x position of mouse
+ * @param mouseY y position of mouse
+ * @param mouseButton button that got pressed
+ */
+ protected void onMouseClicked(int mouseX, int mouseY, int mouseButton) {
+ }
+
+ /**
+ * Function that gets called when a key is typed
+ *
+ * @param typedChar char that has been typed
+ * @param keyCode code of key
+ */
+ protected void keyTyped(char typedChar, int keyCode) {
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
index f0efcb0..c68162e 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
@@ -1,23 +1,20 @@
package io.polyfrost.oneconfig.config.interfaces;
import com.google.gson.*;
-import io.polyfrost.oneconfig.config.annotations.*;
-import io.polyfrost.oneconfig.config.core.ConfigCore;
-import io.polyfrost.oneconfig.config.data.ModData;
+import io.polyfrost.oneconfig.config.annotations.Option;
+import io.polyfrost.oneconfig.config.data.Mod;
+import io.polyfrost.oneconfig.config.data.OptionPage;
import io.polyfrost.oneconfig.config.profiles.Profiles;
-import io.polyfrost.oneconfig.gui.elements.config.*;
-import io.polyfrost.oneconfig.hud.HudCore;
-import io.polyfrost.oneconfig.hud.interfaces.BasicHud;
+import io.polyfrost.oneconfig.gui.elements.config.ConfigPage;
+import io.polyfrost.oneconfig.gui.elements.config.ConfigSwitch;
+import io.polyfrost.oneconfig.test.TestConfig;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
public class Config {
protected final String configFile;
@@ -27,16 +24,16 @@ public class Config {
* @param modData information about the mod
* @param configFile file where config is stored
*/
- public Config(ModData modData, String configFile) {
+ public Config(Mod modData, String configFile) {
this.configFile = configFile;
init(modData);
}
- public void init(ModData modData) {
+ public void init(Mod mod) {
if (Profiles.getProfileFile(configFile).exists()) load();
else save();
- modData.config = this;
- ConfigCore.settings.put(modData, generateOptionList(this.getClass()));
+ mod.config = this;
+ generateOptionList(this.getClass(), mod.defaultPage);
}
/**
@@ -62,63 +59,51 @@ public class Config {
}
/**
- * Generate the option list for internal use only
+ * Generate the option list, for internal use only
*
* @param clazz target class
- * @return list of options
+ * @param page page to add options too
*/
- protected ArrayList