Skip to content

Commit

Permalink
Added option to change the Maximum Autosave turns stored (#12790)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Emandac authored Jan 18, 2025
1 parent 1792ff7 commit 44fa9bd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions android/assets/jsons/translations/template.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
9 changes: 8 additions & 1 deletion core/src/com/unciv/logic/files/UncivFiles.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -486,7 +489,11 @@ class Autosaves(val files: UncivFiles) {
fun getAutosaves(): Sequence<FileHandle> {
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())
}
Expand Down
1 change: 1 addition & 0 deletions core/src/com/unciv/models/metadata/GameSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion core/src/com/unciv/ui/popups/options/AdvancedTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class AdvancedTab(
init {
pad(10f)
defaults().pad(5f)

addMaxAutosavesStored()

addAutosaveTurnsSelectBox()
addSeparator()
Expand Down Expand Up @@ -92,7 +94,22 @@ class AdvancedTab(
optionsPopup.reopenAfterDisplayLayoutChange()
}
}


private fun addMaxAutosavesStored() {
add("Number of autosave files stored".toLabel()).left().fillX()

val maxAutosavesStoredSelectBox = SelectBox<Int>(skin)
val maxAutosavesStoredArray = Array<Int>()
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()
Expand Down

0 comments on commit 44fa9bd

Please sign in to comment.