From 5170a27e077196e68ec7f2c090e967864e48fae7 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Sun, 5 Sep 2021 14:57:21 +0300 Subject: [PATCH] Fixed crash where deleting mods meant you could never start a game again If the last game you created used a mod that you later removed from the the device it could never be removed from the new game parameters Caught exceptions from quickstart failing --- android/assets/jsons/translations/template.properties | 3 ++- core/src/com/unciv/MainMenuScreen.kt | 8 ++++++-- core/src/com/unciv/logic/GameStarter.kt | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index d23bf8f67e..fffa81ce45 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -657,7 +657,8 @@ Main menu = Resume = Cannot resume game! = Not enough memory on phone to load game! = -Quickstart = +Quickstart = +Cannot start game with the default new game parameters! = Victory status = Social policies = Community = diff --git a/core/src/com/unciv/MainMenuScreen.kt b/core/src/com/unciv/MainMenuScreen.kt index 31e2c4c4bf..e45396bdc9 100644 --- a/core/src/com/unciv/MainMenuScreen.kt +++ b/core/src/com/unciv/MainMenuScreen.kt @@ -236,8 +236,12 @@ class MainMenuScreen: CameraStageBaseScreen() { } private fun quickstartNewGame() { - val newGame = GameStarter.startNewGame(GameSetupInfo.fromSettings("Chieftain")) - game.loadGame(newGame) + try { + val newGame = GameStarter.startNewGame(GameSetupInfo.fromSettings("Chieftain")) + game.loadGame(newGame) + } catch (ex: Exception) { + ToastPopup("Cannot start game with the default new game parameters!", this) + } } override fun resize(width: Int, height: Int) { diff --git a/core/src/com/unciv/logic/GameStarter.kt b/core/src/com/unciv/logic/GameStarter.kt index f19fa2bf5f..b202a68bcf 100644 --- a/core/src/com/unciv/logic/GameStarter.kt +++ b/core/src/com/unciv/logic/GameStarter.kt @@ -32,6 +32,10 @@ object GameStarter { val gameInfo = GameInfo() lateinit var tileMap: TileMap + // In the case where we used to have a mod, and now we don't, we cannot "unselect" it in the UI. + // We need to remove the dead mods so there aren't problems later. + gameSetupInfo.gameParameters.mods.removeAll{ !RulesetCache.containsKey(it) } + gameInfo.gameParameters = gameSetupInfo.gameParameters val ruleset = RulesetCache.getComplexRuleset(gameInfo.gameParameters.mods)