'''
	此类为工具体积类，主要为检测玩家是否进入了检测体积。
'''
class_name PlayerTriggerVolumn
extends Area2D

@export var debug_print: bool = false

signal player_entered(body:CharacterBody2D)
signal player_exit(body:CharacterBody2D)

var _cached_player : Player

func _ready() -> void:
	self.body_entered.connect(_on_body_enter)
	self.body_exited.connect(_on_body_exit)

func _on_body_enter(body:Node2D) -> void:
	if not body.is_in_group("PLAYER"):
		return
	
	var p = body as Player
	if not p: return
	
	if debug_print:
		print("[TiggerVolumn]: Player Entered")
	
	_cached_player = p
	player_entered.emit(p)

func _on_body_exit(body:Node2D) -> void:
	if not _cached_player: return
	
	if not body.is_in_group("PLAYER"):
		return
	
	var p = body as Player
	if not p: return
	
	if debug_print:
		print("[TiggerVolumn]: Player Exited")
	
	_cached_player = null
	player_exit.emit(p)
