@tool
class_name BallIcon extends Control
## HUD icon for a ball type

const BASE_MODULATE := Color.WHITE
const EMPTY_MODULATE := Color.DIM_GRAY

@export var text: String:
	set(value):
		text = value
		if ball_label:
			ball_label.text = value

@export var quantity: int:
	set = _set_quantity
@export var empty: bool:
	set(value):
		if value:
			quantity = 0
		elif not quantity:
			quantity = 1
	get:
		return quantity == 0
@export var unlimited: bool:
	set(value):
		quantity = -1 if value else 0
	get:
		return quantity < 0

@onready var ball_label: Label = %BallLabel
@onready var quantity_container: HBoxContainer = %QuantityContainer
@onready var quantity_label: Label = %QuantityLabel


func _ready() -> void:
	text = text
	quantity = quantity


func _set_quantity(value: int) -> void:
	# TODO play effect on gain/loss
	quantity = value
	if not quantity_label:
		return
	quantity_label.text = str(quantity)

	# Quantity is not visible if we're empty or unlimited
	quantity_container.visible = quantity > 0

	# Grey out when empty
	ball_label.modulate = EMPTY_MODULATE if quantity == 0 else BASE_MODULATE
