From 44fa9bde7dfc8daf348139afd796e415b6604a43 Mon Sep 17 00:00:00 2001 From: General_E <121508218+Emandac@users.noreply.github.com> Date: Sat, 18 Jan 2025 17:53:33 +0100 Subject: [PATCH] Added option to change the Maximum Autosave turns stored (#12790) * Settler settle best tile when not escort and dangerous Tiles instead of running away Settler unit will now settle on best tile in dangerous Tiles without escort instead of running away. * Update WorkerAutomation.kt * Update SpecificUnitAutomation.kt * Update WorkerAutomation.kt * Update SpecificUnitAutomation.kt * Now city states get mad when you steal their Lands * new version * change to getDiplomacyManagerOrMeet * added text to template.properties and changed AlertPopup.kt * Update template.properties * with period at the end :b * add flag now * Made Option to declare war when a city state is bullied unavailable * added option to change the Maximum Autosave turns stored * remove print * change letter * should fix issue with building test * update with changes --- .../jsons/translations/template.properties | 2 ++ core/src/com/unciv/logic/files/UncivFiles.kt | 9 ++++++++- .../com/unciv/models/metadata/GameSettings.kt | 1 + .../unciv/ui/popups/options/AdvancedTab.kt | 19 ++++++++++++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 1041675596705..8e0b2b72dce4f 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -886,8 +886,10 @@ Could not download music! = ## Advanced tab Advanced = +Number of autosave files stored = Turns between autosaves = + Screen orientation = Landscape (fixed) = Portrait (fixed) = diff --git a/core/src/com/unciv/logic/files/UncivFiles.kt b/core/src/com/unciv/logic/files/UncivFiles.kt index 7d92fe1449592..11b04e8677bb7 100644 --- a/core/src/com/unciv/logic/files/UncivFiles.kt +++ b/core/src/com/unciv/logic/files/UncivFiles.kt @@ -469,6 +469,9 @@ class Autosaves(val files: UncivFiles) { } fun autoSave(gameInfo: GameInfo, nextTurn: Boolean = false) { + // get GameSettings to check the maxAutosavesStored in the autoSave function + val settings = files.getGeneralSettings() + try { files.saveGame(gameInfo, AUTOSAVE_FILE_NAME) } catch (oom: OutOfMemoryError) { @@ -486,7 +489,11 @@ class Autosaves(val files: UncivFiles) { fun getAutosaves(): Sequence { return files.getSaves().filter { it.name().startsWith(AUTOSAVE_FILE_NAME) } } - while (getAutosaves().count() > 10) { + // added the plus 1 to avoid player choosing 6,11,21,51,101, etc.. in options. +// // with the old version with 10 has example, it would start overriding after 9 instead of 10. + // like from autosave-1 to autosave-9 after the autosave-9 the autosave-1 would override to autosave-2. + // For me it should be after autosave-10 that it should start overriding old autosaves. + while (getAutosaves().count() > settings.maxAutosavesStored+1) { val saveToDelete = getAutosaves().minByOrNull { it.lastModified() }!! files.deleteSave(saveToDelete.name()) } diff --git a/core/src/com/unciv/models/metadata/GameSettings.kt b/core/src/com/unciv/models/metadata/GameSettings.kt index 8a817ede95aa8..e0dc830091ad2 100644 --- a/core/src/com/unciv/models/metadata/GameSettings.kt +++ b/core/src/com/unciv/models/metadata/GameSettings.kt @@ -56,6 +56,7 @@ class GameSettings { var pauseBetweenTracks = 10 var turnsBetweenAutosaves = 1 + var maxAutosavesStored = 10 var tileSet: String = Constants.defaultTileset var unitSet: String? = Constants.defaultUnitset var skin: String = Constants.defaultSkin diff --git a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt index a8704104feabb..ef416ca0cce13 100644 --- a/core/src/com/unciv/ui/popups/options/AdvancedTab.kt +++ b/core/src/com/unciv/ui/popups/options/AdvancedTab.kt @@ -51,6 +51,8 @@ class AdvancedTab( init { pad(10f) defaults().pad(5f) + + addMaxAutosavesStored() addAutosaveTurnsSelectBox() addSeparator() @@ -92,7 +94,22 @@ class AdvancedTab( optionsPopup.reopenAfterDisplayLayoutChange() } } - + + private fun addMaxAutosavesStored() { + add("Number of autosave files stored".toLabel()).left().fillX() + + val maxAutosavesStoredSelectBox = SelectBox(skin) + val maxAutosavesStoredArray = Array() + maxAutosavesStoredArray.addAll(1,2,5,10,15,20,35,50,100,150,200,250) + maxAutosavesStoredSelectBox.items = maxAutosavesStoredArray + maxAutosavesStoredSelectBox.selected = settings.maxAutosavesStored + + add(maxAutosavesStoredSelectBox).pad(10f).row() + + maxAutosavesStoredSelectBox.onChange { + settings.maxAutosavesStored = maxAutosavesStoredSelectBox.selected + } + } private fun addAutosaveTurnsSelectBox() { add("Turns between autosaves".toLabel()).left().fillX()