40 lines
1 KiB
GDScript
40 lines
1 KiB
GDScript
extends Node
|
|
|
|
var queue = ResourceQueue.new()
|
|
var target_scene = null
|
|
var loading_text = null
|
|
|
|
var loader = preload("res://Scenes/Loader.tscn")
|
|
|
|
func _ready() -> void:
|
|
queue.start()
|
|
|
|
func enter_loader() -> void:
|
|
get_tree().change_scene_to(loader)
|
|
|
|
func load_scene(scene_path: String, dependencies: Array) -> void:
|
|
target_scene = scene_path
|
|
queue.queue_resource(scene_path)
|
|
for dep in dependencies:
|
|
queue.queue_resource(dep)
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
if target_scene != null:
|
|
var remaining = queue.pending.size()
|
|
for path in queue.pending:
|
|
if queue.is_ready(path):
|
|
remaining -= 1
|
|
if remaining == 0:
|
|
get_tree().change_scene_to(queue.get_resource(target_scene))
|
|
target_scene = null
|
|
|
|
func get_progress() -> String:
|
|
if loading_text != null:
|
|
return loading_text
|
|
var count = queue.pending.size()
|
|
if count == 0:
|
|
return "Reticulating splines"
|
|
var current = 0
|
|
for path in queue.pending:
|
|
current += queue.get_progress(path)
|
|
return "Loading scene (" + str(round(current/count*100)) + "%)"
|