feat: say_last_dialog_option command

This commit is contained in:
2023-10-13 02:41:43 +02:00
parent 937e0fd8d3
commit 275458a8a4
8 changed files with 75 additions and 18 deletions

View File

@@ -0,0 +1,50 @@
# `say_last_dialog_option`
#
# Current player says the text of the last selected dialog option.
#
# @ESC
extends ESCBaseCommand
class_name SayLastDialogOptionCommand
# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new()
# Run the command
func run(_command_params: Array) -> int:
escoria.current_state = escoria.GAME_STATE.DIALOG
if !escoria.dialog_player:
escoria.logger.error(
self,
"[%s]: No dialog player was registered and the say command was encountered."
% get_command_name()
)
escoria.current_state = escoria.GAME_STATE.DEFAULT
return ESCExecution.RC_ERROR
if not escoria.main.current_scene.player:
escoria.logger.warn(
self,
"[%s]: No player item in the current scene was registered and the say command was encountered."
% get_command_name()
)
escoria.current_state = escoria.GAME_STATE.DEFAULT
return ESCExecution.RC_CANCEL
var last_chosen_option = escoria.globals_manager.get_global("ESC_DIALOG_CHOSEN_OPTION")
# Surround text with quotes. Required by escoria.dialog_player.say()
var text = "\"%s\"" % last_chosen_option
var speaking_character_global_id = escoria.main.current_scene.player.global_id
escoria.dialog_player.say(
speaking_character_global_id,
"",
text
)
yield(escoria.dialog_player, "say_finished")
escoria.current_state = escoria.GAME_STATE.DEFAULT
return ESCExecution.RC_OK

View File

@@ -173,6 +173,9 @@ func do_choose(dialog_player: Node, dialog: ESCDialog, type: String = "simple"):
var option = yield(chooser, "option_chosen")
dialog_player.remove_child(chooser)
# MODIFIED FOR RETURN TO MONKEY UI
escoria.globals_manager.set_global("ESC_DIALOG_CHOSEN_OPTION", option.option)
# END MODIFIED FOR RETURN TO MONKEY UI
emit_signal("option_chosen", option)

View File

@@ -69,4 +69,4 @@ func register_components():
func autoload_components():
add_child(ESCItemComponentOutline.new())
add_child(ESCItemComponentInventoryChecker.new())
add_child(ESCItemComponentInventoryChecker.new())