aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/gui/config/AllConfigsGui.kt8
-rw-r--r--src/main/kotlin/gui/config/FirmamentConfigScreenProvider.kt17
-rw-r--r--src/main/kotlin/gui/config/KeyBindingHandler.kt8
-rw-r--r--src/main/kotlin/gui/config/ManagedConfig.kt2
-rw-r--r--src/main/kotlin/util/MoulConfigUtils.kt13
5 files changed, 30 insertions, 18 deletions
diff --git a/src/main/kotlin/gui/config/AllConfigsGui.kt b/src/main/kotlin/gui/config/AllConfigsGui.kt
index 0e68bc8..16eb0a4 100644
--- a/src/main/kotlin/gui/config/AllConfigsGui.kt
+++ b/src/main/kotlin/gui/config/AllConfigsGui.kt
@@ -4,7 +4,6 @@ import io.github.notenoughupdates.moulconfig.observer.ObservableList
import io.github.notenoughupdates.moulconfig.xml.Bind
import net.minecraft.client.gui.screen.Screen
import net.minecraft.text.Text
-import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.MoulConfigUtils
import moe.nea.firmament.util.ScreenUtil.setScreenLater
@@ -18,6 +17,7 @@ object AllConfigsGui {
object ConfigConfig : ManagedConfig("configconfig", Category.META) {
val enableYacl by toggle("enable-yacl") { false }
+ val enableMoulConfig by toggle("enable-moulconfig") { false }
}
fun <T> List<T>.toObservableList(): ObservableList<T> = ObservableList(this)
@@ -67,7 +67,11 @@ object AllConfigsGui {
}
fun makeScreen(parent: Screen? = null): Screen {
- val wantedKey = if (ConfigConfig.enableYacl) "yacl" else "builtin"
+ val wantedKey = when {
+ ConfigConfig.enableMoulConfig -> "moulconfig"
+ ConfigConfig.enableYacl -> "yacl"
+ else -> "builtin"
+ }
val provider = FirmamentConfigScreenProvider.providers.find { it.key == wantedKey }
?: FirmamentConfigScreenProvider.providers.first()
return provider.open(parent)
diff --git a/src/main/kotlin/gui/config/FirmamentConfigScreenProvider.kt b/src/main/kotlin/gui/config/FirmamentConfigScreenProvider.kt
index 82e151e..5aaa5fa 100644
--- a/src/main/kotlin/gui/config/FirmamentConfigScreenProvider.kt
+++ b/src/main/kotlin/gui/config/FirmamentConfigScreenProvider.kt
@@ -1,9 +1,7 @@
package moe.nea.firmament.gui.config
-import java.util.ServiceLoader
-import kotlin.streams.asSequence
import net.minecraft.client.gui.screen.Screen
-import moe.nea.firmament.Firmament
+import moe.nea.firmament.util.compatloader.CompatLoader
interface FirmamentConfigScreenProvider {
val key: String
@@ -11,17 +9,10 @@ interface FirmamentConfigScreenProvider {
fun open(parent: Screen?): Screen
- companion object {
- private val loader = ServiceLoader.load(FirmamentConfigScreenProvider::class.java)
-
+ companion object : CompatLoader<FirmamentConfigScreenProvider>(FirmamentConfigScreenProvider::class) {
val providers by lazy {
- loader.stream().asSequence().mapNotNull { service ->
- kotlin.runCatching { service.get() }
- .getOrElse {
- Firmament.logger.warn("Could not load config provider ${service.type()}", it)
- null
- }
- }.filter { it.isEnabled }
+ allValidInstances
+ .filter { it.isEnabled }
.sortedWith(Comparator.comparing(
{ it.key },
Comparator<String> { left, right ->
diff --git a/src/main/kotlin/gui/config/KeyBindingHandler.kt b/src/main/kotlin/gui/config/KeyBindingHandler.kt
index 7ec7e81..0cf0c46 100644
--- a/src/main/kotlin/gui/config/KeyBindingHandler.kt
+++ b/src/main/kotlin/gui/config/KeyBindingHandler.kt
@@ -30,7 +30,7 @@ class KeyBindingHandler(val name: String, val managedConfig: ManagedConfig) :
return Json.decodeFromJsonElement(element)
}
- override fun emitGuiElements(opt: ManagedOption<SavedKeyBinding>, guiAppender: GuiAppender) {
+ fun createButtonComponent(opt: ManagedOption<SavedKeyBinding>): FirmButtonComponent {
lateinit var button: FirmButtonComponent
val sm = KeyBindingStateManager(
{ opt.value },
@@ -67,7 +67,11 @@ class KeyBindingHandler(val name: String, val managedConfig: ManagedConfig) :
}
}
sm.updateLabel()
- guiAppender.appendLabeledRow(opt.labelText, button)
+ return button
+ }
+
+ override fun emitGuiElements(opt: ManagedOption<SavedKeyBinding>, guiAppender: GuiAppender) {
+ guiAppender.appendLabeledRow(opt.labelText, createButtonComponent(opt))
}
}
diff --git a/src/main/kotlin/gui/config/ManagedConfig.kt b/src/main/kotlin/gui/config/ManagedConfig.kt
index 44c6e59..c8b6ce8 100644
--- a/src/main/kotlin/gui/config/ManagedConfig.kt
+++ b/src/main/kotlin/gui/config/ManagedConfig.kt
@@ -176,7 +176,7 @@ abstract class ManagedConfig(
}
val translationKey get() = "firmament.config.${name}"
- val labelText = Text.translatable(translationKey)
+ val labelText: Text = Text.translatable(translationKey)
fun getConfigEditor(parent: Screen? = null): Screen {
var screen: Screen? = null
diff --git a/src/main/kotlin/util/MoulConfigUtils.kt b/src/main/kotlin/util/MoulConfigUtils.kt
index 54528dd..2e52092 100644
--- a/src/main/kotlin/util/MoulConfigUtils.kt
+++ b/src/main/kotlin/util/MoulConfigUtils.kt
@@ -234,6 +234,19 @@ object MoulConfigUtils {
// TODO: move this utility into moulconfig (also rework guicontext into an interface so i can make this mesh better into vanilla)
fun GuiContext.adopt(element: GuiComponent) = element.foldRecursive(Unit, { comp, unit -> comp.context = this })
+ inline fun <T, R> GetSetter<T>.xmap(crossinline fromT: (T) -> R, crossinline toT: (R) -> T): GetSetter<R> {
+ val outer = this
+ return object : GetSetter<R> {
+ override fun get(): R {
+ return fromT(outer.get())
+ }
+
+ override fun set(newValue: R) {
+ outer.set(toT(newValue))
+ }
+ }
+ }
+
fun clickMCComponentInPlace(
component: GuiComponent,
x: Int,