]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Resources/TimelineResourceLoader.gd
Squashed commit of the following:
[wolf-seeking-sheep.git] / addons / dialogic / Resources / TimelineResourceLoader.gd
1 @tool
2 class_name DialogicTimelineFormatLoader
3 extends ResourceFormatLoader
4
5
6 ## Returns all excepted extenstions
7 func _get_recognized_extensions() -> PackedStringArray:
8         return PackedStringArray(["dtl"])
9
10
11 ## Returns "Resource" if this file can/should be loaded by this script
12 func _get_resource_type(path: String) -> String:
13         var ext := path.get_extension().to_lower()
14         if ext == "dtl":
15                 return "Resource"
16
17         return ""
18
19
20 ## Returns the script class associated with a Resource
21 func _get_resource_script_class(path: String) -> String:
22         var ext := path.get_extension().to_lower()
23         if ext == "dtl":
24                 return "DialogicTimeline"
25
26         return ""
27
28
29 ## Return true if this type is handled
30 func _handles_type(typename: StringName) -> bool:
31         return ClassDB.is_parent_class(typename, "Resource")
32
33
34 ## Parse the file and return a resource
35 func _load(path: String, _original_path: String, _use_sub_threads: bool, _cache_mode: int) -> Variant:
36         var file := FileAccess.open(path, FileAccess.READ)
37
38         if not file:
39                 # For now, just let editor know that for some reason you can't
40                 # read the file.
41                 print("[Dialogic] Error opening file:", FileAccess.get_open_error())
42                 return FileAccess.get_open_error()
43
44         var tml := DialogicTimeline.new()
45         tml.from_text(file.get_as_text())
46         return tml