feat: port ESCActionManagerMonkey

This commit is contained in:
2025-01-26 19:04:51 +01:00
parent a996af25cb
commit 6521b2f807

View File

@@ -19,7 +19,7 @@ func set_current_action(action: String):
elif action_state == ACTION_INPUT_STATE.AWAITING_VERB:
set_action_input_state(ACTION_INPUT_STATE.AWAITING_VERB_CONFIRMATION)
emit_signal("action_changed")
action_changed.emit()
# Checks if the specified action is valid and returns the associated event;
@@ -33,7 +33,7 @@ func set_current_action(action: String):
# - target: Target ESC object
# - combine_with: ESC object to combine with
#
# *Returns* the appropriate ESCEvent to queue/run, or null if none can be found
# *Returns* the appropriate ESCGrammarStmts.Event to queue/run, or null if none can be found
# or there's a reason not to run an event.
func _get_event_to_queue(
action: String,
@@ -55,24 +55,39 @@ func _get_event_to_queue(
or combine_with):
# or (combine_with && action in combine_with.node.combine_when_selected_action_is_in)):
# Player has item in inventory, we check the element to use on
# Check if object must be in inventory to be used
if target.node.use_from_inventory_only:
if escoria.inventory_manager.inventory_has(target.global_id):
# Player has item in inventory, we check the element to use on
if combine_with:
var target_event = "%s %s" % [
action,
var do_combine = true
if combine_with.node is ESCItem \
and combine_with.node.use_from_inventory_only\
and not escoria.inventory_manager.inventory_has(
combine_with.global_id
]
var combine_with_event = "%s %s" % [
action,
target.global_id
]
):
do_combine = false
if target.events.has(target_event):
event_to_return = target.events[target_event]
elif combine_with.events.has(combine_with_event)\
if do_combine:
# var target_event = "%s %s" % [
# action,
# combine_with.global_id
# ]
# var combine_with_event = "%s %s" % [
# action,
# target.global_id
# ]
if _has_event_with_target(target.events, action, combine_with.global_id):
#if target.events.has(target_event):
#event_to_return = target.events[target_event]
event_to_return = target.events[action]
#elif combine_with.events.has(combine_with_event)\
elif _has_event_with_target(combine_with.events, action, target.global_id)\
and not combine_with.node.combine_is_one_way:
event_to_return = combine_with.events[combine_with_event]
#event_to_return = combine_with.events[combine_with_event]
event_to_return = combine_with.events[action]
else:
# Check to see if there isn't a "fallback" action to
# run before we declare this a failure.
@@ -82,7 +97,12 @@ func _get_event_to_queue(
event_to_return = escoria.action_default_script.events[action]
else:
var errors = [
"Attempted to execute action %s between item %s and item %s" % [
"Attempted to execute action '%s' between item %s and item %s" % [
action,
target.global_id,
combine_with.global_id
],
"Check that action ':%s %s' exists in the script of item '%s'" % [
action,
target.global_id,
combine_with.global_id
@@ -100,7 +120,35 @@ func _get_event_to_queue(
"Invalid action: " + str(errors)
)
else:
if target.events.has(action):
escoria.logger.warn(
self,
"Invalid action on item: " +
(
"Trying to combine object %s with %s, "+
"but %s is not in inventory."
) % [
target.global_id,
combine_with.global_id,
combine_with.global_id
]
)
else:
escoria.logger.warn(
self,
"Invalid action on item: " +
"Trying to run action '%s' on object %s, " %
[
action,
target.node.global_id
]
+ "but item must be in inventory."
)
else:
if _check_target_has_proper_action(target, action):
# ##SAVEGAME
# if target.events[action].is_completed:
# target.events[action].is_completed = false
# target.events[action].from_statement_id = 0
event_to_return = target.events[action]
elif escoria.action_default_script \
and escoria.action_default_script.events.has(action):
@@ -111,7 +159,7 @@ func _get_event_to_queue(
escoria.logger.warn(
self,
"Invalid action: " +
"Event for action %s on object %s not found." % [
"Event for action '%s' on object '%s' not found." % [
action,
target.global_id
]
@@ -208,7 +256,12 @@ func perform_inputevent_on_object(
current_target
)
else:
if need_combine:
# Check if object must be in inventory to be used and update
# action state if necessary
if obj.node.use_from_inventory_only and \
escoria.inventory_manager.inventory_has(obj.global_id) and \
need_combine:
# We're missing a target here for our tool to be used on
current_tool = obj
set_action_input_state(
@@ -228,10 +281,10 @@ func perform_inputevent_on_object(
# player walking towards the destination.
if current_action and not event_to_queue:
clear_current_action()
emit_signal("action_finished")
action_finished.emit()
return
var event_flags = event_to_queue.flags if event_to_queue else 0
var event_flags = event_to_queue.get_flags() if event_to_queue else 0
if escoria.main.current_scene.player:
var destination_position: Vector2 = escoria.main.current_scene.player \
@@ -244,7 +297,7 @@ func perform_inputevent_on_object(
var context = await _walk_towards_object(
obj,
event.position,
event.doubleclick
event.double_click
)
# In case of an interrupted walk, we don't want to proceed.
@@ -255,11 +308,11 @@ func perform_inputevent_on_object(
dont_interact = context.dont_interact_on_arrival
var player_global_pos = escoria.main.current_scene.player.global_position
# var clicked_position = event.position
var clicked_position = event.position
# Using this instead of is_equal_approx due to
# https://github.com/godotengine/godot/issues/65257
if (player_global_pos - destination_position).length() > 1:
if (player_global_pos - destination_position).length() > 1.0:
dont_interact = true
escoria.logger.info(
self,
@@ -344,4 +397,3 @@ func get_tooltip_from_current_target(verb,current_target_object):
func get_action_target_text(action_target_texts: Dictionary):
var action_target_text = action_target_texts.get(escoria.action_manager.current_tool.global_id)
return action_target_text if action_target_text else ""