diff options
author | Linnea Gräf <nea@nea.moe> | 2023-08-29 22:11:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-29 22:11:38 +0200 |
commit | e30585a3323be457dea81b4bc33b020c8547cf54 (patch) | |
tree | bdf86b487927e6ef2a242a472e47e362f78e1f5f /src/main/java/at/hannibal2 | |
parent | 80912f7dcc7a4109b7e917f54689453d575c65f6 (diff) | |
download | skyhanni-e30585a3323be457dea81b4bc33b020c8547cf54.tar.gz skyhanni-e30585a3323be457dea81b4bc33b020c8547cf54.tar.bz2 skyhanni-e30585a3323be457dea81b4bc33b020c8547cf54.zip |
Add properties to feature toggles (#424)
Add properties to feature toggles #424
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java | 1 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/FeatureToggleProcessor.kt | 25 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java index 03fd18cb7..fa099ad29 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/RiftConfig.java @@ -56,6 +56,7 @@ public class RiftConfig { @Expose @ConfigOption(name = "Show Bonuses", desc = "Show bonuses you get from the talisman.") @ConfigEditorBoolean + @FeatureToggle public Property<Boolean> showBonuses = Property.of(true); @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/FeatureToggleProcessor.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/FeatureToggleProcessor.kt index 8d431a64e..fc8c4bd92 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/FeatureToggleProcessor.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/FeatureToggleProcessor.kt @@ -3,8 +3,10 @@ package at.hannibal2.skyhanni.features.misc.massconfiguration import at.hannibal2.skyhanni.config.FeatureToggle import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean import io.github.moulberry.moulconfig.annotations.ConfigOption +import io.github.moulberry.moulconfig.observer.Property import io.github.moulberry.moulconfig.processor.ConfigStructureReader import java.lang.reflect.Field +import java.lang.reflect.ParameterizedType import java.util.* class FeatureToggleProcessor : ConfigStructureReader { @@ -42,14 +44,33 @@ class FeatureToggleProcessor : ConfigStructureReader { val featureToggle = field.getAnnotation(FeatureToggle::class.java) ?: return field.getAnnotation(ConfigEditorBoolean::class.java) ?: error("Feature toggle found without ConfigEditorBoolean: $field") + val setter: (Boolean) -> Unit + val value: Boolean + when (field.type) { + java.lang.Boolean.TYPE -> { + setter = { field.setBoolean(baseObject, it) } + value = field.getBoolean(baseObject) + } + + Property::class.java -> { + val genericType = field.genericType + require(genericType is ParameterizedType) + require((genericType.actualTypeArguments[0] as Class<*>) == (java.lang.Boolean::class.java)) + val prop = field.get(baseObject) as Property<Boolean> + setter = { prop.set(it) } + value = prop.get() + } + + else -> error("Invalid FeatureToggle type: $field") + } allOptions.add( FeatureToggleableOption( option.name, option.desc, - field.getBoolean(baseObject), + value, featureToggle.trueIsEnabled, latestCategory!!, - { field.setBoolean(baseObject, it) }, + setter, pathStack.joinToString(".") + "." + field.name ) ) |