-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLoadingScreen.gd
69 lines (59 loc) · 1.89 KB
/
LoadingScreen.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
extends Control
var loading : bool
var path : String
var waitForInput : bool
var inputKeyPressed : bool
var spawnIndex : int
@export var tips : Array[String]
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if loading:
var progress = []
var status = ResourceLoader.load_threaded_get_status(path, progress)
if status == ResourceLoader.THREAD_LOAD_IN_PROGRESS:
print(progress[0] * 100)
$ProgressBar.value = progress[0] * 100
elif status == ResourceLoader.THREAD_LOAD_LOADED:
set_process(false)
print("Level Loaded")
$ProgressBar.value = 100
waitForInput = true
pass
func _input(event):
if waitForInput:
if event is InputEventKey:
if inputKeyPressed:
GameManager.UnpauseGame()
ChangeScene(ResourceLoader.load_threaded_get(path))
if !event.pressed:
inputKeyPressed = false
else:
inputKeyPressed = true
func ChangeScene(resource : PackedScene):
var currentNode = resource.instantiate()
GameManager.CheckForPlayer()
GameManager.LevelBase.add_child(currentNode)
for item in GameManager.LevelBase.get_children():
if item != currentNode:
GameManager.LevelBase.remove_child(item)
item.queue_free()
if !GameManager.LoadingFromSave:
GameManager.MovePlayer(spawnIndex)
queue_free()
func LoadLevel(path : String, spawnIndex : int):
self.path = path
self.spawnIndex = spawnIndex
show()
if tips.size() != 0:
$Control/VBoxContainer2/TipValue.text = tips[randi() % tips.size()]
var items : PackedStringArray = path.split("/")
var levelname = items[items.size() - 1].split(".")
$Control/VBoxContainer/LevelName.text = levelname[0]
if(ResourceLoader.has_cached(path)):
ResourceLoader.load_threaded_get(path)
else:
ResourceLoader.load_threaded_request(path, "", true)
loading = true