aboutsummaryrefslogtreecommitdiff
path: root/game/src/SaveLoadMenu/SaveResource.gd
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-04-23 22:01:49 +0200
committer Spartan322 <Megacake1234@gmail.com>2023-05-12 13:32:21 +0200
commit8ab166ae0bd784145c3706aba0c3f3326cbbaac1 (patch)
treee4511c51eb4ceaefd92a7ad8a00f42910eb83811 /game/src/SaveLoadMenu/SaveResource.gd
parent398ba6f05ae1bb13e59790436bf0da299e5a399d (diff)
Add SaveManager autoload singleton
Globally handles save finding, creation, removal, changes, naming, and flushing Globally handles the session tags for the active save Add SaveLoadMenu to GameSession Add Start Date Panel and Save Panel loading to LobbyMenu Includes session tag filter Add LobbyPanelButton and SavePanelButton scene and scripts Add SaveResource to handle saving and loading individual save files Add localization for SaveLoadMenu Expand localization for additions to LobbyMenu Add ButtonContainer variation type to default theme Fulfill: UI-82, UI-83, UI-84, UI-85, UI-87, UI-89, UI-90, UI-91, UI-92, UI-94 UIFUN-82, UIFUN-83, UIFUN-84, UIFUN-86, UIFUN-87, UIFUN-89 FS-28
Diffstat (limited to 'game/src/SaveLoadMenu/SaveResource.gd')
-rw-r--r--game/src/SaveLoadMenu/SaveResource.gd59
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)