]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Resources/CharacterResourceLoader.gd
Initial Godot project with Dialogic 2.0-Alpha-17
[wolf-seeking-sheep.git] / addons / dialogic / Resources / CharacterResourceLoader.gd
1 @tool
2 class_name DialogicCharacterFormatLoader
3 extends ResourceFormatLoader
4
5
6
7 ## Returns all excepted extenstions
8 func _get_recognized_extensions() -> PackedStringArray:
9         return PackedStringArray(["dch"])
10
11
12 ## Returns "Resource" if this file can/should be loaded by this script
13 func _get_resource_type(path: String) -> String:
14         var ext := path.get_extension().to_lower()
15         if ext == "dch":
16                 return "Resource"
17
18         return ""
19
20
21 ## Returns the script class associated with a Resource
22 func _get_resource_script_class(path: String) -> String:
23         var ext := path.get_extension().to_lower()
24         if ext == "dch":
25                 return "DialogicCharacter"
26
27         return ""
28
29
30 ## Return true if this type is handled
31 func _handles_type(typename: StringName) -> bool:
32         return ClassDB.is_parent_class(typename, "Resource")
33
34
35 ## Parse the file and return a resource
36 func _load(path: String, _original_path: String, _use_sub_threads: bool, _cache_mode: int) -> Variant:
37 #       print('[Dialogic] Reimporting character "' , path, '"')
38         var file := FileAccess.open(path, FileAccess.READ)
39
40         if not file:
41                 # For now, just let editor know that for some reason you can't
42                 # read the file.
43                 print("[Dialogic] Error opening file:", FileAccess.get_open_error())
44                 return FileAccess.get_open_error()
45
46         return dict_to_inst(str_to_var(file.get_as_text()))
47
48
49 func _get_dependencies(path:String, _add_type:bool) -> PackedStringArray:
50         var depends_on: PackedStringArray = []
51         var character: DialogicCharacter = load(path)
52         for p in character.portraits.values():
53                 if 'path' in p and p.path:
54                         depends_on.append(p.path)
55         return depends_on
56
57
58 func _rename_dependencies(path: String, renames: Dictionary) -> Error:
59         var character: DialogicCharacter = load(path)
60         for p in character.portraits:
61                 if 'path' in character.portraits[p] and character.portraits[p].path in renames:
62                         character.portraits[p].path = renames[character.portraits[p].path]
63         ResourceSaver.save(character, path)
64         return OK