Skip to content

Commit 7b97530

Browse files
committed
Setting Refactor
1 parent 5f5c2db commit 7b97530

File tree

6 files changed

+17
-29
lines changed

6 files changed

+17
-29
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.lambda.config
22

33
import com.google.gson.JsonElement
44
import com.google.gson.JsonObject
5+
import com.google.gson.reflect.TypeToken
56
import com.lambda.Lambda
67
import com.lambda.Lambda.LOG
78
import com.lambda.config.settings.CharSetting
@@ -164,10 +165,9 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
164165
inline fun <reified T : Any> setting(
165166
name: String,
166167
defaultValue: List<T>,
167-
type: Type,
168168
description: String = "",
169169
noinline visibility: () -> Boolean = { true },
170-
) = ListSetting(name, defaultValue, type, description, visibility).also {
170+
) = ListSetting(name, defaultValue, object : TypeToken<List<T>>() {}.type, description, visibility).also {
171171
settings.add(it)
172172
}
173173

@@ -191,10 +191,9 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
191191
inline fun <reified K : Any, V : Any> setting(
192192
name: String,
193193
defaultValue: Map<K, V>,
194-
type: Type,
195194
description: String = "",
196195
noinline visibility: () -> Boolean = { true },
197-
) = MapSetting(name, defaultValue, type, description, visibility).also {
196+
) = MapSetting(name, defaultValue, object : TypeToken<Map<K, V>>() {}.type, description, visibility).also {
198197
settings.add(it)
199198
}
200199

@@ -218,10 +217,9 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
218217
inline fun <reified T : Any> setting(
219218
name: String,
220219
defaultValue: Set<T>,
221-
type: Type,
222220
description: String = "",
223221
noinline visibility: () -> Boolean = { true },
224-
) = SetSetting(name, defaultValue, type, description, visibility).also {
222+
) = SetSetting(name, defaultValue, object : TypeToken<Set<T>>() {}.type, description, visibility).also {
225223
settings.add(it)
226224
}
227225

common/src/main/kotlin/com/lambda/config/serializer/gui/TagWindowSerializer.kt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@ object TagWindowSerializer : JsonSerializer<TagWindow>, JsonDeserializer<TagWind
1515
): JsonElement = src?.let {
1616
JsonObject().apply {
1717
addProperty("title", it.title)
18-
add("tags", JsonArray().apply {
19-
it.tags.forEach { tag ->
20-
add(tag.name)
21-
// add(JsonObject().apply {
22-
// addProperty("name", tag.name)
23-
// addProperty("color", tag.color.rgb)
24-
// })
25-
}
26-
})
18+
addProperty("tag", it.tag.name)
2719
addProperty("width", it.width)
2820
addProperty("height", it.height)
2921
addProperty("isOpen", it.isOpen)
@@ -40,9 +32,7 @@ object TagWindowSerializer : JsonSerializer<TagWindow>, JsonDeserializer<TagWind
4032
context: JsonDeserializationContext?,
4133
) = json?.asJsonObject?.let {
4234
TagWindow(
43-
tags = it["tags"].asJsonArray.map { tag ->
44-
ModuleTag(tag.asString)
45-
}.toSet(),
35+
tag = ModuleTag(it["tag"].asString),
4636
title = it["title"].asString,
4737
width = it["width"].asDouble,
4838
height = it["height"].asDouble
@@ -53,5 +43,5 @@ object TagWindowSerializer : JsonSerializer<TagWindow>, JsonDeserializer<TagWind
5343
it["position"].asJsonArray[1].asDouble
5444
)
5545
}
56-
} ?: TagWindow()
46+
} ?: throw JsonParseException("Invalid window data")
5747
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.lambda.gui.impl.clickgui
22

3-
import com.google.gson.reflect.TypeToken
43
import com.lambda.config.Configurable
54
import com.lambda.config.configurations.GuiConfig
65
import com.lambda.gui.impl.clickgui.windows.TagWindow
6+
import com.lambda.module.tag.ModuleTag
77

88
object GuiConfigurable : Configurable(GuiConfig) {
99
override val name = "gui"
10-
val windows = setting("windows", listOf(TagWindow()), object : TypeToken<List<TagWindow>>() {}.type)
10+
val windows = setting("windows", listOf(TagWindow(ModuleTag("Test Window"))))
1111
}

common/src/main/kotlin/com/lambda/gui/impl/clickgui/windows/TagWindow.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import com.lambda.module.modules.client.ClickGui
77
import com.lambda.module.tag.ModuleTag
88

99
class TagWindow(
10-
val tags: Set<ModuleTag> = emptySet(),
11-
override var title: String = "Test Window",
10+
val tag: ModuleTag,
11+
override var title: String = tag.name,
1212
override var width: Double = 110.0,
1313
override var height: Double = 300.0
1414
) : WindowComponent<ModuleButton>() {
1515
init {
16-
ModuleRegistry.modules.filter {
17-
it.customTags.value.any { tag -> tags.contains(tag) } || tags.isEmpty()
18-
}.forEach {
16+
ModuleRegistry.modules/*.filter { module ->
17+
module.customTags.value.any { it.name.equals(tag.name, true) }
18+
}*/.forEach {
1919
children.add(ModuleButton(it, this))
2020
}
2121
}

common/src/main/kotlin/com/lambda/module/Module.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ abstract class Module(
9999
private val isEnabledSetting = setting("Enabled", enabledByDefault, visibility = { false })
100100
private val keybindSetting = setting("Keybind", defaultKeybind)
101101
private val isVisible = setting("Visible", true)
102-
val customTags = setting("Tags", defaultTags, object : TypeToken<Set<ModuleTag>>() {}.type, visibility = { false })
102+
val customTags = setting("Tags", defaultTags, visibility = { false })
103103

104104
var isEnabled by isEnabledSetting
105105
override val isMuted: Boolean

common/src/main/kotlin/com/lambda/module/modules/Packetlogger.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ object Packetlogger : Module(
3838
private val networkSide by setting("Network Side", NetworkSide.ANY, "Side of the network to log packets from")
3939
private val logTicks by setting("Log Ticks", true, "Show game ticks in the log")
4040
private val scope by setting("Scope", Scope.ANY, "Scope of packets to log")
41-
private val whitelist by setting("Whitelist Packets", listOf<String>(), object : TypeToken<List<String>>() {}.type, "Packets to whitelist") { scope == Scope.WHITELIST }
42-
private val blacklist by setting("Blacklist Packets", listOf<String>(), object : TypeToken<List<String>>() {}.type, "Packets to blacklist") { scope == Scope.BLACKLIST }
41+
private val whitelist by setting("Whitelist Packets", listOf<String>(), "Packets to whitelist") { scope == Scope.WHITELIST }
42+
private val blacklist by setting("Blacklist Packets", listOf<String>(), "Packets to blacklist") { scope == Scope.BLACKLIST }
4343
private val maxRecursionDepth by setting("Max Recursion Depth", 6, 1..10, 1, "Maximum recursion depth for packet serialization")
4444
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.")
4545

0 commit comments

Comments
 (0)