2016-11-29 15:25:14 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2016-12-05 15:29:35 +00:00
|
|
|
var EventDispatcher = require('../events/EventDispatcher');
|
2016-11-29 15:25:14 +00:00
|
|
|
var GameObjectFactory = require('./systems/GameObjectFactory');
|
2016-12-07 02:40:07 +00:00
|
|
|
// var GameObjectCreator = require('./systems/GameObjectCreator');
|
2016-11-30 17:16:45 +00:00
|
|
|
var Loader = require('./systems/Loader');
|
2016-11-29 15:25:14 +00:00
|
|
|
var MainLoop = require('./systems/MainLoop');
|
|
|
|
var UpdateManager = require('./systems/UpdateManager');
|
2016-12-07 02:40:07 +00:00
|
|
|
var Component = require('../components');
|
|
|
|
var Camera = require('../camera/Camera');
|
2016-11-29 15:25:14 +00:00
|
|
|
|
|
|
|
var Systems = function (state, config)
|
|
|
|
{
|
|
|
|
this.state = state;
|
|
|
|
|
|
|
|
this.config = config;
|
|
|
|
|
2016-12-05 15:29:35 +00:00
|
|
|
this.events;
|
|
|
|
|
2016-12-06 16:49:29 +00:00
|
|
|
// Reference to the global Game level TextureManager.
|
|
|
|
this.textures;
|
|
|
|
|
2016-11-29 15:25:14 +00:00
|
|
|
// State specific managers (Factory, Tweens, Loader, Physics, etc)
|
|
|
|
this.add;
|
|
|
|
this.make;
|
|
|
|
this.input;
|
|
|
|
this.load;
|
|
|
|
this.tweens;
|
|
|
|
this.mainloop;
|
|
|
|
this.updates;
|
|
|
|
|
|
|
|
// State specific properties (transform, data, children, etc)
|
|
|
|
this.camera;
|
|
|
|
this.children;
|
|
|
|
this.color;
|
|
|
|
this.data;
|
|
|
|
this.fbo;
|
|
|
|
this.time;
|
|
|
|
this.transform;
|
|
|
|
};
|
|
|
|
|
|
|
|
Systems.prototype.constructor = Systems;
|
|
|
|
|
|
|
|
Systems.prototype = {
|
|
|
|
|
|
|
|
init: function ()
|
|
|
|
{
|
|
|
|
console.log('State.Systems.init');
|
|
|
|
|
2016-12-06 16:49:29 +00:00
|
|
|
this.textures = this.state.game.textures;
|
|
|
|
|
2016-12-06 16:18:28 +00:00
|
|
|
// All of the systems can use the State level EventDispatcher, or their own
|
2016-12-05 15:29:35 +00:00
|
|
|
this.events = new EventDispatcher();
|
2016-11-29 15:25:14 +00:00
|
|
|
|
2016-12-05 15:29:35 +00:00
|
|
|
// State specific managers (Factory, Tweens, Loader, Physics, etc)
|
2016-11-29 15:25:14 +00:00
|
|
|
// All these to be set by a State Config package
|
|
|
|
|
|
|
|
this.add = new GameObjectFactory(this.state);
|
|
|
|
// this.make = GameObjectCreator(this.state);
|
|
|
|
this.mainloop = new MainLoop(this.state, this.state.settings.fps);
|
|
|
|
this.updates = new UpdateManager(this.state);
|
2016-11-30 17:16:45 +00:00
|
|
|
this.load = new Loader(this.state);
|
2016-11-29 15:25:14 +00:00
|
|
|
|
|
|
|
// this.tweens = new Phaser.TweenManager(this.state);
|
|
|
|
// this.input = new Phaser.State.Input(this.state);
|
|
|
|
// this.physics = new Phaser.Physics.Arcade(this.state, 800, 600);
|
|
|
|
|
|
|
|
// State specific properties (transform, data, children, etc)
|
2016-12-07 02:40:07 +00:00
|
|
|
this.camera = new Camera(this.state, 0, 0, 800, 600);
|
|
|
|
this.children = new Component.Children(this.state);
|
|
|
|
this.color = new Component.Color(this.state);
|
|
|
|
this.data = new Component.Data(this.state);
|
|
|
|
this.transform = this.camera.transform;
|
2016-11-29 15:25:14 +00:00
|
|
|
|
|
|
|
// Boot
|
|
|
|
|
|
|
|
// this.input.init();
|
|
|
|
|
|
|
|
// Defaults
|
|
|
|
|
2016-12-05 15:29:35 +00:00
|
|
|
this.state.events = this.events;
|
2016-11-29 15:25:14 +00:00
|
|
|
this.state.add = this.add;
|
2016-11-30 17:16:45 +00:00
|
|
|
this.state.load = this.load;
|
2016-12-07 02:40:07 +00:00
|
|
|
this.state.children = this.children;
|
|
|
|
this.state.color = this.color;
|
|
|
|
this.state.data = this.data;
|
|
|
|
this.state.camera = this.camera;
|
|
|
|
this.state.transform = this.camera.transform;
|
2016-12-08 16:41:23 +00:00
|
|
|
this.state.textures = this.textures;
|
2016-12-07 02:40:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-29 15:25:14 +00:00
|
|
|
// this.state.input = this.input;
|
|
|
|
// this.state.state = this.state.game.state;
|
|
|
|
|
|
|
|
// Here we can check which Systems to install as properties into the State object
|
|
|
|
// (default systems always exist in here, regardless)
|
|
|
|
},
|
|
|
|
|
|
|
|
begin: function (timestamp, frameDelta)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
|
|
|
update: function (timestep, physicsStep)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
|
|
|
preRender: function ()
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
|
|
|
end: function (fps, panic)
|
|
|
|
{
|
|
|
|
if (panic)
|
|
|
|
{
|
|
|
|
// This pattern introduces non-deterministic behavior, but in this case
|
|
|
|
// it's better than the alternative (the application would look like it
|
|
|
|
// was running very quickly until the simulation caught up to real
|
|
|
|
// time).
|
|
|
|
var discardedTime = Math.round(this.mainloop.resetFrameDelta());
|
|
|
|
|
|
|
|
console.warn('Main loop panicked, probably because the browser tab was put in the background. Discarding ' + discardedTime + 'ms');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Systems;
|