diff options
author | Linnea Gräf <nea@nea.moe> | 2024-08-31 11:59:47 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-08-31 11:59:47 +0200 |
commit | 816f80f862d2f5de6bc9b0ae84cd6df0da341228 (patch) | |
tree | ee8aaccbaebe5a024549c2530319ed09a02cc4e4 /src/main/kotlin | |
parent | d2f240ff0ca0d27f417f837e706c781a98c31311 (diff) | |
download | firmament-816f80f862d2f5de6bc9b0ae84cd6df0da341228.tar.gz firmament-816f80f862d2f5de6bc9b0ae84cd6df0da341228.tar.bz2 firmament-816f80f862d2f5de6bc9b0ae84cd6df0da341228.zip |
Add configured compat
[no changelog]
Diffstat (limited to 'src/main/kotlin')
4 files changed, 50 insertions, 4 deletions
diff --git a/src/main/kotlin/gui/config/AllConfigsGui.kt b/src/main/kotlin/gui/config/AllConfigsGui.kt index 4f7731c..3091b2a 100644 --- a/src/main/kotlin/gui/config/AllConfigsGui.kt +++ b/src/main/kotlin/gui/config/AllConfigsGui.kt @@ -1,5 +1,3 @@ - - package moe.nea.firmament.gui.config import io.github.notenoughupdates.moulconfig.observer.ObservableList @@ -36,10 +34,16 @@ object AllConfigsGui { } } - fun makeScreen(parent: Screen? = null): Screen { + fun makeBuiltInScreen(parent: Screen? = null): Screen { return MoulConfigUtils.loadScreen("config/main", MainMapping(allConfigs), parent) } + fun makeScreen(parent: Screen? = null): Screen { + val provider = FirmamentConfigScreenProvider.providers.find { it.key == "builtin" } + ?: FirmamentConfigScreenProvider.providers.first() + return provider.open(parent) + } + fun showAllGuis() { setScreenLater(makeScreen()) } diff --git a/src/main/kotlin/gui/config/BuiltInConfigScreenProvider.kt b/src/main/kotlin/gui/config/BuiltInConfigScreenProvider.kt new file mode 100644 index 0000000..19e7383 --- /dev/null +++ b/src/main/kotlin/gui/config/BuiltInConfigScreenProvider.kt @@ -0,0 +1,14 @@ +package moe.nea.firmament.gui.config + +import com.google.auto.service.AutoService +import net.minecraft.client.gui.screen.Screen + +@AutoService(FirmamentConfigScreenProvider::class) +class BuiltInConfigScreenProvider : FirmamentConfigScreenProvider { + override val key: String + get() = "builtin" + + override fun open(parent: Screen?): Screen { + return AllConfigsGui.makeBuiltInScreen(parent) + } +} diff --git a/src/main/kotlin/gui/config/FirmamentConfigScreenProvider.kt b/src/main/kotlin/gui/config/FirmamentConfigScreenProvider.kt new file mode 100644 index 0000000..582f701 --- /dev/null +++ b/src/main/kotlin/gui/config/FirmamentConfigScreenProvider.kt @@ -0,0 +1,27 @@ +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 + +interface FirmamentConfigScreenProvider { + val key: String + val isEnabled: Boolean get() = true + + fun open(parent: Screen?): Screen + + companion object { + private val loader = ServiceLoader.load(FirmamentConfigScreenProvider::class.java) + + 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 }.toList() + } + } +} diff --git a/src/main/kotlin/gui/config/ManagedConfig.kt b/src/main/kotlin/gui/config/ManagedConfig.kt index aa6e3c8..0d942e2 100644 --- a/src/main/kotlin/gui/config/ManagedConfig.kt +++ b/src/main/kotlin/gui/config/ManagedConfig.kt @@ -145,7 +145,8 @@ abstract class ManagedConfig(override val name: String) : ManagedConfigElement() latestGuiAppender?.reloadables?.forEach { it() } } - val labelText = Text.translatable("firmament.config.${name}") + val translationKey get() = "firmament.config.${name}" + val labelText = Text.translatable(translationKey) fun getConfigEditor(parent: Screen? = null): Screen { var screen: Screen? = null |