From 8fdedabaebae42649246d4a52daf6cff647ec216 Mon Sep 17 00:00:00 2001 From: orblazer Date: Mon, 19 Mar 2018 21:41:24 +0100 Subject: [PATCH 1/7] Add callbacks on Renderer --- src/renderer/canvas/CanvasRenderer.js | 8 +++--- src/renderer/snapshot/index.js | 6 +++++ src/renderer/webgl/WebGLRenderer.js | 38 ++++++++++++++++----------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/renderer/canvas/CanvasRenderer.js b/src/renderer/canvas/CanvasRenderer.js index f4ac30644..203d87f33 100644 --- a/src/renderer/canvas/CanvasRenderer.js +++ b/src/renderer/canvas/CanvasRenderer.js @@ -132,7 +132,7 @@ var CanvasRenderer = new Class({ * Map to the required function. * * @name Phaser.Renderer.Canvas.CanvasRenderer#drawImage - * @type {function} + * @type {Phaser.Renderer.Canvas.DrawImage} * @since 3.0.0 */ this.drawImage = DrawImage(this.config.roundPixels); @@ -141,7 +141,7 @@ var CanvasRenderer = new Class({ * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#blitImage - * @type {function} + * @type {Phaser.Renderer.Canvas.BlitImage} * @since 3.0.0 */ this.blitImage = BlitImage(this.config.roundPixels); @@ -189,7 +189,7 @@ var CanvasRenderer = new Class({ * [description] * * @name Phaser.Renderer.Canvas.CanvasRenderer#snapshotCallback - * @type {?function} + * @type {?SnapshotCallback} * @default null * @since 3.0.0 */ @@ -494,7 +494,7 @@ var CanvasRenderer = new Class({ * @method Phaser.Renderer.Canvas.CanvasRenderer#snapshot * @since 3.0.0 * - * @param {function} callback - [description] + * @param {SnapshotCallback} callback - [description] * @param {string} type - [description] * @param {number} encoderOptions - [description] */ diff --git a/src/renderer/snapshot/index.js b/src/renderer/snapshot/index.js index 0085647e1..cbbe86b76 100644 --- a/src/renderer/snapshot/index.js +++ b/src/renderer/snapshot/index.js @@ -4,6 +4,12 @@ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ +/** + * @callback SnapshotCallback + * + * @param {HTMLImageElement} snapshot - [description] + */ + /** * @namespace Phaser.Renderer.Snapshot */ diff --git a/src/renderer/webgl/WebGLRenderer.js b/src/renderer/webgl/WebGLRenderer.js index f2089b9ce..70c744d74 100644 --- a/src/renderer/webgl/WebGLRenderer.js +++ b/src/renderer/webgl/WebGLRenderer.js @@ -16,6 +16,12 @@ var FlatTintPipeline = require('./pipelines/FlatTintPipeline'); var ForwardDiffuseLightPipeline = require('./pipelines/ForwardDiffuseLightPipeline'); var TextureTintPipeline = require('./pipelines/TextureTintPipeline'); +/** + * @callback WebGLContextCallback + * + * @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - [description] + */ + /** * @classdesc * [description] @@ -115,7 +121,7 @@ var WebGLRenderer = new Class({ * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#lostContextCallbacks - * @type {function[]} + * @type {WebGLContextCallback[]} * @since 3.0.0 */ this.lostContextCallbacks = []; @@ -124,7 +130,7 @@ var WebGLRenderer = new Class({ * [description] * * @name Phaser.Renderer.WebGL.WebGLRenderer#restoredContextCallbacks - * @type {function[]} + * @type {WebGLContextCallback[]} * @since 3.0.0 */ this.restoredContextCallbacks = []; @@ -384,7 +390,7 @@ var WebGLRenderer = new Class({ var canvas = this.canvas; var clearColor = config.backgroundColor; var gl = canvas.getContext('webgl', config.contextCreation) || canvas.getContext('experimental-webgl', config.contextCreation); - + if (!gl) { this.contextLost = true; @@ -431,10 +437,10 @@ var WebGLRenderer = new Class({ this.addPipeline('FlatTintPipeline', new FlatTintPipeline({ game: this.game, renderer: this })); this.addPipeline('BitmapMaskPipeline', new BitmapMaskPipeline({ game: this.game, renderer: this })); this.addPipeline('Light2D', new ForwardDiffuseLightPipeline({ game: this.game, renderer: this })); - + this.setBlendMode(CONST.BlendModes.NORMAL); this.resize(this.width, this.height); - + return this; }, @@ -457,7 +463,7 @@ var WebGLRenderer = new Class({ this.width = Math.floor(width * resolution); this.height = Math.floor(height * resolution); - + this.canvas.width = this.width; this.canvas.height = this.height; @@ -484,7 +490,7 @@ var WebGLRenderer = new Class({ * @method Phaser.Renderer.WebGL.WebGLRenderer#onContextRestored * @since 3.0.0 * - * @param {function} callback - [description] + * @param {WebGLContextCallback} callback - [description] * @param {object} target - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] @@ -502,7 +508,7 @@ var WebGLRenderer = new Class({ * @method Phaser.Renderer.WebGL.WebGLRenderer#onContextLost * @since 3.0.0 * - * @param {function} callback - [description] + * @param {WebGLContextCallback} callback - [description] * @param {object} target - [description] * * @return {Phaser.Renderer.WebGL.WebGLRenderer} [description] @@ -713,7 +719,7 @@ var WebGLRenderer = new Class({ scissorStack[stackIndex + 1] = currentScissor[1]; scissorStack[stackIndex + 2] = currentScissor[2]; scissorStack[stackIndex + 3] = currentScissor[3]; - + this.currentScissorIdx += 4; this.setScissor(x, y, w, h); @@ -732,7 +738,7 @@ var WebGLRenderer = new Class({ { var scissorStack = this.scissorStack; var stackIndex = this.currentScissorIdx - 4; - + var x = scissorStack[stackIndex + 0]; var y = scissorStack[stackIndex + 1]; var w = scissorStack[stackIndex + 2]; @@ -740,7 +746,7 @@ var WebGLRenderer = new Class({ this.currentScissorIdx = stackIndex; this.setScissor(x, y, w, h); - + return this; }, @@ -1002,7 +1008,7 @@ var WebGLRenderer = new Class({ if (indexBuffer !== this.currentIndexBuffer) { this.flush(); - + gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); this.currentIndexBuffer = indexBuffer; @@ -1089,7 +1095,7 @@ var WebGLRenderer = new Class({ pma = (pma === undefined || pma === null) ? true : pma; this.setTexture2D(texture, 0); - + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrapS); @@ -1356,7 +1362,7 @@ var WebGLRenderer = new Class({ var ch = Math.floor(camera.height * resolution); this.pushScissor(cx, cy, cw, ch); - + if (camera.backgroundColor.alphaGL > 0) { var color = camera.backgroundColor; @@ -1533,7 +1539,7 @@ var WebGLRenderer = new Class({ * @method Phaser.Renderer.WebGL.WebGLRenderer#snapshot * @since 3.0.0 * - * @param {function} callback - [description] + * @param {SnapshotCallback} callback - [description] * @param {string} type - [description] * @param {float} encoderOptions - [description] * @@ -1894,7 +1900,7 @@ var WebGLRenderer = new Class({ { this.getExtension('WEBGL_lose_context').loseContext(); } - + delete this.gl; delete this.game; From f30218d3d3a6e152d9ac627777b9c90d3dc1918f Mon Sep 17 00:00:00 2001 From: orblazer Date: Mon, 19 Mar 2018 21:42:07 +0100 Subject: [PATCH 2/7] Add callbacks on Physics --- src/physics/arcade/ArcadePhysics.js | 8 ++--- src/physics/arcade/Collider.js | 8 ++--- src/physics/arcade/Factory.js | 8 ++--- src/physics/arcade/World.js | 54 ++++++++++++++--------------- src/physics/arcade/index.js | 9 ++++- src/physics/impact/Body.js | 8 ++++- 6 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js index c3c26e8d6..54420d02d 100644 --- a/src/physics/arcade/ArcadePhysics.js +++ b/src/physics/arcade/ArcadePhysics.js @@ -144,8 +144,8 @@ var ArcadePhysics = new Class({ * * @param {Phaser.GameObjects.GameObject|array} object1 - The first object or array of objects to check. Can be any Game Object that has an Arcade Physics Body. * @param {Phaser.GameObjects.GameObject|array} object2 - The second object or array of objects to check. Can be any Game Object that has an Arcade Physics Body. - * @param {function} [overlapCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them, unless you are checking Group vs. Sprite, in which case Sprite will always be the first parameter. - * @param {function} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then `overlapCallback` will only be called if this callback returns `true`. + * @param {ArcadePhysicsCallback} [overlapCallback=null] - An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them, unless you are checking Group vs. Sprite, in which case Sprite will always be the first parameter. + * @param {ArcadePhysicsCallback} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then `overlapCallback` will only be called if this callback returns `true`. * @param {object} [callbackContext] - The context in which to run the callbacks. * * @return {boolean} True if an overlap occurred otherwise false. @@ -167,8 +167,8 @@ var ArcadePhysics = new Class({ * * @param {Phaser.GameObjects.GameObject|array} object1 - The first object or array of objects to check. Can be any Game Object that has an Arcade Physics Body. * @param {Phaser.GameObjects.GameObject|array} object2 - The second object or array of objects to check. Can be any Game Object that has an Arcade Physics Body. - * @param {function} [collideCallback=null] - An optional callback function that is called if the objects collide. The two objects will be passed to this function in the same order in which you specified them, unless you are checking Group vs. Sprite, in which case Sprite will always be the first parameter. - * @param {function} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. + * @param {ArcadePhysicsCallback} [collideCallback=null] - An optional callback function that is called if the objects collide. The two objects will be passed to this function in the same order in which you specified them, unless you are checking Group vs. Sprite, in which case Sprite will always be the first parameter. + * @param {ArcadePhysicsCallback} [processCallback=null] - A callback function that lets you perform additional checks against the two objects if they collide. If this is set then `collideCallback` will only be called if this callback returns `true`. * @param {object} [callbackContext] - The context in which to run the callbacks. * * @return {boolean} True if a collision occurred otherwise false. diff --git a/src/physics/arcade/Collider.js b/src/physics/arcade/Collider.js index bc287e38a..e838fe993 100644 --- a/src/physics/arcade/Collider.js +++ b/src/physics/arcade/Collider.js @@ -19,8 +19,8 @@ var Class = require('../../utils/Class'); * @param {boolean} overlapOnly - [description] * @param {Phaser.Physics.Arcade.Body} object1 - The first object to check for collision. * @param {Phaser.Physics.Arcade.Body} object2 - The second object to check for collision. - * @param {function} collideCallback - The callback to invoke when the two objects collide. - * @param {function} processCallback - The callback to invoke when the two objects collide. Must return a boolean. + * @param {ArcadePhysicsCallback} collideCallback - The callback to invoke when the two objects collide. + * @param {ArcadePhysicsCallback} processCallback - The callback to invoke when the two objects collide. Must return a boolean. * @param {object} callbackContext - The scope in which to call the callbacks. */ var Collider = new Class({ @@ -88,7 +88,7 @@ var Collider = new Class({ * [description] * * @name Phaser.Physics.Arcade.Collider#collideCallback - * @type {function} + * @type {ArcadePhysicsCallback} * @since 3.0.0 */ this.collideCallback = collideCallback; @@ -97,7 +97,7 @@ var Collider = new Class({ * [description] * * @name Phaser.Physics.Arcade.Collider#processCallback - * @type {function} + * @type {ArcadePhysicsCallback} * @since 3.0.0 */ this.processCallback = processCallback; diff --git a/src/physics/arcade/Factory.js b/src/physics/arcade/Factory.js index fba5ea9bf..90c186164 100644 --- a/src/physics/arcade/Factory.js +++ b/src/physics/arcade/Factory.js @@ -65,8 +65,8 @@ var Factory = new Class({ * * @param {Phaser.Physics.Arcade.Body} object1 - The first object to check for collision. * @param {Phaser.Physics.Arcade.Body} object2 - The second object to check for collision. - * @param {function} collideCallback - The callback to invoke when the two objects collide. - * @param {function} processCallback - The callback to invoke when the two objects collide. Must return a boolean. + * @param {ArcadePhysicsCallback} collideCallback - The callback to invoke when the two objects collide. + * @param {ArcadePhysicsCallback} processCallback - The callback to invoke when the two objects collide. Must return a boolean. * @param {object} callbackContext - The scope in which to call the callbacks. * * @return {Phaser.Physics.Arcade.Collider} The Collider that was created. @@ -84,8 +84,8 @@ var Factory = new Class({ * * @param {Phaser.Physics.Arcade.Body} object1 - The first object to check for overlap. * @param {Phaser.Physics.Arcade.Body} object2 - The second object to check for overlap. - * @param {function} collideCallback - The callback to invoke when the two objects collide. - * @param {function} processCallback - The callback to invoke when the two objects collide. Must return a boolean. + * @param {ArcadePhysicsCallback} collideCallback - The callback to invoke when the two objects collide. + * @param {ArcadePhysicsCallback} processCallback - The callback to invoke when the two objects collide. Must return a boolean. * @param {object} callbackContext - The scope in which to call the callbacks. * * @return {Phaser.Physics.Arcade.Collider} The Collider that was created. diff --git a/src/physics/arcade/World.js b/src/physics/arcade/World.js index d88bb0f1b..297fa07d1 100644 --- a/src/physics/arcade/World.js +++ b/src/physics/arcade/World.js @@ -565,9 +565,9 @@ var World = new Class({ * * @param {Phaser.Physics.Arcade.Body} object1 - The first object to check for collision. * @param {Phaser.Physics.Arcade.Body} object2 - The second object to check for collision. - * @param {function} collideCallback - The callback to invoke when the two objects collide. - * @param {function} processCallback - The callback to invoke when the two objects collide. Must return a boolean. - * @param {object} callbackContext - The scope in which to call the callbacks. + * @param {ArcadePhysicsCallback} [collideCallback] - The callback to invoke when the two objects collide. + * @param {ArcadePhysicsCallback} [processCallback] - The callback to invoke when the two objects collide. Must return a boolean. + * @param {object} [callbackContext] - The scope in which to call the callbacks. * * @return {Phaser.Physics.Arcade.Collider} The Collider that was created. */ @@ -592,9 +592,9 @@ var World = new Class({ * * @param {Phaser.Physics.Arcade.Body} object1 - The first object to check for overlap. * @param {Phaser.Physics.Arcade.Body} object2 - The second object to check for overlap. - * @param {function} collideCallback - The callback to invoke when the two objects overlap. - * @param {function} processCallback - The callback to invoke when the two objects overlap. Must return a boolean. - * @param {object} callbackContext - The scope in which to call the callbacks. + * @param {ArcadePhysicsCallback} [collideCallback] - The callback to invoke when the two objects overlap. + * @param {ArcadePhysicsCallback} [processCallback] - The callback to invoke when the two objects overlap. Must return a boolean. + * @param {object} [callbackContext] - The scope in which to call the callbacks. * * @return {Phaser.Physics.Arcade.Collider} The Collider that was created. */ @@ -865,7 +865,7 @@ var World = new Class({ * * @param {Phaser.Physics.Arcade.Body} body1 - [description] * @param {Phaser.Physics.Arcade.Body} body2 - [description] - * @param {function} processCallback - [description] + * @param {ArcadePhysicsCallback} processCallback - [description] * @param {object} callbackContext - [description] * @param {boolean} overlapOnly - [description] * @@ -1249,9 +1249,9 @@ var World = new Class({ * * @param {Phaser.GameObjects.GameObject} object1 - [description] * @param {Phaser.GameObjects.GameObject} object2 - [description] - * @param {function} overlapCallback - [description] - * @param {function} processCallback - [description] - * @param {object} callbackContext - [description] + * @param {ArcadePhysicsCallback} [overlapCallback] - [description] + * @param {ArcadePhysicsCallback} [processCallback] - [description] + * @param {object} [callbackContext] - [description] * * @return {boolean} [description] */ @@ -1272,9 +1272,9 @@ var World = new Class({ * * @param {Phaser.GameObjects.GameObject} object1 - [description] * @param {Phaser.GameObjects.GameObject} object2 - [description] - * @param {function} collideCallback - [description] - * @param {function} processCallback - [description] - * @param {object} callbackContext - [description] + * @param {ArcadePhysicsCallback} [collideCallback] - [description] + * @param {ArcadePhysicsCallback} [processCallback] - [description] + * @param {object} [callbackContext] - [description] * * @return {boolean} [description] */ @@ -1295,8 +1295,8 @@ var World = new Class({ * * @param {Phaser.GameObjects.GameObject} object1 - [description] * @param {Phaser.GameObjects.GameObject} object2 - [description] - * @param {function} collideCallback - [description] - * @param {function} processCallback - [description] + * @param {ArcadePhysicsCallback} collideCallback - [description] + * @param {ArcadePhysicsCallback} processCallback - [description] * @param {object} callbackContext - [description] * @param {boolean} overlapOnly - [description] * @@ -1356,8 +1356,8 @@ var World = new Class({ * * @param {Phaser.GameObjects.GameObject} object1 - [description] * @param {Phaser.GameObjects.GameObject} object2 - [description] - * @param {function} collideCallback - [description] - * @param {function} processCallback - [description] + * @param {ArcadePhysicsCallback} collideCallback - [description] + * @param {ArcadePhysicsCallback} processCallback - [description] * @param {object} callbackContext - [description] * @param {boolean} overlapOnly - [description] * @@ -1434,8 +1434,8 @@ var World = new Class({ * * @param {Phaser.GameObjects.GameObject} sprite1 - [description] * @param {Phaser.GameObjects.GameObject} sprite2 - [description] - * @param {function} collideCallback - [description] - * @param {function} processCallback - [description] + * @param {ArcadePhysicsCallback} collideCallback - [description] + * @param {ArcadePhysicsCallback} processCallback - [description] * @param {object} callbackContext - [description] * @param {boolean} overlapOnly - [description] * @@ -1469,8 +1469,8 @@ var World = new Class({ * * @param {Phaser.GameObjects.GameObject} sprite - [description] * @param {Phaser.GameObjects.Group} group - [description] - * @param {function} collideCallback - [description] - * @param {function} processCallback - [description] + * @param {ArcadePhysicsCallback} collideCallback - [description] + * @param {ArcadePhysicsCallback} processCallback - [description] * @param {object} callbackContext - [description] * @param {boolean} overlapOnly - [description] * @@ -1532,8 +1532,8 @@ var World = new Class({ * * @param {Phaser.GameObjects.Group} group - [description] * @param {Phaser.Tilemaps.DynamicTilemapLayer|Phaser.Tilemaps.StaticTilemapLayer} tilemapLayer - [description] - * @param {function} collideCallback - [description] - * @param {function} processCallback - [description] + * @param {ArcadePhysicsCallback} collideCallback - [description] + * @param {ArcadePhysicsCallback} processCallback - [description] * @param {object} callbackContext - [description] * @param {boolean} overlapOnly - [description] * @@ -1572,8 +1572,8 @@ var World = new Class({ * * @param {Phaser.GameObjects.GameObject} sprite - [description] * @param {Phaser.Tilemaps.DynamicTilemapLayer|Phaser.Tilemaps.StaticTilemapLayer} tilemapLayer - [description] - * @param {function} collideCallback - [description] - * @param {function} processCallback - [description] + * @param {ArcadePhysicsCallback} collideCallback - [description] + * @param {ArcadePhysicsCallback} processCallback - [description] * @param {object} callbackContext - [description] * @param {boolean} overlapOnly - [description] * @@ -1671,8 +1671,8 @@ var World = new Class({ * * @param {Phaser.GameObjects.Group} group1 - [description] * @param {Phaser.GameObjects.Group} group2 - [description] - * @param {function} collideCallback - [description] - * @param {function} processCallback - [description] + * @param {ArcadePhysicsCallback} collideCallback - [description] + * @param {ArcadePhysicsCallback} processCallback - [description] * @param {object} callbackContext - [description] * @param {boolean} overlapOnly - [description] * diff --git a/src/physics/arcade/index.js b/src/physics/arcade/index.js index a2b1b16f0..b81f0b3a1 100644 --- a/src/physics/arcade/index.js +++ b/src/physics/arcade/index.js @@ -7,6 +7,13 @@ var CONST = require('./const'); var Extend = require('../../utils/object/Extend'); +/** + * @callback ArcadePhysicsCallback + * + * @param {Phaser.GameObjects.GameObject} object1 - [description] + * @param {Phaser.GameObjects.GameObject} object2 - [description] + */ + /** * @namespace Phaser.Physics.Arcade */ @@ -23,7 +30,7 @@ var Arcade = { StaticBody: require('./StaticBody'), StaticGroup: require('./StaticPhysicsGroup'), World: require('./World') - + }; // Merge in the consts diff --git a/src/physics/impact/Body.js b/src/physics/impact/Body.js index 07e8749a1..ea6be90e7 100644 --- a/src/physics/impact/Body.js +++ b/src/physics/impact/Body.js @@ -10,6 +10,12 @@ var GetVelocity = require('./GetVelocity'); var TYPE = require('./TYPE'); var UpdateMotion = require('./UpdateMotion'); +/** + * @callback BodyUpdateCallback + * + * @param {Phaser.Physics.Impact.Body} body - [description] + */ + /** * @classdesc * An Impact.js compatible physics body. @@ -289,7 +295,7 @@ var Body = new Class({ * [description] * * @name Phaser.Physics.Impact.Body#updateCallback - * @type {function} + * @type {?BodyUpdateCallback} * @since 3.0.0 */ this.updateCallback; From 41d7c4b7151ee67d39dc33777cdb4f9f53f1407c Mon Sep 17 00:00:00 2001 From: orblazer Date: Mon, 19 Mar 2018 22:12:11 +0100 Subject: [PATCH 3/7] Add callbacks on Input and Geom --- src/actions/SetHitArea.js | 4 +-- src/geom/triangle/CenterOn.js | 10 ++++++- src/input/InputPlugin.js | 14 +++++----- src/input/InteractiveObject.js | 41 ++++++++++++++++++++++++++++ src/input/keyboard/combo/KeyCombo.js | 8 +++++- src/input/touch/TouchManager.js | 10 +++++-- 6 files changed, 74 insertions(+), 13 deletions(-) diff --git a/src/actions/SetHitArea.js b/src/actions/SetHitArea.js index 9ed12100e..2e14d7346 100644 --- a/src/actions/SetHitArea.js +++ b/src/actions/SetHitArea.js @@ -9,10 +9,10 @@ * * @function Phaser.Actions.SetHitArea * @since 3.0.0 - * + * * @param {array} items - An array of Game Objects. The contents of this array are updated by this Action. * @param {any} hitArea - [description] - * @param {function} hitAreaCallback - [description] + * @param {HitAreaCallback} hitAreaCallback - [description] * * @return {array} The array of Game Objects that was passed to this Action. */ diff --git a/src/geom/triangle/CenterOn.js b/src/geom/triangle/CenterOn.js index dc936e85a..d6784c214 100644 --- a/src/geom/triangle/CenterOn.js +++ b/src/geom/triangle/CenterOn.js @@ -7,6 +7,14 @@ var Centroid = require('./Centroid'); var Offset = require('./Offset'); +/** + * @callback CenterFunction + * + * @param {Phaser.Geom.Triangle} triangle - [description] + * + * @return {Phaser.Math.Vector2} [description] + */ + /** * [description] * @@ -16,7 +24,7 @@ var Offset = require('./Offset'); * @param {Phaser.Geom.Triangle} triangle - [description] * @param {number} x - [description] * @param {number} y - [description] - * @param {function} [centerFunc] - [description] + * @param {CenterFunction} [centerFunc] - [description] * * @return {Phaser.Geom.Triangle} [description] */ diff --git a/src/input/InputPlugin.js b/src/input/InputPlugin.js index 67ae914c3..27dad065b 100644 --- a/src/input/InputPlugin.js +++ b/src/input/InputPlugin.js @@ -402,7 +402,7 @@ var InputPlugin = new Class({ * * @param {Phaser.GameObjects.GameObject} gameObject - [description] * @param {object} shape - [description] - * @param {function} callback - [description] + * @param {HitAreaCallback} callback - [description] * @param {boolean} [dropZone=false] - [description] * * @return {Phaser.Input.InputPlugin} This Input Plugin. @@ -1053,7 +1053,7 @@ var InputPlugin = new Class({ * * @param {Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[]} gameObjects - An array of Game Objects to set the hit area on. * @param {object} [shape] - The shape or object to check if the pointer is within for hit area checks. - * @param {function} [callback] - The 'contains' function to invoke to check if the pointer is within the hit area. + * @param {HitAreaCallback} [callback] - The 'contains' function to invoke to check if the pointer is within the hit area. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ @@ -1091,7 +1091,7 @@ var InputPlugin = new Class({ * @param {number} x - The center of the circle. * @param {number} y - The center of the circle. * @param {number} radius - The radius of the circle. - * @param {function} [callback] - The hit area callback. If undefined it uses Circle.Contains. + * @param {HitAreaCallback} [callback] - The hit area callback. If undefined it uses Circle.Contains. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ @@ -1115,7 +1115,7 @@ var InputPlugin = new Class({ * @param {number} y - The center of the ellipse. * @param {number} width - The width of the ellipse. * @param {number} height - The height of the ellipse. - * @param {function} [callback] - The hit area callback. If undefined it uses Ellipse.Contains. + * @param {HitAreaCallback} [callback] - The hit area callback. If undefined it uses Ellipse.Contains. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ @@ -1135,7 +1135,7 @@ var InputPlugin = new Class({ * @since 3.0.0 * * @param {Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[]} gameObjects - An array of Game Objects to set as having an ellipse hit area. - * @param {function} [callback] - The hit area callback. If undefined it uses Rectangle.Contains. + * @param {HitAreaCallback} [callback] - The hit area callback. If undefined it uses Rectangle.Contains. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ @@ -1189,7 +1189,7 @@ var InputPlugin = new Class({ * @param {number} y - The top-left of the rectangle. * @param {number} width - The width of the rectangle. * @param {number} height - The height of the rectangle. - * @param {function} [callback] - The hit area callback. If undefined it uses Rectangle.Contains. + * @param {HitAreaCallback} [callback] - The hit area callback. If undefined it uses Rectangle.Contains. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ @@ -1215,7 +1215,7 @@ var InputPlugin = new Class({ * @param {number} y2 - The y coordinate of the second point of the triangle. * @param {number} x3 - The x coordinate of the third point of the triangle. * @param {number} y3 - The y coordinate of the third point of the triangle. - * @param {function} [callback] - The hit area callback. If undefined it uses Triangle.Contains. + * @param {HitAreaCallback} [callback] - The hit area callback. If undefined it uses Triangle.Contains. * * @return {Phaser.Input.InputPlugin} This InputPlugin object. */ diff --git a/src/input/InteractiveObject.js b/src/input/InteractiveObject.js index d325dbc45..1025e7d61 100644 --- a/src/input/InteractiveObject.js +++ b/src/input/InteractiveObject.js @@ -6,6 +6,47 @@ // Phaser.Input.InteractiveObject +/** + * @callback HitAreaCallback + * + * @param {any} hitArea - [description] + * @param {number} x - [description] + * @param {number} y - [description] + * @param {Phaser.GameObjects.GameObject} gameObject - [description] + */ + +/** + * @typedef {object} InteractiveObject + * + * @property {Phaser.GameObjects.GameObject} gameObject - [description] + * @property {boolean} enabled - [description] + * @property {boolean} draggable - [description] + * @property {boolean} dropZone - [description] + * @property {[type]} target - [description] + * @property {Phaser.Cameras.Scene2D.Camera} camera - [description] + * @property {any} hitArea - [description] + * @property {HitAreaCallback} hitAreaCallback - [description] + * @property {number} localX - [description] + * @property {number} localY - [description] + * @property {(0|1|2)} dragState - [description] + * @property {number} dragStartX - [description] + * @property {number} dragStartY - [description] + * @property {number} dragX - [description] + * @property {number} dragY - [description] + */ + +/** + * [description] + * + * @method Phaser.Input.Pointer#positionToCamera + * @since 3.0.0 + * + * @param {Phaser.GameObjects.GameObject} gameObject - [description] + * @param {any} hitArea - [description] + * @param {HitAreaCallback} hitAreaCallback - [description] + * + * @return {InteractiveObject} [description] + */ var InteractiveObject = function (gameObject, hitArea, hitAreaCallback) { return { diff --git a/src/input/keyboard/combo/KeyCombo.js b/src/input/keyboard/combo/KeyCombo.js index d4df6d59f..4b41c44b1 100644 --- a/src/input/keyboard/combo/KeyCombo.js +++ b/src/input/keyboard/combo/KeyCombo.js @@ -9,6 +9,12 @@ var GetFastValue = require('../../../utils/object/GetFastValue'); var ProcessKeyCombo = require('./ProcessKeyCombo'); var ResetKeyCombo = require('./ResetKeyCombo'); +/** + * @callback KeyboardKeydownCallback + * + * @param {KeyboardEvent} event - [description] + */ + /** * @classdesc * [description] @@ -219,7 +225,7 @@ var KeyCombo = new Class({ * [description] * * @name Phaser.Input.Keyboard.KeyCombo#onKeyDown - * @type {function} + * @type {KeyboardKeydownCallback} * @since 3.0.0 */ this.onKeyDown = onKeyDownHandler; diff --git a/src/input/touch/TouchManager.js b/src/input/touch/TouchManager.js index b62a52c80..17e37023f 100644 --- a/src/input/touch/TouchManager.js +++ b/src/input/touch/TouchManager.js @@ -10,6 +10,12 @@ var Class = require('../../utils/Class'); // https://patrickhlauke.github.io/touch/tests/results/ // https://www.html5rocks.com/en/mobile/touch/ +/** + * @callback TouchHandler + * + * @param {TouchEvent} event - [description] + */ + /** * @classdesc * [description] @@ -69,7 +75,7 @@ var TouchManager = new Class({ * [description] * * @name Phaser.Input.Touch.TouchManager#handler - * @type {function} + * @type {TouchHandler} * @since 3.0.0 */ this.handler; @@ -154,7 +160,7 @@ var TouchManager = new Class({ target.addEventListener('touchmove', handler, passive); target.addEventListener('touchend', handler, passive); } - + this.handler = handler; }, From b4a30b8e437c5a8ba5dfa16df7ed7ce6a23e6902 Mon Sep 17 00:00:00 2001 From: orblazer Date: Mon, 19 Mar 2018 22:27:16 +0100 Subject: [PATCH 4/7] Add callbacks on GameObjects --- src/gameobjects/GameObject.js | 2 +- .../bitmaptext/dynamic/DynamicBitmapText.js | 33 +++++++++---------- src/gameobjects/blitter/Blitter.js | 11 +++++-- src/gameobjects/lights/LightsManager.js | 14 +++++--- src/gameobjects/particles/EmitterOp.js | 27 +++++++++++++-- src/gameobjects/particles/ParticleEmitter.js | 29 +++++++++++----- src/gameobjects/text/TextStyle.js | 13 +++++++- src/gameobjects/text/static/Text.js | 2 +- src/gameobjects/zone/Zone.js | 6 ++-- src/input/InteractiveObject.js | 2 ++ 10 files changed, 100 insertions(+), 39 deletions(-) diff --git a/src/gameobjects/GameObject.js b/src/gameobjects/GameObject.js index 8dc083343..3e0fcbe56 100644 --- a/src/gameobjects/GameObject.js +++ b/src/gameobjects/GameObject.js @@ -254,7 +254,7 @@ var GameObject = new Class({ * @since 3.0.0 * * @param {any} [shape] - A geometric shape that defines the hit area for the Game Object. If not specified a Rectangle will be used. - * @param {function} [callback] - A callback to be invoked when the Game Object is interacted with. + * @param {HitAreaCallback} [callback] - A callback to be invoked when the Game Object is interacted with. * @param {boolean} [dropZone=false] - Should this Game Object be treated as a drop zone target? * * @return {Phaser.GameObjects.GameObject} This GameObject. diff --git a/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js b/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js index d350a164a..1d4da25eb 100644 --- a/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js +++ b/src/gameobjects/bitmaptext/dynamic/DynamicBitmapText.js @@ -10,6 +10,20 @@ var GameObject = require('../../GameObject'); var GetBitmapTextSize = require('../GetBitmapTextSize'); var Render = require('./DynamicBitmapTextRender'); +/** + * @callback DisplayCallback + * + * @param {object} display - [description] + * @param {{topLeft:number,topRight:number,bottomLeft:number,bottomRight:number}} display.tint - [description] + * @param {number} display.index - [description] + * @param {number} display.charCode - [description] + * @param {number} display.x - [description] + * @param {number} display.y - [description] + * @param {number} display.scale - [description] + * @param {number} display.rotation - [description] + * @param {[type]} display.data - [description] + */ + /** * @classdesc * [description] @@ -161,7 +175,7 @@ var DynamicBitmapText = new Class({ * [description] * * @name Phaser.GameObjects.DynamicBitmapText#displayCallback; - * @type {function} + * @type {DisplayCallback} * @since 3.0.0 */ this.displayCallback; @@ -192,7 +206,7 @@ var DynamicBitmapText = new Class({ * @method Phaser.GameObjects.DynamicBitmapText#setDisplayCallback * @since 3.0.0 * - * @param {function} callback - [description] + * @param {DisplayCallback} callback - [description] * * @return {Phaser.GameObjects.DynamicBitmapText} This Game Object. */ @@ -286,21 +300,6 @@ var DynamicBitmapText = new Class({ return this; }, - // { - // local: { - // x, - // y, - // width, - // height - // }, - // global: { - // x, - // y, - // width, - // height - // } - // } - /** * [description] * diff --git a/src/gameobjects/blitter/Blitter.js b/src/gameobjects/blitter/Blitter.js index 4e939f1c1..7cb68b44a 100644 --- a/src/gameobjects/blitter/Blitter.js +++ b/src/gameobjects/blitter/Blitter.js @@ -12,6 +12,13 @@ var Frame = require('../../textures/Frame'); var GameObject = require('../GameObject'); var List = require('../../structs/List'); +/** + * @callback BlitterFromCallback + * + * @param {Phaser.GameObjects.Blitter} blitter - [description] + * @param {integer} index - [description] + */ + /** * @classdesc * A Blitter Game Object. @@ -44,7 +51,7 @@ var List = require('../../structs/List'); * @extends Phaser.GameObjects.Components.Texture * @extends Phaser.GameObjects.Components.Transform * @extends Phaser.GameObjects.Components.Visible - * + * * @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. It can only belong to one Scene at any given time. * @param {number} [x=0] - The x coordinate of this Game Object in world space. * @param {number} [y=0] - The y coordinate of this Game Object in world space. @@ -144,7 +151,7 @@ var Blitter = new Class({ * @method Phaser.GameObjects.Blitter#createFromCallback * @since 3.0.0 * - * @param {function} callback - The callback to invoke after creating a bob. It will be sent two arguments: The Bob and the index of the Bob. + * @param {BlitterFromCallback} callback - The callback to invoke after creating a bob. It will be sent two arguments: The Bob and the index of the Bob. * @param {integer} quantity - The quantity of Bob objects to create. * @param {string} [frame] - The Frame the Bobs will use. It must be part of the Blitter Texture. * @param {boolean} [visible=true] - [description] diff --git a/src/gameobjects/lights/LightsManager.js b/src/gameobjects/lights/LightsManager.js index 2581958f3..43eed3949 100644 --- a/src/gameobjects/lights/LightsManager.js +++ b/src/gameobjects/lights/LightsManager.js @@ -9,6 +9,12 @@ var Light = require('./Light'); var LightPipeline = require('../../renderer/webgl/pipelines/ForwardDiffuseLightPipeline'); var Utils = require('../../renderer/webgl/Utils'); +/** + * @callback LightForEach + * + * @param {Phaser.GameObjects.Light} light - [description] + */ + /** * @classdesc * [description] @@ -28,7 +34,7 @@ var LightsManager = new Class({ * [description] * * @name Phaser.GameObjects.LightsManager#lightPool - * @type {array} + * @type {Phaser.GameObjects.Light[]} * @default [] * @since 3.0.0 */ @@ -38,7 +44,7 @@ var LightsManager = new Class({ * [description] * * @name Phaser.GameObjects.LightsManager#lights - * @type {array} + * @type {Phaser.GameObjects.Light[]} * @default [] * @since 3.0.0 */ @@ -48,7 +54,7 @@ var LightsManager = new Class({ * [description] * * @name Phaser.GameObjects.LightsManager#culledLights - * @type {array} + * @type {Phaser.GameObjects.Light[]} * @default [] * @since 3.0.0 */ @@ -155,7 +161,7 @@ var LightsManager = new Class({ * @method Phaser.GameObjects.LightsManager#forEachLight * @since 3.0.0 * - * @param {function} callback - [description] + * @param {LightForEach} callback - [description] * * @return {Phaser.GameObjects.LightsManager} This Lights Manager object. */ diff --git a/src/gameobjects/particles/EmitterOp.js b/src/gameobjects/particles/EmitterOp.js index 5f9f94123..4a8f9d270 100644 --- a/src/gameobjects/particles/EmitterOp.js +++ b/src/gameobjects/particles/EmitterOp.js @@ -10,6 +10,29 @@ var GetEaseFunction = require('../../tweens/builders/GetEaseFunction'); var GetFastValue = require('../../utils/object/GetFastValue'); var Wrap = require('../../math/Wrap'); +/** + * The returned value sets what the property will be at the START of the particles life, on emit. + * @callback EmitterOpOnEmitCallback + * + * @param {Phaser.GameObjects.Particles.Particle} particle - [description] + * @param {string} key - [description] + * @param {number} value - [description] + * + * @return {number} [description] + */ + +/** + * The returned value updates the property for the duration of the particles life. + * @callback EmitterOpOnUpdateCallback + * + * @param {Phaser.GameObjects.Particles.Particle} particle - [description] + * @param {string} key - [description] + * @param {float} t - The T value (between 0 and 1) + * @param {number} value - [description] + * + * @return {number} [description] + */ + /** * @classdesc * [description] @@ -121,7 +144,7 @@ var EmitterOp = new Class({ * [description] * * @name Phaser.GameObjects.Particles.EmitterOp#onEmit - * @type {function} + * @type {EmitterOpOnEmitCallback} * @since 3.0.0 */ this.onEmit = this.defaultEmit; @@ -130,7 +153,7 @@ var EmitterOp = new Class({ * [description] * * @name Phaser.GameObjects.Particles.EmitterOp#onUpdate - * @type {function} + * @type {EmitterOpOnUpdateCallback} * @since 3.0.0 */ this.onUpdate = this.defaultUpdate; diff --git a/src/gameobjects/particles/ParticleEmitter.js b/src/gameobjects/particles/ParticleEmitter.js index 81c432ad9..215981c7d 100644 --- a/src/gameobjects/particles/ParticleEmitter.js +++ b/src/gameobjects/particles/ParticleEmitter.js @@ -21,6 +21,19 @@ var StableSort = require('../../utils/array/StableSort'); var Vector2 = require('../../math/Vector2'); var Wrap = require('../../math/Wrap'); +/** + * @callback ParticleEmitterCallback + * + * @param {Phaser.GameObjects.Particles.Particle} particle - [description] + * @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - [description] + */ + +/** + * @callback ParticleDeathCallback + * + * @param {Phaser.GameObjects.Particles.Particle} particle - [description] + */ + /** * @classdesc * [description] @@ -400,7 +413,7 @@ var ParticleEmitter = new Class({ * [description] * * @name Phaser.GameObjects.Particles.ParticleEmitter#emitCallback - * @type {?function} + * @type {?ParticleEmitterCallback} * @default null * @since 3.0.0 */ @@ -410,7 +423,7 @@ var ParticleEmitter = new Class({ * [description] * * @name Phaser.GameObjects.Particles.ParticleEmitter#emitCallbackScope - * @type {?object} + * @type {?any} * @default null * @since 3.0.0 */ @@ -420,7 +433,7 @@ var ParticleEmitter = new Class({ * [description] * * @name Phaser.GameObjects.Particles.ParticleEmitter#deathCallback - * @type {?function} + * @type {?ParticleDeathCallback} * @default null * @since 3.0.0 */ @@ -430,7 +443,7 @@ var ParticleEmitter = new Class({ * [description] * * @name Phaser.GameObjects.Particles.ParticleEmitter#deathCallbackScope - * @type {?object} + * @type {?any} * @default null * @since 3.0.0 */ @@ -1534,7 +1547,7 @@ var ParticleEmitter = new Class({ * @method Phaser.GameObjects.Particles.ParticleEmitter#onParticleEmit * @since 3.0.0 * - * @param {function} callback - [description] + * @param {ParticleEmitterCallback} callback - [description] * @param {any} [context] - [description] * * @return {Phaser.GameObjects.Particles.ParticleEmitter} This Particle Emitter. @@ -1566,7 +1579,7 @@ var ParticleEmitter = new Class({ * @method Phaser.GameObjects.Particles.ParticleEmitter#onParticleDeath * @since 3.0.0 * - * @param {function} callback - [description] + * @param {ParticleDeathCallback} callback - [description] * @param {any} [context] - [description] * * @return {Phaser.GameObjects.Particles.ParticleEmitter} This Particle Emitter. @@ -1619,7 +1632,7 @@ var ParticleEmitter = new Class({ * @method Phaser.GameObjects.Particles.ParticleEmitter#forEachAlive * @since 3.0.0 * - * @param {function} callback - [description] + * @param {ParticleEmitterCallback} callback - [description] * @param {any} thisArg - [description] * * @return {Phaser.GameObjects.Particles.ParticleEmitter} This Particle Emitter. @@ -1644,7 +1657,7 @@ var ParticleEmitter = new Class({ * @method Phaser.GameObjects.Particles.ParticleEmitter#forEachDead * @since 3.0.0 * - * @param {function} callback - [description] + * @param {ParticleEmitterCallback} callback - [description] * @param {any} thisArg - [description] * * @return {Phaser.GameObjects.Particles.ParticleEmitter} This Particle Emitter. diff --git a/src/gameobjects/text/TextStyle.js b/src/gameobjects/text/TextStyle.js index c7d0d1d3e..9bfeaf59c 100644 --- a/src/gameobjects/text/TextStyle.js +++ b/src/gameobjects/text/TextStyle.js @@ -11,6 +11,17 @@ var MeasureText = require('./MeasureText'); // Key: [ Object Key, Default Value ] +/** + * A custom function that will be responsible for wrapping the text. + * @callback TextStyleWordWrapCallback + * + * @param {string} text - The string to wrap. + * @param {Phaser.GameObjects.Text} textObject - The Text instance. + * + * @return {(string|string[])} Should return the wrapped lines either as an array of lines or as a string with + * newline characters in place to indicate where breaks should happen. + */ + var propertyMap = { fontFamily: [ 'fontFamily', 'Courier' ], fontSize: [ 'fontSize', '16px' ], @@ -820,7 +831,7 @@ var TextStyle = new Class({ * @method Phaser.GameObjects.Components.TextStyle#setWordWrapCallback * @since 3.0.0 * - * @param {function} callback - A custom function that will be responsible for wrapping the + * @param {TextStyleWordWrapCallback} callback - A custom function that will be responsible for wrapping the * text. It will receive two arguments: text (the string to wrap), textObject (this Text * instance). It should return the wrapped lines either as an array of lines or as a string with * newline characters in place to indicate where breaks should happen. diff --git a/src/gameobjects/text/static/Text.js b/src/gameobjects/text/static/Text.js index 645422c50..e2036fc29 100644 --- a/src/gameobjects/text/static/Text.js +++ b/src/gameobjects/text/static/Text.js @@ -795,7 +795,7 @@ var Text = new Class({ * @method Phaser.GameObjects.Text#setWordWrapCallback * @since 3.0.0 * - * @param {function} callback - A custom function that will be responsible for wrapping the + * @param {TextStyleWordWrapCallback} callback - A custom function that will be responsible for wrapping the * text. It will receive two arguments: text (the string to wrap), textObject (this Text * instance). It should return the wrapped lines either as an array of lines or as a string with * newline characters in place to indicate where breaks should happen. diff --git a/src/gameobjects/zone/Zone.js b/src/gameobjects/zone/Zone.js index b01259729..d6b860e70 100644 --- a/src/gameobjects/zone/Zone.js +++ b/src/gameobjects/zone/Zone.js @@ -105,7 +105,7 @@ var Zone = new Class({ /** * The displayed width of this Game Object. * This value takes into account the scale factor. - * + * * @name Phaser.GameObjects.Zone#displayWidth * @type {number} * @since 3.0.0 @@ -127,7 +127,7 @@ var Zone = new Class({ /** * The displayed height of this Game Object. * This value takes into account the scale factor. - * + * * @name Phaser.GameObjects.Zone#displayHeight * @type {number} * @since 3.0.0 @@ -237,7 +237,7 @@ var Zone = new Class({ * @since 3.0.0 * * @param {object} shape - A Geometry shape instance, such as Phaser.Geom.Ellipse, or your own custom shape. - * @param {function} callback - A function that will return `true` if the given x/y coords it is sent are within the shape. + * @param {HitAreaCallback} callback - A function that will return `true` if the given x/y coords it is sent are within the shape. * * @return {Phaser.GameObjects.Zone} This Game Object. */ diff --git a/src/input/InteractiveObject.js b/src/input/InteractiveObject.js index 1025e7d61..23be57168 100644 --- a/src/input/InteractiveObject.js +++ b/src/input/InteractiveObject.js @@ -13,6 +13,8 @@ * @param {number} x - [description] * @param {number} y - [description] * @param {Phaser.GameObjects.GameObject} gameObject - [description] + * + * @return {boolean} [description] */ /** From 33e49a441643de4389532e1d0ebea474288b27bd Mon Sep 17 00:00:00 2001 From: orblazer Date: Mon, 19 Mar 2018 22:37:47 +0100 Subject: [PATCH 5/7] Add callbacks on Boot, Actions and Create --- src/actions/Call.js | 10 ++++++++-- src/boot/Config.js | 10 ++++++++-- src/boot/Game.js | 6 +++++- src/boot/TimeStep.js | 18 +++++++++++++----- src/create/GenerateTexture.js | 11 +++++++++-- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/actions/Call.js b/src/actions/Call.js index fd1a8956e..cef7cc788 100644 --- a/src/actions/Call.js +++ b/src/actions/Call.js @@ -4,14 +4,20 @@ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ +/** + * @callback CallCallback + * + * @param {Phaser.GameObjects.GameObject} item - [description] + */ + /** * Takes an array of objects and passes each of them to the given callback. * * @function Phaser.Actions.Call * @since 3.0.0 - * + * * @param {array|Phaser.GameObjects.GameObject[]} items - The array of items to be updated by this action. - * @param {function} callback - The callback to be invoked. It will be passed just one argument: the item from the array. + * @param {CallCallback} callback - The callback to be invoked. It will be passed just one argument: the item from the array. * @param {object} context - The scope in which the callback will be invoked. * * @return {array} The array of objects that was passed to this Action. diff --git a/src/boot/Config.js b/src/boot/Config.js index 0ef5afdd4..60fd6e7f6 100644 --- a/src/boot/Config.js +++ b/src/boot/Config.js @@ -18,6 +18,12 @@ var ValueToColor = require('../display/color/ValueToColor'); * @callback NOOP */ +/** + * @callback BootCallback + * + * @param {Phaser.Game} game - [description] + */ + /** * @typedef {object} FPSConfig * @@ -86,8 +92,8 @@ var ValueToColor = require('../display/color/ValueToColor'); * @property {boolean} [powerPreference='default'] - "high-performance", "low-power" or "default" * @property {string|number} [backgroundColor=0x000000] - [description] * @property {object} [?callbacks] - [description] - * @property {function} [callbacks.preBoot=NOOP] - [description] - * @property {function} [callbacks.postBoot=NOOP] - [description] + * @property {BootCallback} [callbacks.preBoot=NOOP] - [description] + * @property {BootCallback} [callbacks.postBoot=NOOP] - [description] * @property {LoaderConfig} [?loader] - [description] * @property {object} [?images] - [description] * @property {string} [images.default] - [description] diff --git a/src/boot/Game.js b/src/boot/Game.js index 55a54d2c1..3305000ce 100644 --- a/src/boot/Game.js +++ b/src/boot/Game.js @@ -25,6 +25,10 @@ var TextureManager = require('../textures/TextureManager'); var TimeStep = require('./TimeStep'); var VisibilityHandler = require('./VisibilityHandler'); +/** + * @callback GameStepCallback + */ + /** * @classdesc * The Phaser.Game instance is the main controller for the entire Phaser game. It is responsible @@ -232,7 +236,7 @@ var Game = new Class({ * It is set automatically when the Game boot process has completed. * * @name Phaser.Game#onStepCallback - * @type {function} + * @type {GameStepCallback} * @private * @since 3.0.0 */ diff --git a/src/boot/TimeStep.js b/src/boot/TimeStep.js index 71b42369d..26b90157e 100644 --- a/src/boot/TimeStep.js +++ b/src/boot/TimeStep.js @@ -20,6 +20,14 @@ var RequestAnimationFrame = require('../dom/RequestAnimationFrame'); // http://www.testufo.com/#test=animation-time-graph +/** + * @callback TimeStepCallback + * + * @param {number} time - The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout. + * @param {number} average - The Delta Average. + * @param {number} interpolation - Interpolation - how far between what is expected and where we are? + */ + /** * @classdesc * [description] @@ -78,7 +86,7 @@ var TimeStep = new Class({ * @since 3.0.0 */ this.running = false; - + /** * The minimum fps rate you want the Time Step to run at. * @@ -90,7 +98,7 @@ var TimeStep = new Class({ /** * The target fps rate for the Time Step to run at. - * + * * Setting this value will not actually change the speed at which the browser runs, that is beyond * the control of Phaser. Instead, it allows you to determine performance issues and if the Time Step * is spiraling out of control. @@ -154,7 +162,7 @@ var TimeStep = new Class({ /** * A callback to be invoked each time the Time Step steps. * - * @property {function} callback + * @property {TimeStepCallback} callback * @default NOOP * @since 3.0.0 */ @@ -379,7 +387,7 @@ var TimeStep = new Class({ * @method Phaser.Boot.TimeStep#start * @since 3.0.0 * - * @param {function} callback - The callback to be invoked each time the Time Step steps. + * @param {TimeStepCallback} callback - The callback to be invoked each time the Time Step steps. */ start: function (callback) { @@ -544,7 +552,7 @@ var TimeStep = new Class({ if (this.running) { this.raf.stop(); - + this.running = false; } }, diff --git a/src/create/GenerateTexture.js b/src/create/GenerateTexture.js index 40a8afe51..6fcf940fc 100644 --- a/src/create/GenerateTexture.js +++ b/src/create/GenerateTexture.js @@ -8,6 +8,13 @@ var Arne16 = require('./palettes/Arne16'); var CanvasPool = require('../display/canvas/CanvasPool'); var GetValue = require('../utils/object/GetValue'); +/** + * @callback GenerateTextureRendererCallback + * + * @param {HTMLCanvasElement} canvas - [description] + * @param {CanvasRenderingContext2D} context - [description] + */ + /** * @typedef {object} GenerateTextureConfig * @@ -18,8 +25,8 @@ var GetValue = require('../utils/object/GetValue'); * @property {number} [pixelHeight=1] - [description] * @property {boolean} [resizeCanvas=true] - [description] * @property {boolean} [clearCanvas=true] - [description] - * @property {function} [preRender] - [description] - * @property {function} [postRender] - [description] + * @property {GenerateTextureRendererCallback} [preRender] - [description] + * @property {GenerateTextureRendererCallback} [postRender] - [description] */ /** From 1e8311e1ab102b627993f27a2cc958d0ae2af81e Mon Sep 17 00:00:00 2001 From: orblazer Date: Mon, 19 Mar 2018 22:43:48 +0100 Subject: [PATCH 6/7] Add callbacks on Dom and Data --- src/data/DataManager.js | 11 ++++++++++- src/dom/DOMContentLoaded.js | 6 +++++- src/dom/RequestAnimationFrame.js | 6 +++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/data/DataManager.js b/src/data/DataManager.js index 3187c7dc5..a8b68de39 100644 --- a/src/data/DataManager.js +++ b/src/data/DataManager.js @@ -6,6 +6,15 @@ var Class = require('../utils/Class'); +/** + * @callback DataEachCallback + * + * @param {any} parent - [description] + * @param {string} key - [description] + * @param {any} value - [description] + * @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the game object, key, and data. + */ + /** * @classdesc * The Data Component features a means to store pieces of data specific to a Game Object, System or Plugin. @@ -199,7 +208,7 @@ var DataManager = new Class({ * @method Phaser.Data.DataManager#each * @since 3.0.0 * - * @param {function} callback - The function to call. + * @param {DataEachCallback} callback - The function to call. * @param {object} [scope] - Value to use as `this` when executing callback. * @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the game object, key, and data. * diff --git a/src/dom/DOMContentLoaded.js b/src/dom/DOMContentLoaded.js index 12a3d1a0b..9cf51deb0 100644 --- a/src/dom/DOMContentLoaded.js +++ b/src/dom/DOMContentLoaded.js @@ -6,6 +6,10 @@ var OS = require('../device/OS'); +/** + * @callback ContentLoadedCallback + */ + /** * Inspects the readyState of the document. If the document is already complete then it invokes the given callback. * If not complete it sets up several event listeners such as `deviceready`, and once those fire, it invokes the callback. @@ -14,7 +18,7 @@ var OS = require('../device/OS'); * @function Phaser.DOM.DOMContentLoaded * @since 3.0.0 * - * @param {function} callback - The callback to be invoked when the device is ready and the DOM content is loaded. + * @param {ContentLoadedCallback} callback - The callback to be invoked when the device is ready and the DOM content is loaded. */ var DOMContentLoaded = function (callback) { diff --git a/src/dom/RequestAnimationFrame.js b/src/dom/RequestAnimationFrame.js index 7309102d1..ae480881f 100644 --- a/src/dom/RequestAnimationFrame.js +++ b/src/dom/RequestAnimationFrame.js @@ -37,7 +37,7 @@ var RequestAnimationFrame = new Class({ * The callback to be invoked each step. * * @name Phaser.DOM.RequestAnimationFrame#callback - * @type {function} + * @type {FrameRequestCallback} * @since 3.0.0 */ this.callback = NOOP; @@ -89,7 +89,7 @@ var RequestAnimationFrame = new Class({ * Updates the local tick value, invokes the callback and schedules another call to requestAnimationFrame. * * @name Phaser.DOM.RequestAnimationFrame#step - * @type {function} + * @type {FrameRequestCallback} * @since 3.0.0 */ this.step = function step (timestamp) @@ -134,7 +134,7 @@ var RequestAnimationFrame = new Class({ * @method Phaser.DOM.RequestAnimationFrame#start * @since 3.0.0 * - * @param {function} callback - The callback to invoke each step. + * @param {FrameRequestCallback} callback - The callback to invoke each step. * @param {boolean} forceSetTimeOut - Should it use SetTimeout, even if RAF is available? */ start: function (callback, forceSetTimeOut) From fa13b597e3d43a330afa0c485dc8b085b89d51fd Mon Sep 17 00:00:00 2001 From: orblazer Date: Mon, 19 Mar 2018 22:57:46 +0100 Subject: [PATCH 7/7] Add more callbacks --- src/loader/File.js | 12 +++++++++--- src/loader/filetypes/AudioFile.js | 2 +- src/physics/impact/components/Collides.js | 10 +++++++++- src/sound/BaseSoundManager.js | 15 ++++++++++++--- src/structs/List.js | 9 ++++++++- src/structs/Map.js | 13 +++++++++++-- src/structs/Set.js | 13 +++++++++++-- src/textures/TextureManager.js | 19 +++++++++++++------ 8 files changed, 74 insertions(+), 19 deletions(-) diff --git a/src/loader/File.js b/src/loader/File.js index 8751ebcf2..a9a3bd9be 100644 --- a/src/loader/File.js +++ b/src/loader/File.js @@ -12,6 +12,12 @@ var MergeXHRSettings = require('./MergeXHRSettings'); var XHRLoader = require('./XHRLoader'); var XHRSettings = require('./XHRSettings'); +/** + * @callback FileProcessCallback + * + * @param {Phaser.Loader.File} file - [description] + */ + /** * @classdesc * [description] @@ -31,7 +37,7 @@ var File = new Class({ { /** * The file type string (image, json, etc) for sorting within the Loader. - * + * * @name Phaser.Loader.File#type * @type {string} * @since 3.0.0 @@ -219,7 +225,7 @@ var File = new Class({ * * @method Phaser.Loader.File#setLinkFile * @since 3.0.0 - * + * * @param {Phaser.Loader.File} fileB - The linked file. * @param {string} linkType - The type of association. */ @@ -350,7 +356,7 @@ var File = new Class({ * @method Phaser.Loader.File#onProcess * @since 3.0.0 * - * @param {function} callback - The callback to invoke to process this File. + * @param {FileProcessCallback} callback - The callback to invoke to process this File. */ onProcess: function (callback) { diff --git a/src/loader/filetypes/AudioFile.js b/src/loader/filetypes/AudioFile.js index 51ed9b832..7f60955f4 100644 --- a/src/loader/filetypes/AudioFile.js +++ b/src/loader/filetypes/AudioFile.js @@ -62,7 +62,7 @@ var AudioFile = new Class({ * @method Phaser.Loader.FileTypes.AudioFile#onProcess * @since 3.0.0 * - * @param {function} callback - [description] + * @param {FileProcessCallback} callback - [description] */ onProcess: function (callback) { diff --git a/src/physics/impact/components/Collides.js b/src/physics/impact/components/Collides.js index 0d5822cd4..85963fde4 100644 --- a/src/physics/impact/components/Collides.js +++ b/src/physics/impact/components/Collides.js @@ -6,6 +6,14 @@ var COLLIDES = require('../COLLIDES'); +/** + * @callback CollideCallback + * + * @param {Phaser.Physics.Impact.Body} body - [description] + * @param {Phaser.Physics.Impact.Body} other - [description] + * @param {string} axis - [description] + */ + /** * [description] * @@ -23,7 +31,7 @@ var Collides = { * @method Phaser.Physics.Impact.Components.Collides#setCollideCallback * @since 3.0.0 * - * @param {function} callback - [description] + * @param {CollideCallback} callback - [description] * @param {object} scope - [description] * * @return {Phaser.GameObjects.GameObject} This Game Object. diff --git a/src/sound/BaseSoundManager.js b/src/sound/BaseSoundManager.js index 6596668ad..2b50b3de4 100644 --- a/src/sound/BaseSoundManager.js +++ b/src/sound/BaseSoundManager.js @@ -7,6 +7,15 @@ var Class = require('../utils/Class'); var EventEmitter = require('eventemitter3'); var NOOP = require('../utils/NOOP'); +/** + * @callback EachActiveSoundCallback + * + * @param {Phaser.Sound.BaseSoundManager} manager - [description] + * @param {Phaser.Sound.BaseSound} sound - [description] + * @param {number} index - [description] + * @param {Phaser.Sound.BaseSound[]} sounds - [description] + */ + /** * @classdesc * The sound manager is responsible for playing back audio via Web Audio API or HTML Audio tag as fallback. @@ -466,17 +475,17 @@ var BaseSoundManager = new Class({ * @private * @since 3.0.0 * - * @param {function} callbackfn - Callback function. (sound: ISound, index: number, array: ISound[]) => void + * @param {EachActiveSoundCallback} callback - Callback function. (sound: ISound, index: number, array: ISound[]) => void * @param {object} [scope] - Callback context. */ - forEachActiveSound: function (callbackfn, scope) + forEachActiveSound: function (callback, scope) { var _this = this; this.sounds.forEach(function (sound, index) { if (!sound.pendingRemove) { - callbackfn.call(scope || _this, sound, index, _this.sounds); + callback.call(scope || _this, sound, index, _this.sounds); } }); }, diff --git a/src/structs/List.js b/src/structs/List.js index ef8e445f8..826dbefee 100644 --- a/src/structs/List.js +++ b/src/structs/List.js @@ -6,6 +6,13 @@ var Class = require('../utils/Class'); +/** + * @callback EachListCallback + * + * @param {any} item - [description] + * @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the child. + */ + /** * @classdesc * [description] @@ -737,7 +744,7 @@ var List = new Class({ * @method Phaser.Structs.List#each * @since 3.0.0 * - * @param {function} callback - The function to call. + * @param {EachListCallback} callback - The function to call. * @param {object} [thisArg] - Value to use as `this` when executing callback. * @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the child. */ diff --git a/src/structs/Map.js b/src/structs/Map.js index b531ce8fd..21168a853 100644 --- a/src/structs/Map.js +++ b/src/structs/Map.js @@ -6,6 +6,15 @@ var Class = require('../utils/Class'); +/** + * @callback EachMapCallback + * + * @param {string} key - [description] + * @param {any} entry - [description] + * + * @return {?boolean} [description] + */ + /** * @classdesc * The keys of a Map can be arbitrary values. @@ -32,7 +41,7 @@ var Map = new Class({ * [description] * * @name Phaser.Structs.Map#entries - * @type {object} + * @type {Object.} * @default {} * @since 3.0.0 */ @@ -237,7 +246,7 @@ var Map = new Class({ * @method Phaser.Structs.Map#each * @since 3.0.0 * - * @param {function} callback - [description] + * @param {EachMapCallback} callback - [description] * * @return {Phaser.Structs.Map} This Map object. */ diff --git a/src/structs/Set.js b/src/structs/Set.js index 1f98668b3..687fd7a74 100644 --- a/src/structs/Set.js +++ b/src/structs/Set.js @@ -6,6 +6,15 @@ var Class = require('../utils/Class'); +/** + * @callback EachSetCallback + * + * @param {any} entry - [description] + * @param {number} index - [description] + * + * @return {?boolean} [description] + */ + /** * @classdesc * A Set is a collection of unique elements. @@ -148,7 +157,7 @@ var Set = new Class({ * @method Phaser.Structs.Set#each * @since 3.0.0 * - * @param {function} callback - [description] + * @param {EachSetCallback} callback - [description] * @param {object} callbackScope - [description] * * @return {Phaser.Structs.Set} This Set object. @@ -189,7 +198,7 @@ var Set = new Class({ * @method Phaser.Structs.Set#iterate * @since 3.0.0 * - * @param {function} callback - [description] + * @param {EachSetCallback} callback - [description] * @param {object} callbackScope - [description] * * @return {Phaser.Structs.Set} This Set object. diff --git a/src/textures/TextureManager.js b/src/textures/TextureManager.js index 79f53a4d1..68df61d63 100644 --- a/src/textures/TextureManager.js +++ b/src/textures/TextureManager.js @@ -13,6 +13,13 @@ var GetValue = require('../utils/object/GetValue'); var Parser = require('./parsers'); var Texture = require('./Texture'); +/** + * @callback EachTextureCallback + * + * @param {Phaser.Textures.Texture} texture - [description] + * @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the child. + */ + /** * @classdesc * Textures are managed by the global TextureManager. This is a singleton class that is @@ -163,7 +170,7 @@ var TextureManager = new Class({ image.onload = function () { var texture = _this.create(key, image); - + Parser.Image(texture, 0); _this.emit('onload', key, texture); @@ -187,7 +194,7 @@ var TextureManager = new Class({ addImage: function (key, source, dataSource) { var texture = this.create(key, source); - + Parser.Image(texture, 0); if (dataSource) @@ -262,7 +269,7 @@ var TextureManager = new Class({ addCanvas: function (key, source) { var texture = this.create(key, source); - + Parser.Canvas(texture, 0); return texture; @@ -386,7 +393,7 @@ var TextureManager = new Class({ /** * Adds a Sprite Sheet to this Texture Manager. - * + * * In Phaser terminology a Sprite Sheet is a texture containing different frames, but each frame is the exact * same size and cannot be trimmed or rotated. * @@ -419,7 +426,7 @@ var TextureManager = new Class({ /** * Adds a Sprite Sheet to this Texture Manager, where the Sprite Sheet exists as a Frame within a Texture Atlas. - * + * * In Phaser terminology a Sprite Sheet is a texture containing different frames, but each frame is the exact * same size and cannot be trimmed or rotated. * @@ -738,7 +745,7 @@ var TextureManager = new Class({ * @method Phaser.Textures.TextureManager#each * @since 3.0.0 * - * @param {function} callback - The callback function to be sent the Textures. + * @param {EachTextureCallback} callback - The callback function to be sent the Textures. * @param {object} scope - The value to use as `this` when executing the callback. * @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the child. */