aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config/compatibility
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-05-21 17:50:43 +0700
committerGitHub <noreply@github.com>2022-05-21 12:50:43 +0200
commitba87b8b1fa4e2397a3e0ed5a18f7ea6137d42f77 (patch)
treea052e7ac963be0f64980fc3faa664ebf20a52b34 /src/main/java/cc/polyfrost/oneconfig/config/compatibility
parent1abe65dc3875df5a490d8c900399e61a378ae901 (diff)
downloadOneConfig-ba87b8b1fa4e2397a3e0ed5a18f7ea6137d42f77.tar.gz
OneConfig-ba87b8b1fa4e2397a3e0ed5a18f7ea6137d42f77.tar.bz2
OneConfig-ba87b8b1fa4e2397a3e0ed5a18f7ea6137d42f77.zip
vigilance compat (#15)
* vigilance compat reorganize ASM * remove non-RenderManager nanovg usage wherever possible fix build generalize utils * setupGradle task * migrate to kotlin gradle use essential gradle toolkit shade new gson * Small changes * Update .gitignore * fix natives * Fix all problems * null Co-authored-by: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config/compatibility')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java135
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java7
2 files changed, 142 insertions, 0 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java
new file mode 100644
index 0000000..14d1e72
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java
@@ -0,0 +1,135 @@
+package cc.polyfrost.oneconfig.config.compatibility;
+
+import cc.polyfrost.oneconfig.config.core.ConfigCore;
+import cc.polyfrost.oneconfig.config.data.Mod;
+import cc.polyfrost.oneconfig.config.data.OptionCategory;
+import cc.polyfrost.oneconfig.config.data.OptionPage;
+import cc.polyfrost.oneconfig.config.data.OptionSubcategory;
+import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
+import cc.polyfrost.oneconfig.config.interfaces.Config;
+import cc.polyfrost.oneconfig.gui.elements.config.*;
+import gg.essential.vigilance.Vigilant;
+import gg.essential.vigilance.data.*;
+import kotlin.reflect.KMutableProperty0;
+import kotlin.reflect.jvm.ReflectJvmMapping;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Objects;
+
+public class VigilanceConfig extends Config {
+ public final Vigilant vigilant;
+
+ public VigilanceConfig(Mod modData, String configFile, Vigilant vigilant) {
+ super(modData, configFile);
+ this.vigilant = vigilant;
+ init(modData);
+ }
+
+ @Override
+ public void init(Mod mod) {
+ if (vigilant != null) {
+ mod.config = this;
+ generateOptionsList(mod.defaultPage);
+ ConfigCore.oneConfigMods.add(mod);
+ this.mod = mod;
+ }
+ }
+
+ @Override
+ public void save() {
+ vigilant.markDirty();
+ vigilant.writeData();
+ }
+
+ @Override
+ public void load() {
+ //no-op
+ }
+
+ private void generateOptionsList(OptionPage page) {
+ for (PropertyData option : ((VigilantAccessor) vigilant).getPropertyCollector().getProperties()) {
+ PropertyAttributesExt attributes = option.getAttributesExt();
+ if (attributes.getHidden()) continue;
+ if (!page.categories.containsKey(attributes.getCategory()))
+ page.categories.put(attributes.getCategory(), new OptionCategory());
+ OptionCategory category = page.categories.get(attributes.getCategory());
+ if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(attributes.getSubcategory()))
+ category.subcategories.add(new OptionSubcategory(attributes.getSubcategory()));
+ ArrayList<BasicOption> options = category.subcategories.get(category.subcategories.size() - 1).options;
+ switch (attributes.getType()) {
+ case SWITCH:
+ options.add(new ConfigSwitch(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2));
+ break;
+ case CHECKBOX:
+ options.add(new ConfigCheckbox(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2));
+ break;
+ case PARAGRAPH:
+ case TEXT:
+ options.add(new ConfigTextBox(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, attributes.getPlaceholder(), attributes.getProtected(), attributes.getType() == PropertyType.PARAGRAPH));
+ break;
+ case SELECTOR:
+ options.add(new ConfigDropdown(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, attributes.getOptions().toArray(new String[0])));
+ break;
+ case PERCENT_SLIDER:
+ options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, 0, 1, 0));
+ break;
+ case DECIMAL_SLIDER:
+ options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, attributes.getMinF(), attributes.getMaxF(), 0));
+ break;
+ case SLIDER:
+ options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, attributes.getMin(), attributes.getMax(), 0));
+ break;
+ /*case COLOR: TODO: find a way to go from Color to OneColor
+ options.add(new ConfigColorElement(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2));
+ break;*/
+ case BUTTON:
+ options.add(new ConfigButton(() -> ((CallablePropertyValue) option.getValue()).invoke(option.getInstance()), option.getInstance(), attributes.getName(), 2, attributes.getPlaceholder()));
+ break;
+ }
+ if (attributes.getType() == PropertyType.SWITCH || attributes.getType() == PropertyType.CHECKBOX) {
+ optionNames.put(PropertyKt.fullPropertyPath(option.getAttributesExt()), options.get(options.size() - 1));
+ }
+ }
+ }
+
+ private Field getFieldOfProperty(PropertyData data) {
+ if (data.getValue() instanceof FieldBackedPropertyValue) {
+ FieldBackedPropertyValue fieldBackedPropertyValue = (FieldBackedPropertyValue) data.getValue();
+ try {
+ Field field = fieldBackedPropertyValue.getClass().getDeclaredField("field");
+ field.setAccessible(true);
+ return (Field) field.get(fieldBackedPropertyValue);
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ throw new RuntimeException(e);
+ }
+ } else if (data.getValue() instanceof ValueBackedPropertyValue) {
+ ValueBackedPropertyValue valueBackedPropertyValue = (ValueBackedPropertyValue) data.getValue();
+ try {
+ Field field = valueBackedPropertyValue.getClass().getDeclaredField("obj");
+ field.setAccessible(true);
+ return (Field) field.get(valueBackedPropertyValue);
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ throw new RuntimeException(e);
+ }
+ } else if (data.getValue() instanceof KPropertyBackedPropertyValue) {
+ KPropertyBackedPropertyValue kPropertyBackedPropertyValue = (KPropertyBackedPropertyValue) data.getValue();
+ try {
+ Field field = kPropertyBackedPropertyValue.getClass().getDeclaredField("property");
+ field.setAccessible(true);
+ KMutableProperty0 property = (KMutableProperty0) field.get(kPropertyBackedPropertyValue);
+ return ReflectJvmMapping.getJavaField(property);
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ throw new RuntimeException(e);
+ }
+ } else throw new RuntimeException("Unknown property value type: " + data.getValue().getClass());
+ }
+
+ @SuppressWarnings("unused")
+ public void addDependency(PropertyData property, PropertyData dependency) {
+ BasicOption option = optionNames.get(PropertyKt.fullPropertyPath(property.getAttributesExt()));
+ if (option != null) {
+ option.setDependency(() -> Objects.equals(dependency.getValue().getValue(vigilant), true));
+ }
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java
new file mode 100644
index 0000000..4c79a21
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilantAccessor.java
@@ -0,0 +1,7 @@
+package cc.polyfrost.oneconfig.config.compatibility;
+
+import gg.essential.vigilance.data.PropertyCollector;
+
+public interface VigilantAccessor {
+ PropertyCollector getPropertyCollector();
+}