mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 12:43:26 +00:00
Added jsdocs
This commit is contained in:
parent
97bb52faec
commit
6283a8d6a6
18 changed files with 151 additions and 18 deletions
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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; }
|
|
@ -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')
|
||||
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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)
|
||||
{
|
|
@ -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; }
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue