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 mkConfigList( name: Text, property: KMutableProperty0>, newT: () -> T, elementName: Text, render: (T) -> List>, canDelete: Boolean = true, ): NestedListListEntry> { return NestedListListEntry>( 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) = startStrField(text, prop.get()) .setSaveConsumer { prop.set(it) } .setDefaultValue("") .build() fun ConfigEntryBuilder.mkIntField(text: Text, prop: KMutableProperty0) = startIntField(text, prop.get()) .setSaveConsumer { prop.set(it) } .setDefaultValue(0) .build() fun ConfigEntryBuilder.mkKeyField(text: Text, prop: KMutableProperty0) = startKeyCodeField(text, prop.get()) .setKeySaveConsumer { prop.set(it) } .setDefaultValue(InputUtil.UNKNOWN_KEY) .build() fun ConfigEntryBuilder.mkToggle(text: Text, prop: KMutableProperty0, tooltip: Text = Text.literal("")) = startBooleanToggle(text, prop.get()) .setSaveConsumer { prop.set(it) } .setDefaultValue(false) .setTooltip(tooltip) .build() }