diff --git a/CHANGELOG.md b/CHANGELOG.md index edf219686..e68aa51ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Version 3.next - in development +### New Plugin Manager + +TODO + ### New Features * You can pass in your own `canvas` and `context` elements in your Game Config and Phaser will use those to render with instead of creating its own. This also allows you to pass in a WebGL 2 context. Fix #3653 (thanks @tgrajewski) @@ -11,9 +15,12 @@ ### Updates +* Game.step now emits a `prestep` event, which some of the global systems hook in to, like Sound and Input. You can use it to perform pre-step tasks, ideally from plugins. +* Game.step now emits a `step` event. This is emitted once per frame. You can hook into it from plugins or code that exists outside of a Scene. +* Game.step now emits a `poststep` event. This is the last chance you get to do things before the render process begins. * Optimized TextureTintPipeline.drawBlitter so it skips bobs that have alpha of zero and only calls `setTexture2D` if the bob sourceIndex has changed, previously it called it for every single bob. * Game.context used to be undefined if running in WebGL. It is now set to be the `WebGLRenderingContext` during WebGLRenderer.init. If you provided your own custom context, it is set to this instead. -* Game.onStepCallback has been removed. +* The Game `onStepCallback` has been removed. You can now listen for the new step events instead. * Phaser.EventEmitter was incorrectly namespaced, it's now only available under Phaser.Events.EventEmitter (thanks Tigran) ### Bug Fixes diff --git a/src/boot/Config.js b/src/boot/Config.js index 9e7ccf45f..1700ca01b 100644 --- a/src/boot/Config.js +++ b/src/boot/Config.js @@ -113,7 +113,6 @@ var ValueToColor = require('../display/color/ValueToColor'); * @since 3.0.0 * * @param {GameConfig} [GameConfig] - The configuration object for your Phaser Game instance. - * */ var Config = new Class({ @@ -452,9 +451,11 @@ var Config = new Class({ * the default plugins like previously, or a config object. * * plugins: { - * install: [ - * { key: 'TestPlugin', plugin: TestPlugin, start: false, isScenePlugin: false }, - * { key: 'WireFramePlugin', plugin: WireFramePlugin, start: true, isScenePlugin: true } + * global: [ + * { key: 'TestPlugin', plugin: TestPlugin, start: true }, + * ], + * scene: [ + * { key: 'WireFramePlugin', plugin: WireFramePlugin, systemKey: 'wireFramePlugin', sceneKey: 'wireframe' } * ], * default: [], OR * defaultMerge: { diff --git a/src/boot/Game.js b/src/boot/Game.js index 651520626..96439cd52 100644 --- a/src/boot/Game.js +++ b/src/boot/Game.js @@ -17,7 +17,6 @@ var Device = require('../device'); var DOMContentLoaded = require('../dom/DOMContentLoaded'); var EventEmitter = require('eventemitter3'); var InputManager = require('../input/InputManager'); -var NOOP = require('../utils/NOOP'); var PluginManager = require('../plugins/PluginManager'); var SceneManager = require('../scene/SceneManager'); var SoundManagerCreator = require('../sound/SoundManagerCreator'); @@ -328,6 +327,40 @@ var Game = new Class({ eventEmitter.on('focus', this.onFocus, this); }, + /** + * Game Pre-Step event. + * + * This event is dispatched before the main Step starts. + * By this point none of the Scene updates have happened. + * Hook into it from plugins or systems that need to update before the Scene Manager does. + * + * @event Phaser.Game#prestepEvent + * @param {number} time - [description] + * @param {number} delta - [description] + */ + + /** + * Game Step event. + * + * This event is dispatched after Pre-Step and before the Scene Manager steps. + * Hook into it from plugins or systems that need to update before the Scene Manager does, but after core Systems. + * + * @event Phaser.Game#stepEvent + * @param {number} time - [description] + * @param {number} delta - [description] + */ + + /** + * Game Post-Step event. + * + * This event is dispatched after the Scene Manager has updated. + * Hook into it from plugins or systems that need to do things before the render starts. + * + * @event Phaser.Game#poststepEvent + * @param {number} time - [description] + * @param {number} delta - [description] + */ + /** * Game Pre-Render event. * @@ -358,6 +391,9 @@ var Game = new Class({ * It will then render each Scene in turn, via the Renderer. This process emits `prerender` and `postrender` events. * * @method Phaser.Game#step + * @fires Phaser.Game#prestepEvent + * @fires Phaser.Game#stepEvent + * @fires Phaser.Game#poststepEvent * @fires Phaser.Game#prerenderEvent * @fires Phaser.Game#postrenderEvent * @since 3.0.0 diff --git a/src/events/index.js b/src/events/index.js index 9476d922c..197a44298 100644 --- a/src/events/index.js +++ b/src/events/index.js @@ -8,8 +8,4 @@ * @namespace Phaser.Events */ -module.exports = { - - EventEmitter: require('./EventEmitter') - -}; +module.exports = { EventEmitter: require('./EventEmitter') }; diff --git a/src/loader/filetypes/PluginFile.js b/src/loader/filetypes/PluginFile.js index 363fb5e57..371cee7f9 100644 --- a/src/loader/filetypes/PluginFile.js +++ b/src/loader/filetypes/PluginFile.js @@ -10,7 +10,6 @@ var File = require('../File'); var FileTypesManager = require('../FileTypesManager'); var GetFastValue = require('../../utils/object/GetFastValue'); var IsPlainObject = require('../../utils/object/IsPlainObject'); -var PluginManager = require('../../plugins/PluginManager'); /** * @typedef {object} Phaser.Loader.FileTypes.PluginFileConfig diff --git a/src/loader/filetypes/ScenePluginFile.js b/src/loader/filetypes/ScenePluginFile.js index cf2e89028..24b3d145d 100644 --- a/src/loader/filetypes/ScenePluginFile.js +++ b/src/loader/filetypes/ScenePluginFile.js @@ -10,7 +10,6 @@ var File = require('../File'); var FileTypesManager = require('../FileTypesManager'); var GetFastValue = require('../../utils/object/GetFastValue'); var IsPlainObject = require('../../utils/object/IsPlainObject'); -var PluginManager = require('../../plugins/PluginManager'); /** * @typedef {object} Phaser.Loader.FileTypes.ScenePluginFileConfig diff --git a/src/plugins/PluginManager.js b/src/plugins/PluginManager.js index 56e0410fa..7311d1dfb 100644 --- a/src/plugins/PluginManager.js +++ b/src/plugins/PluginManager.js @@ -6,7 +6,6 @@ var Class = require('../utils/Class'); var EventEmitter = require('eventemitter3'); -var IsPlainObject = require('../utils/object/IsPlainObject'); var GetFastValue = require('../utils/object/GetFastValue'); // Contains the plugins that Phaser uses globally and locally. @@ -83,6 +82,11 @@ var PluginManager = new Class({ boot: function () { var i; + var entry; + var key; + var plugin; + var start; + var mapping; var config = this.game.config; // Any plugins to install? @@ -93,13 +97,13 @@ var PluginManager = new Class({ for (i = 0; i < list.length; i++) { - var entry = list[i]; + entry = list[i]; // { key: 'TestPlugin', plugin: TestPlugin, start: true } - var key = GetFastValue(entry, 'key', null); - var plugin = GetFastValue(entry, 'plugin', null); - var start = GetFastValue(entry, 'start', false); + key = GetFastValue(entry, 'key', null); + plugin = GetFastValue(entry, 'plugin', null); + start = GetFastValue(entry, 'start', false); if (key && plugin) { @@ -115,13 +119,13 @@ var PluginManager = new Class({ for (i = 0; i < list.length; i++) { - var entry = list[i]; + entry = list[i]; // { key: 'moveSpritePlugin', plugin: MoveSpritePlugin, , mapping: 'move' } - var key = GetFastValue(entry, 'key', null); - var plugin = GetFastValue(entry, 'plugin', null); - var mapping = GetFastValue(entry, 'mapping', null); + key = GetFastValue(entry, 'key', null); + plugin = GetFastValue(entry, 'plugin', null); + mapping = GetFastValue(entry, 'mapping', null); if (key && plugin) {