spaceship/CaptureLabel.gd

32 lines
904 B
GDScript3
Raw Normal View History

extends Label
# Polls GameState directly, same convention as ResourceCounter/GasCounter,
# so it stays correct without anyone having to push updates into it. Hidden
# entirely when the current planet has no capture points (e.g. no setup
# resolved for it) rather than showing "0/0".
var _was_conquered: bool = false
func _process(_delta: float) -> void:
var planet_id: String = GameState.planet_id
var total: int = GameState.total_capture_points(planet_id)
if total <= 0:
visible = false
return
visible = true
var conquered: bool = GameState.is_planet_conquered(planet_id)
if conquered:
text = "CONQUERED"
if not _was_conquered:
_flash()
else:
text = "CAPTURED %d/%d" % [GameState.captured_point_count(planet_id), total]
_was_conquered = conquered
func _flash() -> void:
modulate.a = 0.0
var tween: Tween = create_tween()
tween.tween_property(self, "modulate:a", 1.0, 1.2)