From 383cb38c7df5913b0bf99e755c4b21dcad556482 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Thu, 20 Jul 2023 08:24:25 +0200 Subject: [PATCH] NotificationAction compatibility patch (#9824) * NotificationAction compatibility patch * NotificationAction compatibility patch --- .../logic/civilization/NotificationActions.kt | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/NotificationActions.kt b/core/src/com/unciv/logic/civilization/NotificationActions.kt index faa307c76e..de233c665c 100644 --- a/core/src/com/unciv/logic/civilization/NotificationActions.kt +++ b/core/src/com/unciv/logic/civilization/NotificationActions.kt @@ -18,6 +18,12 @@ import com.unciv.ui.screens.worldscreen.WorldScreen /* * Not realized as lambda, as it would be too easy to introduce references to objects * there that should not be serialized to the saved game. + * + * IsPartOfGameInfoSerialization is just a marker class and not actually tested for, so inheriting it + * _indirectly_ is OK (the NotificationAction subclasses need not re-implement, a `is`test would still succeed). + * + * Also note all implementations need the default no-args constructor for deserialization, + * therefore the otherwise unused default initializers. */ interface NotificationAction : IsPartOfGameInfoSerialization { fun execute(worldScreen: WorldScreen) @@ -25,7 +31,7 @@ interface NotificationAction : IsPartOfGameInfoSerialization { /** A notification action that shows map places. */ // Note location is nonprivate only for writeOldFormatAction -class LocationAction(internal val location: Vector2) : NotificationAction, IsPartOfGameInfoSerialization { +class LocationAction(internal val location: Vector2 = Vector2.Zero) : NotificationAction { override fun execute(worldScreen: WorldScreen) { worldScreen.mapHolder.setCenterPosition(location, selectUnit = false) } @@ -47,7 +53,7 @@ class LocationAction(internal val location: Vector2) : NotificationAction, IsPar } /** show tech screen */ -class TechAction(private val techName: String = "") : NotificationAction, IsPartOfGameInfoSerialization { +class TechAction(private val techName: String = "") : NotificationAction { override fun execute(worldScreen: WorldScreen) { val tech = worldScreen.gameInfo.ruleset.technologies[techName] worldScreen.game.pushScreen(TechPickerScreen(worldScreen.viewingCiv, tech)) @@ -55,8 +61,7 @@ class TechAction(private val techName: String = "") : NotificationAction, IsPart } /** enter city */ -class CityAction(private val city: Vector2 = Vector2.Zero): NotificationAction, - IsPartOfGameInfoSerialization { +class CityAction(private val city: Vector2 = Vector2.Zero): NotificationAction { override fun execute(worldScreen: WorldScreen) { val cityObject = worldScreen.mapHolder.tileMap[city].getCity() ?: return @@ -66,8 +71,7 @@ class CityAction(private val city: Vector2 = Vector2.Zero): NotificationAction, } /** enter diplomacy screen */ -class DiplomacyAction(private val otherCivName: String = ""): NotificationAction, - IsPartOfGameInfoSerialization { +class DiplomacyAction(private val otherCivName: String = ""): NotificationAction { override fun execute(worldScreen: WorldScreen) { val otherCiv = worldScreen.gameInfo.getCivilization(otherCivName) worldScreen.game.pushScreen(DiplomacyScreen(worldScreen.viewingCiv, otherCiv)) @@ -75,28 +79,28 @@ class DiplomacyAction(private val otherCivName: String = ""): NotificationAction } /** enter Maya Long Count popup */ -class MayaLongCountAction : NotificationAction, IsPartOfGameInfoSerialization { +class MayaLongCountAction : NotificationAction { override fun execute(worldScreen: WorldScreen) { MayaCalendar.openPopup(worldScreen, worldScreen.selectedCiv, worldScreen.gameInfo.getYear()) } } /** A notification action that shows and selects units on the map. */ -class MapUnitAction(private val location: Vector2) : NotificationAction, IsPartOfGameInfoSerialization { +class MapUnitAction(private val location: Vector2 = Vector2.Zero) : NotificationAction { override fun execute(worldScreen: WorldScreen) { worldScreen.mapHolder.setCenterPosition(location, selectUnit = true) } } /** A notification action that shows the Civilopedia entry for a Wonder. */ -class WonderAction(private val wonderName: String) : NotificationAction, IsPartOfGameInfoSerialization { +class WonderAction(private val wonderName: String = "") : NotificationAction { override fun execute(worldScreen: WorldScreen) { worldScreen.game.pushScreen(CivilopediaScreen(worldScreen.gameInfo.ruleset, CivilopediaCategories.Wonder, wonderName)) } } /** Show Promotion picker for a MapUnit - by name and location, as they lack a serialized unique ID */ -class PromoteUnitAction(private val name: String, private val location: Vector2) : NotificationAction, IsPartOfGameInfoSerialization { +class PromoteUnitAction(private val name: String = "", private val location: Vector2 = Vector2.Zero) : NotificationAction { override fun execute(worldScreen: WorldScreen) { val tile = worldScreen.gameInfo.tileMap[location] val unit = tile.militaryUnit?.takeIf { it.name == name && it.civ == worldScreen.selectedCiv }