feat: Made dialogs pluggable (#424)
Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
@@ -62,6 +62,8 @@ func run(command_params: Array) -> int:
|
||||
)
|
||||
|
||||
escoria.event_manager.interrupt_running_event()
|
||||
if escoria.dialog_player:
|
||||
escoria.dialog_player.interrupt()
|
||||
|
||||
if !command_params[1]:
|
||||
escoria.main.scene_transition.transition(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# `say object text [type] [avatar]`
|
||||
# `say player text [type]`
|
||||
#
|
||||
# Runs the specified string as a dialog said by the object. Blocks execution
|
||||
# Runs the specified string as a dialog said by the player. Blocks execution
|
||||
# until the dialog finishes playing.
|
||||
#
|
||||
# The text supports translation keys by prepending the key and separating
|
||||
@@ -11,8 +11,6 @@
|
||||
# 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
|
||||
# "default"
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
@@ -23,42 +21,41 @@ class_name SayCommand
|
||||
func configure() -> ESCCommandArgumentDescriptor:
|
||||
return ESCCommandArgumentDescriptor.new(
|
||||
2,
|
||||
[TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_STRING],
|
||||
[TYPE_STRING, TYPE_STRING, TYPE_STRING],
|
||||
[
|
||||
null,
|
||||
null,
|
||||
ProjectSettings.get_setting("escoria/ui/default_dialog_scene")\
|
||||
.get_file().get_basename(),
|
||||
"default"
|
||||
ProjectSettings.get_setting("escoria/ui/default_dialog_type")
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
|
||||
# Validate wether the given arguments match the command descriptor
|
||||
func validate(arguments: Array):
|
||||
if not escoria.object_manager.objects.has(arguments[0]):
|
||||
escoria.logger.report_errors(
|
||||
"anim: invalid object",
|
||||
[
|
||||
"Object with global id %s not found." % arguments[0]
|
||||
]
|
||||
)
|
||||
return false
|
||||
if ProjectSettings.get_setting("escoria/ui/default_dialog_type") == "" \
|
||||
and arguments[2] == "":
|
||||
escoria.logger.report_errors(
|
||||
"say()",
|
||||
[
|
||||
"Project setting 'escoria/ui/default_dialog_type' is not set.",
|
||||
"Please set a default dialog type."
|
||||
]
|
||||
)
|
||||
return .validate(arguments)
|
||||
|
||||
|
||||
# Run the command
|
||||
func run(command_params: Array) -> int:
|
||||
|
||||
var dict: Dictionary
|
||||
var dialog_scene_name = ProjectSettings.get_setting(
|
||||
"escoria/ui/default_dialog_scene"
|
||||
)
|
||||
|
||||
if dialog_scene_name.empty():
|
||||
escoria.logger.report_errors(
|
||||
"say()",
|
||||
[
|
||||
"Project setting 'escoria/ui/default_dialog_scene' is not set.",
|
||||
"Please set a default dialog scene."
|
||||
]
|
||||
)
|
||||
return ESCExecution.RC_ERROR
|
||||
|
||||
var file = dialog_scene_name.get_file()
|
||||
var extension = dialog_scene_name.get_extension()
|
||||
dialog_scene_name = file.rstrip("." + extension)
|
||||
|
||||
# Manage specific dialog scene
|
||||
if command_params.size() > 2:
|
||||
dialog_scene_name = command_params[2]
|
||||
|
||||
escoria.current_state = escoria.GAME_STATE.DIALOG
|
||||
|
||||
@@ -74,9 +71,9 @@ func run(command_params: Array) -> int:
|
||||
|
||||
escoria.dialog_player.say(
|
||||
command_params[0],
|
||||
dialog_scene_name,
|
||||
command_params[2],
|
||||
command_params[1]
|
||||
)
|
||||
yield(escoria.dialog_player, "dialog_line_finished")
|
||||
yield(escoria.dialog_player, "say_finished")
|
||||
escoria.current_state = escoria.GAME_STATE.DEFAULT
|
||||
return ESCExecution.RC_OK
|
||||
|
||||
Reference in New Issue
Block a user