aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/misc
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2023-08-29 22:11:38 +0200
committerGitHub <noreply@github.com>2023-08-29 22:11:38 +0200
commite30585a3323be457dea81b4bc33b020c8547cf54 (patch)
treebdf86b487927e6ef2a242a472e47e362f78e1f5f /src/main/java/at/hannibal2/skyhanni/features/misc
parent80912f7dcc7a4109b7e917f54689453d575c65f6 (diff)
downloadskyhanni-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/skyhanni/features/misc')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/massconfiguration/FeatureToggleProcessor.kt25
1 files changed, 23 insertions, 2 deletions
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
)
)