Skip to content

Commit 3e7eca8

Browse files
authored
Merge pull request #29 from nndda/dev
0.6.1
2 parents 9c688d6 + 798376e commit 3e7eca8

15 files changed

+644
-145
lines changed

addons/Theatre/classes/Dialogue.gd

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ extends Resource
88
## Load it from the text file with [method Dialogue.load], or write it directly in script using [method Dialogue.new]
99
## [codeblock]
1010
## var dlg = Dialogue.load("res://your_dialogue.dlg")
11-
##
11+
## # or
1212
## var dlg = Dialogue.new("""
1313
##
1414
## Godette:
1515
## "Hello world!"
1616
##
1717
## """)
1818
## [/codeblock]
19+
##
20+
## @tutorial(Dialogue Syntax): https://nndda.github.io/Theatre/class/dialogue/syntax/
21+
## @tutorial(Theatre's tutorial page): https://nndda.github.io/Theatre/tutorials/
1922

2023
#region NOTE: Stored variables ---------------------------------------------------------------------
2124
@export_storage var _sets : Array[Dictionary] = []
@@ -82,11 +85,9 @@ func get_source_path() -> String:
8285
## Returns word count in the compiled [Dialogue]. Optionally pass [param variables] to insert
8386
## variables used by the [Dialogue], otherwise it will count any variable placeholder as 1 word.
8487
func get_word_count(variables : Dictionary = {}) -> int:
85-
var regex := RegEx.new()
86-
regex.compile(r"\w+")
87-
88-
# is it really any better?
89-
return regex.search_all(_strip(
88+
return RegEx \
89+
.create_from_string(r"\w+") \
90+
.search_all(_strip(
9091
variables.merged(Stage._VARIABLES_BUILT_IN),
9192
true, true
9293
)).size()
@@ -104,13 +105,13 @@ func get_sections() -> Dictionary:
104105

105106
func _update_used_function_calls() -> void:
106107
for n : Dictionary in _sets:
107-
for m : Dictionary in n["func"]:
108-
if !_used_function_calls.has(m["caller"]):
109-
_used_function_calls[m["caller"]] = {}
108+
for m : Dictionary in n[DialogueParser.__FUNC]:
109+
if !_used_function_calls.has(m[DialogueParser.__CALLER]):
110+
_used_function_calls[m[DialogueParser.__CALLER]] = {}
110111

111-
_used_function_calls[m["caller"]][m["ln_num"]] = {
112-
"name": m["name"],
113-
"args": m["args"],
112+
_used_function_calls[m[DialogueParser.__CALLER]][m[DialogueParser.__LN_NUM]] = {
113+
DialogueParser.__NAME: m[DialogueParser.__NAME],
114+
DialogueParser.__ARGS: m[DialogueParser.__ARGS],
114115
}
115116

116117
## Gets all variables used in the written [Dialogue].
@@ -119,7 +120,7 @@ func get_variables() -> PackedStringArray:
119120

120121
func _update_used_variables() -> void:
121122
for n : Dictionary in _sets:
122-
for m : String in n["vars"]:
123+
for m : String in n[DialogueParser.__VARS]:
123124
if not m in _used_variables:
124125
_used_variables.append(m)
125126

@@ -145,8 +146,7 @@ func _strip(
145146
) + n.line + newline + newline
146147

147148
# Strip BBCode tags
148-
for bb in DialogueParser._regex_bbcode_tags.search_all(output):
149-
output = output.replace(bb.strings[0], DialogueParser.EMPTY)
149+
output = DialogueParser._regex_bbcode_tags.sub(output, DialogueParser.EMPTY, true)
150150

151151
return output.format(variables)
152152

addons/Theatre/classes/DialogueLabel.gd

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ extends RichTextLabel
55

66
## Control node built for displaying [Dialogue].
77
##
8+
## @tutorial(Theatre's tutorial page): https://nndda.github.io/Theatre/tutorials/
9+
##
810
## A [RichTextLabel] inherited node that are built for displaying and rendering [Dialogue] lines.
911
## [DialogueLabel] has a partial support for BBCode tags, as for now, the [code][img][/code] tag are not supported.
1012
## [member RichTextLabel.bbcode_enabled] will always be [code]true[/code].
@@ -105,9 +107,9 @@ func start_render() -> void:
105107
_current_stage.speed_scale_global / _current_stage.speed_scale
106108
_characters_ticker.start(_characters_draw_tick_scaled)
107109

108-
_delay_queue = _current_stage._current_dialogue_set["tags"]["delays"].keys()
109-
_speed_queue = _current_stage._current_dialogue_set["tags"]["speeds"].keys()
110-
_func_queue = _current_stage._current_dialogue_set["func_pos"].keys()
110+
_delay_queue = _current_stage._current_dialogue_set[DialogueParser.__TAGS][DialogueParser.__TAGS_DELAYS].keys()
111+
_speed_queue = _current_stage._current_dialogue_set[DialogueParser.__TAGS][DialogueParser.__TAGS_SPEEDS].keys()
112+
_func_queue = _current_stage._current_dialogue_set[DialogueParser.__FUNC_POS].keys()
111113
_is_rendering = true
112114

113115
## Stop the process of rendering text, and clear the [DialogueLabel] text.
@@ -149,8 +151,8 @@ func _characters_ticker_timeout() -> void:
149151
if _func_queue[0] == visible_characters:
150152
if _current_stage.allow_func:
151153
_current_stage._call_functions(
152-
_current_stage._current_dialogue_set["func"][
153-
_current_stage._current_dialogue_set["func_pos"][_func_queue[0]]
154+
_current_stage._current_dialogue_set[DialogueParser.__FUNC][
155+
_current_stage._current_dialogue_set[DialogueParser.__FUNC_POS][_func_queue[0]]
154156
]
155157
)
156158
_func_queue.remove_at(0)
@@ -159,15 +161,15 @@ func _characters_ticker_timeout() -> void:
159161
if _delay_queue[0] == visible_characters:
160162
_characters_ticker.stop()
161163
_delay_timer.start(
162-
_current_stage._current_dialogue_set["tags"]["delays"][_delay_queue[0]]
164+
_current_stage._current_dialogue_set[DialogueParser.__TAGS][DialogueParser.__TAGS_DELAYS][_delay_queue[0]]
163165
)
164166
return
165167

166168
if !_speed_queue.is_empty():
167169
if _speed_queue[0] == visible_characters:
168170
_characters_ticker.wait_time = _characters_draw_tick_scaled /\
169171
_current_stage.speed_scale_global /\
170-
_current_stage._current_dialogue_set["tags"]["speeds"][_speed_queue[0]]
172+
_current_stage._current_dialogue_set[DialogueParser.__TAGS][DialogueParser.__TAGS_SPEEDS][_speed_queue[0]]
171173
_characters_ticker.start()
172174
_speed_queue.remove_at(0)
173175

@@ -191,8 +193,8 @@ func _delay_timer_timeout() -> void:
191193
func _on_stage_skipped() -> void:
192194
for f in _func_queue:
193195
_current_stage._call_functions(
194-
_current_stage._current_dialogue_set["func"][
195-
_current_stage._current_dialogue_set["func_pos"][f]
196+
_current_stage._current_dialogue_set[DialogueParser.__FUNC][
197+
_current_stage._current_dialogue_set[DialogueParser.__FUNC_POS][f]
196198
]
197199
)
198200
text_rendered.emit(text)

0 commit comments

Comments
 (0)