extends Control

@onready var groups: Array[String] = ["ASD", "Jumalauta", "Marmot", "Future Crew", "Gray Marchers", "Byterapers", "Pyrotech", "Gorbat Soft", "U+1F35E"]
var group_iter: int = 0;

@onready var pallo: PackedScene = load("res://entities/ball.tscn")
# Called when the node enters the scene tree for the first time.
@onready var grouptimer: Timer = Timer.new();

func _ready() -> void:
	($TextViewPort/Label.label_settings as LabelSettings).font_size = 1;
	
	grouptimer.autostart = false;
	grouptimer.wait_time = 1.5;
	grouptimer.connect("timeout", random_group);
	add_child(grouptimer);
	
func _process(delta: float) -> void:
	if ($TextViewPort/Label.label_settings as LabelSettings).font_size < 256:
		($TextViewPort/Label.label_settings as LabelSettings).font_size += 1
	elif grouptimer.is_stopped():
		grouptimer.start();

func _on_timer_timeout() -> void:
	
	for i in 2:
		var x: float = randf_range(-6, 6)
		var z: float = randf_range(-2, 2)
		var boll: Node3D = pallo.instantiate()
		var ttl_timer: Timer = Timer.new();
		ttl_timer.wait_time = 7;
		ttl_timer.connect("timeout", func() -> void: boll.queue_free());
		ttl_timer.one_shot = true;
		ttl_timer.autostart = true;
		boll.add_child(ttl_timer);
		var spawn: Vector3 = Vector3(x, 3, z)
		add_child(boll)

		boll.global_position = spawn
	
func random_group() -> void:
	if group_iter <= 3:
		var group: String = groups.pick_random();
		$TextViewPort/Label.text = group;
		groups.remove_at(groups.find(group, 0));
		group_iter += 1;
