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:
parent
e46f407f41
commit
57e11162ef
|
|
@ -32,7 +32,17 @@ func load_room():
|
||||||
%Room.add_child(loaded_room)
|
%Room.add_child(loaded_room)
|
||||||
|
|
||||||
func _on_start_button_pressed():
|
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()
|
var vis_tween = get_tree().create_tween()
|
||||||
vis_tween.tween_property(%Menu, \"modulate\", Color(1,1,1,0), .3)
|
vis_tween.tween_property(%Menu, \"modulate\", Color(1,1,1,0), .3)
|
||||||
await vis_tween.finished
|
await vis_tween.finished
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ var _is_initialised: bool = false
|
||||||
if _is_initialised: changed.emit()
|
if _is_initialised: changed.emit()
|
||||||
|
|
||||||
@export var is_valid: bool = false
|
@export var is_valid: bool = false
|
||||||
|
@export var is_demo: bool = OS.has_feature("Demo")
|
||||||
@export var is_empty: bool = true:
|
@export var is_empty: bool = true:
|
||||||
get():
|
get():
|
||||||
return not FileAccess.file_exists("%s.json:" % filepath)
|
return not FileAccess.file_exists("%s.json:" % filepath)
|
||||||
|
|
@ -54,19 +55,22 @@ func _validate_property(property: Dictionary):
|
||||||
|
|
||||||
func _init(initial_filepath = "") -> void:
|
func _init(initial_filepath = "") -> void:
|
||||||
if initial_filepath == "":
|
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:
|
else:
|
||||||
filepath = initial_filepath
|
filepath = initial_filepath
|
||||||
unique_save_name = initial_filepath.get_file()
|
unique_save_name = initial_filepath.get_file()
|
||||||
read_save_file()
|
read_save_file()
|
||||||
_is_initialised = true
|
_is_initialised = true
|
||||||
|
|
||||||
func read_save_file():
|
if not DirAccess.dir_exists_absolute(filepath.get_base_dir()):
|
||||||
print("Opening Savegame: %s.json" % filepath)
|
DirAccess.make_dir_absolute(filepath.get_base_dir())
|
||||||
|
|
||||||
if FileAccess.file_exists("%s.json" % filepath):
|
func read_save_file():
|
||||||
var file = FileAccess.open("%s.json" % filepath, FileAccess.READ)
|
print("Opening Savegame: %s" % filepath)
|
||||||
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()
|
file.close()
|
||||||
var parsed: Dictionary = JSON.parse_string(raw_json)
|
var parsed: Dictionary = JSON.parse_string(raw_json)
|
||||||
|
|
||||||
|
|
@ -80,7 +84,8 @@ func read_save_file():
|
||||||
parsed["current_room"] is float and
|
parsed["current_room"] is float and
|
||||||
parsed["mementos_complete"] is float and
|
parsed["mementos_complete"] is float and
|
||||||
parsed["board_state"] is Dictionary 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:
|
if are_types_valid:
|
||||||
|
|
@ -126,15 +131,15 @@ func _get_save_dict() -> Dictionary:
|
||||||
"current_room": current_room,
|
"current_room": current_room,
|
||||||
"mementos_complete": mementos_complete,
|
"mementos_complete": mementos_complete,
|
||||||
"board_state": board_state,
|
"board_state": board_state,
|
||||||
"last_saved": last_saved
|
"last_saved": last_saved,
|
||||||
|
"is_demo": is_demo
|
||||||
}
|
}
|
||||||
|
|
||||||
func save_to_file(current_screen: Texture):
|
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()
|
last_saved = Time.get_unix_time_from_system()
|
||||||
|
|
||||||
var thumbnail_image: Image = current_screen.get_image()
|
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
|
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]
|
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/thumbnails/%s.png" % [filepath.get_base_dir(), unique_save_name])
|
||||||
#thumbnail_image.save_png("%s/test.png" % State.user_saves_path)
|
#thumbnail_image.save_png("%s/test.png" % State.user_saves_path)
|
||||||
print(filepath.get_base_dir())
|
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.store_string(JSON.stringify(_get_save_dict()))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue