2020-07-13 09:20:51 +00:00
|
|
|
extends Node
|
|
|
|
|
2020-07-13 19:01:36 +00:00
|
|
|
var queue = ResourceQueue.new()
|
2020-07-13 09:20:51 +00:00
|
|
|
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"
|
|
|
|
|
2020-07-13 19:01:36 +00:00
|
|
|
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)
|
2020-07-13 19:01:36 +00:00
|
|
|
|
|
|
|
func enter_loader() -> void:
|
2020-07-13 09:20:51 +00:00
|
|
|
get_tree().change_scene_to(loader)
|
|
|
|
|
2020-07-13 19:01:36 +00:00
|
|
|
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)
|
2020-07-13 09:20:51 +00:00
|
|
|
|
2020-07-13 19:01:36 +00:00
|
|
|
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
|
2020-07-13 09:20:51 +00:00
|
|
|
|
2020-07-13 19:01:36 +00:00
|
|
|
func get_progress() -> String:
|
2020-07-13 09:20:51 +00:00
|
|
|
if loading_text != null:
|
|
|
|
return loading_text
|
2020-07-13 19:01:36 +00:00
|
|
|
var count = queue.pending.size()
|
|
|
|
if count == 0:
|
|
|
|
return "Reticulating splines"
|
|
|
|
var current = 0
|
|
|
|
for path in queue.pending:
|
|
|
|
current += queue.get_progress(path)
|
2020-07-23 09:12:07 +00:00
|
|
|
return "Loading scene (%.0f%%)" % (current/count*100)
|