extends Node3D

var update_ui_timer = 0.1
@onready var player = $Player

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	update_ui_timer -= delta
	
	if update_ui_timer <= 0:
		update_ui_timer = 0.1
		
		$UI/Hotbar/Bars/Health/Bar.value = player.health
		
		var item_buttons = $UI/Hotbar/Items.get_children()
		
		var i = 0
		
		for n in player.slots:
			if item_buttons.size() <= i:
				var button = preload("res://scenes/ui/item_button.tscn").instantiate()
				button.weapon = player.slots[i]
				button.player = player
				
				$UI/Hotbar/Items.add_child(button)
				
				button.started = true
			elif item_buttons[i].weapon != player.slots[i]:
				item_buttons[i].weapon = player.slots[i]
				
			i += 1
