Resolved #2853 - Sped up loading of all saved games

This commit is contained in:
Yair Morgenstern 2020-07-23 14:38:36 +03:00
parent 0f70726c10
commit c50c490a63
2 changed files with 9 additions and 9 deletions

View file

@ -31,10 +31,10 @@ object GameSaver {
return externalFile
}
fun getSaves(multiplayer: Boolean = false): List<String> {
val localSaves = Gdx.files.local(getSubfolder(multiplayer)).list().map { it.name() }
fun getSaves(multiplayer: Boolean = false): Sequence<String> {
val localSaves = Gdx.files.local(getSubfolder(multiplayer)).list().asSequence().map { it.name() }
if (externalFilesDirForAndroid == "" || !Gdx.files.isExternalStorageAvailable) return localSaves
return localSaves + Gdx.files.absolute(externalFilesDirForAndroid + "/${getSubfolder(multiplayer)}").list().map { it.name() }
return localSaves + Gdx.files.absolute(externalFilesDirForAndroid + "/${getSubfolder(multiplayer)}").list().asSequence().map { it.name() }
}
fun saveGame(game: GameInfo, GameName: String, multiplayer: Boolean = false) {
@ -110,8 +110,8 @@ object GameSaver {
val newAutosaveFilename = saveFilesFolder + File.separator + "Autosave-${gameInfo.currentPlayer}-${gameInfo.turns}"
getSave("Autosave").copyTo(Gdx.files.local(newAutosaveFilename))
fun getAutosaves(): List<String> { return getSaves().filter { it.startsWith("Autosave") } }
while(getAutosaves().size>10){
fun getAutosaves(): Sequence<String> { return getSaves().filter { it.startsWith("Autosave") } }
while(getAutosaves().count()>10){
val saveToDelete = getAutosaves().minBy { getSave(it).lastModified() }!!
deleteSave(saveToDelete)
}

View file

@ -68,9 +68,9 @@ class MultiplayerScreen(previousScreen: CameraStageBaseScreen) : PickerScreen()
topTable.add(mainTable).row()
scrollPane.setScrollingDisabled(false, true)
rightSideTable.defaults().uniformX();
rightSideTable.defaults().fillX();
rightSideTable.defaults().pad(10.0f);
rightSideTable.defaults().uniformX()
rightSideTable.defaults().fillX()
rightSideTable.defaults().pad(10.0f)
// leftTable Setup
reloadGameListUI()
@ -186,7 +186,7 @@ class MultiplayerScreen(previousScreen: CameraStageBaseScreen) : PickerScreen()
fun reloadGameListUI() {
val leftSubTable = Table()
val gameSaver = GameSaver
val savedGames: List<String>?
val savedGames: Sequence<String>
try {
savedGames = gameSaver.getSaves(true)