Only save buttons which can be toggled
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
bd02e2c1e7
commit
904c0ac831
|
@ -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<String, Boolean>().apply {
|
||||
"enabledFeatures".let { obtained.run {
|
||||
if (hasPath(it)) {
|
||||
putAll(extract(it))
|
||||
putAll(extract<Map<out String, Boolean>>(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
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue