var Class = require('../utils/Class'); var CONST = require('./const'); var DefaultPlugins = require('../plugins/DefaultPlugins'); var Events = require('./events'); var GetPhysicsPlugins = require('./GetPhysicsPlugins'); var GetScenePlugins = require('./GetScenePlugins'); var NOOP = require('../utils/NOOP'); var Settings = require('./Settings'); var Systems = new Class({ initialize: function Systems(scene, config){ this.scene = scene; this.game; this.renderer; if (typeof PLUGIN_FBINSTANT) { this.facebook; } this.config = config; this.settings = Settings.create(config); this.canvas; this.context; this.anims; this.cache; this.plugins; this.registry; this.scale; this.sound; this.textures; this.add; this.cameras; this.displayList; this.events; this.make; this.scenePlugin; this.updateList; this.sceneUpdate = NOOP; } , init: function (game){ this.settings.status = CONST.INIT; this.sceneUpdate = NOOP; this.game = game; this.renderer = game.renderer; this.canvas = game.canvas; this.context = game.context; var pluginManager = game.plugins; this.plugins = pluginManager; pluginManager.addToScene(this, DefaultPlugins.Global, [DefaultPlugins.CoreScene, GetScenePlugins(this), GetPhysicsPlugins(this)] ); this.events.emit(Events.BOOT, this); this.settings.isBooted = true ; } , install: function (plugin){ if (!Array.isArray(plugin)) { plugin = [plugin] ; } this.plugins.installLocal(this, plugin); } , step: function (time, delta){ this.events.emit(Events.PRE_UPDATE, time, delta); this.events.emit(Events.UPDATE, time, delta); this.sceneUpdate.call(this.scene, time, delta); this.events.emit(Events.POST_UPDATE, time, delta); } , render: function (renderer){ var displayList = this.displayList; displayList.depthSort(); this.cameras.render(renderer, displayList); this.events.emit(Events.RENDER, renderer); } , queueDepthSort: function (){ this.displayList.queueDepthSort(); } , depthSort: function (){ this.displayList.depthSort(); } , pause: function (data){ if (this.settings.active) { this.settings.status = CONST.PAUSED; this.settings.active = false ; this.events.emit(Events.PAUSE, this, data); } return this; } , resume: function (data){ if (!this.settings.active) { this.settings.status = CONST.RUNNING; this.settings.active = true ; this.events.emit(Events.RESUME, this, data); } return this; } , sleep: function (data){ this.settings.status = CONST.SLEEPING; this.settings.active = false ; this.settings.visible = false ; this.events.emit(Events.SLEEP, this, data); return this; } , wake: function (data){ var settings = this.settings; settings.status = CONST.RUNNING; settings.active = true ; settings.visible = true ; this.events.emit(Events.WAKE, this, data); if (settings.isTransition) { this.events.emit(Events.TRANSITION_WAKE, settings.transitionFrom, settings.transitionDuration); } return this; } , getData: function (){ return this.settings.data; } , isSleeping: function (){ return (this.settings.status === CONST.SLEEPING); } , isActive: function (){ return (this.settings.status === CONST.RUNNING); } , isPaused: function (){ return (this.settings.status === CONST.PAUSED); } , isTransitioning: function (){ return (this.settings.isTransition || this.scenePlugin._target !== null ); } , isTransitionOut: function (){ return (this.scenePlugin._target !== null && this.scenePlugin._duration > 0); } , isTransitionIn: function (){ return (this.settings.isTransition); } , isVisible: function (){ return this.settings.visible; } , setVisible: function (value){ this.settings.visible = value; return this; } , setActive: function (value, data){ if (value) { return this.resume(data); } else { return this.pause(data); } } , start: function (data){ if (data) { this.settings.data = data; } this.settings.status = CONST.START; this.settings.active = true ; this.settings.visible = true ; this.events.emit(Events.START, this); this.events.emit(Events.READY, this, data); } , shutdown: function (data){ this.events.off(Events.TRANSITION_INIT); this.events.off(Events.TRANSITION_START); this.events.off(Events.TRANSITION_COMPLETE); this.events.off(Events.TRANSITION_OUT); this.settings.status = CONST.SHUTDOWN; this.settings.active = false ; this.settings.visible = false ; this.events.emit(Events.SHUTDOWN, this, data); } , destroy: function (){ this.settings.status = CONST.DESTROYED; this.settings.active = false ; this.settings.visible = false ; this.events.emit(Events.DESTROY, this); this.events.removeAllListeners(); var props = ['scene', 'game', 'anims', 'cache', 'plugins', 'registry', 'sound', 'textures', 'add', 'camera', 'displayList', 'events', 'make', 'scenePlugin', 'updateList'] ; for (var i = 0; i < (_AN_Read_length('length', props)); i++ ){ this[props[i]] = null ; } } } ); module.exports = Systems;