fix color space of thumbnails, adding saveguards against savegames attempting to save to non-existent folders, prevent demo from creating infinite saves

This commit is contained in:
betalars 2025-05-26 19:43:26 +02:00
parent e46f407f41
commit 57e11162ef
2 changed files with 27 additions and 12 deletions

View File

@ -32,7 +32,17 @@ func load_room():
%Room.add_child(loaded_room)
func _on_start_button_pressed():
State.active_save_game = SaveGame.new()
var new_save = SaveGame.new()
if DirAccess.dir_exists_absolute( State.user_saves_path ):
var usr_dir = DirAccess.open(State.user_saves_path)
for path in usr_dir.get_files():
if path.ends_with(\".json\"):
var found_save: = SaveGame.new(\"%s/%s\" % [State.user_saves_path, path.get_basename()])
if found_save.is_demo:
new_save = found_save
break
State.active_save_game = new_save
var vis_tween = get_tree().create_tween()
vis_tween.tween_property(%Menu, \"modulate\", Color(1,1,1,0), .3)
await vis_tween.finished

View File

@ -35,6 +35,7 @@ var _is_initialised: bool = false
if _is_initialised: changed.emit()
@export var is_valid: bool = false
@export var is_demo: bool = OS.has_feature("Demo")
@export var is_empty: bool = true:
get():
return not FileAccess.file_exists("%s.json:" % filepath)
@ -54,19 +55,22 @@ func _validate_property(property: Dictionary):
func _init(initial_filepath = "") -> void:
if initial_filepath == "":
filepath = "%s/%s" % [State.user_saves_path, unique_save_name]
filepath = "%s/%s.json" % [State.user_saves_path, unique_save_name]
else:
filepath = initial_filepath
unique_save_name = initial_filepath.get_file()
read_save_file()
_is_initialised = true
if not DirAccess.dir_exists_absolute(filepath.get_base_dir()):
DirAccess.make_dir_absolute(filepath.get_base_dir())
func read_save_file():
print("Opening Savegame: %s.json" % filepath)
print("Opening Savegame: %s" % filepath)
if FileAccess.file_exists("%s.json" % filepath):
var file = FileAccess.open("%s.json" % filepath, FileAccess.READ)
var raw_json = FileAccess.get_file_as_string("%s.json" % filepath)
if FileAccess.file_exists(filepath):
var file = FileAccess.open(filepath, FileAccess.READ)
var raw_json = FileAccess.get_file_as_string(filepath)
file.close()
var parsed: Dictionary = JSON.parse_string(raw_json)
@ -80,7 +84,8 @@ func read_save_file():
parsed["current_room"] is float and
parsed["mementos_complete"] is float and
parsed["board_state"] is Dictionary and
parsed["last_saved"] is float and last_saved != 0
parsed["last_saved"] is float and
parsed["demo"] is bool and last_saved != 0
)
if are_types_valid:
@ -126,15 +131,15 @@ func _get_save_dict() -> Dictionary:
"current_room": current_room,
"mementos_complete": mementos_complete,
"board_state": board_state,
"last_saved": last_saved
"last_saved": last_saved,
"is_demo": is_demo
}
func save_to_file(current_screen: Texture):
# FIXME
if OS.has_feature("Demo") or OS.has_feature("Debug"): return
last_saved = Time.get_unix_time_from_system()
var thumbnail_image: Image = current_screen.get_image()
thumbnail_image.convert(Image.Format.FORMAT_RGB8)
thumbnail_image.linear_to_srgb()
thumbnail_image.resize(384, 261, Image.INTERPOLATE_LANCZOS) # nonexistent call in ViewportTexturew
var thumbnail_path: String = "%s/thumbnails/%s.png" % [filepath.get_base_dir(), unique_save_name]
@ -145,7 +150,7 @@ func save_to_file(current_screen: Texture):
thumbnail_image.save_png("%s/thumbnails/%s.png" % [filepath.get_base_dir(), unique_save_name])
#thumbnail_image.save_png("%s/test.png" % State.user_saves_path)
print(filepath.get_base_dir())
var file = FileAccess.open("%s.json" % filepath, FileAccess.WRITE)
var file = FileAccess.open(filepath, FileAccess.WRITE)
file.store_string(JSON.stringify(_get_save_dict()))
file.close()