parse-tmx 1.0.21 → 1.0.25
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/dist/index.js +10 -13
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var shared = require('@esposter/shared');
|
|
4
|
-
var node_zlib = require('node:zlib');
|
|
1
|
+
import { exhaustiveGuard, InvalidOperationError, Operation, parseXmlString } from 'esposter-shared';
|
|
2
|
+
import { gunzip, inflate } from 'node:zlib';
|
|
5
3
|
|
|
6
4
|
var TMXNodeType;
|
|
7
5
|
(function (TMXNodeType) {
|
|
@@ -180,7 +178,7 @@ const parseTileLayer = async (node, expectedCount, translateFlips) => {
|
|
|
180
178
|
case Compression.Gzip:
|
|
181
179
|
case Compression.Zlib:
|
|
182
180
|
{
|
|
183
|
-
const decompress = compression === Compression.Gzip ?
|
|
181
|
+
const decompress = compression === Compression.Gzip ? gunzip : inflate;
|
|
184
182
|
layer.data = await new Promise((resolve, reject) => {
|
|
185
183
|
decompress(buffer, (err, buf) => {
|
|
186
184
|
if (err)
|
|
@@ -195,12 +193,12 @@ const parseTileLayer = async (node, expectedCount, translateFlips) => {
|
|
|
195
193
|
layer.data = unpackTileBytes(buffer, expectedCount);
|
|
196
194
|
break;
|
|
197
195
|
default:
|
|
198
|
-
|
|
196
|
+
exhaustiveGuard(compression);
|
|
199
197
|
}
|
|
200
198
|
break;
|
|
201
199
|
}
|
|
202
200
|
default:
|
|
203
|
-
|
|
201
|
+
exhaustiveGuard(encoding);
|
|
204
202
|
}
|
|
205
203
|
}
|
|
206
204
|
if (translateFlips) {
|
|
@@ -225,7 +223,7 @@ const parseNode = (node, expectedCount, translateFlips) => {
|
|
|
225
223
|
case TMXNodeType.Objectgroup:
|
|
226
224
|
return parseLayer(node);
|
|
227
225
|
default:
|
|
228
|
-
throw new
|
|
226
|
+
throw new InvalidOperationError(Operation.Read, parseNode.name, tmxNodeType);
|
|
229
227
|
}
|
|
230
228
|
};
|
|
231
229
|
|
|
@@ -257,13 +255,13 @@ const parseTileset = (node) => {
|
|
|
257
255
|
const tiles = tile?.map((t) => parseTile(t)) ?? [];
|
|
258
256
|
return { ...$, image, tiles };
|
|
259
257
|
}
|
|
260
|
-
throw new
|
|
258
|
+
throw new InvalidOperationError(Operation.Read, parseTileset.name, $.name);
|
|
261
259
|
};
|
|
262
260
|
|
|
263
261
|
// We will try and match phaser's transform when exporting tmx => json tilemaps
|
|
264
262
|
// but also support extra functionality like using external tilesets
|
|
265
263
|
const parseTmx = async (xmlString, translateFlips = false) => {
|
|
266
|
-
const { map: { $, $$ }, } = (await
|
|
264
|
+
const { map: { $, $$ }, } = (await parseXmlString(xmlString));
|
|
267
265
|
const map = new TMXMapParsed(structuredClone($));
|
|
268
266
|
const expectedCount = map.width * map.height * 4;
|
|
269
267
|
await Promise.all($$.map(async (node) => {
|
|
@@ -299,11 +297,10 @@ const parseTmx = async (xmlString, translateFlips = false) => {
|
|
|
299
297
|
case TMXNodeType.Property:
|
|
300
298
|
break;
|
|
301
299
|
default:
|
|
302
|
-
|
|
300
|
+
exhaustiveGuard(tmxNodeType);
|
|
303
301
|
}
|
|
304
302
|
}));
|
|
305
303
|
return { map };
|
|
306
304
|
};
|
|
307
305
|
|
|
308
|
-
|
|
309
|
-
exports.parseTmx = parseTmx;
|
|
306
|
+
export { parseTileset, parseTmx };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parse-tmx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"description": "A parser for tmx",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/Esposter/Esposter#readme",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"types:gen": "dts-bundle-generator -o dist/index.d.ts src/index.ts"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"esposter-shared": "1.0.
|
|
30
|
+
"esposter-shared": "1.0.25"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"rollup": "^4.17.2",
|
|
37
37
|
"typescript": "^5.4.5"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "a7b739cdc8f4a0db0256ce980a15906445bd019d"
|
|
40
40
|
}
|