From 4955d35efbd8509e93b7f54c8a974335d41dd461 Mon Sep 17 00:00:00 2001 From: OptimizedForDensity <105244635+OptimizedForDensity@users.noreply.github.com> Date: Sun, 19 Jun 2022 03:23:56 -0400 Subject: [PATCH] Moddable game speed backwards compatibility (#7212) * Move GameSpeed definition to JSON files * Minor cleanup and some corrections * Round down tribute gold to match old when statement * Small variable name changes * Some typos * Reduce number of speed modifiers plus code improvements * Catch missing game speed * Found a better place for the check * More tweaks * Added a startYear mod constant and some tweaks * Cleanup old GameSpeed file references * Fix tests * Add game speeds civilopedia page * Remove one last todo * Fix translation * New icon for game speeds * More game speed modifiers * Fix error * Update Speeds.json files and move tutorial to docs * Rename GameSpeed class to Speed * Rename GameSpeed -> Speed and other reviews * Forgot a file * Add start year to civilopedia * Remove decimal from default starting years * Fix backwards compatibility * Unused import Co-authored-by: OptimizedForDensity <> --- core/src/com/unciv/logic/BackwardCompatibility.kt | 8 ++++++++ core/src/com/unciv/logic/GameInfo.kt | 3 +++ core/src/com/unciv/models/metadata/GameParameters.kt | 3 +++ 3 files changed, 14 insertions(+) diff --git a/core/src/com/unciv/logic/BackwardCompatibility.kt b/core/src/com/unciv/logic/BackwardCompatibility.kt index 5631341293..4b22b4af31 100644 --- a/core/src/com/unciv/logic/BackwardCompatibility.kt +++ b/core/src/com/unciv/logic/BackwardCompatibility.kt @@ -218,4 +218,12 @@ object BackwardCompatibility { } return false } + + @Suppress("DEPRECATION") + fun GameInfo.convertOldGameSpeed() { + if (gameParameters.gameSpeed != "" && gameParameters.gameSpeed in ruleSet.speeds.keys) { + gameParameters.speed = gameParameters.gameSpeed + gameParameters.gameSpeed = "" + } + } } diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index 959a2b30cd..a4ac3a3cde 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -3,6 +3,7 @@ package com.unciv.logic import com.unciv.Constants import com.unciv.UncivGame import com.unciv.logic.BackwardCompatibility.convertFortify +import com.unciv.logic.BackwardCompatibility.convertOldGameSpeed import com.unciv.utils.debug import com.unciv.logic.BackwardCompatibility.guaranteeUnitPromotions import com.unciv.logic.BackwardCompatibility.migrateBarbarianCamps @@ -399,6 +400,8 @@ class GameInfo { updateGreatGeneralUniques() + convertOldGameSpeed() + for (baseUnit in ruleSet.units.values) baseUnit.ruleset = ruleSet diff --git a/core/src/com/unciv/models/metadata/GameParameters.kt b/core/src/com/unciv/models/metadata/GameParameters.kt index f523459fbf..54f2847803 100644 --- a/core/src/com/unciv/models/metadata/GameParameters.kt +++ b/core/src/com/unciv/models/metadata/GameParameters.kt @@ -11,6 +11,9 @@ enum class BaseRuleset(val fullName:String){ class GameParameters { // Default values are the default new game var difficulty = "Prince" var speed = Speed.DEFAULT + + @Deprecated("Since 4.1.11") + var gameSpeed = "" var players = ArrayList().apply { add(Player().apply { playerType = PlayerType.Human }) for (i in 1..3) add(Player())