fix: MoulConfig options sometimes not saving
This commit is contained in:
@@ -122,17 +122,16 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
|
|||||||
return GuiOptionEditorBoolean(this, -1, configObject)
|
return GuiOptionEditorBoolean(this, -1, configObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(): Any {
|
override fun toT(any: Any?): Boolean? {
|
||||||
return managedOption.value
|
return any as Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getType(): Type {
|
override fun getType(): Type {
|
||||||
return Boolean::class.java
|
return Boolean::class.java
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun set(value: Any?): Boolean {
|
override fun fromT(t: Boolean): Any {
|
||||||
managedOption.value = value as Boolean
|
return t
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,17 +141,16 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
|
|||||||
return GuiOptionEditorText(this)
|
return GuiOptionEditorText(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(): Any {
|
|
||||||
return managedOption.value
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getType(): Type {
|
override fun getType(): Type {
|
||||||
return String::class.java
|
return String::class.java
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun set(value: Any?): Boolean {
|
override fun fromT(t: String): Any {
|
||||||
managedOption.value = value as String
|
return t
|
||||||
return true
|
}
|
||||||
|
|
||||||
|
override fun toT(any: Any?): String? {
|
||||||
|
return any as String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,18 +160,17 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
|
|||||||
return GuiOptionEditorButton(this, -1, "Click", configObject)
|
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() }
|
return Runnable { handler.runnable() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getType(): Type {
|
override fun getType(): Type {
|
||||||
return Runnable::class.java
|
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 ->
|
register(HudMetaHandler::class.java) { handler, option, categoryAccordionId, configObject ->
|
||||||
@@ -182,20 +179,18 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
|
|||||||
return GuiOptionEditorButton(this, -1, "Edit HUD", configObject)
|
return GuiOptionEditorButton(this, -1, "Edit HUD", configObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(): Any {
|
override fun fromT(t: HudMeta): Any {
|
||||||
return Runnable {
|
return Runnable {
|
||||||
handler.openEditor(option, MC.screen!!)
|
handler.openEditor(option, MC.screen!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun getType(): Type {
|
override fun getType(): Type {
|
||||||
return Runnable::class.java
|
return Runnable::class.java
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun set(value: Any?): Boolean {
|
override fun toT(any: Any?): HudMeta? = null
|
||||||
ErrorUtil.softError("Trying to assign to a hud meta")
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
register(DurationHandler::class.java) { handler, option, categoryAccordionId, configObject ->
|
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")
|
ErrorUtil.softError("Getting on a slider component")
|
||||||
return Unit
|
return Unit
|
||||||
}
|
}
|
||||||
@@ -222,10 +218,6 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
|
|||||||
return Nothing::class.java
|
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 ->
|
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")
|
ErrorUtil.softError("Getting on a slider component")
|
||||||
return Unit
|
return Unit
|
||||||
}
|
}
|
||||||
@@ -251,11 +244,6 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
|
|||||||
override fun getType(): Type {
|
override fun getType(): Type {
|
||||||
return Nothing::class.java
|
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 ->
|
register(KeyBindingHandler::class.java) { handler, option, categoryAccordionId, configObject ->
|
||||||
@@ -269,18 +257,17 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(): Any {
|
override fun toT(any: Any?): SavedKeyBinding? {
|
||||||
ErrorUtil.softError("Getting on a keybinding")
|
return null
|
||||||
return Unit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getType(): Type {
|
override fun getType(): Type {
|
||||||
return Nothing::class.java
|
return Nothing::class.java
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun set(value: Any?): Boolean {
|
override fun fromT(t: SavedKeyBinding): Any {
|
||||||
ErrorUtil.softError("Setting on a keybinding")
|
ErrorUtil.softError("Cannot get a keybinding editor")
|
||||||
return false
|
return Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package moe.nea.firmament.compat.moulconfig
|
|||||||
|
|
||||||
import io.github.notenoughupdates.moulconfig.Config
|
import io.github.notenoughupdates.moulconfig.Config
|
||||||
import moe.nea.firmament.gui.config.ManagedOption
|
import moe.nea.firmament.gui.config.ManagedOption
|
||||||
|
import moe.nea.firmament.util.ErrorUtil
|
||||||
|
|
||||||
abstract class ProcessedEditableOptionFirm<T : Any>(
|
abstract class ProcessedEditableOptionFirm<T : Any>(
|
||||||
val managedOption: ManagedOption<T>,
|
val managedOption: ManagedOption<T>,
|
||||||
@@ -21,6 +22,22 @@ abstract class ProcessedEditableOptionFirm<T : Any>(
|
|||||||
return managedOption.labelDescription.string
|
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() {
|
override fun explicitNotifyChange() {
|
||||||
managedConfig.save()
|
managedConfig.save()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.GuiImmediateContext
|
||||||
import io.github.notenoughupdates.moulconfig.gui.KeyboardEvent
|
import io.github.notenoughupdates.moulconfig.gui.KeyboardEvent
|
||||||
import io.github.notenoughupdates.moulconfig.gui.component.TextComponent
|
import io.github.notenoughupdates.moulconfig.gui.component.TextComponent
|
||||||
import org.lwjgl.glfw.GLFW
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.JsonElement
|
import kotlinx.serialization.json.JsonElement
|
||||||
import kotlinx.serialization.json.decodeFromJsonElement
|
import kotlinx.serialization.json.decodeFromJsonElement
|
||||||
@@ -34,7 +33,10 @@ class KeyBindingHandler(val name: String, val managedConfig: ManagedConfig) :
|
|||||||
lateinit var button: FirmButtonComponent
|
lateinit var button: FirmButtonComponent
|
||||||
val sm = KeyBindingStateManager(
|
val sm = KeyBindingStateManager(
|
||||||
{ opt.value },
|
{ opt.value },
|
||||||
{ opt.value = it },
|
{
|
||||||
|
opt.value = it
|
||||||
|
opt.element.save()
|
||||||
|
},
|
||||||
{ button.blur() },
|
{ button.blur() },
|
||||||
{ button.requestFocus() }
|
{ button.requestFocus() }
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user