NotificationAction compatibility patch (#9824)

* NotificationAction compatibility patch

* NotificationAction compatibility patch
This commit is contained in:
SomeTroglodyte 2023-07-20 08:24:25 +02:00 committed by GitHub
parent 4421a2a54e
commit 383cb38c7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 }