diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-09-14 20:13:38 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-09-14 20:13:38 +0200 |
| commit | 0dd12964fc3b7b14736d5ec29d583bf30c6af0c5 (patch) | |
| tree | 56213b089dd9175075ce7c0d024ef726e821dc07 | |
| parent | 0a96dd618acba15269627c7eae8a2291fb2dc84a (diff) | |
| download | Firmament-0dd12964fc3b7b14736d5ec29d583bf30c6af0c5.tar.gz Firmament-0dd12964fc3b7b14736d5ec29d583bf30c6af0c5.tar.bz2 Firmament-0dd12964fc3b7b14736d5ec29d583bf30c6af0c5.zip | |
finishing touches
| -rw-r--r-- | src/main/java/moe/nea/firmament/util/data/ManagedConfig.kt | 11 | ||||
| -rw-r--r-- | src/main/kotlin/gui/config/storage/LegacyImporter.kt | 18 |
2 files changed, 20 insertions, 9 deletions
diff --git a/src/main/java/moe/nea/firmament/util/data/ManagedConfig.kt b/src/main/java/moe/nea/firmament/util/data/ManagedConfig.kt index 032784a..b441b02 100644 --- a/src/main/java/moe/nea/firmament/util/data/ManagedConfig.kt +++ b/src/main/java/moe/nea/firmament/util/data/ManagedConfig.kt @@ -37,6 +37,8 @@ import net.minecraft.text.Text import net.minecraft.util.StringIdentifiable import org.joml.Vector2i import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.putJsonObject import kotlin.io.path.createDirectories import kotlin.io.path.readText import kotlin.io.path.writeText @@ -100,15 +102,18 @@ abstract class ManagedConfig( override fun saveTo(key: Unit): JsonObject { return buildJsonObject { - sortedOptions.forEach { - put(it.propertyName, it.toJson() ?: return@forEach) + putJsonObject(name) { + sortedOptions.forEach { + put(it.propertyName, it.toJson() ?: return@forEach) + } } } } override fun loadFrom(key: Unit, jsonObject: JsonObject) { + val unprefixed = jsonObject[name]?.jsonObject ?: JsonObject(mapOf()) sortedOptions.forEach { - it.load(jsonObject) + it.load(unprefixed) } } diff --git a/src/main/kotlin/gui/config/storage/LegacyImporter.kt b/src/main/kotlin/gui/config/storage/LegacyImporter.kt index 942fd2a..d06afcc 100644 --- a/src/main/kotlin/gui/config/storage/LegacyImporter.kt +++ b/src/main/kotlin/gui/config/storage/LegacyImporter.kt @@ -26,20 +26,26 @@ object LegacyImporter { } } + val legacyStorage = listOf( + "inventory-buttons", + "macros", + ) + fun importFromLegacy() { configFolder.moveTo(backupPath) configFolder.createDirectories() - copyIf( - backupPath.resolve("inventory-buttons.json"), - storageFolder.resolve("inventory-buttons.json") - ) + legacyStorage.forEach { + copyIf( + backupPath.resolve("$it.json"), + storageFolder.resolve("$it.json") + ) + } backupPath.listDirectoryEntries("*.json") + .filter { it.nameWithoutExtension !in legacyStorage } .forEach { path -> val name = path.name - if (name == "inventory-buttons.json") - return@forEach path.copyTo(configFolder.resolve(name)) } |
