2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2020-01-15 12:07:09 +00:00
|
|
|
* @copyright 2020 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-07 17:10:01 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2020-10-02 11:02:40 +00:00
|
|
|
var CONST = require('../const');
|
2018-02-07 17:10:01 +00:00
|
|
|
var GetFastValue = require('../../utils/object/GetFastValue');
|
2017-11-17 19:16:39 +00:00
|
|
|
|
2018-02-07 15:27:21 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* A class for representing data about about a layer in a map. Maps are parsed from CSV, Tiled,
|
2020-10-12 10:40:40 +00:00
|
|
|
* etc. into this format. Tilemap and TilemapLayer objects have a reference
|
2018-02-07 15:27:21 +00:00
|
|
|
* to this data and use it to look up and perform operations on tiles.
|
|
|
|
*
|
|
|
|
* @class LayerData
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Tilemaps
|
2018-02-07 15:27:21 +00:00
|
|
|
* @constructor
|
2018-02-07 23:40:59 +00:00
|
|
|
* @since 3.0.0
|
2018-02-07 15:27:21 +00:00
|
|
|
*
|
2020-04-27 15:13:40 +00:00
|
|
|
* @param {Phaser.Types.Tilemaps.LayerDataConfig} [config] - The Layer Data configuration object.
|
2018-02-07 15:27:21 +00:00
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
var LayerData = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-11-27 13:33:30 +00:00
|
|
|
function LayerData (config)
|
2017-11-17 19:16:39 +00:00
|
|
|
{
|
|
|
|
if (config === undefined) { config = {}; }
|
|
|
|
|
2018-02-07 23:40:59 +00:00
|
|
|
/**
|
2019-01-23 23:00:07 +00:00
|
|
|
* The name of the layer, if specified in Tiled.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#name
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.name = GetFastValue(config, 'name', 'layer');
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The x offset of where to draw from the top left.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#x
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.x = GetFastValue(config, 'x', 0);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The y offset of where to draw from the top left.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#y
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.y = GetFastValue(config, 'y', 0);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The width of the layer in tiles.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#width
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.width = GetFastValue(config, 'width', 0);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The height of the layer in tiles.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#height
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.height = GetFastValue(config, 'height', 0);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2019-01-23 19:30:08 +00:00
|
|
|
* The pixel width of the tiles.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#tileWidth
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.tileWidth = GetFastValue(config, 'tileWidth', 0);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2019-01-23 19:30:08 +00:00
|
|
|
* The pixel height of the tiles.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#tileHeight
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.tileHeight = GetFastValue(config, 'tileHeight', 0);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The base tile width.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#baseTileWidth
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-12-01 19:25:48 +00:00
|
|
|
this.baseTileWidth = GetFastValue(config, 'baseTileWidth', this.tileWidth);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The base tile height.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#baseTileHeight
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-12-01 19:25:48 +00:00
|
|
|
this.baseTileHeight = GetFastValue(config, 'baseTileHeight', this.tileHeight);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
2020-09-19 08:56:05 +00:00
|
|
|
/**
|
2020-10-02 10:57:37 +00:00
|
|
|
* The layers orientation, necessary to be able to determine a tiles pixelX and pixelY as well as the layers width and height.
|
2020-09-19 08:56:05 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#orientation
|
2020-10-02 11:02:40 +00:00
|
|
|
* @type {Phaser.Types.Tilemaps.TilemapOrientationType}
|
2020-10-02 10:57:37 +00:00
|
|
|
* @since 3.50.0
|
2020-09-19 08:56:05 +00:00
|
|
|
*/
|
|
|
|
this.orientation = GetFastValue(config, 'orientation', CONST.ORTHOGONAL);
|
|
|
|
|
2018-02-07 23:40:59 +00:00
|
|
|
/**
|
2019-01-23 19:30:08 +00:00
|
|
|
* The width in pixels of the entire layer.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#widthInPixels
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-12-01 19:25:48 +00:00
|
|
|
this.widthInPixels = GetFastValue(config, 'widthInPixels', this.width * this.baseTileWidth);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2019-01-23 19:30:08 +00:00
|
|
|
* The height in pixels of the entire layer.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#heightInPixels
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-12-01 19:25:48 +00:00
|
|
|
this.heightInPixels = GetFastValue(config, 'heightInPixels', this.height * this.baseTileHeight);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* The alpha value of the layer.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#alpha
|
2018-06-26 22:19:14 +00:00
|
|
|
* @type {number}
|
2018-02-07 23:40:59 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.alpha = GetFastValue(config, 'alpha', 1);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* Is the layer visible or not?
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#visible
|
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.visible = GetFastValue(config, 'visible', true);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2019-01-23 19:30:08 +00:00
|
|
|
* Layer specific properties (can be specified in Tiled)
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#properties
|
2020-02-05 03:47:22 +00:00
|
|
|
* @type {object[]}
|
2018-02-07 23:40:59 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2020-02-05 03:47:22 +00:00
|
|
|
this.properties = GetFastValue(config, 'properties', []);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* Tile ID index map.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#indexes
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.indexes = GetFastValue(config, 'indexes', []);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* Tile Collision ID index map.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#collideIndexes
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-22 01:13:43 +00:00
|
|
|
this.collideIndexes = GetFastValue(config, 'collideIndexes', []);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* An array of callbacks.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#callbacks
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.callbacks = GetFastValue(config, 'callbacks', []);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* An array of physics bodies.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#bodies
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.bodies = GetFastValue(config, 'bodies', []);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* An array of the tile data indexes.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#data
|
2019-12-23 20:57:58 +00:00
|
|
|
* @type {Phaser.Tilemaps.Tile[][]}
|
2018-02-07 23:40:59 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.data = GetFastValue(config, 'data', []);
|
2018-02-07 23:40:59 +00:00
|
|
|
|
|
|
|
/**
|
2020-04-27 15:13:40 +00:00
|
|
|
* A reference to the Tilemap layer that owns this data.
|
2018-03-20 15:11:33 +00:00
|
|
|
*
|
2018-02-07 23:40:59 +00:00
|
|
|
* @name Phaser.Tilemaps.LayerData#tilemapLayer
|
2020-10-12 10:40:40 +00:00
|
|
|
* @type {Phaser.Tilemaps.TilemapLayer}
|
2018-02-07 23:40:59 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-17 19:16:39 +00:00
|
|
|
this.tilemapLayer = GetFastValue(config, 'tilemapLayer', null);
|
2020-10-02 10:57:37 +00:00
|
|
|
|
2020-09-19 08:56:05 +00:00
|
|
|
/**
|
|
|
|
* The length of the horizontal sides of the hexagon.
|
2020-10-02 10:57:37 +00:00
|
|
|
* Only used for hexagonal orientation Tilemaps.
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.LayerData#hexSideLength
|
2020-11-23 10:22:13 +00:00
|
|
|
* @type {number}
|
2020-10-02 10:57:37 +00:00
|
|
|
* @since 3.50.0
|
2020-09-19 08:56:05 +00:00
|
|
|
*/
|
|
|
|
this.hexSideLength = GetFastValue(config, 'hexSideLength', 0);
|
2017-11-17 19:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = LayerData;
|