Makes ESCDialog and ESCDialogOption instantiable without an ESC string

and other dialog optimizations
Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
Dennis Ploeger
2021-11-11 22:55:35 +01:00
committed by GitHub
parent 907ba5f9d8
commit 1823845141
6 changed files with 40 additions and 33 deletions

View File

@@ -160,7 +160,8 @@ func _compile(lines: Array) -> Array:
group.statements = self._compile(group_lines)
returned.append(group)
elif dialog_regex.search(line):
var dialog = ESCDialog.new(line)
var dialog = ESCDialog.new()
dialog.load_string(line)
escoria.logger.trace("Line is a dialog")
var dialog_lines = []
while lines.size() > 0:
@@ -187,7 +188,8 @@ func _compile(lines: Array) -> Array:
lines.pop_front()
returned.append(dialog)
elif dialog_option_regex.search(line):
var dialog_option = ESCDialogOption.new(line)
var dialog_option = ESCDialogOption.new()
dialog_option.load_string(line)
escoria.logger.trace(
"Line is the dialog option %s" % \
dialog_option.option

View File

@@ -27,8 +27,11 @@ var timeout_option: int = 0
var options: Array
# Construct a dialog from a dialog string
func _init(dialog_string: String):
# Construct a dialog from an ESC dialog string
#
# #### Parameters
# - dialog_string: ESC dialog string
func load_string(dialog_string: String):
var dialog_regex = RegEx.new()
dialog_regex.compile(REGEX)

View File

@@ -16,8 +16,11 @@ var option: String setget ,get_option
var conditions: Array = []
# Create a dialog option from a string
func _init(option_string: String):
# Create a dialog option from an ESC string
#
# #### Parameter
# - option_string: ESC string for the dialog option
func load_string(option_string: String):
var option_regex = RegEx.new()
option_regex.compile(REGEX)

View File

@@ -438,16 +438,22 @@ func turn_to(object: Node, wait: float = 0.0):
# Play the talking animation
func start_talking():
if get_animation_player().is_playing():
get_animation_player().stop()
get_animation_player().play(animations.speaks[_movable.last_dir].animation)
if get_animation_player():
if get_animation_player().is_playing():
get_animation_player().stop()
get_animation_player().play(
animations.speaks[_movable.last_dir].animation
)
# Stop playing the talking animation
func stop_talking():
if get_animation_player().is_playing():
get_animation_player().stop()
get_animation_player().play(animations.idles[_movable.last_dir].animation)
if get_animation_player():
if get_animation_player().is_playing():
get_animation_player().stop()
get_animation_player().play(
animations.idles[_movable.last_dir].animation
)
# Detect the child nodes and set respective references

View File

@@ -64,12 +64,6 @@ func say(character: String, line: String) :
# Position the RichTextLabel on the character's dialog position, if any.
_current_character = escoria.object_manager.get_object(character).node
rect_position = _current_character.get_node("dialog_position") \
.get_global_transform_with_canvas().origin
rect_position.x -= rect_size.x / 2
# Start talking animation
_current_character.start_talking()
# Set text color to color set in the actor
var text_color = _current_character.dialog_color
@@ -78,6 +72,18 @@ func say(character: String, line: String) :
text_node.bbcode_text = "[center][color=#" + text_color_html + "]" \
.format([text_color_html]) + tr(line) + "[/color][center]"
if _current_character.is_inside_tree() and \
_current_character.has_node("dialog_position"):
rect_position = _current_character.get_node(
"dialog_position"
).get_global_transform_with_canvas().origin
rect_position.x -= rect_size.x / 2
else:
rect_position.x = 0
rect_size.x = ProjectSettings.get_setting("display/window/size/width")
_current_character.start_talking()
text_node.percent_visible = 0.0
var time_show_full_text = _text_speed_per_character * len(line)