@codexo/exojs-tiled 0.12.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.
- package/LICENSE +21 -0
- package/README.md +130 -0
- package/dist/esm/TiledMap.d.ts +88 -0
- package/dist/esm/TiledMap.js +51 -0
- package/dist/esm/TiledMap.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/public.d.ts +6 -0
- package/dist/esm/register.d.ts +1 -0
- package/dist/esm/register.js +14 -0
- package/dist/esm/register.js.map +1 -0
- package/dist/esm/tiledBuildInfo.d.ts +15 -0
- package/dist/esm/tiledBuildInfo.js +8 -0
- package/dist/esm/tiledBuildInfo.js.map +1 -0
- package/dist/esm/tiledExtension.d.ts +7 -0
- package/dist/esm/tiledExtension.js +60 -0
- package/dist/esm/tiledExtension.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Codexo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# @codexo/exojs-tiled
|
|
2
|
+
|
|
3
|
+
Official ExoJS extension for loading [Tiled](https://mapeditor.org) maps (`.tmj` JSON format).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @codexo/exojs @codexo/exojs-tiled
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package requires `@codexo/exojs` as a peer dependency. Both must be the same version.
|
|
12
|
+
|
|
13
|
+
## Core compatibility
|
|
14
|
+
|
|
15
|
+
| `@codexo/exojs-tiled` | `@codexo/exojs` |
|
|
16
|
+
|---|---|
|
|
17
|
+
| 0.12.x | 0.12.x |
|
|
18
|
+
|
|
19
|
+
## Supported Tiled scope
|
|
20
|
+
|
|
21
|
+
- Tiled JSON map format (`.tmj`)
|
|
22
|
+
- Orthogonal tile layers
|
|
23
|
+
- Object layers (basic)
|
|
24
|
+
- External tilesets (`.tsj`) referenced from `.tmj`
|
|
25
|
+
- Multiple tile layers per map
|
|
26
|
+
|
|
27
|
+
## Not supported in 0.12.x
|
|
28
|
+
|
|
29
|
+
- TMX (XML) format — use `.tmj` export from Tiled
|
|
30
|
+
- Isometric and hexagonal maps
|
|
31
|
+
- Image layers
|
|
32
|
+
- Wangsets
|
|
33
|
+
- Custom class / enum properties
|
|
34
|
+
|
|
35
|
+
## Usage — side-effect-free root entry
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { Application } from '@codexo/exojs';
|
|
39
|
+
import { TiledMap, tiledExtension } from '@codexo/exojs-tiled';
|
|
40
|
+
|
|
41
|
+
const app = new Application({
|
|
42
|
+
extensions: [tiledExtension],
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Importing from the root entry does **not** register the extension globally.
|
|
47
|
+
|
|
48
|
+
## Extension descriptor
|
|
49
|
+
|
|
50
|
+
`tiledExtension` is the default descriptor. It registers the `TiledMap` asset type with the following bindings:
|
|
51
|
+
|
|
52
|
+
- Constructor load: `loader.load(TiledMap, url)`
|
|
53
|
+
- Extension routing: `.tmj` files auto-route to `TiledMap`
|
|
54
|
+
- Type-name load: `loader.load('tiledMap', url)`
|
|
55
|
+
|
|
56
|
+
## Loading a Tiled map
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { TiledMap } from '@codexo/exojs-tiled';
|
|
60
|
+
|
|
61
|
+
// Inside a Scene:
|
|
62
|
+
override async load(loader) {
|
|
63
|
+
// By constructor (explicit)
|
|
64
|
+
await loader.load(TiledMap, { myMap: '/maps/level1.tmj' });
|
|
65
|
+
|
|
66
|
+
// By file extension (auto-routed)
|
|
67
|
+
await loader.load('/maps/level1.tmj');
|
|
68
|
+
|
|
69
|
+
// By type name
|
|
70
|
+
await loader.load('tiledMap', { myMap: '/maps/level1.tmj' });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
override create(loader) {
|
|
74
|
+
const map = loader.get(TiledMap, 'myMap');
|
|
75
|
+
this.addChild(map);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## `/register` convenience entry
|
|
80
|
+
|
|
81
|
+
Importing `/register` registers the default `tiledExtension` descriptor in the global `ExtensionRegistry`. Subsequently created Applications that use global defaults will automatically receive the Tiled extension.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
// Side effect: registers tiledExtension in the global ExtensionRegistry.
|
|
85
|
+
import '@codexo/exojs-tiled/register';
|
|
86
|
+
|
|
87
|
+
// All named exports are re-exported from /register:
|
|
88
|
+
import { TiledMap, tiledExtension } from '@codexo/exojs-tiled/register';
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Note:** `/register` does not use automatic discovery. It explicitly calls `ExtensionRegistry.register(tiledExtension)` at module evaluation time.
|
|
92
|
+
|
|
93
|
+
## Texture and sub-asset ownership
|
|
94
|
+
|
|
95
|
+
Tilesets referenced from a Tiled map are loaded as sub-assets and stored in the Loader cache. The `TiledMap` does **not** own or destroy tileset textures — the Loader cache owns them. Do not call `tileset.destroy()` from your code; let the Loader handle cleanup when the scene is destroyed.
|
|
96
|
+
|
|
97
|
+
## Minimal working example
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { Application, Scene } from '@codexo/exojs';
|
|
101
|
+
import { TiledMap, tiledExtension } from '@codexo/exojs-tiled';
|
|
102
|
+
|
|
103
|
+
const app = new Application({ extensions: [tiledExtension] });
|
|
104
|
+
document.body.append(app.canvas);
|
|
105
|
+
|
|
106
|
+
class GameScene extends Scene {
|
|
107
|
+
map!: TiledMap;
|
|
108
|
+
|
|
109
|
+
override async load(loader) {
|
|
110
|
+
await loader.load(TiledMap, { level1: '/maps/level1.tmj' });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
override create(loader) {
|
|
114
|
+
this.map = loader.get(TiledMap, 'level1');
|
|
115
|
+
this.addChild(this.map);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
app.scenes.start(GameScene);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Links
|
|
123
|
+
|
|
124
|
+
- [Official ExoJS Tiled guide](https://exojs.dev/guides/extensions/tiled)
|
|
125
|
+
- [API reference](https://exojs.dev/api/exojs-tiled)
|
|
126
|
+
- [Tiled map editor](https://mapeditor.org)
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
MIT
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Texture } from '@codexo/exojs';
|
|
2
|
+
export interface TiledTileset {
|
|
3
|
+
readonly firstgid: number;
|
|
4
|
+
readonly source?: string;
|
|
5
|
+
readonly image?: string;
|
|
6
|
+
readonly name?: string;
|
|
7
|
+
readonly tilewidth?: number;
|
|
8
|
+
readonly tileheight?: number;
|
|
9
|
+
readonly columns?: number;
|
|
10
|
+
readonly tilecount?: number;
|
|
11
|
+
readonly spacing?: number;
|
|
12
|
+
readonly margin?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface TiledLayer {
|
|
15
|
+
readonly id: number;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly type: 'tilelayer' | 'objectgroup' | 'imagelayer' | 'group';
|
|
18
|
+
readonly visible: boolean;
|
|
19
|
+
readonly x: number;
|
|
20
|
+
readonly y: number;
|
|
21
|
+
readonly width?: number;
|
|
22
|
+
readonly height?: number;
|
|
23
|
+
readonly data?: number[];
|
|
24
|
+
readonly objects?: TiledObject[];
|
|
25
|
+
readonly opacity: number;
|
|
26
|
+
}
|
|
27
|
+
export interface TiledObject {
|
|
28
|
+
readonly id: number;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly type: string;
|
|
31
|
+
readonly x: number;
|
|
32
|
+
readonly y: number;
|
|
33
|
+
readonly width: number;
|
|
34
|
+
readonly height: number;
|
|
35
|
+
readonly rotation: number;
|
|
36
|
+
readonly visible: boolean;
|
|
37
|
+
readonly gid?: number;
|
|
38
|
+
readonly properties?: TiledProperty[];
|
|
39
|
+
}
|
|
40
|
+
export interface TiledProperty {
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly type: string;
|
|
43
|
+
readonly value: unknown;
|
|
44
|
+
}
|
|
45
|
+
/** Raw data shape parsed from a Tiled JSON (.tmj) file. */
|
|
46
|
+
export interface TiledMapData {
|
|
47
|
+
readonly width: number;
|
|
48
|
+
readonly height: number;
|
|
49
|
+
readonly tilewidth: number;
|
|
50
|
+
readonly tileheight: number;
|
|
51
|
+
readonly infinite?: boolean;
|
|
52
|
+
readonly orientation?: string;
|
|
53
|
+
readonly renderorder?: string;
|
|
54
|
+
readonly layers: readonly TiledLayer[];
|
|
55
|
+
readonly tilesets: readonly TiledTileset[];
|
|
56
|
+
readonly version?: string | number;
|
|
57
|
+
readonly type?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Runtime representation of a loaded Tiled map.
|
|
61
|
+
*
|
|
62
|
+
* Exposes map metadata, layers, and tileset textures. Tileset textures
|
|
63
|
+
* are owned by the Loader cache — `TiledMap.destroy()` does NOT destroy them.
|
|
64
|
+
*
|
|
65
|
+
* Only the initial proof scope is implemented: orthogonal tile layers,
|
|
66
|
+
* basic tilesets, and basic object layers. TMX/XML, infinite maps, and
|
|
67
|
+
* world streaming are not supported.
|
|
68
|
+
*/
|
|
69
|
+
export declare class TiledMap {
|
|
70
|
+
readonly data: TiledMapData;
|
|
71
|
+
readonly tilesetTextures: readonly Texture[];
|
|
72
|
+
readonly width: number;
|
|
73
|
+
readonly height: number;
|
|
74
|
+
readonly tileWidth: number;
|
|
75
|
+
readonly tileHeight: number;
|
|
76
|
+
readonly layers: readonly TiledLayer[];
|
|
77
|
+
readonly tilesets: readonly TiledTileset[];
|
|
78
|
+
constructor(data: TiledMapData, tilesetTextures: readonly Texture[]);
|
|
79
|
+
/** Tile layers only. */
|
|
80
|
+
get tileLayers(): readonly TiledLayer[];
|
|
81
|
+
/** Object group layers only. */
|
|
82
|
+
get objectLayers(): readonly TiledLayer[];
|
|
83
|
+
/**
|
|
84
|
+
* Destroy this TiledMap. Does NOT destroy tileset textures — they are
|
|
85
|
+
* owned by the Loader's cache and may be shared with other callers.
|
|
86
|
+
*/
|
|
87
|
+
destroy(): void;
|
|
88
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// TiledMap runtime object
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
/**
|
|
5
|
+
* Runtime representation of a loaded Tiled map.
|
|
6
|
+
*
|
|
7
|
+
* Exposes map metadata, layers, and tileset textures. Tileset textures
|
|
8
|
+
* are owned by the Loader cache — `TiledMap.destroy()` does NOT destroy them.
|
|
9
|
+
*
|
|
10
|
+
* Only the initial proof scope is implemented: orthogonal tile layers,
|
|
11
|
+
* basic tilesets, and basic object layers. TMX/XML, infinite maps, and
|
|
12
|
+
* world streaming are not supported.
|
|
13
|
+
*/
|
|
14
|
+
class TiledMap {
|
|
15
|
+
data;
|
|
16
|
+
tilesetTextures;
|
|
17
|
+
width;
|
|
18
|
+
height;
|
|
19
|
+
tileWidth;
|
|
20
|
+
tileHeight;
|
|
21
|
+
layers;
|
|
22
|
+
tilesets;
|
|
23
|
+
constructor(data, tilesetTextures) {
|
|
24
|
+
this.data = data;
|
|
25
|
+
this.tilesetTextures = tilesetTextures;
|
|
26
|
+
this.width = data.width;
|
|
27
|
+
this.height = data.height;
|
|
28
|
+
this.tileWidth = data.tilewidth;
|
|
29
|
+
this.tileHeight = data.tileheight;
|
|
30
|
+
this.layers = data.layers;
|
|
31
|
+
this.tilesets = data.tilesets;
|
|
32
|
+
}
|
|
33
|
+
/** Tile layers only. */
|
|
34
|
+
get tileLayers() {
|
|
35
|
+
return this.layers.filter(l => l.type === 'tilelayer');
|
|
36
|
+
}
|
|
37
|
+
/** Object group layers only. */
|
|
38
|
+
get objectLayers() {
|
|
39
|
+
return this.layers.filter(l => l.type === 'objectgroup');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Destroy this TiledMap. Does NOT destroy tileset textures — they are
|
|
43
|
+
* owned by the Loader's cache and may be shared with other callers.
|
|
44
|
+
*/
|
|
45
|
+
destroy() {
|
|
46
|
+
// Intentionally empty: tileset textures are Loader-owned.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { TiledMap };
|
|
51
|
+
//# sourceMappingURL=TiledMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TiledMap.js","sources":["../../../src/TiledMap.ts"],"sourcesContent":[null],"names":[],"mappings":"AAoEA;AACA;AACA;AAEA;;;;;;;;;AASG;MACU,QAAQ,CAAA;AACH,IAAA,IAAI;AACJ,IAAA,eAAe;AAEf,IAAA,KAAK;AACL,IAAA,MAAM;AACN,IAAA,SAAS;AACT,IAAA,UAAU;AAEV,IAAA,MAAM;AACN,IAAA,QAAQ;IAExB,WAAA,CAAmB,IAAkB,EAAE,eAAmC,EAAA;AACxE,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAChB,QAAA,IAAI,CAAC,eAAe,GAAG,eAAe;AACtC,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK;AACvB,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM;AACzB,QAAA,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS;AAC/B,QAAA,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU;AACjC,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM;AACzB,QAAA,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ;IAC/B;;AAGA,IAAA,IAAW,UAAU,GAAA;AACnB,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;IACxD;;AAGA,IAAA,IAAW,YAAY,GAAA;AACrB,QAAA,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,aAAa,CAAC;IAC1D;AAEA;;;AAGG;IACI,OAAO,GAAA;;IAEd;AACD;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { Extension, AssetBinding, AssetHandler, AssetLoadRequest } from '@codexo/exojs/extensions';
|
|
2
|
+
export { tiledExtension } from './tiledExtension';
|
|
3
|
+
export type { TiledBuildInfo } from './tiledBuildInfo';
|
|
4
|
+
export { tiledBuildInfo } from './tiledBuildInfo';
|
|
5
|
+
export { TiledMap } from './TiledMap';
|
|
6
|
+
export type { TiledLayer, TiledMapData, TiledObject, TiledProperty, TiledTileset } from './TiledMap';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ExtensionRegistry } from '@codexo/exojs/extensions';
|
|
2
|
+
import { tiledExtension } from './tiledExtension.js';
|
|
3
|
+
export { tiledBuildInfo } from './tiledBuildInfo.js';
|
|
4
|
+
export { TiledMap } from './TiledMap.js';
|
|
5
|
+
|
|
6
|
+
// @codexo/exojs-tiled/register — explicit registration entry.
|
|
7
|
+
// Importing this entry registers the default tiledExtension descriptor
|
|
8
|
+
// in the global ExtensionRegistry. Subsequently constructed Applications
|
|
9
|
+
// that use global defaults will receive the Tiled extension.
|
|
10
|
+
// This is the only side-effectful entry in this package.
|
|
11
|
+
ExtensionRegistry.register(tiledExtension);
|
|
12
|
+
|
|
13
|
+
export { tiledExtension };
|
|
14
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sources":["../../../src/register.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AAMA,iBAAiB,CAAC,QAAQ,CAAC,cAAc,CAAC;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Immutable compile-time build metadata for `@codexo/exojs-tiled`.
|
|
3
|
+
*
|
|
4
|
+
* `development` mirrors the `__DEV__` compile-time constant and is statically
|
|
5
|
+
* replaced before tree shaking. `version` is the exact `package.json` version
|
|
6
|
+
* of the Tiled package at build time. `revision` is the short
|
|
7
|
+
* source-control revision (appended with `-dirty` when uncommitted changes are
|
|
8
|
+
* present) or `"unknown"` when no revision information is available.
|
|
9
|
+
*/
|
|
10
|
+
export interface TiledBuildInfo {
|
|
11
|
+
readonly version: string;
|
|
12
|
+
readonly revision: string;
|
|
13
|
+
readonly development: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const tiledBuildInfo: TiledBuildInfo;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiledBuildInfo.js","sources":["../../../src/tiledBuildInfo.ts"],"sourcesContent":[null],"names":[],"mappings":"AAeO,MAAM,cAAc,GAAmB,MAAM,CAAC,MAAM,CAAC;AAC1D,IAAA,OAAO,EAAE,QAAW;AACpB,IAAA,QAAQ,EAAE,SAAY;AACtB,IAAA,WAAW,EAAE,KAAO;AACrB,CAAA;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Extension } from '@codexo/exojs/extensions';
|
|
2
|
+
/**
|
|
3
|
+
* Default immutable Tiled extension descriptor.
|
|
4
|
+
* Use with `ApplicationOptions.extensions` or call
|
|
5
|
+
* `import '@codexo/exojs-tiled/register'` for global auto-registration.
|
|
6
|
+
*/
|
|
7
|
+
export declare const tiledExtension: Extension;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Texture } from '@codexo/exojs';
|
|
2
|
+
import { TiledMap } from './TiledMap.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a tileset image reference relative to the map's source path.
|
|
6
|
+
* `new URL(ref, source)` only works when `source` is an absolute URL; the
|
|
7
|
+
* loader is frequently called with relative paths, so fall back to a synthetic
|
|
8
|
+
* base and strip it.
|
|
9
|
+
*/
|
|
10
|
+
function resolveRelative(ref, source) {
|
|
11
|
+
try {
|
|
12
|
+
return new URL(ref, source).href;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
const base = 'https://exojs.invalid/';
|
|
16
|
+
return new URL(ref, base + source.replace(/^\/+/, '')).href.slice(base.length);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const tiledBinding = {
|
|
20
|
+
type: TiledMap,
|
|
21
|
+
typeNames: ['tiledMap'],
|
|
22
|
+
extensions: ['tmj'],
|
|
23
|
+
create(loader) {
|
|
24
|
+
return {
|
|
25
|
+
async load({ source }, context) {
|
|
26
|
+
const data = await context.fetchJson(source);
|
|
27
|
+
if (!data || typeof data !== 'object' || !Array.isArray(data.tilesets)) {
|
|
28
|
+
throw new Error(`TiledMap: invalid or unsupported map file at "${source}".`);
|
|
29
|
+
}
|
|
30
|
+
if (data.infinite === true) {
|
|
31
|
+
throw new Error(`TiledMap: infinite maps are not supported (at "${source}").`);
|
|
32
|
+
}
|
|
33
|
+
if (data.orientation !== undefined && data.orientation !== 'orthogonal') {
|
|
34
|
+
throw new Error(`TiledMap: only orthogonal orientation is supported (got "${data.orientation}" at "${source}").`);
|
|
35
|
+
}
|
|
36
|
+
// Load tileset textures. Sub-assets are owned by the Loader cache —
|
|
37
|
+
// TiledMap must NOT destroy them.
|
|
38
|
+
const tilesetTextures = (await Promise.all(data.tilesets
|
|
39
|
+
.filter(ts => ts.image !== undefined)
|
|
40
|
+
.map(ts => loader.load(Texture, resolveRelative(ts.image, source)))));
|
|
41
|
+
return new TiledMap(data, tilesetTextures);
|
|
42
|
+
},
|
|
43
|
+
destroy() {
|
|
44
|
+
// This handler holds no loader-local resources.
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Default immutable Tiled extension descriptor.
|
|
51
|
+
* Use with `ApplicationOptions.extensions` or call
|
|
52
|
+
* `import '@codexo/exojs-tiled/register'` for global auto-registration.
|
|
53
|
+
*/
|
|
54
|
+
const tiledExtension = Object.freeze({
|
|
55
|
+
id: '@codexo/exojs-tiled',
|
|
56
|
+
assets: [tiledBinding],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export { tiledExtension };
|
|
60
|
+
//# sourceMappingURL=tiledExtension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tiledExtension.js","sources":["../../../src/tiledExtension.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAMA;;;;;AAKG;AACH,SAAS,eAAe,CAAC,GAAW,EAAE,MAAc,EAAA;AAClD,IAAA,IAAI;QACF,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,IAAI;IAClC;AAAE,IAAA,MAAM;QACN,MAAM,IAAI,GAAG,wBAAwB;QACrC,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;IAChF;AACF;AAEA,MAAM,YAAY,GAA2B;AAC3C,IAAA,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,CAAC,UAAU,CAAC;IACvB,UAAU,EAAE,CAAC,KAAK,CAAC;AACnB,IAAA,MAAM,CAAC,MAAc,EAAA;QACnB,OAAO;AACL,YAAA,MAAM,IAAI,CAAC,EAAE,MAAM,EAAoB,EAAE,OAA2B,EAAA;gBAClE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,SAAS,CAAe,MAAM,CAAC;AAE1D,gBAAA,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;AACtE,oBAAA,MAAM,IAAI,KAAK,CAAC,iDAAiD,MAAM,CAAA,EAAA,CAAI,CAAC;gBAC9E;AAEA,gBAAA,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE;AAC1B,oBAAA,MAAM,IAAI,KAAK,CAAC,kDAAkD,MAAM,CAAA,GAAA,CAAK,CAAC;gBAChF;AAEA,gBAAA,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,IAAI,IAAI,CAAC,WAAW,KAAK,YAAY,EAAE;oBACvE,MAAM,IAAI,KAAK,CAAC,CAAA,yDAAA,EAA4D,IAAI,CAAC,WAAW,CAAA,MAAA,EAAS,MAAM,CAAA,GAAA,CAAK,CAAC;gBACnH;;;gBAIA,MAAM,eAAe,IAAI,MAAM,OAAO,CAAC,GAAG,CACxC,IAAI,CAAC;qBACF,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,KAAK,SAAS;qBACnC,GAAG,CAAC,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,EAAE,CAAC,KAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CACvE,CAAc;AAEf,gBAAA,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;YAC5C,CAAC;YACD,OAAO,GAAA;;YAEP,CAAC;SACF;IACH,CAAC;CACF;AAED;;;;AAIG;AACI,MAAM,cAAc,GAAc,MAAM,CAAC,MAAM,CAAC;AACrD,IAAA,EAAE,EAAE,qBAAqB;IACzB,MAAM,EAAE,CAAC,YAAY,CAAC;AACvB,CAAA;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codexo/exojs-tiled",
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "Tiled map format asset extension for ExoJS.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"./dist/esm/register.js"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/esm/index.js",
|
|
10
|
+
"module": "./dist/esm/index.js",
|
|
11
|
+
"types": "./dist/esm/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/esm/index.d.ts",
|
|
15
|
+
"import": "./dist/esm/index.js",
|
|
16
|
+
"default": "./dist/esm/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./register": {
|
|
19
|
+
"types": "./dist/esm/register.d.ts",
|
|
20
|
+
"import": "./dist/esm/register.js",
|
|
21
|
+
"default": "./dist/esm/register.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/esm/",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@codexo/exojs": "0.12.x"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@codexo/exojs": "0.12.0",
|
|
35
|
+
"@codexo/exojs-config": "0.0.0"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsx ../../node_modules/rollup/dist/bin/rollup -c --environment EXOJS_ENV:production",
|
|
43
|
+
"build:dev": "tsx ../../node_modules/rollup/dist/bin/rollup -c --environment EXOJS_ENV:development",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
46
|
+
"test": "vitest run --root ../.. --project=exojs-tiled"
|
|
47
|
+
}
|
|
48
|
+
}
|