Issue 336 (#380)

Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
Co-authored-by: dploeger <dploeger@users.noreply.github.com>
This commit is contained in:
Dennis Ploeger
2021-08-30 20:57:25 +02:00
committed by GitHub
parent 3b36031f24
commit 3dc779311c
35 changed files with 389 additions and 254 deletions

View File

@@ -18,6 +18,7 @@ func _test_basic() -> bool:
>
say player "Test5"
say player "Test 6"
say player TEST:"Test 7"
"""
var script = escoria.esc_compiler.compile(esc.split("\n"))
@@ -70,12 +71,17 @@ func _test_basic() -> bool:
subject = script.events["test"].statements[1]
assert(subject is ESCGroup)
assert(subject.statements.size() == 2)
assert(subject.statements.size() == 3)
subject = script.events["test"].statements[1].statements[1]
assert(subject is ESCCommand)
assert(subject.name == "say")
assert(subject.parameters[1] == "Test 6")
assert(subject.parameters[1] == "Test 6")
subject = script.events["test"].statements[1].statements[2]
assert(subject is ESCCommand)
assert(subject.name == "say")
assert(subject.parameters[1] == "TEST:Test 7")
return true
@@ -222,6 +228,8 @@ func _test_dialog() -> bool:
- "Option 3"
>
say player "test3"
- TEST:"Option 4"
say player "test4"
!
"""
var script = escoria.esc_compiler.compile(esc.split("\n"))
@@ -230,7 +238,7 @@ func _test_dialog() -> bool:
assert(subject.size() == 1)
assert(subject[0] is ESCDialog)
assert(subject[0].options.size() == 3)
assert(subject[0].options.size() == 4)
subject = script.events["test"].statements[0].options[0]
assert(subject is ESCDialogOption)
@@ -276,6 +284,10 @@ func _test_dialog() -> bool:
assert(subject[0].statements[0] is ESCCommand)
assert(subject[0].statements[0].parameters.size() == 2)
subject = script.events["test"].statements[0].options[3]
assert(subject is ESCDialogOption)
assert(subject.option == "TEST:Option 4")
return true

View File

@@ -1,7 +1,14 @@
# `say object text [type] [avatar]`
#
# Runs the specified string as a dialog said by the object. Blocks execution
# until the dialog finishes playing. Optional parameters:
# until the dialog finishes playing.
#
# The text supports translation keys by prepending the key and separating
# it with a `:` from the text.
#
# Example: `say player ROOM1_PICTURE:"Picture's looking good."`
#
# Optional parameters:
#
# * "type" determines the type of dialog UI to use. Default value is "default"
# * "avatar" determines the avatar to use for the dialog. Default value is
@@ -64,11 +71,15 @@ func run(command_params: Array) -> int:
]
)
return ESCExecution.RC_ERROR
var _line = command_params[1]
if ":" in _line:
_line = tr(_line.split(":")[0])
escoria.dialog_player.say(
command_params[0],
dialog_scene_name,
command_params[1]
_line
)
yield(escoria.dialog_player, "dialog_line_finished")
return ESCExecution.RC_OK

View File

@@ -46,6 +46,9 @@ func _init(command_string):
parameters.append(
parameter.substr(1, parameter.length() - 2)
)
elif ":" in parameter and '"' in parameter:
quote_open = true
parameter_values.append(parameter.replace('"', ''))
elif parameter.begins_with('"'):
quote_open = true
parameter_values.append(parameter.substr(1))

View File

@@ -5,11 +5,12 @@ class_name ESCDialogOption
# Regex that matches dialog option lines
const REGEX = \
'^[^-]*- "(?<option>[^"]+)"( \\[(?<conditions>[^\\]]+)\\])?$'
'^[^-]*- (?<trans_key>[^:]+)?:?"' +\
'(?<option>[^"]+)"( \\[(?<conditions>[^\\]]+)\\])?$'
# Option displayed in the HUD
var option: String
var option: String setget ,get_option
# Conditions to show this dialog
var conditions: Array = []
@@ -23,7 +24,14 @@ func _init(option_string: String):
if option_regex.search(option_string):
for result in option_regex.search_all(option_string):
if "option" in result.names:
self.option = escoria.utils.get_re_group(result, "option")
var _trans_key = ""
if "trans_key" in result.names:
_trans_key = "%s:" % \
escoria.utils.get_re_group(result, "trans_key")
self.option = "%s%s" % [
_trans_key,
escoria.utils.get_re_group(result, "option")
]
if "conditions" in result.names:
for condition_text in escoria.utils.get_re_group(
result,
@@ -41,6 +49,12 @@ func _init(option_string: String):
)
func get_option():
if ":" in option:
return tr(option.split(":")[0])
return option
# Check, if conditions match
func is_valid() -> bool:
for condition in self.conditions: