diff --git a/src/gameobjects/GameObject.js b/src/gameobjects/GameObject.js index f965efeda..55317b342 100644 --- a/src/gameobjects/GameObject.js +++ b/src/gameobjects/GameObject.js @@ -11,6 +11,7 @@ var EventEmitter = require('eventemitter3'); * * @class GameObject * @memberOf Phaser.GameObjects + * @extends EventEmitter * @constructor * @since 3.0.0 * diff --git a/src/gameobjects/particles/EmitterOp.js b/src/gameobjects/particles/EmitterOp.js index 6b08f029e..214c25acc 100644 --- a/src/gameobjects/particles/EmitterOp.js +++ b/src/gameobjects/particles/EmitterOp.js @@ -1,6 +1,6 @@ var Class = require('../../utils/Class'); var FloatBetween = require('../../math/FloatBetween'); -var GetEaseFunction = require('../../tweens/builder/GetEaseFunction'); +var GetEaseFunction = require('../../tweens/builders/GetEaseFunction'); var GetFastValue = require('../../utils/object/GetFastValue'); var Wrap = require('../../math/Wrap'); diff --git a/src/gameobjects/pathfollower/PathFollower.js b/src/gameobjects/pathfollower/PathFollower.js index a91f307ef..52d3b0c4d 100644 --- a/src/gameobjects/pathfollower/PathFollower.js +++ b/src/gameobjects/pathfollower/PathFollower.js @@ -1,6 +1,6 @@ var Class = require('../../utils/Class'); var DegToRad = require('../../math/DegToRad'); -var GetBoolean = require('../../tweens/builder/GetBoolean'); +var GetBoolean = require('../../tweens/builders/GetBoolean'); var GetValue = require('../../utils/object/GetValue'); var Sprite = require('../sprite/Sprite'); var TWEEN_CONST = require('../../tweens/tween/const'); diff --git a/src/input/gamepad/configs/SNES_USB_Controller.js b/src/input/gamepad/configs/SNES_USB_Controller.js index 6d40591b7..45609b20e 100644 --- a/src/input/gamepad/configs/SNES_USB_Controller.js +++ b/src/input/gamepad/configs/SNES_USB_Controller.js @@ -1,5 +1,11 @@ -// Tatar SNES USB Controller -// USB Gamepad (STANDARD GAMEPAD Vendor: 0079 Product: 0011) +/** + * Tatar SNES USB Controller Gamepad Configuration. + * USB Gamepad (STANDARD GAMEPAD Vendor: 0079 Product: 0011) + * + * @name Phaser.Input.Gamepad.Configs.SNES_USB + * @type {object} + * @since 3.0.0 + */ module.exports = { diff --git a/src/input/gamepad/configs/Sony_PlayStation_DualShock_4.js b/src/input/gamepad/configs/Sony_PlayStation_DualShock_4.js index 58d276fbd..8aa37c1a3 100644 --- a/src/input/gamepad/configs/Sony_PlayStation_DualShock_4.js +++ b/src/input/gamepad/configs/Sony_PlayStation_DualShock_4.js @@ -1,4 +1,11 @@ -// Sony PlayStation DualShock 4 (v2) wireless controller +/** + * PlayStation DualShock 4 Gamepad Configuration. + * Sony PlayStation DualShock 4 (v2) wireless controller + * + * @name Phaser.Input.Gamepad.Configs.DUALSHOCK_4 + * @type {object} + * @since 3.0.0 + */ module.exports = { diff --git a/src/input/gamepad/configs/XBox360_Controller.js b/src/input/gamepad/configs/XBox360_Controller.js index 10ed93543..6b26cf3db 100644 --- a/src/input/gamepad/configs/XBox360_Controller.js +++ b/src/input/gamepad/configs/XBox360_Controller.js @@ -1,4 +1,10 @@ -// XBox 360 controller +/** + * XBox 360 Gamepad Configuration. + * + * @name Phaser.Input.Gamepad.Configs.XBOX_360 + * @type {object} + * @since 3.0.0 + */ module.exports = { diff --git a/src/input/gamepad/configs/index.js b/src/input/gamepad/configs/index.js index d19cd942b..24d2c8141 100644 --- a/src/input/gamepad/configs/index.js +++ b/src/input/gamepad/configs/index.js @@ -1,4 +1,6 @@ -// Phaser.Input.Gamepad.Configs +/** + * @namespace Phaser.Input.Gamepad.Configs + */ module.exports = { diff --git a/src/input/keyboard/keys/KeyCodes.js b/src/input/keyboard/keys/KeyCodes.js index 0ab1287eb..5ce75cdcf 100644 --- a/src/input/keyboard/keys/KeyCodes.js +++ b/src/input/keyboard/keys/KeyCodes.js @@ -1,93 +1,563 @@ module.exports = { + /** + * @name Phaser.Input.Keyboard.KeyCodes.BACKSPACE + * @type {integer} + * @since 3.0.0 + */ BACKSPACE: 8, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.TAB + * @type {integer} + * @since 3.0.0 + */ TAB: 9, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.ENTER + * @type {integer} + * @since 3.0.0 + */ ENTER: 13, + /** + * @name Phaser.Input.Keyboard.KeyCodes.SHIFT + * @type {integer} + * @since 3.0.0 + */ SHIFT: 16, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.CTRL + * @type {integer} + * @since 3.0.0 + */ CTRL: 17, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.ALT + * @type {integer} + * @since 3.0.0 + */ ALT: 18, + /** + * @name Phaser.Input.Keyboard.KeyCodes.PAUSE + * @type {integer} + * @since 3.0.0 + */ PAUSE: 19, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.CAPS_LOCK + * @type {integer} + * @since 3.0.0 + */ CAPS_LOCK: 20, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.ESC + * @type {integer} + * @since 3.0.0 + */ ESC: 27, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.SPACE + * @type {integer} + * @since 3.0.0 + */ SPACE: 32, + /** + * @name Phaser.Input.Keyboard.KeyCodes.PAGE_UP + * @type {integer} + * @since 3.0.0 + */ PAGE_UP: 33, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.PAGE_DOWN + * @type {integer} + * @since 3.0.0 + */ PAGE_DOWN: 34, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.END + * @type {integer} + * @since 3.0.0 + */ END: 35, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.HOME + * @type {integer} + * @since 3.0.0 + */ HOME: 36, + /** + * @name Phaser.Input.Keyboard.KeyCodes.LEFT + * @type {integer} + * @since 3.0.0 + */ LEFT: 37, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.UP + * @type {integer} + * @since 3.0.0 + */ UP: 38, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.RIGHT + * @type {integer} + * @since 3.0.0 + */ RIGHT: 39, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.DOWN + * @type {integer} + * @since 3.0.0 + */ DOWN: 40, + /** + * @name Phaser.Input.Keyboard.KeyCodes.PRINT_SCREEN + * @type {integer} + * @since 3.0.0 + */ PRINT_SCREEN: 42, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.INSERT + * @type {integer} + * @since 3.0.0 + */ INSERT: 45, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.DELETE + * @type {integer} + * @since 3.0.0 + */ DELETE: 46, + /** + * @name Phaser.Input.Keyboard.KeyCodes.ZERO + * @type {integer} + * @since 3.0.0 + */ ZERO: 48, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.ONE + * @type {integer} + * @since 3.0.0 + */ ONE: 49, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.TWO + * @type {integer} + * @since 3.0.0 + */ TWO: 50, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.THREE + * @type {integer} + * @since 3.0.0 + */ THREE: 51, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.FOUR + * @type {integer} + * @since 3.0.0 + */ FOUR: 52, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.FIVE + * @type {integer} + * @since 3.0.0 + */ FIVE: 53, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.SIX + * @type {integer} + * @since 3.0.0 + */ SIX: 54, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.SEVEN + * @type {integer} + * @since 3.0.0 + */ SEVEN: 55, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.EIGHT + * @type {integer} + * @since 3.0.0 + */ EIGHT: 56, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.NINE + * @type {integer} + * @since 3.0.0 + */ NINE: 57, + /** + * @name Phaser.Input.Keyboard.KeyCodes.A + * @type {integer} + * @since 3.0.0 + */ A: 65, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.B + * @type {integer} + * @since 3.0.0 + */ B: 66, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.C + * @type {integer} + * @since 3.0.0 + */ C: 67, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.D + * @type {integer} + * @since 3.0.0 + */ D: 68, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.E + * @type {integer} + * @since 3.0.0 + */ E: 69, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F + * @type {integer} + * @since 3.0.0 + */ F: 70, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.G + * @type {integer} + * @since 3.0.0 + */ G: 71, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.H + * @type {integer} + * @since 3.0.0 + */ H: 72, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.I + * @type {integer} + * @since 3.0.0 + */ I: 73, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.J + * @type {integer} + * @since 3.0.0 + */ J: 74, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.K + * @type {integer} + * @since 3.0.0 + */ K: 75, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.L + * @type {integer} + * @since 3.0.0 + */ L: 76, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.M + * @type {integer} + * @since 3.0.0 + */ M: 77, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.N + * @type {integer} + * @since 3.0.0 + */ N: 78, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.O + * @type {integer} + * @since 3.0.0 + */ O: 79, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.P + * @type {integer} + * @since 3.0.0 + */ P: 80, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.Q + * @type {integer} + * @since 3.0.0 + */ Q: 81, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.R + * @type {integer} + * @since 3.0.0 + */ R: 82, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.S + * @type {integer} + * @since 3.0.0 + */ S: 83, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.T + * @type {integer} + * @since 3.0.0 + */ T: 84, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.U + * @type {integer} + * @since 3.0.0 + */ U: 85, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.V + * @type {integer} + * @since 3.0.0 + */ V: 86, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.W + * @type {integer} + * @since 3.0.0 + */ W: 87, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.X + * @type {integer} + * @since 3.0.0 + */ X: 88, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.Y + * @type {integer} + * @since 3.0.0 + */ Y: 89, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.Z + * @type {integer} + * @since 3.0.0 + */ Z: 90, + /** + * @name Phaser.Input.Keyboard.KeyCodes.F1 + * @type {integer} + * @since 3.0.0 + */ F1: 112, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F2 + * @type {integer} + * @since 3.0.0 + */ F2: 113, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F3 + * @type {integer} + * @since 3.0.0 + */ F3: 114, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F4 + * @type {integer} + * @since 3.0.0 + */ F4: 115, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F5 + * @type {integer} + * @since 3.0.0 + */ F5: 116, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F6 + * @type {integer} + * @since 3.0.0 + */ F6: 117, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F7 + * @type {integer} + * @since 3.0.0 + */ F7: 118, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F8 + * @type {integer} + * @since 3.0.0 + */ F8: 119, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F9 + * @type {integer} + * @since 3.0.0 + */ F9: 120, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F10 + * @type {integer} + * @since 3.0.0 + */ F10: 121, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F11 + * @type {integer} + * @since 3.0.0 + */ F11: 122, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.F12 + * @type {integer} + * @since 3.0.0 + */ F12: 123, + /** + * @name Phaser.Input.Keyboard.KeyCodes.SEMICOLON + * @type {integer} + * @since 3.0.0 + */ SEMICOLON: 186, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.PLUS + * @type {integer} + * @since 3.0.0 + */ PLUS: 187, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.COMMA + * @type {integer} + * @since 3.0.0 + */ COMMA: 188, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.MINUS + * @type {integer} + * @since 3.0.0 + */ MINUS: 189, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.PERIOD + * @type {integer} + * @since 3.0.0 + */ PERIOD: 190, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.FORWAD_SLASH + * @type {integer} + * @since 3.0.0 + */ FORWAD_SLASH: 191, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.BACK_SLASH + * @type {integer} + * @since 3.0.0 + */ BACK_SLASH: 220, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.QUOTES + * @type {integer} + * @since 3.0.0 + */ QUOTES: 222, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.BACKTICK + * @type {integer} + * @since 3.0.0 + */ BACKTICK: 192, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.OPEN_BRACKET + * @type {integer} + * @since 3.0.0 + */ OPEN_BRACKET: 219, + + /** + * @name Phaser.Input.Keyboard.KeyCodes.CLOSED_BRACKET + * @type {integer} + * @since 3.0.0 + */ CLOSED_BRACKET: 221 }; diff --git a/src/tilemaps/parsers/Parse.js b/src/tilemaps/parsers/Parse.js index f5c738296..36170a055 100644 --- a/src/tilemaps/parsers/Parse.js +++ b/src/tilemaps/parsers/Parse.js @@ -1,8 +1,8 @@ var Formats = require('../Formats'); var Parse2DArray = require('./Parse2DArray'); var ParseCSV = require('./ParseCSV'); -var ParseTiledJSON = require('./tiled/'); -var ParseWeltmister = require('./impact/'); +var ParseJSONTiled = require('./tiled/ParseJSONTiled'); +var ParseWeltmeister = require('./impact/ParseWeltmeister'); /** * Parses raw data of a given Tilemap format into a new MapData object. If no recognized data format @@ -10,6 +10,9 @@ var ParseWeltmister = require('./impact/'); * tileHeight. When parsing from a map from Tiled, the tileWidth & tileHeight will be pulled from * the map data. * + * @function Phaser.Tilemaps.Parsers.Parse + * @since 3.0.0 + * * @param {string} name - The name of the tilemap, used to set the name on the MapData. * @param {integer} mapFormat - See ../Formats.js. * @param {integer[][]|string|object} data - 2D array, CSV string or Tiled JSON object. @@ -23,12 +26,14 @@ var ParseWeltmister = require('./impact/'); * the tile data doesn't need to change then setting this value to `true` will help with memory * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. + * + * @return {[type]} [description] */ var Parse = function (name, mapFormat, data, tileWidth, tileHeight, insertNull) { var newMap; - switch(mapFormat) + switch (mapFormat) { case (Formats.ARRAY_2D): newMap = Parse2DArray(name, data, tileWidth, tileHeight, insertNull); @@ -37,10 +42,10 @@ var Parse = function (name, mapFormat, data, tileWidth, tileHeight, insertNull) newMap = ParseCSV(name, data, tileWidth, tileHeight, insertNull); break; case (Formats.TILED_JSON): - newMap = ParseTiledJSON(name, data, insertNull); + newMap = ParseJSONTiled(name, data, insertNull); break; case (Formats.WELTMEISTER): - newMap = ParseWeltmister(name, data, insertNull); + newMap = ParseWeltmeister(name, data, insertNull); break; default: console.warn('Unrecognized tilemap data format: ' + mapFormat); diff --git a/src/tilemaps/parsers/Parse2DArray.js b/src/tilemaps/parsers/Parse2DArray.js index 37a76b31d..0c65a2183 100644 --- a/src/tilemaps/parsers/Parse2DArray.js +++ b/src/tilemaps/parsers/Parse2DArray.js @@ -6,6 +6,9 @@ var Tile = require('../Tile'); /** * Parses a 2D array of tile indexes into a new MapData object with a single layer. * + * @function Phaser.Tilemaps.Parsers.Parse2DArray + * @since 3.0.0 + * * @param {string} name - The name of the tilemap, used to set the name on the MapData. * @param {integer[][]} data - 2D array, CSV string or Tiled JSON object. * @param {integer} tileWidth - The width of a tile in pixels. @@ -16,6 +19,8 @@ var Tile = require('../Tile'); * the tile data doesn't need to change then setting this value to `true` will help with memory * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. + * + * @return {[type]} [description] */ var Parse2DArray = function (name, data, tileWidth, tileHeight, insertNull) { diff --git a/src/tilemaps/parsers/ParseCSV.js b/src/tilemaps/parsers/ParseCSV.js index 21a3330b4..5669c762f 100644 --- a/src/tilemaps/parsers/ParseCSV.js +++ b/src/tilemaps/parsers/ParseCSV.js @@ -4,6 +4,9 @@ var Parse2DArray = require('./Parse2DArray'); /** * Parses a CSV string of tile indexes into a new MapData object with a single layer. * + * @function Phaser.Tilemaps.Parsers.ParseCSV + * @since 3.0.0 + * * @param {string} name - The name of the tilemap, used to set the name on the MapData. * @param {string} data - CSV string of tile indexes. * @param {integer} tileWidth - The width of a tile in pixels. @@ -14,6 +17,8 @@ var Parse2DArray = require('./Parse2DArray'); * the tile data doesn't need to change then setting this value to `true` will help with memory * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. + * + * @return {[type]} [description] */ var ParseCSV = function (name, data, tileWidth, tileHeight, insertNull) { diff --git a/src/tilemaps/parsers/impact/ParseTileLayers.js b/src/tilemaps/parsers/impact/ParseTileLayers.js index 86bf0f793..e8aaea89e 100644 --- a/src/tilemaps/parsers/impact/ParseTileLayers.js +++ b/src/tilemaps/parsers/impact/ParseTileLayers.js @@ -1,6 +1,17 @@ var LayerData = require('../../mapdata/LayerData'); var Tile = require('../../Tile'); +/** + * [description] + * + * @function Phaser.Tilemaps.Parsers.Impact.ParseTileLayers + * @since 3.0.0 + * + * @param {object} json - [description] + * @param {boolean} insertNull - [description] + * + * @return {array} [description] + */ var ParseTileLayers = function (json, insertNull) { var tileLayers = []; diff --git a/src/tilemaps/parsers/impact/ParseTilesets.js b/src/tilemaps/parsers/impact/ParseTilesets.js index 112a8c2ad..a28fb9f34 100644 --- a/src/tilemaps/parsers/impact/ParseTilesets.js +++ b/src/tilemaps/parsers/impact/ParseTilesets.js @@ -1,5 +1,15 @@ var Tileset = require('../../Tileset'); +/** + * [description] + * + * @function Phaser.Tilemaps.Parsers.Impact.ParseTilesets + * @since 3.0.0 + * + * @param {object} json - [description] + * + * @return {array} [description] + */ var ParseTilesets = function (json) { var tilesets = []; diff --git a/src/tilemaps/parsers/impact/index.js b/src/tilemaps/parsers/impact/ParseWeltmeister.js similarity index 93% rename from src/tilemaps/parsers/impact/index.js rename to src/tilemaps/parsers/impact/ParseWeltmeister.js index 079c47cbb..36dcbff4a 100644 --- a/src/tilemaps/parsers/impact/index.js +++ b/src/tilemaps/parsers/impact/ParseWeltmeister.js @@ -1,11 +1,14 @@ var Formats = require('../../Formats'); var MapData = require('../../mapdata/MapData'); -var ParseTilesets = require('./ParseTilesets'); var ParseTileLayers = require('./ParseTileLayers'); +var ParseTilesets = require('./ParseTilesets'); /** * Parses a Weltmeister JSON object into a new MapData object. * + * @function Phaser.Tilemaps.Parsers.Impact.ParseWeltmeister + * @since 3.0.0 + * * @param {string} name - The name of the tilemap, used to set the name on the MapData. * @param {object} json - The Weltmeister JSON object. * @param {boolean} insertNull - Controls how empty tiles, tiles with an index of -1, in the map @@ -14,6 +17,8 @@ var ParseTileLayers = require('./ParseTileLayers'); * the tile data doesn't need to change then setting this value to `true` will help with memory * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. + * + * @return {object|null} [description] */ var ParseWeltmeister = function (name, json, insertNull) { @@ -25,6 +30,7 @@ var ParseWeltmeister = function (name, json, insertNull) var width = 0; var height = 0; + for (var i = 0; i < json.layer.length; i++) { if (json.layer[i].width > width) { width = json.layer[i].width; } diff --git a/src/tilemaps/parsers/index.js b/src/tilemaps/parsers/index.js index d3035288d..0f26712c1 100644 --- a/src/tilemaps/parsers/index.js +++ b/src/tilemaps/parsers/index.js @@ -8,7 +8,7 @@ module.exports = { Parse2DArray: require('./Parse2DArray'), ParseCSV: require('./ParseCSV'), - Impact: require('./impact'), - Tiled: require('./tiled') + Impact: require('./impact/ParseWeltmeister'), + Tiled: require('./tiled/ParseJSONTiled') }; diff --git a/src/tilemaps/parsers/tiled/AssignTileProperties.js b/src/tilemaps/parsers/tiled/AssignTileProperties.js index cd0e42c52..d668657b1 100644 --- a/src/tilemaps/parsers/tiled/AssignTileProperties.js +++ b/src/tilemaps/parsers/tiled/AssignTileProperties.js @@ -1,6 +1,13 @@ var Extend = require('../../../utils/object/Extend'); -// Copy properties from tileset to tiles +/** + * Copy properties from tileset to tiles. + * + * @function Phaser.Tilemaps.Parsers.Tiled.AssignTileProperties + * @since 3.0.0 + * + * @param {Phaser.Tilemaps.MapData} mapData - [description] + */ var AssignTileProperties = function (mapData) { var layerData; diff --git a/src/tilemaps/parsers/tiled/Base64Decode.js b/src/tilemaps/parsers/tiled/Base64Decode.js index 6d05fb096..742f7a9b8 100644 --- a/src/tilemaps/parsers/tiled/Base64Decode.js +++ b/src/tilemaps/parsers/tiled/Base64Decode.js @@ -1,3 +1,13 @@ +/** + * [description] + * + * @function Phaser.Tilemaps.Parsers.Tiled.Base64Decode + * @since 3.0.0 + * + * @param {object} data - [description] + * + * @return {array} [description] + */ var Base64Decode = function (data) { var binaryString = window.atob(data); diff --git a/src/tilemaps/parsers/tiled/BuildTilesetIndex.js b/src/tilemaps/parsers/tiled/BuildTilesetIndex.js index bd8a9de1e..4a14f1631 100644 --- a/src/tilemaps/parsers/tiled/BuildTilesetIndex.js +++ b/src/tilemaps/parsers/tiled/BuildTilesetIndex.js @@ -1,4 +1,13 @@ -// Master list of tiles -> x, y, index in tileset +/** + * Master list of tiles -> x, y, index in tileset. + * + * @function Phaser.Tilemaps.Parsers.Tiled.BuildTilesetIndex + * @since 3.0.0 + * + * @param {Phaser.Tilemaps.MapData} mapData - [description] + * + * @return {array} [description] + */ var BuildTilesetIndex = function (mapData) { var tiles = []; diff --git a/src/tilemaps/parsers/tiled/ParseGID.js b/src/tilemaps/parsers/tiled/ParseGID.js index 6a2f3eb82..ad9db8738 100644 --- a/src/tilemaps/parsers/tiled/ParseGID.js +++ b/src/tilemaps/parsers/tiled/ParseGID.js @@ -2,12 +2,19 @@ var FLIPPED_HORIZONTAL = 0x80000000; var FLIPPED_VERTICAL = 0x40000000; var FLIPPED_ANTI_DIAGONAL = 0x20000000; // Top-right is swapped with bottom-left corners -// See Tiled documentation on tile flipping: -// http://docs.mapeditor.org/en/latest/reference/tmx-map-format/ - +/** + * See Tiled documentation on tile flipping: + * http://docs.mapeditor.org/en/latest/reference/tmx-map-format/ + * + * @function Phaser.Tilemaps.Parsers.Tiled.ParseGID + * @since 3.0.0 + * + * @param {number} gid - [description] + * + * @return {object} [description] + */ var ParseGID = function (gid) { - var flippedHorizontal = Boolean(gid & FLIPPED_HORIZONTAL); var flippedVertical = Boolean(gid & FLIPPED_VERTICAL); var flippedAntiDiagonal = Boolean(gid & FLIPPED_ANTI_DIAGONAL); diff --git a/src/tilemaps/parsers/tiled/ParseImageLayers.js b/src/tilemaps/parsers/tiled/ParseImageLayers.js index ca5636164..7d2d6959d 100644 --- a/src/tilemaps/parsers/tiled/ParseImageLayers.js +++ b/src/tilemaps/parsers/tiled/ParseImageLayers.js @@ -1,5 +1,15 @@ var GetFastValue = require('../../../utils/object/GetFastValue'); +/** + * [description] + * + * @function Phaser.Tilemaps.Parsers.Tiled.ParseImageLayers + * @since 3.0.0 + * + * @param {object} json - [description] + * + * @return {array} [description] + */ var ParseImageLayers = function (json) { var images = []; diff --git a/src/tilemaps/parsers/tiled/index.js b/src/tilemaps/parsers/tiled/ParseJSONTiled.js similarity index 94% rename from src/tilemaps/parsers/tiled/index.js rename to src/tilemaps/parsers/tiled/ParseJSONTiled.js index 70a6f5814..d88bf7d8d 100644 --- a/src/tilemaps/parsers/tiled/index.js +++ b/src/tilemaps/parsers/tiled/ParseJSONTiled.js @@ -10,6 +10,9 @@ var AssignTileProperties = require('./AssignTileProperties'); /** * Parses a Tiled JSON object into a new MapData object. * + * @function Phaser.Tilemaps.Parsers.Tiled.ParseJSONTiled + * @since 3.0.0 + * * @param {string} name - The name of the tilemap, used to set the name on the MapData. * @param {object} json - The Tiled JSON object. * @param {boolean} insertNull - Controls how empty tiles, tiles with an index of -1, in the map @@ -18,6 +21,8 @@ var AssignTileProperties = require('./AssignTileProperties'); * the tile data doesn't need to change then setting this value to `true` will help with memory * consumption. However if your map is small or you need to update the tiles dynamically, then leave * the default value set. + * + * @return {Phaser.Tilemaps.MapData|null} [description] */ var ParseJSONTiled = function (name, json, insertNull) { diff --git a/src/tilemaps/parsers/tiled/ParseObject.js b/src/tilemaps/parsers/tiled/ParseObject.js index 143c13789..b31940273 100644 --- a/src/tilemaps/parsers/tiled/ParseObject.js +++ b/src/tilemaps/parsers/tiled/ParseObject.js @@ -2,8 +2,21 @@ var Pick = require('./Pick'); var ParseGID = require('./ParseGID'); var copyPoints = function (p) { return { x: p.x, y: p.y }; }; + var commonObjectProps = [ 'id', 'name', 'type', 'rotation', 'properties', 'visible', 'x', 'y', 'width', 'height' ]; +/** + * [description] + * + * @function Phaser.Tilemaps.Parsers.Tiled.ParseObject + * @since 3.0.0 + * + * @param {object} tiledObject - [description] + * @param {number} [offsetX=0] - [description] + * @param {number} [offsetY=0] - [description] + * + * @return {object} [description] + */ var ParseObject = function (tiledObject, offsetX, offsetY) { if (offsetX === undefined) { offsetX = 0; } diff --git a/src/tilemaps/parsers/tiled/ParseObjectLayers.js b/src/tilemaps/parsers/tiled/ParseObjectLayers.js index 6bbc9e5f8..890442426 100644 --- a/src/tilemaps/parsers/tiled/ParseObjectLayers.js +++ b/src/tilemaps/parsers/tiled/ParseObjectLayers.js @@ -2,6 +2,16 @@ var GetFastValue = require('../../../utils/object/GetFastValue'); var ParseObject = require('./ParseObject'); var ObjectLayer = require('../../mapdata/ObjectLayer'); +/** + * [description] + * + * @function Phaser.Tilemaps.Parsers.Tiled.ParseObjectLayers + * @since 3.0.0 + * + * @param {object} json - [description] + * + * @return {array} [description] + */ var ParseObjectLayers = function (json) { var objectLayers = []; diff --git a/src/tilemaps/parsers/tiled/ParseTileLayers.js b/src/tilemaps/parsers/tiled/ParseTileLayers.js index f51cfe0a4..abed546b1 100644 --- a/src/tilemaps/parsers/tiled/ParseTileLayers.js +++ b/src/tilemaps/parsers/tiled/ParseTileLayers.js @@ -4,6 +4,17 @@ var LayerData = require('../../mapdata/LayerData'); var ParseGID = require('./ParseGID'); var Tile = require('../../Tile'); +/** + * [description] + * + * @function Phaser.Tilemaps.Parsers.Tiled.ParseTileLayers + * @since 3.0.0 + * + * @param {object} json - [description] + * @param {boolean} insertNull - [description] + * + * @return {array} [description] + */ var ParseTileLayers = function (json, insertNull) { var tileLayers = []; diff --git a/src/tilemaps/parsers/tiled/ParseTilesets.js b/src/tilemaps/parsers/tiled/ParseTilesets.js index 16db15abc..782d16473 100644 --- a/src/tilemaps/parsers/tiled/ParseTilesets.js +++ b/src/tilemaps/parsers/tiled/ParseTilesets.js @@ -2,7 +2,16 @@ var Tileset = require('../../Tileset'); var ImageCollection = require('../../ImageCollection'); var ParseObject = require('./ParseObject'); -// Tilesets & Image Collections +/** + * Tilesets & Image Collections + * + * @function Phaser.Tilemaps.Parsers.Tiled.ParseTilesets + * @since 3.0.0 + * + * @param {object} json - [description] + * + * @return {object} [description] + */ var ParseTilesets = function (json) { var tilesets = []; diff --git a/src/tilemaps/parsers/tiled/Pick.js b/src/tilemaps/parsers/tiled/Pick.js index 38315ba72..0cf44887b 100644 --- a/src/tilemaps/parsers/tiled/Pick.js +++ b/src/tilemaps/parsers/tiled/Pick.js @@ -6,10 +6,10 @@ var HasValue = require('../../../utils/object/HasValue'); * @function Phaser.Tilemaps.Parsers.Tiled.Pick * @since 3.0.0 * - * @param {[type]} object - [description] - * @param {[type]} keys - [description] + * @param {object} object - [description] + * @param {array} keys - [description] * - * @return {[type]} [description] + * @return {object} [description] */ var Pick = function (object, keys) { diff --git a/src/time/TimerEvent.js b/src/time/TimerEvent.js index 1ce54043a..c7a5603aa 100644 --- a/src/time/TimerEvent.js +++ b/src/time/TimerEvent.js @@ -1,6 +1,17 @@ var Class = require('../utils/Class'); var GetFastValue = require('../utils/object/GetFastValue'); +/** + * @classdesc + * [description] + * + * @class TimerEvent + * @memberOf Phaser.Time + * @constructor + * @since 3.0.0 + * + * @param {object} config - [description] + */ var TimerEvent = new Class({ initialize: @@ -8,58 +19,138 @@ var TimerEvent = new Class({ function TimerEvent (config) { /** - * @property {number} delay - The delay in ms at which this TimerEvent fires. - * @readOnly - */ + * The delay in ms at which this TimerEvent fires. + * + * @name Phaser.Time.TimerEvent#delay + * @type {number} + * @default 0 + * @readOnly + * @since 3.0.0 + */ this.delay = 0; /** - * @property {number} repeat - The total number of times this TimerEvent will repeat before finishing. - * @readOnly - */ + * The total number of times this TimerEvent will repeat before finishing. + * + * @name Phaser.Time.TimerEvent#repeat + * @type {number} + * @default 0 + * @readOnly + * @since 3.0.0 + */ this.repeat = 0; /** - * @property {number} repeatCount - If repeating this contains the current repeat count. - */ + * If repeating this contains the current repeat count. + * + * @name Phaser.Time.TimerEvent#repeatCount + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.repeatCount = 0; /** - * @property {boolean} loop - True if this TimerEvent loops, otherwise false. - * @readOnly - */ + * True if this TimerEvent loops, otherwise false. + * + * @name Phaser.Time.TimerEvent#loop + * @type {boolean} + * @default false + * @readOnly + * @since 3.0.0 + */ this.loop = false; /** - * @property {function} callback - The callback that will be called when the TimerEvent occurs. - */ + * The callback that will be called when the TimerEvent occurs. + * + * @name Phaser.Time.TimerEvent#callback + * @type {function} + * @since 3.0.0 + */ this.callback; /** - * @property {object} callbackContext - The context in which the callback will be called. - */ + * The scope in which the callback will be called. + * + * @name Phaser.Time.TimerEvent#callbackScope + * @type {object} + * @since 3.0.0 + */ this.callbackScope; /** - * @property {any[]} arguments - Additional arguments to be passed to the callback. - */ + * Additional arguments to be passed to the callback. + * + * @name Phaser.Time.TimerEvent#args + * @type {array} + * @since 3.0.0 + */ this.args; - // Scale the time causing this TimerEvent to update + /** + * Scale the time causing this TimerEvent to update. + * + * @name Phaser.Time.TimerEvent#timeScale + * @type {number} + * @default 1 + * @since 3.0.0 + */ this.timeScale = 1; - // Start this many MS into the elapsed (useful if you want a long duration with repeat, but for the first loop to fire quickly) + /** + * Start this many MS into the elapsed (useful if you want a long duration with repeat, but for the first loop to fire quickly) + * + * @name Phaser.Time.TimerEvent#startAt + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.startAt = 0; + /** + * [description] + * + * @name Phaser.Time.TimerEvent#elapsed + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.elapsed = 0; + /** + * [description] + * + * @name Phaser.Time.TimerEvent#paused + * @type {boolean} + * @default false + * @since 3.0.0 + */ this.paused = false; + /** + * [description] + * + * @name Phaser.Time.TimerEvent#hasDispatched + * @type {boolean} + * @default false + * @since 3.0.0 + */ this.hasDispatched = false; this.reset(config); }, + /** + * [description] + * + * @method Phaser.Time.TimerEvent#reset + * @since 3.0.0 + * + * @param {object} config - [description] + * + * @return {Phaser.Time.TimerEvent} This TimerEvent object. + */ reset: function (config) { this.delay = GetFastValue(config, 'delay', 0); @@ -88,13 +179,27 @@ var TimerEvent = new Class({ return this; }, - // Gets the progress of the current iteration, not factoring in repeats + /** + * Gets the progress of the current iteration, not factoring in repeats. + * + * @method Phaser.Time.TimerEvent#getProgress + * @since 3.0.0 + * + * @return {number} [description] + */ getProgress: function () { return (this.elapsed / this.delay); }, - // Gets the progress of the timer overall, factoring in repeats. + /** + * Gets the progress of the timer overall, factoring in repeats. + * + * @method Phaser.Time.TimerEvent#getOverallProgress + * @since 3.0.0 + * + * @return {number} [description] + */ getOverallProgress: function () { if (this.repeat > 0) @@ -110,21 +215,53 @@ var TimerEvent = new Class({ } }, + /** + * [description] + * + * @method Phaser.Time.TimerEvent#getRepeatCount + * @since 3.0.0 + * + * @return {number} [description] + */ getRepeatCount: function () { return this.repeatCount; }, + /** + * [description] + * + * @method Phaser.Time.TimerEvent#getElapsed + * @since 3.0.0 + * + * @return {number} [description] + */ getElapsed: function () { return this.elapsed; }, + /** + * [description] + * + * @method Phaser.Time.TimerEvent#getElapsedSeconds + * @since 3.0.0 + * + * @return {number} [description] + */ getElapsedSeconds: function () { return this.elapsed * 0.001; }, + /** + * [description] + * + * @method Phaser.Time.TimerEvent#remove + * @since 3.0.0 + * + * @param {function} dispatchCallback - [description] + */ remove: function (dispatchCallback) { if (dispatchCallback === undefined) { dispatchCallback = false; } @@ -136,7 +273,12 @@ var TimerEvent = new Class({ this.repeatCount = 0; }, - // Called internaly, private + /** + * [description] + * + * @method Phaser.Time.TimerEvent#destroy + * @since 3.0.0 + */ destroy: function () { this.callback = undefined; diff --git a/src/tweens/Timeline.js b/src/tweens/Timeline.js index 0f59fa6ae..f5f24a7a0 100644 --- a/src/tweens/Timeline.js +++ b/src/tweens/Timeline.js @@ -1,73 +1,228 @@ var Class = require('../utils/Class'); -var TweenBuilder = require('./builder/TweenBuilder'); +var EventEmitter = require('eventemitter3'); +var TweenBuilder = require('./builders/TweenBuilder'); var TWEEN_CONST = require('./tween/const'); -// Phaser.Tweens.Timeline - +/** + * @classdesc + * [description] + * + * @class Timeline + * @memberOf Phaser.Tweens + * @extends EventEmitter + * @constructor + * @since 3.0.0 + * + * @param {Phaser.Tweens.TweenManager} manager - [description] + */ var Timeline = new Class({ + Extends: EventEmitter, + initialize: function Timeline (manager) { + EventEmitter.call(this); + + /** + * [description] + * + * @name Phaser.Tweens.Timeline#manager + * @type {Phaser.Tweens.TweenManager} + * @since 3.0.0 + */ this.manager = manager; + /** + * [description] + * + * @name Phaser.Tweens.Timeline#isTimeline + * @type {boolean} + * @default true + * @since 3.0.0 + */ this.isTimeline = true; - // An array of Tween objects, each containing a unique property and target being tweened. + /** + * An array of Tween objects, each containing a unique property and target being tweened. + * + * @name Phaser.Tweens.Timeline#data + * @type {array} + * @default [] + * @since 3.0.0 + */ this.data = []; - // data array doesn't usually change, so we can cache the length + /** + * data array doesn't usually change, so we can cache the length + * + * @name Phaser.Tweens.Timeline#totalData + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.totalData = 0; - // If true then duration, delay, etc values are all frame totals + /** + * If true then duration, delay, etc values are all frame totals. + * + * @name Phaser.Tweens.Timeline#useFrames + * @type {boolean} + * @default false + * @since 3.0.0 + */ this.useFrames = false; - // Scales the time applied to this Tween. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on. - // Value isn't used when calculating total duration of the tween, it's a run-time delta adjustment only. + /** + * Scales the time applied to this Tween. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on. + * Value isn't used when calculating total duration of the tween, it's a run-time delta adjustment only. + * + * @name Phaser.Tweens.Timeline#timeScale + * @type {number} + * @default 1 + * @since 3.0.0 + */ this.timeScale = 1; - // Loop this tween? Can be -1 for an infinite loop, or an integer. - // When enabled it will play through ALL TweenDatas again (use TweenData.repeat to loop a single TD) + /** + * Loop this tween? Can be -1 for an infinite loop, or an integer. + * When enabled it will play through ALL TweenDatas again (use TweenData.repeat to loop a single TD) + * + * @name Phaser.Tweens.Timeline#loop + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.loop = 0; - // Time in ms/frames before the tween loops. + /** + * Time in ms/frames before the tween loops. + * + * @name Phaser.Tweens.Timeline#loopDelay + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.loopDelay = 0; - // How many loops are left to run? + /** + * How many loops are left to run? + * + * @name Phaser.Tweens.Timeline#loopCounter + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.loopCounter = 0; - // Time in ms/frames before the 'onComplete' event fires. This never fires if loop = true (as it never completes) + /** + * Time in ms/frames before the 'onComplete' event fires. This never fires if loop = true (as it never completes) + * + * @name Phaser.Tweens.Timeline#completeDelay + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.completeDelay = 0; - // Countdown timer (used by loopDelay and completeDelay) + /** + * Countdown timer (used by loopDelay and completeDelay) + * + * @name Phaser.Tweens.Timeline#countdown + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.countdown = 0; - // The current state of the tween + /** + * The current state of the tween + * + * @name Phaser.Tweens.Timeline#state + * @type {integer} + * @since 3.0.0 + */ this.state = TWEEN_CONST.PENDING_ADD; - // The state of the tween when it was paused (used by Resume) + /** + * The state of the tween when it was paused (used by Resume) + * + * @name Phaser.Tweens.Timeline#_pausedState + * @type {integer} + * @private + * @since 3.0.0 + */ this._pausedState = TWEEN_CONST.PENDING_ADD; - // Does the Tween start off paused? (if so it needs to be started with Tween.play) + /** + * Does the Tween start off paused? (if so it needs to be started with Tween.play) + * + * @name Phaser.Tweens.Timeline#paused + * @type {boolean} + * @default false + * @since 3.0.0 + */ this.paused = false; - // Elapsed time in ms/frames of this run through the Tween. + /** + * Elapsed time in ms/frames of this run through the Tween. + * + * @name Phaser.Tweens.Timeline#elapsed + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.elapsed = 0; - // Total elapsed time in ms/frames of the entire Tween, including looping. + /** + * Total elapsed time in ms/frames of the entire Tween, including looping. + * + * @name Phaser.Tweens.Timeline#totalElapsed + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.totalElapsed = 0; - // Time in ms/frames for the whole Tween to play through once, excluding loop amounts and loop delays + /** + * Time in ms/frames for the whole Tween to play through once, excluding loop amounts and loop delays. + * + * @name Phaser.Tweens.Timeline#duration + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.duration = 0; - // Value between 0 and 1. The amount through the Tween, excluding loops. + /** + * Value between 0 and 1. The amount through the Tween, excluding loops. + * + * @name Phaser.Tweens.Timeline#progress + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.progress = 0; - // Time in ms/frames for all Tweens to complete (including looping) + /** + * Time in ms/frames for all Tweens to complete (including looping) + * + * @name Phaser.Tweens.Timeline#totalDuration + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.totalDuration = 0; - // Value between 0 and 1. The amount through the entire Tween, including looping. + /** + * Value between 0 and 1. The amount through the entire Tween, including looping. + * + * @name Phaser.Tweens.Timeline#totalProgress + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.totalProgress = 0; this.callbacks = { @@ -81,6 +236,16 @@ var Timeline = new Class({ this.callbackScope; }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#setTimeScale + * @since 3.0.0 + * + * @param {number} value - [description] + * + * @return {Phaser.Tweens.Timeline} This Timeline object. + */ setTimeScale: function (value) { this.timeScale = value; @@ -88,21 +253,57 @@ var Timeline = new Class({ return this; }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#getTimeScale + * @since 3.0.0 + * + * @return {number} [description] + */ getTimeScale: function () { return this.timeScale; }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#isPlaying + * @since 3.0.0 + * + * @return {boolean} [description] + */ isPlaying: function () { return (this.state === TWEEN_CONST.ACTIVE); }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#add + * @since 3.0.0 + * + * @param {[type]} config - [description] + * + * @return {Phaser.Tweens.Timeline} This Timeline object. + */ add: function (config) { return this.queue(TweenBuilder(this, config)); }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#queue + * @since 3.0.0 + * + * @param {[type]} tween - [description] + * + * @return {Phaser.Tweens.Timeline} This Timeline object. + */ queue: function (tween) { if (!this.isPlaying()) @@ -118,16 +319,46 @@ var Timeline = new Class({ return this; }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#hasOffset + * @since 3.0.0 + * + * @param {Phaser.Tweens.Tween} tween - [description] + * + * @return {boolean} [description] + */ hasOffset: function (tween) { return (tween.offset !== null); }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#isOffsetAbsolute + * @since 3.0.0 + * + * @param {number} value - [description] + * + * @return {boolean} [description] + */ isOffsetAbsolute: function (value) { return (typeof(value) === 'number'); }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#isOffsetRelative + * @since 3.0.0 + * + * @param {string} value - [description] + * + * @return {boolean} [description] + */ isOffsetRelative: function (value) { var t = typeof(value); @@ -145,6 +376,17 @@ var Timeline = new Class({ return false; }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#getRelativeOffset + * @since 3.0.0 + * + * @param {string} value - [description] + * @param {number} base - [description] + * + * @return {number} [description] + */ getRelativeOffset: function (value, base) { var op = value[0]; @@ -166,6 +408,12 @@ var Timeline = new Class({ return Math.max(0, result); }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#calcDuration + * @since 3.0.0 + */ calcDuration: function () { var prevEnd = 0; @@ -189,29 +437,21 @@ var Timeline = new Class({ { offsetDuration = 0; } - - // console.log('Timeline.calcDuration', i, 'absolute', tween.calculatedOffset); } else if (this.isOffsetRelative(tween.offset)) { // A relative offset (i.e. '-=1000', so starts at 'offset' ms relative to the PREVIOUS Tweens ending time) tween.calculatedOffset = this.getRelativeOffset(tween.offset, prevEnd); - - // console.log('Timeline.calcDuration', i, 'relative', tween.calculatedOffset); } } else { // Sequential tween.calculatedOffset = offsetDuration; - - // console.log('Timeline.calcDuration', i, 'sequential', tween.calculatedOffset); } prevEnd = tween.totalDuration + tween.calculatedOffset; - // console.log('Span', i, tween.calculatedOffset, 'to', prevEnd); - totalDuration += tween.totalDuration; offsetDuration += tween.totalDuration; } @@ -231,6 +471,14 @@ var Timeline = new Class({ } }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#init + * @since 3.0.0 + * + * @return {boolean} [description] + */ init: function () { this.calcDuration(); @@ -250,6 +498,14 @@ var Timeline = new Class({ } }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#resetTweens + * @since 3.0.0 + * + * @param {boolean} resetFromLoop - [description] + */ resetTweens: function (resetFromLoop) { for (var i = 0; i < this.totalData; i++) @@ -260,6 +516,19 @@ var Timeline = new Class({ } }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#setCallback + * @since 3.0.0 + * + * @param {string} type - [description] + * @param {function} callback - [description] + * @param {array} [params] - [description] + * @param {object} [scope] - [description] + * + * @return {Phaser.Tweens.Timeline} This Timeline object. + */ setCallback: function (type, callback, params, scope) { if (Timeline.TYPES.indexOf(type) !== -1) @@ -270,6 +539,12 @@ var Timeline = new Class({ return this; }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#play + * @since 3.0.0 + */ play: function () { if (this.state === TWEEN_CONST.ACTIVE) @@ -298,8 +573,16 @@ var Timeline = new Class({ { onStart.func.apply(onStart.scope, onStart.params); } + + this.emit('start', this); }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#nextState + * @since 3.0.0 + */ nextState: function () { if (this.loopCounter > 0) @@ -320,6 +603,8 @@ var Timeline = new Class({ onLoop.func.apply(onLoop.scope, onLoop.params); } + this.emit('loop', this, this.loopCounter); + this.resetTweens(true); if (this.loopDelay > 0) @@ -346,12 +631,24 @@ var Timeline = new Class({ onComplete.func.apply(onComplete.scope, onComplete.params); } + this.emit('complete', this); + this.state = TWEEN_CONST.PENDING_REMOVE; } }, - // Returns 'true' if this Timeline has finished and should be removed from the Tween Manager - // Otherwise, returns false + /** + * Returns 'true' if this Timeline has finished and should be removed from the Tween Manager. + * Otherwise, returns false. + * + * @method Phaser.Tweens.Timeline#update + * @since 3.0.0 + * + * @param {number} timestamp - [description] + * @param {number} delta - [description] + * + * @return {boolean} Returns `true` if this Timeline has finished and should be removed from the Tween Manager. + */ update: function (timestamp, delta) { if (this.state === TWEEN_CONST.PAUSED) @@ -397,6 +694,8 @@ var Timeline = new Class({ onUpdate.func.apply(onUpdate.scope, onUpdate.params); } + this.emit('update', this); + // Anything still running? If not, we're done if (stillRunning === 0) { @@ -429,6 +728,8 @@ var Timeline = new Class({ onComplete.func.apply(onComplete.scope, onComplete.params); } + this.emit('complete', this); + this.state = TWEEN_CONST.PENDING_REMOVE; } @@ -438,12 +739,25 @@ var Timeline = new Class({ return (this.state === TWEEN_CONST.PENDING_REMOVE); }, - // Stops the Tween immediately, whatever stage of progress it is at and flags it for removal by the TweenManager + /** + * Stops the Tween immediately, whatever stage of progress it is at and flags it for removal by the TweenManager. + * + * @method Phaser.Tweens.Timeline#stop + * @since 3.0.0 + */ stop: function () { this.state = TWEEN_CONST.PENDING_REMOVE; }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#pause + * @since 3.0.0 + * + * @return {Phaser.Tweens.Timeline} This Timeline object. + */ pause: function () { if (this.state === TWEEN_CONST.PAUSED) @@ -457,9 +771,19 @@ var Timeline = new Class({ this.state = TWEEN_CONST.PAUSED; + this.emit('pause', this); + return this; }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#resume + * @since 3.0.0 + * + * @return {Phaser.Tweens.Timeline} This Timeline object. + */ resume: function () { if (this.state === TWEEN_CONST.PAUSED) @@ -469,9 +793,21 @@ var Timeline = new Class({ this.state = this._pausedState; } + this.emit('resume', this); + return this; }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#hasTarget + * @since 3.0.0 + * + * @param {object} target - [description] + * + * @return {boolean} [description] + */ hasTarget: function (target) { for (var i = 0; i < this.data.length; i++) @@ -485,6 +821,12 @@ var Timeline = new Class({ return false; }, + /** + * [description] + * + * @method Phaser.Tweens.Timeline#destroy + * @since 3.0.0 + */ destroy: function () { for (var i = 0; i < this.data.length; i++) diff --git a/src/tweens/TweenManager.js b/src/tweens/TweenManager.js index 80018ced9..2936389aa 100644 --- a/src/tweens/TweenManager.js +++ b/src/tweens/TweenManager.js @@ -1,21 +1,45 @@ var Class = require('../utils/Class'); -var NumberTweenBuilder = require('./builder/NumberTweenBuilder'); +var NumberTweenBuilder = require('./builders/NumberTweenBuilder'); var PluginManager = require('../plugins/PluginManager'); -var TimelineBuilder = require('./builder/TimelineBuilder'); +var TimelineBuilder = require('./builders/TimelineBuilder'); var TWEEN_CONST = require('./tween/const'); -var TweenBuilder = require('./builder/TweenBuilder'); +var TweenBuilder = require('./builders/TweenBuilder'); // Phaser.Tweens.TweenManager +/** + * @classdesc + * [description] + * + * @class TweenManager + * @memberOf Phaser.Tweens + * @constructor + * @since 3.0.0 + * + * @param {Phaser.Scene} scene - [description] + */ var TweenManager = new Class({ initialize: function TweenManager (scene) { - // The Scene that owns this plugin + /** + * [description] + * + * @name Phaser.Tweens.TweenManager#scene + * @type {Phaser.Scene} + * @since 3.0.0 + */ this.scene = scene; + /** + * [description] + * + * @name Phaser.Tweens.TweenManager#systems + * @type {Phaser.Scenes.Systems} + * @since 3.0.0 + */ this.systems = scene.sys; if (!scene.sys.settings.isBooted) @@ -23,16 +47,74 @@ var TweenManager = new Class({ scene.sys.events.once('boot', this.boot, this); } + /** + * [description] + * + * @name Phaser.Tweens.TweenManager#timeScale + * @type {number} + * @default 1 + * @since 3.0.0 + */ this.timeScale = 1; + /** + * [description] + * + * @name Phaser.Tweens.TweenManager#_add + * @type {array} + * @private + * @since 3.0.0 + */ this._add = []; + + /** + * [description] + * + * @name Phaser.Tweens.TweenManager#_pending + * @type {array} + * @private + * @since 3.0.0 + */ this._pending = []; + + /** + * [description] + * + * @name Phaser.Tweens.TweenManager#_active + * @type {array} + * @private + * @since 3.0.0 + */ this._active = []; + + /** + * [description] + * + * @name Phaser.Tweens.TweenManager#_destroy + * @type {array} + * @private + * @since 3.0.0 + */ this._destroy = []; + /** + * [description] + * + * @name Phaser.Tweens.TweenManager#_toProcess + * @type {integer} + * @private + * @default 0 + * @since 3.0.0 + */ this._toProcess = 0; }, + /** + * [description] + * + * @method Phaser.Tweens.TweenManager#boot + * @since 3.0.0 + */ boot: function () { var eventEmitter = this.systems.events; @@ -45,13 +127,31 @@ var TweenManager = new Class({ this.timeScale = 1; }, - // Create a Tween Timeline and return it, but do NOT add it to the active or pending Tween lists + /** + * Create a Tween Timeline and return it, but do NOT add it to the active or pending Tween lists. + * + * @method Phaser.Tweens.TweenManager#createTimeline + * @since 3.0.0 + * + * @param {object} config - [description] + * + * @return {Phaser.Tweens.Timeline} [description] + */ createTimeline: function (config) { return TimelineBuilder(this, config); }, - // Create a Tween Timeline and add it to the active Tween list + /** + * Create a Tween Timeline and add it to the active Tween list/ + * + * @method Phaser.Tweens.TweenManager#timeline + * @since 3.0.0 + * + * @param {object} config - [description] + * + * @return {Phaser.Tweens.Timeline} [description] + */ timeline: function (config) { var timeline = TimelineBuilder(this, config); @@ -66,13 +166,31 @@ var TweenManager = new Class({ return timeline; }, - // Create a Tween and return it, but do NOT add it to the active or pending Tween lists + /** + * Create a Tween and return it, but do NOT add it to the active or pending Tween lists. + * + * @method Phaser.Tweens.TweenManager#create + * @since 3.0.0 + * + * @param {object} config - [description] + * + * @return {Phaser.Tweens.Tween} [description] + */ create: function (config) { return TweenBuilder(this, config); }, - // Create a Tween and add it to the active Tween list + /** + * Create a Tween and add it to the active Tween list. + * + * @method Phaser.Tweens.TweenManager#add + * @since 3.0.0 + * + * @param {[type]} config - [description] + * + * @return {Phaser.Tweens.Tween} [description] + */ add: function (config) { var tween = TweenBuilder(this, config); @@ -84,7 +202,16 @@ var TweenManager = new Class({ return tween; }, - // Add an existing tween into the active Tween list + /** + * Add an existing tween into the active Tween list. + * + * @method Phaser.Tweens.TweenManager#existing + * @since 3.0.0 + * + * @param {Phaser.Tweens.Tween} tween - [description] + * + * @return {Phaser.Tweens.TweenManager} This Tween Manager object. + */ existing: function (tween) { this._add.push(tween); @@ -94,7 +221,16 @@ var TweenManager = new Class({ return this; }, - // Create a Tween and add it to the active Tween list + /** + * Create a Tween and add it to the active Tween list. + * + * @method Phaser.Tweens.TweenManager#addCounter + * @since 3.0.0 + * + * @param {object} config - [description] + * + * @return {Phaser.Tweens.Tween} [description] + */ addCounter: function (config) { var tween = NumberTweenBuilder(this, config); @@ -106,6 +242,12 @@ var TweenManager = new Class({ return tween; }, + /** + * [description] + * + * @method Phaser.Tweens.TweenManager#preUpdate + * @since 3.0.0 + */ preUpdate: function () { if (this._toProcess === 0) @@ -163,6 +305,15 @@ var TweenManager = new Class({ this._toProcess = 0; }, + /** + * [description] + * + * @method Phaser.Tweens.TweenManager#update + * @since 3.0.0 + * + * @param {number} timestamp - [description] + * @param {number} delta - [description] + */ update: function (timestamp, delta) { // Process active tweens @@ -186,6 +337,16 @@ var TweenManager = new Class({ } }, + /** + * [description] + * + * @method Phaser.Tweens.TweenManager#makeActive + * @since 3.0.0 + * + * @param {Phaser.Tweens.Tween} tween - [description] + * + * @return {Phaser.Tweens.TweenManager} This Tween Manager object. + */ makeActive: function (tween) { if (this._add.indexOf(tween) !== -1 || this._active.indexOf(tween) !== -1) @@ -209,19 +370,17 @@ var TweenManager = new Class({ return this; }, - // Passes all Tweens to the given callback. - /** - * [description] + * Passes all Tweens to the given callback. * * @method Phaser.Tweens.TweenManager#each * @since 3.0.0 * * @param {function} callback - [description] - * @param {object} [thisArg] - [description] + * @param {object} [scope] - [description] * @param {...*} [arguments] - [description] */ - each: function (callback, thisArg) + each: function (callback, scope) { var args = [ null ]; @@ -234,7 +393,7 @@ var TweenManager = new Class({ { args[0] = this.list[texture]; - callback.apply(thisArg, args); + callback.apply(scope, args); } }, @@ -326,7 +485,7 @@ var TweenManager = new Class({ * @method Phaser.Tweens.TweenManager#isTweening * @since 3.0.0 * - * @param {any} target - [description] + * @param {object} target - [description] * * @return {boolean} [description] */ @@ -447,10 +606,8 @@ var TweenManager = new Class({ return this; }, - // Scene that owns this manager is shutting down - /** - * [description] + * Scene that owns this manager is shutting down. * * @method Phaser.Tweens.TweenManager#shutdown * @since 3.0.0 diff --git a/src/tweens/builder/GetBoolean.js b/src/tweens/builders/GetBoolean.js similarity index 52% rename from src/tweens/builder/GetBoolean.js rename to src/tweens/builders/GetBoolean.js index 7c1657e2a..c30f13f09 100644 --- a/src/tweens/builder/GetBoolean.js +++ b/src/tweens/builders/GetBoolean.js @@ -1,3 +1,15 @@ +/** + * [description] + * + * @function Phaser.Tweens.Builders.GetBoolean + * @since 3.0.0 + * + * @param {object} source - [description] + * @param {string} key - [description] + * @param {any} defaultValue - [description] + * + * @return {any} [description] + */ var GetBoolean = function (source, key, defaultValue) { if (!source) diff --git a/src/tweens/builder/GetEaseFunction.js b/src/tweens/builders/GetEaseFunction.js similarity index 78% rename from src/tweens/builder/GetEaseFunction.js rename to src/tweens/builders/GetEaseFunction.js index a50d5bee9..939779d1c 100644 --- a/src/tweens/builder/GetEaseFunction.js +++ b/src/tweens/builders/GetEaseFunction.js @@ -1,5 +1,16 @@ var EaseMap = require('../../math/easing/EaseMap'); +/** + * [description] + * + * @function Phaser.Tweens.Builders.GetEaseFunction + * @since 3.0.0 + * + * @param {string|function} ease - [description] + * @param {array} easeParams - [description] + * + * @return {function} [description] + */ var GetEaseFunction = function (ease, easeParams) { if (typeof ease === 'string' && EaseMap.hasOwnProperty(ease)) diff --git a/src/tweens/builder/GetNewValue.js b/src/tweens/builders/GetNewValue.js similarity index 75% rename from src/tweens/builder/GetNewValue.js rename to src/tweens/builders/GetNewValue.js index 9922b6401..3af209395 100644 --- a/src/tweens/builder/GetNewValue.js +++ b/src/tweens/builders/GetNewValue.js @@ -1,3 +1,15 @@ +/** + * [description] + * + * @function Phaser.Tweens.Builders.GetNewValue + * @since 3.0.0 + * + * @param {object} source - [description] + * @param {string} key - [description] + * @param {any} defaultValue - [description] + * + * @return {function} [description] + */ var GetNewValue = function (source, key, defaultValue) { var valueCallback; diff --git a/src/tweens/builder/GetProps.js b/src/tweens/builders/GetProps.js similarity index 83% rename from src/tweens/builder/GetProps.js rename to src/tweens/builders/GetProps.js index fd2a03920..3b95ced2a 100644 --- a/src/tweens/builder/GetProps.js +++ b/src/tweens/builders/GetProps.js @@ -1,5 +1,15 @@ var RESERVED = require('../tween/ReservedProps'); +/** + * [description] + * + * @function Phaser.Tweens.Builders.GetProps + * @since 3.0.0 + * + * @param {object} config - [description] + * + * @return {array} [description] + */ var GetProps = function (config) { var key; diff --git a/src/tweens/builder/GetTargets.js b/src/tweens/builders/GetTargets.js similarity index 71% rename from src/tweens/builder/GetTargets.js rename to src/tweens/builders/GetTargets.js index f26777cbb..8f9d0ca5e 100644 --- a/src/tweens/builder/GetTargets.js +++ b/src/tweens/builders/GetTargets.js @@ -1,5 +1,15 @@ var GetValue = require('../../utils/object/GetValue'); +/** + * [description] + * + * @function Phaser.Tweens.Builders.GetTargets + * @since 3.0.0 + * + * @param {object} config - [description] + * + * @return {array} [description] + */ var GetTargets = function (config) { var targets = GetValue(config, 'targets', null); diff --git a/src/tweens/builder/GetTweens.js b/src/tweens/builders/GetTweens.js similarity index 70% rename from src/tweens/builder/GetTweens.js rename to src/tweens/builders/GetTweens.js index ceeb0bc41..0fe9ed9c6 100644 --- a/src/tweens/builder/GetTweens.js +++ b/src/tweens/builders/GetTweens.js @@ -1,5 +1,15 @@ var GetValue = require('../../utils/object/GetValue'); +/** + * [description] + * + * @function Phaser.Tweens.Builders.GetTweens + * @since 3.0.0 + * + * @param {object} config - [description] + * + * @return {array} [description] + */ var GetTweens = function (config) { var tweens = GetValue(config, 'tweens', null); diff --git a/src/tweens/builder/GetValueOp.js b/src/tweens/builders/GetValueOp.js similarity index 94% rename from src/tweens/builder/GetValueOp.js rename to src/tweens/builders/GetValueOp.js index 0c9c15b1f..cc7e291d7 100644 --- a/src/tweens/builder/GetValueOp.js +++ b/src/tweens/builders/GetValueOp.js @@ -13,6 +13,17 @@ function hasGetters (def) return hasGetStart(def) || hasGetEnd(def); } +/** + * [description] + * + * @function Phaser.Tweens.Builders.GetValueOp + * @since 3.0.0 + * + * @param {string} key - [description] + * @param {any} propertyValue - [description] + * + * @return {function} [description] + */ var GetValueOp = function (key, propertyValue) { var callbacks; diff --git a/src/tweens/builder/NumberTweenBuilder.js b/src/tweens/builders/NumberTweenBuilder.js similarity index 90% rename from src/tweens/builder/NumberTweenBuilder.js rename to src/tweens/builders/NumberTweenBuilder.js index 5b7cbb077..99addb9f6 100644 --- a/src/tweens/builder/NumberTweenBuilder.js +++ b/src/tweens/builders/NumberTweenBuilder.js @@ -8,8 +8,18 @@ var GetValueOp = require('./GetValueOp'); var Tween = require('../tween/Tween'); var TweenData = require('../tween/TweenData'); -// Phaser.Tweens.NumberTweenBuilder - +/** + * [description] + * + * @function Phaser.Tweens.Builders.NumberTweenBuilder + * @since 3.0.0 + * + * @param {Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline} parent - [description] + * @param {object} config - [description] + * @param {Phaser.Tweens.Tween~ConfigDefaults} defaults - [description] + * + * @return {Phaser.Tweens.Tween} [description] + */ var NumberTweenBuilder = function (parent, config, defaults) { if (defaults === undefined) diff --git a/src/tweens/builder/TimelineBuilder.js b/src/tweens/builders/TimelineBuilder.js similarity index 94% rename from src/tweens/builder/TimelineBuilder.js rename to src/tweens/builders/TimelineBuilder.js index 3bb3b8412..47d6918f0 100644 --- a/src/tweens/builder/TimelineBuilder.js +++ b/src/tweens/builders/TimelineBuilder.js @@ -1,17 +1,26 @@ var Clone = require('../../utils/object/Clone'); var Defaults = require('../tween/Defaults'); +var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var GetBoolean = require('./GetBoolean'); var GetEaseFunction = require('./GetEaseFunction'); var GetNewValue = require('./GetNewValue'); var GetTargets = require('./GetTargets'); var GetTweens = require('./GetTweens'); var GetValue = require('../../utils/object/GetValue'); -var GetAdvancedValue = require('../../utils/object/GetAdvancedValue'); var Timeline = require('../Timeline'); var TweenBuilder = require('./TweenBuilder'); -// Phaser.Tweens.TimelineBuilder - +/** + * [description] + * + * @function Phaser.Tweens.Builders.TimelineBuilder + * @since 3.0.0 + * + * @param {Phaser.Tweens.TweenManager} manager - [description] + * @param {object} config - [description] + * + * @return {Phaser.Tweens.Timeline} [description] + */ var TimelineBuilder = function (manager, config) { var timeline = new Timeline(manager); diff --git a/src/tweens/builder/TweenBuilder.js b/src/tweens/builders/TweenBuilder.js similarity index 91% rename from src/tweens/builder/TweenBuilder.js rename to src/tweens/builders/TweenBuilder.js index 95c653937..8ad17e21c 100644 --- a/src/tweens/builder/TweenBuilder.js +++ b/src/tweens/builders/TweenBuilder.js @@ -10,8 +10,18 @@ var GetValueOp = require('./GetValueOp'); var Tween = require('../tween/Tween'); var TweenData = require('../tween/TweenData'); -// Phaser.Tweens.TweenBuilder - +/** + * [description] + * + * @function Phaser.Tweens.Builders.TweenBuilder + * @since 3.0.0 + * + * @param {Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline} parent - [description] + * @param {object} config - [description] + * @param {Phaser.Tweens.Tween~ConfigDefaults} defaults - [description] + * + * @return {Phaser.Tweens.Tween} [description] + */ var TweenBuilder = function (parent, config, defaults) { if (defaults === undefined) diff --git a/src/tweens/builders/index.js b/src/tweens/builders/index.js new file mode 100644 index 000000000..30ca68f88 --- /dev/null +++ b/src/tweens/builders/index.js @@ -0,0 +1,18 @@ +/** + * @namespace Phaser.Tweens.Builders + */ + +module.exports = { + + GetBoolean: require('./GetBoolean'), + GetEaseFunction: require('./GetEaseFunction'), + GetNewValue: require('./GetNewValue'), + GetProps: require('./GetProps'), + GetTargets: require('./GetTargets'), + GetTweens: require('./GetTweens'), + GetValueOp: require('./GetValueOp'), + NumberTweenBuilder: require('./NumberTweenBuilder'), + TimelineBuilder: require('./TimelineBuilder'), + TweenBuilder: require('./TweenBuilder'), + +}; diff --git a/src/tweens/index.js b/src/tweens/index.js index 11b29cb03..39b55d0d0 100644 --- a/src/tweens/index.js +++ b/src/tweens/index.js @@ -4,6 +4,8 @@ module.exports = { + Builders: require('./builders'), + TweenManager: require('./TweenManager'), Tween: require('./tween/Tween'), TweenData: require('./tween/TweenData'), diff --git a/src/tweens/tween/Defaults.js b/src/tweens/tween/Defaults.js index eede395ec..1568f089f 100644 --- a/src/tweens/tween/Defaults.js +++ b/src/tweens/tween/Defaults.js @@ -1,3 +1,18 @@ +/** + * @typedef {object} Phaser.Tweens.Tween~ConfigDefaults + * @property {object|object[]} targets - [description] + * @property {number} [delay=0] - [description] + * @property {number} [duration=1000] - [description] + * @property {string} [ease='Power0'] - [description] + * @property {array} [easeParams] - [description] + * @property {number} [hold=0] - [description] + * @property {number} [repeat=0] - [description] + * @property {number} [repeatDelay=0] - [description] + * @property {boolean} [yoyo=false] - [description] + * @property {boolean} [flipX=false] - [description] + * @property {boolean} [flipY=false] - [description] + */ + var TWEEN_DEFAULTS = { targets: null, delay: 0, diff --git a/src/tweens/tween/ReservedProps.js b/src/tweens/tween/ReservedProps.js index ada1f223d..52f06736a 100644 --- a/src/tweens/tween/ReservedProps.js +++ b/src/tweens/tween/ReservedProps.js @@ -5,6 +5,8 @@ // duration: The duration of the tween // ease: The ease function used by the tween // easeParams: The parameters to go with the ease function (if any) +// flipX: flip X the GameObject on tween end +// flipY: flip Y the GameObject on tween end// hold: The time the tween will pause before running a yoyo // hold: The time the tween will pause before running a yoyo // loop: The time the tween will pause before starting either a yoyo or returning to the start for a repeat // loopDelay: diff --git a/src/tweens/tween/Tween.js b/src/tweens/tween/Tween.js index 68d146e2f..5849a893a 100644 --- a/src/tweens/tween/Tween.js +++ b/src/tweens/tween/Tween.js @@ -3,87 +3,268 @@ var GameObjectCreator = require('../../gameobjects/GameObjectCreator'); var GameObjectFactory = require('../../gameobjects/GameObjectFactory'); var TWEEN_CONST = require('./const'); -// Phaser.Tweens.Tween - +/** + * @classdesc + * [description] + * + * @class Tween + * @memberOf Phaser.Tweens + * @constructor + * @since 3.0.0 + * + * @param {Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline} parent - [description] + * @param {Phaser.Tweens.TweenData[]} data - [description] + * @param {array} targets - [description] + */ var Tween = new Class({ initialize: function Tween (parent, data, targets) { + /** + * [description] + * + * @name Phaser.Tweens.Tween#parent + * @type {Phaser.Tweens.TweenManager|Phaser.Tweens.Timeline} + * @since 3.0.0 + */ this.parent = parent; - // Is the parent of this Tween a Timeline? + /** + * Is the parent of this Tween a Timeline? + * + * @name Phaser.Tweens.Tween#parentIsTimeline + * @type {boolean} + * @since 3.0.0 + */ this.parentIsTimeline = parent.hasOwnProperty('isTimeline'); - // An array of TweenData objects, each containing a unique property and target being tweened. + /** + * An array of TweenData objects, each containing a unique property and target being tweened. + * + * @name Phaser.Tweens.Tween#data + * @type {Phaser.Tweens.TweenData[]} + * @since 3.0.0 + */ this.data = data; - // data array doesn't change, so we can cache the length + /** + * data array doesn't change, so we can cache the length + * + * @name Phaser.Tweens.Tween#totalData + * @type {integer} + * @since 3.0.0 + */ this.totalData = data.length; - // An array of references to the target/s this Tween is operating on + /** + * An array of references to the target/s this Tween is operating on + * + * @name Phaser.Tweens.Tween#targets + * @type {object[]} + * @since 3.0.0 + */ this.targets = targets; - // Cached target total (not necessarily the same as the data total) + /** + * Cached target total (not necessarily the same as the data total) + * + * @name Phaser.Tweens.Tween#totalTargets + * @type {integer} + * @since 3.0.0 + */ this.totalTargets = targets.length; - // If true then duration, delay, etc values are all frame totals + /** + * If true then duration, delay, etc values are all frame totals. + * + * @name Phaser.Tweens.Tween#useFrames + * @type {boolean} + * @default false + * @since 3.0.0 + */ this.useFrames = false; - // Scales the time applied to this Tween. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on. - // Value isn't used when calculating total duration of the tween, it's a run-time delta adjustment only. + /** + * Scales the time applied to this Tween. A value of 1 runs in real-time. A value of 0.5 runs 50% slower, and so on. + * Value isn't used when calculating total duration of the tween, it's a run-time delta adjustment only. + * + * @name Phaser.Tweens.Tween#timeScale + * @type {number} + * @default 1 + * @since 3.0.0 + */ this.timeScale = 1; - // Loop this tween? Can be -1 for an infinite loop, or an integer. - // When enabled it will play through ALL TweenDatas again (use TweenData.repeat to loop a single TD) + /** + * Loop this tween? Can be -1 for an infinite loop, or an integer. + * When enabled it will play through ALL TweenDatas again (use TweenData.repeat to loop a single TD) + * + * @name Phaser.Tweens.Tween#loop + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.loop = 0; - // Time in ms/frames before the tween loops. + /** + * Time in ms/frames before the tween loops. + * + * @name Phaser.Tweens.Tween#loopDelay + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.loopDelay = 0; - // How many loops are left to run? + /** + * How many loops are left to run? + * + * @name Phaser.Tweens.Tween#loopCounter + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.loopCounter = 0; - // Time in ms/frames before the 'onComplete' event fires. This never fires if loop = -1 (as it never completes) + /** + * Time in ms/frames before the 'onComplete' event fires. This never fires if loop = -1 (as it never completes) + * + * @name Phaser.Tweens.Tween#completeDelay + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.completeDelay = 0; - // Countdown timer (used by timeline offset, loopDelay and completeDelay) + /** + * Countdown timer (used by timeline offset, loopDelay and completeDelay) + * + * @name Phaser.Tweens.Tween#countdown + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.countdown = 0; - // Set only if this Tween is part of a Timeline. + /** + * Set only if this Tween is part of a Timeline. + * + * @name Phaser.Tweens.Tween#offset + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.offset = 0; - // Set only if this Tween is part of a Timeline. The calculated offset amount. + /** + * Set only if this Tween is part of a Timeline. The calculated offset amount. + * + * @name Phaser.Tweens.Tween#calculatedOffset + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.calculatedOffset = 0; - // The current state of the tween + /** + * The current state of the tween + * + * @name Phaser.Tweens.Tween#state + * @type {integer} + * @since 3.0.0 + */ this.state = TWEEN_CONST.PENDING_ADD; - // The state of the tween when it was paused (used by Resume) + /** + * The state of the tween when it was paused (used by Resume) + * + * @name Phaser.Tweens.Tween#_pausedState + * @type {integer} + * @private + * @since 3.0.0 + */ this._pausedState = TWEEN_CONST.PENDING_ADD; - // Does the Tween start off paused? (if so it needs to be started with Tween.play) + /** + * Does the Tween start off paused? (if so it needs to be started with Tween.play) + * + * @name Phaser.Tweens.Tween#paused + * @type {boolean} + * @default false + * @since 3.0.0 + */ this.paused = false; - // Elapsed time in ms/frames of this run through the Tween. + /** + * Elapsed time in ms/frames of this run through the Tween. + * + * @name Phaser.Tweens.Tween#elapsed + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.elapsed = 0; - // Total elapsed time in ms/frames of the entire Tween, including looping. + /** + * Total elapsed time in ms/frames of the entire Tween, including looping. + * + * @name Phaser.Tweens.Tween#totalElapsed + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.totalElapsed = 0; - // Time in ms/frames for the whole Tween to play through once, excluding loop amounts and loop delays + /** + * Time in ms/frames for the whole Tween to play through once, excluding loop amounts and loop delays. + * + * @name Phaser.Tweens.Tween#duration + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.duration = 0; - // Value between 0 and 1. The amount through the Tween, excluding loops. + /** + * Value between 0 and 1. The amount through the Tween, excluding loops. + * + * @name Phaser.Tweens.Tween#progress + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.progress = 0; - // Time in ms/frames for the Tween to complete (including looping) + /** + * Time in ms/frames for the Tween to complete (including looping) + * + * @name Phaser.Tweens.Tween#totalDuration + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.totalDuration = 0; - // Value between 0 and 1. The amount through the entire Tween, including looping. + /** + * Value between 0 and 1. The amount through the entire Tween, including looping. + * + * @name Phaser.Tweens.Tween#totalProgress + * @type {number} + * @default 0 + * @since 3.0.0 + */ this.totalProgress = 0; + /** + * An object containing the various Tween callback references. + * + * @name Phaser.Tweens.Tween#callbacks + * @type {object} + * @default 0 + * @since 3.0.0 + */ this.callbacks = { onComplete: null, onLoop: null, @@ -96,11 +277,29 @@ var Tween = new Class({ this.callbackScope; }, + /** + * [description] + * + * @method Phaser.Tweens.Tween#getValue + * @since 3.0.0 + * + * @return {[type]} [description] + */ getValue: function () { return this.data[0].current; }, + /** + * [description] + * + * @method Phaser.Tweens.Tween#setTimeScale + * @since 3.0.0 + * + * @param {number} value - [description] + * + * @return {Phaser.Tweens.Tween} This Tween object. + */ setTimeScale: function (value) { this.timeScale = value; @@ -108,26 +307,72 @@ var Tween = new Class({ return this; }, + /** + * [description] + * + * @method Phaser.Tweens.Tween#getTimeScale + * @since 3.0.0 + * + * @return {number} [description] + */ getTimeScale: function () { return this.timeScale; }, + /** + * [description] + * + * @method Phaser.Tweens.Tween#isPlaying + * @since 3.0.0 + * + * @return {boolean} [description] + */ isPlaying: function () { return (this.state === TWEEN_CONST.ACTIVE); }, + /** + * [description] + * + * @method Phaser.Tweens.Tween#isPaused + * @since 3.0.0 + * + * @return {boolean} [description] + */ isPaused: function () { return (this.state === TWEEN_CONST.PAUSED); }, + /** + * [description] + * + * @method Phaser.Tweens.Tween#hasTarget + * @since 3.0.0 + * + * @param {object} target - [description] + * + * @return {boolean} [description] + */ hasTarget: function (target) { return (this.targets.indexOf(target) !== -1); }, + /** + * [description] + * + * @method Phaser.Tweens.Tween#updateTo + * @since 3.0.0 + * + * @param {string} key - [description] + * @param {any} value - [description] + * @param {boolean} startToCurrent - [description] + * + * @return {Phaser.Tweens.Tween} This Tween object. + */ updateTo: function (key, value, startToCurrent) { for (var i = 0; i < this.totalData; i++) @@ -150,6 +395,12 @@ var Tween = new Class({ return this; }, + /** + * [description] + * + * @method Phaser.Tweens.Tween#restart + * @since 3.0.0 + */ restart: function () { this.stop(); @@ -324,7 +575,7 @@ var Tween = new Class({ * @method Phaser.Tweens.Tween#pause * @since 3.0.0 * - * @return {Phaser.Tweens.Tween} [description] + * @return {Phaser.Tweens.Tween} This Tween object. */ pause: function () { @@ -339,6 +590,8 @@ var Tween = new Class({ this.state = TWEEN_CONST.PAUSED; + this.emit('pause', this); + return this; }, @@ -457,7 +710,7 @@ var Tween = new Class({ * @method Phaser.Tweens.Tween#resume * @since 3.0.0 * - * @return {Phaser.Tweens.Tween} [description] + * @return {Phaser.Tweens.Tween} This Tween object. */ resume: function () { @@ -468,6 +721,8 @@ var Tween = new Class({ this.state = this._pausedState; } + this.emit('resume', this); + return this; }, @@ -550,10 +805,10 @@ var Tween = new Class({ * * @param {string} type - [description] * @param {function} callback - [description] - * @param {array} params - [description] - * @param {object} scope - [description] + * @param {array} [params] - [description] + * @param {object} [scope] - [description] * - * @return {Phaser.Tweens.Tween} [description] + * @return {Phaser.Tweens.Tween} This Tween object. */ setCallback: function (type, callback, params, scope) { @@ -567,6 +822,8 @@ var Tween = new Class({ * * @method Phaser.Tweens.Tween#stop * @since 3.0.0 + * + * @param {float} [resetTo] - A value between 0 and 1. */ stop: function (resetTo) { @@ -585,7 +842,7 @@ var Tween = new Class({ * @since 3.0.0 * * @param {number} timestamp - [description] - * @param {float} delta - [description] + * @param {number} delta - [description] * * @return {boolean} Returns `true` if this Tween has finished and should be removed from the Tween Manager, otherwise returns `false`. */ @@ -684,6 +941,18 @@ var Tween = new Class({ return (this.state === TWEEN_CONST.PENDING_REMOVE); }, + /** + * [description] + * + * @method Phaser.Tweens.Tween#setStateFromEnd + * @since 3.0.0 + * + * @param {Phaser.Tweens.Tween} tween - [description] + * @param {Phaser.Tweens.TweenData} tweenData - [description] + * @param {number} diff - [description] + * + * @return {integer} The state of this Tween. + */ setStateFromEnd: function (tween, tweenData, diff) { if (tweenData.yoyo) @@ -717,8 +986,6 @@ var Tween = new Class({ onYoyo.func.apply(onYoyo.scope, onYoyo.params); } - // console.log('SetStateFromEnd-a', tweenData.start, tweenData.end); - tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start); return TWEEN_CONST.PLAYING_BACKWARD; @@ -734,9 +1001,6 @@ var Tween = new Class({ tweenData.elapsed = diff; tweenData.progress = diff / tweenData.duration; - // tweenData.elapsed = 0; - // tweenData.progress = 0; - if (tweenData.flipX) { tweenData.target.toggleFlipX(); @@ -757,8 +1021,6 @@ var Tween = new Class({ onRepeat.func.apply(onRepeat.scope, onRepeat.params); } - // console.log('SetStateFromEnd-b', tweenData.start, tweenData.end); - tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start); tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start); @@ -783,7 +1045,18 @@ var Tween = new Class({ return TWEEN_CONST.COMPLETE; }, - // Was PLAYING_BACKWARD and has hit the start + /** + * Was PLAYING_BACKWARD and has hit the start. + * + * @method Phaser.Tweens.Tween#setStateFromStart + * @since 3.0.0 + * + * @param {Phaser.Tweens.Tween} tween - [description] + * @param {Phaser.Tweens.TweenData} tweenData - [description] + * @param {number} diff - [description] + * + * @return {integer} The state of this Tween. + */ setStateFromStart: function (tween, tweenData, diff) { if (tweenData.repeatCounter > 0) @@ -794,9 +1067,6 @@ var Tween = new Class({ tweenData.elapsed = diff; tweenData.progress = diff / tweenData.duration; - // tweenData.elapsed = 0; - // tweenData.progress = 0; - if (tweenData.flipX) { tweenData.target.toggleFlipX(); @@ -817,8 +1087,6 @@ var Tween = new Class({ onRepeat.func.apply(onRepeat.scope, onRepeat.params); } - // console.log('SetStateFromStart', tweenData.start, tweenData.end); - tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start); // Delay? @@ -841,7 +1109,19 @@ var Tween = new Class({ return TWEEN_CONST.COMPLETE; }, - // Delta is either a value in ms, or 1 if Tween.useFrames is true + // + /** + * [description] + * + * @method Phaser.Tweens.Tween#updateTweenData + * @since 3.0.0 + * + * @param {Phaser.Tweens.Tween} tween - [description] + * @param {Phaser.Tweens.TweenData} tweenData - [description] + * @param {number} delta - Either a value in ms, or 1 if Tween.useFrames is true + * + * @return {boolean} [description] + */ updateTweenData: function (tween, tweenData, delta) { switch (tweenData.state) @@ -981,6 +1261,23 @@ Tween.TYPES = [ 'onYoyo' ]; +/** + * Creates a new Tween object. + * + * Note: This method will only be available Tweens have been built into Phaser. + * + * @method Phaser.GameObjects.GameObjectFactory#tween + * @since 3.0.0 + * + * @param {object} config - The Tween configuration. + * + * @return {Phaser.Tweens.Tween} The Tween that was created. + */ +GameObjectFactory.register('tween', function (config) +{ + return this.scene.sys.tweens.add(config); +}); + // When registering a factory function 'this' refers to the GameObjectFactory context. // // There are several properties available to use: @@ -989,16 +1286,23 @@ Tween.TYPES = [ // this.displayList - a reference to the Display List the Scene owns // this.updateList - a reference to the Update List the Scene owns -GameObjectFactory.register('tween', function (config) -{ - return this.scene.sys.tweens.add(config); -}); - -// When registering a factory function 'this' refers to the GameObjectCreator context. - +/** + * Creates a new Tween object and returns it. + * + * Note: This method will only be available if Tweens have been built into Phaser. + * + * @method Phaser.GameObjects.GameObjectCreator#tween + * @since 3.0.0 + * + * @param {object} config - The Tween configuration. + * + * @return {Phaser.Tweens.Tween} The Tween that was created. + */ GameObjectCreator.register('tween', function (config) { return this.scene.sys.tweens.create(config); }); +// When registering a factory function 'this' refers to the GameObjectCreator context. + module.exports = Tween; diff --git a/src/tweens/tween/TweenData.js b/src/tweens/tween/TweenData.js index 7f0108b0f..bc929b4dd 100644 --- a/src/tweens/tween/TweenData.js +++ b/src/tweens/tween/TweenData.js @@ -1,5 +1,25 @@ -// Phaser.Tweens.TweenData - +/** + * [description] + * + * @function Phaser.Tweens.TweenData + * @since 3.0.0 + * + * @param {object} target - [description] + * @param {string} key - [description] + * @param {function} getEnd - [description] + * @param {function} getStart - [description] + * @param {function} ease - [description] + * @param {number} delay - [description] + * @param {number} duration - [description] + * @param {boolean} yoyo - [description] + * @param {number} hold - [description] + * @param {number} repeat - [description] + * @param {number} repeatDelay - [description] + * @param {boolean} flipX - [description] + * @param {boolean} flipY - [description] + * + * @return {Phaser.Tweens.TweenData} [description] + */ var TweenData = function (target, key, getEnd, getStart, ease, delay, duration, yoyo, hold, repeat, repeatDelay, flipX, flipY) { return { diff --git a/src/math/noise/SimplexNoise.js b/wip/noise/SimplexNoise.js similarity index 100% rename from src/math/noise/SimplexNoise.js rename to wip/noise/SimplexNoise.js