fix: slot numbers are now in order of save date

This commit is contained in:
tiger tiger tiger 2026-01-16 18:16:53 +01:00
parent 3cb7a2d704
commit f2ab1d7689
1 changed files with 12 additions and 1 deletions

View File

@ -58,6 +58,16 @@ func _sort_saves() -> void:
return a.last_saved > b.last_saved
)
func _get_slot_number(save: SaveGame) -> int:
# Create a list sorted by file name (creation order) to determine slot numbers
var saves_by_creation := saves.duplicate()
saves_by_creation.sort_custom(func(a: SaveGame, b: SaveGame) -> int:
return a.file_name < b.file_name # Older files first (ascending)
)
# Find this save's position in the creation-order list
return saves_by_creation.find(save) + 1
func _rebuild_buttons() -> void:
save_buttons = []
for child in list_container.get_children():
@ -68,7 +78,8 @@ func _rebuild_buttons() -> void:
list_container.add_child(save_box)
for i in range(saves.size()):
var new_button := SaveGameDisplay.new(saves[i], i+1)
var slot_number := _get_slot_number(saves[i])
var new_button := SaveGameDisplay.new(saves[i], slot_number)
save_box.add_child(new_button)
save_buttons.append(new_button)
new_button.pressed.connect(_on_game_picked.bind(i))