extends Label
class_name DamageNumber

# Floating "(amount)" combat text shown only to the attacker when their shot
# lands (see ships/ship_movement.gd's _notify_damage_dealt()) — purely
# cosmetic and spawned locally on whichever peer it's told to appear for,
# same "no networked node needed" approach as effects/explosion.gd.
var amount: int = 0

const BOX_SIZE := Vector2(80, 24)


func _ready() -> void:
	text = "(%d)" % amount
	add_theme_font_size_override("font_size", GameConfig.damage_number_font_size)
	add_theme_color_override("font_color", GameConfig.damage_number_color)
	add_theme_color_override("font_outline_color", Color(0, 0, 0, 0.8))
	add_theme_constant_override("outline_size", 3)
	mouse_filter = Control.MOUSE_FILTER_IGNORE
	horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
	vertical_alignment = VERTICAL_ALIGNMENT_CENTER
	custom_minimum_size = BOX_SIZE
	size = BOX_SIZE
	# global_position was set to the hit point by the spawner; center the box
	# on it instead of growing down-right from it.
	global_position -= BOX_SIZE / 2.0

	var tween := create_tween()
	tween.set_parallel(true)
	tween.tween_property(self, "position:y", position.y - GameConfig.damage_number_rise_distance, GameConfig.damage_number_duration)
	tween.tween_property(self, "modulate:a", 0.0, GameConfig.damage_number_duration)
	tween.chain().tween_callback(queue_free)
