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) {