diff options
author | George L. Albany <Megacake1234@gmail.com> | 2023-05-13 00:44:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-13 00:44:10 +0200 |
commit | 5b207ea57ec278daf5b8b44fdf72757fda1a7bd0 (patch) | |
tree | e4511c51eb4ceaefd92a7ad8a00f42910eb83811 /game/src/SaveLoadMenu/SaveResource.gd | |
parent | 398ba6f05ae1bb13e59790436bf0da299e5a399d (diff) | |
parent | 8ab166ae0bd784145c3706aba0c3f3326cbbaac1 (diff) |
Merge pull request #110 from Spartan322/add/save-and-load
Diffstat (limited to 'game/src/SaveLoadMenu/SaveResource.gd')
-rw-r--r-- | game/src/SaveLoadMenu/SaveResource.gd | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/game/src/SaveLoadMenu/SaveResource.gd b/game/src/SaveLoadMenu/SaveResource.gd new file mode 100644 index 0000000..5e7faa6 --- /dev/null +++ b/game/src/SaveLoadMenu/SaveResource.gd @@ -0,0 +1,59 @@ +extends Resource +class_name SaveResource + +signal file_flushed(path : String) +signal file_loaded +signal file_moved_to_trash +signal file_deleted +signal trash_moved +signal deleted + +var save_name : StringName: + get: return save_name + set(v): + save_name = v + file.set_value("Save", "name", save_name) + emit_changed() +var session_tag : StringName: + get: return session_tag + set(v): + session_tag = v + file.set_value("Save", "session_tag", v) + emit_changed() +var file_path : String: + get: return file_path + set(v): + file_path = v + emit_changed() +var file : ConfigFile = ConfigFile.new() + +func set_file_path(name : StringName, path : String): + file_path = path + save_name = name + +func flush_save() -> Error: + file_flushed.emit(file_path) + var result := file.save(file_path) + file.clear() + return result + +func load_save(path : String = file_path) -> Error: + file_loaded.emit() + var result := file.load(path) + session_tag = file.get_value("Save", "session_tag", session_tag) + if path != file_path: + set_file_path(file.get_value("Save", "name", save_name), path) + return result + +func get_save_file_time() -> int: + return FileAccess.get_modified_time(file_path) + +func move_to_trash() -> Error: + trash_moved.emit() + file_moved_to_trash.emit() + return OS.move_to_trash(file_path) + +func delete() -> Error: + deleted.emit() + file_deleted.emit() + return DirAccess.remove_absolute(file_path) |