@flighthq/tilemap-formats 0.2.0 → 0.2.1-next.410.a23f189

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/tilemap-formats",
3
- "version": "0.2.0",
3
+ "version": "0.2.1-next.410.a23f189",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/flighthq/flight.git",
@@ -32,9 +32,9 @@
32
32
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
33
33
  },
34
34
  "dependencies": {
35
- "@flighthq/sprite": "0.2.0",
36
- "@flighthq/types": "0.2.0",
37
- "@flighthq/xml": "0.2.0"
35
+ "@flighthq/sprite": "0.2.1-next.410.a23f189",
36
+ "@flighthq/types": "0.2.1-next.410.a23f189",
37
+ "@flighthq/xml": "0.2.1-next.410.a23f189"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@flighthq/tileset": "*",
@@ -130,6 +130,150 @@ describe('parseTiledTmj', () => {
130
130
  expect(Array.from(decodedLayer.data)).toEqual([1, 5, 2147483649, 6]);
131
131
  });
132
132
 
133
+ it('parses a group layer and its nested children', () => {
134
+ const tmj = JSON.stringify({
135
+ height: 2,
136
+ layers: [
137
+ {
138
+ id: 1,
139
+ name: 'top',
140
+ type: 'group',
141
+ layers: [
142
+ { data: [1, 2, 3, 4], height: 2, id: 2, name: 'inner-tiles', type: 'tilelayer', width: 2 },
143
+ { id: 3, image: 'bg.png', name: 'inner-image', type: 'imagelayer' },
144
+ ],
145
+ },
146
+ ],
147
+ tileheight: 32,
148
+ tilewidth: 32,
149
+ type: 'map',
150
+ version: '1.10',
151
+ width: 2,
152
+ });
153
+ const map = parseTiledTmj(tmj)!;
154
+ expect(map.layers).toHaveLength(1);
155
+ const group = map.layers[0];
156
+ if (group.type !== 'group') throw new Error('expected a group layer');
157
+ expect(group.name).toBe('top');
158
+ expect(group.layers).toHaveLength(2);
159
+
160
+ const tileChild = group.layers[0];
161
+ if (tileChild.type !== 'tilelayer') throw new Error('expected a tile layer');
162
+ expect(tileChild.name).toBe('inner-tiles');
163
+ expect(Array.from(tileChild.data)).toEqual([1, 2, 3, 4]);
164
+
165
+ const imageChild = group.layers[1];
166
+ if (imageChild.type !== 'imagelayer') throw new Error('expected an image layer');
167
+ expect(imageChild.name).toBe('inner-image');
168
+ expect(imageChild.image).toBe('bg.png');
169
+ });
170
+
171
+ it('parses a multi-tileset map with two tilesets at different firstgid values', () => {
172
+ const tmj = JSON.stringify({
173
+ height: 1,
174
+ layers: [{ data: [1, 5], height: 1, id: 1, name: 'g', type: 'tilelayer', width: 2 }],
175
+ tileheight: 32,
176
+ tilesets: [
177
+ {
178
+ columns: 2,
179
+ firstgid: 1,
180
+ image: 'terrain.png',
181
+ imageheight: 64,
182
+ imagewidth: 64,
183
+ name: 'terrain',
184
+ tilecount: 4,
185
+ tileheight: 32,
186
+ tilewidth: 32,
187
+ },
188
+ {
189
+ columns: 3,
190
+ firstgid: 5,
191
+ image: 'items.png',
192
+ imageheight: 64,
193
+ imagewidth: 96,
194
+ name: 'items',
195
+ tilecount: 6,
196
+ tileheight: 32,
197
+ tilewidth: 32,
198
+ },
199
+ ],
200
+ tilewidth: 32,
201
+ type: 'map',
202
+ version: '1.10',
203
+ width: 2,
204
+ });
205
+ const map = parseTiledTmj(tmj)!;
206
+ expect(map.tilesets).toHaveLength(2);
207
+ expect(map.tilesets[0].firstGid).toBe(1);
208
+ expect(map.tilesets[0].tileset!.name).toBe('terrain');
209
+ expect(map.tilesets[1].firstGid).toBe(5);
210
+ expect(map.tilesets[1].tileset!.name).toBe('items');
211
+ expect(map.tilesets[1].tileset!.columns).toBe(3);
212
+ });
213
+
214
+ it('parses an object group with ellipse and polygon objects', () => {
215
+ const tmj = JSON.stringify({
216
+ height: 1,
217
+ layers: [
218
+ {
219
+ id: 1,
220
+ name: 'objects',
221
+ objects: [
222
+ { ellipse: true, height: 40, id: 1, name: 'circle', type: 'trigger', width: 40, x: 10, y: 20 },
223
+ {
224
+ height: 0,
225
+ id: 2,
226
+ name: 'region',
227
+ polygon: [
228
+ { x: 0, y: 0 },
229
+ { x: 64, y: 0 },
230
+ { x: 64, y: 64 },
231
+ { x: 0, y: 64 },
232
+ ],
233
+ type: 'zone',
234
+ width: 0,
235
+ x: 100,
236
+ y: 200,
237
+ },
238
+ ],
239
+ type: 'objectgroup',
240
+ },
241
+ ],
242
+ tileheight: 32,
243
+ tilewidth: 32,
244
+ type: 'map',
245
+ version: '1.10',
246
+ width: 1,
247
+ });
248
+ const map = parseTiledTmj(tmj)!;
249
+ const layer = map.layers[0];
250
+ if (layer.type !== 'objectgroup') throw new Error('expected an object group');
251
+ expect(layer.objects).toHaveLength(2);
252
+
253
+ const ellipseObj = layer.objects[0];
254
+ expect(ellipseObj.ellipse).toBe(true);
255
+ expect(ellipseObj.name).toBe('circle');
256
+ expect(ellipseObj.type).toBe('trigger');
257
+ expect(ellipseObj.width).toBe(40);
258
+ expect(ellipseObj.height).toBe(40);
259
+ expect(ellipseObj.x).toBe(10);
260
+ expect(ellipseObj.y).toBe(20);
261
+ expect(ellipseObj.polygon).toBeNull();
262
+
263
+ const polygonObj = layer.objects[1];
264
+ expect(polygonObj.ellipse).toBe(false);
265
+ expect(polygonObj.name).toBe('region');
266
+ expect(polygonObj.type).toBe('zone');
267
+ expect(polygonObj.x).toBe(100);
268
+ expect(polygonObj.y).toBe(200);
269
+ expect(polygonObj.polygon).toEqual([
270
+ { x: 0, y: 0 },
271
+ { x: 64, y: 0 },
272
+ { x: 64, y: 64 },
273
+ { x: 0, y: 64 },
274
+ ]);
275
+ });
276
+
133
277
  it('returns null on malformed JSON', () => {
134
278
  expect(parseTiledTmj('{ not json')).toBeNull();
135
279
  expect(parseTiledTmj('42')).toBeNull();