diff options
Diffstat (limited to 'src/main/kotlin/gui')
-rw-r--r-- | src/main/kotlin/gui/config/ManagedConfig.kt | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main/kotlin/gui/config/ManagedConfig.kt b/src/main/kotlin/gui/config/ManagedConfig.kt index 47a9c92..ea55f67 100644 --- a/src/main/kotlin/gui/config/ManagedConfig.kt +++ b/src/main/kotlin/gui/config/ManagedConfig.kt @@ -15,6 +15,7 @@ import org.lwjgl.glfw.GLFW import kotlinx.serialization.encodeToString import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject +import kotlin.enums.enumEntries import kotlin.io.path.createDirectories import kotlin.io.path.readText import kotlin.io.path.writeText @@ -123,6 +124,17 @@ abstract class ManagedConfig( return option(propertyName, default, ChoiceHandler(universe)) } + 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) + } + + private fun <E> createStringIdentifiable(x: () -> Array<out E>): Codec<E> where E : Enum<E>, E : StringIdentifiable { + return StringIdentifiable.createCodec { x() } + } + // TODO: wait on https://youtrack.jetbrains.com/issue/KT-73434 // protected inline fun <reified E> choice( // propertyName: String, |