@@ -310,7 +310,7 @@ var SceneManager = new Class({
310
310
{
311
311
entry = this . _queue [ i ] ;
312
312
313
- this [ entry . op ] ( entry . keyA , entry . keyB ) ;
313
+ this [ entry . op ] ( entry . keyA , entry . keyB , entry . data ) ;
314
314
}
315
315
316
316
this . _queue . length = 0 ;
@@ -427,33 +427,31 @@ var SceneManager = new Class({
427
427
{
428
428
if ( this . isProcessing )
429
429
{
430
- this . _queue . push ( { op : 'remove' , keyA : key , keyB : null } ) ;
430
+ return this . queueOp ( 'remove' , key ) ;
431
431
}
432
- else
433
- {
434
- var sceneToRemove = this . getScene ( key ) ;
435
432
436
- if ( ! sceneToRemove || sceneToRemove . sys . isTransitioning ( ) )
437
- {
438
- return this ;
439
- }
433
+ var sceneToRemove = this . getScene ( key ) ;
440
434
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
+ }
443
439
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 ;
448
442
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 ) ;
454
447
455
- sceneToRemove . sys . destroy ( ) ;
448
+ if ( this . _start . indexOf ( sceneKey ) > - 1 )
449
+ {
450
+ index = this . _start . indexOf ( sceneKey ) ;
451
+ this . _start . splice ( index , 1 ) ;
456
452
}
453
+
454
+ sceneToRemove . sys . destroy ( ) ;
457
455
}
458
456
459
457
return this ;
@@ -528,13 +526,6 @@ var SceneManager = new Class({
528
526
*/
529
527
loadComplete : function ( loader )
530
528
{
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
-
538
529
this . create ( loader . scene ) ;
539
530
} ,
540
531
@@ -679,7 +670,7 @@ var SceneManager = new Class({
679
670
680
671
if ( this . keys . hasOwnProperty ( key ) )
681
672
{
682
- throw new Error ( 'Cannot add a Scene with duplicate key: ' + key ) ;
673
+ throw new Error ( 'Cannot add Scene with duplicate key: ' + key ) ;
683
674
}
684
675
685
676
return this . createSceneFromInstance ( key , newScene ) ;
@@ -838,7 +829,7 @@ var SceneManager = new Class({
838
829
839
830
if ( this . keys . hasOwnProperty ( key ) )
840
831
{
841
- throw new Error ( 'Cannot add a Scene with duplicate key: ' + key ) ;
832
+ throw new Error ( 'Cannot add Scene with duplicate key: ' + key ) ;
842
833
}
843
834
else
844
835
{
@@ -1214,7 +1205,7 @@ var SceneManager = new Class({
1214
1205
1215
1206
if ( ! scene )
1216
1207
{
1217
- console . warn ( 'Scene not found for key : ' + key ) ;
1208
+ console . warn ( 'Scene key not found: ' + key ) ;
1218
1209
return this ;
1219
1210
}
1220
1211
@@ -1337,7 +1328,7 @@ var SceneManager = new Class({
1337
1328
1338
1329
if ( this . isSleeping ( to ) )
1339
1330
{
1340
- this . wake ( to ) ;
1331
+ this . wake ( to , data ) ;
1341
1332
}
1342
1333
else
1343
1334
{
@@ -1405,19 +1396,18 @@ var SceneManager = new Class({
1405
1396
{
1406
1397
if ( this . isProcessing )
1407
1398
{
1408
- this . _queue . push ( { op : 'bringToTop' , keyA : key , keyB : null } ) ;
1399
+ return this . queueOp ( 'bringToTop' , key ) ;
1409
1400
}
1410
- else
1411
- {
1412
- var index = this . getIndex ( key ) ;
1413
1401
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 ;
1417
1404
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 ) ;
1421
1411
}
1422
1412
1423
1413
return this ;
@@ -1442,19 +1432,17 @@ var SceneManager = new Class({
1442
1432
{
1443
1433
if ( this . isProcessing )
1444
1434
{
1445
- this . _queue . push ( { op : 'sendToBack' , keyA : key , keyB : null } ) ;
1435
+ return this . queueOp ( 'sendToBack' , key ) ;
1446
1436
}
1447
- else
1448
- {
1449
- var index = this . getIndex ( key ) ;
1450
1437
1451
- if ( index !== - 1 && index > 0 )
1452
- {
1453
- var scene = this . getScene ( key ) ;
1438
+ var index = this . getIndex ( key ) ;
1454
1439
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 ) ;
1458
1446
}
1459
1447
1460
1448
return this ;
@@ -1477,21 +1465,19 @@ var SceneManager = new Class({
1477
1465
{
1478
1466
if ( this . isProcessing )
1479
1467
{
1480
- this . _queue . push ( { op : 'moveDown' , keyA : key , keyB : null } ) ;
1468
+ return this . queueOp ( 'moveDown' , key ) ;
1481
1469
}
1482
- else
1483
- {
1484
- var indexA = this . getIndex ( key ) ;
1485
1470
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 ) ;
1491
1472
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 ;
1495
1481
}
1496
1482
1497
1483
return this ;
@@ -1514,21 +1500,19 @@ var SceneManager = new Class({
1514
1500
{
1515
1501
if ( this . isProcessing )
1516
1502
{
1517
- this . _queue . push ( { op : 'moveUp' , keyA : key , keyB : null } ) ;
1503
+ return this . queueOp ( 'moveUp' , key ) ;
1518
1504
}
1519
- else
1520
- {
1521
- var indexA = this . getIndex ( key ) ;
1522
1505
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 ) ;
1528
1507
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 ;
1532
1516
}
1533
1517
1534
1518
return this ;
@@ -1560,23 +1544,21 @@ var SceneManager = new Class({
1560
1544
1561
1545
if ( this . isProcessing )
1562
1546
{
1563
- this . _queue . push ( { op : 'moveAbove' , keyA : keyA , keyB : keyB } ) ;
1547
+ return this . queueOp ( 'moveAbove' , keyA , keyB ) ;
1564
1548
}
1565
- else
1566
- {
1567
- var indexA = this . getIndex ( keyA ) ;
1568
- var indexB = this . getIndex ( keyB ) ;
1569
1549
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 ) ;
1573
1552
1574
- // Remove
1575
- this . scenes . splice ( indexB , 1 ) ;
1553
+ if ( indexA !== - 1 && indexB !== - 1 && indexB < indexA )
1554
+ {
1555
+ var tempScene = this . getAt ( indexB ) ;
1576
1556
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 ) ;
1580
1562
}
1581
1563
1582
1564
return this ;
@@ -1608,29 +1590,27 @@ var SceneManager = new Class({
1608
1590
1609
1591
if ( this . isProcessing )
1610
1592
{
1611
- this . _queue . push ( { op : 'moveBelow' , keyA : keyA , keyB : keyB } ) ;
1593
+ return this . queueOp ( 'moveBelow' , keyA , keyB ) ;
1612
1594
}
1613
- else
1614
- {
1615
- var indexA = this . getIndex ( keyA ) ;
1616
- var indexB = this . getIndex ( keyB ) ;
1617
1595
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 ) ;
1621
1598
1622
- // Remove
1623
- this . scenes . splice ( indexB , 1 ) ;
1599
+ if ( indexA !== - 1 && indexB !== - 1 && indexB > indexA )
1600
+ {
1601
+ var tempScene = this . getAt ( indexB ) ;
1624
1602
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 ) ;
1634
1614
}
1635
1615
}
1636
1616
@@ -1647,12 +1627,13 @@ var SceneManager = new Class({
1647
1627
* @param {string } op - The operation to perform.
1648
1628
* @param {(string|Phaser.Scene) } keyA - Scene A.
1649
1629
* @param {(any|string|Phaser.Scene) } [keyB] - Scene B, or a data object.
1630
+ * @param {any } [data] - Optional data object to pass.
1650
1631
*
1651
1632
* @return {this } This Scene Manager instance.
1652
1633
*/
1653
- queueOp : function ( op , keyA , keyB )
1634
+ queueOp : function ( op , keyA , keyB , data )
1654
1635
{
1655
- this . _queue . push ( { op : op , keyA : keyA , keyB : keyB } ) ;
1636
+ this . _queue . push ( { op : op , keyA : keyA , keyB : keyB , data : data } ) ;
1656
1637
1657
1638
return this ;
1658
1639
} ,
@@ -1680,20 +1661,18 @@ var SceneManager = new Class({
1680
1661
1681
1662
if ( this . isProcessing )
1682
1663
{
1683
- this . _queue . push ( { op : 'swapPosition' , keyA : keyA , keyB : keyB } ) ;
1664
+ return this . queueOp ( 'swapPosition' , keyA , keyB ) ;
1684
1665
}
1685
- else
1686
- {
1687
- var indexA = this . getIndex ( keyA ) ;
1688
- var indexB = this . getIndex ( keyB ) ;
1689
1666
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 ) ;
1693
1669
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 ;
1697
1676
}
1698
1677
1699
1678
return this ;
0 commit comments