diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-17 17:45:29 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-17 17:45:29 +0100 |
commit | e00c21b2ade870c94b2641d24bf75ca15f81b044 (patch) | |
tree | cdf8e5564027891ad62b299aaf1b71628af75b9d | |
parent | 7c4205a07cd720af7660672c129607d2dcf1b1e7 (diff) | |
download | Firmament-e00c21b2ade870c94b2641d24bf75ca15f81b044.tar.gz Firmament-e00c21b2ade870c94b2641d24bf75ca15f81b044.tar.bz2 Firmament-e00c21b2ade870c94b2641d24bf75ca15f81b044.zip |
fix: MoulConfig options sometimes not saving
-rw-r--r-- | src/compat/moulconfig/java/MCConfigEditorIntegration.kt | 67 | ||||
-rw-r--r-- | src/compat/moulconfig/java/ProcessedEditableOptionFirm.kt | 17 | ||||
-rw-r--r-- | src/main/kotlin/gui/config/KeyBindingHandler.kt | 6 |
3 files changed, 48 insertions, 42 deletions
diff --git a/src/compat/moulconfig/java/MCConfigEditorIntegration.kt b/src/compat/moulconfig/java/MCConfigEditorIntegration.kt index f1e7a98..20a79a8 100644 --- a/src/compat/moulconfig/java/MCConfigEditorIntegration.kt +++ b/src/compat/moulconfig/java/MCConfigEditorIntegration.kt @@ -122,17 +122,16 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { return GuiOptionEditorBoolean(this, -1, configObject) } - override fun get(): Any { - return managedOption.value + override fun toT(any: Any?): Boolean? { + return any as Boolean } override fun getType(): Type { return Boolean::class.java } - override fun set(value: Any?): Boolean { - managedOption.value = value as Boolean - return true + override fun fromT(t: Boolean): Any { + return t } } } @@ -142,17 +141,16 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { return GuiOptionEditorText(this) } - override fun get(): Any { - return managedOption.value - } - override fun getType(): Type { return String::class.java } - override fun set(value: Any?): Boolean { - managedOption.value = value as String - return true + override fun fromT(t: String): Any { + return t + } + + override fun toT(any: Any?): String? { + return any as String } } } @@ -162,18 +160,17 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { return GuiOptionEditorButton(this, -1, "Click", configObject) } - override fun get(): Any { + override fun toT(any: Any?): Unit? { + return null + } + + override fun fromT(t: Unit): Any { return Runnable { handler.runnable() } } override fun getType(): Type { return Runnable::class.java } - - override fun set(value: Any?): Boolean { - ErrorUtil.softError("Trying to set a buttons data") - return false - } } } register(HudMetaHandler::class.java) { handler, option, categoryAccordionId, configObject -> @@ -182,20 +179,18 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { return GuiOptionEditorButton(this, -1, "Edit HUD", configObject) } - override fun get(): Any { + override fun fromT(t: HudMeta): Any { return Runnable { handler.openEditor(option, MC.screen!!) } } + override fun getType(): Type { return Runnable::class.java } - override fun set(value: Any?): Boolean { - ErrorUtil.softError("Trying to assign to a hud meta") - return false - } + override fun toT(any: Any?): HudMeta? = null } } register(DurationHandler::class.java) { handler, option, categoryAccordionId, configObject -> @@ -213,7 +208,8 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { ) } - override fun get(): Any { + override fun toT(any: Any?): Duration? = null + override fun fromT(t: Duration): Any { ErrorUtil.softError("Getting on a slider component") return Unit } @@ -222,10 +218,6 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { return Nothing::class.java } - override fun set(value: Any?): Boolean { - ErrorUtil.softError("Setting on a slider component") - return false - } } } register(IntegerHandler::class.java) { handler, option, categoryAccordionId, configObject -> @@ -243,7 +235,8 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { ) } - override fun get(): Any { + override fun toT(any: Any?): Int? = null + override fun fromT(t: Int): Any { ErrorUtil.softError("Getting on a slider component") return Unit } @@ -251,11 +244,6 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { override fun getType(): Type { return Nothing::class.java } - - override fun set(value: Any?): Boolean { - ErrorUtil.softError("Setting on a slider component") - return false - } } } register(KeyBindingHandler::class.java) { handler, option, categoryAccordionId, configObject -> @@ -269,18 +257,17 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { } } - override fun get(): Any { - ErrorUtil.softError("Getting on a keybinding") - return Unit + override fun toT(any: Any?): SavedKeyBinding? { + return null } override fun getType(): Type { return Nothing::class.java } - override fun set(value: Any?): Boolean { - ErrorUtil.softError("Setting on a keybinding") - return false + override fun fromT(t: SavedKeyBinding): Any { + ErrorUtil.softError("Cannot get a keybinding editor") + return Unit } } } diff --git a/src/compat/moulconfig/java/ProcessedEditableOptionFirm.kt b/src/compat/moulconfig/java/ProcessedEditableOptionFirm.kt index 2bc5cd4..f0e9aa4 100644 --- a/src/compat/moulconfig/java/ProcessedEditableOptionFirm.kt +++ b/src/compat/moulconfig/java/ProcessedEditableOptionFirm.kt @@ -2,6 +2,7 @@ package moe.nea.firmament.compat.moulconfig import io.github.notenoughupdates.moulconfig.Config import moe.nea.firmament.gui.config.ManagedOption +import moe.nea.firmament.util.ErrorUtil abstract class ProcessedEditableOptionFirm<T : Any>( val managedOption: ManagedOption<T>, @@ -21,6 +22,22 @@ abstract class ProcessedEditableOptionFirm<T : Any>( return managedOption.labelDescription.string } + abstract fun fromT(t: T): Any + abstract fun toT(any: Any?): T? + + final override fun get(): Any { + return fromT(managedOption.value) + } + + final override fun set(p0: Any?): Boolean { + managedOption.value = toT(p0) ?: run { + ErrorUtil.softError("Failed to set value p0 in $this") + return false + } + managedConfig.save() + return true + } + override fun explicitNotifyChange() { managedConfig.save() } diff --git a/src/main/kotlin/gui/config/KeyBindingHandler.kt b/src/main/kotlin/gui/config/KeyBindingHandler.kt index 0cf0c46..d7d0b47 100644 --- a/src/main/kotlin/gui/config/KeyBindingHandler.kt +++ b/src/main/kotlin/gui/config/KeyBindingHandler.kt @@ -6,7 +6,6 @@ import io.github.notenoughupdates.moulconfig.deps.libninepatch.NinePatch import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext import io.github.notenoughupdates.moulconfig.gui.KeyboardEvent import io.github.notenoughupdates.moulconfig.gui.component.TextComponent -import org.lwjgl.glfw.GLFW import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.decodeFromJsonElement @@ -34,7 +33,10 @@ class KeyBindingHandler(val name: String, val managedConfig: ManagedConfig) : lateinit var button: FirmButtonComponent val sm = KeyBindingStateManager( { opt.value }, - { opt.value = it }, + { + opt.value = it + opt.element.save() + }, { button.blur() }, { button.requestFocus() } ) |