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()