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
590 lines (515 loc) · 13.7 KB
/
Copy pathScenePlugin.js
File metadata and controls
590 lines (515 loc) · 13.7 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
var CONST = require('./const');
var PluginManager = require('../boot/PluginManager');
/**
* @classdesc
* A proxy class to the Global Scene Manager.
*
* @class ScenePlugin
* @memberOf Phaser.Scenes
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var ScenePlugin = new Class({
initialize:
function ScenePlugin (scene)
{
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#settings
* @type {object}
* @since 3.0.0
*/
this.settings = scene.sys.settings;
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#key
* @type {string}
* @since 3.0.0
*/
this.key = scene.sys.settings.key;
/**
* [description]
*
* @name Phaser.Scenes.ScenePlugin#manager
* @type {Phaser.Scenes.SceneManager}
* @since 3.0.0
*/
this.manager = scene.sys.game.scene;
},
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#boot
* @since 3.0.0
*/
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
/**
* Shutdown this Scene and run the given one.
*
* @method Phaser.Scenes.ScenePlugin#start
* @since 3.0.0
*
* @param {string} key - [description]
* @param {object} [data] - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
start: function (key, data)
{
if (key === undefined) { key = this.key; }
if (this.settings.status !== CONST.RUNNING)
{
this.manager.queueOp('stop', this.key);
this.manager.queueOp('start', key, data);
}
else
{
this.manager.stop(this.key);
this.manager.start(key, 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.
*
* @method Phaser.Scenes.ScenePlugin#add
* @since 3.0.0
*
* @param {string} key - [description]
* @param {object} sceneConfig - [description]
* @param {boolean} autoStart - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
add: function (key, sceneConfig, autoStart)
{
this.manager.add(key, sceneConfig, autoStart);
return this;
},
/**
* Launch the given Scene and run it in parallel with this one.
*
* @method Phaser.Scenes.ScenePlugin#launch
* @since 3.0.0
*
* @param {string} key - [description]
* @param {object} [data] - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
launch: function (key, data)
{
if (key && key !== this.key)
{
if (this.settings.status !== CONST.RUNNING)
{
this.manager.queueOp('start', key, data);
}
else
{
this.manager.start(key, data);
}
}
return this;
},
/**
* Pause the Scene - this stops the update step from happening but it still renders.
*
* @method Phaser.Scenes.ScenePlugin#pause
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
pause: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.pause(key);
return this;
},
/**
* Resume the Scene - starts the update loop again.
*
* @method Phaser.Scenes.ScenePlugin#resume
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
resume: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.resume(key);
return this;
},
/**
* Makes the Scene sleep (no update, no render) but doesn't shutdown.
*
* @method Phaser.Scenes.ScenePlugin#sleep
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
sleep: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.sleep(key);
return this;
},
/**
* Makes the Scene wake-up (starts update and render)
*
* @method Phaser.Scenes.ScenePlugin#wake
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
wake: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.wake(key);
return this;
},
/**
* Makes this Scene sleep then starts the Scene given.
*
* @method Phaser.Scenes.ScenePlugin#switch
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
switch: function (key)
{
if (key !== this.key)
{
if (this.settings.status !== CONST.RUNNING)
{
this.manager.queueOp('switch', this.key, key);
}
else
{
this.manager.switch(this.key, key);
}
}
return this;
},
/**
* Shutdown the Scene, clearing display list, timers, etc.
*
* @method Phaser.Scenes.ScenePlugin#stop
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
stop: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.stop(key);
return this;
},
/**
* Sets the active state of the given Scene.
*
* @method Phaser.Scenes.ScenePlugin#setActive
* @since 3.0.0
*
* @param {boolean} value - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
setActive: function (value)
{
this.settings.active = value;
return this;
},
/**
* Sets the visible state of the given Scene.
*
* @method Phaser.Scenes.ScenePlugin#setVisible
* @since 3.0.0
*
* @param {boolean} value - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
setVisible: function (value)
{
this.settings.visible = value;
return this;
},
/**
* Checks if the given Scene is sleeping or not?
*
* @method Phaser.Scenes.ScenePlugin#isSleeping
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {boolean} [description]
*/
isSleeping: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isSleeping(key);
},
/**
* Checks if the given Scene is active or not?
*
* @method Phaser.Scenes.ScenePlugin#isActive
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {boolean} [description]
*/
isActive: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isActive(key);
},
/**
* Checks if the given Scene is visible or not?
*
* @method Phaser.Scenes.ScenePlugin#isVisible
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {boolean} [description]
*/
isVisible: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isVisible(key);
},
/**
* Swaps the position of two scenes in the Scenes list.
* This controls the order in which they are rendered and updated.
*
* @method Phaser.Scenes.ScenePlugin#swapPosition
* @since 3.2.0
*
* @param {string} keyA - The first Scene to swap.
* @param {string} [keyB] - The second Scene to swap. If none is given it defaults to this Scene.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
swapPosition: function (keyA, keyB)
{
if (keyB === undefined) { keyB = this.key; }
if (keyA !== keyB)
{
this.manager.swapPosition(keyA, keyB);
}
return this;
},
/**
* Swaps the position of two scenes in the Scenes list, so that Scene B is directly above Scene A.
* This controls the order in which they are rendered and updated.
*
* @method Phaser.Scenes.ScenePlugin#moveAbove
* @since 3.2.0
*
* @param {string} keyA - The Scene that Scene B will be moved to be above.
* @param {string} [keyB] - The Scene to be moved. If none is given it defaults to this Scene.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
moveAbove: function (keyA, keyB)
{
if (keyB === undefined) { keyB = this.key; }
if (keyA !== keyB)
{
this.manager.moveAbove(keyA, keyB);
}
return this;
},
/**
* Swaps the position of two scenes in the Scenes list, so that Scene B is directly below Scene A.
* This controls the order in which they are rendered and updated.
*
* @method Phaser.Scenes.ScenePlugin#moveBelow
* @since 3.2.0
*
* @param {string} keyA - The Scene that Scene B will be moved to be below.
* @param {string} [keyB] - The Scene to be moved. If none is given it defaults to this Scene.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
moveBelow: function (keyA, keyB)
{
if (keyB === undefined) { keyB = this.key; }
if (keyA !== keyB)
{
this.manager.moveBelow(keyA, keyB);
}
return this;
},
/**
* Removes a Scene from the SceneManager.
*
* The Scene is removed from the local scenes array, it's key is cleared from the keys
* cache and Scene.Systems.destroy is then called on it.
*
* If the SceneManager is processing the Scenes when this method is called it wil
* queue the operation for the next update sequence.
*
* @method Phaser.Scenes.ScenePlugin#remove
* @since 3.2.0
*
* @param {string|Phaser.Scene} scene - The Scene to be removed.
*
* @return {Phaser.Scenes.SceneManager} This SceneManager.
*/
remove: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.remove(key);
return this;
},
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#moveUp
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
moveUp: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.moveUp(key);
return this;
},
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#moveDown
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
moveDown: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.moveDown(key);
return this;
},
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#bringToTop
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
bringToTop: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.bringToTop(key);
return this;
},
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#sendToBack
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
sendToBack: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.sendToBack(key);
return this;
},
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#get
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scene} [description]
*/
get: function (key)
{
return this.manager.getScene(key);
},
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#shutdown
* @since 3.0.0
*/
shutdown: function ()
{
// TODO
},
/**
* [description]
*
* @method Phaser.Scenes.ScenePlugin#destroy
* @since 3.0.0
*/
destroy: function ()
{
// TODO
}
});
PluginManager.register('ScenePlugin', ScenePlugin, 'scenePlugin');
module.exports = ScenePlugin;