Skip to content

Commit 134c67a

Browse files
committed
Split into base class and plugin extension so other classes can use them too
1 parent e1609fc commit 134c67a

6 files changed

Lines changed: 100 additions & 49 deletions

File tree

src/CoreScenePlugins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ var CoreScenePlugins = [
1111
'GameObjectCreator',
1212
'GameObjectFactory',
1313
'ScenePlugin',
14-
'DisplayList',
15-
'UpdateList'
14+
'DisplayListPlugin',
15+
'UpdateListPlugin'
1616

1717
];
1818

src/gameobjects/DisplayList.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
var Class = require('../utils/Class');
22
var StableSort = require('../utils/array/StableSort');
3-
var PluginManager = require('../plugins/PluginManager');
43

54
var DisplayList = new Class({
65

76
initialize:
87

9-
function DisplayList (scene)
8+
function DisplayList ()
109
{
11-
// The Scene that owns this plugin
12-
this.scene = scene;
13-
14-
this.systems = scene.sys;
15-
16-
if (!scene.sys.settings.isBooted)
17-
{
18-
scene.sys.events.once('boot', this.boot, this);
19-
}
20-
2110
// The objects that belong to this collection.
2211
// The equivalent of the old `Sprite.children` array.
2312
this.list = [];
@@ -27,14 +16,6 @@ var DisplayList = new Class({
2716
this.position = 0;
2817
},
2918

30-
boot: function ()
31-
{
32-
var eventEmitter = this.systems.events;
33-
34-
eventEmitter.on('shutdown', this.shutdown, this);
35-
eventEmitter.on('destroy', this.destroy, this);
36-
},
37-
3819
process: function ()
3920
{
4021
if (this.sortChildrenFlag)
@@ -725,6 +706,4 @@ var DisplayList = new Class({
725706

726707
});
727708

728-
PluginManager.register('DisplayList', DisplayList, 'displayList');
729-
730709
module.exports = DisplayList;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var Class = require('../utils/Class');
2+
var DisplayList = require('./DisplayList');
3+
var PluginManager = require('../plugins/PluginManager');
4+
5+
var DisplayListPlugin = new Class({
6+
7+
Extends: DisplayList,
8+
9+
initialize:
10+
11+
function DisplayListPlugin (scene)
12+
{
13+
// The Scene that owns this plugin
14+
this.scene = scene;
15+
16+
this.systems = scene.sys;
17+
18+
if (!scene.sys.settings.isBooted)
19+
{
20+
scene.sys.events.once('boot', this.boot, this);
21+
}
22+
23+
DisplayList.call(this);
24+
},
25+
26+
boot: function ()
27+
{
28+
var eventEmitter = this.systems.events;
29+
30+
eventEmitter.on('shutdown', this.shutdown, this);
31+
eventEmitter.on('destroy', this.destroy, this);
32+
},
33+
34+
shutdown: function ()
35+
{
36+
this.removeAll();
37+
},
38+
39+
destroy: function ()
40+
{
41+
this.shutdown();
42+
}
43+
44+
});
45+
46+
PluginManager.register('DisplayListPlugin', DisplayListPlugin, 'displayList');
47+
48+
module.exports = DisplayListPlugin;

src/gameobjects/UpdateList.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
11
var Class = require('../utils/Class');
2-
var PluginManager = require('../plugins/PluginManager');
32

43
var UpdateList = new Class({
54

65
initialize:
76

8-
function UpdateList (scene)
7+
function UpdateList ()
98
{
10-
this.scene = scene;
11-
12-
this.systems = scene.sys;
13-
14-
if (!scene.sys.settings.isBooted)
15-
{
16-
scene.sys.events.once('boot', this.boot, this);
17-
}
18-
199
this._list = [];
2010
this._pendingInsertion = [];
2111
this._pendingRemoval = [];
2212
},
2313

24-
boot: function ()
25-
{
26-
var eventEmitter = this.systems.events;
27-
28-
eventEmitter.on('preupdate', this.preUpdate, this);
29-
eventEmitter.on('update', this.update, this);
30-
eventEmitter.on('shutdown', this.shutdown, this);
31-
eventEmitter.on('destroy', this.destroy, this);
32-
},
33-
3414
add: function (child)
3515
{
3616
// Is child already in this list?
@@ -130,12 +110,8 @@ var UpdateList = new Class({
130110
destroy: function ()
131111
{
132112
this.shutdown();
133-
134-
this.scene = undefined;
135113
}
136114

137115
});
138116

139-
PluginManager.register('UpdateList', UpdateList, 'updateList');
140-
141117
module.exports = UpdateList;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var Class = require('../utils/Class');
2+
var PluginManager = require('../plugins/PluginManager');
3+
var UpdateList = require('./UpdateList');
4+
5+
var UpdateListPlugin = new Class({
6+
7+
Extends: UpdateList,
8+
9+
initialize:
10+
11+
function UpdateListPlugin (scene)
12+
{
13+
this.scene = scene;
14+
15+
this.systems = scene.sys;
16+
17+
if (!scene.sys.settings.isBooted)
18+
{
19+
scene.sys.events.once('boot', this.boot, this);
20+
}
21+
22+
UpdateList.call(this);
23+
},
24+
25+
boot: function ()
26+
{
27+
var eventEmitter = this.systems.events;
28+
29+
eventEmitter.on('preupdate', this.preUpdate, this);
30+
eventEmitter.on('update', this.update, this);
31+
eventEmitter.on('shutdown', this.shutdown, this);
32+
eventEmitter.on('destroy', this.destroy, this);
33+
},
34+
35+
destroy: function ()
36+
{
37+
this.shutdown();
38+
39+
this.scene = undefined;
40+
}
41+
42+
});
43+
44+
PluginManager.register('UpdateListPlugin', UpdateListPlugin, 'updateList');
45+
46+
module.exports = UpdateListPlugin;

src/gameobjects/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
var GameObjects = {
44

55
DisplayList: require('./DisplayList'),
6+
DisplayListPlugin: require('./DisplayListPlugin'),
67
UpdateList: require('./UpdateList'),
8+
UpdateListPlugin: require('./UpdateListPlugin'),
79
GameObjectCreator: require('./GameObjectCreator'),
810
GameObjectFactory: require('./GameObjectFactory'),
911

0 commit comments

Comments
 (0)