@codexo/exojs-tilemap 0.19.0 → 0.20.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/README.md +7 -163
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +12 -20
- package/dist/esm/ChunkSource.d.ts +0 -33
- package/dist/esm/ChunkSource.d.ts.map +0 -1
- package/dist/esm/ChunkStreamer.d.ts +0 -104
- package/dist/esm/ChunkStreamer.d.ts.map +0 -1
- package/dist/esm/ChunkStreamer.js +0 -229
- package/dist/esm/ChunkStreamer.js.map +0 -1
- package/dist/esm/ImageLayer.d.ts +0 -89
- package/dist/esm/ImageLayer.d.ts.map +0 -1
- package/dist/esm/ImageLayer.js +0 -74
- package/dist/esm/ImageLayer.js.map +0 -1
- package/dist/esm/ImageLayerNode.d.ts +0 -91
- package/dist/esm/ImageLayerNode.d.ts.map +0 -1
- package/dist/esm/ImageLayerNode.js +0 -210
- package/dist/esm/ImageLayerNode.js.map +0 -1
- package/dist/esm/MapObject.d.ts +0 -70
- package/dist/esm/MapObject.d.ts.map +0 -1
- package/dist/esm/MapObject.js +0 -34
- package/dist/esm/MapObject.js.map +0 -1
- package/dist/esm/MapObjectSpawner.d.ts +0 -133
- package/dist/esm/MapObjectSpawner.d.ts.map +0 -1
- package/dist/esm/MapObjectSpawner.js +0 -147
- package/dist/esm/MapObjectSpawner.js.map +0 -1
- package/dist/esm/MapSpawnSession.d.ts +0 -46
- package/dist/esm/MapSpawnSession.d.ts.map +0 -1
- package/dist/esm/MapSpawnSession.js +0 -88
- package/dist/esm/MapSpawnSession.js.map +0 -1
- package/dist/esm/MapWorld.d.ts +0 -134
- package/dist/esm/MapWorld.d.ts.map +0 -1
- package/dist/esm/MapWorld.js +0 -150
- package/dist/esm/MapWorld.js.map +0 -1
- package/dist/esm/MapWorldRuntime.d.ts +0 -180
- package/dist/esm/MapWorldRuntime.d.ts.map +0 -1
- package/dist/esm/MapWorldRuntime.js +0 -261
- package/dist/esm/MapWorldRuntime.js.map +0 -1
- package/dist/esm/ObjectLayer.d.ts +0 -379
- package/dist/esm/ObjectLayer.d.ts.map +0 -1
- package/dist/esm/ObjectLayer.js +0 -221
- package/dist/esm/ObjectLayer.js.map +0 -1
- package/dist/esm/SampledChunkSource.d.ts +0 -43
- package/dist/esm/SampledChunkSource.d.ts.map +0 -1
- package/dist/esm/SampledChunkSource.js +0 -48
- package/dist/esm/SampledChunkSource.js.map +0 -1
- package/dist/esm/TileAnimator.d.ts +0 -72
- package/dist/esm/TileAnimator.d.ts.map +0 -1
- package/dist/esm/TileAnimator.js +0 -158
- package/dist/esm/TileAnimator.js.map +0 -1
- package/dist/esm/TileChunk.d.ts +0 -103
- package/dist/esm/TileChunk.d.ts.map +0 -1
- package/dist/esm/TileChunk.js +0 -194
- package/dist/esm/TileChunk.js.map +0 -1
- package/dist/esm/TileChunkNode.d.ts +0 -2
- package/dist/esm/TileChunkNode.d.ts.map +0 -1
- package/dist/esm/TileChunkNode.js +0 -145
- package/dist/esm/TileChunkNode.js.map +0 -1
- package/dist/esm/TileLayer.d.ts +0 -286
- package/dist/esm/TileLayer.d.ts.map +0 -1
- package/dist/esm/TileLayer.js +0 -526
- package/dist/esm/TileLayer.js.map +0 -1
- package/dist/esm/TileLayerNode.d.ts +0 -129
- package/dist/esm/TileLayerNode.d.ts.map +0 -1
- package/dist/esm/TileLayerNode.js +0 -245
- package/dist/esm/TileLayerNode.js.map +0 -1
- package/dist/esm/TileMap.d.ts +0 -317
- package/dist/esm/TileMap.d.ts.map +0 -1
- package/dist/esm/TileMap.js +0 -406
- package/dist/esm/TileMap.js.map +0 -1
- package/dist/esm/TileMapBand.d.ts +0 -80
- package/dist/esm/TileMapBand.d.ts.map +0 -1
- package/dist/esm/TileMapBand.js +0 -155
- package/dist/esm/TileMapBand.js.map +0 -1
- package/dist/esm/TileMapNode.d.ts +0 -92
- package/dist/esm/TileMapNode.d.ts.map +0 -1
- package/dist/esm/TileMapNode.js +0 -134
- package/dist/esm/TileMapNode.js.map +0 -1
- package/dist/esm/TileMapView.d.ts +0 -248
- package/dist/esm/TileMapView.d.ts.map +0 -1
- package/dist/esm/TileMapView.js +0 -394
- package/dist/esm/TileMapView.js.map +0 -1
- package/dist/esm/TileProjection.d.ts +0 -59
- package/dist/esm/TileProjection.d.ts.map +0 -1
- package/dist/esm/TileProjection.js +0 -106
- package/dist/esm/TileProjection.js.map +0 -1
- package/dist/esm/TileSet.d.ts +0 -116
- package/dist/esm/TileSet.d.ts.map +0 -1
- package/dist/esm/TileSet.js +0 -168
- package/dist/esm/TileSet.js.map +0 -1
- package/dist/esm/WangSet.d.ts +0 -80
- package/dist/esm/WangSet.d.ts.map +0 -1
- package/dist/esm/WangSet.js +0 -73
- package/dist/esm/WangSet.js.map +0 -1
- package/dist/esm/WorkerSampledChunkSource.d.ts +0 -94
- package/dist/esm/WorkerSampledChunkSource.d.ts.map +0 -1
- package/dist/esm/WorkerSampledChunkSource.js +0 -113
- package/dist/esm/WorkerSampledChunkSource.js.map +0 -1
- package/dist/esm/autoTile.d.ts +0 -88
- package/dist/esm/autoTile.d.ts.map +0 -1
- package/dist/esm/autoTile.js +0 -173
- package/dist/esm/autoTile.js.map +0 -1
- package/dist/esm/chunkGeometry.d.ts +0 -2
- package/dist/esm/chunkGeometry.d.ts.map +0 -1
- package/dist/esm/chunkGeometry.js +0 -116
- package/dist/esm/chunkGeometry.js.map +0 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -27
- package/dist/esm/nodeBounds.d.ts +0 -2
- package/dist/esm/nodeBounds.d.ts.map +0 -1
- package/dist/esm/nodeBounds.js +0 -40
- package/dist/esm/nodeBounds.js.map +0 -1
- package/dist/esm/pixelSnap.d.ts +0 -2
- package/dist/esm/pixelSnap.d.ts.map +0 -1
- package/dist/esm/pixelSnap.js +0 -21
- package/dist/esm/pixelSnap.js.map +0 -1
- package/dist/esm/projectObject.d.ts +0 -4
- package/dist/esm/projectObject.d.ts.map +0 -1
- package/dist/esm/projectObject.js +0 -87
- package/dist/esm/projectObject.js.map +0 -1
- package/dist/esm/public.d.ts +0 -48
- package/dist/esm/public.d.ts.map +0 -1
- package/dist/esm/tileCollision.d.ts +0 -190
- package/dist/esm/tileCollision.d.ts.map +0 -1
- package/dist/esm/tileCollision.js +0 -399
- package/dist/esm/tileCollision.js.map +0 -1
- package/dist/esm/tileWord.d.ts +0 -2
- package/dist/esm/tileWord.d.ts.map +0 -1
- package/dist/esm/tileWord.js +0 -16
- package/dist/esm/tileWord.js.map +0 -1
- package/dist/esm/tilemapExtension.d.ts +0 -20
- package/dist/esm/tilemapExtension.d.ts.map +0 -1
- package/dist/esm/tilemapExtension.js +0 -53
- package/dist/esm/tilemapExtension.js.map +0 -1
- package/dist/esm/tilemapSerializers.d.ts +0 -2
- package/dist/esm/tilemapSerializers.d.ts.map +0 -1
- package/dist/esm/tilemapSerializers.js +0 -54
- package/dist/esm/tilemapSerializers.js.map +0 -1
- package/dist/esm/types.d.ts +0 -231
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -129
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts +0 -2
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts.map +0 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +0 -376
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +0 -1
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js +0 -6
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +0 -1
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js +0 -6
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +0 -1
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts +0 -2
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts.map +0 -1
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +0 -539
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +0 -1
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +0 -6
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +0 -1
package/dist/esm/TileMapBand.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { Container } from "@codexo/exojs";
|
|
2
|
-
|
|
3
|
-
//#region src/TileMapBand.ts
|
|
4
|
-
/**
|
|
5
|
-
* A named, ordered group of layer nodes ({@link TileLayerNode}s and
|
|
6
|
-
* {@link ImageLayerNode}s) produced by a {@link TileMapView} for ergonomic
|
|
7
|
-
* actor interleaving.
|
|
8
|
-
*
|
|
9
|
-
* A band is a plain {@link Container} scene node that the application parents
|
|
10
|
-
* wherever it wants (typically directly under its own world root). Bands are
|
|
11
|
-
* composition units only: a band owns **its generated layer nodes** and
|
|
12
|
-
* never application actors. Placing actors *between* bands is done by parenting
|
|
13
|
-
* the bands and the actor containers as siblings in the desired document order:
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* worldRoot.addChild(view.band('ground'), actors, view.band('roof'));
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* **Rendering order within a band always follows map document order**
|
|
20
|
-
* ({@link import('./TileMap').TileMap.renderableLayers}), not the order layers
|
|
21
|
-
* were listed in the band definition - band membership *selects* layers; it
|
|
22
|
-
* never reorders them. Tile and image members interleave exactly as the map's
|
|
23
|
-
* combined document order dictates.
|
|
24
|
-
*
|
|
25
|
-
* **Ownership:** the band owns the layer nodes it was created with. Destroying
|
|
26
|
-
* the band destroys those layer nodes (and their cached chunk geometry) and
|
|
27
|
-
* detaches the band from its application parent - it never touches application
|
|
28
|
-
* actors, sibling bands, the {@link TileMap}, the {@link TileLayer}s /
|
|
29
|
-
* {@link ImageLayer}s, or Loader-owned textures.
|
|
30
|
-
*
|
|
31
|
-
* Bounds are the union of the band's layer-node bounds (an empty band
|
|
32
|
-
* collapses to a degenerate rect at the band's transformed origin).
|
|
33
|
-
*
|
|
34
|
-
* Bands are created by {@link TileMapView}; construct them through
|
|
35
|
-
* {@link TileMapView} rather than directly.
|
|
36
|
-
*
|
|
37
|
-
* @advanced
|
|
38
|
-
*/
|
|
39
|
-
var TileMapBand = class extends Container {
|
|
40
|
-
/**
|
|
41
|
-
* The band name (unique within its owning {@link TileMapView}). Narrows the
|
|
42
|
-
* inherited {@link SceneNode.name} from `string | null` to a required string;
|
|
43
|
-
* assigned once at construction.
|
|
44
|
-
*/
|
|
45
|
-
name = "";
|
|
46
|
-
_layerNodes;
|
|
47
|
-
_destroyed = false;
|
|
48
|
-
/**
|
|
49
|
-
* @param name The band name (unique within its owning view).
|
|
50
|
-
* @param layerNodes The layer nodes composing this band, already ordered by
|
|
51
|
-
* map document order. Adopted as children.
|
|
52
|
-
* @internal Constructed by {@link TileMapView}.
|
|
53
|
-
*/
|
|
54
|
-
constructor(name, layerNodes) {
|
|
55
|
-
super();
|
|
56
|
-
this.name = name;
|
|
57
|
-
this._layerNodes = [...layerNodes];
|
|
58
|
-
for (const node of this._layerNodes) this.addChild(node);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* The layer nodes that compose this band, in map document order - tile and
|
|
62
|
-
* image members interleaved. This is the band's **membership** list (the
|
|
63
|
-
* nodes it owns and destroys); it may differ from {@link Container.children}
|
|
64
|
-
* if the caller reparents an individual layer node elsewhere.
|
|
65
|
-
*/
|
|
66
|
-
get layerNodes() {
|
|
67
|
-
return this._layerNodes;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Find this band's layer node rendering the layer with the given id (tile or
|
|
71
|
-
* image member; first match in document order).
|
|
72
|
-
*/
|
|
73
|
-
getLayerNodeById(id) {
|
|
74
|
-
return this._layerNodes.find((node) => node.layer.id === id);
|
|
75
|
-
}
|
|
76
|
-
/** Whether this band currently owns no layer nodes. */
|
|
77
|
-
get isEmpty() {
|
|
78
|
-
return this._layerNodes.length === 0;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Bounds are the union of the band's visible layer-node bounds. With no
|
|
82
|
-
* visible children the band collapses to a degenerate rect at its transformed
|
|
83
|
-
* origin (rather than the whole-subtree-plus-origin union a bare Container
|
|
84
|
-
* would report).
|
|
85
|
-
*/
|
|
86
|
-
updateBounds() {
|
|
87
|
-
this._bounds.reset();
|
|
88
|
-
let hasVisibleChild = false;
|
|
89
|
-
for (const child of this.children) if (child.visible) {
|
|
90
|
-
this._bounds.addRect(child.getBounds());
|
|
91
|
-
hasVisibleChild = true;
|
|
92
|
-
}
|
|
93
|
-
if (!hasVisibleChild) this._bounds.addRect(this.getLocalBounds(), this.getGlobalTransform());
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Adopt a freshly created layer node into this band (used by
|
|
98
|
-
* {@link TileMapView.refreshLayers} when a newly added map layer joins this
|
|
99
|
-
* band). Appended; call {@link TileMapBand._reorder} afterwards to restore
|
|
100
|
-
* map document order.
|
|
101
|
-
* @internal
|
|
102
|
-
*/
|
|
103
|
-
_adopt(node) {
|
|
104
|
-
if (!this._layerNodes.includes(node)) this._layerNodes.push(node);
|
|
105
|
-
this.addChild(node);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Drop a layer node from this band's membership without destroying it (used
|
|
109
|
-
* when its map layer was removed; the view destroys the node separately).
|
|
110
|
-
* @internal
|
|
111
|
-
*/
|
|
112
|
-
_release(node) {
|
|
113
|
-
const index = this._layerNodes.indexOf(node);
|
|
114
|
-
if (index !== -1) this._layerNodes.splice(index, 1);
|
|
115
|
-
if (node.parent === this) this.removeChild(node);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Reorder this band's membership and its still-parented children to map
|
|
119
|
-
* document order. `documentIndex` maps a layer **instance** to its index in
|
|
120
|
-
* the map's combined document order - keyed by instance rather than id
|
|
121
|
-
* because a tile layer and an image layer may share an id in fallback-ordered
|
|
122
|
-
* maps. Layer nodes the caller has reparented away from this band keep their
|
|
123
|
-
* membership (for ownership) but are not re-adopted.
|
|
124
|
-
* @internal
|
|
125
|
-
*/
|
|
126
|
-
_reorder(documentIndex) {
|
|
127
|
-
this._layerNodes.sort((a, b) => (documentIndex.get(a.layer) ?? 0) - (documentIndex.get(b.layer) ?? 0));
|
|
128
|
-
for (const node of this._layerNodes) if (node.parent === this) this.addChild(node);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Destroy the band: detach it from its application parent, then destroy the
|
|
132
|
-
* layer nodes it owns (freeing their chunk geometry / image sprites).
|
|
133
|
-
* Application actors, sibling bands, the map, layers, and Loader-owned
|
|
134
|
-
* textures are untouched.
|
|
135
|
-
*
|
|
136
|
-
* Idempotent: a second call (e.g. when {@link TileMapView.destroy} runs after
|
|
137
|
-
* the application already destroyed this band directly) is a safe no-op.
|
|
138
|
-
*/
|
|
139
|
-
destroy() {
|
|
140
|
-
if (this._destroyed) return;
|
|
141
|
-
this._destroyed = true;
|
|
142
|
-
this.parent?.removeChild(this);
|
|
143
|
-
const owned = [...this._layerNodes];
|
|
144
|
-
this._layerNodes.length = 0;
|
|
145
|
-
super.destroy();
|
|
146
|
-
for (const node of owned) {
|
|
147
|
-
node.parent?.removeChild(node);
|
|
148
|
-
node.destroy();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
//#endregion
|
|
154
|
-
export { TileMapBand };
|
|
155
|
-
//# sourceMappingURL=TileMapBand.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TileMapBand.js","names":[],"sources":["../../src/TileMapBand.ts"],"sourcesContent":["import { Container } from '@codexo/exojs';\n\nimport type { ImageLayer } from './ImageLayer';\nimport type { ImageLayerNode } from './ImageLayerNode';\nimport type { TileLayer } from './TileLayer';\nimport type { TileLayerNode } from './TileLayerNode';\n\n/**\n * A named, ordered group of layer nodes ({@link TileLayerNode}s and\n * {@link ImageLayerNode}s) produced by a {@link TileMapView} for ergonomic\n * actor interleaving.\n *\n * A band is a plain {@link Container} scene node that the application parents\n * wherever it wants (typically directly under its own world root). Bands are\n * composition units only: a band owns **its generated layer nodes** and\n * never application actors. Placing actors *between* bands is done by parenting\n * the bands and the actor containers as siblings in the desired document order:\n *\n * ```ts\n * worldRoot.addChild(view.band('ground'), actors, view.band('roof'));\n * ```\n *\n * **Rendering order within a band always follows map document order**\n * ({@link import('./TileMap').TileMap.renderableLayers}), not the order layers\n * were listed in the band definition - band membership *selects* layers; it\n * never reorders them. Tile and image members interleave exactly as the map's\n * combined document order dictates.\n *\n * **Ownership:** the band owns the layer nodes it was created with. Destroying\n * the band destroys those layer nodes (and their cached chunk geometry) and\n * detaches the band from its application parent - it never touches application\n * actors, sibling bands, the {@link TileMap}, the {@link TileLayer}s /\n * {@link ImageLayer}s, or Loader-owned textures.\n *\n * Bounds are the union of the band's layer-node bounds (an empty band\n * collapses to a degenerate rect at the band's transformed origin).\n *\n * Bands are created by {@link TileMapView}; construct them through\n * {@link TileMapView} rather than directly.\n *\n * @advanced\n */\nexport class TileMapBand extends Container {\n /**\n * The band name (unique within its owning {@link TileMapView}). Narrows the\n * inherited {@link SceneNode.name} from `string | null` to a required string;\n * assigned once at construction.\n */\n public override name = '';\n\n private readonly _layerNodes: Array<TileLayerNode | ImageLayerNode>;\n private _destroyed = false;\n\n /**\n * @param name The band name (unique within its owning view).\n * @param layerNodes The layer nodes composing this band, already ordered by\n * map document order. Adopted as children.\n * @internal Constructed by {@link TileMapView}.\n */\n public constructor(name: string, layerNodes: ReadonlyArray<TileLayerNode | ImageLayerNode>) {\n super();\n\n this.name = name;\n this._layerNodes = [...layerNodes];\n\n for (const node of this._layerNodes) {\n this.addChild(node);\n }\n }\n\n /**\n * The layer nodes that compose this band, in map document order - tile and\n * image members interleaved. This is the band's **membership** list (the\n * nodes it owns and destroys); it may differ from {@link Container.children}\n * if the caller reparents an individual layer node elsewhere.\n */\n public get layerNodes(): ReadonlyArray<TileLayerNode | ImageLayerNode> {\n return this._layerNodes;\n }\n\n /**\n * Find this band's layer node rendering the layer with the given id (tile or\n * image member; first match in document order).\n */\n public getLayerNodeById(id: number): TileLayerNode | ImageLayerNode | undefined {\n return this._layerNodes.find(node => node.layer.id === id);\n }\n\n /** Whether this band currently owns no layer nodes. */\n public get isEmpty(): boolean {\n return this._layerNodes.length === 0;\n }\n\n /**\n * Bounds are the union of the band's visible layer-node bounds. With no\n * visible children the band collapses to a degenerate rect at its transformed\n * origin (rather than the whole-subtree-plus-origin union a bare Container\n * would report).\n */\n public override updateBounds(): this {\n this._bounds.reset();\n\n let hasVisibleChild = false;\n\n for (const child of this.children) {\n if (child.visible) {\n this._bounds.addRect(child.getBounds());\n hasVisibleChild = true;\n }\n }\n\n if (!hasVisibleChild) {\n this._bounds.addRect(this.getLocalBounds(), this.getGlobalTransform());\n }\n\n return this;\n }\n\n /**\n * Adopt a freshly created layer node into this band (used by\n * {@link TileMapView.refreshLayers} when a newly added map layer joins this\n * band). Appended; call {@link TileMapBand._reorder} afterwards to restore\n * map document order.\n * @internal\n */\n public _adopt(node: TileLayerNode | ImageLayerNode): void {\n if (!this._layerNodes.includes(node)) {\n this._layerNodes.push(node);\n }\n\n this.addChild(node);\n }\n\n /**\n * Drop a layer node from this band's membership without destroying it (used\n * when its map layer was removed; the view destroys the node separately).\n * @internal\n */\n public _release(node: TileLayerNode | ImageLayerNode): void {\n const index = this._layerNodes.indexOf(node);\n\n if (index !== -1) {\n this._layerNodes.splice(index, 1);\n }\n\n if (node.parent === this) {\n this.removeChild(node);\n }\n }\n\n /**\n * Reorder this band's membership and its still-parented children to map\n * document order. `documentIndex` maps a layer **instance** to its index in\n * the map's combined document order - keyed by instance rather than id\n * because a tile layer and an image layer may share an id in fallback-ordered\n * maps. Layer nodes the caller has reparented away from this band keep their\n * membership (for ownership) but are not re-adopted.\n * @internal\n */\n public _reorder(documentIndex: ReadonlyMap<TileLayer | ImageLayer, number>): void {\n this._layerNodes.sort((a, b) => (documentIndex.get(a.layer) ?? 0) - (documentIndex.get(b.layer) ?? 0));\n\n for (const node of this._layerNodes) {\n if (node.parent === this) {\n this.addChild(node);\n }\n }\n }\n\n /**\n * Destroy the band: detach it from its application parent, then destroy the\n * layer nodes it owns (freeing their chunk geometry / image sprites).\n * Application actors, sibling bands, the map, layers, and Loader-owned\n * textures are untouched.\n *\n * Idempotent: a second call (e.g. when {@link TileMapView.destroy} runs after\n * the application already destroyed this band directly) is a safe no-op.\n */\n public override destroy(): void {\n if (this._destroyed) {\n return;\n }\n this._destroyed = true;\n\n this.parent?.removeChild(this);\n\n const owned = [...this._layerNodes];\n\n this._layerNodes.length = 0;\n\n super.destroy();\n\n for (const node of owned) {\n node.parent?.removeChild(node);\n node.destroy();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,cAAb,cAAiC,UAAU;;;;;;CAMzC,AAAgB,OAAO;CAEvB,AAAiB;CACjB,AAAQ,aAAa;;;;;;;CAQrB,AAAO,YAAY,MAAc,YAA2D;EAC1F,MAAM;EAEN,KAAK,OAAO;EACZ,KAAK,cAAc,CAAC,GAAG,UAAU;EAEjC,KAAK,MAAM,QAAQ,KAAK,aACtB,KAAK,SAAS,IAAI;CAEtB;;;;;;;CAQA,IAAW,aAA4D;EACrE,OAAO,KAAK;CACd;;;;;CAMA,AAAO,iBAAiB,IAAwD;EAC9E,OAAO,KAAK,YAAY,MAAK,SAAQ,KAAK,MAAM,OAAO,EAAE;CAC3D;;CAGA,IAAW,UAAmB;EAC5B,OAAO,KAAK,YAAY,WAAW;CACrC;;;;;;;CAQA,AAAgB,eAAqB;EACnC,KAAK,QAAQ,MAAM;EAEnB,IAAI,kBAAkB;EAEtB,KAAK,MAAM,SAAS,KAAK,UACvB,IAAI,MAAM,SAAS;GACjB,KAAK,QAAQ,QAAQ,MAAM,UAAU,CAAC;GACtC,kBAAkB;EACpB;EAGF,IAAI,CAAC,iBACH,KAAK,QAAQ,QAAQ,KAAK,eAAe,GAAG,KAAK,mBAAmB,CAAC;EAGvE,OAAO;CACT;;;;;;;;CASA,AAAO,OAAO,MAA4C;EACxD,IAAI,CAAC,KAAK,YAAY,SAAS,IAAI,GACjC,KAAK,YAAY,KAAK,IAAI;EAG5B,KAAK,SAAS,IAAI;CACpB;;;;;;CAOA,AAAO,SAAS,MAA4C;EAC1D,MAAM,QAAQ,KAAK,YAAY,QAAQ,IAAI;EAE3C,IAAI,UAAU,IACZ,KAAK,YAAY,OAAO,OAAO,CAAC;EAGlC,IAAI,KAAK,WAAW,MAClB,KAAK,YAAY,IAAI;CAEzB;;;;;;;;;;CAWA,AAAO,SAAS,eAAkE;EAChF,KAAK,YAAY,MAAM,GAAG,OAAO,cAAc,IAAI,EAAE,KAAK,KAAK,MAAM,cAAc,IAAI,EAAE,KAAK,KAAK,EAAE;EAErG,KAAK,MAAM,QAAQ,KAAK,aACtB,IAAI,KAAK,WAAW,MAClB,KAAK,SAAS,IAAI;CAGxB;;;;;;;;;;CAWA,AAAgB,UAAgB;EAC9B,IAAI,KAAK,YACP;EAEF,KAAK,aAAa;EAElB,KAAK,QAAQ,YAAY,IAAI;EAE7B,MAAM,QAAQ,CAAC,GAAG,KAAK,WAAW;EAElC,KAAK,YAAY,SAAS;EAE1B,MAAM,QAAQ;EAEd,KAAK,MAAM,QAAQ,OAAO;GACxB,KAAK,QAAQ,YAAY,IAAI;GAC7B,KAAK,QAAQ;EACf;CACF;AACF"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { ReadonlyRectangle } from '@codexo/exojs';
|
|
2
|
-
import { Container } from '@codexo/exojs';
|
|
3
|
-
import { PixelSnapMode } from '@codexo/exojs/renderer-sdk';
|
|
4
|
-
import { ImageLayerNode } from './ImageLayerNode';
|
|
5
|
-
import { TileLayerNode } from './TileLayerNode';
|
|
6
|
-
import type { TileMap } from './TileMap';
|
|
7
|
-
/**
|
|
8
|
-
* Options for a {@link TileMapNode}.
|
|
9
|
-
* @advanced
|
|
10
|
-
*/
|
|
11
|
-
export interface TileMapNodeOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Whether the map's chunk nodes participate in per-chunk view culling.
|
|
14
|
-
* Forwarded to every {@link TileLayerNode}. Defaults to `true`.
|
|
15
|
-
*/
|
|
16
|
-
readonly cullable?: boolean;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* A convenience scene node that renders a whole {@link TileMap} as a
|
|
20
|
-
* {@link Container} of one node per renderable layer - a {@link TileLayerNode}
|
|
21
|
-
* per tile layer and an {@link ImageLayerNode} per image layer, interleaved
|
|
22
|
-
* back-to-front by the map's combined document order
|
|
23
|
-
* ({@link import('./TileMap').TileMap.renderableLayers}).
|
|
24
|
-
*
|
|
25
|
-
* `TileMapNode` owns **only** its layer nodes - never application actors. Use
|
|
26
|
-
* it for the simple, non-interleaved case (no actors between layers); for
|
|
27
|
-
* actor interleaving, place individual `TileLayerNode`s / `ImageLayerNode`s
|
|
28
|
-
* into your own scene graph instead (see `TileMapView`).
|
|
29
|
-
*
|
|
30
|
-
* The node references - but never owns - the {@link TileMap}: destroying the
|
|
31
|
-
* node frees its layer/chunk nodes and their cached GPU geometry, while the
|
|
32
|
-
* `TileMap` data and Loader-owned textures survive (free them via
|
|
33
|
-
* `TileMap.destroy()` / `Loader.destroy()` respectively).
|
|
34
|
-
*
|
|
35
|
-
* Layers added to or removed from the map after construction are reflected only
|
|
36
|
-
* after {@link TileMapNode.refreshLayers}.
|
|
37
|
-
*
|
|
38
|
-
* @advanced
|
|
39
|
-
*/
|
|
40
|
-
export declare class TileMapNode extends Container {
|
|
41
|
-
private readonly _map;
|
|
42
|
-
private readonly _cullChunks;
|
|
43
|
-
private readonly _layerNodes;
|
|
44
|
-
private _pixelSnapMode;
|
|
45
|
-
constructor(map: TileMap, options?: TileMapNodeOptions);
|
|
46
|
-
/** The runtime map this node renders. */
|
|
47
|
-
get map(): TileMap;
|
|
48
|
-
/**
|
|
49
|
-
* Render-only pixel-snap mode applied to every layer (and forwarded to every
|
|
50
|
-
* chunk node, current and rebuilt). Snaps tile chunk origins to the active
|
|
51
|
-
* render target's device-pixel grid for crisp tiles; with integer tile pitch
|
|
52
|
-
* the grid stays exact and adjacent chunks/layers cannot drift apart. Purely
|
|
53
|
-
* visual - tile data, layer offsets, chunk revisions, and culling are
|
|
54
|
-
* unchanged. Setting the current value is a no-op; an invalid value throws and
|
|
55
|
-
* leaves the prior mode unchanged.
|
|
56
|
-
*
|
|
57
|
-
* Defaults to `Geometry` because a tile grid is made of quads that share
|
|
58
|
-
* their edges: left unsnapped, a boundary landing between two device pixels
|
|
59
|
-
* is sampled across both, so the seams blur and shimmer as the view moves.
|
|
60
|
-
* Set `None` to opt out.
|
|
61
|
-
*
|
|
62
|
-
* @default PixelSnapMode.Geometry
|
|
63
|
-
* @stable
|
|
64
|
-
*/
|
|
65
|
-
get pixelSnapMode(): PixelSnapMode;
|
|
66
|
-
set pixelSnapMode(mode: PixelSnapMode);
|
|
67
|
-
/**
|
|
68
|
-
* The layer render nodes - tile and image alike - in the map's combined
|
|
69
|
-
* document order.
|
|
70
|
-
*/
|
|
71
|
-
get layerNodes(): ReadonlyArray<TileLayerNode | ImageLayerNode>;
|
|
72
|
-
/**
|
|
73
|
-
* Find the layer node rendering the named layer (tile or image; first match
|
|
74
|
-
* in document order), or `undefined`.
|
|
75
|
-
*/
|
|
76
|
-
getLayerNode(name: string): TileLayerNode | ImageLayerNode | undefined;
|
|
77
|
-
/**
|
|
78
|
-
* Rebuild the layer-node children from the map's current renderable layers.
|
|
79
|
-
* Call after tile or image layers are structurally added to or removed from
|
|
80
|
-
* the map.
|
|
81
|
-
*/
|
|
82
|
-
refreshLayers(): this;
|
|
83
|
-
/**
|
|
84
|
-
* Recomputed lazily on read, so it writes `_localBounds` directly rather than
|
|
85
|
-
* going through `setLocalBounds`: an invalidating write inside a getter
|
|
86
|
-
* would re-dirty the node on every read.
|
|
87
|
-
*/
|
|
88
|
-
getLocalBounds(): ReadonlyRectangle;
|
|
89
|
-
destroy(): void;
|
|
90
|
-
private _buildLayerNodes;
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=TileMapNode.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TileMapNode.d.ts","sourceRoot":"","sources":["../../src/TileMapNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,WAAY,SAAQ,SAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAU;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6C;IACzE,OAAO,CAAC,cAAc,CAAyC;IAE/D,YAAmB,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,kBAAkB,EAW5D;IAED,yCAAyC;IACzC,IAAW,GAAG,IAAI,OAAO,CAExB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,IAAW,aAAa,IAAI,aAAa,CAExC;IAED,IAAW,aAAa,CAAC,IAAI,EAAE,aAAa,EAW3C;IAED;;;OAGG;IACH,IAAW,UAAU,IAAI,aAAa,CAAC,aAAa,GAAG,cAAc,CAAC,CAErE;IAED;;;OAGG;IACI,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,cAAc,GAAG,SAAS,CAE5E;IAED;;;;OAIG;IACI,aAAa,IAAI,IAAI,CAa3B;IAED;;;;OAIG;IACa,cAAc,IAAI,iBAAiB,CAiBlD;IAEe,OAAO,IAAI,IAAI,CAU9B;IAED,OAAO,CAAC,gBAAgB;CAYzB"}
|
package/dist/esm/TileMapNode.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { ImageLayer } from "./ImageLayer.js";
|
|
2
|
-
import { assertPixelSnapMode } from "./pixelSnap.js";
|
|
3
|
-
import { ImageLayerNode } from "./ImageLayerNode.js";
|
|
4
|
-
import { aggregateChildLocalBounds } from "./nodeBounds.js";
|
|
5
|
-
import { TileLayerNode } from "./TileLayerNode.js";
|
|
6
|
-
import { PixelSnapMode } from "@codexo/exojs/renderer-sdk";
|
|
7
|
-
import { Container } from "@codexo/exojs";
|
|
8
|
-
|
|
9
|
-
//#region src/TileMapNode.ts
|
|
10
|
-
/**
|
|
11
|
-
* A convenience scene node that renders a whole {@link TileMap} as a
|
|
12
|
-
* {@link Container} of one node per renderable layer - a {@link TileLayerNode}
|
|
13
|
-
* per tile layer and an {@link ImageLayerNode} per image layer, interleaved
|
|
14
|
-
* back-to-front by the map's combined document order
|
|
15
|
-
* ({@link import('./TileMap').TileMap.renderableLayers}).
|
|
16
|
-
*
|
|
17
|
-
* `TileMapNode` owns **only** its layer nodes - never application actors. Use
|
|
18
|
-
* it for the simple, non-interleaved case (no actors between layers); for
|
|
19
|
-
* actor interleaving, place individual `TileLayerNode`s / `ImageLayerNode`s
|
|
20
|
-
* into your own scene graph instead (see `TileMapView`).
|
|
21
|
-
*
|
|
22
|
-
* The node references - but never owns - the {@link TileMap}: destroying the
|
|
23
|
-
* node frees its layer/chunk nodes and their cached GPU geometry, while the
|
|
24
|
-
* `TileMap` data and Loader-owned textures survive (free them via
|
|
25
|
-
* `TileMap.destroy()` / `Loader.destroy()` respectively).
|
|
26
|
-
*
|
|
27
|
-
* Layers added to or removed from the map after construction are reflected only
|
|
28
|
-
* after {@link TileMapNode.refreshLayers}.
|
|
29
|
-
*
|
|
30
|
-
* @advanced
|
|
31
|
-
*/
|
|
32
|
-
var TileMapNode = class extends Container {
|
|
33
|
-
_map;
|
|
34
|
-
_cullChunks;
|
|
35
|
-
_layerNodes = [];
|
|
36
|
-
_pixelSnapMode = PixelSnapMode.Geometry;
|
|
37
|
-
constructor(map, options) {
|
|
38
|
-
super();
|
|
39
|
-
this._map = map;
|
|
40
|
-
this._cullChunks = options?.cullable ?? true;
|
|
41
|
-
this._buildLayerNodes();
|
|
42
|
-
if (!this._map.bounded) this.cullable = false;
|
|
43
|
-
}
|
|
44
|
-
/** The runtime map this node renders. */
|
|
45
|
-
get map() {
|
|
46
|
-
return this._map;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Render-only pixel-snap mode applied to every layer (and forwarded to every
|
|
50
|
-
* chunk node, current and rebuilt). Snaps tile chunk origins to the active
|
|
51
|
-
* render target's device-pixel grid for crisp tiles; with integer tile pitch
|
|
52
|
-
* the grid stays exact and adjacent chunks/layers cannot drift apart. Purely
|
|
53
|
-
* visual - tile data, layer offsets, chunk revisions, and culling are
|
|
54
|
-
* unchanged. Setting the current value is a no-op; an invalid value throws and
|
|
55
|
-
* leaves the prior mode unchanged.
|
|
56
|
-
*
|
|
57
|
-
* Defaults to `Geometry` because a tile grid is made of quads that share
|
|
58
|
-
* their edges: left unsnapped, a boundary landing between two device pixels
|
|
59
|
-
* is sampled across both, so the seams blur and shimmer as the view moves.
|
|
60
|
-
* Set `None` to opt out.
|
|
61
|
-
*
|
|
62
|
-
* @default PixelSnapMode.Geometry
|
|
63
|
-
* @stable
|
|
64
|
-
*/
|
|
65
|
-
get pixelSnapMode() {
|
|
66
|
-
return this._pixelSnapMode;
|
|
67
|
-
}
|
|
68
|
-
set pixelSnapMode(mode) {
|
|
69
|
-
if (mode === this._pixelSnapMode) return;
|
|
70
|
-
assertPixelSnapMode(mode);
|
|
71
|
-
this._pixelSnapMode = mode;
|
|
72
|
-
for (const node of this._layerNodes) node.pixelSnapMode = mode;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* The layer render nodes - tile and image alike - in the map's combined
|
|
76
|
-
* document order.
|
|
77
|
-
*/
|
|
78
|
-
get layerNodes() {
|
|
79
|
-
return this._layerNodes;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Find the layer node rendering the named layer (tile or image; first match
|
|
83
|
-
* in document order), or `undefined`.
|
|
84
|
-
*/
|
|
85
|
-
getLayerNode(name) {
|
|
86
|
-
return this._layerNodes.find((node) => node.layer.name === name);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Rebuild the layer-node children from the map's current renderable layers.
|
|
90
|
-
* Call after tile or image layers are structurally added to or removed from
|
|
91
|
-
* the map.
|
|
92
|
-
*/
|
|
93
|
-
refreshLayers() {
|
|
94
|
-
const previous = [...this._layerNodes];
|
|
95
|
-
this.removeChildren();
|
|
96
|
-
this._layerNodes.length = 0;
|
|
97
|
-
for (const node of previous) node.destroy();
|
|
98
|
-
this._buildLayerNodes();
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Recomputed lazily on read, so it writes `_localBounds` directly rather than
|
|
103
|
-
* going through `setLocalBounds`: an invalidating write inside a getter
|
|
104
|
-
* would re-dirty the node on every read.
|
|
105
|
-
*/
|
|
106
|
-
getLocalBounds() {
|
|
107
|
-
const bounds = this._localBounds;
|
|
108
|
-
const { pixelHeight, pixelWidth } = this._map;
|
|
109
|
-
if (this._map.projection.orientation === "isometric") {
|
|
110
|
-
bounds.set(0, 0, 0, 0);
|
|
111
|
-
aggregateChildLocalBounds(this._layerNodes, bounds);
|
|
112
|
-
} else if (pixelWidth !== void 0 && pixelHeight !== void 0) bounds.set(this._map.projection.originX, this._map.projection.originY, pixelWidth, pixelHeight);
|
|
113
|
-
else if (this._layerNodes.length > 0) aggregateChildLocalBounds(this._layerNodes, bounds);
|
|
114
|
-
return bounds;
|
|
115
|
-
}
|
|
116
|
-
destroy() {
|
|
117
|
-
const layerNodes = [...this._layerNodes];
|
|
118
|
-
this._layerNodes.length = 0;
|
|
119
|
-
super.destroy();
|
|
120
|
-
for (const node of layerNodes) node.destroy();
|
|
121
|
-
}
|
|
122
|
-
_buildLayerNodes() {
|
|
123
|
-
for (const layer of this._map.renderableLayers) {
|
|
124
|
-
const node = layer instanceof ImageLayer ? new ImageLayerNode(layer) : new TileLayerNode(layer, { cullable: this._cullChunks });
|
|
125
|
-
node.pixelSnapMode = this._pixelSnapMode;
|
|
126
|
-
this._layerNodes.push(node);
|
|
127
|
-
this.addChild(node);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
//#endregion
|
|
133
|
-
export { TileMapNode };
|
|
134
|
-
//# sourceMappingURL=TileMapNode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TileMapNode.js","names":[],"sources":["../../src/TileMapNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode } from '@codexo/exojs/renderer-sdk';\n\nimport { ImageLayer } from './ImageLayer';\nimport { ImageLayerNode } from './ImageLayerNode';\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport { TileLayerNode } from './TileLayerNode';\nimport type { TileMap } from './TileMap';\n\n/**\n * Options for a {@link TileMapNode}.\n * @advanced\n */\nexport interface TileMapNodeOptions {\n /**\n * Whether the map's chunk nodes participate in per-chunk view culling.\n * Forwarded to every {@link TileLayerNode}. Defaults to `true`.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A convenience scene node that renders a whole {@link TileMap} as a\n * {@link Container} of one node per renderable layer - a {@link TileLayerNode}\n * per tile layer and an {@link ImageLayerNode} per image layer, interleaved\n * back-to-front by the map's combined document order\n * ({@link import('./TileMap').TileMap.renderableLayers}).\n *\n * `TileMapNode` owns **only** its layer nodes - never application actors. Use\n * it for the simple, non-interleaved case (no actors between layers); for\n * actor interleaving, place individual `TileLayerNode`s / `ImageLayerNode`s\n * into your own scene graph instead (see `TileMapView`).\n *\n * The node references - but never owns - the {@link TileMap}: destroying the\n * node frees its layer/chunk nodes and their cached GPU geometry, while the\n * `TileMap` data and Loader-owned textures survive (free them via\n * `TileMap.destroy()` / `Loader.destroy()` respectively).\n *\n * Layers added to or removed from the map after construction are reflected only\n * after {@link TileMapNode.refreshLayers}.\n *\n * @advanced\n */\nexport class TileMapNode extends Container {\n private readonly _map: TileMap;\n private readonly _cullChunks: boolean;\n private readonly _layerNodes: Array<TileLayerNode | ImageLayerNode> = [];\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.Geometry;\n\n public constructor(map: TileMap, options?: TileMapNodeOptions) {\n super();\n\n this._map = map;\n this._cullChunks = options?.cullable ?? true;\n\n this._buildLayerNodes();\n\n if (!this._map.bounded) {\n this.cullable = false;\n }\n }\n\n /** The runtime map this node renders. */\n public get map(): TileMap {\n return this._map;\n }\n\n /**\n * Render-only pixel-snap mode applied to every layer (and forwarded to every\n * chunk node, current and rebuilt). Snaps tile chunk origins to the active\n * render target's device-pixel grid for crisp tiles; with integer tile pitch\n * the grid stays exact and adjacent chunks/layers cannot drift apart. Purely\n * visual - tile data, layer offsets, chunk revisions, and culling are\n * unchanged. Setting the current value is a no-op; an invalid value throws and\n * leaves the prior mode unchanged.\n *\n * Defaults to `Geometry` because a tile grid is made of quads that share\n * their edges: left unsnapped, a boundary landing between two device pixels\n * is sampled across both, so the seams blur and shimmer as the view moves.\n * Set `None` to opt out.\n *\n * @default PixelSnapMode.Geometry\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n for (const node of this._layerNodes) {\n node.pixelSnapMode = mode;\n }\n }\n\n /**\n * The layer render nodes - tile and image alike - in the map's combined\n * document order.\n */\n public get layerNodes(): ReadonlyArray<TileLayerNode | ImageLayerNode> {\n return this._layerNodes;\n }\n\n /**\n * Find the layer node rendering the named layer (tile or image; first match\n * in document order), or `undefined`.\n */\n public getLayerNode(name: string): TileLayerNode | ImageLayerNode | undefined {\n return this._layerNodes.find(node => node.layer.name === name);\n }\n\n /**\n * Rebuild the layer-node children from the map's current renderable layers.\n * Call after tile or image layers are structurally added to or removed from\n * the map.\n */\n public refreshLayers(): this {\n const previous = [...this._layerNodes];\n\n this.removeChildren();\n this._layerNodes.length = 0;\n\n for (const node of previous) {\n node.destroy();\n }\n\n this._buildLayerNodes();\n\n return this;\n }\n\n /**\n * Recomputed lazily on read, so it writes `_localBounds` directly rather than\n * going through `setLocalBounds`: an invalidating write inside a getter\n * would re-dirty the node on every read.\n */\n public override getLocalBounds(): ReadonlyRectangle {\n const bounds = this._localBounds;\n\n // Reading the pixel extents directly (rather than gating on `bounded`)\n // is what narrows them to numbers - `bounded` is a plain boolean getter.\n const { pixelHeight, pixelWidth } = this._map;\n\n if (this._map.projection.orientation === 'isometric') {\n bounds.set(0, 0, 0, 0);\n aggregateChildLocalBounds(this._layerNodes, bounds);\n } else if (pixelWidth !== undefined && pixelHeight !== undefined) {\n bounds.set(this._map.projection.originX, this._map.projection.originY, pixelWidth, pixelHeight);\n } else if (this._layerNodes.length > 0) {\n aggregateChildLocalBounds(this._layerNodes, bounds);\n }\n\n return bounds;\n }\n\n public override destroy(): void {\n const layerNodes = [...this._layerNodes];\n\n this._layerNodes.length = 0;\n\n super.destroy();\n\n for (const node of layerNodes) {\n node.destroy();\n }\n }\n\n private _buildLayerNodes(): void {\n for (const layer of this._map.renderableLayers) {\n const node = layer instanceof ImageLayer ? new ImageLayerNode(layer) : new TileLayerNode(layer, { cullable: this._cullChunks });\n\n // Unconditional: a node built after the map was set to `None` has to\n // inherit that too, not just a non-default mode.\n node.pixelSnapMode = this._pixelSnapMode;\n\n this._layerNodes.push(node);\n this.addChild(node);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,cAAb,cAAiC,UAAU;CACzC,AAAiB;CACjB,AAAiB;CACjB,AAAiB,cAAqD,CAAC;CACvE,AAAQ,iBAAgC,cAAc;CAEtD,AAAO,YAAY,KAAc,SAA8B;EAC7D,MAAM;EAEN,KAAK,OAAO;EACZ,KAAK,cAAc,SAAS,YAAY;EAExC,KAAK,iBAAiB;EAEtB,IAAI,CAAC,KAAK,KAAK,SACb,KAAK,WAAW;CAEpB;;CAGA,IAAW,MAAe;EACxB,OAAO,KAAK;CACd;;;;;;;;;;;;;;;;;;CAmBA,IAAW,gBAA+B;EACxC,OAAO,KAAK;CACd;CAEA,IAAW,cAAc,MAAqB;EAC5C,IAAI,SAAS,KAAK,gBAChB;EAGF,oBAAoB,IAAI;EACxB,KAAK,iBAAiB;EAEtB,KAAK,MAAM,QAAQ,KAAK,aACtB,KAAK,gBAAgB;CAEzB;;;;;CAMA,IAAW,aAA4D;EACrE,OAAO,KAAK;CACd;;;;;CAMA,AAAO,aAAa,MAA0D;EAC5E,OAAO,KAAK,YAAY,MAAK,SAAQ,KAAK,MAAM,SAAS,IAAI;CAC/D;;;;;;CAOA,AAAO,gBAAsB;EAC3B,MAAM,WAAW,CAAC,GAAG,KAAK,WAAW;EAErC,KAAK,eAAe;EACpB,KAAK,YAAY,SAAS;EAE1B,KAAK,MAAM,QAAQ,UACjB,KAAK,QAAQ;EAGf,KAAK,iBAAiB;EAEtB,OAAO;CACT;;;;;;CAOA,AAAgB,iBAAoC;EAClD,MAAM,SAAS,KAAK;EAIpB,MAAM,EAAE,aAAa,eAAe,KAAK;EAEzC,IAAI,KAAK,KAAK,WAAW,gBAAgB,aAAa;GACpD,OAAO,IAAI,GAAG,GAAG,GAAG,CAAC;GACrB,0BAA0B,KAAK,aAAa,MAAM;EACpD,OAAO,IAAI,eAAe,UAAa,gBAAgB,QACrD,OAAO,IAAI,KAAK,KAAK,WAAW,SAAS,KAAK,KAAK,WAAW,SAAS,YAAY,WAAW;OACzF,IAAI,KAAK,YAAY,SAAS,GACnC,0BAA0B,KAAK,aAAa,MAAM;EAGpD,OAAO;CACT;CAEA,AAAgB,UAAgB;EAC9B,MAAM,aAAa,CAAC,GAAG,KAAK,WAAW;EAEvC,KAAK,YAAY,SAAS;EAE1B,MAAM,QAAQ;EAEd,KAAK,MAAM,QAAQ,YACjB,KAAK,QAAQ;CAEjB;CAEA,AAAQ,mBAAyB;EAC/B,KAAK,MAAM,SAAS,KAAK,KAAK,kBAAkB;GAC9C,MAAM,OAAO,iBAAiB,aAAa,IAAI,eAAe,KAAK,IAAI,IAAI,cAAc,OAAO,EAAE,UAAU,KAAK,YAAY,CAAC;GAI9H,KAAK,gBAAgB,KAAK;GAE1B,KAAK,YAAY,KAAK,IAAI;GAC1B,KAAK,SAAS,IAAI;EACpB;CACF;AACF"}
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { PixelSnapMode } from '@codexo/exojs/renderer-sdk';
|
|
2
|
-
import { ImageLayerNode } from './ImageLayerNode';
|
|
3
|
-
import { TileLayerNode } from './TileLayerNode';
|
|
4
|
-
import type { TileMap } from './TileMap';
|
|
5
|
-
import { TileMapBand } from './TileMapBand';
|
|
6
|
-
/**
|
|
7
|
-
* A layer selector inside a {@link TileMapBandDefinition}: either a stable
|
|
8
|
-
* layer **id** (`number`) or a **unique** layer **name** (`string`). Selectors
|
|
9
|
-
* resolve across the map's tile **and** image layers. Names that are shared by
|
|
10
|
-
* more than one layer (of either kind) are rejected as ambiguous - reference
|
|
11
|
-
* such layers by id. An id shared by a tile layer and an image layer (possible
|
|
12
|
-
* only in fallback-ordered maps, which never validated cross-kind uniqueness)
|
|
13
|
-
* is equally ambiguous - reference such layers by a unique name.
|
|
14
|
-
* @advanced
|
|
15
|
-
*/
|
|
16
|
-
export type TileLayerSelector = number | string;
|
|
17
|
-
/**
|
|
18
|
-
* The layers composing one band, by id or unique name, in any order. Tile and
|
|
19
|
-
* image layers may be freely mixed. Rendering order always follows the map's
|
|
20
|
-
* combined document order ({@link import('./TileMap').TileMap.renderableLayers})
|
|
21
|
-
* regardless of the order listed here - a definition *selects* layers, it never
|
|
22
|
-
* reorders them. The band's name is the key it is registered under in
|
|
23
|
-
* {@link TileMapViewOptions.bands}.
|
|
24
|
-
* @advanced
|
|
25
|
-
*/
|
|
26
|
-
export type TileMapBandDefinition = readonly TileLayerSelector[];
|
|
27
|
-
/**
|
|
28
|
-
* Options for a {@link TileMapView}.
|
|
29
|
-
* @advanced
|
|
30
|
-
*/
|
|
31
|
-
export interface TileMapViewOptions {
|
|
32
|
-
/**
|
|
33
|
-
* Named bands, keyed by band name (keys are unique, so duplicate band names
|
|
34
|
-
* cannot occur). Each value lists the layers that compose the band - tile
|
|
35
|
-
* and image layers alike. Layers not listed in any band remain reachable
|
|
36
|
-
* through {@link TileMapView.getLayerNodeById} and friends and are owned
|
|
37
|
-
* directly by the view (no implicit fallback band). The definition is copied
|
|
38
|
-
* and frozen; mutating the caller's object afterwards does not change band
|
|
39
|
-
* assignments.
|
|
40
|
-
*
|
|
41
|
-
* @throws (at construction) on an unknown layer id, an unknown or ambiguous
|
|
42
|
-
* layer name, a cross-kind ambiguous layer id, a layer listed twice within
|
|
43
|
-
* one band, or a layer assigned to more than one band.
|
|
44
|
-
*/
|
|
45
|
-
readonly bands?: Readonly<Record<string, TileMapBandDefinition>>;
|
|
46
|
-
/**
|
|
47
|
-
* Whether the generated {@link TileLayerNode}s' chunks participate in
|
|
48
|
-
* per-chunk view culling. Forwarded to every layer node. Default `true`.
|
|
49
|
-
*/
|
|
50
|
-
readonly cullable?: boolean;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Groups a {@link TileMap}'s layers into independently placeable scene nodes so
|
|
54
|
-
* application actors can be interleaved **between** tile layers.
|
|
55
|
-
*
|
|
56
|
-
* A view produces exactly one canonical {@link TileLayerNode} per map layer
|
|
57
|
-
* (stable identity, map document order) and, optionally, named {@link TileMapBand}s
|
|
58
|
-
* grouping subsets of those nodes. The application parents the bands / layer
|
|
59
|
-
* nodes wherever it wants - typically as siblings of its own actor containers:
|
|
60
|
-
*
|
|
61
|
-
* ```ts
|
|
62
|
-
* const view = map.createView({ bands: { ground: ['background', 'ground'], roof: ['roofs'] } });
|
|
63
|
-
* worldRoot.addChild(view.band('ground'), actors, view.band('roof'));
|
|
64
|
-
* // or without bands:
|
|
65
|
-
* worldRoot.addChild(view.getLayerNodeById(groundId)!, actors, view.getLayerNodeById(roofId)!);
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* **Actors are application-owned siblings.** A `TileMapView` never adopts or
|
|
69
|
-
* destroys actors. The view is a helper, not a scene node - it does not own the
|
|
70
|
-
* world container, the {@link TileMap}, the {@link TileLayer}s, or tileset
|
|
71
|
-
* textures.
|
|
72
|
-
*
|
|
73
|
-
* **Ownership:** the view owns its generated layer nodes and bands. A layer
|
|
74
|
-
* assigned to a band is owned by that band; an unbanded layer is owned by the
|
|
75
|
-
* view directly. {@link TileMapView.destroy} destroys every band and layer node
|
|
76
|
-
* (detaching them from their application parents) but leaves actors, the map,
|
|
77
|
-
* its layers, and Loader-owned textures untouched. There is no map-replacement
|
|
78
|
-
* mutation API: to swap maps, destroy the old view, construct a new one, and
|
|
79
|
-
* re-parent its bands - the actor tree is never involved.
|
|
80
|
-
*
|
|
81
|
-
* **Image layers.** A view also produces exactly one canonical
|
|
82
|
-
* {@link ImageLayerNode} per {@link TileMap.imageLayers} entry (stable identity,
|
|
83
|
-
* map document order), reachable through {@link imageLayerNodes},
|
|
84
|
-
* {@link getImageLayerNodeById}, and {@link getImageLayerNodeByName}. Image
|
|
85
|
-
* layers are selectable in {@link TileMapViewOptions.bands} exactly like tile
|
|
86
|
-
* layers: a band member list may mix both kinds, and the band stacks its
|
|
87
|
-
* members by the map's combined document order
|
|
88
|
-
* ({@link import('./TileMap').TileMap.renderableLayers}). A banded image node
|
|
89
|
-
* is owned by its band; an unbanded one is owned by the view directly, and the
|
|
90
|
-
* application parents it wherever the image belongs in draw order - the same
|
|
91
|
-
* way actors are interleaved.
|
|
92
|
-
*
|
|
93
|
-
* @advanced
|
|
94
|
-
*/
|
|
95
|
-
export declare class TileMapView {
|
|
96
|
-
private readonly _map;
|
|
97
|
-
private readonly _cullable;
|
|
98
|
-
/** All canonical tile-layer nodes, in map document order. */
|
|
99
|
-
private readonly _layerNodes;
|
|
100
|
-
/** Tile layer id → its canonical layer node. */
|
|
101
|
-
private readonly _layerNodeById;
|
|
102
|
-
/** Bands in definition (insertion) order. */
|
|
103
|
-
private readonly _bands;
|
|
104
|
-
/** Band name → band. */
|
|
105
|
-
private readonly _bandByName;
|
|
106
|
-
/** Original band definitions (frozen) for re-resolution on refresh. */
|
|
107
|
-
private readonly _bandDefs;
|
|
108
|
-
/** Layer node → its owning band (absent = view-owned / unbanded). */
|
|
109
|
-
private readonly _nodeBand;
|
|
110
|
-
/** Unbanded tile-layer nodes owned directly by the view, in map document order. */
|
|
111
|
-
private readonly _directLayerNodes;
|
|
112
|
-
/** All canonical image layer nodes, in map document order. */
|
|
113
|
-
private readonly _imageLayerNodes;
|
|
114
|
-
/** Image layer id → its canonical image layer node. */
|
|
115
|
-
private readonly _imageLayerNodeById;
|
|
116
|
-
private _destroyed;
|
|
117
|
-
private _pixelSnapMode;
|
|
118
|
-
/**
|
|
119
|
-
* @param map The runtime map to compose. Referenced, never owned.
|
|
120
|
-
* @param options Band definitions and culling.
|
|
121
|
-
* @throws When a band definition references an unknown/ambiguous layer or
|
|
122
|
-
* assigns a layer twice / to multiple bands.
|
|
123
|
-
*/
|
|
124
|
-
constructor(map: TileMap, options?: TileMapViewOptions);
|
|
125
|
-
/** The runtime map this view composes. Referenced, never owned. */
|
|
126
|
-
get map(): TileMap;
|
|
127
|
-
/** All canonical tile-layer nodes, one per map tile layer, in map document order. */
|
|
128
|
-
get layers(): readonly TileLayerNode[];
|
|
129
|
-
/** The bands, in definition (insertion) order. */
|
|
130
|
-
get bands(): readonly TileMapBand[];
|
|
131
|
-
/** Whether this view has been destroyed. */
|
|
132
|
-
get destroyed(): boolean;
|
|
133
|
-
/**
|
|
134
|
-
* Render-only pixel-snap mode applied to every layer node this view owns (and
|
|
135
|
-
* forwarded to every chunk drawable, current and rebuilt by
|
|
136
|
-
* {@link refreshLayers}). Snaps tile chunk origins to the active render
|
|
137
|
-
* target's device-pixel grid for crisp tiles; with integer tile pitch the grid
|
|
138
|
-
* stays exact and adjacent chunks cannot drift apart. Purely visual - tile
|
|
139
|
-
* data, layer offsets, chunk revisions, and culling are unchanged. Setting the
|
|
140
|
-
* current value is a no-op; an invalid value throws and leaves the prior mode
|
|
141
|
-
* unchanged.
|
|
142
|
-
*
|
|
143
|
-
* Defaults to `Geometry` because a tile grid is made of quads that share
|
|
144
|
-
* their edges: left unsnapped, a boundary landing between two device pixels
|
|
145
|
-
* is sampled across both, so the seams blur and shimmer as the view moves.
|
|
146
|
-
* Set `None` to opt out.
|
|
147
|
-
*
|
|
148
|
-
* @default PixelSnapMode.Geometry
|
|
149
|
-
* @stable
|
|
150
|
-
*/
|
|
151
|
-
get pixelSnapMode(): PixelSnapMode;
|
|
152
|
-
set pixelSnapMode(mode: PixelSnapMode);
|
|
153
|
-
/**
|
|
154
|
-
* The canonical layer node for the **tile** layer with the given **id**, or
|
|
155
|
-
* `undefined`. Tile ids are authoritative and unique - this is the
|
|
156
|
-
* unambiguous lookup. The returned node may be reparented into the caller's
|
|
157
|
-
* own containers; the view still tracks it for refresh and destruction.
|
|
158
|
-
*/
|
|
159
|
-
getLayerNodeById(id: number): TileLayerNode | undefined;
|
|
160
|
-
/**
|
|
161
|
-
* Every canonical tile-layer node whose layer has the given **name**, in map
|
|
162
|
-
* document order. Layer names are not guaranteed unique, so this returns an
|
|
163
|
-
* array (empty when no layer matches). Prefer {@link getLayerNodeById} when
|
|
164
|
-
* you have the id.
|
|
165
|
-
*/
|
|
166
|
-
getLayerNodesByName(name: string): readonly TileLayerNode[];
|
|
167
|
-
/** All canonical image layer nodes, one per map image layer, in map document order. */
|
|
168
|
-
get imageLayerNodes(): readonly ImageLayerNode[];
|
|
169
|
-
/**
|
|
170
|
-
* The canonical image layer node for the image layer with the given **id**,
|
|
171
|
-
* or `undefined`. Ids are authoritative and unique - this is the unambiguous
|
|
172
|
-
* lookup. The returned node may be reparented into the caller's own
|
|
173
|
-
* containers; the view still tracks it for refresh and destruction.
|
|
174
|
-
*/
|
|
175
|
-
getImageLayerNodeById(id: number): ImageLayerNode | undefined;
|
|
176
|
-
/**
|
|
177
|
-
* The canonical image layer node for the image layer with the given
|
|
178
|
-
* **name**, or `undefined` if no image layer has that name. Prefer
|
|
179
|
-
* {@link getImageLayerNodeById} when you have the id.
|
|
180
|
-
* @throws If more than one image layer shares that name (reference such
|
|
181
|
-
* layers by id instead).
|
|
182
|
-
*/
|
|
183
|
-
getImageLayerNodeByName(name: string): ImageLayerNode | undefined;
|
|
184
|
-
/**
|
|
185
|
-
* The band registered under `name`.
|
|
186
|
-
* @throws If no band with that name was defined.
|
|
187
|
-
*/
|
|
188
|
-
band(name: string): TileMapBand;
|
|
189
|
-
/** Whether a band with the given name was defined. */
|
|
190
|
-
hasBand(name: string): boolean;
|
|
191
|
-
/**
|
|
192
|
-
* Rebuild the view after **structural** map changes (tile or image layers
|
|
193
|
-
* added to or removed from the map). Ordinary tile edits and chunk
|
|
194
|
-
* creation/removal do NOT need this - those are handled by chunk revisions
|
|
195
|
-
* and {@link TileLayerNode.refresh} respectively.
|
|
196
|
-
*
|
|
197
|
-
* - Removed layers (tile or image): their generated node is detached and
|
|
198
|
-
* destroyed.
|
|
199
|
-
* - Unchanged layers: keep their existing node (stable identity).
|
|
200
|
-
* - Added layers (tile or image): a new node is created and assigned to the
|
|
201
|
-
* first band whose definition selects it (by a currently-unambiguous id or
|
|
202
|
-
* name), otherwise owned directly by the view.
|
|
203
|
-
* - Every band's children are re-ordered to the map's combined document
|
|
204
|
-
* order ({@link import('./TileMap').TileMap.renderableLayers}).
|
|
205
|
-
*
|
|
206
|
-
* Application actors are never touched, and bands keep their placement in the
|
|
207
|
-
* application scene graph.
|
|
208
|
-
*
|
|
209
|
-
* @throws If the view has been destroyed.
|
|
210
|
-
*/
|
|
211
|
-
refreshLayers(): this;
|
|
212
|
-
/**
|
|
213
|
-
* Destroy the view: every band, generated tile-layer node, and generated
|
|
214
|
-
* {@link ImageLayerNode} is destroyed (and detached from its application
|
|
215
|
-
* parent), freeing cached chunk geometry. Banded nodes are destroyed by
|
|
216
|
-
* their band; unbanded ones by the view directly. Idempotent. Application
|
|
217
|
-
* actors, sibling content, the {@link TileMap}, its {@link TileLayer}s and
|
|
218
|
-
* image layers, and Loader-owned textures all survive.
|
|
219
|
-
*/
|
|
220
|
-
destroy(): void;
|
|
221
|
-
/** Resolve one band definition into a {@link TileMapBand} and record it. */
|
|
222
|
-
private _defineBand;
|
|
223
|
-
/**
|
|
224
|
-
* Resolve a single selector to a tile or image layer instance, throwing on
|
|
225
|
-
* unknown/ambiguous. Instances (not ids) disambiguate fallback-ordered maps
|
|
226
|
-
* in which a tile layer and an image layer share an id.
|
|
227
|
-
*/
|
|
228
|
-
private _resolveSelector;
|
|
229
|
-
/** The canonical node for a tile or image layer instance, if one exists. */
|
|
230
|
-
private _nodeFor;
|
|
231
|
-
/** Assign a freshly created node to the first band that selects its layer. */
|
|
232
|
-
private _assignNewNode;
|
|
233
|
-
/**
|
|
234
|
-
* Whether a band definition selects the given layer - only by a selector
|
|
235
|
-
* that is currently unambiguous (a unique name, or an id not shared across
|
|
236
|
-
* kinds), mirroring {@link _resolveSelector}'s construction-time rules.
|
|
237
|
-
*/
|
|
238
|
-
private _definitionSelects;
|
|
239
|
-
/** Whether an id currently belongs to both a tile layer and an image layer. */
|
|
240
|
-
private _isCrossKindId;
|
|
241
|
-
/** Detach + destroy a tile node, dropping it from bands and registries. */
|
|
242
|
-
private _removeTileNode;
|
|
243
|
-
/** Detach + destroy an image node, dropping it from bands and registries. */
|
|
244
|
-
private _removeImageNode;
|
|
245
|
-
/** Release a node from its band, or from the view's direct-ownership list. */
|
|
246
|
-
private _releaseFromOwner;
|
|
247
|
-
}
|
|
248
|
-
//# sourceMappingURL=TileMapView.d.ts.map
|