fix: savegame date calculation was off by 1 (wrong weekday)

fix: empty savegames hidden from list
feat: a basic savegame delete button
This commit is contained in:
tiger tiger tiger 2026-01-16 12:08:25 +01:00
parent 8707ef9ecf
commit bc91204aa2
4 changed files with 49 additions and 4 deletions

View File

@ -51,7 +51,8 @@ var current_room_path: String:
@export var is_demo: bool = OS.has_feature("Demo")
@export var is_empty: bool = true:
get():
return not FileAccess.file_exists("%s.json:" % filepath)
return not FileAccess.file_exists(filepath) or (current_room == State.rooms.NULL)
@export var save_manually: bool = false:
set(val):
if val: save_to_file(thumbnail)

View File

@ -253,3 +253,6 @@ func pick_cards(id: Scenes.id, repeat: bool):
await cards_picked
hide()
await get_tree().process_frame
State.room.save_room()

View File

@ -1,5 +1,7 @@
class_name SaveGameDisplay extends Button
signal delete_requested
var _is_built: bool = false
@export var save: SaveGame:
@ -53,7 +55,7 @@ func rebuild():
match TranslationServer.get_locale():
"de":
localised_weekday = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"]
localised_weekday = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]
localised_date_time = "%s, %d.%d.%d um %d:%02d" % [localised_weekday[date_time["weekday"]],
date_time["day"],
date_time["month"],
@ -62,7 +64,7 @@ func rebuild():
date_time["minute"]
]
_:
localised_weekday = ["Monday", "Tuseday", "Wensday", "Thursday", "Friday", "Saturday", "Sunday"]
localised_weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
localised_date_time = "%s, %d/%d/%d - %d:%02d (%s)" % [localised_weekday[date_time["weekday"]],
date_time["day"],
date_time["month"],
@ -75,6 +77,7 @@ func rebuild():
time_label.text = localised_date_time if not save.current_room == State.rooms.NULL else "Start new game"
var info:= VBoxContainer.new()
info.size_flags_horizontal = Control.SIZE_EXPAND_FILL
base_container.add_child(info)
info.add_child(heading_split)
@ -108,6 +111,16 @@ func rebuild():
info.add_child(room)
info.add_child(state)
info.size_flags_vertical = Control.SIZE_SHRINK_CENTER
# Delete button anchored to bottom right
var delete_button := Button.new()
delete_button.text = "Delete"
delete_button.size_flags_vertical = Control.SIZE_SHRINK_END
delete_button.pressed.connect(func():
delete_requested.emit()
get_viewport().set_input_as_handled()
)
base_container.add_child(delete_button)
theme_type_variation = "SaveButton"

View File

@ -10,6 +10,7 @@ var save_buttons: Array[SaveGameDisplay]
_load_games()
@onready var list_container: VBoxContainer = %ListContainer
@onready var back_button: Button = $MarginContainer/VBoxContainer/HBoxContainer/Button
func _validate_property(property: Dictionary) -> void:
if property.name == "saves":
@ -21,6 +22,7 @@ func _ready() -> void:
_load_games()
hide()
set_process_input(false)
back_button.pressed.connect(cancel)
func _ensure_directory() -> void:
var dir := DirAccess.open(State.user_saves_path)
@ -42,7 +44,10 @@ func _load_games():
for path in filepaths:
if path is String and path.ends_with(".json"):
saves.append(SaveGame.new("%s/%s" % [State.user_saves_path, path.get_basename()]))
var save := SaveGame.new("%s/%s" % [State.user_saves_path, path.get_basename()])
# HACK: Skip empty saves (we decide later what to do with them)
if not save.is_empty:
saves.append(save)
_sort_saves()
_rebuild_buttons()
@ -67,11 +72,34 @@ func _rebuild_buttons() -> void:
save_box.add_child(new_button)
save_buttons.append(new_button)
new_button.pressed.connect(_on_game_picked.bind(i))
new_button.delete_requested.connect(_on_delete_requested.bind(i))
func _on_game_picked(id: int) -> void:
_picked.emit(saves[id])
func _on_delete_requested(id: int) -> void:
var save_to_delete := saves[id]
var save_path := save_to_delete.filepath
var thumbnail_path := "%s/thumbnails/%s.png" % [save_path.get_base_dir(), save_to_delete.unique_save_name]
# Delete the save file
if FileAccess.file_exists(save_path):
DirAccess.remove_absolute(save_path)
print_debug("Deleted save file: %s" % save_path)
# Delete the thumbnail
if FileAccess.file_exists(thumbnail_path):
DirAccess.remove_absolute(thumbnail_path)
print_debug("Deleted thumbnail: %s" % thumbnail_path)
# Reload the save list
_load_games()
# Refocus on a valid button if any exist
if save_buttons.size() > 0:
var focus_index := mini(id, save_buttons.size() - 1)
save_buttons[focus_index].grab_focus()
func get_most_recent_save() -> SaveGame:
_sort_saves()