Caught exception when map fails to load

This commit is contained in:
Yair Morgenstern 2021-05-13 21:43:42 +03:00
parent d92e9a1dc7
commit d546b2b00e
2 changed files with 14 additions and 1 deletions

View File

@ -198,6 +198,7 @@ Game Options =
Civilizations =
Map Type =
Map file =
Could not load map! =
Generated =
Existing =
Custom =

View File

@ -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()