From d546b2b00efd19bf69b57f01125dbca9fb59382e Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 13 May 2021 21:43:42 +0300 Subject: [PATCH] Caught exception when map fails to load --- .../assets/jsons/translations/template.properties | 1 + .../com/unciv/ui/newgamescreen/MapOptionsTable.kt | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 389f9e8abe..b50c78b9e4 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -198,6 +198,7 @@ Game Options = Civilizations = Map Type = Map file = +Could not load map! = Generated = Existing = Custom = diff --git a/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt b/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt index 9ab095deea..d2fd672da4 100644 --- a/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt +++ b/core/src/com/unciv/ui/newgamescreen/MapOptionsTable.kt @@ -7,7 +7,9 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Array import com.unciv.logic.MapSaver import com.unciv.logic.map.MapType +import com.unciv.logic.map.TileMap import com.unciv.ui.utils.CameraStageBaseScreen +import com.unciv.ui.utils.Popup import com.unciv.ui.utils.onChange import com.unciv.ui.utils.toLabel @@ -89,9 +91,19 @@ class MapOptionsTable(val newGameScreen: NewGameScreen): Table() { mapFileSelectBox.onChange { val mapFile = mapFileSelectBox.selected.fileHandle + val map: TileMap + try { + map = MapSaver.loadMap(mapFile) + } catch (ex:Exception){ + Popup(newGameScreen).apply { + addGoodSizedLabel("Could not load map!") + addCloseButton() + open() + } + return@onChange + } mapParameters.name = mapFile.name() newGameScreen.gameSetupInfo.mapFile = mapFile - val map = MapSaver.loadMap(mapFile) newGameScreen.gameSetupInfo.gameParameters.mods = map.mapParameters.mods newGameScreen.updateRuleset() newGameScreen.updateTables()