Skip to content

Commit caa1add

Browse files
committed
Remove delegation hack, byte and short settings; added SettingTest
1 parent dbe258b commit caa1add

File tree

7 files changed

+75
-174
lines changed

7 files changed

+75
-174
lines changed

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

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,11 @@ abstract class Configurable(
193193
defaultValue: List<T>,
194194
description: String = "",
195195
noinline visibility: () -> Boolean = { true },
196-
hackDelegates: Boolean = false,
197196
) = ListSetting(
198197
name,
199198
defaultValue.toMutableList(),
200199
TypeToken.getParameterized(MutableList::class.java, T::class.java).type,
201200
description,
202-
hackDelegates,
203201
visibility,
204202
).also {
205203
settings.add(it)
@@ -227,14 +225,12 @@ abstract class Configurable(
227225
name: String,
228226
defaultValue: Map<K, V>,
229227
description: String = "",
230-
hackDelegates: Boolean,
231228
noinline visibility: () -> Boolean = { true },
232229
) = MapSetting(
233230
name,
234231
defaultValue.toMutableMap(),
235232
TypeToken.getParameterized(MutableMap::class.java, K::class.java, V::class.java).type,
236233
description,
237-
hackDelegates,
238234
visibility
239235
).also {
240236
settings.add(it)
@@ -272,33 +268,6 @@ abstract class Configurable(
272268
settings.add(it)
273269
}
274270

275-
/**
276-
* Creates a [ByteSetting] with the provided parameters and adds it to the [settings].
277-
*
278-
* The value of the setting is coerced into the specified [range] and rounded to the nearest [step].
279-
*
280-
* @param name The unique identifier for the setting.
281-
* @param defaultValue The default [Byte] value of the setting.
282-
* @param range The range within which the setting's value must fall.
283-
* @param step The step to which the setting's value is rounded.
284-
* @param description A brief explanation of the setting's purpose and behavior.
285-
* @param visibility A lambda expression that determines the visibility status of the setting.
286-
* @param unit The unit of the setting. E.g. "°C", "m/s", "ms", "ticks", etc.
287-
*
288-
* @return The created [ByteSetting].
289-
*/
290-
fun setting(
291-
name: String,
292-
defaultValue: Byte,
293-
range: ClosedRange<Byte>,
294-
step: Byte = 1,
295-
description: String = "",
296-
unit: String = "",
297-
visibility: () -> Boolean = { true },
298-
) = ByteSetting(name, defaultValue, range, step, description, visibility, unit).also {
299-
settings.add(it)
300-
}
301-
302271
/**
303272
* Creates a [DoubleSetting] with the provided parameters and adds it to the [settings].
304273
*
@@ -407,33 +376,6 @@ abstract class Configurable(
407376
settings.add(it)
408377
}
409378

410-
/**
411-
* Creates a [ShortSetting] with the provided parameters and adds it to the [settings].
412-
*
413-
* The value of the setting is coerced into the specified [range] and rounded to the nearest [step].
414-
*
415-
* @param name The unique identifier for the setting.
416-
* @param defaultValue The default [Short] value of the setting.
417-
* @param range The range within which the setting's value must fall.
418-
* @param step The step to which the setting's value is rounded.
419-
* @param description A brief explanation of the setting's purpose and behavior.
420-
* @param visibility A lambda expression that determines the visibility status of the setting.
421-
* @param unit The unit of the setting. E.g. "°C", "m/s", "ms", "ticks", etc.
422-
*
423-
* @return The created [ShortSetting].
424-
*/
425-
fun setting(
426-
name: String,
427-
defaultValue: Short,
428-
range: ClosedRange<Short>,
429-
step: Short = 1,
430-
description: String = "",
431-
unit: String = "",
432-
visibility: () -> Boolean = { true },
433-
) = ShortSetting(name, defaultValue, range, step, description, visibility, unit).also {
434-
settings.add(it)
435-
}
436-
437379
/**
438380
* Creates a [KeyBindSetting] with the provided parameters and adds it to the [settings].
439381
*

common/src/main/kotlin/com/lambda/config/settings/collections/ListSetting.kt

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package com.lambda.config.settings.collections
1919

20-
import com.google.gson.JsonElement
21-
import com.lambda.Lambda.gson
2220
import com.lambda.config.AbstractSetting
2321
import java.lang.reflect.Type
2422

@@ -27,26 +25,13 @@ import java.lang.reflect.Type
2725
*/
2826
class ListSetting<T : Any>(
2927
override val name: String,
30-
private val defaultValue: MutableList<T>,
28+
defaultValue: MutableList<T>,
3129
type: Type,
3230
description: String,
33-
private val hackDelegates: Boolean,
3431
visibility: () -> Boolean,
3532
) : AbstractSetting<MutableList<T>>(
3633
defaultValue,
3734
type,
3835
description,
3936
visibility
40-
) {
41-
override fun toJson(): JsonElement {
42-
return if (hackDelegates) gson.toJsonTree(defaultValue, type)
43-
else super.toJson()
44-
}
45-
46-
override fun loadFromJson(serialized: JsonElement) {
47-
if (hackDelegates) {
48-
defaultValue.addAll(gson.fromJson(serialized, type))
49-
setValue(this, ::value, defaultValue.distinct().toMutableList())
50-
} else super.loadFromJson(serialized)
51-
}
52-
}
37+
)

common/src/main/kotlin/com/lambda/config/settings/collections/MapSetting.kt

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package com.lambda.config.settings.collections
1919

20-
import com.google.gson.JsonElement
21-
import com.lambda.Lambda.gson
2220
import com.lambda.config.AbstractSetting
2321
import java.lang.reflect.Type
2422

@@ -27,26 +25,13 @@ import java.lang.reflect.Type
2725
*/
2826
class MapSetting<K, V>(
2927
override val name: String,
30-
private val defaultValue: MutableMap<K, V>,
28+
defaultValue: MutableMap<K, V>,
3129
type: Type,
3230
description: String,
33-
private val hackDelegates: Boolean,
3431
visibility: () -> Boolean,
3532
) : AbstractSetting<MutableMap<K, V>>(
3633
defaultValue,
3734
type,
3835
description,
3936
visibility
40-
) {
41-
override fun toJson(): JsonElement {
42-
return if (hackDelegates) gson.toJsonTree(defaultValue, type)
43-
else super.toJson()
44-
}
45-
46-
override fun loadFromJson(serialized: JsonElement) {
47-
if (hackDelegates) {
48-
defaultValue.putAll(gson.fromJson(serialized, type))
49-
setValue(this, ::value, defaultValue)
50-
} else super.loadFromJson(serialized)
51-
}
52-
}
37+
)

