1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
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<T> = (Option<T>) -> ControllerBuilder<T>
fun tickBox(): ControllerBuilderFactory<Boolean> = { option ->
TickBoxControllerBuilder.create(option)
}
fun textSwitch(formatter: ValueFormatter<Boolean>? = null): ControllerBuilderFactory<Boolean> = { option ->
BooleanControllerBuilder.create(option).apply {
formatter?.let { formatValue(it) }
}
}
fun slider(range: IntRange, step: Int = 1, formatter: ValueFormatter<Int>? = null): ControllerBuilderFactory<Int> = { 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<Long>? = null): ControllerBuilderFactory<Long> = { option ->
LongSliderControllerBuilder.create(option).apply {
range(range.first, range.last)
step(step)
formatter?.let { formatValue(it) }
}
}
fun slider(range: ClosedRange<Float>, step: Float = 1f, formatter: ValueFormatter<Float>? = null): ControllerBuilderFactory<Float> = { option ->
FloatSliderControllerBuilder.create(option).apply {
range(range.start, range.endInclusive)
step(step)
formatter?.let { formatValue(it) }
}
}
fun slider(range: ClosedRange<Double>, step: Double = 1.0, formatter: ValueFormatter<Double>? = null): ControllerBuilderFactory<Double> = { option ->
DoubleSliderControllerBuilder.create(option).apply {
range(range.start, range.endInclusive)
step(step)
formatter?.let { formatValue(it) }
}
}
fun stringField(): ControllerBuilderFactory<String> = { option ->
StringControllerBuilder.create(option)
}
fun numberField(min: Int? = null, max: Int? = null, formatter: ValueFormatter<Int>? = null): ControllerBuilderFactory<Int> = { 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<Long>? = null): ControllerBuilderFactory<Long> = { 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<Float>? = null): ControllerBuilderFactory<Float> = { 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<Double>? = null): ControllerBuilderFactory<Double> = { option ->
DoubleFieldControllerBuilder.create(option).apply {
min?.let { min(it) }
max?.let { max(it) }
formatter?.let { formatValue(it) }
}
}
fun colorPicker(allowAlpha: Boolean = false): ControllerBuilderFactory<Color> = { option ->
ColorControllerBuilder.create(option).apply {
allowAlpha(allowAlpha)
}
}
fun <T> cyclingList(values: Iterable<T>, formatter: ValueFormatter<T>? = null): ControllerBuilderFactory<T> = { option ->
CyclingListControllerBuilder.create(option).apply {
values(values)
formatter?.let { formatValue(it) }
}
}
fun <T : Enum<T>> enumSwitch(enumClass: Class<T>, formatter: ValueFormatter<T>? = null): ControllerBuilderFactory<T> = { option ->
EnumControllerBuilder.create(option).apply {
enumClass(enumClass)
formatter?.let { formatValue(it) }
}
}
inline fun <reified T : Enum<T>> enumSwitch(formatter: ValueFormatter<T>? = null): ControllerBuilderFactory<T> =
enumSwitch(T::class.java, formatter)
fun <T : Enum<T>> enumDropdown(formatter: ValueFormatter<T>? = null): ControllerBuilderFactory<T> = { option ->
EnumDropdownControllerBuilder.create(option).apply {
formatter?.let { formatValue(it) }
}
}
fun minecraftItem(): ControllerBuilderFactory<Item> = { option ->
ItemControllerBuilder.create(option)
}
|