class_name LevelThresholdArea
extends Area3D

static var is_level_loading: bool = false

@export var level_loaders: Array[LevelLoader] = []


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	body_entered.connect(prevent_if_any_loading.unbind(1))


func prevent_if_any_loading() -> bool:
	for loader: LevelLoader in level_loaders:
		if not loader.is_loading:
			continue

		get_tree().paused = true
		is_level_loading = true
		SceneFader.set_loading_hints_visible(true)

		while loader.is_loading:
			await get_tree().process_frame

		SceneFader.set_loading_hints_visible(false)
		get_tree().paused = false
		is_level_loading = false
		return true

	return false
