extends PIDCamera2D
class_name CameraController

@export var player : Player
var _player : PlayerBase
@export var map_loader : MapLoader

func _ready() -> void:
	if player:
		_player = player.player_base
	else:
		push_warning("No player assigned!")
	
	if map_loader:
		set_cam_limits()
		SignalBus.loaded_room.connect(set_cam_limits)
	else:
		push_warning("No map loader assigned!")
	
	SignalBus.changed_player_position.connect(set_cam_limits)

func _set_target() -> Vector2:
	return _player.global_position;

func update_cam_limits():
	limit_enabled = false
	set_cam_limits()

func set_cam_limits() -> void:
	limit_enabled = true
	var coords : Vector4 = map_loader._get_current_room_by_time().get_camera_limits()
	limit_left = coords.x as int
	limit_top = coords.y as int
	limit_right = coords.z as int
	limit_bottom = coords.w as int
