aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/Menu/SaveLoadMenu/SaveResource.gd
blob: 63cfd7fea611d7a62e699fe95f6a44fe8b3e9527 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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) -> void:
   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)