aboutsummaryrefslogtreecommitdiff
path: root/src/compat
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-10-13 21:46:46 +0200
committerLinnea Gräf <nea@nea.moe>2024-10-13 21:46:46 +0200
commit4e9b0ded27df8b6ce7f5b2fa1b4b1ddbc1cbd452 (patch)
treea489fdd97e6c4dde1bd77bf216ed9c2ec2657db3 /src/compat
parent0cc77949c907d38497f8cdf6fd8198fe5f0a9440 (diff)
downloadFirmament-4e9b0ded27df8b6ce7f5b2fa1b4b1ddbc1cbd452.tar.gz
Firmament-4e9b0ded27df8b6ce7f5b2fa1b4b1ddbc1cbd452.tar.bz2
Firmament-4e9b0ded27df8b6ce7f5b2fa1b4b1ddbc1cbd452.zip
Add config categories
Diffstat (limited to 'src/compat')
-rw-r--r--src/compat/configured/java/BaseConfigNode.kt5
-rw-r--r--src/compat/configured/java/ConfiguredCompat.kt3
-rw-r--r--src/compat/yacl/java/YaclIntegration.kt24
3 files changed, 21 insertions, 11 deletions
diff --git a/src/compat/configured/java/BaseConfigNode.kt b/src/compat/configured/java/BaseConfigNode.kt
index 7330990..afe0375 100644
--- a/src/compat/configured/java/BaseConfigNode.kt
+++ b/src/compat/configured/java/BaseConfigNode.kt
@@ -4,11 +4,12 @@ import com.mrcrayfish.configured.api.IConfigEntry
import com.mrcrayfish.configured.api.IConfigValue
import net.minecraft.text.Text
import moe.nea.firmament.gui.config.AllConfigsGui
+import moe.nea.firmament.gui.config.ManagedConfig
object BaseConfigNode : IConfigEntry {
override fun getChildren(): List<IConfigEntry> {
- return AllConfigsGui.allConfigs.map {
- ConfigNode(it)
+ return ManagedConfig.allManagedConfigs.getAll().map {
+ ConfigNode(it) // TODO: fix add categories here
}
}
diff --git a/src/compat/configured/java/ConfiguredCompat.kt b/src/compat/configured/java/ConfiguredCompat.kt
index a5b78bb..8e8b022 100644
--- a/src/compat/configured/java/ConfiguredCompat.kt
+++ b/src/compat/configured/java/ConfiguredCompat.kt
@@ -6,6 +6,7 @@ import com.mrcrayfish.configured.api.IModConfigProvider
import com.mrcrayfish.configured.api.ModContext
import moe.nea.firmament.Firmament
import moe.nea.firmament.gui.config.AllConfigsGui
+import moe.nea.firmament.gui.config.ManagedConfig
/**
* Registered in `fabric.mod.json` at `custom.configured.providers`
@@ -23,7 +24,7 @@ class ConfiguredCompat : IModConfigProvider {
return "firmament.config.all-configs"
}
})
- AllConfigsGui.allConfigs.mapTo(this) { ConfigCategory(it) }
+ ManagedConfig.allManagedConfigs.getAll().mapTo(this) { ConfigCategory(it) }
}
}
}
diff --git a/src/compat/yacl/java/YaclIntegration.kt b/src/compat/yacl/java/YaclIntegration.kt
index 6c9354a..fc5ff59 100644
--- a/src/compat/yacl/java/YaclIntegration.kt
+++ b/src/compat/yacl/java/YaclIntegration.kt
@@ -6,6 +6,7 @@ import dev.isxander.yacl3.api.ButtonOption
import dev.isxander.yacl3.api.ConfigCategory
import dev.isxander.yacl3.api.LabelOption
import dev.isxander.yacl3.api.Option
+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
@@ -17,7 +18,6 @@ import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
import net.minecraft.client.gui.screen.Screen
import net.minecraft.text.Text
-import moe.nea.firmament.gui.config.AllConfigsGui
import moe.nea.firmament.gui.config.BooleanHandler
import moe.nea.firmament.gui.config.ClickHandler
import moe.nea.firmament.gui.config.DurationHandler
@@ -36,15 +36,20 @@ import moe.nea.firmament.util.FirmFormatters
@AutoService(FirmamentConfigScreenProvider::class)
class YaclIntegration : FirmamentConfigScreenProvider {
fun buildCategories() =
- AllConfigsGui.allConfigs
+ ManagedConfig.Category.entries
.map(::buildCategory)
- private fun buildCategory(managedConfig: ManagedConfig): ConfigCategory {
+ private fun buildCategory(category: ManagedConfig.Category): ConfigCategory {
return ConfigCategory.createBuilder()
- .name(managedConfig.labelText)
- .also {
- it.rootGroupBuilder()
- .options(buildOptions(managedConfig.sortedOptions))
+ .name(category.labelText)
+ .also { categoryB ->
+ category.configs.forEach {
+ categoryB.group(
+ OptionGroup.createBuilder()
+ .name(it.labelText)
+ .options(buildOptions(it.sortedOptions))
+ .build())
+ }
}
.build()
}
@@ -54,7 +59,10 @@ class YaclIntegration : FirmamentConfigScreenProvider {
private fun <T : Any> buildOption(managedOption: ManagedOption<T>): Option<*> {
val handler = managedOption.handler
- val binding = Binding.generic(managedOption.default(), managedOption::value, managedOption::value.setter)
+ val binding = Binding.generic(managedOption.default(),
+ managedOption::value,
+ { managedOption.value = it; managedOption.element.save() })
+
fun <T> createDefaultBinding(function: (Option<T>) -> ControllerBuilder<T>): Option.Builder<T> {
return Option.createBuilder<T>()
.name(managedOption.labelText)