Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent deserialization problem with Espionage #9809

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/src/com/unciv/logic/GameInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down