From 9e247a9218b2b08654ef92e060b591ff3759dcb6 Mon Sep 17 00:00:00 2001 From: Duncan Brown Date: Sat, 7 May 2022 17:01:06 -0400 Subject: [PATCH] fix: checks to make sure target_object after a walk to an object is the proper one in case action manager is already yielding and expecting a particular one; change to proper interrupt method name; clears out pending events --- .../game/core-scripts/esc/esc_action_manager.gd | 13 +++++++++++++ .../game/core-scripts/esc/esc_event_manager.gd | 11 +++++++---- .../game/core-scripts/esc/types/esc_base_command.gd | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/escoria-core/game/core-scripts/esc/esc_action_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_action_manager.gd index 704fda2d..9d7f3bcb 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_action_manager.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_action_manager.gd @@ -522,6 +522,11 @@ func perform_inputevent_on_object( ) if context is GDScriptFunctionState: context = yield(context, "completed") + + # In case of an interrupted walk, we don't want to proceed. + if context == null: + return + destination_position = context.target_position dont_interact = context.dont_interact_on_arrival @@ -640,11 +645,19 @@ func _walk_towards_object( escoria.main.current_scene.player.walk_to(destination_position, walk_context) + escoria.logger.debug("Player walking to destination. Yielding.") + # Wait for the player to arrive before continuing with action. var context: ESCWalkContext = yield( escoria.main.current_scene.player, "arrived" ) + + if context.target_object != obj: + escoria.logger.debug("Original walk context target does not match " \ + + "yielded walk context. Likely interrutped walk.") + return + escoria.logger.info("Context arrived: %s" % context) # Confirm that reached item was the one user clicked in the first place. diff --git a/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd index d0f3e95a..75cd7608 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd @@ -57,8 +57,11 @@ var _yielding: Dictionary = {} # Whether we're currently changing the scene. var _changing_scene: bool = false setget set_changing_scene +# ESC "change_scene" command. var _change_scene: ChangeSceneCommand + +# Constructor func _init(): _change_scene = ChangeSceneCommand.new() @@ -330,14 +333,14 @@ func get_running_event(name: String) -> ESCEvent: # # #### Parameterse # - value: boolean value to set _changing_scene to -func set_changing_scene(value: bool) -> void: - escoria.logger.trace("Setting _changing_scene to %s." % value) +func set_changing_scene(p_is_changing_scene: bool) -> void: + escoria.logger.trace("Setting _changing_scene to %s." % p_is_changing_scene) - _changing_scene = value + _changing_scene = p_is_changing_scene # If we're changing scenes, interrupt any (other) running events and purge # all event queues. - if value: + if _changing_scene: interrupt([EVENT_INIT, EVENT_EXIT_SCENE, _change_scene.get_command_name()]) diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_base_command.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_base_command.gd index 030e7389..bb5f260d 100644 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_base_command.gd +++ b/addons/escoria-core/game/core-scripts/esc/types/esc_base_command.gd @@ -44,4 +44,4 @@ func get_command_name() -> String: # Function called when the command is interrupted. func interrupt(): - escoria.logger.info("Command %s did not override interrupt." % get_command_name()) + escoria.logger.trace("Command %s did not override interrupt." % get_command_name())