Skip to content

Commit a76e58b

Browse files
committed
remove setting from the settings list entirely if hidden to avoid it being included in configs and commands. Will also reduce overhead from checks when drawing ui
1 parent 9612507 commit a76e58b

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ abstract class AbstractSetting<T : Any>(
101101
override var description: String,
102102
var visibility: () -> Boolean,
103103
) : Jsonable, Nameable, Describable, Layout {
104-
var hidden = false
105104
private val listeners = mutableListOf<ValueListener<T>>()
106105
var groups: MutableList<List<NamedEnum>> = mutableListOf()
107106

@@ -188,7 +187,7 @@ abstract class AbstractSetting<T : Any>(
188187
val previous = this@AbstractSetting.value
189188
try {
190189
loadFromJson(parsed)
191-
} catch (e: Exception) {
190+
} catch (_: Exception) {
192191
return@executeWithResult failure("Failed to load $valueString as a ${type::class.simpleName} for $name in ${config.name}.")
193192
}
194193
ConfigCommand.info(setMessage(previous, this@AbstractSetting.value))

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ abstract class SettingGroup(val c: Configurable) {
5454
fun edit(
5555
vararg settings: KProperty0<*>,
5656
edits: BasicEditBuilder.() -> Unit
57-
) { BasicEditBuilder(settings.map { it.delegate } as List<AbstractSetting<*>>).apply(edits) }
57+
) { BasicEditBuilder(c, settings.map { it.delegate } as List<AbstractSetting<*>>).apply(edits) }
5858

5959
@SettingEditorDsl
6060
fun editWith(
6161
vararg settings: KProperty0<*>,
6262
other: KProperty0<*>,
6363
edits: BasicEditBuilder.(AbstractSetting<*>) -> Unit
64-
) { BasicEditBuilder(settings.map { it.delegate } as List<AbstractSetting<*>>).edits(other.delegate as AbstractSetting<*>) }
64+
) { BasicEditBuilder(c, settings.map { it.delegate } as List<AbstractSetting<*>>).edits(other.delegate as AbstractSetting<*>) }
6565

6666
@SettingEditorDsl
6767
internal inline fun <T : Any> editTyped(
@@ -78,7 +78,7 @@ abstract class SettingGroup(val c: Configurable) {
7878

7979
@SettingEditorDsl
8080
fun hide(vararg settings: KProperty0<*>) =
81-
(settings.map { it.delegate } as List<AbstractSetting<*>>).forEach { it.hidden = true }
81+
c.settings.removeAll(settings.map { it.delegate } as List<AbstractSetting<*>>)
8282

8383
@SettingEditorDsl
8484
fun KProperty0<*>.insert(insert: KProperty0<*>, insertMode: InsertMode) {
@@ -98,14 +98,15 @@ abstract class SettingGroup(val c: Configurable) {
9898
)
9999
}
100100

101-
open class BasicEditBuilder(open val settings: Collection<AbstractSetting<*>>) {
101+
open class BasicEditBuilder(val c: Configurable, open val settings: Collection<AbstractSetting<*>>) {
102102
@SettingEditorDsl
103103
fun visibility(vis: () -> Boolean) =
104104
settings.forEach { it.visibility = vis }
105105

106106
@SettingEditorDsl
107-
fun hide() =
108-
settings.forEach { it.hidden = true }
107+
fun hide() {
108+
c.settings.removeAll(settings)
109+
}
109110

110111
@SettingEditorDsl
111112
fun groups(vararg groups: NamedEnum) =
@@ -118,8 +119,8 @@ abstract class SettingGroup(val c: Configurable) {
118119

119120
open class TypedEditBuilder<T : Any>(
120121
override val settings: Collection<AbstractSetting<T>>,
121-
val c: Configurable
122-
) : BasicEditBuilder(settings) {
122+
c: Configurable
123+
) : BasicEditBuilder(c, settings) {
123124
@SettingEditorDsl
124125
fun defaultValue(value: T) =
125126
settings.forEach {

src/main/kotlin/com/lambda/gui/components/SettingsWidget.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ object SettingsWidget {
4141
}
4242
separator()
4343
val toIgnoreSettings = if (config is Module) setOf(config.keybindSetting, config.disableOnReleaseSetting) else emptySet()
44-
val visibleSettings = config.settings.filter { it.visibility() && !it.hidden } - toIgnoreSettings
44+
val visibleSettings = config.settings.filter { it.visibility() } - toIgnoreSettings
4545
val (grouped, ungrouped) = visibleSettings.partition { it.groups.isNotEmpty() }
4646
ungrouped.forEach { with(it) { buildLayout() } }
4747
renderGroup(grouped, emptyList(), config)

0 commit comments

Comments
 (0)