diff options
author | inglettronald <inglettronald@gmail.com> | 2023-06-10 16:45:58 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-06-10 16:45:58 -0500 |
commit | 22508bb83e8d5846a7a68dd5346e8a2013e1c710 (patch) | |
tree | c1d1cea4acd3a7560b6e813f0081fe7e89feb8a6 /src/main/kotlin/com/dulkirfabric/config/ConfigHelper.kt | |
parent | 8b69b68978e32d6f8e66fca06a8c7ed36523062f (diff) | |
download | DulkirMod-Fabric-22508bb83e8d5846a7a68dd5346e8a2013e1c710.tar.gz DulkirMod-Fabric-22508bb83e8d5846a7a68dd5346e8a2013e1c710.tar.bz2 DulkirMod-Fabric-22508bb83e8d5846a7a68dd5346e8a2013e1c710.zip |
more shortcuts stuff
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric/config/ConfigHelper.kt')
-rw-r--r-- | src/main/kotlin/com/dulkirfabric/config/ConfigHelper.kt | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/config/ConfigHelper.kt b/src/main/kotlin/com/dulkirfabric/config/ConfigHelper.kt new file mode 100644 index 0000000..4f12d27 --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/config/ConfigHelper.kt @@ -0,0 +1,58 @@ +package com.dulkirfabric.config + +import me.shedaniel.clothconfig2.api.AbstractConfigListEntry +import me.shedaniel.clothconfig2.api.ConfigEntryBuilder +import me.shedaniel.clothconfig2.gui.entries.MultiElementListEntry +import me.shedaniel.clothconfig2.gui.entries.NestedListListEntry +import net.minecraft.client.util.InputUtil +import net.minecraft.text.Text +import java.util.* +import kotlin.reflect.KMutableProperty0 + +object ConfigHelper { + fun <T> mkConfigList( + name: Text, + property: KMutableProperty0<List<T>>, + newT: () -> T, + elementName: Text, + render: (T) -> List<AbstractConfigListEntry<*>>, + canDelete: Boolean = true, + ): NestedListListEntry<T, MultiElementListEntry<T>> { + return NestedListListEntry<T, MultiElementListEntry<T>>( + name, // field name + property.get(), // value + false, // defaultExpanded + { Optional.empty() }, // tooltipSupplier + { property.set(it) }, // saveConsumer + { mutableListOf() }, // defaultValue + Text.literal("Reset"), // resetButtonKey + canDelete, + false, + { value, entry -> // createNewCell + val value = value ?: newT() + MultiElementListEntry(elementName, value, render(value), true) + } + ) + } + + fun ConfigEntryBuilder.mkStringField(text: Text, prop: KMutableProperty0<String>) = startStrField(text, prop.get()) + .setSaveConsumer { prop.set(it) } + .setDefaultValue("") + .build() + fun ConfigEntryBuilder.mkIntField(text: Text, prop: KMutableProperty0<Int>) = startIntField(text, prop.get()) + .setSaveConsumer { prop.set(it) } + .setDefaultValue(0) + .build() + + fun ConfigEntryBuilder.mkKeyField(text: Text, prop: KMutableProperty0<InputUtil.Key>) = startKeyCodeField(text, prop.get()) + .setKeySaveConsumer { prop.set(it) } + .setDefaultValue(InputUtil.UNKNOWN_KEY) + .build() + + fun ConfigEntryBuilder.mkToggle(text: Text, prop: KMutableProperty0<Boolean>, tooltip: Text = Text.literal("")) + = startBooleanToggle(text, prop.get()) + .setSaveConsumer { prop.set(it) } + .setDefaultValue(false) + .setTooltip(tooltip) + .build() +}
\ No newline at end of file |