From 904c0ac83152f563bb1492c8f262cfe692c9d04f Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 26 Mar 2022 11:00:38 +0100 Subject: [PATCH] Only save buttons which can be toggled Signed-off-by: Username404 --- .../fr/username404/snowygui/config/Configuration.kt | 9 +++++++-- .../fr/username404/snowygui/gui/feature/ButtonImpl.kt | 2 +- .../fr/username404/snowygui/gui/feature/ButtonInfo.kt | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt index a1ed85c..9ae3043 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt @@ -11,6 +11,7 @@ import com.typesafe.config.ConfigValueFactory import fr.username404.snowygui.ClickGui import fr.username404.snowygui.Snowy import fr.username404.snowygui.Snowy.Companion.MissingComponent +import fr.username404.snowygui.gui.feature.shouldSave import fr.username404.snowygui.gui.feature.Category import fr.username404.snowygui.gui.feature.Macro import io.github.config4k.extract @@ -84,7 +85,11 @@ object Configuration { val enabledFeatures = mutableMapOf().apply { "enabledFeatures".let { obtained.run { if (hasPath(it)) { - putAll(extract(it)) + putAll(extract>(it).filterKeys { keyName -> ClickGui.clickBoxes.any { + it.buttons.any { button -> + button.info.shouldSave() && button.title == keyName + } + }}) } } } } @@ -98,7 +103,7 @@ object Configuration { Thread { runBlocking { ClickGui.boxContext { - enabledFeatures.putAll(buttons.filter { it.info.shouldSave }.map { + enabledFeatures.putAll(buttons.filter { it.info.shouldSave() }.map { it.title to it.toggled }) } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt index c7f534a..27e9670 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt @@ -17,7 +17,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { buttons.groupBy { impl -> ClickGui.clickBoxes.find { box -> with(impl) { - if (info.shouldSave && info.kind == Type.TOGGLE && !info.parent.shouldHide) { + if (info.shouldSave() && !info.parent.shouldHide) { Configuration.enabledFeatures[title]?.let { bool -> toggled = bool } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt index 99a39c9..2e89b7f 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt @@ -12,6 +12,7 @@ import net.minecraft.network.chat.TranslatableComponent annotation class ButtonInfo( val parent: Category, val kind: Type = Type.TOGGLE, + @Deprecated("Use shouldSave() instead", level = DeprecationLevel.ERROR) val shouldSave: Boolean = true, /** Whether or not the state of the button should be saved */ val ignored: Boolean = false /** Excludes a class from button collection */ ) { @@ -53,4 +54,6 @@ annotation class ButtonInfo( } } +fun ButtonInfo.shouldSave(): Boolean = @Suppress("DEPRECATION_ERROR") shouldSave && kind == ButtonInfo.Companion.Type.TOGGLE + typealias Category = ButtonInfo.Companion.Category \ No newline at end of file