@flighthq/tilemap-formats 0.3.0-next.906.07cea63 → 0.3.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiledProject.d.ts","sourceRoot":"","sources":["../src/tiledProject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"tiledProject.d.ts","sourceRoot":"","sources":["../src/tiledProject.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAmB5F,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,EACvB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,oBAAoB,GACnC,WAAW,EAAE,GAAG,IAAI,CAgDtB"}
|
package/dist/tiledProject.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createTilemapData } from '@flighthq/
|
|
1
|
+
import { createTilemapData } from '@flighthq/tilemap/contract';
|
|
2
2
|
import { decodeTiledGid, getTiledTilesetRefForGid } from './tiledGid';
|
|
3
3
|
// Projects one Tiled tile layer into runtime `TilemapData`, split by tileset. A Flight `Tilemap`
|
|
4
4
|
// batches a single tileset per draw, so a layer that draws from N tilesets becomes N single-tileset
|
|
@@ -7,7 +7,7 @@ import { decodeTiledGid, getTiledTilesetRefForGid } from './tiledGid';
|
|
|
7
7
|
// 1-element array.
|
|
8
8
|
//
|
|
9
9
|
// Each cell's raw GID is decoded to a global tile id; its owning `TiledTilesetRef` is found by
|
|
10
|
-
// firstGid range and resolved to
|
|
10
|
+
// firstGid range and resolved to runtime atlas/layout data via `resolveTileset`. The stored tile is the
|
|
11
11
|
// local id (`globalTileId - firstGid`). Flip flags are decoded for range/identity purposes but are
|
|
12
12
|
// NOT carried into the grid: `TilemapData` has no per-tile flip slot, so flips survive only in the
|
|
13
13
|
// faithful `TiledMap` document, not in the projected tilemap.
|
|
@@ -34,15 +34,15 @@ export function buildTilemapLayersFromTiled(map, layerIndex, resolveTileset) {
|
|
|
34
34
|
continue;
|
|
35
35
|
let group = byFirstGid.get(ref.firstGid);
|
|
36
36
|
if (group === undefined) {
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
37
|
+
const layout = resolveTileset(ref);
|
|
38
|
+
if (layout === null) {
|
|
39
39
|
// Remember the failure so its tiles stay empty without re-resolving each cell.
|
|
40
40
|
byFirstGid.set(ref.firstGid, null);
|
|
41
41
|
group = null;
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
44
|
anyResolved = true;
|
|
45
|
-
group = { firstGid: ref.firstGid, tiles: new Int16Array(cellCount).fill(-1)
|
|
45
|
+
group = { firstGid: ref.firstGid, layout, tiles: new Int16Array(cellCount).fill(-1) };
|
|
46
46
|
byFirstGid.set(ref.firstGid, group);
|
|
47
47
|
groups.push(group);
|
|
48
48
|
}
|
|
@@ -53,6 +53,13 @@ export function buildTilemapLayersFromTiled(map, layerIndex, resolveTileset) {
|
|
|
53
53
|
}
|
|
54
54
|
if (!anyResolved)
|
|
55
55
|
return null;
|
|
56
|
-
return groups.map((group) => createTilemapData({
|
|
56
|
+
return groups.map((group) => createTilemapData({
|
|
57
|
+
atlas: group.layout.atlas,
|
|
58
|
+
columns: width,
|
|
59
|
+
rows: height,
|
|
60
|
+
tileHeight: group.layout.tileHeight,
|
|
61
|
+
tileWidth: group.layout.tileWidth,
|
|
62
|
+
tiles: group.tiles,
|
|
63
|
+
}));
|
|
57
64
|
}
|
|
58
65
|
//# sourceMappingURL=tiledProject.js.map
|
package/dist/tiledProject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiledProject.js","sourceRoot":"","sources":["../src/tiledProject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAA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CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/tilemap-formats",
|
|
3
|
-
"version": "0.3.0
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"author": "Joshua Granick and other contributors",
|
|
5
|
+
"license": "MIT",
|
|
4
6
|
"repository": {
|
|
5
7
|
"type": "git",
|
|
6
8
|
"url": "https://github.com/flighthq/flight.git",
|
|
@@ -36,12 +38,11 @@
|
|
|
36
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
|
-
"@flighthq/
|
|
40
|
-
"@flighthq/types": "0.3.0
|
|
41
|
-
"@flighthq/xml": "0.3.0
|
|
41
|
+
"@flighthq/tilemap": "0.3.0",
|
|
42
|
+
"@flighthq/types": "0.3.0",
|
|
43
|
+
"@flighthq/xml": "0.3.0"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
|
-
"@flighthq/tileset": "*",
|
|
45
46
|
"typescript": "^5.3.0"
|
|
46
47
|
},
|
|
47
48
|
"description": "Tiled (TMX/TMJ/TSX/TSJ) tilemap import/export codec — faithful TiledMap document plus TilemapData projection",
|
package/src/tiledProject.test.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createTileset } from '@flighthq/tileset/contract';
|
|
2
1
|
import type { TiledTilesetResolver } from '@flighthq/types/contract';
|
|
3
2
|
import { describe, expect, it } from 'vitest';
|
|
4
3
|
|
|
@@ -16,8 +15,8 @@ function mapWithLayerData(data: string): ReturnType<typeof parseTiledTmx> {
|
|
|
16
15
|
);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
const tilesetA =
|
|
20
|
-
const tilesetB =
|
|
18
|
+
const tilesetA = { atlas: null, tileHeight: 16, tileWidth: 16 };
|
|
19
|
+
const tilesetB = { atlas: null, tileHeight: 16, tileWidth: 16 };
|
|
21
20
|
|
|
22
21
|
const resolve: TiledTilesetResolver = (ref) => {
|
|
23
22
|
if (ref.firstGid === 1) return tilesetA;
|
|
@@ -31,11 +30,11 @@ describe('buildTilemapLayersFromTiled', () => {
|
|
|
31
30
|
const result = buildTilemapLayersFromTiled(map, 0, resolve)!;
|
|
32
31
|
expect(result).toHaveLength(2);
|
|
33
32
|
|
|
34
|
-
expect(result[0]
|
|
33
|
+
expect(result[0]).toMatchObject(tilesetA);
|
|
35
34
|
// Cell 2's GID has the flip bit set; its tile id (1) still resolves to tileset A as local id 0.
|
|
36
35
|
expect(Array.from(result[0].tiles)).toEqual([0, -1, 0, -1]);
|
|
37
36
|
|
|
38
|
-
expect(result[1]
|
|
37
|
+
expect(result[1]).toMatchObject(tilesetB);
|
|
39
38
|
expect(Array.from(result[1].tiles)).toEqual([-1, 0, -1, 1]);
|
|
40
39
|
expect(result[1].columns).toBe(2);
|
|
41
40
|
expect(result[1].rows).toBe(2);
|
|
@@ -45,7 +44,7 @@ describe('buildTilemapLayersFromTiled', () => {
|
|
|
45
44
|
const map = mapWithLayerData('1,2,1,2')!;
|
|
46
45
|
const result = buildTilemapLayersFromTiled(map, 0, resolve)!;
|
|
47
46
|
expect(result).toHaveLength(1);
|
|
48
|
-
expect(result[0]
|
|
47
|
+
expect(result[0]).toMatchObject(tilesetA);
|
|
49
48
|
expect(Array.from(result[0].tiles)).toEqual([0, 1, 0, 1]);
|
|
50
49
|
});
|
|
51
50
|
|
|
@@ -54,7 +53,7 @@ describe('buildTilemapLayersFromTiled', () => {
|
|
|
54
53
|
const onlyA: TiledTilesetResolver = (ref) => (ref.firstGid === 1 ? tilesetA : null);
|
|
55
54
|
const result = buildTilemapLayersFromTiled(map, 0, onlyA)!;
|
|
56
55
|
expect(result).toHaveLength(1);
|
|
57
|
-
expect(result[0]
|
|
56
|
+
expect(result[0]).toMatchObject(tilesetA);
|
|
58
57
|
expect(Array.from(result[0].tiles)).toEqual([0, -1, 0, -1]);
|
|
59
58
|
});
|
|
60
59
|
|