From 856f5e0e815c8ef3be77ef342e1b0ca91aab8b0a Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sun, 22 Dec 2024 16:08:31 +0100 Subject: fix: Add choice options to YACL integration --- src/main/kotlin/gui/config/ChoiceHandler.kt | 1 + src/main/kotlin/gui/config/ManagedConfig.kt | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/main/kotlin/gui/config') 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( + val enumClass: Class, val universe: List, ) : ManagedConfig.OptionHandler where E : Enum, 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 choice( propertyName: String, - universe: List, + enumClass: Class, default: () -> E ): ManagedOption where E : Enum, E : StringIdentifiable { - return option(propertyName, default, ChoiceHandler(universe)) + return option(propertyName, default, ChoiceHandler(enumClass, enumClass.enumConstants.toList())) } protected inline fun choice( propertyName: String, noinline default: () -> E ): ManagedOption where E : Enum, E : StringIdentifiable { - return choice(propertyName, enumEntries(), default) + return choice(propertyName, E::class.java, default) } private fun createStringIdentifiable(x: () -> Array): Codec where E : Enum, E : StringIdentifiable { -- cgit