@flare-engine/tilemap 0.2.1 → 0.3.1
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/LICENSE +201 -21
- package/NOTICE +2 -0
- package/README.md +22 -5
- package/dist/index.d.mts +194 -143
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +194 -143
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +442 -389
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +430 -356
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -11
package/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Grzegorz Otto
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -12,16 +12,33 @@ bun add @flare-engine/tilemap
|
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
14
|
import { parseTiled, TilemapRenderer, extractColliders } from '@flare-engine/tilemap';
|
|
15
|
+
import type { SkImageLike } from '@flare-engine/assets';
|
|
16
|
+
import { Camera2D } from '@flare-engine/render';
|
|
15
17
|
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
18
|
+
declare const rawMap: unknown;
|
|
19
|
+
declare const tilesetImage: SkImageLike;
|
|
20
|
+
|
|
21
|
+
const data = parseTiled(rawMap);
|
|
22
|
+
|
|
23
|
+
// renderer takes only the map; images are registered per tileset name
|
|
24
|
+
const renderer = new TilemapRenderer(data);
|
|
25
|
+
renderer.setTilesetImage('terrain', tilesetImage);
|
|
26
|
+
|
|
27
|
+
const camera = new Camera2D();
|
|
28
|
+
camera.setViewport(800, 600);
|
|
29
|
+
|
|
30
|
+
// draw culls to camera bounds; flush owns the actual draw calls
|
|
31
|
+
renderer.draw(camera, (batch) =>
|
|
32
|
+
batch.flush((image, commands) => {
|
|
33
|
+
// hand off image + commands to your Skia drawAtlas bridge
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
19
36
|
|
|
20
37
|
const colliders = extractColliders(data);
|
|
21
38
|
```
|
|
22
39
|
|
|
23
|
-
See [API spec](
|
|
40
|
+
See [API spec](https://github.com/grzott/flare-engine/blob/main/docs/design/api-specs.md#flare-enginetilemap--8kb-gzip).
|
|
24
41
|
|
|
25
42
|
## License
|
|
26
43
|
|
|
27
|
-
|
|
44
|
+
Apache-2.0
|
package/dist/index.d.mts
CHANGED
|
@@ -1,180 +1,198 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { AABBShape } from "@flare-engine/physics";
|
|
2
|
+
import { Camera2D, SpriteBatch } from "@flare-engine/render";
|
|
3
|
+
import { Rect } from "@flare-engine/math";
|
|
4
|
+
import { SkImageLike } from "@flare-engine/assets";
|
|
5
|
+
//#region src/tilemap-data.d.ts
|
|
6
|
+
/** Low 29 bits of a Tiled GID — Tiled stores flip state in the high 3 bits. */
|
|
7
|
+
declare const GID_FLIP_MASK = 536870911;
|
|
8
|
+
/** Flip state encoded in the high bits of a Tiled GID. */
|
|
9
|
+
interface TileFlipFlags {
|
|
10
|
+
horizontal: boolean;
|
|
11
|
+
vertical: boolean;
|
|
12
|
+
diagonal: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Strip the Tiled flip bits from a raw GID, returning the real global tile id. */
|
|
15
|
+
declare function stripGidFlags(gid: number): number;
|
|
16
|
+
/**
|
|
17
|
+
* Decode the Tiled flip bits encoded in the high bits of a raw GID.
|
|
18
|
+
* Note: `gid & 0x80000000` yields a negative Int32 when the bit is set;
|
|
19
|
+
* compare with `!== 0`, not `> 0`.
|
|
20
|
+
*/
|
|
21
|
+
declare function decodeGidFlags(gid: number): TileFlipFlags;
|
|
6
22
|
/** A single tile in a tilemap grid. */
|
|
7
23
|
interface TileData {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
/** Global tile ID (0 = empty). */
|
|
25
|
+
gid: number;
|
|
26
|
+
/** Whether this tile is flagged as solid (for collision). */
|
|
27
|
+
solid: boolean;
|
|
28
|
+
/** Custom properties on the tile. */
|
|
29
|
+
properties: Record<string, unknown>;
|
|
14
30
|
}
|
|
15
31
|
/** A layer of tiles in a grid. */
|
|
16
32
|
interface TileLayer {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
readonly type: 'tile';
|
|
34
|
+
/** Layer name. */
|
|
35
|
+
name: string;
|
|
36
|
+
/** Grid width in tiles. */
|
|
37
|
+
width: number;
|
|
38
|
+
/** Grid height in tiles. */
|
|
39
|
+
height: number;
|
|
40
|
+
/** Flat array of tile GIDs (row-major, length = width * height). */
|
|
41
|
+
tiles: number[];
|
|
42
|
+
/** Visibility flag. */
|
|
43
|
+
visible: boolean;
|
|
44
|
+
/** Opacity (0–1). */
|
|
45
|
+
opacity: number;
|
|
46
|
+
/** Layer offset in pixels. */
|
|
47
|
+
offsetX: number;
|
|
48
|
+
offsetY: number;
|
|
49
|
+
/** Custom properties. */
|
|
50
|
+
properties: Record<string, unknown>;
|
|
35
51
|
}
|
|
36
52
|
/** An object in an object layer. */
|
|
37
53
|
interface MapObject {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
/** Object ID. */
|
|
55
|
+
id: number;
|
|
56
|
+
/** Object name. */
|
|
57
|
+
name: string;
|
|
58
|
+
/** Object type/class. */
|
|
59
|
+
type: string;
|
|
60
|
+
/** Position in pixels. */
|
|
61
|
+
x: number;
|
|
62
|
+
y: number;
|
|
63
|
+
/** Size in pixels. */
|
|
64
|
+
width: number;
|
|
65
|
+
height: number;
|
|
66
|
+
/** Rotation in degrees. */
|
|
67
|
+
rotation: number;
|
|
68
|
+
/** Custom properties. */
|
|
69
|
+
properties: Record<string, unknown>;
|
|
54
70
|
}
|
|
55
71
|
/** A layer of objects. */
|
|
56
72
|
interface ObjectLayer {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
readonly type: 'object';
|
|
74
|
+
/** Layer name. */
|
|
75
|
+
name: string;
|
|
76
|
+
/** Objects in the layer. */
|
|
77
|
+
objects: MapObject[];
|
|
78
|
+
/** Visibility flag. */
|
|
79
|
+
visible: boolean;
|
|
80
|
+
/** Opacity (0–1). */
|
|
81
|
+
opacity: number;
|
|
82
|
+
/** Custom properties. */
|
|
83
|
+
properties: Record<string, unknown>;
|
|
68
84
|
}
|
|
69
85
|
/** Union of layer types. */
|
|
70
86
|
type MapLayer = TileLayer | ObjectLayer;
|
|
71
87
|
/** Information about a tileset used in the map. */
|
|
72
88
|
interface TilesetRef {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
/** First GID in this tileset. */
|
|
90
|
+
firstGid: number;
|
|
91
|
+
/** Tileset name. */
|
|
92
|
+
name: string;
|
|
93
|
+
/** Tile width in pixels. */
|
|
94
|
+
tileWidth: number;
|
|
95
|
+
/** Tile height in pixels. */
|
|
96
|
+
tileHeight: number;
|
|
97
|
+
/** Number of columns in the tileset image. */
|
|
98
|
+
columns: number;
|
|
99
|
+
/** Total tile count. */
|
|
100
|
+
tileCount: number;
|
|
101
|
+
/** Image source path (may need resolving). */
|
|
102
|
+
image: string;
|
|
103
|
+
/** Image width in pixels. */
|
|
104
|
+
imageWidth: number;
|
|
105
|
+
/** Image height in pixels. */
|
|
106
|
+
imageHeight: number;
|
|
107
|
+
/** Per-tile properties (indexed by local tile ID). */
|
|
108
|
+
tileProperties: Map<number, Record<string, unknown>>;
|
|
109
|
+
/** Tile IDs marked as solid/collision. */
|
|
110
|
+
solidTiles: Set<number>;
|
|
95
111
|
}
|
|
96
112
|
/** Complete parsed tilemap data — format-independent. */
|
|
97
113
|
interface TilemapData {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
/** Map width in tiles. */
|
|
115
|
+
width: number;
|
|
116
|
+
/** Map height in tiles. */
|
|
117
|
+
height: number;
|
|
118
|
+
/** Tile width in pixels. */
|
|
119
|
+
tileWidth: number;
|
|
120
|
+
/** Tile height in pixels. */
|
|
121
|
+
tileHeight: number;
|
|
122
|
+
/** All layers in order. */
|
|
123
|
+
layers: MapLayer[];
|
|
124
|
+
/** Tilesets referenced by this map. */
|
|
125
|
+
tilesets: TilesetRef[];
|
|
126
|
+
/** Custom map properties. */
|
|
127
|
+
properties: Record<string, unknown>;
|
|
112
128
|
}
|
|
113
129
|
/** Create an empty TilemapData. */
|
|
114
130
|
declare function createTilemapData(width: number, height: number, tileWidth: number, tileHeight: number): TilemapData;
|
|
115
131
|
/** Get a tile GID at a grid position from a tile layer. Returns 0 if out of bounds. */
|
|
116
132
|
declare function getTileAt(layer: TileLayer, col: number, row: number): number;
|
|
117
|
-
/** Get the tileset that owns a given GID. */
|
|
133
|
+
/** Get the tileset that owns a given GID. Handles Tiled flip bits in the high bits. */
|
|
118
134
|
declare function getTilesetForGid(tilesets: TilesetRef[], gid: number): TilesetRef | undefined;
|
|
119
|
-
/** Compute the source rect in a tileset image for a given GID. */
|
|
135
|
+
/** Compute the source rect in a tileset image for a given GID. Strips Tiled flip bits. */
|
|
120
136
|
declare function getTileSourceRect(tileset: TilesetRef, gid: number): Rect;
|
|
121
|
-
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/ldtk-parser.d.ts
|
|
139
|
+
interface ParseLDtkOptions {
|
|
140
|
+
/** Predicate deciding whether an IntGrid value marks a solid cell. Default: value > 0. */
|
|
141
|
+
intGridSolid?: (value: number) => boolean;
|
|
142
|
+
}
|
|
143
|
+
interface LDtkEntity {
|
|
144
|
+
/** LDtk entity identifier (its type, e.g. "Player") — the key you switch on to decide what to spawn. */
|
|
145
|
+
id: string;
|
|
146
|
+
/** Entity position in pixels (LDtk px, pivot-adjusted per the parser convention). */
|
|
147
|
+
x: number;
|
|
148
|
+
y: number;
|
|
149
|
+
/** Entity box size in pixels. */
|
|
150
|
+
width: number;
|
|
151
|
+
height: number;
|
|
152
|
+
/** Custom field instances, keyed by field identifier. */
|
|
153
|
+
fields: Record<string, unknown>;
|
|
154
|
+
}
|
|
122
155
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
156
|
+
* Extract every LDtk entity from a parsed map as a flat, spawn-ready list —
|
|
157
|
+
* the LDtk-entity → ECS spawn convention. Walks all object layers; tile layers are skipped.
|
|
125
158
|
*/
|
|
126
|
-
declare function
|
|
127
|
-
|
|
159
|
+
declare function parseLDtkEntities(map: TilemapData): LDtkEntity[];
|
|
128
160
|
/**
|
|
129
161
|
* Parse an LDtk JSON project into an array of TilemapData (one per level).
|
|
130
162
|
* Returns all levels with their tile and entity layers.
|
|
163
|
+
* Throws TilemapParseError for unsupported formats (externalLevels, invalid input).
|
|
131
164
|
*/
|
|
132
|
-
declare function parseLDtk(json: unknown): TilemapData[];
|
|
133
|
-
|
|
165
|
+
declare function parseLDtk(json: unknown, options?: ParseLDtkOptions): TilemapData[];
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/parse-error.d.ts
|
|
168
|
+
/** Thrown by parseTiled/parseLDtk when a map uses an unsupported format or feature. */
|
|
169
|
+
declare class TilemapParseError extends Error {
|
|
170
|
+
constructor(message: string);
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/tiled-parser.d.ts
|
|
134
174
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
175
|
+
* Parse a Tiled .tmj (JSON) map into TilemapData.
|
|
176
|
+
* Supports orthogonal maps with CSV tile layers and object layers.
|
|
177
|
+
* Throws TilemapParseError for unsupported formats (infinite, non-orthogonal,
|
|
178
|
+
* external tilesets, base64/compressed/chunked layer data).
|
|
137
179
|
*/
|
|
138
|
-
declare
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
/** SpriteBatch used for batched tile rendering. */
|
|
142
|
-
readonly batch: SpriteBatch;
|
|
143
|
-
/** Map from tileset name → SkImage. Set via setTilesetImage(). */
|
|
144
|
-
private _images;
|
|
145
|
-
/** Reusable bounds rect — avoids per-frame allocation from camera.getBounds(). */
|
|
146
|
-
private _boundsBuf;
|
|
147
|
-
constructor(map: TilemapData);
|
|
148
|
-
/** Associate a loaded image with a tileset by name. */
|
|
149
|
-
setTilesetImage(tilesetName: string, image: SkImageLike): void;
|
|
150
|
-
/**
|
|
151
|
-
* Queue visible tile layers into a caller-owned `batch` using the camera for
|
|
152
|
-
* culling. Does NOT flush — the caller owns the single flush so tiles z-order
|
|
153
|
-
* under sprites. Zero-alloc: reuses the internal bounds buffer.
|
|
154
|
-
*/
|
|
155
|
-
drawInto(camera: Camera2D, batch: SpriteBatch): void;
|
|
156
|
-
/**
|
|
157
|
-
* Draw visible tile layers using the camera for culling.
|
|
158
|
-
* Call `flush` on a callback to issue the actual draw calls.
|
|
159
|
-
* Delegates to `drawInto` so culling and queuing logic live in one place.
|
|
160
|
-
*/
|
|
161
|
-
draw(camera: Camera2D, flush: (batch: SpriteBatch) => void): void;
|
|
162
|
-
private _drawTileLayer;
|
|
163
|
-
}
|
|
164
|
-
|
|
180
|
+
declare function parseTiled(json: unknown): TilemapData;
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region src/tilemap-collider.d.ts
|
|
165
183
|
/** A collision body extracted from a solid tile. */
|
|
166
184
|
interface TileCollider {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
185
|
+
/** World position of the tile center. */
|
|
186
|
+
x: number;
|
|
187
|
+
y: number;
|
|
188
|
+
/** AABB collision shape. */
|
|
189
|
+
shape: AABBShape;
|
|
190
|
+
/** Grid column. */
|
|
191
|
+
col: number;
|
|
192
|
+
/** Grid row. */
|
|
193
|
+
row: number;
|
|
194
|
+
/** The tile GID (flip bits stripped — AABB is symmetric, downstream lookups want the real id). */
|
|
195
|
+
gid: number;
|
|
178
196
|
}
|
|
179
197
|
/**
|
|
180
198
|
* Extract collision shapes from solid tiles in a tilemap.
|
|
@@ -185,5 +203,38 @@ interface TileCollider {
|
|
|
185
203
|
* @returns Array of TileCollider bodies.
|
|
186
204
|
*/
|
|
187
205
|
declare function extractColliders(map: TilemapData, layerName?: string): TileCollider[];
|
|
188
|
-
|
|
189
|
-
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/tilemap-renderer.d.ts
|
|
208
|
+
/**
|
|
209
|
+
* TilemapRenderer — draws a tilemap with viewport culling.
|
|
210
|
+
* Only tiles visible to the camera are submitted to the SpriteBatch.
|
|
211
|
+
*/
|
|
212
|
+
declare class TilemapRenderer {
|
|
213
|
+
/** The tilemap data to render. */
|
|
214
|
+
readonly map: TilemapData;
|
|
215
|
+
/** SpriteBatch used for batched tile rendering. */
|
|
216
|
+
readonly batch: SpriteBatch;
|
|
217
|
+
/** Map from tileset name → SkImage. Set via setTilesetImage(). */
|
|
218
|
+
private _images;
|
|
219
|
+
/** Reusable bounds rect — avoids per-frame allocation from camera.getBounds(). */
|
|
220
|
+
private _boundsBuf;
|
|
221
|
+
constructor(map: TilemapData);
|
|
222
|
+
/** Associate a loaded image with a tileset by name. */
|
|
223
|
+
setTilesetImage(tilesetName: string, image: SkImageLike): void;
|
|
224
|
+
/**
|
|
225
|
+
* Queue visible tile layers into a caller-owned `batch` using the camera for
|
|
226
|
+
* culling. Does NOT flush — the caller owns the single flush so tiles z-order
|
|
227
|
+
* under sprites. Zero-alloc: reuses the internal bounds buffer.
|
|
228
|
+
*/
|
|
229
|
+
drawInto(camera: Camera2D, batch: SpriteBatch): void;
|
|
230
|
+
/**
|
|
231
|
+
* Draw visible tile layers using the camera for culling.
|
|
232
|
+
* Call `flush` on a callback to issue the actual draw calls.
|
|
233
|
+
* Delegates to `drawInto` so culling and queuing logic live in one place.
|
|
234
|
+
*/
|
|
235
|
+
draw(camera: Camera2D, flush: (batch: SpriteBatch) => void): void;
|
|
236
|
+
private _drawTileLayer;
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
export { GID_FLIP_MASK, type LDtkEntity, type MapLayer, type MapObject, type ObjectLayer, type ParseLDtkOptions, type TileCollider, type TileData, type TileFlipFlags, type TileLayer, type TilemapData, TilemapParseError, TilemapRenderer, type TilesetRef, createTilemapData, decodeGidFlags, extractColliders, getTileAt, getTileSourceRect, getTilesetForGid, parseLDtk, parseLDtkEntities, parseTiled, stripGidFlags };
|
|
240
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/tilemap-data.ts","../src/ldtk-parser.ts","../src/parse-error.ts","../src/tiled-parser.ts","../src/tilemap-collider.ts","../src/tilemap-renderer.ts"],"mappings":";;;;;;cAGa;;UAOI;EACf;EACA;EACA;;;iBAIc,cAAc;;;;;;iBASd,eAAe,cAAc;;UAS5B;;EAEf;;EAEA;;EAEA,YAAY;;;UAIG;WACN;;EAET;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA;;EAEA,YAAY;;;UAIG;;EAEf;;EAEA;;EAEA;;EAEA;EACA;;EAEA;EACA;;EAEA;;EAEA,YAAY;;;UAIG;WACN;;EAET;;EAEA,SAAS;;EAET;;EAEA;;EAEA,YAAY;;;KAIF,WAAW,YAAY;;UAGlB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA,gBAAgB,YAAY;;EAE5B,YAAY;;;UAIG;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA,QAAQ;;EAER,UAAU;;EAEV,YAAY;;;iBAIE,kBACd,eACA,gBACA,mBACA,qBACC;;iBAaa,UAAU,OAAO,WAAW,aAAa;;iBAMzC,iBAAiB,UAAU,cAAc,cAAc;;iBAevD,kBAAkB,SAAS,YAAY,cAAc;;;UC9GpD;;EAEf,gBAAgB;;UAGD;;EAEf;;EAEA;EACA;;EAEA;EACA;;EAEA,QAAQ;;;;;;iBAOM,kBAAkB,KAAK,cAAc;;;;;;iBAuBrC,UAAU,eAAe,UAAS,mBAAwB;;;;cC1H7D,0BAA0B;cACzB;;;;;;;;;;iBC2GE,WAAW,gBAAgB;;;;UCvG1B;;EAEf;EACA;;EAEA,OAAO;;EAEP;;EAEA;;EAEA;;;;;;;;;;iBAWc,iBAAiB,KAAK,aAAa,qBAAqB;;;;;;;cCjB3D;;WAEF,KAAK;;WAGL,OAAO;;UAGR;;UAGA;cAEI,KAAK;;EAMjB,gBAAgB,qBAAqB,OAAO;;;;;;EAS5C,SAAS,QAAQ,UAAU,OAAO;;;;;;EAgBlC,KAAK,QAAQ,UAAU,QAAQ,OAAO;UAQ9B"}
|