Skip to content

Commit

Permalink
fix: early return for mouse_in_shape
Browse files Browse the repository at this point in the history
  • Loading branch information
bolinfest authored and StraToN committed Mar 3, 2022
1 parent e9dcf8d commit f21ec15
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions addons/escoria-core/game/core-scripts/esc_item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,7 @@ func _unhandled_input(event: InputEvent) -> void:
escoria.logger.info("Game state doesn't accept interactions")
return
var p = get_global_mouse_position()
var mouse_in_shape: bool = false
var colliders = get_world_2d().direct_space_state.intersect_point(
p,
32,
[],
2147483647,
true,
true
)
for _owner in get_shape_owners():
for _shape_id in range(0, shape_owner_get_shape_count(_owner)):
for _collider in colliders:
if _collider.collider == self and\
_collider.shape == _shape_id:
mouse_in_shape = true
if mouse_in_shape:
if _is_in_shape(p):
if event.doubleclick and event.button_index == BUTTON_LEFT:
emit_signal("mouse_double_left_clicked_item", self, event)
get_tree().set_input_as_handled()
Expand All @@ -310,6 +295,25 @@ func _unhandled_input(event: InputEvent) -> void:
get_tree().set_input_as_handled()


func _is_in_shape(position: Vector2) -> bool:
var colliders = get_world_2d().direct_space_state.intersect_point(
position,
32,
[],
2147483647,
true,
true
)
for _owner in get_shape_owners():
for _shape_id in range(0, shape_owner_get_shape_count(_owner)):
for _collider in colliders:
if _collider.collider == self and _collider.shape == _shape_id:
return true
return false




# Return the animation player node
func get_animation_player() -> Node:
if _animation_player == null:
Expand Down

0 comments on commit f21ec15

Please sign in to comment.