mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 15:01:09 -04:00
Harden map editor map loader against most bad maps (#4711)
* Harden map editor map loader against most bad maps * Harden map editor map loader against most bad maps - patch1
This commit is contained in:
parent
5511c80eb5
commit
7d52cfbcab
@ -879,6 +879,7 @@ Clear current map =
|
|||||||
Save map =
|
Save map =
|
||||||
Download map =
|
Download map =
|
||||||
Loading... =
|
Loading... =
|
||||||
|
Error loading map! =
|
||||||
Filter: =
|
Filter: =
|
||||||
OK =
|
OK =
|
||||||
Exit map editor =
|
Exit map editor =
|
||||||
|
@ -10,6 +10,7 @@ import com.badlogic.gdx.utils.Json
|
|||||||
import com.unciv.logic.MapSaver
|
import com.unciv.logic.MapSaver
|
||||||
import com.unciv.logic.map.MapType
|
import com.unciv.logic.map.MapType
|
||||||
import com.unciv.logic.map.TileMap
|
import com.unciv.logic.map.TileMap
|
||||||
|
import com.unciv.models.ruleset.RulesetCache
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.pickerscreens.PickerScreen
|
import com.unciv.ui.pickerscreens.PickerScreen
|
||||||
import com.unciv.ui.saves.Gzip
|
import com.unciv.ui.saves.Gzip
|
||||||
@ -54,17 +55,45 @@ class SaveAndLoadMapScreen(mapToSave: TileMap?, save:Boolean = false, previousSc
|
|||||||
} else {
|
} else {
|
||||||
rightSideButton.setText("Load map".tr())
|
rightSideButton.setText("Load map".tr())
|
||||||
rightSideButtonAction = {
|
rightSideButtonAction = {
|
||||||
thread {
|
thread(name = "MapLoader") {
|
||||||
|
var popup: Popup? = null
|
||||||
|
var needPopup = true // loadMap can fail faster than postRunnable runs
|
||||||
Gdx.app.postRunnable {
|
Gdx.app.postRunnable {
|
||||||
val popup = Popup(this)
|
if (!needPopup) return@postRunnable
|
||||||
popup.addGoodSizedLabel("Loading...")
|
popup = Popup(this).apply {
|
||||||
popup.open()
|
addGoodSizedLabel("Loading...")
|
||||||
|
open()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val map = MapSaver.loadMap(chosenMap!!)
|
try {
|
||||||
Gdx.app.postRunnable {
|
val map = MapSaver.loadMap(chosenMap!!)
|
||||||
Gdx.input.inputProcessor = null // This is to stop ANRs happening here, until the map editor screen sets up.
|
val missingMods = map.mapParameters.mods.filter { it !in RulesetCache }
|
||||||
game.setScreen(MapEditorScreen(map))
|
if (missingMods.isNotEmpty()) {
|
||||||
dispose()
|
Gdx.app.postRunnable {
|
||||||
|
needPopup = false
|
||||||
|
popup?.close()
|
||||||
|
ToastPopup("Missing mods: [${missingMods.joinToString()}]", this)
|
||||||
|
}
|
||||||
|
} else Gdx.app.postRunnable {
|
||||||
|
Gdx.input.inputProcessor = null // This is to stop ANRs happening here, until the map editor screen sets up.
|
||||||
|
try {
|
||||||
|
game.setScreen(MapEditorScreen(map))
|
||||||
|
dispose()
|
||||||
|
} catch (ex: Throwable) {
|
||||||
|
needPopup = false
|
||||||
|
popup?.close()
|
||||||
|
println("Error displaying map \"$chosenMap\": ${ex.localizedMessage}")
|
||||||
|
Gdx.input.inputProcessor = stage
|
||||||
|
ToastPopup("Error loading map!", this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ex: Throwable) {
|
||||||
|
needPopup = false
|
||||||
|
Gdx.app.postRunnable {
|
||||||
|
popup?.close()
|
||||||
|
println("Error loading map \"$chosenMap\": ${ex.localizedMessage}")
|
||||||
|
ToastPopup("Error loading map!", this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user