class_name DamageLabel extends Label3D

@export var timer:Timer
@export var speed:Vector3 = Vector3(0, 1, 0)

func onTimeout() -> void:
  self.visible = false
  queue_free()
  print("Damage label removed")

func _process(delta: float) -> void:
  self.position += speed * delta

func showDamage(
  parent:Node3D,
  amount:int,
  isCritical:bool
) -> void:
  if amount == 0:
    return

  text = str(amount)

  if amount > 0:
    # Healing
    modulate = Color.GREEN
    outline_modulate = Color.TRANSPARENT
  elif isCritical:
    # Crit
    modulate = Color.RED
    outline_modulate = Color.BLACK
  else:
    # DMG
    modulate = Color.RED
    outline_modulate = Color.TRANSPARENT

  parent.add_child(self)
  self.position = Vector3.ZERO

  timer.timeout.connect(onTimeout)
