extends Control

signal countdown_finished

@export var race_music: AudioStream = null
@export var countdown_sound: AudioStream = null
@export var image_3: TextureRect = null
@export var image_2: TextureRect = null
@export var image_1: TextureRect = null
@export var image_go: TextureRect = null


func _ready() -> void:
	show()
	PulseSound1.load_and_play(countdown_sound)
	for i in range(3, -1, -1):
		show_image(i)
		await get_tree().create_timer(0.5).timeout
	hide()
	Music.load_stream(race_music)
	Music.play()
	countdown_finished.emit()


func show_image(index: int) -> void:
	image_3.visible = index == 3
	image_2.visible = index == 2
	image_1.visible = index == 1
	image_go.visible = index == 0
