]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Core/event_end_branch.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Core / event_end_branch.gd
1 @tool
2 class_name DialogicEndBranchEvent
3 extends DialogicEvent
4
5 ## Event that indicates the end of a condition or choice (or custom branch).
6 ## In text this is not stored (only as a change in indentation).
7
8
9 #region EXECUTE
10 ################################################################################
11
12 func _execute() -> void:
13         dialogic.current_event_idx = find_next_index()-1
14         finish()
15
16
17 func find_next_index() -> int:
18         var idx: int = dialogic.current_event_idx
19
20         var ignore: int = 1
21         while true:
22                 idx += 1
23                 var event: DialogicEvent = dialogic.current_timeline.get_event(idx)
24                 if not event:
25                         return idx
26                 if event is DialogicEndBranchEvent:
27                         if ignore > 1:
28                                 ignore -= 1
29                 elif event.can_contain_events and not event.should_execute_this_branch():
30                         ignore += 1
31                 elif ignore <= 1:
32                         return idx
33
34         return idx
35
36
37 func find_opening_index(at_index:int) -> int:
38         var idx: int = at_index
39
40         var ignore: int = 1
41         while true:
42                 idx -= 1
43                 var event: DialogicEvent = dialogic.current_timeline.get_event(idx)
44                 if not event:
45                         return idx
46                 if event is DialogicEndBranchEvent:
47                         ignore += 1
48                 elif event.can_contain_events:
49                         ignore -= 1
50                         if ignore == 0:
51                                 return idx
52
53         return idx
54 #endregion
55
56 #region INITIALIZE
57 ################################################################################
58
59 func _init() -> void:
60         event_name = "End Branch"
61         disable_editor_button = true
62
63 #endregion
64
65 #region SAVING/LOADING
66 ################################################################################
67
68 ## NOTE: This event is very special. It is rarely stored at all, as it is usually
69 ## just a placeholder for removing an indentation level.
70 ## When copying events however, some representation of this is necessary. That's why this is half-implemented.
71 func to_text() -> String:
72         return "<<END BRANCH>>"
73
74
75 func from_text(_string:String) -> void:
76         pass
77
78
79 func is_valid_event(string:String) -> bool:
80         if string.strip_edges().begins_with("<<END BRANCH>>"):
81                 return true
82         return false