1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-25 09:04:19 +00:00
swear-jar/interface/ghost/placeable_area_checker.gd

35 lines
1.1 KiB
GDScript3
Raw Normal View History

2023-10-08 01:56:29 +00:00
extends Node
class_name PlaceableAreaChecker
2023-10-12 19:45:52 +00:00
## Layers to consider when checking overlap with [PhysicBody2D].
##
## Ignored during the actual collision check, just used to expand it in the Ghost's initialization phase.
@export_flags_2d_physics var overlap_mask: int
2023-10-08 01:56:29 +00:00
## The [Area2D] this script should act on.
@onready var target: Area2D = get_parent()
## What the [target] object is currently overlapping with.
var is_overlapping_with: PlaceableArea = null
## Get the first [PlaceableArea] overlapping the [target].
func get_first_overlapping_placeable_area() -> PlaceableArea:
for area in target.get_overlapping_areas():
if area is PlaceableArea:
return area
return null
## Emitted when the value of [is_overlapping_with] changes because of [_update_is_overlapping_with].
signal overlap_changing(to: PlaceableArea)
2023-10-12 16:41:16 +00:00
func update_is_overlapping_with() -> void:
2023-10-08 01:56:29 +00:00
var current_overlap = get_first_overlapping_placeable_area()
if current_overlap != is_overlapping_with:
2023-10-13 17:21:07 +00:00
print("[PlaceableAreaChecker] Now overlapping with: ", current_overlap)
2023-10-08 01:56:29 +00:00
overlap_changing.emit(current_overlap)
is_overlapping_with = current_overlap