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: elif action_state == ACTION_INPUT_STATE.AWAITING_VERB:
set_action_input_state(ACTION_INPUT_STATE.AWAITING_VERB_CONFIRMATION) 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; # 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 # - target: Target ESC object
# - combine_with: ESC object to combine with # - 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. # or there's a reason not to run an event.
func _get_event_to_queue( func _get_event_to_queue(
action: String, action: String,
@@ -55,52 +55,100 @@ func _get_event_to_queue(
or combine_with): or combine_with):
# or (combine_with && action in combine_with.node.combine_when_selected_action_is_in)): # 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 escoria.inventory_manager.inventory_has(target.global_id): if target.node.use_from_inventory_only:
if combine_with: if escoria.inventory_manager.inventory_has(target.global_id):
var target_event = "%s %s" % [ # Player has item in inventory, we check the element to use on
action, if combine_with:
combine_with.global_id var do_combine = true
] if combine_with.node is ESCItem \
var combine_with_event = "%s %s" % [ and combine_with.node.use_from_inventory_only\
action, and not escoria.inventory_manager.inventory_has(
target.global_id
]
if target.events.has(target_event):
event_to_return = target.events[target_event]
elif combine_with.events.has(combine_with_event)\
and not combine_with.node.combine_is_one_way:
event_to_return = combine_with.events[combine_with_event]
else:
# Check to see if there isn't a "fallback" action to
# run before we declare this a failure.
if escoria.action_default_script \
and escoria.action_default_script.events.has(action):
event_to_return = escoria.action_default_script.events[action]
else:
var errors = [
"Attempted to execute action %s between item %s and item %s" % [
action,
target.global_id,
combine_with.global_id combine_with.global_id
] ):
] do_combine = false
if combine_with.node.combine_is_one_way: if do_combine:
errors.append( # var target_event = "%s %s" % [
("Reason: %s's item interaction " + \ # action,
"is one-way.") % combine_with.global_id # 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[action]
else:
# Check to see if there isn't a "fallback" action to
# run before we declare this a failure.
if escoria.action_default_script \
and escoria.action_default_script.events.has(action):
event_to_return = escoria.action_default_script.events[action]
else:
var errors = [
"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
]
]
if combine_with.node.combine_is_one_way:
errors.append(
("Reason: %s's item interaction " + \
"is one-way.") % combine_with.global_id
)
escoria.logger.warn(
self,
"Invalid action: " + str(errors)
)
else:
escoria.logger.warn( escoria.logger.warn(
self, self,
"Invalid action: " + str(errors) "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: else:
if target.events.has(action): 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] event_to_return = target.events[action]
elif escoria.action_default_script \ elif escoria.action_default_script \
and escoria.action_default_script.events.has(action): and escoria.action_default_script.events.has(action):
@@ -111,7 +159,7 @@ func _get_event_to_queue(
escoria.logger.warn( escoria.logger.warn(
self, self,
"Invalid action: " + "Invalid action: " +
"Event for action %s on object %s not found." % [ "Event for action '%s' on object '%s' not found." % [
action, action,
target.global_id target.global_id
] ]
@@ -208,7 +256,12 @@ func perform_inputevent_on_object(
current_target current_target
) )
else: 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 # We're missing a target here for our tool to be used on
current_tool = obj current_tool = obj
set_action_input_state( set_action_input_state(
@@ -228,10 +281,10 @@ func perform_inputevent_on_object(
# player walking towards the destination. # player walking towards the destination.
if current_action and not event_to_queue: if current_action and not event_to_queue:
clear_current_action() clear_current_action()
emit_signal("action_finished") action_finished.emit()
return 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: if escoria.main.current_scene.player:
var destination_position: Vector2 = 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( var context = await _walk_towards_object(
obj, obj,
event.position, event.position,
event.doubleclick event.double_click
) )
# In case of an interrupted walk, we don't want to proceed. # 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 dont_interact = context.dont_interact_on_arrival
var player_global_pos = escoria.main.current_scene.player.global_position 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 # Using this instead of is_equal_approx due to
# https://github.com/godotengine/godot/issues/65257 # 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 dont_interact = true
escoria.logger.info( escoria.logger.info(
self, self,
@@ -344,4 +397,3 @@ func get_tooltip_from_current_target(verb,current_target_object):
func get_action_target_text(action_target_texts: Dictionary): func get_action_target_text(action_target_texts: Dictionary):
var action_target_text = action_target_texts.get(escoria.action_manager.current_tool.global_id) var action_target_text = action_target_texts.get(escoria.action_manager.current_tool.global_id)
return action_target_text if action_target_text else "" return action_target_text if action_target_text else ""