mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
Converted to use the new plugin format
This commit is contained in:
parent
9fabd000b5
commit
4240f6c4af
9 changed files with 243 additions and 54 deletions
|
@ -1,4 +1,5 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var PluginManager = require('../../plugins/PluginManager');
|
||||
|
||||
var CameraManager = new Class({
|
||||
|
||||
|
@ -7,9 +8,16 @@ var CameraManager = new Class({
|
|||
function CameraManager (scene)
|
||||
{
|
||||
// The Scene that owns this plugin
|
||||
this.currentCameraId = 1;
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
this.mapping = 'cameras';
|
||||
|
||||
this.systems.events.on('boot', this.boot, this);
|
||||
|
||||
this.currentCameraId = 1;
|
||||
|
||||
this.cameras = [];
|
||||
this.cameraPool = [];
|
||||
|
||||
|
@ -28,6 +36,15 @@ var CameraManager = new Class({
|
|||
this.main = this.cameras[0];
|
||||
},
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
this.systems.inject(this);
|
||||
|
||||
this.systems.events.on('update', this.update, this);
|
||||
this.systems.events.on('shutdown', this.shutdown, this);
|
||||
this.systems.events.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
add3D: require('./inc/AddPerspectiveCamera'),
|
||||
add: require('./inc/Add2DCamera'),
|
||||
addExisting: require('./inc/AddExisting'),
|
||||
|
@ -42,8 +59,15 @@ var CameraManager = new Class({
|
|||
remove: require('./inc/RemoveCamera'),
|
||||
render: require('./inc/Render'),
|
||||
resetAll: require('./inc/ResetAll'),
|
||||
update: require('./inc/Update')
|
||||
update: require('./inc/Update'),
|
||||
|
||||
shutdown: function ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
PluginManager.register('cameras', CameraManager);
|
||||
|
||||
module.exports = CameraManager;
|
||||
|
|
39
src/plugins/TestPlugin.js
Normal file
39
src/plugins/TestPlugin.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
var Class = require('../utils/Class');
|
||||
var PluginManager = require('../plugins/PluginManager');
|
||||
|
||||
var TestPlugin = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function TestPlugin (scene)
|
||||
{
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
this.mapping = 'test';
|
||||
|
||||
console.log('TestPlugin is alive');
|
||||
|
||||
this.systems.events.on('boot', this.boot, this);
|
||||
},
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
console.log('TestPlugin has booted');
|
||||
|
||||
this.scene[this.mapping] = this;
|
||||
},
|
||||
|
||||
fire: function (img)
|
||||
{
|
||||
console.log('Hello!');
|
||||
|
||||
this.systems.add.image(400, 300, img);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
PluginManager.register('test', TestPlugin);
|
||||
|
||||
module.exports = TestPlugin;
|
|
@ -15,7 +15,7 @@ var Settings = require('./Settings');
|
|||
var TweenManager = require('../../tweens/manager/TweenManager');
|
||||
var UpdateList = require('../plugins/UpdateList');
|
||||
|
||||
// var PluginManager = require('../../plugins/PluginManager');
|
||||
var TestPlugin = require('../../plugins/TestPlugin');
|
||||
|
||||
var Systems = new Class({
|
||||
|
||||
|
@ -31,7 +31,7 @@ var Systems = new Class({
|
|||
|
||||
this.settings = Settings.create(config);
|
||||
|
||||
// Set by the GlobalSceneManager - a reference to the game canvas / context
|
||||
// Set by the GlobalSceneManager - a reference to the Scene canvas / context
|
||||
|
||||
this.canvas;
|
||||
this.context;
|
||||
|
@ -46,25 +46,14 @@ var Systems = new Class({
|
|||
|
||||
// These are core Scene plugins, needed by lots of the global systems (and each other)
|
||||
|
||||
this.add;
|
||||
this.cameras;
|
||||
this.displayList;
|
||||
this.events;
|
||||
this.make;
|
||||
this.sceneManager;
|
||||
this.time;
|
||||
this.updateList;
|
||||
|
||||
// Optional Scene plugins - not referenced by core systems, can be overridden with user code
|
||||
|
||||
// this.plugins;
|
||||
|
||||
this.add;
|
||||
this.data;
|
||||
this.dataStore;
|
||||
this.inputManager;
|
||||
this.load;
|
||||
this.make;
|
||||
this.physicsManager;
|
||||
this.tweens;
|
||||
},
|
||||
|
||||
init: function (game)
|
||||
|
@ -83,36 +72,42 @@ var Systems = new Class({
|
|||
|
||||
// These are core Scene plugins, needed by lots of the global systems (and each other)
|
||||
|
||||
this.cameras = new CameraManager(scene);
|
||||
this.displayList = new DisplayList(scene);
|
||||
this.events = new EventEmitter();
|
||||
this.sceneManager = new SceneManager(scene);
|
||||
this.time = new Clock(scene);
|
||||
this.updateList = new UpdateList(scene);
|
||||
|
||||
game.plugins.install(scene, [ 'displayList', 'updateList', 'sceneManager', 'time', 'cameras', 'add', 'make' ]);
|
||||
|
||||
// Optional Scene plugins - not referenced by core systems, can be overridden with user code
|
||||
|
||||
this.add = new GameObjectFactory(scene);
|
||||
// game.plugins.install(scene, [ , 'test' ]);
|
||||
|
||||
this.data = new Data(scene);
|
||||
this.dataStore = new DataStore(scene);
|
||||
this.inputManager = new InputManager(scene);
|
||||
this.load = new Loader(scene);
|
||||
this.make = new GameObjectCreator(scene);
|
||||
this.physicsManager = new PhysicsManager(scene);
|
||||
this.tweens = new TweenManager(scene);
|
||||
|
||||
// this.plugins = new PluginManager(scene);
|
||||
|
||||
// Sometimes the managers need access to a system created after them
|
||||
this.add.boot(this);
|
||||
this.make.boot(this);
|
||||
|
||||
this.events.emit('boot', this);
|
||||
|
||||
this.inputManager.boot();
|
||||
this.physicsManager.boot();
|
||||
|
||||
this.inject();
|
||||
this.inject2();
|
||||
},
|
||||
|
||||
inject: function ()
|
||||
inject: function (plugin)
|
||||
{
|
||||
var map = this.settings.map;
|
||||
|
||||
if (plugin.mapping && map.hasOwnProperty(plugin.mapping))
|
||||
{
|
||||
this.scene[plugin.mapping] = plugin;
|
||||
}
|
||||
},
|
||||
|
||||
inject2: function ()
|
||||
{
|
||||
var map = this.settings.map;
|
||||
|
||||
|
@ -130,6 +125,7 @@ var Systems = new Class({
|
|||
step: function (time, delta)
|
||||
{
|
||||
// Are there any pending SceneManager actions?
|
||||
// This plugin is a special case, as it can literally modify this Scene, so we update it directly.
|
||||
this.sceneManager.update();
|
||||
|
||||
if (!this.settings.active)
|
||||
|
@ -137,24 +133,22 @@ var Systems = new Class({
|
|||
return;
|
||||
}
|
||||
|
||||
// Move these into local arrays, so you can control which systems are registered here and their
|
||||
// execution order
|
||||
this.events.emit('preupdate', time, delta);
|
||||
|
||||
this.updateList.begin(time);
|
||||
this.time.begin(time);
|
||||
this.tweens.begin(time);
|
||||
this.inputManager.begin(time);
|
||||
|
||||
this.events.emit('update', time, delta);
|
||||
|
||||
this.physicsManager.update(time, delta);
|
||||
|
||||
this.updateList.update(time, delta);
|
||||
this.time.update(time, delta);
|
||||
this.tweens.update(time, delta);
|
||||
this.cameras.update(time, delta);
|
||||
this.inputManager.update(time, delta);
|
||||
|
||||
this.scene.update.call(this.scene, time, delta);
|
||||
|
||||
this.events.emit('postupdate', time, delta);
|
||||
|
||||
this.physicsManager.postUpdate();
|
||||
},
|
||||
|
||||
|
@ -252,9 +246,11 @@ var Systems = new Class({
|
|||
this.settings.active = false;
|
||||
this.settings.visible = false;
|
||||
|
||||
this.displayList.shutdown();
|
||||
this.updateList.shutdown();
|
||||
this.time.shutdown();
|
||||
this.events.emit('shutdown', this);
|
||||
|
||||
// this.displayList.shutdown();
|
||||
// this.updateList.shutdown();
|
||||
// this.time.shutdown();
|
||||
this.tweens.shutdown();
|
||||
this.physicsManager.shutdown();
|
||||
|
||||
|
@ -267,8 +263,10 @@ var Systems = new Class({
|
|||
// TODO: Game level nuke
|
||||
destroy: function ()
|
||||
{
|
||||
this.events.emit('destroy', this);
|
||||
|
||||
this.add.destroy();
|
||||
this.time.destroy();
|
||||
// this.time.destroy();
|
||||
this.tweens.destroy();
|
||||
this.physicsManager.destroy();
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var StableSort = require('../../utils/array/StableSort');
|
||||
var PluginManager = require('../../plugins/PluginManager');
|
||||
|
||||
var DisplayList = new Class({
|
||||
|
||||
|
@ -10,6 +11,12 @@ var DisplayList = new Class({
|
|||
// The Scene that owns this plugin
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
this.mapping = 'add';
|
||||
|
||||
this.systems.events.on('boot', this.boot, this);
|
||||
|
||||
// The objects that belong to this collection.
|
||||
// The equivalent of the old `Sprite.children` array.
|
||||
this.list = [];
|
||||
|
@ -19,6 +26,14 @@ var DisplayList = new Class({
|
|||
this.position = 0;
|
||||
},
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
this.systems.inject(this);
|
||||
|
||||
this.systems.events.on('shutdown', this.shutdown, this);
|
||||
this.systems.events.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
process: function ()
|
||||
{
|
||||
if (this.sortChildrenFlag)
|
||||
|
@ -371,11 +386,6 @@ var DisplayList = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
shutdown: function ()
|
||||
{
|
||||
this.removeAll();
|
||||
},
|
||||
|
||||
/**
|
||||
* Brings the given child to the top of this group so it renders above all other children.
|
||||
*
|
||||
|
@ -621,6 +631,16 @@ var DisplayList = new Class({
|
|||
return newParent;
|
||||
},
|
||||
|
||||
shutdown: function ()
|
||||
{
|
||||
this.removeAll();
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.shutdown();
|
||||
},
|
||||
|
||||
length: {
|
||||
|
||||
get: function ()
|
||||
|
@ -704,4 +724,6 @@ var DisplayList = new Class({
|
|||
|
||||
});
|
||||
|
||||
PluginManager.register('displayList', DisplayList);
|
||||
|
||||
module.exports = DisplayList;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var PluginManager = require('../../plugins/PluginManager');
|
||||
|
||||
var GameObjectCreator = new Class({
|
||||
|
||||
|
@ -6,16 +7,33 @@ var GameObjectCreator = new Class({
|
|||
|
||||
function GameObjectCreator (scene)
|
||||
{
|
||||
// The Scene that owns this plugin
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
this.mapping = 'make';
|
||||
|
||||
this.systems.events.on('boot', this.boot, this);
|
||||
|
||||
this.displayList;
|
||||
this.updateList;
|
||||
},
|
||||
|
||||
boot: function (sys)
|
||||
boot: function ()
|
||||
{
|
||||
this.displayList = sys.displayList;
|
||||
this.updateList = sys.updateList;
|
||||
this.systems.inject(this);
|
||||
|
||||
this.displayList = this.systems.displayList;
|
||||
this.updateList = this.systems.updateList;
|
||||
|
||||
this.systems.events.on('shutdown', this.shutdown, this);
|
||||
this.systems.events.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
shutdown: function ()
|
||||
{
|
||||
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
|
@ -37,4 +55,6 @@ GameObjectCreator.register = function (type, factoryFunction)
|
|||
}
|
||||
};
|
||||
|
||||
PluginManager.register('make', GameObjectCreator);
|
||||
|
||||
module.exports = GameObjectCreator;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var PluginManager = require('../../plugins/PluginManager');
|
||||
|
||||
var GameObjectFactory = new Class({
|
||||
|
||||
|
@ -6,16 +7,28 @@ var GameObjectFactory = new Class({
|
|||
|
||||
function GameObjectFactory (scene)
|
||||
{
|
||||
// The Scene that owns this plugin
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
this.mapping = 'time';
|
||||
|
||||
this.systems.events.on('boot', this.boot, this);
|
||||
|
||||
this.displayList;
|
||||
this.updateList;
|
||||
},
|
||||
|
||||
boot: function (sys)
|
||||
boot: function ()
|
||||
{
|
||||
this.displayList = sys.displayList;
|
||||
this.updateList = sys.updateList;
|
||||
this.systems.inject(this);
|
||||
|
||||
this.displayList = this.systems.displayList;
|
||||
this.updateList = this.systems.updateList;
|
||||
|
||||
this.systems.events.on('shutdown', this.shutdown, this);
|
||||
this.systems.events.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
existing: function (child)
|
||||
|
@ -33,6 +46,11 @@ var GameObjectFactory = new Class({
|
|||
return child;
|
||||
},
|
||||
|
||||
shutdown: function ()
|
||||
{
|
||||
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.scene = null;
|
||||
|
@ -52,4 +70,6 @@ GameObjectFactory.register = function (type, factoryFunction)
|
|||
}
|
||||
};
|
||||
|
||||
PluginManager.register('add', GameObjectFactory);
|
||||
|
||||
module.exports = GameObjectFactory;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var PluginManager = require('../../plugins/PluginManager');
|
||||
|
||||
// A proxy class to the Global Scene Manager
|
||||
var SceneManager = new Class({
|
||||
|
@ -10,6 +11,12 @@ var SceneManager = new Class({
|
|||
// The Scene that owns this plugin
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
this.mapping = 'scene';
|
||||
|
||||
this.systems.events.on('boot', this.boot, this);
|
||||
|
||||
this.settings = scene.sys.settings;
|
||||
|
||||
this.key = scene.sys.settings.key;
|
||||
|
@ -21,6 +28,14 @@ var SceneManager = new Class({
|
|||
this._queue = [];
|
||||
},
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
this.systems.inject(this);
|
||||
|
||||
this.systems.events.on('shutdown', this.shutdown, this);
|
||||
this.systems.events.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
update: function ()
|
||||
{
|
||||
var len = this._queue.length;
|
||||
|
@ -229,8 +244,20 @@ var SceneManager = new Class({
|
|||
if (key === undefined) { key = this.key; }
|
||||
|
||||
return this.manager.isActive(key);
|
||||
},
|
||||
|
||||
shutdown: function ()
|
||||
{
|
||||
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
PluginManager.register('sceneManager', SceneManager);
|
||||
|
||||
module.exports = SceneManager;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var PluginManager = require('../../plugins/PluginManager');
|
||||
|
||||
// TODO - Extend from ProcessQueue
|
||||
var UpdateList = new Class({
|
||||
|
@ -9,11 +10,27 @@ var UpdateList = new Class({
|
|||
{
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
this.mapping = 'children';
|
||||
|
||||
this.systems.events.on('boot', this.boot, this);
|
||||
|
||||
this._list = [];
|
||||
this._pendingInsertion = [];
|
||||
this._pendingRemoval = [];
|
||||
},
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
this.systems.inject(this);
|
||||
|
||||
this.systems.events.on('preupdate', this.preUpdate, this);
|
||||
this.systems.events.on('update', this.update, this);
|
||||
this.systems.events.on('shutdown', this.shutdown, this);
|
||||
this.systems.events.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
add: function (child)
|
||||
{
|
||||
// Is child already in this list?
|
||||
|
@ -26,7 +43,7 @@ var UpdateList = new Class({
|
|||
return child;
|
||||
},
|
||||
|
||||
begin: function ()
|
||||
preUpdate: function (time, delta)
|
||||
{
|
||||
var toRemove = this._pendingRemoval.length;
|
||||
var toInsert = this._pendingInsertion.length;
|
||||
|
@ -119,4 +136,6 @@ var UpdateList = new Class({
|
|||
|
||||
});
|
||||
|
||||
PluginManager.register('updateList', UpdateList);
|
||||
|
||||
module.exports = UpdateList;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var Class = require('../utils/Class');
|
||||
var PluginManager = require('../plugins/PluginManager');
|
||||
var TimerEvent = require('./TimerEvent');
|
||||
|
||||
var Clock = new Class({
|
||||
|
@ -7,8 +8,15 @@ var Clock = new Class({
|
|||
|
||||
function Clock (scene)
|
||||
{
|
||||
// The Scene that owns this plugin
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
this.mapping = 'time';
|
||||
|
||||
this.systems.events.on('boot', this.boot, this);
|
||||
|
||||
this.now = Date.now();
|
||||
|
||||
// Scale the delta time coming into the Clock by this factor
|
||||
|
@ -22,6 +30,16 @@ var Clock = new Class({
|
|||
this._pendingRemoval = [];
|
||||
},
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
this.systems.inject(this);
|
||||
|
||||
this.systems.events.on('preupdate', this.preUpdate, this);
|
||||
this.systems.events.on('update', this.update, this);
|
||||
this.systems.events.on('shutdown', this.shutdown, this);
|
||||
this.systems.events.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
addEvent: function (config)
|
||||
{
|
||||
var event = new TimerEvent(config);
|
||||
|
@ -48,7 +66,7 @@ var Clock = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
begin: function ()
|
||||
preUpdate: function (time, delta)
|
||||
{
|
||||
var toRemove = this._pendingRemoval.length;
|
||||
var toInsert = this._pendingInsertion.length;
|
||||
|
@ -182,4 +200,6 @@ var Clock = new Class({
|
|||
|
||||
});
|
||||
|
||||
PluginManager.register('time', Clock);
|
||||
|
||||
module.exports = Clock;
|
||||
|
|
Loading…
Reference in a new issue