From d1df2fd128e280c78e4c15d40eb3256de09d1f99 Mon Sep 17 00:00:00 2001 From: GGGuenni Date: Fri, 12 Mar 2021 11:20:55 +0100 Subject: [PATCH] Adding convert Function (#3687) * Adding convert Function * field = null to be safe --- core/src/com/unciv/logic/map/TileInfo.kt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 9ee1845ce9..f978d0fd60 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -54,6 +54,7 @@ open class TileInfo { val terrainFeatures: ArrayList = ArrayList() @Transient // So it won't be serialized from now on + @Deprecated(message = "Since 3.13.7 - gets replaced by terrainFeatures") var terrainFeature: String? = null get() = terrainFeatures.firstOrNull() ?: field //if terrainFeatures contains no terrainFeature maybe one got deserialized to field @@ -64,7 +65,20 @@ open class TileInfo { } else { if (value != null) terrainFeatures.add(value) } + field = null } + + private fun convertTerrainFeatureToArray() { + if (terrainFeatures.firstOrNull() == null && terrainFeature != null)// -> terranFeature getter returns terrainFeature field + terrainFeature = terrainFeature // getter returns field, setter calls terrainFeatures.add() + //Note to Future GGGuenni + //TODO Use the following when terrainFeature got changed everywhere to support old saves in the future + //if (terrainFeature != null){ + //terrainFeatures.add(terrainFeature) + //terrainFeature = null + //} + } + var naturalWonder: String? = null var resource: String? = null var improvement: String? = null @@ -92,6 +106,7 @@ open class TileInfo { toReturn.position = position.cpy() toReturn.baseTerrain = baseTerrain // toReturn.terrainFeature = terrainFeature + convertTerrainFeatureToArray() toReturn.terrainFeatures.addAll(terrainFeatures) toReturn.naturalWonder = naturalWonder toReturn.resource = resource @@ -538,9 +553,7 @@ open class TileInfo { //region state-changing functions fun setTransients() { - if (terrainFeatures.firstOrNull() == null && terrainFeature != null) {// -> terranFeature getter returns terrainFeature field - terrainFeature = terrainFeature // getter returns field, setter calls terrainFeatures.add() - } + convertTerrainFeatureToArray() setTerrainTransients() setUnitTransients(true) }