common/src/main/kotlin/com/lambda/config/settings/numeric/ByteSetting.kt

Lines changed: 0 additions & 40 deletions
This file was deleted.

common/src/main/kotlin/com/lambda/config/settings/numeric/ShortSetting.kt

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.module.modules.debug
19+
20+
import com.lambda.module.Module
21+
import com.lambda.module.tag.ModuleTag
22+
import com.lambda.util.KeyCode
23+
import net.minecraft.block.Blocks
24+
import net.minecraft.util.math.BlockPos
25+
import java.awt.Color
26+
27+
object SettingTest : Module(
28+
name = "SettingTest",
29+
defaultTags = setOf(ModuleTag.DEBUG)
30+
) {
31+
// CharSetting
32+
private val charSetting by setting("Character Setting", 'A')
33+
34+
// String
35+
private val stringSetting by setting("String Setting", "Default String")
36+
37+
// Comparable
38+
private val booleanSetting by setting("Boolean Setting", true)
39+
private val enumSetting by setting("Enum Setting", ExampleEnum.VALUE_ONE)
40+
41+
// Numeric
42+
private val doubleSetting by setting("Double Setting", 3.14159, 0.0..100.0, 0.1)
43+
private val floatSetting by setting("Float Setting", 3.14f, 0.0f..100.0f, 0.1f)
44+
private val integerSetting by setting("Integer Setting", 42, 0..1000)
45+
private val longSetting by setting("Long Setting", 100000L, 0L..1000000L, 1000L)
46+
47+
// Collections
48+
private val stringList by setting("String List", listOf("Hello", "World"))
49+
private val stringSet by setting("String Set", setOf("Apple", "Banana"))
50+
private val stringMap by setting("String Map", mapOf("Key1" to "Value1", "Key2" to "Value2"))
51+
52+
// Complex
53+
private val blockPosSetting by setting("Block Position", BlockPos(0, 0, 0))
54+
private val blockSetting by setting("Block Setting", Blocks.OBSIDIAN)
55+
private val colorSetting by setting("Color Setting", Color.GREEN)
56+
private val keyBindSetting by setting("Key Bind Setting", KeyCode.T)
57+
58+
// Complex collections
59+
private val blockPosSet by setting("Block Position Set", setOf(BlockPos(0, 0, 0)))
60+
private val blockList by setting("Block List", listOf(Blocks.OBSIDIAN))
61+
private val colorMap by setting("Color Map", mapOf("Primary" to Color.GREEN))
62+
private val keyBindSet by setting("Key Bind Set", setOf(KeyCode.T))
63+
64+
enum class ExampleEnum {
65+
VALUE_ONE,
66+
VALUE_TWO,
67+
VALUE_THREE
68+
}
69+
}

common/src/main/kotlin/com/lambda/module/modules/network/PacketLogger.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ object PacketLogger : Module(
5353
private val networkSide by setting("Network Side", NetworkSide.ANY, "Side of the network to log packets from")
5454
private val logTicks by setting("Log Ticks", true, "Show game ticks in the log")
5555
private val scope by setting("Scope", Scope.ANY, "Scope of packets to log")
56-
private val whitelist by setting("Whitelist Packets", emptyList<String>(), "Packets to whitelist", visibility = { scope == Scope.WHITELIST })
57-
private val blacklist by setting("Blacklist Packets", emptyList<String>(), "Packets to blacklist", visibility = { scope == Scope.BLACKLIST })
56+
private val whitelist by setting("Whitelist Packets", emptyList<String>(), "Packets to whitelist") { scope == Scope.WHITELIST }
57+
private val blacklist by setting("Blacklist Packets", emptyList<String>(), "Packets to blacklist") { scope == Scope.BLACKLIST }
5858
private val maxRecursionDepth by setting("Max Recursion Depth", 6, 1..10, 1, "Maximum recursion depth for packet serialization")
5959
private val logConcurrent by setting("Build Data Concurrent", false, "Whether to serialize packets concurrently. Will not save packets in chronological order but wont lag the game.")
6060

0 commit comments

Comments
 (0)