mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-05 21:11:35 +07:00
Prevent deserialization problem with Espionage (#9809)
* Prevent deserialization problem with Espionage * Move comment and explain context a little better
This commit is contained in:
parent
0e64b8230f
commit
37465b5032
@ -56,6 +56,13 @@ import java.util.UUID
|
||||
* When you change the structure of any class with this interface in a way which makes it impossible
|
||||
* to load the new saves from an older game version, increment [CURRENT_COMPATIBILITY_NUMBER]! And don't forget
|
||||
* to add backwards compatibility for the previous format.
|
||||
*
|
||||
* Reminder: In all subclasse, do use only actual Collection types, not abstractions like
|
||||
* `= mutableSetOf<Something>()`. That would make the reflection type of the field an interface, which
|
||||
* hides the actual implementation from Gdx Json, so it will not try to call a no-args constructor but
|
||||
* will instead deserialize a List in the jsonData.isArray() -> isAssignableFrom(Collection) branch of readValue:
|
||||
* https://github.com/libgdx/libgdx/blob/75612dae1eeddc9611ed62366858ff1d0ac7898b/gdx/src/com/badlogic/gdx/utils/Json.java#L1111
|
||||
* .. which will crash later (when readFields actually assigns it) unless empty.
|
||||
*/
|
||||
interface IsPartOfGameInfoSerialization
|
||||
|
||||
|
@ -8,15 +8,15 @@ import com.unciv.models.Spy
|
||||
|
||||
class EspionageManager : IsPartOfGameInfoSerialization {
|
||||
|
||||
var spyList = mutableListOf<Spy>()
|
||||
val erasSpyEarnedFor = mutableSetOf<String>()
|
||||
var spyList = ArrayList<Spy>()
|
||||
val erasSpyEarnedFor = LinkedHashSet<String>()
|
||||
|
||||
@Transient
|
||||
lateinit var civInfo: Civilization
|
||||
|
||||
fun clone(): EspionageManager {
|
||||
val toReturn = EspionageManager()
|
||||
toReturn.spyList.addAll(spyList.map { it.clone() })
|
||||
spyList.mapTo(toReturn.spyList) { it.clone() }
|
||||
toReturn.erasSpyEarnedFor.addAll(erasSpyEarnedFor)
|
||||
return toReturn
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user