package dev.isxander.yacl3.dsl import dev.isxander.yacl3.api.Option import dev.isxander.yacl3.api.controller.* import net.minecraft.world.item.Item import java.awt.Color typealias ControllerBuilderFactory = (Option) -> ControllerBuilder fun tickBox(): ControllerBuilderFactory = { option -> TickBoxControllerBuilder.create(option) } fun textSwitch(formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> BooleanControllerBuilder.create(option).apply { formatter?.let { formatValue(it) } } } fun slider(range: IntRange, step: Int = 1, formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> IntegerSliderControllerBuilder.create(option).apply { range(range.first, range.last) step(step) formatter?.let { formatValue(it) } } } fun slider(range: LongRange, step: Long = 1, formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> LongSliderControllerBuilder.create(option).apply { range(range.first, range.last) step(step) formatter?.let { formatValue(it) } } } fun slider(range: ClosedRange, step: Float = 1f, formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> FloatSliderControllerBuilder.create(option).apply { range(range.start, range.endInclusive) step(step) formatter?.let { formatValue(it) } } } fun slider(range: ClosedRange, step: Double = 1.0, formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> DoubleSliderControllerBuilder.create(option).apply { range(range.start, range.endInclusive) step(step) formatter?.let { formatValue(it) } } } fun stringField(): ControllerBuilderFactory = { option -> StringControllerBuilder.create(option) } fun numberField(min: Int? = null, max: Int? = null, formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> IntegerFieldControllerBuilder.create(option).apply { min?.let { min(it) } max?.let { max(it) } formatter?.let { formatValue(it) } } } fun numberField(min: Long? = null, max: Long? = null, formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> LongFieldControllerBuilder.create(option).apply { min?.let { min(it) } max?.let { max(it) } formatter?.let { formatValue(it) } } } fun numberField(min: Float? = null, max: Float? = null, formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> FloatFieldControllerBuilder.create(option).apply { min?.let { min(it) } max?.let { max(it) } formatter?.let { formatValue(it) } } } fun numberField(min: Double? = null, max: Double? = null, formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> DoubleFieldControllerBuilder.create(option).apply { min?.let { min(it) } max?.let { max(it) } formatter?.let { formatValue(it) } } } fun colorPicker(allowAlpha: Boolean = false): ControllerBuilderFactory = { option -> ColorControllerBuilder.create(option).apply { allowAlpha(allowAlpha) } } fun cyclingList(values: Iterable, formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> CyclingListControllerBuilder.create(option).apply { values(values) formatter?.let { formatValue(it) } } } fun > enumSwitch(enumClass: Class, formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> EnumControllerBuilder.create(option).apply { enumClass(enumClass) formatter?.let { formatValue(it) } } } inline fun > enumSwitch(formatter: ValueFormatter? = null): ControllerBuilderFactory = enumSwitch(T::class.java, formatter) fun > enumDropdown(formatter: ValueFormatter? = null): ControllerBuilderFactory = { option -> EnumDropdownControllerBuilder.create(option).apply { formatter?.let { formatValue(it) } } } fun minecraftItem(): ControllerBuilderFactory = { option -> ItemControllerBuilder.create(option) }