aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/gui/config
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-22 16:08:31 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-22 16:08:31 +0100
commit856f5e0e815c8ef3be77ef342e1b0ca91aab8b0a (patch)
tree4584afffa853e882fe3440a6e7f481d15f5ea5e7 /src/main/kotlin/gui/config
parenta9a801048d694e5b250f3a23089075e9b7bd976c (diff)
downloadFirmament-856f5e0e815c8ef3be77ef342e1b0ca91aab8b0a.tar.gz
Firmament-856f5e0e815c8ef3be77ef342e1b0ca91aab8b0a.tar.bz2
Firmament-856f5e0e815c8ef3be77ef342e1b0ca91aab8b0a.zip
fix: Add choice options to YACL integration
Diffstat (limited to 'src/main/kotlin/gui/config')
-rw-r--r--src/main/kotlin/gui/config/ChoiceHandler.kt1
-rw-r--r--src/main/kotlin/gui/config/ManagedConfig.kt6
2 files changed, 4 insertions, 3 deletions
diff --git a/src/main/kotlin/gui/config/ChoiceHandler.kt b/src/main/kotlin/gui/config/ChoiceHandler.kt
index 25e885a..2ea3efc 100644
--- a/src/main/kotlin/gui/config/ChoiceHandler.kt
+++ b/src/main/kotlin/gui/config/ChoiceHandler.kt
@@ -13,6 +13,7 @@ import moe.nea.firmament.util.ErrorUtil
import moe.nea.firmament.util.json.KJsonOps
class ChoiceHandler<E>(
+ val enumClass: Class<E>,
val universe: List<E>,
) : ManagedConfig.OptionHandler<E> where E : Enum<E>, E : StringIdentifiable {
val codec = StringIdentifiable.createCodec {
diff --git a/src/main/kotlin/gui/config/ManagedConfig.kt b/src/main/kotlin/gui/config/ManagedConfig.kt
index ea55f67..641b673 100644
--- a/src/main/kotlin/gui/config/ManagedConfig.kt
+++ b/src/main/kotlin/gui/config/ManagedConfig.kt
@@ -118,17 +118,17 @@ abstract class ManagedConfig(
protected fun <E> choice(
propertyName: String,
- universe: List<E>,
+ enumClass: Class<E>,
default: () -> E
): ManagedOption<E> where E : Enum<E>, E : StringIdentifiable {
- return option(propertyName, default, ChoiceHandler(universe))
+ return option(propertyName, default, ChoiceHandler(enumClass, enumClass.enumConstants.toList()))
}
protected inline fun <reified E> choice(
propertyName: String,
noinline default: () -> E
): ManagedOption<E> where E : Enum<E>, E : StringIdentifiable {
- return choice(propertyName, enumEntries<E>(), default)
+ return choice(propertyName, E::class.java, default)
}
private fun <E> createStringIdentifiable(x: () -> Array<out E>): Codec<E> where E : Enum<E>, E : StringIdentifiable {