Browse Source

Create the Autosave timer on _ready()

pull/19/head
Ryan Reed 3 months ago
parent
commit
150e01f11e
1 changed files with 23 additions and 24 deletions
  1. +23
    -24
      addons/save_load_system/autoloads/save_game_manager.gd

+ 23
- 24
addons/save_load_system/autoloads/save_game_manager.gd View File

@ -28,6 +28,7 @@ signal quick_load
signal toggle_save_icon_generation(toggled: bool) ## Enable/Disable the generation of a screenshot during save for the save icon.
var _autosave_timer: Timer = Timer.new()
var _enable_save_icon_generation: bool = true
var _loaded_save_resource: SaveGameDataResource = SaveGameDataResource.new()
var _save_game_settings: SaveGameSettings ## Contains the save paths, filename prepends, and other save settings
@ -45,6 +46,11 @@ func _ready() -> void:
stop_autosave.connect(_on_stop_autosave)
toggle_save_icon_generation.connect(_on_toggle_save_icon_generation)
_autosave_timer.name = "AutosaveTimer"
_autosave_timer.one_shot = false
_autosave_timer.timeout.connect(_on_autosave_timer_timeout)
add_child(_autosave_timer)
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("quick_save"):
quick_save.emit()
@ -96,6 +102,18 @@ func list_saves(include_quick_saves: bool = true, include_auto_saves: bool = tru
return save_files
func _create_autosave() -> 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()
## Sort the save files list by date created, descending
func _custom_save_file_sort(a: SaveFileDetailsResource, b: SaveFileDetailsResource) -> bool:
return a.date_created > b.date_created
@ -229,16 +247,7 @@ 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()
_create_autosave()
## Delete both the save file and the related screenshot
func _on_delete_save(filename: String) -> void:
@ -274,22 +283,12 @@ func _on_save_game_as_resource(save_name: String) -> void:
save_complete.emit()
func _on_start_autosave() -> void:
if _save_game_settings == null: _load_save_settings()
var autosave_timer: Timer = get_node_or_null("AutosaveTimer")
if autosave_timer == null:
autosave_timer = Timer.new()
autosave_timer.name = "AutosaveTimer"
autosave_timer.one_shot = false
autosave_timer.timeout.connect(_on_autosave_timer_timeout)
add_child(autosave_timer)
autosave_timer.start(_save_game_settings.autosave_duration)
if _save_game_settings == null:
_load_save_settings()
_autosave_timer.start(_save_game_settings.autosave_duration)
func _on_stop_autosave() -> void:
var autosave_timer: Timer = get_node_or_null("AutosaveTimer")
if autosave_timer == null: return
autosave_timer.stop()
_autosave_timer.stop()
func _on_toggle_save_icon_generation(toggled: bool) -> void:
_enable_save_icon_generation = toggled

Loading…
Cancel
Save