Skip to content

Commit b6c6569

Browse files
committed
re-fix collection settings displaying wrong toString (sorry)
1 parent c584342 commit b6c6569

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/main/kotlin/com/lambda/config/settings/collections/BlockCollectionSetting.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.google.gson.JsonElement
2121
import com.google.gson.reflect.TypeToken
2222
import com.lambda.Lambda.gson
2323
import com.lambda.config.Setting
24+
import com.lambda.config.serializer.BlockCodec
2425
import com.lambda.gui.dsl.ImGuiBuilder
2526
import net.minecraft.block.Block
2627

@@ -33,7 +34,7 @@ class BlockCollectionSetting(
3334
TypeToken.getParameterized(Collection::class.java, Block::class.java).type
3435
) {
3536
context(setting: Setting<*, MutableCollection<Block>>)
36-
override fun ImGuiBuilder.buildLayout() = buildComboBox("block")
37+
override fun ImGuiBuilder.buildLayout() = buildComboBox("block") { BlockCodec.stringify(it) }
3738

3839
context(setting: Setting<*, MutableCollection<Block>>)
3940
override fun toJson(): JsonElement = gson.toJsonTree(value, type)

src/main/kotlin/com/lambda/config/settings/collections/ClassCollectionSetting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ClassCollectionSetting<T : Any>(
3737
TypeToken.getParameterized(Collection::class.java, Any::class.java).type
3838
) {
3939
context(setting: Setting<*, MutableCollection<T>>)
40-
override fun ImGuiBuilder.buildLayout() = buildComboBox("item")
40+
override fun ImGuiBuilder.buildLayout() = buildComboBox("item") { it.className }
4141

4242
// When serializing the list to json we do not want to serialize the elements' classes, but their stringified representation.
4343
// If we do serialize the classes we'll run into missing type adapters errors by Gson.

src/main/kotlin/com/lambda/config/settings/collections/CollectionSetting.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ import imgui.flag.ImGuiSelectableFlags.DontClosePopups
3434
import java.lang.reflect.Type
3535

3636
/**
37-
* This generic collection settings handles all [Comparable] values (i.e not classes) and serialize
37+
* This generic collection settings handles all [Comparable] values (i.e., not classes) and serialize
3838
* their values by calling [Any.toString] and loads them by comparing what's in the [immutableCollection].
39-
* This behaviour is by design. If you wish to store collections of non-comparable values you must use [ClassCollectionSetting].
39+
* This behavior is by design. If you wish to store collections of non-comparable values you must use [ClassCollectionSetting].
4040
*
41-
* If you wish to use a different codec or simply display values differently you must create your own
41+
* If you wish to use a different codec or simply display values differently, you must create your own
4242
* collection setting.
4343
*
4444
* @see [com.lambda.config.Configurable]
@@ -59,10 +59,10 @@ open class CollectionSetting<R : Any>(
5959
val deselectListeners = mutableListOf<SafeContext.(R) -> Unit>()
6060

6161
context(setting: Setting<*, MutableCollection<R>>)
62-
override fun ImGuiBuilder.buildLayout() = buildComboBox("item")
62+
override fun ImGuiBuilder.buildLayout() = buildComboBox("item") { it.toString() }
6363

6464
context(setting: Setting<*, MutableCollection<R>>)
65-
fun ImGuiBuilder.buildComboBox(itemName: String) {
65+
fun ImGuiBuilder.buildComboBox(itemName: String, toString: (R) -> String) {
6666
val text = if (value.size == 1) itemName else "${itemName}s"
6767

6868
combo("##${setting.name}", "${setting.name}: ${value.size} $text") {
@@ -85,7 +85,7 @@ open class CollectionSetting<R : Any>(
8585
val selected = value.contains(v)
8686

8787
selectable(
88-
label = v.toString(),
88+
label = toString(v),
8989
selected = selected,
9090
flags = DontClosePopups
9191
) {

src/main/kotlin/com/lambda/config/settings/collections/ItemCollectionSetting.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.google.gson.JsonElement
2121
import com.google.gson.reflect.TypeToken
2222
import com.lambda.Lambda.gson
2323
import com.lambda.config.Setting
24+
import com.lambda.config.serializer.ItemCodec
2425
import com.lambda.gui.dsl.ImGuiBuilder
2526
import net.minecraft.item.Item
2627

@@ -33,7 +34,7 @@ class ItemCollectionSetting(
3334
TypeToken.getParameterized(Collection::class.java, Item::class.java).type
3435
) {
3536
context(setting: Setting<*, MutableCollection<Item>>)
36-
override fun ImGuiBuilder.buildLayout() = buildComboBox("item")
37+
override fun ImGuiBuilder.buildLayout() = buildComboBox("item") { ItemCodec.stringify(it) }
3738

3839
context(setting: Setting<*, MutableCollection<Item>>)
3940
override fun toJson(): JsonElement = gson.toJsonTree(value, type)

0 commit comments

Comments
 (0)