2025-08-26 13:56:12 +08:00
|
|
|
extends Node2D
|
|
|
|
|
class_name DamageLabel
|
|
|
|
|
|
|
|
|
|
@export var damage: float = 0
|
|
|
|
|
@export var crit: bool = false
|
2025-08-26 14:26:45 +08:00
|
|
|
|
|
|
|
|
@onready var label: Label = $"%label"
|
|
|
|
|
@onready var animator: AnimationPlayer = $"%animator"
|
|
|
|
|
|
2025-08-26 13:56:12 +08:00
|
|
|
func _ready():
|
2025-08-26 14:26:45 +08:00
|
|
|
if damage == 0:
|
|
|
|
|
label.text = "MISS"
|
|
|
|
|
else:
|
|
|
|
|
label.text = str(round(damage)) + ("!!!" if crit else "")
|
|
|
|
|
animator.play("show")
|
|
|
|
|
await animator.animation_finished
|
|
|
|
|
queue_free()
|
2025-08-26 13:56:12 +08:00
|
|
|
|
|
|
|
|
static func create(spawnDamage: float, spawnCrit: bool, spawnPosition: Vector2, addToWorld: bool = true) -> DamageLabel:
|
|
|
|
|
var instance = preload("res://components/UI/DamageLabel.tscn").instantiate()
|
|
|
|
|
instance.damage = spawnDamage
|
|
|
|
|
instance.crit = spawnCrit
|
|
|
|
|
instance.position = spawnPosition
|
|
|
|
|
if addToWorld:
|
|
|
|
|
WorldTool.rootNode.add_child(instance)
|
|
|
|
|
return instance
|