class_name WaveNode extends Node2D

@export var spawn_interval := 0.2
signal finished;
var entities := 0;
var started_wave = false

func _ready() -> void:
	entities = get_child_count()

func spawn_wave():
	if started_wave: return
	
	started_wave = true
	if get_child_count() == 0:
		finished.emit()
		return
	
	for c : Spawner in get_children():
		c.spawn();
		c.finished.connect(entity_left)
		await get_tree().create_timer(spawn_interval).timeout
		
func entity_left():
	entities -= 1
	if entities <= 0:
		finished.emit()
