forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScenePlugin.js
More file actions
265 lines (196 loc) · 5.93 KB
/
Copy pathScenePlugin.js
File metadata and controls
265 lines (196 loc) · 5.93 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
// A proxy class to the Global Scene Manager
var ScenePlugin = new Class({
initialize:
function ScenePlugin (scene)
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
this.settings = scene.sys.settings;
this.key = scene.sys.settings.key;
// SceneManager
this.manager = scene.sys.game.scene;
// Private
this._queue = [];
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('preupdate', this.preUpdate, this);
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
preUpdate: function ()
{
var len = this._queue.length;
if (len === 0)
{
return;
}
var manager = this.manager;
// Process the queue
for (var i = 0; i < len; i++)
{
var action = this._queue[i];
switch (action.type)
{
case 'add':
manager.add(action.key, action.data, action.autoStart);
break;
case 'start':
manager.stop(this.key);
manager.start(action.key, action.data);
break;
case 'launch':
manager.start(action.key, action.data);
break;
case 'pause':
manager.pause(action.key);
break;
case 'resume':
manager.resume(action.key);
break;
case 'stop':
manager.stop(action.key);
break;
case 'swap':
manager.swap(this.key, action.key);
break;
case 'moveUp':
manager.moveUp(this.key);
break;
case 'moveDown':
manager.moveDown(this.key);
break;
case 'bringToTop':
manager.bringToTop(this.key);
break;
case 'sendToBack':
manager.sendToBack(this.key);
break;
case 'swapPosition':
manager.swapPosition(this.key, action.key);
break;
case 'sleep':
manager.sleep(action.key);
break;
case 'wake':
manager.wake(action.key);
break;
}
}
this._queue.length = 0;
},
// Shutdown this Scene and run the given one
start: function (key, data)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'start', key: key, data: data });
return this;
},
// Add the Scene into the Scene Manager and start it if 'autoStart' is true or the Scene config 'active' property is set
add: function (key, sceneConfig, autoStart)
{
this._queue.push({ type: 'add', key: key, data: sceneConfig, autoStart: autoStart });
return this;
},
// Launch the given Scene and run it in parallel with this one
launch: function (key, data)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'launch', key: key, data: data });
return this;
},
// Pause the Scene - this stops the update step from happening but it still renders
pause: function (key)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'pause', key: key });
return this;
},
// Resume the Scene - starts the update loop again
resume: function (key)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'resume', key: key });
return this;
},
// Makes the Scene sleep (no update, no render) but doesn't shutdown
sleep: function (key)
{
this._queue.push({ type: 'sleep', key: key });
return this;
},
// Makes the Scene wake-up (starts update and render)
wake: function (key)
{
this._queue.push({ type: 'wake', key: key });
return this;
},
// Makes this Scene sleep then starts the Scene given
swap: function (key)
{
this._queue.push({ type: 'swap', key: key });
return this;
},
// Shutdown the Scene, clearing display list, timers, etc
stop: function (key)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'stop', key: key });
return this;
},
setVisible: function (value)
{
this.settings.visible = value;
return this;
},
swapPosition: function (key)
{
this._queue.push({ type: 'swapPosition', key: key });
},
moveUp: function ()
{
this._queue.push({ type: 'moveUp' });
},
moveDown: function ()
{
this._queue.push({ type: 'moveDown' });
},
bringToTop: function ()
{
this._queue.push({ type: 'bringToTop' });
},
sendToBack: function ()
{
this._queue.push({ type: 'sendToBack' });
},
get: function (key)
{
return this.manager.getScene(key);
},
transitionTo: function (key, duration)
{
},
isActive: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isActive(key);
},
shutdown: function ()
{
// TODO
},
destroy: function ()
{
// TODO
}
});
PluginManager.register('ScenePlugin', ScenePlugin, 'scenePlugin');
module.exports = ScenePlugin;