Split into base class and plugin extension so other classes can use them too

This commit is contained in:
Richard Davey 2018-01-20 16:21:12 +00:00
parent e1609fc866
commit 134c67a51b
6 changed files with 100 additions and 49 deletions

View file

@ -11,8 +11,8 @@ var CoreScenePlugins = [
'GameObjectCreator',
'GameObjectFactory',
'ScenePlugin',
'DisplayList',
'UpdateList'
'DisplayListPlugin',
'UpdateListPlugin'
];

View file

@ -1,23 +1,12 @@
var Class = require('../utils/Class');
var StableSort = require('../utils/array/StableSort');
var PluginManager = require('../plugins/PluginManager');
var DisplayList = new Class({
initialize:
function DisplayList (scene)
function DisplayList ()
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
// The objects that belong to this collection.
// The equivalent of the old `Sprite.children` array.
this.list = [];
@ -27,14 +16,6 @@ var DisplayList = new Class({
this.position = 0;
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
process: function ()
{
if (this.sortChildrenFlag)
@ -725,6 +706,4 @@ var DisplayList = new Class({
});
PluginManager.register('DisplayList', DisplayList, 'displayList');
module.exports = DisplayList;

View file

@ -0,0 +1,48 @@
var Class = require('../utils/Class');
var DisplayList = require('./DisplayList');
var PluginManager = require('../plugins/PluginManager');
var DisplayListPlugin = new Class({
Extends: DisplayList,
initialize:
function DisplayListPlugin (scene)
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
DisplayList.call(this);
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
shutdown: function ()
{
this.removeAll();
},
destroy: function ()
{
this.shutdown();
}
});
PluginManager.register('DisplayListPlugin', DisplayListPlugin, 'displayList');
module.exports = DisplayListPlugin;

View file

@ -1,36 +1,16 @@
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
var UpdateList = new Class({
initialize:
function UpdateList (scene)
function UpdateList ()
{
this.scene = scene;
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
this._list = [];
this._pendingInsertion = [];
this._pendingRemoval = [];
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('preupdate', this.preUpdate, this);
eventEmitter.on('update', this.update, this);
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
add: function (child)
{
// Is child already in this list?
@ -130,12 +110,8 @@ var UpdateList = new Class({
destroy: function ()
{
this.shutdown();
this.scene = undefined;
}
});
PluginManager.register('UpdateList', UpdateList, 'updateList');
module.exports = UpdateList;

View file

@ -0,0 +1,46 @@
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
var UpdateList = require('./UpdateList');
var UpdateListPlugin = new Class({
Extends: UpdateList,
initialize:
function UpdateListPlugin (scene)
{
this.scene = scene;
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
UpdateList.call(this);
},
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('preupdate', this.preUpdate, this);
eventEmitter.on('update', this.update, this);
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
destroy: function ()
{
this.shutdown();
this.scene = undefined;
}
});
PluginManager.register('UpdateListPlugin', UpdateListPlugin, 'updateList');
module.exports = UpdateListPlugin;

View file

@ -3,7 +3,9 @@
var GameObjects = {
DisplayList: require('./DisplayList'),
DisplayListPlugin: require('./DisplayListPlugin'),
UpdateList: require('./UpdateList'),
UpdateListPlugin: require('./UpdateListPlugin'),
GameObjectCreator: require('./GameObjectCreator'),
GameObjectFactory: require('./GameObjectFactory'),