aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-07-05 16:05:55 +0200
committerLinnea Gräf <nea@nea.moe>2025-07-05 16:05:55 +0200
commitef97e9eeff77d6c5cbfb6625c7b999e5e7a9ec80 (patch)
treef48208dc1003904336bdc4b69322d112899f7029 /src
parentda0be5222556797d332ab5a996a3cbd1140a2282 (diff)
downloadFirmament-ef97e9eeff77d6c5cbfb6625c7b999e5e7a9ec80.tar.gz
Firmament-ef97e9eeff77d6c5cbfb6625c7b999e5e7a9ec80.tar.bz2
Firmament-ef97e9eeff77d6c5cbfb6625c7b999e5e7a9ec80.zip
fix: item exporter overwriting wiki links
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/features/debug/itemeditor/ItemExporter.kt20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt b/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt
index d7d17aa..37875fb 100644
--- a/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt
+++ b/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt
@@ -48,11 +48,27 @@ object ItemExporter {
fun exportItem(itemStack: ItemStack): Text {
val exporter = LegacyItemExporter.createExporter(itemStack)
- val json = exporter.exportJson()
- val jsonFormatted = Firmament.twoSpaceJson.encodeToString(json)
+ var json = exporter.exportJson()
val fileName = json.jsonObject["internalname"]!!.jsonPrimitive.content
val itemFile = RepoDownloadManager.repoSavedLocation.resolve("items").resolve("${fileName}.json")
itemFile.createParentDirectories()
+ if (itemFile.exists()) {
+ val existing = try {
+ Firmament.json.decodeFromString<JsonObject>(itemFile.readText())
+ } catch (ex: Exception) {
+ ex.printStackTrace()
+ JsonObject(mapOf())
+ }
+ val mut = json.jsonObject.toMutableMap()
+ for (prop in existing) {
+ if (prop.key !in mut || mut[prop.key]!!.let {
+ (it is JsonPrimitive && (it.content.isEmpty() || it.content == "0")) || (it is JsonArray && it.isEmpty()) || (it is JsonObject && it.isEmpty())
+ })
+ mut[prop.key] = prop.value
+ }
+ json = JsonObject(mut)
+ }
+ val jsonFormatted = Firmament.twoSpaceJson.encodeToString(json)
itemFile.writeText(jsonFormatted)
val overlayFile = RepoDownloadManager.repoSavedLocation.resolve("itemsOverlay")
.resolve(ExportedTestConstantMeta.current.dataVersion.toString())