Skip to content

Commit

Permalink
Merge pull request #29 from nndda/dev
Browse files Browse the repository at this point in the history
0.6.1
  • Loading branch information
nndda authored Sep 25, 2024
2 parents 9c688d6 + 798376e commit 3e7eca8
Show file tree
Hide file tree
Showing 15 changed files with 644 additions and 145 deletions.
30 changes: 15 additions & 15 deletions addons/Theatre/classes/Dialogue.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ extends Resource
## Load it from the text file with [method Dialogue.load], or write it directly in script using [method Dialogue.new]
## [codeblock]
## var dlg = Dialogue.load("res://your_dialogue.dlg")
##
## # or
## var dlg = Dialogue.new("""
##
## Godette:
## "Hello world!"
##
## """)
## [/codeblock]
##
## @tutorial(Dialogue Syntax): https://nndda.github.io/Theatre/class/dialogue/syntax/
## @tutorial(Theatre's tutorial page): https://nndda.github.io/Theatre/tutorials/

#region NOTE: Stored variables ---------------------------------------------------------------------
@export_storage var _sets : Array[Dictionary] = []
Expand Down Expand Up @@ -82,11 +85,9 @@ func get_source_path() -> String:
## Returns word count in the compiled [Dialogue]. Optionally pass [param variables] to insert
## variables used by the [Dialogue], otherwise it will count any variable placeholder as 1 word.
func get_word_count(variables : Dictionary = {}) -> int:
var regex := RegEx.new()
regex.compile(r"\w+")

# is it really any better?
return regex.search_all(_strip(
return RegEx \
.create_from_string(r"\w+") \
.search_all(_strip(
variables.merged(Stage._VARIABLES_BUILT_IN),
true, true
)).size()
Expand All @@ -104,13 +105,13 @@ func get_sections() -> Dictionary:

func _update_used_function_calls() -> void:
for n : Dictionary in _sets:
for m : Dictionary in n["func"]:
if !_used_function_calls.has(m["caller"]):
_used_function_calls[m["caller"]] = {}
for m : Dictionary in n[DialogueParser.__FUNC]:
if !_used_function_calls.has(m[DialogueParser.__CALLER]):
_used_function_calls[m[DialogueParser.__CALLER]] = {}

_used_function_calls[m["caller"]][m["ln_num"]] = {
"name": m["name"],
"args": m["args"],
_used_function_calls[m[DialogueParser.__CALLER]][m[DialogueParser.__LN_NUM]] = {
DialogueParser.__NAME: m[DialogueParser.__NAME],
DialogueParser.__ARGS: m[DialogueParser.__ARGS],
}

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

func _update_used_variables() -> void:
for n : Dictionary in _sets:
for m : String in n["vars"]:
for m : String in n[DialogueParser.__VARS]:
if not m in _used_variables:
_used_variables.append(m)

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

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

return output.format(variables)

Expand Down
20 changes: 11 additions & 9 deletions addons/Theatre/classes/DialogueLabel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ extends RichTextLabel

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

_delay_queue = _current_stage._current_dialogue_set["tags"]["delays"].keys()
_speed_queue = _current_stage._current_dialogue_set["tags"]["speeds"].keys()
_func_queue = _current_stage._current_dialogue_set["func_pos"].keys()
_delay_queue = _current_stage._current_dialogue_set[DialogueParser.__TAGS][DialogueParser.__TAGS_DELAYS].keys()
_speed_queue = _current_stage._current_dialogue_set[DialogueParser.__TAGS][DialogueParser.__TAGS_SPEEDS].keys()
_func_queue = _current_stage._current_dialogue_set[DialogueParser.__FUNC_POS].keys()
_is_rendering = true

## Stop the process of rendering text, and clear the [DialogueLabel] text.
Expand Down Expand Up @@ -149,8 +151,8 @@ func _characters_ticker_timeout() -> void:
if _func_queue[0] == visible_characters:
if _current_stage.allow_func:
_current_stage._call_functions(
_current_stage._current_dialogue_set["func"][
_current_stage._current_dialogue_set["func_pos"][_func_queue[0]]
_current_stage._current_dialogue_set[DialogueParser.__FUNC][
_current_stage._current_dialogue_set[DialogueParser.__FUNC_POS][_func_queue[0]]
]
)
_func_queue.remove_at(0)
Expand All @@ -159,15 +161,15 @@ func _characters_ticker_timeout() -> void:
if _delay_queue[0] == visible_characters:
_characters_ticker.stop()
_delay_timer.start(
_current_stage._current_dialogue_set["tags"]["delays"][_delay_queue[0]]
_current_stage._current_dialogue_set[DialogueParser.__TAGS][DialogueParser.__TAGS_DELAYS][_delay_queue[0]]
)
return

if !_speed_queue.is_empty():
if _speed_queue[0] == visible_characters:
_characters_ticker.wait_time = _characters_draw_tick_scaled /\
_current_stage.speed_scale_global /\
_current_stage._current_dialogue_set["tags"]["speeds"][_speed_queue[0]]
_current_stage._current_dialogue_set[DialogueParser.__TAGS][DialogueParser.__TAGS_SPEEDS][_speed_queue[0]]
_characters_ticker.start()
_speed_queue.remove_at(0)

Expand All @@ -191,8 +193,8 @@ func _delay_timer_timeout() -> void:
func _on_stage_skipped() -> void:
for f in _func_queue:
_current_stage._call_functions(
_current_stage._current_dialogue_set["func"][
_current_stage._current_dialogue_set["func_pos"][f]
_current_stage._current_dialogue_set[DialogueParser.__FUNC][
_current_stage._current_dialogue_set[DialogueParser.__FUNC_POS][f]
]
)
text_rendered.emit(text)
Expand Down
Loading

0 comments on commit 3e7eca8

Please sign in to comment.