|
|
@ -9,6 +9,8 @@ extends Node |
|
|
|
|
|
|
|
signal apply_complete |
|
|
|
signal apply_save ## Apply the loaded data to the tree. Note: This should happen AFTER load_save() |
|
|
|
signal autosave_start ## Autosave has started |
|
|
|
signal autosave_complete ## Autosave has completed |
|
|
|
signal create_auto_save |
|
|
|
signal create_save(save_name: String) |
|
|
|
signal delete_save(filename: String) |
|
|
@ -156,6 +158,32 @@ func _load_save_settings() -> bool: |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
## Increment autosave numbers and if we've reach max number of autosaves, remove the oldest one |
|
|
|
func _move_autosaves() -> void: |
|
|
|
var saves_dir = DirAccess.open(_save_game_settings.save_game_data_path) |
|
|
|
if saves_dir == null: |
|
|
|
DirAccess.make_dir_absolute(_save_game_settings.save_game_data_path) |
|
|
|
|
|
|
|
var autosaves: Array[String] = [] |
|
|
|
for filename in saves_dir.get_files(): |
|
|
|
if !filename.begins_with(_save_game_settings.autosave_file_name_prepend): continue |
|
|
|
if !filename.ends_with(".tres"): continue |
|
|
|
autosaves.append(filename) |
|
|
|
|
|
|
|
if autosaves.size() == _save_game_settings.max_auto_saves: # Delete oldest save |
|
|
|
DirAccess.remove_absolute(_save_game_settings.save_game_data_path + autosaves.pop_back()) |
|
|
|
|
|
|
|
var filepath: String = _save_game_settings.save_game_data_path + _save_game_settings.autosave_file_name_prepend |
|
|
|
for index in range(autosaves.size(), 0, -1): |
|
|
|
var old_save_path: String = "%s%02d.tres" % [filepath, index] |
|
|
|
var old_screenshot_path: String = "%s%02d.png" % [filepath, index] |
|
|
|
var new_save_path: String = "%s%02d.tres" % [filepath, index + 1] |
|
|
|
var new_screenshot_path: String = "%s%02d.png" % [filepath, index + 1] |
|
|
|
DirAccess.copy_absolute(old_save_path, new_save_path) |
|
|
|
|
|
|
|
if FileAccess.file_exists(old_screenshot_path): |
|
|
|
DirAccess.copy_absolute(old_screenshot_path, new_screenshot_path) |
|
|
|
|
|
|
|
func _save_game_as_resource(save_name, resource_filename: String) -> void: |
|
|
|
if not _load_save_settings(): return |
|
|
|
|
|
|
@ -200,6 +228,18 @@ func _on_apply_save() -> void: |
|
|
|
|
|
|
|
apply_complete.emit() |
|
|
|
|
|
|
|
func _on_autosave_timer_timeout() -> void: |
|
|
|
if not _load_save_settings(): return |
|
|
|
|
|
|
|
autosave_start.emit() |
|
|
|
|
|
|
|
_move_autosaves() |
|
|
|
|
|
|
|
var autosave_filename: String = _save_game_settings.autosave_file_name_prepend + "01.tres" |
|
|
|
_save_game_as_resource("Auto Save", autosave_filename) |
|
|
|
|
|
|
|
autosave_complete.emit() |
|
|
|
|
|
|
|
## Delete both the save file and the related screenshot |
|
|
|
func _on_delete_save(filename: String) -> void: |
|
|
|
if filename.length() < 1: |
|
|
@ -233,10 +273,6 @@ func _on_save_game_as_resource(save_name: String) -> void: |
|
|
|
_save_game_as_resource(save_name, _filename) |
|
|
|
save_complete.emit() |
|
|
|
|
|
|
|
func _on_toggle_save_icon_generation(toggled: bool) -> void: |
|
|
|
_enable_save_icon_generation = toggled |
|
|
|
|
|
|
|
|
|
|
|
func _on_start_autosave() -> void: |
|
|
|
if _save_game_settings == null: _load_save_settings() |
|
|
|
|
|
|
@ -254,3 +290,6 @@ func _on_stop_autosave() -> void: |
|
|
|
var autosave_timer: Timer = get_node_or_null("AutosaveTimer") |
|
|
|
if autosave_timer == null: return |
|
|
|
autosave_timer.stop() |
|
|
|
|
|
|
|
func _on_toggle_save_icon_generation(toggled: bool) -> void: |
|
|
|
_enable_save_icon_generation = toggled |