aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/moe/nea/firmament/util/data/ManagedConfig.kt11
-rw-r--r--src/main/kotlin/gui/config/storage/LegacyImporter.kt18
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))
}