Skip to content

Commit ca4b17e

Browse files
committed
mostly structurally complete, need to add a gui to create and link presets, set presets on modules from config load, add a way to view the configs in modules, then cleanup whatever mess is left behind from incomplete refactors
1 parent 6c48763 commit ca4b17e

36 files changed

+340
-142
lines changed

src/main/kotlin/com/lambda/command/commands/BuildCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ object BuildCommand : LambdaCommand(
6262
.loadStructureByRelativePath(Path.of(pathString))
6363
.let { template ->
6464
info("Building structure $pathString with dimensions ${template.size.toShortString()} created by ${template.author}")
65-
lastBuildTask = with(AutomationConfig) {
65+
lastBuildTask = with(AutomationConfig.Companion.DEFAULT) {
6666
template.toStructure()
6767
.move(player.blockPos)
6868
.toBlueprint()

src/main/kotlin/com/lambda/command/commands/TransferCommand.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ object TransferCommand : LambdaCommand(
5353
val selection = selectStack(count) {
5454
isItem(stack(ctx).value().item)
5555
}
56-
with(AutomationConfig) {
56+
with(AutomationConfig.Companion.DEFAULT) {
5757
selection.containerWithMaterial().forEachIndexed { i, container ->
5858
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
5959
}
@@ -65,7 +65,7 @@ object TransferCommand : LambdaCommand(
6565
val selection = selectStack(amount(ctx).value()) {
6666
isItem(stack(ctx).value().item)
6767
}
68-
with(AutomationConfig) {
68+
with(AutomationConfig.Companion.DEFAULT) {
6969
containerWithSpace(selection).forEachIndexed { i, container ->
7070
builder.suggest("\"${i + 1}. ${container.name}\"", container.description(selection))
7171
}
@@ -84,7 +84,7 @@ object TransferCommand : LambdaCommand(
8484
it.name == to().value().split(".").last().trim()
8585
} ?: return@executeWithResult failure("To container not found")
8686

87-
with(AutomationConfig) {
87+
with(AutomationConfig.Companion.DEFAULT) {
8888
when (val transaction = fromContainer.transfer(selection, toContainer)) {
8989
is TransferResult.ContainerTransfer -> {
9090
info("${transaction.name} started.")

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.lambda.config
2020
import com.google.gson.JsonElement
2121
import com.google.gson.JsonObject
2222
import com.google.gson.reflect.TypeToken
23-
import com.lambda.Lambda
2423
import com.lambda.Lambda.LOG
2524
import com.lambda.config.settings.CharSetting
2625
import com.lambda.config.settings.FunctionSetting
@@ -69,7 +68,9 @@ abstract class Configurable(
6968
private fun registerConfigurable() = configuration.configurables.add(this)
7069

7170
inline fun <reified T : AbstractSetting<*>> T.register(): T {
72-
check(settings.add(this)) { "Setting with name $name already exists for configurable: ${this@Configurable.name}" }
71+
if (settings.any { it.name == name })
72+
throw IllegalStateException("Setting with name $name already exists for configurable: ${this@Configurable.name}")
73+
settings.add(this)
7374
return this
7475
}
7576

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import com.google.gson.JsonSyntaxException
2525
import com.lambda.Lambda.LOG
2626
import com.lambda.Lambda.gson
2727
import com.lambda.config.Configuration.Companion.configurables
28-
import com.lambda.config.configurations.ModuleConfig
28+
import com.lambda.config.configurations.ModuleConfigs
2929
import com.lambda.event.events.ClientEvent
3030
import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe
3131
import com.lambda.threading.runIO
@@ -48,7 +48,7 @@ import kotlin.time.Duration.Companion.minutes
4848
* Each configuration will be loaded concurrently,
4949
* while the underlying configurables are populated with the settings in sequence.
5050
*
51-
* See also [ModuleConfig].
51+
* See also [ModuleConfigs].
5252
*
5353
* @property configName The name of the configuration.
5454
* @property primary The primary file where the configuration is saved.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.config.configurations
19+
20+
import com.lambda.config.Configuration
21+
import com.lambda.util.FolderRegister
22+
import java.io.File
23+
24+
object AutomationConfigs : Configuration() {
25+
override val configName = "automation"
26+
override val primary: File = FolderRegister.config.resolve("${configName}.json").toFile()
27+
}

src/main/kotlin/com/lambda/config/configurations/ModuleConfig.kt renamed to src/main/kotlin/com/lambda/config/configurations/ModuleConfigs.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
package com.lambda.config.configurations
1919

2020
import com.lambda.config.Configuration
21-
import com.lambda.config.configurations.ModuleConfig.configName
22-
import com.lambda.config.configurations.ModuleConfig.primary
21+
import com.lambda.config.configurations.ModuleConfigs.configName
22+
import com.lambda.config.configurations.ModuleConfigs.primary
2323
import com.lambda.util.FolderRegister
2424
import java.io.File
2525

2626

2727
/**
28-
* The [ModuleConfig] object represents the configuration file for the [Module]s.
28+
* The [ModuleConfigs] object represents the configuration file for the [Module]s.
2929
*
3030
* This object is used to save and load the settings of all [Module]s in the system.
3131
*
3232
* @property configName The name of the configuration.
3333
* @property primary The primary file where the configuration is saved.
3434
*/
35-
object ModuleConfig : Configuration() {
35+
object ModuleConfigs : Configuration() {
3636
override val configName get() = "modules"
3737
override val primary: File = FolderRegister.config.resolve("$configName.json").toFile()
3838
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import com.lambda.util.BlockUtils.allSigns
2828
import com.lambda.util.NamedEnum
2929
import java.awt.Color
3030

31-
class BreakSettings(
31+
open class BreakSettings(
3232
c: Configurable,
3333
baseGroup: NamedEnum,
3434
vis: () -> Boolean = { true },
35-
) : BreakConfig, SettingGroup(c) {
35+
) : BreakConfig, MutableSettings(c) {
3636
enum class Group(override val displayName: String) : NamedEnum {
3737
General("General"),
3838
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 baseGroup: NamedEnum,
2828
vis: () -> Boolean = { true },
29-
) : BuildConfig, SettingGroup(c) {
29+
) : BuildConfig, MutableSettings(c) {
3030
enum class Group(override val displayName: String) : NamedEnum {
3131
General("General"),
3232
Reach("Reach"),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class EatSettings(
2525
c: Configurable,
2626
baseGroup: NamedEnum,
2727
vis: () -> Boolean = { true }
28-
) : EatConfig, SettingGroup(c) {
28+
) : EatConfig, MutableSettings(c) {
2929
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)
3030
val resistanceFoodDefaults = listOf(Items.ENCHANTED_GOLDEN_APPLE)
3131
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, SettingGroup(c) {
29+
) : HotbarConfig, MutableSettings(c) {
3030
override val keepTicks by c.setting("Keep Ticks", 1, 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)

0 commit comments

Comments
 (0)