-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenestack.js
112 lines (112 loc) · 3.41 KB
/
scenestack.js
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
110
111
112
var gdjs;
(function(gdjs2) {
class SceneStack {
constructor(runtimeGame) {
this._stack = [];
this._wasFirstSceneLoaded = false;
if (!runtimeGame) {
throw "SceneStack must be constructed with a gdjs.RuntimeGame.";
}
this._runtimeGame = runtimeGame;
}
onGameResolutionResized() {
for (let i = 0; i < this._stack.length; ++i) {
this._stack[i].onGameResolutionResized();
}
}
step(elapsedTime) {
if (this._stack.length === 0) {
return false;
}
const currentScene = this._stack[this._stack.length - 1];
if (currentScene.renderAndStep(elapsedTime)) {
const request = currentScene.getRequestedChange();
if (request === gdjs2.SceneChangeRequest.STOP_GAME) {
this._runtimeGame.getRenderer().stopGame();
return true;
} else if (request === gdjs2.SceneChangeRequest.POP_SCENE) {
this.pop();
} else if (request === gdjs2.SceneChangeRequest.PUSH_SCENE) {
this.push(currentScene.getRequestedScene());
} else if (request === gdjs2.SceneChangeRequest.REPLACE_SCENE) {
this.replace(currentScene.getRequestedScene());
} else if (request === gdjs2.SceneChangeRequest.CLEAR_SCENES) {
this.replace(currentScene.getRequestedScene(), true);
} else {
console.error("Unrecognized change in scene stack.");
return false;
}
}
return true;
}
renderWithoutStep() {
if (this._stack.length === 0) {
return false;
}
const currentScene = this._stack[this._stack.length - 1];
currentScene.render();
return true;
}
pop() {
if (this._stack.length <= 1) {
return null;
}
const scene = this._stack.pop();
if (!scene) {
return null;
}
scene.unloadScene();
const currentScene = this._stack[this._stack.length - 1];
if (currentScene) {
currentScene.onResume();
}
return scene;
}
push(newSceneName, externalLayoutName) {
const currentScene = this._stack[this._stack.length - 1];
if (currentScene) {
currentScene.onPause();
}
const newScene = new gdjs2.RuntimeScene(this._runtimeGame);
newScene.loadFromScene(this._runtimeGame.getSceneData(newSceneName));
this._wasFirstSceneLoaded = true;
if (externalLayoutName) {
const externalLayoutData = this._runtimeGame.getExternalLayoutData(externalLayoutName);
if (externalLayoutData) {
newScene.createObjectsFrom(externalLayoutData.instances, 0, 0, true);
}
}
this._stack.push(newScene);
return newScene;
}
replace(newSceneName, clear) {
if (!!clear) {
while (this._stack.length !== 0) {
let scene = this._stack.pop();
if (scene) {
scene.unloadScene();
}
}
} else {
if (this._stack.length !== 0) {
let scene = this._stack.pop();
if (scene) {
scene.unloadScene();
}
}
}
return this.push(newSceneName);
}
getCurrentScene() {
if (this._stack.length === 0) {
return null;
}
return this._stack[this._stack.length - 1];
}
wasFirstSceneLoaded() {
return this._wasFirstSceneLoaded;
}
}
gdjs2.SceneStack = SceneStack;
})(gdjs || (gdjs = {}));
//# sourceMappingURL=scenestack.js.map