phaser/src/tilemaps/mapdata/LayerData.js

215 lines
5.4 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2018-02-07 17:10:01 +00:00
var Class = require('../../utils/Class');
var GetFastValue = require('../../utils/object/GetFastValue');
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,
* 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
2018-02-07 23:40:59 +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
*
* @param {object} [config] - [description]
*/
var LayerData = new Class({
initialize:
2017-11-27 13:33:30 +00:00
function LayerData (config)
{
if (config === undefined) { config = {}; }
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.name = GetFastValue(config, 'name', 'layer');
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.x = GetFastValue(config, 'x', 0);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.y = GetFastValue(config, 'y', 0);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.width = GetFastValue(config, 'width', 0);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.height = GetFastValue(config, 'height', 0);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.tileWidth = GetFastValue(config, 'tileWidth', 0);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.tileHeight = GetFastValue(config, 'tileHeight', 0);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.baseTileWidth = GetFastValue(config, 'baseTileWidth', this.tileWidth);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.baseTileHeight = GetFastValue(config, 'baseTileHeight', this.tileHeight);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.widthInPixels = GetFastValue(config, 'widthInPixels', this.width * this.baseTileWidth);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.heightInPixels = GetFastValue(config, 'heightInPixels', this.height * this.baseTileHeight);
2018-02-07 23:40:59 +00:00
/**
* [description]
2018-03-20 15:11:33 +00:00
*
2018-02-07 23:40:59 +00:00
* @name Phaser.Tilemaps.LayerData#alpha
* @type {float}
* @since 3.0.0
*/
this.alpha = GetFastValue(config, 'alpha', 1);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.visible = GetFastValue(config, 'visible', true);
2018-02-07 23:40:59 +00:00
/**
* [description]
2018-03-20 15:11:33 +00:00
*
2018-02-07 23:40:59 +00:00
* @name Phaser.Tilemaps.LayerData#properties
* @type {object}
* @since 3.0.0
*/
this.properties = GetFastValue(config, 'properties', {});
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.indexes = GetFastValue(config, 'indexes', []);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.collideIndexes = GetFastValue(config, 'collideIndexes', []);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.callbacks = GetFastValue(config, 'callbacks', []);
2018-02-07 23:40:59 +00:00
/**
* [description]
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
*/
this.bodies = GetFastValue(config, 'bodies', []);
2018-02-07 23:40:59 +00:00
/**
* [description]
2018-03-20 15:11:33 +00:00
*
2018-02-07 23:40:59 +00:00
* @name Phaser.Tilemaps.LayerData#data
* @type {array}
* @since 3.0.0
*/
this.data = GetFastValue(config, 'data', []);
2018-02-07 23:40:59 +00:00
/**
* [description]
2018-03-20 15:11:33 +00:00
*
2018-02-07 23:40:59 +00:00
* @name Phaser.Tilemaps.LayerData#tilemapLayer
2018-03-20 15:11:33 +00:00
* @type {(Phaser.Tilemaps.DynamicTilemapLayer|Phaser.Tilemaps.StaticTilemapLayer)}
2018-02-07 23:40:59 +00:00
* @since 3.0.0
*/
this.tilemapLayer = GetFastValue(config, 'tilemapLayer', null);
}
});
module.exports = LayerData;