From a2939c0e27341ec6370acb0c5f834d3a3d57b733 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Mon, 10 May 2021 05:50:49 +0200 Subject: [PATCH] Accelerate Load Game Screen Info (#3902) --- core/src/com/unciv/logic/GameInfo.kt | 14 ++++++++++-- core/src/com/unciv/logic/GameSaver.kt | 8 ++++--- .../logic/civilization/CivilizationInfo.kt | 10 ++++++++- core/src/com/unciv/ui/saves/LoadGameScreen.kt | 22 ++++++++++--------- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index 8bc25bf99d..7ea6878827 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -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) } } -} \ No newline at end of file +} + +// reduced variant only for load preview +class GameInfoPreview { + var civilizations = mutableListOf() + var difficulty = "Chieftain" + var gameParameters = GameParameters() + var turns = 0 + var gameId = "" + var currentPlayer = "" + fun getCivilization(civName: String) = civilizations.first { it.civName == civName } +} diff --git a/core/src/com/unciv/logic/GameSaver.kt b/core/src/com/unciv/logic/GameSaver.kt index 62ac113568..be41fee635 100644 --- a/core/src/com/unciv/logic/GameSaver.kt +++ b/core/src/com/unciv/logic/GameSaver.kt @@ -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 } -} \ No newline at end of file +} diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index adff396851..f38a94db5c 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -680,4 +680,12 @@ class CivilizationInfo { } //endregion -} \ No newline at end of file +} + +// reduced variant only for load preview +class CivilizationInfoPreview { + var civName = "" + var playerType = PlayerType.AI + var playerId = "" + fun isPlayerCivilization() = playerType == PlayerType.Human +} diff --git a/core/src/com/unciv/ui/saves/LoadGameScreen.kt b/core/src/com/unciv/ui/saves/LoadGameScreen.kt index 6c9504e1f0..7465adb7e4 100644 --- a/core/src/com/unciv/ui/saves/LoadGameScreen.kt +++ b/core/src/com/unciv/ui/saves/LoadGameScreen.kt @@ -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 } } }