aboutsummaryrefslogtreecommitdiff
path: root/src/compat/configured/java/ConfigValue.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-08-31 11:59:47 +0200
committerLinnea Gräf <nea@nea.moe>2024-08-31 11:59:47 +0200
commit816f80f862d2f5de6bc9b0ae84cd6df0da341228 (patch)
treeee8aaccbaebe5a024549c2530319ed09a02cc4e4 /src/compat/configured/java/ConfigValue.kt
parentd2f240ff0ca0d27f417f837e706c781a98c31311 (diff)
downloadfirmament-816f80f862d2f5de6bc9b0ae84cd6df0da341228.tar.gz
firmament-816f80f862d2f5de6bc9b0ae84cd6df0da341228.tar.bz2
firmament-816f80f862d2f5de6bc9b0ae84cd6df0da341228.zip
Add configured compat
[no changelog]
Diffstat (limited to 'src/compat/configured/java/ConfigValue.kt')
-rw-r--r--src/compat/configured/java/ConfigValue.kt72
1 files changed, 72 insertions, 0 deletions
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)
+ }
+}