parse-tmx 1.0.10 → 1.0.21
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/README.md +106 -0
- package/package.json +9 -4
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# parse-tmx [](https://www.npmjs.org/package/parse-tmx)
|
|
2
|
+
|
|
3
|
+
Inspired by [tmx-map-parser](https://github.com/praghus/tmx-map-parser).
|
|
4
|
+
A parser for [Tiled Map Editor](http://www.mapeditor.org/) \*.tmx files.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm i parse-tmx
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
The basic implementation:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { parseTmx } from "parse-tmx";
|
|
18
|
+
// The *.tmx file can be loaded as a string or URL encoded data.
|
|
19
|
+
// for Webpack use 'url-loader' plugin, for Rollup it can be '@rollup/plugin-url'
|
|
20
|
+
import tmxFile from "map.tmx";
|
|
21
|
+
|
|
22
|
+
// Translates the tile flips in the layer data (default: false)
|
|
23
|
+
const translateFlips = true;
|
|
24
|
+
|
|
25
|
+
const loadMap = async () => {
|
|
26
|
+
const data = await parseTmx(tmxFile, translateFlips);
|
|
27
|
+
console.log(data);
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Important
|
|
32
|
+
|
|
33
|
+
Parser only supports embedded tilesets. At the moment, external tilesets are not supported!
|
|
34
|
+
|
|
35
|
+
## Example data
|
|
36
|
+
|
|
37
|
+
[TMX Map Format documentation](https://doc.mapeditor.org/en/stable/reference/tmx-map-format/)
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
{
|
|
41
|
+
tiledversion: "1.8.0",
|
|
42
|
+
tilewidth: 16,
|
|
43
|
+
tileheight: 16,
|
|
44
|
+
version: 1.8,
|
|
45
|
+
width: 512,
|
|
46
|
+
height: 128,
|
|
47
|
+
infinite: 0,
|
|
48
|
+
nextlayerid: 5,
|
|
49
|
+
nextobjectid: 165,
|
|
50
|
+
orientation: "orthogonal",
|
|
51
|
+
renderorder: "right-down",
|
|
52
|
+
properties: {
|
|
53
|
+
property1: 'value',
|
|
54
|
+
property2: 0.5
|
|
55
|
+
},
|
|
56
|
+
layers: [{
|
|
57
|
+
id: 1,
|
|
58
|
+
name: "layer name",
|
|
59
|
+
type: "layer",
|
|
60
|
+
visible: 1,
|
|
61
|
+
data: [0, 1, 1, 10, 10, 10, 1, 1, 0, 0, 0, 0, …],
|
|
62
|
+
// When the translateFlips parameter is enabled
|
|
63
|
+
flips: [
|
|
64
|
+
{H: false, V: false, D: false},
|
|
65
|
+
{H: true, V: false, D: true},
|
|
66
|
+
{H: false, V: false, D: false},
|
|
67
|
+
{…}
|
|
68
|
+
],
|
|
69
|
+
width: 512,
|
|
70
|
+
height: 128,
|
|
71
|
+
opacity: 0.77,
|
|
72
|
+
properties: {
|
|
73
|
+
property1: 'value',
|
|
74
|
+
property2: false
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
id: 2,
|
|
78
|
+
name: "objects",
|
|
79
|
+
type: "objectgroup",
|
|
80
|
+
visible: 1,
|
|
81
|
+
objects: [{…}, {…}, {…}],
|
|
82
|
+
properties: {
|
|
83
|
+
property1: 'value',
|
|
84
|
+
property2: false
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
…
|
|
88
|
+
}],
|
|
89
|
+
tilesets: [{
|
|
90
|
+
columns: 32,
|
|
91
|
+
firstgid: 1,
|
|
92
|
+
image: {source: "tiles.png", width: 512, height: 512},
|
|
93
|
+
name: "tiles",
|
|
94
|
+
tilecount: 1024,
|
|
95
|
+
tilewidth: 16,
|
|
96
|
+
tileheight: 16,
|
|
97
|
+
tiles: [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
|
|
98
|
+
}, {
|
|
99
|
+
…
|
|
100
|
+
}]
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
[Apache-2.0 licensed](../../LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "parse-tmx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"description": "A parser for tmx",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"homepage": "https://github.com/Esposter/Esposter#readme",
|
|
@@ -8,7 +8,12 @@
|
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
|
-
"dist"
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"tmx",
|
|
16
|
+
"parser"
|
|
12
17
|
],
|
|
13
18
|
"repository": {
|
|
14
19
|
"type": "git",
|
|
@@ -22,7 +27,7 @@
|
|
|
22
27
|
"types:gen": "dts-bundle-generator -o dist/index.d.ts src/index.ts"
|
|
23
28
|
},
|
|
24
29
|
"dependencies": {
|
|
25
|
-
"
|
|
30
|
+
"esposter-shared": "1.0.21"
|
|
26
31
|
},
|
|
27
32
|
"devDependencies": {
|
|
28
33
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
@@ -31,5 +36,5 @@
|
|
|
31
36
|
"rollup": "^4.17.2",
|
|
32
37
|
"typescript": "^5.4.5"
|
|
33
38
|
},
|
|
34
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "bb22a744b9d3dbb423277ed1484026d1ee8be34e"
|
|
35
40
|
}
|