Browse Source

Initial work toward autosaves

pull/19/head
Ryan Reed 3 months ago
parent
commit
aac4dbb1d9
3 changed files with 37 additions and 2 deletions
  1. +25
    -2
      addons/save_load_system/autoloads/save_game_manager.gd
  2. +2
    -0
      addons/save_load_system/resources/save_game_settings_resource.gd
  3. +10
    -0
      scenes/world/world.gd

+ 25
- 2
addons/save_load_system/autoloads/save_game_manager.gd View File

@ -18,6 +18,8 @@ signal load_error(error_message: String)
signal load_save(filename: String) ## Loads the save into memory. Does NOT apply the load as this allows for other actions (such as resetting the levle/world).[br]Don't forget to run `apply_save` after loading
signal save_complete
signal save_error(error_message: String)
signal start_autosave
signal stop_autosave
signal quick_save
signal quick_load
@ -37,13 +39,15 @@ func _ready() -> void:
load_save.connect(_on_load_game_save)
quick_load.connect(_on_quick_load)
quick_save.connect(_on_quick_save)
start_autosave.connect(_on_start_autosave)
stop_autosave.connect(_on_stop_autosave)
toggle_save_icon_generation.connect(_on_toggle_save_icon_generation)
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("quick_save"):
_on_quick_save()
quick_save.emit()
if event.is_action_pressed("quick_load"):
_on_quick_load()
quick_load.emit()
func list_saves(include_quick_saves: bool = true, include_auto_saves: bool = true) -> Array[SaveFileDetailsResource]:
@ -231,3 +235,22 @@ func _on_save_game_as_resource(save_name: String) -> void:
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()
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)
func _on_stop_autosave() -> void:
var autosave_timer: Timer = get_node_or_null("AutosaveTimer")
if autosave_timer == null: return
autosave_timer.stop()

+ 2
- 0
addons/save_load_system/resources/save_game_settings_resource.gd View File

@ -10,6 +10,8 @@ extends Resource
@export var save_game_data_path: String = "user://game_data/"
@export var max_auto_saves: int = 5
@export var autosave_duration: int = 60 ## How often, in seconds, should an autosave run[br]SaveGameManager will NOT autostart the autosave timer. This must be done by the world/scene.
@export var save_file_name_prepend: String = "save_"
@export var quicksave_file_name_prepend: String = "quicksave_"
@export var autosave_file_name_prepend: String = "autosave_"


+ 10
- 0
scenes/world/world.gd View File

@ -16,9 +16,12 @@ func _ready() -> void:
EntityManager.reset_world.connect(clear_world)
EntityManager.spawn_player.connect(spawn_player)
SaveGameManager.load_complete.connect(_on_load_save_complete)
SignalManager.open_pause_menu.connect(_on_open_pause_menu)
SignalManager.resume_game.connect(_on_resume_game)
clear_world()
create_world()
SaveGameManager.start_autosave.emit()
## For resetting/emptying the world to allow for load_game or generating a new world
func clear_world() -> void:
@ -87,3 +90,10 @@ func _on_reset_world() -> void:
func _on_load_save_complete() -> void:
clear_world()
SaveGameManager.apply_save.emit()
SaveGameManager.start_autosave.emit()
func _on_open_pause_menu() -> void:
SaveGameManager.stop_autosave.emit()
func _on_resume_game() -> void:
SaveGameManager.start_autosave.emit()

Loading…
Cancel
Save