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 package com.unciv.logic
import com.badlogic.gdx.graphics.Color
import com.unciv.Constants import com.unciv.Constants
import com.unciv.UncivGame import com.unciv.UncivGame
import com.unciv.logic.automation.NextTurnAutomation import com.unciv.logic.automation.NextTurnAutomation
@ -393,3 +392,14 @@ class GameInfo {
} }
} }
} }
// 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.files.FileHandle
import com.badlogic.gdx.utils.Json import com.badlogic.gdx.utils.Json
import com.unciv.UncivGame import com.unciv.UncivGame
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.metadata.GameSettings import com.unciv.models.metadata.GameSettings
import com.unciv.ui.utils.ImageGetter
import java.io.File import java.io.File
import kotlin.concurrent.thread import kotlin.concurrent.thread
@ -68,6 +66,10 @@ object GameSaver {
return game return game
} }
fun loadGamePreviewFromFile(gameFile: FileHandle): GameInfoPreview {
return json().fromJson(GameInfoPreview::class.java, gameFile)
}
fun loadGameFromCustomLocation(loadCompletionCallback: (GameInfo?, Exception?) -> Unit) { fun loadGameFromCustomLocation(loadCompletionCallback: (GameInfo?, Exception?) -> Unit) {
customSaveLocationHelper!!.loadGame { game, e -> customSaveLocationHelper!!.loadGame { game, e ->
loadCompletionCallback(game?.apply { setTransients() }, e) loadCompletionCallback(game?.apply { setTransients() }, e)

View File

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