Skip to content

Commit 39c8ee5

Browse files
committed
Code cleanup
1 parent fe6e990 commit 39c8ee5

30 files changed

+73
-63
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import kotlin.reflect.KProperty
1111
abstract class AbstractSetting<T : Any>(
1212
private val defaultValue: T,
1313
val visibility: () -> Boolean,
14-
val description: String
14+
val description: String,
1515
) : Jsonable, Nameable {
1616
private val listeners = mutableListOf<(from: T, to: T) -> Unit>()
1717

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import com.lambda.config.settings.numeric.*
1616
import com.lambda.util.KeyCode
1717
import com.lambda.util.Nameable
1818
import net.minecraft.block.Block
19-
import net.minecraft.client.option.KeyBinding
2019
import net.minecraft.util.math.BlockPos
2120

2221
/**
@@ -40,15 +39,16 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
4039
serialized.asJsonObject.entrySet().forEach { (name, value) ->
4140
settings.find {
4241
it.name == name
43-
}?.loadFromJson(value) ?: LOG.warn("No saved setting found for $name with $value in ${this::class.simpleName}")
42+
}?.loadFromJson(value)
43+
?: LOG.warn("No saved setting found for $name with $value in ${this::class.simpleName}")
4444
}
4545
}
4646

4747
fun setting(
4848
name: String,
4949
defaultValue: Boolean,
5050
visibility: () -> Boolean = { true },
51-
description: String = ""
51+
description: String = "",
5252
) = BooleanSetting(name, defaultValue, visibility, description).also {
5353
settings.add(it)
5454
}
@@ -57,7 +57,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
5757
name: String,
5858
defaultValue: T,
5959
noinline visibility: () -> Boolean = { true },
60-
description: String = ""
60+
description: String = "",
6161
) = EnumSetting(name, defaultValue, visibility, description).also {
6262
settings.add(it)
6363
}
@@ -66,7 +66,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
6666
name: String,
6767
defaultValue: String,
6868
visibility: () -> Boolean = { true },
69-
description: String = ""
69+
description: String = "",
7070
) = StringSetting(name, defaultValue, visibility, description).also {
7171
settings.add(it)
7272
}
@@ -75,7 +75,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
7575
name: String,
7676
defaultValue: List<T>,
7777
noinline visibility: () -> Boolean = { true },
78-
description: String = ""
78+
description: String = "",
7979
) = ListSetting(name, defaultValue, visibility, description).also {
8080
settings.add(it)
8181
}
@@ -84,7 +84,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
8484
name: String,
8585
defaultValue: Map<K, V>,
8686
noinline visibility: () -> Boolean = { true },
87-
description: String = ""
87+
description: String = "",
8888
) = MapSetting(name, defaultValue, visibility, description).also {
8989
settings.add(it)
9090
}
@@ -93,7 +93,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
9393
name: String,
9494
defaultValue: Set<T>,
9595
noinline visibility: () -> Boolean = { true },
96-
description: String = ""
96+
description: String = "",
9797
) = SetSetting(name, defaultValue, visibility, description).also {
9898
settings.add(it)
9999
}
@@ -104,7 +104,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
104104
range: ClosedRange<Byte>,
105105
step: Byte = 1,
106106
visibility: () -> Boolean = { true },
107-
description: String = ""
107+
description: String = "",
108108
) = ByteSetting(name, defaultValue, range, step, visibility, description).also {
109109
settings.add(it)
110110
}
@@ -115,7 +115,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
115115
range: ClosedRange<Double>,
116116
step: Double = 1.0,
117117
visibility: () -> Boolean = { true },
118-
description: String = ""
118+
description: String = "",
119119
) = DoubleSetting(name, defaultValue, range, step, visibility, description).also {
120120
settings.add(it)
121121
}
@@ -126,7 +126,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
126126
range: ClosedRange<Float>,
127127
step: Float = 1f,
128128
visibility: () -> Boolean = { true },
129-
description: String = ""
129+
description: String = "",
130130
) = FloatSetting(name, defaultValue, range, step, visibility, description).also {
131131
settings.add(it)
132132
}
@@ -137,7 +137,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
137137
range: ClosedRange<Int>,
138138
step: Int = 1,
139139
visibility: () -> Boolean = { true },
140-
description: String = ""
140+
description: String = "",
141141
) = IntegerSetting(name, defaultValue, range, step, visibility, description).also {
142142
settings.add(it)
143143
}
@@ -148,7 +148,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
148148
range: ClosedRange<Long>,
149149
step: Long = 1,
150150
visibility: () -> Boolean = { true },
151-
description: String = ""
151+
description: String = "",
152152
) = LongSetting(name, defaultValue, range, step, visibility, description).also {
153153
settings.add(it)
154154
}
@@ -159,7 +159,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
159159
range: ClosedRange<Short>,
160160
step: Short = 1,
161161
visibility: () -> Boolean = { true },
162-
description: String = ""
162+
description: String = "",
163163
) = ShortSetting(name, defaultValue, range, step, visibility, description).also {
164164
settings.add(it)
165165
}
@@ -168,7 +168,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
168168
name: String,
169169
defaultValue: KeyCode,
170170
visibility: () -> Boolean = { true },
171-
description: String = ""
171+
description: String = "",
172172
) = KeyBindSetting(name, defaultValue, visibility, description).also {
173173
settings.add(it)
174174
}
@@ -177,7 +177,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
177177
name: String,
178178
defaultValue: BlockPos,
179179
visibility: () -> Boolean = { true },
180-
description: String = ""
180+
description: String = "",
181181
) = BlockPosSetting(name, defaultValue, visibility, description).also {
182182
settings.add(it)
183183
}
@@ -186,7 +186,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
186186
name: String,
187187
defaultValue: Block,
188188
visibility: () -> Boolean = { true },
189-
description: String = ""
189+
description: String = "",
190190
) = BlockSetting(name, defaultValue, visibility, description).also {
191191
settings.add(it)
192192
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ abstract class Configuration : Jsonable {
3838
serialized.asJsonObject.entrySet().forEach { (name, value) ->
3939
configurables.find {
4040
it.name == name
41-
}?.loadFromJson(value) ?: LOG.warn("No matching setting found for saved setting $name with $value in $configName config")
41+
}?.loadFromJson(value)
42+
?: LOG.warn("No matching setting found for saved setting $name with $value in $configName config")
4243
}
4344
}
4445

@@ -71,7 +72,12 @@ abstract class Configuration : Jsonable {
7172
.recoverCatching {
7273
runCatching { load(backup) }
7374
.onSuccess { LOG.info("$configName config loaded from backup") }
74-
.onFailure { LOG.error("Failed to load $configName config from backup, unrecoverable error", it) }
75+
.onFailure {
76+
LOG.error(
77+
"Failed to load $configName config from backup, unrecoverable error",
78+
it
79+
)
80+
}
7581
}
7682
}
7783
}

common/src/main/kotlin/com/lambda/config/serializer/BlockPosSerializer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object BlockPosSerializer : JsonSerializer<BlockPos>, JsonDeserializer<BlockPos>
88
override fun serialize(
99
src: BlockPos?,
1010
typeOfSrc: Type?,
11-
context: JsonSerializationContext?
11+
context: JsonSerializationContext?,
1212
): JsonElement =
1313
src?.let {
1414
JsonObject().apply {
@@ -21,7 +21,7 @@ object BlockPosSerializer : JsonSerializer<BlockPos>, JsonDeserializer<BlockPos>
2121
override fun deserialize(
2222
json: JsonElement?,
2323
typeOfT: Type?,
24-
context: JsonDeserializationContext?
24+
context: JsonDeserializationContext?,
2525
): BlockPos =
2626
json?.asJsonObject?.let {
2727
BlockPos(it["x"].asInt, it["y"].asInt, it["z"].asInt)

common/src/main/kotlin/com/lambda/config/settings/NumericSetting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class NumericSetting<T>(
99
open val range: ClosedRange<T>,
1010
open val step: T,
1111
visibility: () -> Boolean,
12-
description: String
12+
description: String,
1313
) : AbstractSetting<T>(
1414
value,
1515
visibility,

common/src/main/kotlin/com/lambda/config/settings/StringSetting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class StringSetting(
66
override val name: String,
77
defaultValue: String,
88
visibility: () -> Boolean,
9-
description: String
9+
description: String,
1010
) : AbstractSetting<String>(
1111
defaultValue,
1212
visibility,

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ package com.lambda.config.settings.collections
22

33
import com.google.gson.JsonElement
44
import com.google.gson.reflect.TypeToken
5-
import com.lambda.Lambda
6-
import com.lambda.Lambda.LOG
75
import com.lambda.Lambda.gson
86
import com.lambda.config.AbstractSetting
9-
import java.lang.reflect.Type
107

118
class ListSetting<T>(
129
override val name: String,
1310
defaultValue: List<T>,
1411
visibility: () -> Boolean,
15-
description: String
12+
description: String,
1613
) : AbstractSetting<List<T>>(
1714
defaultValue,
1815
visibility,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MapSetting<K, V>(
99
override val name: String,
1010
defaultValue: Map<K, V>,
1111
visibility: () -> Boolean,
12-
description: String
12+
description: String,
1313
) : AbstractSetting<Map<K, V>>(
1414
defaultValue,
1515
visibility,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class SetSetting<T : Any>(
99
override val name: String,
1010
defaultValue: Set<T>,
1111
visibility: () -> Boolean,
12-
description: String
12+
description: String,
1313
) : AbstractSetting<Set<T>>(
1414
defaultValue,
1515
visibility,

common/src/main/kotlin/com/lambda/config/settings/comparable/BooleanSetting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class BooleanSetting(
66
override val name: String,
77
defaultValue: Boolean,
88
visibility: () -> Boolean,
9-
description: String
9+
description: String,
1010
) : AbstractSetting<Boolean>(
1111
defaultValue,
1212
visibility,

0 commit comments

Comments
 (0)