Skip to content

Commit

Permalink
Calls to the Scene Manager that happen before the Scene is running ar…
Browse files Browse the repository at this point in the history
…e now queued

Thanks to gdomaradzki for bringing this one to my attention!
  • Loading branch information
photonstorm committed Jan 23, 2018
1 parent dfe2599 commit 123c8f8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 26 deletions.
39 changes: 22 additions & 17 deletions src/scene/SceneManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,21 @@ var SceneManager = new Class({

this.start(entry);
}

// Clear the pending lists
this._start.length = 0;
this._pending.length = 0;

return;
}

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

if (entry.op === 'swapPosition')
{
this.swapPosition(entry.keyA, entry.keyB);
}
else
{
this[entry.op](entry.key);
}
this[entry.op](entry.keyA, entry.keyB);
}

// Clear the pending lists
this._start.length = 0;
this._pending.length = 0;

this._queue.length = 0;
},

Expand Down Expand Up @@ -342,9 +338,11 @@ var SceneManager = new Class({
{
if (scene.create)
{
scene.sys.settings.status = CONST.CREATING;

scene.create.call(scene, scene.sys.settings.data);
}

scene.sys.settings.status = CONST.RUNNING;
},

Expand Down Expand Up @@ -902,7 +900,7 @@ var SceneManager = new Class({
{
if (this._processing)
{
this._queue.push( { op: 'bringToTop', key: key });
this._queue.push( { op: 'bringToTop', keyA: key, keyB: null });
}
else
{
Expand Down Expand Up @@ -934,7 +932,7 @@ var SceneManager = new Class({
{
if (this._processing)
{
this._queue.push( { op: 'sendToBack', key: key });
this._queue.push( { op: 'sendToBack', keyA: key, keyB: null });
}
else
{
Expand Down Expand Up @@ -966,7 +964,7 @@ var SceneManager = new Class({
{
if (this._processing)
{
this._queue.push( { op: 'moveDown', key: key });
this._queue.push( { op: 'moveDown', keyA: key, keyB: null });
}
else
{
Expand Down Expand Up @@ -1000,7 +998,7 @@ var SceneManager = new Class({
{
if (this._processing)
{
this._queue.push( { op: 'moveUp', key: key });
this._queue.push( { op: 'moveUp', keyA: key, keyB: null });
}
else
{
Expand All @@ -1020,6 +1018,13 @@ var SceneManager = new Class({
return this;
},

queueOp: function (op, keyA, keyB)
{
this._queue.push( { op: op, keyA: keyA, keyB: keyB });

return this;
},

/**
* [description]
*
Expand Down
31 changes: 27 additions & 4 deletions src/scene/ScenePlugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var Class = require('../utils/Class');
var CONST = require('./const');
var PluginManager = require('../plugins/PluginManager');

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

if (key !== this.key)
{
this.manager.stop(this.key);
this.manager.start(key);
if (this.settings.status !== CONST.RUNNING)
{
this.manager.queueOp('stop', this.key);
this.manager.queueOp('start', key);
}
else
{
this.manager.stop(this.key);
this.manager.start(key);
}
}

return this;
Expand All @@ -64,7 +73,14 @@ var ScenePlugin = new Class({
{
if (key && key !== this.key)
{
this.manager.start(key);
if (this.settings.status !== CONST.RUNNING)
{
this.manager.queueOp('start', key);
}
else
{
this.manager.start(key);
}
}

return this;
Expand Down Expand Up @@ -115,7 +131,14 @@ var ScenePlugin = new Class({
{
if (key !== this.key)
{
this.manager.switch(this.key, key);
if (this.settings.status !== CONST.RUNNING)
{
this.manager.queueOp('switch', this.key, key);
}
else
{
this.manager.switch(this.key, key);
}
}

return this;
Expand Down
11 changes: 6 additions & 5 deletions src/scene/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ module.exports = {
INIT: 1,
START: 2,
LOADING: 3,
RUNNING: 4,
PAUSED: 5,
SLEEPING: 6,
SHUTDOWN: 7,
DESTROYED: 8
CREATING: 4,
RUNNING: 5,
PAUSED: 6,
SLEEPING: 7,
SHUTDOWN: 8,
DESTROYED: 9

};

0 comments on commit 123c8f8

Please sign in to comment.