Skip to content

Commit

Permalink
fix: blocks actions on inputs for non-interactive and/or non-active i…
Browse files Browse the repository at this point in the history
…tems/objects
  • Loading branch information
BHSDuncan committed Aug 23, 2022
1 parent 7755a4a commit 8134950
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
46 changes: 45 additions & 1 deletion addons/escoria-core/game/core-scripts/esc/esc_action_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
escoria.event_manager.interrupt()

var item = escoria.object_manager.get_object(params[0])

self.perform_inputevent_on_object(item, params[1])

ACTION.ITEM_RIGHT_CLICK:
Expand All @@ -139,6 +140,7 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
escoria.event_manager.interrupt()

var item = escoria.object_manager.get_object(params[0])

self.perform_inputevent_on_object(item, params[1], true)

ACTION.TRIGGER_IN:
Expand Down Expand Up @@ -476,7 +478,7 @@ func perform_inputevent_on_object(

escoria.logger.info(
self,
"%s left-clicked with event %s." % [obj.global_id, event]
"%s to perform event %s." % [obj.global_id, event]
)

var event_flags = 0
Expand Down Expand Up @@ -584,6 +586,19 @@ func perform_inputevent_on_object(
)


# Determines whether the object in question can be acted upon.
#
# #### Parameters
#
# - global_id: the global ID of the item to examine
#
# *Returns* True iff the item represented by global_id can be acted upon.
func is_object_actionable(global_id: String) -> bool:
var obj: ESCObject = escoria.object_manager.get_object(global_id) as ESCObject

return _is_object_actionable(obj)


# Prepare the "obj" object for current_action: if required, set the object as
# current tool.
#
Expand Down Expand Up @@ -698,3 +713,32 @@ func _walk_towards_object(
walk_context.dont_interact_on_arrival = true

return context


# Determines whether the object in question can be acted upon.
#
# #### Parameters
#
# - obj: the ESCObject to examine
#
# *Returns* True iff 'obj' can be acted upon.
func _is_object_actionable(obj: ESCObject) -> bool:
var object_is_actionable: bool = true

if not obj:
return false

if not obj.active:
escoria.logger.debug(
self,
"Item %s is not active." % obj.global_id
)
object_is_actionable = false
elif not obj.interactive:
escoria.logger.debug(
self,
"Item %s is not interactive." % obj.global_id
)
object_is_actionable = false

return object_is_actionable
21 changes: 21 additions & 0 deletions addons/escoria-core/game/esc_inputs_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ func _on_mouse_exited_item(item: ESCItem) -> void:
# - event: The input event from the click
func _on_mouse_left_clicked_item(item: ESCItem, event: InputEvent) -> void:
if input_mode == INPUT_ALL:
if not escoria.action_manager.is_object_actionable(item.global_id):
escoria.logger.debug(
self,
"Ignoring left click on %s with event %s." % [item.global_id, event]
)
return

if hover_stack.empty() or hover_stack.back() == item:
escoria.logger.info(
self,
Expand All @@ -362,6 +369,13 @@ func _on_mouse_left_double_clicked_item(
event: InputEvent
) -> void:
if input_mode == INPUT_ALL:
if not escoria.action_manager.is_object_actionable(item.global_id):
escoria.logger.debug(
self,
"Ignoring double-left click on %s with event %s." % [item.global_id, event]
)
return

escoria.logger.info(
self,
"Item %s left double clicked with event %s." % [item.global_id, event]
Expand All @@ -381,6 +395,13 @@ func _on_mouse_left_double_clicked_item(
# - event: The input event from the click
func _on_mouse_right_clicked_item(item: ESCItem, event: InputEvent) -> void:
if input_mode == INPUT_ALL:
if not escoria.action_manager.is_object_actionable(item.global_id):
escoria.logger.debug(
self,
"Ignoring right click on %s with event %s." % [item.global_id, event]
)
return

escoria.logger.info(
self,
"Item %s right clicked with event %s." % [item.global_id, event]
Expand Down

0 comments on commit 8134950

Please sign in to comment.