From f4c6691b628cca146ddb44e77f54cb46387aa15d Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Mon, 6 Jun 2022 14:54:56 +0200 Subject: internalizing --- .../java/cc/polyfrost/oneconfig/config/Config.java | 9 +-- .../compatibility/vigilance/VigilanceConfig.java | 2 +- .../oneconfig/config/core/ConfigCore.java | 67 ---------------------- .../oneconfig/config/core/ConfigUtils.java | 48 ++++++++++++++++ .../oneconfig/config/profiles/Profiles.java | 2 +- .../java/cc/polyfrost/oneconfig/gui/HudGui.java | 4 +- .../java/cc/polyfrost/oneconfig/hud/HudCore.java | 21 ------- .../cc/polyfrost/oneconfig/internal/OneConfig.java | 4 +- .../oneconfig/internal/config/ConfigCore.java | 25 ++++++++ .../polyfrost/oneconfig/internal/hud/HudCore.java | 22 +++++++ .../plugin/asm/tweakers/VigilantTransformer.java | 2 +- 11 files changed, 107 insertions(+), 99 deletions(-) delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/config/ConfigCore.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java (limited to 'src/main/java/cc') diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java index 65d6b00..2c51387 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java @@ -2,7 +2,8 @@ package cc.polyfrost.oneconfig.config; import cc.polyfrost.oneconfig.config.annotations.ConfigPage; import cc.polyfrost.oneconfig.config.annotations.Option; -import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.config.core.ConfigUtils; +import cc.polyfrost.oneconfig.internal.config.ConfigCore; import cc.polyfrost.oneconfig.config.data.*; import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.config.elements.OptionCategory; @@ -13,7 +14,7 @@ import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.config.*; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; import cc.polyfrost.oneconfig.hud.BasicHud; -import cc.polyfrost.oneconfig.hud.HudCore; +import cc.polyfrost.oneconfig.internal.hud.HudCore; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import com.google.gson.*; @@ -144,7 +145,7 @@ public class Config { HudCore.huds.add(hud); options.add(new ConfigHeader(field, hud, option.name(), 1)); options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", 1)); - options.addAll(ConfigCore.getClassOptions(hud)); + options.addAll(ConfigUtils.getClassOptions(hud)); options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", 1)); options.get(options.size() - 1).setDependency(() -> hud.enabled); options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", 1)); @@ -165,7 +166,7 @@ public class Config { e.printStackTrace(); } } else { - options.add(ConfigCore.getOption(option, field, instance)); + options.add(ConfigUtils.getOption(option, field, instance)); } if (!option.type().equals(OptionType.HUD)) optionNames.put(pagePrefix + field.getName(), options.get(options.size() - 1)); diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java index cfa717f..3b0fcd6 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.config.compatibility.vigilance; -import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.internal.config.ConfigCore; import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.config.data.Mod; import cc.polyfrost.oneconfig.config.elements.OptionCategory; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java deleted file mode 100644 index f1aa1ab..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigCore.java +++ /dev/null @@ -1,67 +0,0 @@ -package cc.polyfrost.oneconfig.config.core; - -import cc.polyfrost.oneconfig.config.annotations.Option; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.elements.BasicOption; -import cc.polyfrost.oneconfig.gui.elements.config.*; -import cc.polyfrost.oneconfig.hud.HudCore; - -import java.lang.reflect.Field; -import java.util.ArrayList; - -public class ConfigCore { - public static ArrayList oneConfigMods = new ArrayList<>(); - - public static void saveAll() { - for (Mod modData : oneConfigMods) { - modData.config.save(); - } - } - - public static void reInitAll() { - ArrayList data = new ArrayList<>(oneConfigMods); - oneConfigMods.clear(); - HudCore.huds.clear(); - for (Mod modData : data) { - modData.config.init(modData); - } - } - - public static BasicOption getOption(Option option, Field field, Object instance) { - switch (option.type()) { - case SWITCH: - return new ConfigSwitch(field, instance, option.name(), option.size()); - case CHECKBOX: - return new ConfigCheckbox(field, instance, option.name(), option.size()); - case TEXT: - return new ConfigTextBox(field, instance, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine()); - case DUAL_OPTION: - return new ConfigDualOption(field, instance, option.name(), option.size(), option.options()); - case DROPDOWN: - return new ConfigDropdown(field, instance, option.name(), option.size(), option.options()); - case SLIDER: - return new ConfigSlider(field, instance, option.name(), option.size(), option.min(), option.max(), option.step()); - case INFO: - return new ConfigInfo(field, instance, option.name(), option.size(), option.infoType()); - case COLOR: - return new ConfigColorElement(field, instance, option.name(), option.size()); - case HEADER: - return new ConfigHeader(field, instance, option.name(), option.size()); - case BUTTON: - return new ConfigButton(field, instance, option.name(), option.size(), option.buttonText()); - case KEYBIND: - return new ConfigKeyBind(field, instance, option.name(), option.size()); - } - return null; - } - - public static ArrayList getClassOptions(Object hud) { - ArrayList options = new ArrayList<>(); - for (Field field : hud.getClass().getDeclaredFields()) { - if (!field.isAnnotationPresent(Option.class)) continue; - Option option = field.getAnnotation(Option.class); - options.add(getOption(option, field, hud)); - } - return options; - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java new file mode 100644 index 0000000..d44488d --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java @@ -0,0 +1,48 @@ +package cc.polyfrost.oneconfig.config.core; + +import cc.polyfrost.oneconfig.config.annotations.Option; +import cc.polyfrost.oneconfig.config.elements.BasicOption; +import cc.polyfrost.oneconfig.gui.elements.config.*; + +import java.lang.reflect.Field; +import java.util.ArrayList; + +public class ConfigUtils { + public static BasicOption getOption(Option option, Field field, Object instance) { + switch (option.type()) { + case SWITCH: + return new ConfigSwitch(field, instance, option.name(), option.size()); + case CHECKBOX: + return new ConfigCheckbox(field, instance, option.name(), option.size()); + case TEXT: + return new ConfigTextBox(field, instance, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine()); + case DUAL_OPTION: + return new ConfigDualOption(field, instance, option.name(), option.size(), option.options()); + case DROPDOWN: + return new ConfigDropdown(field, instance, option.name(), option.size(), option.options()); + case SLIDER: + return new ConfigSlider(field, instance, option.name(), option.size(), option.min(), option.max(), option.step()); + case INFO: + return new ConfigInfo(field, instance, option.name(), option.size(), option.infoType()); + case COLOR: + return new ConfigColorElement(field, instance, option.name(), option.size()); + case HEADER: + return new ConfigHeader(field, instance, option.name(), option.size()); + case BUTTON: + return new ConfigButton(field, instance, option.name(), option.size(), option.buttonText()); + case KEYBIND: + return new ConfigKeyBind(field, instance, option.name(), option.size()); + } + return null; + } + + public static ArrayList getClassOptions(Object hud) { + ArrayList options = new ArrayList<>(); + for (Field field : hud.getClass().getDeclaredFields()) { + if (!field.isAnnotationPresent(Option.class)) continue; + Option option = field.getAnnotation(Option.class); + options.add(getOption(option, field, hud)); + } + return options; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java index 006fea9..2b0a97e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java @@ -1,7 +1,7 @@ package cc.polyfrost.oneconfig.config.profiles; import cc.polyfrost.oneconfig.internal.OneConfig; -import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.internal.config.ConfigCore; import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; import org.apache.commons.io.FileUtils; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java index 1b172d0..7f3bf15 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java @@ -1,8 +1,8 @@ package cc.polyfrost.oneconfig.gui; -import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.internal.config.ConfigCore; import cc.polyfrost.oneconfig.hud.BasicHud; -import cc.polyfrost.oneconfig.hud.HudCore; +import cc.polyfrost.oneconfig.internal.hud.HudCore; import cc.polyfrost.oneconfig.renderer.RenderManager; import gg.essential.universal.UKeyboard; import gg.essential.universal.UMatrixStack; diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java deleted file mode 100644 index c3e7f9b..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java +++ /dev/null @@ -1,21 +0,0 @@ -package cc.polyfrost.oneconfig.hud; - -import cc.polyfrost.oneconfig.events.event.HudRenderEvent; -import gg.essential.universal.UResolution; -import me.kbrewster.eventbus.Subscribe; - -import java.util.ArrayList; - -public class HudCore { - public static ArrayList huds = new ArrayList<>(); - public static boolean editing = false; - - @Subscribe - public void onRender(HudRenderEvent event) { - if (editing) return; - for (BasicHud hud : huds) { - if (hud.enabled) - hud.drawAll(hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true); - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java index 3a00e06..7f0882a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java @@ -1,10 +1,10 @@ package cc.polyfrost.oneconfig.internal; -import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.internal.config.ConfigCore; import cc.polyfrost.oneconfig.config.data.Mod; import cc.polyfrost.oneconfig.config.data.ModType; import cc.polyfrost.oneconfig.events.EventManager; -import cc.polyfrost.oneconfig.hud.HudCore; +import cc.polyfrost.oneconfig.internal.hud.HudCore; import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; import cc.polyfrost.oneconfig.internal.command.OneConfigCommand; import cc.polyfrost.oneconfig.internal.gui.BlurHandler; diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/ConfigCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/ConfigCore.java new file mode 100644 index 0000000..f41b74e --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/ConfigCore.java @@ -0,0 +1,25 @@ +package cc.polyfrost.oneconfig.internal.config; + +import cc.polyfrost.oneconfig.config.data.Mod; +import cc.polyfrost.oneconfig.internal.hud.HudCore; + +import java.util.ArrayList; + +public class ConfigCore { + public static ArrayList oneConfigMods = new ArrayList<>(); + + public static void saveAll() { + for (Mod modData : oneConfigMods) { + modData.config.save(); + } + } + + public static void reInitAll() { + ArrayList data = new ArrayList<>(oneConfigMods); + oneConfigMods.clear(); + HudCore.huds.clear(); + for (Mod modData : data) { + modData.config.init(modData); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java new file mode 100644 index 0000000..7c92799 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/hud/HudCore.java @@ -0,0 +1,22 @@ +package cc.polyfrost.oneconfig.internal.hud; + +import cc.polyfrost.oneconfig.events.event.HudRenderEvent; +import cc.polyfrost.oneconfig.hud.BasicHud; +import gg.essential.universal.UResolution; +import me.kbrewster.eventbus.Subscribe; + +import java.util.ArrayList; + +public class HudCore { + public static ArrayList huds = new ArrayList<>(); + public static boolean editing = false; + + @Subscribe + public void onRender(HudRenderEvent event) { + if (editing) return; + for (BasicHud hud : huds) { + if (hud.enabled) + hud.drawAll(hud.getXScaled(UResolution.getScaledWidth()), hud.getYScaled(UResolution.getScaledHeight()), hud.scale, true); + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java index f241c74..09f40e7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/asm/tweakers/VigilantTransformer.java @@ -1,7 +1,7 @@ package cc.polyfrost.oneconfig.internal.plugin.asm.tweakers; import cc.polyfrost.oneconfig.config.compatibility.vigilance.VigilanceConfig; -import cc.polyfrost.oneconfig.config.core.ConfigCore; +import cc.polyfrost.oneconfig.internal.config.ConfigCore; import cc.polyfrost.oneconfig.config.data.Mod; import cc.polyfrost.oneconfig.config.data.ModType; import cc.polyfrost.oneconfig.internal.plugin.asm.ITransformer; -- cgit