2 class_name DialogicTimelineFormatSaver
3 extends ResourceFormatSaver
6 func _get_recognized_extensions(_resource: Resource) -> PackedStringArray:
7 return PackedStringArray(["dtl"])
10 ## Return true if this resource should be loaded as a DialogicTimeline
11 func _recognize(resource: Resource) -> bool:
12 # Cast instead of using "is" keyword in case is a subclass
13 resource = resource as DialogicTimeline
22 ## TODO: This should use timeline.as_text(), why is this still here?
23 func _save(resource: Resource, path: String = '', _flags: int = 0) -> Error:
24 if resource.get_meta("timeline_not_saved", false):
26 var timeline_as_text := ""
27 # if events are resources, create text
28 if resource.events_processed:
31 for idx in range(0, len(resource.events)):
32 if resource.events[idx]:
33 var event: DialogicEvent = resource.events[idx]
34 if event.event_name == 'End Branch':
38 for i in event.empty_lines_above:
39 timeline_as_text += '\t'.repeat(indent) + '\n'
42 timeline_as_text += "\t".repeat(indent)+ event.event_node_as_text + "\n"
43 if event.can_contain_events:
48 # if events are string lines, just save them
50 for event in resource.events:
51 timeline_as_text += event + "\n"
53 # Now do the actual saving
54 var file := FileAccess.open(path, FileAccess.WRITE)
56 print("[Dialogic] Error opening file:", FileAccess.get_open_error())
58 file.store_string(timeline_as_text)