mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 11:28:03 +07:00
Resolved #8880 - deprecated old barb camp serialzation
This commit is contained in:
parent
cd8b68253b
commit
9eee47a628
@ -40,28 +40,10 @@ class NonStringKeyMapSerializer<MT: MutableMap<KT, Any>, KT>(
|
||||
override fun read(json: Json, jsonData: JsonValue, type: Class<*>?): MT {
|
||||
val result = mutableMapFactory()
|
||||
val entries = jsonData.get("entries")
|
||||
if (entries == null) {
|
||||
readOldFormat(jsonData, json, result)
|
||||
} else {
|
||||
readNewFormat(entries, json, result)
|
||||
}
|
||||
readNewFormat(entries, json, result)
|
||||
return result
|
||||
}
|
||||
|
||||
@Deprecated("This is only here temporarily until all users migrate the old properties to the new ones")
|
||||
private fun readOldFormat(jsonData: JsonValue, json: Json, result: MT) {
|
||||
@Suppress("UNCHECKED_CAST") // We know better
|
||||
val map = result as MutableMap<String, Any>
|
||||
var child: JsonValue? = jsonData.child
|
||||
while (child != null) {
|
||||
if (child.name == "class") {
|
||||
child = child.next
|
||||
continue
|
||||
}
|
||||
map[child.name] = json.readValue(null, child)
|
||||
child = child.next
|
||||
}
|
||||
}
|
||||
|
||||
private fun readNewFormat(entries: JsonValue, json: Json, result: MT) {
|
||||
var entry = entries.child
|
||||
@ -73,4 +55,4 @@ class NonStringKeyMapSerializer<MT: MutableMap<KT, Any>, KT>(
|
||||
entry = entry.next
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,5 @@
|
||||
package com.unciv.logic
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.badlogic.gdx.utils.JsonValue
|
||||
import com.unciv.json.HashMapVector2
|
||||
import com.unciv.json.json
|
||||
import com.unciv.logic.city.CityConstructions
|
||||
import com.unciv.logic.city.PerpetualConstruction
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
||||
@ -152,27 +148,6 @@ object BackwardCompatibility {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes barbarian manager camps not being correctly serialized. Previously we had a [HashMap<Vector2, Encampment] but it was being
|
||||
* serialized as [HashMap<String, Encampment>]. We need to fix that each time an old save is loaded.
|
||||
*
|
||||
* When removing this, also remove [com.unciv.json.NonStringKeyMapSerializer.readOldFormat]
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
fun BarbarianManager.migrateBarbarianCamps() {
|
||||
if (isOldFormat(this)) {
|
||||
val newFormat = HashMapVector2<Encampment>()
|
||||
@Suppress("UNCHECKED_CAST") // The old format is deserialized to a <String, JsonValue> map
|
||||
for ((key, value) in camps as MutableMap<String, JsonValue>) {
|
||||
val newKey = Vector2().fromString(key)
|
||||
val newValue = json().readValue(Encampment::class.java, value)
|
||||
newFormat[newKey] = newValue
|
||||
}
|
||||
|
||||
camps.clear()
|
||||
camps.putAll(newFormat)
|
||||
}
|
||||
}
|
||||
|
||||
/** Convert from Fortify X to Fortify and save off X */
|
||||
fun GameInfo.convertFortify() {
|
||||
|
@ -6,7 +6,6 @@ import com.unciv.UncivGame.Version
|
||||
import com.unciv.logic.BackwardCompatibility.convertFortify
|
||||
import com.unciv.logic.BackwardCompatibility.convertOldGameSpeed
|
||||
import com.unciv.logic.BackwardCompatibility.guaranteeUnitPromotions
|
||||
import com.unciv.logic.BackwardCompatibility.migrateBarbarianCamps
|
||||
import com.unciv.logic.BackwardCompatibility.migrateToTileHistory
|
||||
import com.unciv.logic.BackwardCompatibility.removeMissingModReferences
|
||||
import com.unciv.logic.GameInfo.Companion.CURRENT_COMPATIBILITY_NUMBER
|
||||
@ -494,7 +493,6 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion
|
||||
gameParameters.baseRuleset = baseRulesetInMods
|
||||
gameParameters.mods = LinkedHashSet(gameParameters.mods.filter { it != baseRulesetInMods })
|
||||
}
|
||||
barbarians.migrateBarbarianCamps()
|
||||
|
||||
ruleset = RulesetCache.getComplexRuleset(gameParameters)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user