From 65b7927df661bced0d5192e3d32863a1718199fd Mon Sep 17 00:00:00 2001 From: Jack Rainy Date: Sun, 12 Apr 2020 14:40:17 +0300 Subject: [PATCH] Throw exceptions for better debugging of saved games with missing mods (#2388) * Throw exceptions for better debugging of saved games with missing mods * Close buttons are added --- core/src/com/unciv/logic/city/CityConstructions.kt | 3 ++- core/src/com/unciv/logic/civilization/CivilizationInfo.kt | 3 ++- core/src/com/unciv/logic/map/MapUnit.kt | 3 ++- core/src/com/unciv/ui/saves/LoadGameScreen.kt | 2 ++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index a36e73df..2f1bd451 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -210,7 +210,8 @@ class CityConstructions { //region state changing functions fun setTransients(){ - builtBuildingObjects = ArrayList(builtBuildings.map { cityInfo.getRuleset().buildings[it]!! }) + builtBuildingObjects = ArrayList(builtBuildings.map { cityInfo.getRuleset().buildings[it] + ?: throw java.lang.Exception("Building $it is not found!")}) } fun addProductionPoints(productionToAdd: Int) { diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 76d94c11..b05ffb23 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -338,7 +338,8 @@ class CivilizationInfo { * And if they civs on't yet know who they are then they don;t know if they're barbarians =\ * */ fun setNationTransient(){ - nation = gameInfo.ruleSet.nations[civName]!! + nation = gameInfo.ruleSet.nations[civName] + ?: throw java.lang.Exception("Nation $civName is not found!") } fun setTransients() { diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 7b98111c..ec37d031 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -307,7 +307,8 @@ class MapUnit { fun setTransients(ruleset: Ruleset) { promotions.unit=this mapUnitAction?.unit = this - baseUnit=ruleset.units[name]!! + baseUnit=ruleset.units[name] + ?: throw java.lang.Exception("Unit $name is not found!") updateUniques() } diff --git a/core/src/com/unciv/ui/saves/LoadGameScreen.kt b/core/src/com/unciv/ui/saves/LoadGameScreen.kt index 66a871c2..34dcc256 100644 --- a/core/src/com/unciv/ui/saves/LoadGameScreen.kt +++ b/core/src/com/unciv/ui/saves/LoadGameScreen.kt @@ -42,11 +42,13 @@ class LoadGameScreen : PickerScreen() { if (ex is UncivShowableException && ex.localizedMessage != null) { // thrown exceptions are our own tests and can be shown to the user cantLoadGamePopup.addGoodSizedLabel(ex.localizedMessage).row() + cantLoadGamePopup.addCloseButton() cantLoadGamePopup.open() } else { cantLoadGamePopup.addGoodSizedLabel("If you could copy your game data (\"Copy saved game to clipboard\" - ").row() cantLoadGamePopup.addGoodSizedLabel(" paste into an email to yairm210@hotmail.com)").row() cantLoadGamePopup.addGoodSizedLabel("I could maybe help you figure out what went wrong, since this isn't supposed to happen!").row() + cantLoadGamePopup.addCloseButton() cantLoadGamePopup.open() ex.printStackTrace() }