]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Resources/CharacterResourceSaver.gd
Squashed commit of the following:
[wolf-seeking-sheep.git] / addons / dialogic / Resources / CharacterResourceSaver.gd
1 @tool
2 class_name DialogicCharacterFormatSaver
3 extends ResourceFormatSaver
4
5
6 func _get_recognized_extensions(_resource: Resource) -> PackedStringArray:
7         return PackedStringArray(["dch"])
8
9
10 ## Return true if this resource should be loaded as a DialogicCharacter
11 func _recognize(resource: Resource) -> bool:
12         # Cast instead of using "is" keyword in case is a subclass
13         resource = resource as DialogicCharacter
14
15         if resource:
16                 return true
17
18         return false
19
20
21 ## Save the resource
22 func _save(resource: Resource, path: String = '', _flags: int = 0) -> Error:
23         var file := FileAccess.open(path, FileAccess.WRITE)
24
25         if not file:
26                 # For now, just let editor know that for some reason you can't
27                 # read the file.
28                 print("[Dialogic] Error opening file:", FileAccess.get_open_error())
29                 return FileAccess.get_open_error()
30
31         var result := var_to_str(inst_to_dict(resource))
32         file.store_string(result)
33 #       print('[Dialogic] Saved character "' , path, '"')
34         return OK