Skip to content

Commit 123c8f8

Browse files
committed
Calls to the Scene Manager that happen before the Scene is running are now queued
Thanks to gdomaradzki for bringing this one to my attention!
1 parent dfe2599 commit 123c8f8

3 files changed

Lines changed: 55 additions & 26 deletions

File tree

src/scene/SceneManager.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,21 @@ var SceneManager = new Class({
9090

9191
this.start(entry);
9292
}
93+
94+
// Clear the pending lists
95+
this._start.length = 0;
96+
this._pending.length = 0;
97+
98+
return;
9399
}
94100

95101
for (i = 0; i < queueLength; i++)
96102
{
97103
entry = this._queue[i];
98104

99-
if (entry.op === 'swapPosition')
100-
{
101-
this.swapPosition(entry.keyA, entry.keyB);
102-
}
103-
else
104-
{
105-
this[entry.op](entry.key);
106-
}
105+
this[entry.op](entry.keyA, entry.keyB);
107106
}
108-
109-
// Clear the pending lists
110-
this._start.length = 0;
111-
this._pending.length = 0;
107+
112108
this._queue.length = 0;
113109
},
114110

@@ -342,9 +338,11 @@ var SceneManager = new Class({
342338
{
343339
if (scene.create)
344340
{
341+
scene.sys.settings.status = CONST.CREATING;
342+
345343
scene.create.call(scene, scene.sys.settings.data);
346344
}
347-
345+
348346
scene.sys.settings.status = CONST.RUNNING;
349347
},
350348

@@ -902,7 +900,7 @@ var SceneManager = new Class({
902900
{
903901
if (this._processing)
904902
{
905-
this._queue.push( { op: 'bringToTop', key: key });
903+
this._queue.push( { op: 'bringToTop', keyA: key, keyB: null });
906904
}
907905
else
908906
{
@@ -934,7 +932,7 @@ var SceneManager = new Class({
934932
{
935933
if (this._processing)
936934
{
937-
this._queue.push( { op: 'sendToBack', key: key });
935+
this._queue.push( { op: 'sendToBack', keyA: key, keyB: null });
938936
}
939937
else
940938
{
@@ -966,7 +964,7 @@ var SceneManager = new Class({
966964
{
967965
if (this._processing)
968966
{
969-
this._queue.push( { op: 'moveDown', key: key });
967+
this._queue.push( { op: 'moveDown', keyA: key, keyB: null });
970968
}
971969
else
972970
{
@@ -1000,7 +998,7 @@ var SceneManager = new Class({
1000998
{
1001999
if (this._processing)
10021000
{
1003-
this._queue.push( { op: 'moveUp', key: key });
1001+
this._queue.push( { op: 'moveUp', keyA: key, keyB: null });
10041002
}
10051003
else
10061004
{
@@ -1020,6 +1018,13 @@ var SceneManager = new Class({
10201018
return this;
10211019
},
10221020

1021+
queueOp: function (op, keyA, keyB)
1022+
{
1023+
this._queue.push( { op: op, keyA: keyA, keyB: keyB });
1024+
1025+
return this;
1026+
},
1027+
10231028
/**
10241029
* [description]
10251030
*

src/scene/ScenePlugin.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var Class = require('../utils/Class');
2+
var CONST = require('./const');
23
var PluginManager = require('../plugins/PluginManager');
34

45
// A proxy class to the Global Scene Manager
@@ -44,8 +45,16 @@ var ScenePlugin = new Class({
4445

4546
if (key !== this.key)
4647
{
47-
this.manager.stop(this.key);
48-
this.manager.start(key);
48+
if (this.settings.status !== CONST.RUNNING)
49+
{
50+
this.manager.queueOp('stop', this.key);
51+
this.manager.queueOp('start', key);
52+
}
53+
else
54+
{
55+
this.manager.stop(this.key);
56+
this.manager.start(key);
57+
}
4958
}
5059

5160
return this;
@@ -64,7 +73,14 @@ var ScenePlugin = new Class({
6473
{
6574
if (key && key !== this.key)
6675
{
67-
this.manager.start(key);
76+
if (this.settings.status !== CONST.RUNNING)
77+
{
78+
this.manager.queueOp('start', key);
79+
}
80+
else
81+
{
82+
this.manager.start(key);
83+
}
6884
}
6985

7086
return this;
@@ -115,7 +131,14 @@ var ScenePlugin = new Class({
115131
{
116132
if (key !== this.key)
117133
{
118-
this.manager.switch(this.key, key);
134+
if (this.settings.status !== CONST.RUNNING)
135+
{
136+
this.manager.queueOp('switch', this.key, key);
137+
}
138+
else
139+
{
140+
this.manager.switch(this.key, key);
141+
}
119142
}
120143

121144
return this;

src/scene/const.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ module.exports = {
55
INIT: 1,
66
START: 2,
77
LOADING: 3,
8-
RUNNING: 4,
9-
PAUSED: 5,
10-
SLEEPING: 6,
11-
SHUTDOWN: 7,
12-
DESTROYED: 8
8+
CREATING: 4,
9+
RUNNING: 5,
10+
PAUSED: 6,
11+
SLEEPING: 7,
12+
SHUTDOWN: 8,
13+
DESTROYED: 9
1314

1415
};

0 commit comments

Comments
 (0)