-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGameScene.gd
109 lines (81 loc) · 2.89 KB
/
GameScene.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
extends Node3D
class_name GameScene
@onready var Map = preload("res://MapScene.tscn")
@onready var MapEnvironment = preload("res://TestTrackEnv.tscn")
@onready var mapScene: PackedScene = preload("res://Editor/InteractiveMap.tscn")
var map = null
signal exitPressed()
signal finishedLoading()
func setup(
mapName: String,
ranked: bool = false,
online: bool = false,
validation: bool = false,
localReplays: Array[String] = [],
downloadedReplays: Array[String] = [],
timeMultiplier: float = 1.0,
totalTimePB: int = 9223372036854775807,
lapTimePB: int = 9223372036854775807,
) -> bool:
# load map
get_tree().root.content_scale_mode = Window.CONTENT_SCALE_MODE_DISABLED
# try loading new format
map = mapScene.instantiate() as InteractiveMap
add_child(map)
var success = map.importTrack(mapName)
if !success:
print("[GameScene.gd] Failed to load map: " + mapName)
print("[GameScene.gd] Trying legacy format")
map.queue_free()
map = Map.instantiate()
add_child(map)
# TODO: check if map exists locally, if not, download it
success = map.loadMap(mapName)
if !success:
get_tree().root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
print("[GameScene.gd] Failed to load legacy format, exiting.")
exitPressed.emit()
return false
map.setIngame()
%GameEventListener.state.ranked = ranked
%GameEventListener.state.online = online
%GameEventListener.state.validation = validation
if validation && map.bestTotalReplay != "":
localReplays = [
map.bestTotalReplay.split("/")[-1],
]
%GameEventListener.map = map
# %GameEventListener.ingameMedalMenu.chronoTime = map.bestTotalTime
# %GameEventListener.ingameMedalMenu.blitzTime = map.bestLapTime
# %GameEventListener.ingameMedalMenu.totalTimePB = totalTimePB
# %GameEventListener.ingameMedalMenu.lapTimePB = lapTimePB
%GameEventListener.ingameMedalMenu.setup(
map.bestTotalTime,
map.bestLapTime,
totalTimePB,
lapTimePB,
map.trackId
)
%GameEventListener.replayGhost.setTimeMultiplier(timeMultiplier)
print("Time Multiplier: ", timeMultiplier)
if timeMultiplier != 1.0:
%GameEventListener.state.timeMultiplier = timeMultiplier
%GameEventListener.addGhosts([] as Array[String], [map.bestTotalReplay + '.replay'] as Array[String])
%GameEventListener.replayGhost.setTimeMultiplier(timeMultiplier)
else:
%GameEventListener.addGhosts(localReplays, downloadedReplays)
# # load environment
# if !ClassFunctions.getClassName(map) == "InteractiveMap":
# var environment: WorldEnvironment = MapEnvironment.instantiate()
# add_child(environment)
if !online:
initializeLocalPlayers()
finishedLoading.emit()
return true
func initializePlayers():
%GameEventListener.clearPlayers()
if Network.userId == 1:
for key in Network.playerDatas:
%GameEventListener.addPlayers(Network.playerDatas[key], key.to_int())
func initializeLocalPlayers():
%GameEventListener.addPlayers(Network.localData, 1)