diff options
author | inglettronald <inglettronald@gmail.com> | 2023-06-09 00:17:02 -0500 |
---|---|---|
committer | inglettronald <inglettronald@gmail.com> | 2023-06-09 00:17:02 -0500 |
commit | 81ff04e0ad56b9f197bb9617d414e3dbf5331eca (patch) | |
tree | b52febbfbb76d0a7e460392f8728546602bb7258 /src/main/kotlin/com/dulkirfabric/config | |
parent | 2e2583a1f1964714624744c342321602d41b3eae (diff) | |
download | DulkirMod-Fabric-81ff04e0ad56b9f197bb9617d414e3dbf5331eca.tar.gz DulkirMod-Fabric-81ff04e0ad56b9f197bb9617d414e3dbf5331eca.tar.bz2 DulkirMod-Fabric-81ff04e0ad56b9f197bb9617d414e3dbf5331eca.zip |
initial commit
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric/config')
-rw-r--r-- | src/main/kotlin/com/dulkirfabric/config/ListHelper.kt | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/config/ListHelper.kt b/src/main/kotlin/com/dulkirfabric/config/ListHelper.kt new file mode 100644 index 0000000..b99787f --- /dev/null +++ b/src/main/kotlin/com/dulkirfabric/config/ListHelper.kt @@ -0,0 +1,47 @@ +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.text.Text +import java.util.* +import kotlin.reflect.KMutableProperty0 + +object ListHelper { + 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) + } + ) + } + + object Holder { + var macros = listOf(DulkirConfig.Macro(-1, "Hello World")) + } + + fun ConfigEntryBuilder.mkStringField(text: Text, prop: KMutableProperty0<String>) = startStrField(text, prop.get()) + .setSaveConsumer { prop.set(it) } + .build() + fun ConfigEntryBuilder.mkIntField(text: Text, prop: KMutableProperty0<Int>) = startIntField(text, prop.get()) + .setSaveConsumer { prop.set(it) } + .build() +}
\ No newline at end of file |