'''
此脚本可以强制让一个相机的Priority锁定为1
'''
extends Node

@export var target_camera: PhantomCamera2D

var _p

func _ready() -> void:
	_p = target_camera
	if not _p:
		_p = get_parent() as PhantomCamera2D
	
	if not _p: 
		printerr("[CameraLocker]: No vaild Camera Founded")
	
	var pcm = Engine.get_singleton("PhantomCameraManager")
	pcm.pcam_priority_changed.connect(_enforce)
	pcm.pcam_visibility_changed.connect(_enforce)

	# 启动时先保证一次
	_enforce()

func _enforce(_pcam = null):
	if not is_instance_valid(_p):
		return

	if _p.get_priority() != 1:
		_p.set_priority(1)
