extends Node3D

@export_file(".tscn") var youth_room_path: String
@export_file(".tscn") var voluntary_room: String
@export_file(".tscn") var study_room: String

@onready var loading_player: AnimationPlayer = %MenuAnimationPlayer

var last_progress_state: float = 0
var current_loaded_room: Node3D
var currently_loading_room: String = "":
	set(path):
		if path != "":
			ResourceLoader.load_threaded_request(path, "PackedScene")
			currently_loading_room = path
			last_progress_state
			loading_player.queue("loading")
		else:
			loading_player.queue("loading_done")


# Called when the node enters the scene tree for the first time.
func _ready():
	currently_loading_room = youth_room_path

func _process(delta: float) -> void:
	if currently_loading_room != "":
		var progress:Array
		if ResourceLoader.load_threaded_get_status(youth_room_path, progress) == 3:
			current_loaded_room = ResourceLoader.load_threaded_get(youth_room_path).instantiate()
			add_child(current_loaded_room)
			move_child(current_loaded_room, 0)
			currently_loading_room = ""
		elif last_progress_state != progress[0]:
			loading_player.seek(progress[0])
			last_progress_state = progress[0]

func debug_youth():
	get_child(1).hide()
	get_child(2).hide()
	get_child(3).hide()
	get_child(0).get_ready()
	get_child(0).start()
