Skip to content

Commit 8204de8

Browse files
committed
complete builder and setting builder extension functions
1 parent ef5e7bc commit 8204de8

31 files changed

+238
-49
lines changed

src/main/kotlin/com/lambda/config/AbstractSetting.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.lambda.context.SafeContext
3333
import com.lambda.gui.Layout
3434
import com.lambda.threading.runSafe
3535
import com.lambda.util.Communication.info
36+
import com.lambda.util.Describable
3637
import com.lambda.util.Nameable
3738
import com.lambda.util.NamedEnum
3839
import com.lambda.util.extension.CommandBuilder
@@ -94,13 +95,14 @@ import kotlin.reflect.KProperty
9495
* @property visibility A function that determines whether the setting is visible.
9596
*/
9697
abstract class AbstractSetting<T : Any>(
98+
override var name: String,
9799
internal val defaultValue: T,
98100
val type: Type,
99-
val description: String,
100-
val visibility: () -> Boolean,
101-
) : Jsonable, Nameable, Layout {
101+
override var description: String,
102+
var visibility: () -> Boolean,
103+
) : Jsonable, Nameable, Describable, Layout {
102104
private val listeners = mutableListOf<ValueListener<T>>()
103-
val groups: MutableList<List<NamedEnum>> = mutableListOf()
105+
var groups: MutableList<List<NamedEnum>> = mutableListOf()
104106

105107
var value by Delegates.observable(defaultValue) { _, from, to ->
106108
listeners.forEach {

src/main/kotlin/com/lambda/config/Configurable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import java.awt.Color
5959
abstract class Configurable(
6060
private val configuration: Configuration,
6161
) : Jsonable, Nameable {
62-
val settings = mutableSetOf<AbstractSetting<*>>()
62+
val settings = mutableListOf<AbstractSetting<*>>()
6363

6464
init {
6565
registerConfigurable()

src/main/kotlin/com/lambda/config/groups/BreakSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BreakSettings(
3333
c: Configurable,
3434
groupPath: List<NamedEnum> = emptyList(),
3535
vis: () -> Boolean = { true },
36-
) : BreakConfig {
36+
) : BreakConfig, SettingGroup(c, c.settings.size) {
3737
enum class Group(override val displayName: String) : NamedEnum {
3838
General("General"),
3939
Cosmetic("Cosmetic")

src/main/kotlin/com/lambda/config/groups/BuildSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class BuildSettings(
2626
c: Configurable,
2727
vararg groupPath: NamedEnum,
2828
vis: () -> Boolean = { true },
29-
) : BuildConfig {
29+
) : BuildConfig, SettingGroup(c, c.settings.size) {
3030
enum class Group(override val displayName: String) : NamedEnum {
3131
General("General"),
3232
Break("Break"),

src/main/kotlin/com/lambda/config/groups/EatSettings.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ package com.lambda.config.groups
1919

2020
import com.lambda.config.Configurable
2121
import com.lambda.util.NamedEnum
22-
import net.minecraft.item.Item
2322
import net.minecraft.item.Items
2423

2524
class EatSettings(
2625
c: Configurable,
2726
baseGroup: NamedEnum,
2827
vis: () -> Boolean = { true }
29-
) : EatConfig {
28+
) : EatConfig, SettingGroup(c, c.settings.size) {
3029
val nutritiousFoodDefaults = listOf(Items.APPLE, Items.BAKED_POTATO, Items.BEEF, Items.BEETROOT, Items.BEETROOT_SOUP, Items.BREAD, Items.CARROT, Items.CHICKEN, Items.CHORUS_FRUIT, Items.COD, Items.COOKED_BEEF, Items.COOKED_CHICKEN, Items.COOKED_COD, Items.COOKED_MUTTON, Items.COOKED_PORKCHOP, Items.COOKED_RABBIT, Items.COOKED_SALMON, Items.COOKIE, Items.DRIED_KELP, Items.ENCHANTED_GOLDEN_APPLE, Items.GOLDEN_APPLE, Items.GOLDEN_CARROT, Items.HONEY_BOTTLE, Items.MELON_SLICE, Items.MUSHROOM_STEW, Items.MUTTON, Items.POISONOUS_POTATO, Items.PORKCHOP, Items.POTATO, Items.PUFFERFISH, Items.PUMPKIN_PIE, Items.RABBIT, Items.RABBIT_STEW, Items.ROTTEN_FLESH, Items.SALMON, Items.SPIDER_EYE, Items.SUSPICIOUS_STEW, Items.SWEET_BERRIES, Items.GLOW_BERRIES, Items.TROPICAL_FISH)
3130
val resistanceFoodDefaults = listOf(Items.ENCHANTED_GOLDEN_APPLE)
3231
val regenerationFoodDefaults = listOf(Items.ENCHANTED_GOLDEN_APPLE, Items.GOLDEN_APPLE)

src/main/kotlin/com/lambda/config/groups/HotbarSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class HotbarSettings(
2626
c: Configurable,
2727
baseGroup: NamedEnum,
2828
vis: () -> Boolean = { true }
29-
) : HotbarConfig {
29+
) : HotbarConfig, SettingGroup(c, c.settings.size) {
3030
override val keepTicks by c.setting("Keep Ticks", 3, 0..20, 1, "The number of ticks to keep the current hotbar selection active", " ticks", visibility = vis).group(baseGroup)
3131
override val swapDelay by c.setting("Swap Delay", 0, 0..3, 1, "The number of ticks delay before allowing another hotbar selection swap", " ticks", visibility = vis).group(baseGroup)
3232
override val swapsPerTick by c.setting("Swaps Per Tick", 3, 1..10, 1, "The number of hotbar selection swaps that can take place each tick") { swapDelay <= 0 && vis() }.group(baseGroup)

src/main/kotlin/com/lambda/config/groups/InteractSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class InteractSettings(
2626
c: Configurable,
2727
groupPath: List<NamedEnum> = emptyList(),
2828
vis: () -> Boolean = { true }
29-
) : InteractConfig {
29+
) : InteractConfig, SettingGroup(c, c.settings.size) {
3030
override val rotate by c.setting("Rotate For Interact", true, "Rotates the player to look at the block when interacting", visibility = vis).group(groupPath)
3131
override val swingHand by c.setting("Swing On Interact", true, "Swings the players hand after interacting", visibility = vis).group(groupPath)
3232
override val interactStageMask by c.setting("Interact Stage Mask", setOf(TickEvent.Input.Post), description = "The sub-tick timing at which interact actions are performed", visibility = vis).group(groupPath)

src/main/kotlin/com/lambda/config/groups/InteractionSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class InteractionSettings(
2828
baseGroup: NamedEnum,
2929
private val usage: InteractionMask,
3030
vis: () -> Boolean = { true },
31-
) : InteractionConfig {
31+
) : InteractionConfig, SettingGroup(c, c.settings.size) {
3232
// Reach
3333
private val useDefaultReach by c.setting("Default Reach", true, "Whether to use vanilla interaction ranges", vis).group(baseGroup)
3434
private val attackReachSetting = if (usage.entity) c.setting("Attack Reach", DEFAULT_ATTACK_REACH, 1.0..10.0, 0.01, "Maximum entity interaction distance") { vis() && !useDefaultReach }.group(baseGroup) else null

src/main/kotlin/com/lambda/config/groups/InventorySettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class InventorySettings(
2626
c: Configurable,
2727
baseGroup: NamedEnum,
2828
vis: () -> Boolean = { true }
29-
) : InventoryConfig {
29+
) : InventoryConfig, SettingGroup(c, c.settings.size) {
3030
enum class Group(override val displayName: String) : NamedEnum {
3131
Container("Container"),
3232
Access("Access")

src/main/kotlin/com/lambda/config/groups/PlaceSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PlaceSettings(
2828
c: Configurable,
2929
groupPath: List<NamedEnum> = emptyList(),
3030
vis: () -> Boolean = { true }
31-
) : PlaceConfig {
31+
) : PlaceConfig, SettingGroup(c, c.settings.size) {
3232
override val rotateForPlace by c.setting("Rotate For Place", true, "Rotate towards block while placing", visibility = vis).group(groupPath)
3333
override val airPlace by c.setting("Air Place", AirPlaceMode.None, "Allows for placing blocks without adjacent faces", visibility = vis).group(groupPath)
3434
override val axisRotateSetting by c.setting("Axis Rotate", true, "Overrides the Rotate For Place setting and rotates the player on each axis to air place rotational blocks") { vis() && airPlace.isEnabled }.group(groupPath)

0 commit comments

Comments
 (0)