mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-13 19:39:34 +07:00
Removed empty objects from json serialization with equality instead of post-hoc string replace - kudos @SomeTroglodyte
This commit is contained in:
parent
2b81172d20
commit
5eddb505d2
@ -428,14 +428,7 @@ class UncivFiles(
|
||||
game.version = GameInfo.CURRENT_COMPATIBILITY_VERSION
|
||||
|
||||
if (updateChecksum) game.checksum = game.calculateChecksum()
|
||||
var plainJson = json().toJson(game)
|
||||
|
||||
val removeableStrings = listOf(
|
||||
",\"history\":{}", // empty history object in tile
|
||||
",\"promotions\":{}", // empty promotions object in unit
|
||||
)
|
||||
for (removableString in removeableStrings)
|
||||
plainJson = plainJson.replace(removableString,"")
|
||||
val plainJson = json().toJson(game)
|
||||
|
||||
return if (forceZip ?: saveZipped) Gzip.zip(plainJson) else plainJson
|
||||
}
|
||||
|
@ -137,4 +137,10 @@ class UnitPromotions : IsPartOfGameInfoSerialization {
|
||||
toReturn.unit = unit
|
||||
return toReturn
|
||||
}
|
||||
|
||||
// For json serialization, to not serialize an empty object
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is UnitPromotions) return false
|
||||
return XP == other.XP && promotions == other.promotions && numberOfPromotions == other.numberOfPromotions
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class TileHistory(
|
||||
|
||||
companion object {
|
||||
fun deserialize(s: String): CityCenterType =
|
||||
values().firstOrNull { it.serializedRepresentation == s } ?: None
|
||||
entries.firstOrNull { it.serializedRepresentation == s } ?: None
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,4 +91,13 @@ class TileHistory(
|
||||
|
||||
@VisibleForTesting
|
||||
override fun iterator() = history.iterator()
|
||||
|
||||
// For json serialization, to not serialize an empty object
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is TileHistory) return false
|
||||
if (history == other.history) return true
|
||||
return history.size == other.history.size && history.entries.all { (turn, state) ->
|
||||
state == other.history[turn]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user