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/compat | |
parent | d2f240ff0ca0d27f417f837e706c781a98c31311 (diff) | |
download | firmament-816f80f862d2f5de6bc9b0ae84cd6df0da341228.tar.gz firmament-816f80f862d2f5de6bc9b0ae84cd6df0da341228.tar.bz2 firmament-816f80f862d2f5de6bc9b0ae84cd6df0da341228.zip |
Add configured compat
[no changelog]
Diffstat (limited to 'src/compat')
-rw-r--r-- | src/compat/configured/java/BaseConfigNode.kt | 39 | ||||
-rw-r--r-- | src/compat/configured/java/ConfigCategory.kt | 48 | ||||
-rw-r--r-- | src/compat/configured/java/ConfigNode.kt | 39 | ||||
-rw-r--r-- | src/compat/configured/java/ConfigValue.kt | 72 | ||||
-rw-r--r-- | src/compat/configured/java/ConfigValueNode.kt | 37 | ||||
-rw-r--r-- | src/compat/configured/java/ConfiguredCompat.kt | 29 | ||||
-rw-r--r-- | src/compat/configured/java/ConfiguredConfigScreenProvider.kt | 22 | ||||
-rw-r--r-- | src/compat/sodium/java/SodiumChunkReloader.kt | 2 |
8 files changed, 288 insertions, 0 deletions
diff --git a/src/compat/configured/java/BaseConfigNode.kt b/src/compat/configured/java/BaseConfigNode.kt new file mode 100644 index 0000000..7330990 --- /dev/null +++ b/src/compat/configured/java/BaseConfigNode.kt @@ -0,0 +1,39 @@ +package moe.nea.firmament.compat.configured + +import com.mrcrayfish.configured.api.IConfigEntry +import com.mrcrayfish.configured.api.IConfigValue +import net.minecraft.text.Text +import moe.nea.firmament.gui.config.AllConfigsGui + +object BaseConfigNode : IConfigEntry { + override fun getChildren(): List<IConfigEntry> { + return AllConfigsGui.allConfigs.map { + ConfigNode(it) + } + } + + override fun isRoot(): Boolean { + return true + } + + override fun isLeaf(): Boolean { + return false + } + + override fun getValue(): IConfigValue<*>? { + return null + } + + override fun getEntryName(): String { + return "Firmament" + } + + override fun getTooltip(): Text? { + return null + } + + override fun getTranslationKey(): String? { + return null + } + +} diff --git a/src/compat/configured/java/ConfigCategory.kt b/src/compat/configured/java/ConfigCategory.kt new file mode 100644 index 0000000..4e33b8b --- /dev/null +++ b/src/compat/configured/java/ConfigCategory.kt @@ -0,0 +1,48 @@ +package moe.nea.firmament.compat.configured + +import com.mrcrayfish.configured.api.ConfigType +import com.mrcrayfish.configured.api.IConfigEntry +import com.mrcrayfish.configured.api.IModConfig +import com.mrcrayfish.configured.util.ConfigHelper +import java.nio.file.Path +import java.util.function.Consumer +import moe.nea.firmament.Firmament +import moe.nea.firmament.gui.config.ManagedConfig + +class ConfigCategory( + val category: ManagedConfig +) : BaseConfig() { + + override fun getRoot(): IConfigEntry { + return ConfigNode(category) + } + + override fun getTranslationKey(): String? { + return category.translationKey + } +} + +abstract class BaseConfig : IModConfig { + override fun update(p0: IConfigEntry) { + ConfigHelper.getChangedValues(p0).forEach { + it as ConfigValue + it.saveValue() + } + } + + override fun getType(): ConfigType { + return ConfigType.CLIENT + } + + override fun getFileName(): String { + return "" + } + + override fun getModId(): String { + return Firmament.MOD_ID + } + + override fun loadWorldConfig(p0: Path?, p1: Consumer<IModConfig>?) { + } + +} diff --git a/src/compat/configured/java/ConfigNode.kt b/src/compat/configured/java/ConfigNode.kt new file mode 100644 index 0000000..16e54a6 --- /dev/null +++ b/src/compat/configured/java/ConfigNode.kt @@ -0,0 +1,39 @@ +package moe.nea.firmament.compat.configured + +import com.mrcrayfish.configured.api.IConfigEntry +import com.mrcrayfish.configured.api.IConfigValue +import net.minecraft.text.Text +import moe.nea.firmament.gui.config.ManagedConfig + +class ConfigNode(val config: ManagedConfig) : IConfigEntry { + override fun getChildren(): List<IConfigEntry> { + return config.allOptions.map { + ConfigValueNode(it.value) + } + } + + override fun isRoot(): Boolean { + return false + } + + override fun isLeaf(): Boolean { + return false + } + + override fun getValue(): IConfigValue<*>? { + return null + } + + override fun getEntryName(): String { + return config.translationKey + } + + override fun getTooltip(): Text? { + return null + } + + override fun getTranslationKey(): String { + return config.translationKey + } + +} diff --git a/src/compat/configured/java/ConfigValue.kt b/src/compat/configured/java/ConfigValue.kt new file mode 100644 index 0000000..e16c51c --- /dev/null +++ b/src/compat/configured/java/ConfigValue.kt @@ -0,0 +1,72 @@ +package moe.nea.firmament.compat.configured + +import com.mrcrayfish.configured.api.IConfigValue +import net.minecraft.text.Text +import moe.nea.firmament.gui.config.ManagedOption + +class ConfigValue<T: Any>(val option: ManagedOption<T>) : IConfigValue<T> { + var value = option.get() + var initialValue = option.get() + + override fun get(): T { + return value + } + + override fun set(p0: T) { + this.value = p0 + } + + override fun getDefault(): T { + return option.default() + } + + override fun isDefault(): Boolean { + // TODO: should this be an option in handlers? + return option == option.default() + } + + override fun isChanged(): Boolean { + return value != initialValue + } + + override fun restore() { + this.value = option.default() + } + + override fun getComment(): Text? { + return null + } + + override fun getTranslationKey(): String? { + return option.rawLabelText + } + + override fun getValidationHint(): Text? { + return null + } + + override fun getName(): String { + return "" + } + + override fun cleanCache() { + + } + + override fun requiresWorldRestart(): Boolean { + return false + } + + override fun requiresGameRestart(): Boolean { + return false + } + + override fun isValid(p0: T): Boolean { + // TODO: should this be validated? + return true + } + + fun saveValue() { + option.set(value) + } +} diff --git a/src/compat/configured/java/ConfigValueNode.kt b/src/compat/configured/java/ConfigValueNode.kt new file mode 100644 index 0000000..df59739 --- /dev/null +++ b/src/compat/configured/java/ConfigValueNode.kt @@ -0,0 +1,37 @@ +package moe.nea.firmament.compat.configured + +import com.mrcrayfish.configured.api.IConfigEntry +import com.mrcrayfish.configured.api.IConfigValue +import net.minecraft.text.Text +import moe.nea.firmament.gui.config.ManagedOption + +class ConfigValueNode(val option: ManagedOption<*>) : IConfigEntry { + override fun getChildren(): List<IConfigEntry> { + return listOf() + } + + override fun isRoot(): Boolean { + return false + } + + override fun isLeaf(): Boolean { + return true + } + + val value = ConfigValue(option) + override fun getValue(): IConfigValue<*>? { + return value + } + + override fun getEntryName(): String { + return option.propertyName + } + + override fun getTooltip(): Text? { + return null + } + + override fun getTranslationKey(): String? { + return option.rawLabelText + } +} diff --git a/src/compat/configured/java/ConfiguredCompat.kt b/src/compat/configured/java/ConfiguredCompat.kt new file mode 100644 index 0000000..a5b78bb --- /dev/null +++ b/src/compat/configured/java/ConfiguredCompat.kt @@ -0,0 +1,29 @@ +package moe.nea.firmament.compat.configured + +import com.mrcrayfish.configured.api.IConfigEntry +import com.mrcrayfish.configured.api.IModConfig +import com.mrcrayfish.configured.api.IModConfigProvider +import com.mrcrayfish.configured.api.ModContext +import moe.nea.firmament.Firmament +import moe.nea.firmament.gui.config.AllConfigsGui + +/** + * Registered in `fabric.mod.json` at `custom.configured.providers` + */ +class ConfiguredCompat : IModConfigProvider { + override fun getConfigurationsForMod(modContext: ModContext): Set<IModConfig> { + if (modContext.modId != Firmament.MOD_ID) return emptySet() + return buildSet { + add(object : BaseConfig() { + override fun getRoot(): IConfigEntry { + return BaseConfigNode + } + + override fun getTranslationKey(): String? { + return "firmament.config.all-configs" + } + }) + AllConfigsGui.allConfigs.mapTo(this) { ConfigCategory(it) } + } + } +} diff --git a/src/compat/configured/java/ConfiguredConfigScreenProvider.kt b/src/compat/configured/java/ConfiguredConfigScreenProvider.kt new file mode 100644 index 0000000..c0095bf --- /dev/null +++ b/src/compat/configured/java/ConfiguredConfigScreenProvider.kt @@ -0,0 +1,22 @@ +package moe.nea.firmament.compat.configured + +import com.google.auto.service.AutoService +import com.mrcrayfish.configured.integration.CatalogueConfigFactory +import net.fabricmc.loader.api.FabricLoader +import net.minecraft.client.gui.screen.Screen +import moe.nea.firmament.Firmament +import moe.nea.firmament.gui.config.FirmamentConfigScreenProvider + +@AutoService(FirmamentConfigScreenProvider::class) +class ConfiguredConfigScreenProvider : FirmamentConfigScreenProvider { + override val key: String + get() = "configured" + override val isEnabled: Boolean + get() = FabricLoader.getInstance().isModLoaded("configured") + + override fun open(parent: Screen?): Screen { + return CatalogueConfigFactory.createConfigScreen( + parent, + FabricLoader.getInstance().getModContainer(Firmament.MOD_ID).get()) + } +} diff --git a/src/compat/sodium/java/SodiumChunkReloader.kt b/src/compat/sodium/java/SodiumChunkReloader.kt index 9456861..932c338 100644 --- a/src/compat/sodium/java/SodiumChunkReloader.kt +++ b/src/compat/sodium/java/SodiumChunkReloader.kt @@ -1,3 +1,5 @@ +package moe.nea.firmament.compat.sodium + import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer import moe.nea.firmament.mixins.accessor.sodium.AccessorSodiumWorldRenderer |