forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapData.js
More file actions
219 lines (193 loc) · 6.09 KB
/
Copy pathMapData.js
File metadata and controls
219 lines (193 loc) · 6.09 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
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = require('../../utils/Class');
var GetFastValue = require('../../utils/object/GetFastValue');
/**
* @classdesc
* A class for representing data about a map. Maps are parsed from CSV, Tiled, etc. into this
* format. A Tilemap object get a copy of this data and then unpacks the needed properties into
* itself.
*
* @class MapData
* @memberof Phaser.Tilemaps
* @constructor
* @since 3.0.0
*
* @param {Phaser.Types.Tilemaps.MapDataConfig} [config] - The Map configuration object.
*/
var MapData = new Class({
initialize:
function MapData (config)
{
if (config === undefined) { config = {}; }
/**
* The key in the Phaser cache that corresponds to the loaded tilemap data.
*
* @name Phaser.Tilemaps.MapData#name
* @type {string}
* @since 3.0.0
*/
this.name = GetFastValue(config, 'name', 'map');
/**
* The width of the entire tilemap.
*
* @name Phaser.Tilemaps.MapData#width
* @type {number}
* @since 3.0.0
*/
this.width = GetFastValue(config, 'width', 0);
/**
* The height of the entire tilemap.
*
* @name Phaser.Tilemaps.MapData#height
* @type {number}
* @since 3.0.0
*/
this.height = GetFastValue(config, 'height', 0);
/**
* If the map is infinite or not.
*
* @name Phaser.Tilemaps.MapData#infinite
* @type {boolean}
* @since 3.17.0
*/
this.infinite = GetFastValue(config, 'infinite', false);
/**
* The width of the tiles.
*
* @name Phaser.Tilemaps.MapData#tileWidth
* @type {number}
* @since 3.0.0
*/
this.tileWidth = GetFastValue(config, 'tileWidth', 0);
/**
* The height of the tiles.
*
* @name Phaser.Tilemaps.MapData#tileHeight
* @type {number}
* @since 3.0.0
*/
this.tileHeight = GetFastValue(config, 'tileHeight', 0);
/**
* The width in pixels of the entire tilemap.
*
* @name Phaser.Tilemaps.MapData#widthInPixels
* @type {number}
* @since 3.0.0
*/
this.widthInPixels = GetFastValue(config, 'widthInPixels', this.width * this.tileWidth);
/**
* The height in pixels of the entire tilemap.
*
* @name Phaser.Tilemaps.MapData#heightInPixels
* @type {number}
* @since 3.0.0
*/
this.heightInPixels = GetFastValue(config, 'heightInPixels', this.height * this.tileHeight);
/**
* [description]
*
* @name Phaser.Tilemaps.MapData#format
* @type {integer}
* @since 3.0.0
*/
this.format = GetFastValue(config, 'format', null);
/**
* The orientation of the map data (i.e. orthogonal, isometric, hexagonal), default 'orthogonal'.
*
* @name Phaser.Tilemaps.MapData#orientation
* @type {string}
* @since 3.0.0
*/
this.orientation = GetFastValue(config, 'orientation', 'orthogonal');
/**
* Determines the draw order of tilemap. Default is right-down
*
* 0, or 'right-down'
* 1, or 'left-down'
* 2, or 'right-up'
* 3, or 'left-up'
*
* @name Phaser.Tilemaps.MapData#renderOrder
* @type {string}
* @since 3.12.0
*/
this.renderOrder = GetFastValue(config, 'renderOrder', 'right-down');
/**
* The version of the map data (as specified in Tiled).
*
* @name Phaser.Tilemaps.MapData#version
* @type {string}
* @since 3.0.0
*/
this.version = GetFastValue(config, 'version', '1');
/**
* Map specific properties (can be specified in Tiled)
*
* @name Phaser.Tilemaps.MapData#properties
* @type {object}
* @since 3.0.0
*/
this.properties = GetFastValue(config, 'properties', {});
/**
* An array with all the layers configured to the MapData.
*
* @name Phaser.Tilemaps.MapData#layers
* @type {(Phaser.Tilemaps.LayerData[]|Phaser.Tilemaps.ObjectLayer)}
* @since 3.0.0
*/
this.layers = GetFastValue(config, 'layers', []);
/**
* An array of Tiled Image Layers.
*
* @name Phaser.Tilemaps.MapData#images
* @type {array}
* @since 3.0.0
*/
this.images = GetFastValue(config, 'images', []);
/**
* An object of Tiled Object Layers.
*
* @name Phaser.Tilemaps.MapData#objects
* @type {object}
* @since 3.0.0
*/
this.objects = GetFastValue(config, 'objects', {});
/**
* An object of collision data. Must be created as physics object or will return undefined.
*
* @name Phaser.Tilemaps.MapData#collision
* @type {object}
* @since 3.0.0
*/
this.collision = GetFastValue(config, 'collision', {});
/**
* An array of Tilesets.
*
* @name Phaser.Tilemaps.MapData#tilesets
* @type {Phaser.Tilemaps.Tileset[]}
* @since 3.0.0
*/
this.tilesets = GetFastValue(config, 'tilesets', []);
/**
* The collection of images the map uses(specified in Tiled)
*
* @name Phaser.Tilemaps.MapData#imageCollections
* @type {array}
* @since 3.0.0
*/
this.imageCollections = GetFastValue(config, 'imageCollections', []);
/**
* [description]
*
* @name Phaser.Tilemaps.MapData#tiles
* @type {array}
* @since 3.0.0
*/
this.tiles = GetFastValue(config, 'tiles', []);
}
});
module.exports = MapData;