forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayerData.js
More file actions
234 lines (206 loc) · 6.58 KB
/
Copy pathLayerData.js
File metadata and controls
234 lines (206 loc) · 6.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
* @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 CONST = require('../const/ORIENTATION_CONST');
var GetFastValue = require('../../utils/object/GetFastValue');
/**
* @classdesc
* A class for representing data about about a layer in a map. Maps are parsed from CSV, Tiled,
* etc. into this format. Tilemap and TilemapLayer objects 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
*
* @param {Phaser.Types.Tilemaps.LayerDataConfig} [config] - The Layer Data configuration object.
*/
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');
/**
* The x offset of where to draw from the top left.
*
* @name Phaser.Tilemaps.LayerData#x
* @type {number}
* @since 3.0.0
*/
this.x = GetFastValue(config, 'x', 0);
/**
* The y offset of where to draw from the top left.
*
* @name Phaser.Tilemaps.LayerData#y
* @type {number}
* @since 3.0.0
*/
this.y = GetFastValue(config, 'y', 0);
/**
* The width of the layer in tiles.
*
* @name Phaser.Tilemaps.LayerData#width
* @type {number}
* @since 3.0.0
*/
this.width = GetFastValue(config, 'width', 0);
/**
* The height of the layer in tiles.
*
* @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);
/**
* The base tile width.
*
* @name Phaser.Tilemaps.LayerData#baseTileWidth
* @type {number}
* @since 3.0.0
*/
this.baseTileWidth = GetFastValue(config, 'baseTileWidth', this.tileWidth);
/**
* The base tile height.
*
* @name Phaser.Tilemaps.LayerData#baseTileHeight
* @type {number}
* @since 3.0.0
*/
this.baseTileHeight = GetFastValue(config, 'baseTileHeight', this.tileHeight);
/**
* The layers orientation, necessary to be able to determine a tiles pixelX and pixelY as well as the layers width and height.
*
* @name Phaser.Tilemaps.LayerData#orientation
* @type {Phaser.Tilemaps.OrientationType}
* @since 3.50.0
*/
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);
/**
* The alpha value of the layer.
*
* @name Phaser.Tilemaps.LayerData#alpha
* @type {number}
* @since 3.0.0
*/
this.alpha = GetFastValue(config, 'alpha', 1);
/**
* Is the layer visible or not?
*
* @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
* @type {object[]}
* @since 3.0.0
*/
this.properties = GetFastValue(config, 'properties', []);
/**
* Tile ID index map.
*
* @name Phaser.Tilemaps.LayerData#indexes
* @type {array}
* @since 3.0.0
*/
this.indexes = GetFastValue(config, 'indexes', []);
/**
* Tile Collision ID index map.
*
* @name Phaser.Tilemaps.LayerData#collideIndexes
* @type {array}
* @since 3.0.0
*/
this.collideIndexes = GetFastValue(config, 'collideIndexes', []);
/**
* An array of callbacks.
*
* @name Phaser.Tilemaps.LayerData#callbacks
* @type {array}
* @since 3.0.0
*/
this.callbacks = GetFastValue(config, 'callbacks', []);
/**
* An array of physics bodies.
*
* @name Phaser.Tilemaps.LayerData#bodies
* @type {array}
* @since 3.0.0
*/
this.bodies = GetFastValue(config, 'bodies', []);
/**
* An array of the tile data indexes.
*
* @name Phaser.Tilemaps.LayerData#data
* @type {Phaser.Tilemaps.Tile[][]}
* @since 3.0.0
*/
this.data = GetFastValue(config, 'data', []);
/**
* A reference to the Tilemap layer that owns this data.
*
* @name Phaser.Tilemaps.LayerData#tilemapLayer
* @type {Phaser.Tilemaps.TilemapLayer}
* @since 3.0.0
*/
this.tilemapLayer = GetFastValue(config, 'tilemapLayer', null);
/**
* The length of the horizontal sides of the hexagon.
* Only used for hexagonal orientation Tilemaps.
*
* @name Phaser.Tilemaps.LayerData#hexSideLength
* @type {number}
* @since 3.50.0
*/
this.hexSideLength = GetFastValue(config, 'hexSideLength', 0);
}
});
module.exports = LayerData;