Accelerate Load Game Screen Info (#3902)

This commit is contained in:
SomeTroglodyte 2021-05-10 05:50:49 +02:00 committed by GitHub
parent 3065cca5e1
commit a2939c0e27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 16 deletions

View File

@ -1,6 +1,5 @@
package com.unciv.logic
import com.badlogic.gdx.graphics.Color
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.automation.NextTurnAutomation
@ -392,4 +391,15 @@ class GameInfo {
cityConstructions.inProgressConstructions.remove(oldBuildingName)
}
}
}
}
// reduced variant only for load preview
class GameInfoPreview {
var civilizations = mutableListOf<CivilizationInfoPreview>()
var difficulty = "Chieftain"
var gameParameters = GameParameters()
var turns = 0
var gameId = ""
var currentPlayer = ""
fun getCivilization(civName: String) = civilizations.first { it.civName == civName }
}

View File

@ -4,9 +4,7 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.files.FileHandle
import com.badlogic.gdx.utils.Json
import com.unciv.UncivGame
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.metadata.GameSettings
import com.unciv.ui.utils.ImageGetter
import java.io.File
import kotlin.concurrent.thread
@ -68,6 +66,10 @@ object GameSaver {
return game
}
fun loadGamePreviewFromFile(gameFile: FileHandle): GameInfoPreview {
return json().fromJson(GameInfoPreview::class.java, gameFile)
}
fun loadGameFromCustomLocation(loadCompletionCallback: (GameInfo?, Exception?) -> Unit) {
customSaveLocationHelper!!.loadGame { game, e ->
loadCompletionCallback(game?.apply { setTransients() }, e)
@ -172,4 +174,4 @@ object GameSaver {
fun getGameIdFromFile(gameFile: FileHandle): String {
return json().fromJson(GameInfo::class.java, gameFile).gameId
}
}
}

View File

@ -680,4 +680,12 @@ class CivilizationInfo {
}
//endregion
}
}
// reduced variant only for load preview
class CivilizationInfoPreview {
var civName = ""
var playerType = PlayerType.AI
var playerId = ""
fun isPlayerCivilization() = playerType == PlayerType.Human
}

View File

@ -171,29 +171,31 @@ class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen(disabl
private fun onSaveSelected(save: FileHandle) {
selectedSave = save.name()
copySavedGameToClipboardButton.enable()
var textToSet = save.name()
rightSideButton.setText("Load [${save.name()}]".tr())
rightSideButton.enable()
deleteSaveButton.enable()
deleteSaveButton.color = Color.RED
descriptionLabel.setText("Loading...".tr())
val savedAt = Date(save.lastModified())
descriptionLabel.setText("Loading...".tr())
textToSet += "\n{Saved at}: ".tr() + SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US).format(savedAt)
var textToSet = save.name() +
"\n${"Saved at".tr()}: " + SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US).format(savedAt)
thread { // Even loading the game to get its metadata can take a long time on older phones
try {
val game = GameSaver.loadGameFromFile(save)
val game = GameSaver.loadGamePreviewFromFile(save)
val playerCivNames = game.civilizations.filter { it.isPlayerCivilization() }.joinToString { it.civName.tr() }
textToSet += "\n" + playerCivNames +
", " + game.difficulty.tr() + ", ${Fonts.turn}" + game.turns
if (game.gameParameters.mods.isNotEmpty())
textToSet += "\n {Mods:} ".tr() + game.gameParameters.mods.joinToString()
textToSet += "\n${"Mods:".tr()} " + game.gameParameters.mods.joinToString()
} catch (ex: Exception) {
textToSet += "\n{Could not load game}!".tr()
textToSet += "\n${"Could not load game".tr()}!"
}
Gdx.app.postRunnable {
descriptionLabel.setText(textToSet)
rightSideButton.setText("Load [${save.name()}]".tr())
rightSideButton.enable()
deleteSaveButton.enable()
deleteSaveButton.color = Color.RED
}
}
}