2020-04-10 18:55:31 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2020 Photon Storm Ltd.
|
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var GetFastValue = require('../../utils/object/GetFastValue');
|
|
|
|
var CONST = require('../../const.js');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* A class for representing data about about a layer in a map. Maps are parsed from CSV, Tiled,
|
|
|
|
* etc. into this format. Tilemap, StaticTilemapLayer and DynamicTilemapLayer have a reference
|
|
|
|
* to this data and use it to look up and perform operations on tiles.
|
|
|
|
*
|
|
|
|
* @class LayerData
|
|
|
|
* @memberof Phaser.Tilemaps
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-04-27 15:13:40 +00:00
|
|
|
* @param {Phaser.Types.Tilemaps.LayerDataConfig} [config] - The Layer Data configuration object.
|
2020-04-10 18:55:31 +00:00
|
|
|
*/
|
|
|
|
var LayerData = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function LayerData (config)
|
|
|
|
{
|
|
|
|
if (config === undefined) { config = {}; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the layer, if specified in Tiled.
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#name
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.name = GetFastValue(config, 'name', 'layer');
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The x offset of where to draw from the top left.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#x
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.x = GetFastValue(config, 'x', 0);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The y offset of where to draw from the top left.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#y
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.y = GetFastValue(config, 'y', 0);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The width of the layer in tiles.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#width
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.width = GetFastValue(config, 'width', 0);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The height of the layer in tiles.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#height
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.height = GetFastValue(config, 'height', 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The pixel width of the tiles.
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#tileWidth
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.tileWidth = GetFastValue(config, 'tileWidth', 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The pixel height of the tiles.
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#tileHeight
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.tileHeight = GetFastValue(config, 'tileHeight', 0);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The base tile width.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#baseTileWidth
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.baseTileWidth = GetFastValue(config, 'baseTileWidth', this.tileWidth);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The base tile height.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#baseTileHeight
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.baseTileHeight = GetFastValue(config, 'baseTileHeight', this.tileHeight);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The layer's orientation, necessary to be able to determine a tile's pixelX and pixelY as well as the layer's width and height.
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#orientation
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.23beta.PR_svipal
|
|
|
|
*/
|
|
|
|
this.orientation = GetFastValue(config, 'orientation', CONST.ORTHOGONAL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The width in pixels of the entire layer.
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#widthInPixels
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.widthInPixels = GetFastValue(config, 'widthInPixels', this.width * this.baseTileWidth);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The height in pixels of the entire layer.
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#heightInPixels
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.heightInPixels = GetFastValue(config, 'heightInPixels', this.height * this.baseTileHeight);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The alpha value of the layer.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#alpha
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.alpha = GetFastValue(config, 'alpha', 1);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* Is the layer visible or not?
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#visible
|
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.visible = GetFastValue(config, 'visible', true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Layer specific properties (can be specified in Tiled)
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#properties
|
2020-02-05 03:47:22 +00:00
|
|
|
* @type {object[]}
|
2020-04-10 18:55:31 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-02-05 03:47:22 +00:00
|
|
|
this.properties = GetFastValue(config, 'properties', []);
|
2020-04-10 18:55:31 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* Tile ID index map.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#indexes
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.indexes = GetFastValue(config, 'indexes', []);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* Tile Collision ID index map.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#collideIndexes
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.collideIndexes = GetFastValue(config, 'collideIndexes', []);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* An array of callbacks.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#callbacks
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.callbacks = GetFastValue(config, 'callbacks', []);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* An array of physics bodies.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#bodies
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.bodies = GetFastValue(config, 'bodies', []);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* An array of the tile data indexes.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#data
|
|
|
|
* @type {Phaser.Tilemaps.Tile[][]}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.data = GetFastValue(config, 'data', []);
|
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* A reference to the Tilemap layer that owns this data.
|
2020-04-10 18:55:31 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#tilemapLayer
|
|
|
|
* @type {(Phaser.Tilemaps.DynamicTilemapLayer|Phaser.Tilemaps.StaticTilemapLayer)}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.tilemapLayer = GetFastValue(config, 'tilemapLayer', null);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional : Only for hexagonal tilemaps.
|
|
|
|
* The length of the horizontal sides of the hexagon.
|
|
|
|
* @name Phaser.Tilemaps.MapData#tiles
|
|
|
|
* @type {integer}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.hexSideLength = GetFastValue(config, 'hexSideLength', 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = LayerData;
|