class_name HUD extends Control

@onready var trap_display : TrapDisplay = %TrapDisplay
@onready var p1_healthbar : HealthBar = %P1HealthBar
@onready var p2_healthbar : HealthBar = %P2HealthBar
@onready var control_display : ControlDisplay = %ControlDisplay
@onready var ammo_label : Label = %AmmoLabel
func _ready() -> void:
	Game.hud = self

func register_pawn(player : PawnController, is_local : bool) -> void:

	player.health_changed.connect(p1_healthbar._on_health_changed if is_local else p2_healthbar._on_health_changed)
	player.poison_status_changed.connect(p1_healthbar._on_poison_status_changed if is_local else p2_healthbar._on_poison_status_changed)
	if is_local:
		trap_display._on_trap_list_changed(player.data.traps, player.data.active_trap)
		player.trap_cycled.connect(trap_display._on_trap_cycled)
		player.trap_quantity_changed.connect(trap_display._on_trap_quantity_changed)
		player.trap_list_changed.connect(trap_display._on_trap_list_changed)
		player.combat_target_changed.connect(control_display._on_melee_range_changed)
		player.ammo_changed.connect(_on_ammo_changed)
		set_ammo(player.ammo)
	
func set_ammo(ammo : int) -> void:
	ammo_label.text = str(ammo)
	ammo_label.modulate = Color.DIM_GRAY if ammo == 0 else Color.WHITE
	
func _on_ammo_changed(current : int, max : int) -> void:
	set_ammo(current)
		
