phaser/v3/src/state/Systems.js

171 lines
4.4 KiB
JavaScript
Raw Normal View History

var CameraManager = require('./systems/CameraManager');
2017-06-28 16:17:54 +00:00
var Clock = require('../time/Clock');
var Component = require('../components');
var EventDispatcher = require('../events/EventDispatcher');
var GameObjectCreator = require('./systems/GameObjectCreator');
var GameObjectFactory = require('./systems/GameObjectFactory');
var Loader = require('./systems/Loader');
var Settings = require('./Settings');
2017-03-23 19:51:02 +00:00
var StableSort = require('../utils/array/StableSort');
var StateManager = require('./systems/StateManager');
var TweenManager = require('../tween/TweenManager');
2017-06-28 16:17:54 +00:00
var UpdateManager = require('./systems/UpdateManager');
var Systems = function (state, config)
{
this.state = state;
this.config = config;
2017-02-06 23:59:15 +00:00
this.settings = Settings.create(config);
// this.x = this.settings.x;
// this.y = this.settings.y;
// this.width = this.settings.width;
// this.height = this.settings.height;
this.sortChildrenFlag = false;
// Set by the GlobalStateManager
this.mask = null;
this.canvas;
this.context;
// CORE (GLOBAL) SYSTEMS / PROPERTIES
this.game;
this.anims;
this.cache;
this.input;
this.textures;
// Reference to State specific managers (Factory, Tweens, Loader, Physics, etc)
this.add;
this.cameras;
2017-06-28 16:17:54 +00:00
this.time;
this.events;
this.load;
this.make;
this.stateManager;
this.updates;
this.tweens;
// State properties
this.children;
this.color;
this.data;
};
Systems.prototype.constructor = Systems;
Systems.prototype = {
init: function (game)
{
this.game = game;
// Settings.init(this.settings, this.game.config);
// this.width = this.settings.width;
// this.height = this.settings.height;
this.anims = this.game.anims;
this.cache = this.game.cache;
this.input = this.game.input;
this.textures = this.game.textures;
// State specific properties (transform, data, children, etc)
2016-12-07 02:40:07 +00:00
this.children = new Component.Children(this.state);
this.color = new Component.Color(this.state);
this.data = new Component.Data(this.state);
// State specific managers (Factory, Tweens, Loader, Physics, etc)
this.add = new GameObjectFactory(this.state);
this.cameras = new CameraManager(this.state);
this.events = new EventDispatcher();
this.load = new Loader(this.state);
this.make = new GameObjectCreator(this.state);
this.stateManager = new StateManager(this.state, game);
this.time = new Clock(this.state);
this.tweens = new TweenManager(this.state);
this.updates = new UpdateManager(this.state);
this.inject();
},
inject: function ()
{
// Defaults properties injected into the State
this.state.game = this.game;
this.state.anims = this.anims;
this.state.cache = this.cache;
this.state.input = this.input;
this.state.textures = this.textures;
this.state.add = this.add;
this.state.cameras = this.cameras;
this.state.events = this.events;
this.state.load = this.load;
2017-06-28 16:17:54 +00:00
this.state.make = this.make;
this.state.settings = this.settings;
this.state.state = this.stateManager;
2017-06-28 16:17:54 +00:00
this.state.time = this.time;
this.state.tweens = this.tweens;
this.state.children = this.children;
this.state.color = this.color;
this.state.data = this.data;
},
step: function (time, delta)
{
2017-06-28 16:17:54 +00:00
this.time.begin(time);
2017-05-17 03:37:30 +00:00
this.tweens.begin(time);
var list = this.children.list;
for (var i = 0; i < list.length; i++)
{
list[i].preUpdate(time, delta);
}
// preUpdate TimerEvents
2017-06-28 16:17:54 +00:00
this.time.update(time, delta);
2017-05-17 03:37:30 +00:00
this.tweens.update(time, delta);
this.cameras.update(time, delta);
this.state.update.call(this.state, time, delta);
},
render: function (interpolation, renderer)
{
if (!this.settings.visible)
{
return;
}
if (this.sortChildrenFlag)
{
StableSort.inplace(this.children.list, this.sortZ);
this.sortChildrenFlag = false;
}
this.cameras.render(renderer, this.children, interpolation);
},
sortZ: function (childA, childB)
{
return childA._z - childB._z;
2017-02-08 00:08:09 +00:00
}
};
module.exports = Systems;