2 class_name DialogicCharacterFormatLoader
3 extends ResourceFormatLoader
7 ## Returns all excepted extenstions
8 func _get_recognized_extensions() -> PackedStringArray:
9 return PackedStringArray(["dch"])
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()
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()
25 return "DialogicCharacter"
30 ## Return true if this type is handled
31 func _handles_type(typename: StringName) -> bool:
32 return ClassDB.is_parent_class(typename, "Resource")
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)
41 # For now, just let editor know that for some reason you can't
43 print("[Dialogic] Error opening file:", FileAccess.get_open_error())
44 return FileAccess.get_open_error()
46 return dict_to_inst(str_to_var(file.get_as_text()))
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)
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)