mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
We now try to load the last tturn-autosave whn loading the regular autosaves failed (e.g. when the save file is corrupt)
This commit is contained in:
parent
89751ca6ec
commit
9b2c1b2ace
@ -6,6 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.Touchable
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.utils.SerializationException
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.GameSaver
|
||||
import com.unciv.logic.GameStarter
|
||||
@ -166,15 +167,20 @@ class MainMenuScreen: CameraStageBaseScreen() {
|
||||
private fun autoLoadGame() {
|
||||
ToastPopup("Loading...", this)
|
||||
thread { // Load game from file to class on separate thread to avoid ANR...
|
||||
val savedGame: GameInfo
|
||||
var savedGame: GameInfo
|
||||
try {
|
||||
savedGame = GameSaver.loadGameByName(autosave)
|
||||
} catch (outOfMemory: OutOfMemoryError) {
|
||||
ToastPopup("Not enough memory on phone to load game!", this)
|
||||
return@thread
|
||||
} catch (ex: Exception) { // silent fail if we can't read the autosave for any reason
|
||||
ToastPopup("Cannot resume game!", this)
|
||||
return@thread
|
||||
} catch (ex: Exception) { // silent fail if we can't read the autosave for any reason - try to load the last autosave by turn number first
|
||||
try {
|
||||
val autosaves = GameSaver.getSaves().filter { it.name() != autosave && it.name().startsWith(autosave) }
|
||||
savedGame = GameSaver.loadGameFromFile(autosaves.maxBy { it.lastModified() }!!)
|
||||
} catch (ex: Exception) {
|
||||
ToastPopup("Cannot resume game!", this)
|
||||
return@thread
|
||||
}
|
||||
}
|
||||
|
||||
Gdx.app.postRunnable { /// ... and load it into the screen on main thread for GL context
|
||||
|
Loading…
x
Reference in New Issue
Block a user