1 extends DialogicSubsystem
3 ## Subsystem that holds methods for jumping to specific labels, or return to the previous jump.
5 signal switched_timeline(info:Dictionary)
6 signal jumped_to_label(info:Dictionary)
7 signal returned_from_jump(info:Dictionary)
8 signal passed_label(info:Dictionary)
12 ####################################################################################################
14 func clear_game_state(_clear_flag:=DialogicGameHandler.ClearFlags.FULL_CLEAR) -> void:
15 dialogic.current_state_info['jump_stack'] = []
16 dialogic.current_state_info.erase("last_label")
19 func load_game_state(_load_flag:=LoadFlags.FULL_LOAD) -> void:
20 if not 'jump_stack' in dialogic.current_state_info:
21 dialogic.current_state_info['jump_stack'] = []
26 #region MAIN METHODS JUMP
27 ####################################################################################################
29 func jump_to_label(label:String) -> void:
31 dialogic.current_event_idx = 0
32 jumped_to_label.emit({'timeline':dialogic.current_timeline, 'label':"TOP"})
38 var event: Variant = dialogic.current_timeline.get_event(idx)
40 idx = dialogic.current_event_idx
42 if event is DialogicLabelEvent and event.name == label:
44 dialogic.current_event_idx = idx-1
45 jumped_to_label.emit({'timeline':dialogic.current_timeline, 'label':label})
48 func push_to_jump_stack() -> void:
49 dialogic.current_state_info['jump_stack'].push_back({'timeline':dialogic.current_timeline, 'index':dialogic.current_event_idx, 'label':dialogic.current_timeline_events[dialogic.current_event_idx].label_name})
52 func resume_from_last_jump() -> void:
53 var sub_timeline: DialogicTimeline = dialogic.current_timeline
54 var stack_info: Dictionary = dialogic.current_state_info['jump_stack'].pop_back()
55 dialogic.start_timeline(stack_info.timeline, stack_info.index+1)
56 returned_from_jump.emit({'sub_timeline':sub_timeline, 'label':stack_info.label})
59 func is_jump_stack_empty() -> bool:
60 return len(dialogic.current_state_info['jump_stack']) < 1
65 #region MAIN MEHTODS LABELS
66 ####################################################################################################
68 func _ready() -> void:
69 passed_label.connect(_on_passed_label)
72 func _on_passed_label(info:Dictionary) -> void:
73 dialogic.current_state_info["last_label"] = info
76 ## Returns the identifier name of the last passed label
77 func get_last_label_identifier() -> String:
78 if not dialogic.current_state_info.has("last_label"):
81 return dialogic.current_state_info["last_label"].identifier
84 ## Returns the display name of the last passed label (translated if translation are enabled)
85 func get_last_label_name() -> String:
86 if not dialogic.current_state_info.has("last_label"):
89 return dialogic.current_state_info["last_label"].display_name