aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gradle.properties3
-rw-r--r--src/compat/yacl/java/YaclIntegration.kt29
-rw-r--r--src/main/kotlin/features/mining/PickaxeAbility.kt1
-rw-r--r--src/main/kotlin/gui/config/ChoiceHandler.kt1
-rw-r--r--src/main/kotlin/gui/config/ManagedConfig.kt6
5 files changed, 36 insertions, 4 deletions
diff --git a/gradle.properties b/gradle.properties
index ec779d5..2385103 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -10,3 +10,6 @@ archives_base_name=Firmament
maven_group=moe.nea.firmament
firmament.compiletimerepohash=a6116d945491d7c57c93d43f51250f93d62d8434
+
+# TODO: remove after https://github.com/google/ksp/issues/2072
+ksp.incremental=false
diff --git a/src/compat/yacl/java/YaclIntegration.kt b/src/compat/yacl/java/YaclIntegration.kt
index 9aec501..45a0d02 100644
--- a/src/compat/yacl/java/YaclIntegration.kt
+++ b/src/compat/yacl/java/YaclIntegration.kt
@@ -11,9 +11,11 @@ import dev.isxander.yacl3.api.OptionGroup
import dev.isxander.yacl3.api.YetAnotherConfigLib
import dev.isxander.yacl3.api.controller.ControllerBuilder
import dev.isxander.yacl3.api.controller.DoubleSliderControllerBuilder
+import dev.isxander.yacl3.api.controller.EnumControllerBuilder
import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder
import dev.isxander.yacl3.api.controller.StringControllerBuilder
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder
+import dev.isxander.yacl3.api.controller.ValueFormatter
import dev.isxander.yacl3.gui.YACLScreen
import dev.isxander.yacl3.gui.tab.ListHolderWidget
import kotlin.time.Duration
@@ -23,8 +25,10 @@ import net.minecraft.client.gui.Element
import net.minecraft.client.gui.screen.Screen
import net.minecraft.text.Text
import moe.nea.firmament.gui.config.BooleanHandler
+import moe.nea.firmament.gui.config.ChoiceHandler
import moe.nea.firmament.gui.config.ClickHandler
import moe.nea.firmament.gui.config.DurationHandler
+import moe.nea.firmament.gui.config.EnumRenderer
import moe.nea.firmament.gui.config.FirmamentConfigScreenProvider
import moe.nea.firmament.gui.config.HudMeta
import moe.nea.firmament.gui.config.HudMetaHandler
@@ -89,6 +93,10 @@ class YaclIntegration : FirmamentConfigScreenProvider {
}
.build()
+ is ChoiceHandler<*> -> return createDefaultBinding {
+ createChoiceBinding(handler as ChoiceHandler<*>, managedOption as ManagedOption<*>, it as Option<*>)
+ }.build()
+
is BooleanHandler -> return createDefaultBinding(TickBoxControllerBuilder::create).build()
is StringHandler -> return createDefaultBinding(StringControllerBuilder::create).build()
is IntegerHandler -> return createDefaultBinding {
@@ -114,6 +122,27 @@ class YaclIntegration : FirmamentConfigScreenProvider {
}
}
+ private enum class Sacrifice {}
+
+ private fun createChoiceBinding(
+ handler: ChoiceHandler<*>,
+ managedOption: ManagedOption<*>,
+ option: Option<*>
+ ): ControllerBuilder<Any> {
+ val b = EnumControllerBuilder.create(option as Option<Sacrifice>)
+ b.enumClass(handler.enumClass as Class<Sacrifice>)
+ /**
+ * This is a function with E to avoid realizing the Sacrifice outside of a `X<E>` wrapper.
+ */
+ fun <E : Enum<*>> makeValueFormatter(): ValueFormatter<E> {
+ return ValueFormatter<E> {
+ (handler.renderer as EnumRenderer<E>).getName(managedOption as ManagedOption<E>, it)
+ }
+ }
+ b.formatValue(makeValueFormatter())
+ return b as ControllerBuilder<Any>
+ }
+
fun buildConfig(): YetAnotherConfigLib {
return YetAnotherConfigLib.createBuilder()
diff --git a/src/main/kotlin/features/mining/PickaxeAbility.kt b/src/main/kotlin/features/mining/PickaxeAbility.kt
index a184c81..94b49f9 100644
--- a/src/main/kotlin/features/mining/PickaxeAbility.kt
+++ b/src/main/kotlin/features/mining/PickaxeAbility.kt
@@ -50,7 +50,6 @@ object PickaxeAbility : FirmamentFeature {
val drillFuelBar by toggle("fuel-bar") { true }
val blockOnPrivateIsland by choice(
"block-on-dynamic",
- BlockPickaxeAbility.entries,
) {
BlockPickaxeAbility.ONLY_DESTRUCTIVE
}
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 {