This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Scenes/Global/SceneManager.gd

50 lines
1.2 KiB
GDScript3
Raw Permalink Normal View History

extends Node
var queue = ResourceQueue.new()
var target_scene = null
var loading_text = null
var loader = preload("res://Scenes/Loader.tscn")
2020-07-14 14:20:06 +00:00
onready var netgame = $"/root/Multiplayer"
func _ready() -> void:
2020-07-22 15:34:04 +00:00
var threads_supported = true
if OS.get_name() == "HTML5":
threads_supported = false
queue.start(threads_supported)
func enter_loader() -> void:
get_tree().change_scene_to(loader)
func load_scene(scene_path: String, dependencies: Array) -> void:
2020-07-22 15:34:04 +00:00
if queue.threaded:
2020-07-14 14:20:06 +00:00
target_scene = scene_path
queue.queue_resource(scene_path)
for dep in dependencies:
queue.queue_resource(dep)
else:
get_tree().change_scene(scene_path)
func _physics_process(_delta: float) -> void:
2020-07-22 15:34:04 +00:00
if queue.threaded:
2020-07-14 14:20:06 +00:00
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 (%.0f%%)" % (current/count*100)