Skip to content

Commit 378838a

Browse files
committed
All functions now call 'queueOp'.
Removed sound unlocking on load complete.
1 parent 53c491f commit 378838a

File tree

1 file changed

+100
-121
lines changed

1 file changed

+100
-121
lines changed

src/scene/SceneManager.js

+100-121
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ var SceneManager = new Class({
310310
{
311311
entry = this._queue[i];
312312

313-
this[entry.op](entry.keyA, entry.keyB);
313+
this[entry.op](entry.keyA, entry.keyB, entry.data);
314314
}
315315

316316
this._queue.length = 0;
@@ -427,33 +427,31 @@ var SceneManager = new Class({
427427
{
428428
if (this.isProcessing)
429429
{
430-
this._queue.push({ op: 'remove', keyA: key, keyB: null });
430+
return this.queueOp('remove', key);
431431
}
432-
else
433-
{
434-
var sceneToRemove = this.getScene(key);
435432

436-
if (!sceneToRemove || sceneToRemove.sys.isTransitioning())
437-
{
438-
return this;
439-
}
433+
var sceneToRemove = this.getScene(key);
440434

441-
var index = this.scenes.indexOf(sceneToRemove);
442-
var sceneKey = sceneToRemove.sys.settings.key;
435+
if (!sceneToRemove || sceneToRemove.sys.isTransitioning())
436+
{
437+
return this;
438+
}
443439

444-
if (index > -1)
445-
{
446-
delete this.keys[sceneKey];
447-
this.scenes.splice(index, 1);
440+
var index = this.scenes.indexOf(sceneToRemove);
441+
var sceneKey = sceneToRemove.sys.settings.key;
448442

449-
if (this._start.indexOf(sceneKey) > -1)
450-
{
451-
index = this._start.indexOf(sceneKey);
452-
this._start.splice(index, 1);
453-
}
443+
if (index > -1)
444+
{
445+
delete this.keys[sceneKey];
446+
this.scenes.splice(index, 1);
454447

455-
sceneToRemove.sys.destroy();
448+
if (this._start.indexOf(sceneKey) > -1)
449+
{
450+
index = this._start.indexOf(sceneKey);
451+
this._start.splice(index, 1);
456452
}
453+
454+
sceneToRemove.sys.destroy();
457455
}
458456

459457
return this;
@@ -528,13 +526,6 @@ var SceneManager = new Class({
528526
*/
529527
loadComplete: function (loader)
530528
{
531-
// TODO - Remove. This should *not* be handled here
532-
// Try to unlock HTML5 sounds every time any loader completes
533-
if (this.game.sound && this.game.sound.onBlurPausedSounds)
534-
{
535-
this.game.sound.unlock();
536-
}
537-
538529
this.create(loader.scene);
539530
},
540531

@@ -679,7 +670,7 @@ var SceneManager = new Class({
679670

680671
if (this.keys.hasOwnProperty(key))
681672
{
682-
throw new Error('Cannot add a Scene with duplicate key: ' + key);
673+
throw new Error('Cannot add Scene with duplicate key: ' + key);
683674
}
684675

685676
return this.createSceneFromInstance(key, newScene);
@@ -838,7 +829,7 @@ var SceneManager = new Class({
838829

839830
if (this.keys.hasOwnProperty(key))
840831
{
841-
throw new Error('Cannot add a Scene with duplicate key: ' + key);
832+
throw new Error('Cannot add Scene with duplicate key: ' + key);
842833
}
843834
else
844835
{
@@ -1214,7 +1205,7 @@ var SceneManager = new Class({
12141205

12151206
if (!scene)
12161207
{
1217-
console.warn('Scene not found for key: ' + key);
1208+
console.warn('Scene key not found: ' + key);
12181209
return this;
12191210
}
12201211

@@ -1337,7 +1328,7 @@ var SceneManager = new Class({
13371328

13381329
if (this.isSleeping(to))
13391330
{
1340-
this.wake(to);
1331+
this.wake(to, data);
13411332
}
13421333
else
13431334
{
@@ -1405,19 +1396,18 @@ var SceneManager = new Class({
14051396
{
14061397
if (this.isProcessing)
14071398
{
1408-
this._queue.push({ op: 'bringToTop', keyA: key, keyB: null });
1399+
return this.queueOp('bringToTop', key);
14091400
}
1410-
else
1411-
{
1412-
var index = this.getIndex(key);
14131401

1414-
if (index !== -1 && index < this.scenes.length)
1415-
{
1416-
var scene = this.getScene(key);
1402+
var index = this.getIndex(key);
1403+
var scenes = this.scenes;
14171404

1418-
this.scenes.splice(index, 1);
1419-
this.scenes.push(scene);
1420-
}
1405+
if (index !== -1 && index < scenes.length)
1406+
{
1407+
var scene = this.getScene(key);
1408+
1409+
scenes.splice(index, 1);
1410+
scenes.push(scene);
14211411
}
14221412

14231413
return this;
@@ -1442,19 +1432,17 @@ var SceneManager = new Class({
14421432
{
14431433
if (this.isProcessing)
14441434
{
1445-
this._queue.push({ op: 'sendToBack', keyA: key, keyB: null });
1435+
return this.queueOp('sendToBack', key);
14461436
}
1447-
else
1448-
{
1449-
var index = this.getIndex(key);
14501437

1451-
if (index !== -1 && index > 0)
1452-
{
1453-
var scene = this.getScene(key);
1438+
var index = this.getIndex(key);
14541439

1455-
this.scenes.splice(index, 1);
1456-
this.scenes.unshift(scene);
1457-
}
1440+
if (index !== -1 && index > 0)
1441+
{
1442+
var scene = this.getScene(key);
1443+
1444+
this.scenes.splice(index, 1);
1445+
this.scenes.unshift(scene);
14581446
}
14591447

14601448
return this;
@@ -1477,21 +1465,19 @@ var SceneManager = new Class({
14771465
{
14781466
if (this.isProcessing)
14791467
{
1480-
this._queue.push({ op: 'moveDown', keyA: key, keyB: null });
1468+
return this.queueOp('moveDown', key);
14811469
}
1482-
else
1483-
{
1484-
var indexA = this.getIndex(key);
14851470

1486-
if (indexA > 0)
1487-
{
1488-
var indexB = indexA - 1;
1489-
var sceneA = this.getScene(key);
1490-
var sceneB = this.getAt(indexB);
1471+
var indexA = this.getIndex(key);
14911472

1492-
this.scenes[indexA] = sceneB;
1493-
this.scenes[indexB] = sceneA;
1494-
}
1473+
if (indexA > 0)
1474+
{
1475+
var indexB = indexA - 1;
1476+
var sceneA = this.getScene(key);
1477+
var sceneB = this.getAt(indexB);
1478+
1479+
this.scenes[indexA] = sceneB;
1480+
this.scenes[indexB] = sceneA;
14951481
}
14961482

14971483
return this;
@@ -1514,21 +1500,19 @@ var SceneManager = new Class({
15141500
{
15151501
if (this.isProcessing)
15161502
{
1517-
this._queue.push({ op: 'moveUp', keyA: key, keyB: null });
1503+
return this.queueOp('moveUp', key);
15181504
}
1519-
else
1520-
{
1521-
var indexA = this.getIndex(key);
15221505

1523-
if (indexA < this.scenes.length - 1)
1524-
{
1525-
var indexB = indexA + 1;
1526-
var sceneA = this.getScene(key);
1527-
var sceneB = this.getAt(indexB);
1506+
var indexA = this.getIndex(key);
15281507

1529-
this.scenes[indexA] = sceneB;
1530-
this.scenes[indexB] = sceneA;
1531-
}
1508+
if (indexA < this.scenes.length - 1)
1509+
{
1510+
var indexB = indexA + 1;
1511+
var sceneA = this.getScene(key);
1512+
var sceneB = this.getAt(indexB);
1513+
1514+
this.scenes[indexA] = sceneB;
1515+
this.scenes[indexB] = sceneA;
15321516
}
15331517

15341518
return this;
@@ -1560,23 +1544,21 @@ var SceneManager = new Class({
15601544

15611545
if (this.isProcessing)
15621546
{
1563-
this._queue.push({ op: 'moveAbove', keyA: keyA, keyB: keyB });
1547+
return this.queueOp('moveAbove', keyA, keyB);
15641548
}
1565-
else
1566-
{
1567-
var indexA = this.getIndex(keyA);
1568-
var indexB = this.getIndex(keyB);
15691549

1570-
if (indexA !== -1 && indexB !== -1 && indexB < indexA)
1571-
{
1572-
var tempScene = this.getAt(indexB);
1550+
var indexA = this.getIndex(keyA);
1551+
var indexB = this.getIndex(keyB);
15731552

1574-
// Remove
1575-
this.scenes.splice(indexB, 1);
1553+
if (indexA !== -1 && indexB !== -1 && indexB < indexA)
1554+
{
1555+
var tempScene = this.getAt(indexB);
15761556

1577-
// Add in new location
1578-
this.scenes.splice(indexA + (indexB > indexA), 0, tempScene);
1579-
}
1557+
// Remove
1558+
this.scenes.splice(indexB, 1);
1559+
1560+
// Add in new location
1561+
this.scenes.splice(indexA + (indexB > indexA), 0, tempScene);
15801562
}
15811563

15821564
return this;
@@ -1608,29 +1590,27 @@ var SceneManager = new Class({
16081590

16091591
if (this.isProcessing)
16101592
{
1611-
this._queue.push({ op: 'moveBelow', keyA: keyA, keyB: keyB });
1593+
return this.queueOp('moveBelow', keyA, keyB);
16121594
}
1613-
else
1614-
{
1615-
var indexA = this.getIndex(keyA);
1616-
var indexB = this.getIndex(keyB);
16171595

1618-
if (indexA !== -1 && indexB !== -1 && indexB > indexA)
1619-
{
1620-
var tempScene = this.getAt(indexB);
1596+
var indexA = this.getIndex(keyA);
1597+
var indexB = this.getIndex(keyB);
16211598

1622-
// Remove
1623-
this.scenes.splice(indexB, 1);
1599+
if (indexA !== -1 && indexB !== -1 && indexB > indexA)
1600+
{
1601+
var tempScene = this.getAt(indexB);
16241602

1625-
if (indexA === 0)
1626-
{
1627-
this.scenes.unshift(tempScene);
1628-
}
1629-
else
1630-
{
1631-
// Add in new location
1632-
this.scenes.splice(indexA - (indexB < indexA), 0, tempScene);
1633-
}
1603+
// Remove
1604+
this.scenes.splice(indexB, 1);
1605+
1606+
if (indexA === 0)
1607+
{
1608+
this.scenes.unshift(tempScene);
1609+
}
1610+
else
1611+
{
1612+
// Add in new location
1613+
this.scenes.splice(indexA - (indexB < indexA), 0, tempScene);
16341614
}
16351615
}
16361616

@@ -1647,12 +1627,13 @@ var SceneManager = new Class({
16471627
* @param {string} op - The operation to perform.
16481628
* @param {(string|Phaser.Scene)} keyA - Scene A.
16491629
* @param {(any|string|Phaser.Scene)} [keyB] - Scene B, or a data object.
1630+
* @param {any} [data] - Optional data object to pass.
16501631
*
16511632
* @return {this} This Scene Manager instance.
16521633
*/
1653-
queueOp: function (op, keyA, keyB)
1634+
queueOp: function (op, keyA, keyB, data)
16541635
{
1655-
this._queue.push({ op: op, keyA: keyA, keyB: keyB });
1636+
this._queue.push({ op: op, keyA: keyA, keyB: keyB, data: data });
16561637

16571638
return this;
16581639
},
@@ -1680,20 +1661,18 @@ var SceneManager = new Class({
16801661

16811662
if (this.isProcessing)
16821663
{
1683-
this._queue.push({ op: 'swapPosition', keyA: keyA, keyB: keyB });
1664+
return this.queueOp('swapPosition', keyA, keyB);
16841665
}
1685-
else
1686-
{
1687-
var indexA = this.getIndex(keyA);
1688-
var indexB = this.getIndex(keyB);
16891666

1690-
if (indexA !== indexB && indexA !== -1 && indexB !== -1)
1691-
{
1692-
var tempScene = this.getAt(indexA);
1667+
var indexA = this.getIndex(keyA);
1668+
var indexB = this.getIndex(keyB);
16931669

1694-
this.scenes[indexA] = this.scenes[indexB];
1695-
this.scenes[indexB] = tempScene;
1696-
}
1670+
if (indexA !== indexB && indexA !== -1 && indexB !== -1)
1671+
{
1672+
var tempScene = this.getAt(indexA);
1673+
1674+
this.scenes[indexA] = this.scenes[indexB];
1675+
this.scenes[indexB] = tempScene;
16971676
}
16981677

16991678
return this;

0 commit comments

Comments
 (0)