@codexo/exojs-tilemap 0.19.1 → 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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TileMapView.d.ts","sourceRoot":"","sources":["../../src/TileMapView.ts"],"names":[],"mappings":"AAAA,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;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,GAAG,SAAS,iBAAiB,EAAE,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;IACjE;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAU;IAC/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAU;IAEpC,6DAA6D;IAC7D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuB;IACnD,gDAAgD;IAChD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoC;IAEnE,6CAA6C;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAA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MAAM,GAAG,cAAc,GAAG,SAAS,CAYvE;IAED;;;OAGG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAUrC;IAED,sDAAsD;IAC/C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACI,aAAa,IAAI,IAAI,CA4F3B;IAED;;;;;;;OAOG;IACI,OAAO,IAAI,IAAI,CAkCrB;IAID,4EAA4E;IAC5E,OAAO,CAAC,WAAW;IAwCnB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAuCxB,4EAA4E;IAC5E,OAAO,CAAC,QAAQ;IAUhB,8EAA8E;IAC9E,OAAO,CAAC,cAAc;IAatB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAmB1B,+EAA+E;IAC/E,OAAO,CAAC,cAAc;IAItB,2EAA2E;IAC3E,OAAO,CAAC,eAAe;IAevB,6EAA6E;IAC7E,OAAO,CAAC,gBAAgB;IAkBxB,8EAA8E;IAC9E,OAAO,CAAC,iBAAiB;CAc1B"}
|
package/dist/esm/TileMapView.js
DELETED
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
import { ImageLayer } from "./ImageLayer.js";
|
|
2
|
-
import { assertPixelSnapMode } from "./pixelSnap.js";
|
|
3
|
-
import { ImageLayerNode } from "./ImageLayerNode.js";
|
|
4
|
-
import { TileLayerNode } from "./TileLayerNode.js";
|
|
5
|
-
import { TileMapBand } from "./TileMapBand.js";
|
|
6
|
-
import { PixelSnapMode } from "@codexo/exojs/renderer-sdk";
|
|
7
|
-
|
|
8
|
-
//#region src/TileMapView.ts
|
|
9
|
-
/**
|
|
10
|
-
* Groups a {@link TileMap}'s layers into independently placeable scene nodes so
|
|
11
|
-
* application actors can be interleaved **between** tile layers.
|
|
12
|
-
*
|
|
13
|
-
* A view produces exactly one canonical {@link TileLayerNode} per map layer
|
|
14
|
-
* (stable identity, map document order) and, optionally, named {@link TileMapBand}s
|
|
15
|
-
* grouping subsets of those nodes. The application parents the bands / layer
|
|
16
|
-
* nodes wherever it wants - typically as siblings of its own actor containers:
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* const view = map.createView({ bands: { ground: ['background', 'ground'], roof: ['roofs'] } });
|
|
20
|
-
* worldRoot.addChild(view.band('ground'), actors, view.band('roof'));
|
|
21
|
-
* // or without bands:
|
|
22
|
-
* worldRoot.addChild(view.getLayerNodeById(groundId)!, actors, view.getLayerNodeById(roofId)!);
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* **Actors are application-owned siblings.** A `TileMapView` never adopts or
|
|
26
|
-
* destroys actors. The view is a helper, not a scene node - it does not own the
|
|
27
|
-
* world container, the {@link TileMap}, the {@link TileLayer}s, or tileset
|
|
28
|
-
* textures.
|
|
29
|
-
*
|
|
30
|
-
* **Ownership:** the view owns its generated layer nodes and bands. A layer
|
|
31
|
-
* assigned to a band is owned by that band; an unbanded layer is owned by the
|
|
32
|
-
* view directly. {@link TileMapView.destroy} destroys every band and layer node
|
|
33
|
-
* (detaching them from their application parents) but leaves actors, the map,
|
|
34
|
-
* its layers, and Loader-owned textures untouched. There is no map-replacement
|
|
35
|
-
* mutation API: to swap maps, destroy the old view, construct a new one, and
|
|
36
|
-
* re-parent its bands - the actor tree is never involved.
|
|
37
|
-
*
|
|
38
|
-
* **Image layers.** A view also produces exactly one canonical
|
|
39
|
-
* {@link ImageLayerNode} per {@link TileMap.imageLayers} entry (stable identity,
|
|
40
|
-
* map document order), reachable through {@link imageLayerNodes},
|
|
41
|
-
* {@link getImageLayerNodeById}, and {@link getImageLayerNodeByName}. Image
|
|
42
|
-
* layers are selectable in {@link TileMapViewOptions.bands} exactly like tile
|
|
43
|
-
* layers: a band member list may mix both kinds, and the band stacks its
|
|
44
|
-
* members by the map's combined document order
|
|
45
|
-
* ({@link import('./TileMap').TileMap.renderableLayers}). A banded image node
|
|
46
|
-
* is owned by its band; an unbanded one is owned by the view directly, and the
|
|
47
|
-
* application parents it wherever the image belongs in draw order - the same
|
|
48
|
-
* way actors are interleaved.
|
|
49
|
-
*
|
|
50
|
-
* @advanced
|
|
51
|
-
*/
|
|
52
|
-
var TileMapView = class {
|
|
53
|
-
_map;
|
|
54
|
-
_cullable;
|
|
55
|
-
/** All canonical tile-layer nodes, in map document order. */
|
|
56
|
-
_layerNodes = [];
|
|
57
|
-
/** Tile layer id → its canonical layer node. */
|
|
58
|
-
_layerNodeById = /* @__PURE__ */ new Map();
|
|
59
|
-
/** Bands in definition (insertion) order. */
|
|
60
|
-
_bands = [];
|
|
61
|
-
/** Band name → band. */
|
|
62
|
-
_bandByName = /* @__PURE__ */ new Map();
|
|
63
|
-
/** Original band definitions (frozen) for re-resolution on refresh. */
|
|
64
|
-
_bandDefs = [];
|
|
65
|
-
/** Layer node → its owning band (absent = view-owned / unbanded). */
|
|
66
|
-
_nodeBand = /* @__PURE__ */ new Map();
|
|
67
|
-
/** Unbanded tile-layer nodes owned directly by the view, in map document order. */
|
|
68
|
-
_directLayerNodes = [];
|
|
69
|
-
/** All canonical image layer nodes, in map document order. */
|
|
70
|
-
_imageLayerNodes = [];
|
|
71
|
-
/** Image layer id → its canonical image layer node. */
|
|
72
|
-
_imageLayerNodeById = /* @__PURE__ */ new Map();
|
|
73
|
-
_destroyed = false;
|
|
74
|
-
_pixelSnapMode = PixelSnapMode.Geometry;
|
|
75
|
-
/**
|
|
76
|
-
* @param map The runtime map to compose. Referenced, never owned.
|
|
77
|
-
* @param options Band definitions and culling.
|
|
78
|
-
* @throws When a band definition references an unknown/ambiguous layer or
|
|
79
|
-
* assigns a layer twice / to multiple bands.
|
|
80
|
-
*/
|
|
81
|
-
constructor(map, options) {
|
|
82
|
-
this._map = map;
|
|
83
|
-
this._cullable = options?.cullable ?? true;
|
|
84
|
-
for (const layer of map.layers) {
|
|
85
|
-
const node = new TileLayerNode(layer, { cullable: this._cullable });
|
|
86
|
-
this._layerNodes.push(node);
|
|
87
|
-
this._layerNodeById.set(layer.id, node);
|
|
88
|
-
}
|
|
89
|
-
for (const imageLayer of map.imageLayers) {
|
|
90
|
-
const imageNode = new ImageLayerNode(imageLayer);
|
|
91
|
-
this._imageLayerNodes.push(imageNode);
|
|
92
|
-
this._imageLayerNodeById.set(imageLayer.id, imageNode);
|
|
93
|
-
}
|
|
94
|
-
if (options?.bands) for (const [name, selectors] of Object.entries(options.bands)) this._defineBand(name, selectors);
|
|
95
|
-
for (const node of this._layerNodes) if (!this._nodeBand.has(node)) this._directLayerNodes.push(node);
|
|
96
|
-
}
|
|
97
|
-
/** The runtime map this view composes. Referenced, never owned. */
|
|
98
|
-
get map() {
|
|
99
|
-
return this._map;
|
|
100
|
-
}
|
|
101
|
-
/** All canonical tile-layer nodes, one per map tile layer, in map document order. */
|
|
102
|
-
get layers() {
|
|
103
|
-
return this._layerNodes;
|
|
104
|
-
}
|
|
105
|
-
/** The bands, in definition (insertion) order. */
|
|
106
|
-
get bands() {
|
|
107
|
-
return this._bands;
|
|
108
|
-
}
|
|
109
|
-
/** Whether this view has been destroyed. */
|
|
110
|
-
get destroyed() {
|
|
111
|
-
return this._destroyed;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Render-only pixel-snap mode applied to every layer node this view owns (and
|
|
115
|
-
* forwarded to every chunk drawable, current and rebuilt by
|
|
116
|
-
* {@link refreshLayers}). Snaps tile chunk origins to the active render
|
|
117
|
-
* target's device-pixel grid for crisp tiles; with integer tile pitch the grid
|
|
118
|
-
* stays exact and adjacent chunks cannot drift apart. Purely visual - tile
|
|
119
|
-
* data, layer offsets, chunk revisions, and culling are unchanged. Setting the
|
|
120
|
-
* current value is a no-op; an invalid value throws and leaves the prior mode
|
|
121
|
-
* unchanged.
|
|
122
|
-
*
|
|
123
|
-
* Defaults to `Geometry` because a tile grid is made of quads that share
|
|
124
|
-
* their edges: left unsnapped, a boundary landing between two device pixels
|
|
125
|
-
* is sampled across both, so the seams blur and shimmer as the view moves.
|
|
126
|
-
* Set `None` to opt out.
|
|
127
|
-
*
|
|
128
|
-
* @default PixelSnapMode.Geometry
|
|
129
|
-
* @stable
|
|
130
|
-
*/
|
|
131
|
-
get pixelSnapMode() {
|
|
132
|
-
return this._pixelSnapMode;
|
|
133
|
-
}
|
|
134
|
-
set pixelSnapMode(mode) {
|
|
135
|
-
if (mode === this._pixelSnapMode) return;
|
|
136
|
-
assertPixelSnapMode(mode);
|
|
137
|
-
this._pixelSnapMode = mode;
|
|
138
|
-
for (const node of this._layerNodes) node.pixelSnapMode = mode;
|
|
139
|
-
for (const node of this._imageLayerNodes) node.pixelSnapMode = mode;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* The canonical layer node for the **tile** layer with the given **id**, or
|
|
143
|
-
* `undefined`. Tile ids are authoritative and unique - this is the
|
|
144
|
-
* unambiguous lookup. The returned node may be reparented into the caller's
|
|
145
|
-
* own containers; the view still tracks it for refresh and destruction.
|
|
146
|
-
*/
|
|
147
|
-
getLayerNodeById(id) {
|
|
148
|
-
return this._layerNodeById.get(id);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Every canonical tile-layer node whose layer has the given **name**, in map
|
|
152
|
-
* document order. Layer names are not guaranteed unique, so this returns an
|
|
153
|
-
* array (empty when no layer matches). Prefer {@link getLayerNodeById} when
|
|
154
|
-
* you have the id.
|
|
155
|
-
*/
|
|
156
|
-
getLayerNodesByName(name) {
|
|
157
|
-
return this._layerNodes.filter((node) => node.layer.name === name);
|
|
158
|
-
}
|
|
159
|
-
/** All canonical image layer nodes, one per map image layer, in map document order. */
|
|
160
|
-
get imageLayerNodes() {
|
|
161
|
-
return this._imageLayerNodes;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* The canonical image layer node for the image layer with the given **id**,
|
|
165
|
-
* or `undefined`. Ids are authoritative and unique - this is the unambiguous
|
|
166
|
-
* lookup. The returned node may be reparented into the caller's own
|
|
167
|
-
* containers; the view still tracks it for refresh and destruction.
|
|
168
|
-
*/
|
|
169
|
-
getImageLayerNodeById(id) {
|
|
170
|
-
return this._imageLayerNodeById.get(id);
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* The canonical image layer node for the image layer with the given
|
|
174
|
-
* **name**, or `undefined` if no image layer has that name. Prefer
|
|
175
|
-
* {@link getImageLayerNodeById} when you have the id.
|
|
176
|
-
* @throws If more than one image layer shares that name (reference such
|
|
177
|
-
* layers by id instead).
|
|
178
|
-
*/
|
|
179
|
-
getImageLayerNodeByName(name) {
|
|
180
|
-
const matches = this._map.imageLayers.filter((layer) => layer.name === name);
|
|
181
|
-
if (matches.length === 0) return;
|
|
182
|
-
if (matches.length > 1) throw new Error(`TileMapView image layer name "${name}" is ambiguous (${matches.length} image layers share it); reference it by id instead.`);
|
|
183
|
-
return this._imageLayerNodeById.get(matches[0].id);
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* The band registered under `name`.
|
|
187
|
-
* @throws If no band with that name was defined.
|
|
188
|
-
*/
|
|
189
|
-
band(name) {
|
|
190
|
-
const band = this._bandByName.get(name);
|
|
191
|
-
if (!band) throw new Error(`TileMapView has no band named "${name}". Defined bands: ${this._bands.length > 0 ? this._bands.map((b) => `"${b.name}"`).join(", ") : "(none)"}.`);
|
|
192
|
-
return band;
|
|
193
|
-
}
|
|
194
|
-
/** Whether a band with the given name was defined. */
|
|
195
|
-
hasBand(name) {
|
|
196
|
-
return this._bandByName.has(name);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Rebuild the view after **structural** map changes (tile or image layers
|
|
200
|
-
* added to or removed from the map). Ordinary tile edits and chunk
|
|
201
|
-
* creation/removal do NOT need this - those are handled by chunk revisions
|
|
202
|
-
* and {@link TileLayerNode.refresh} respectively.
|
|
203
|
-
*
|
|
204
|
-
* - Removed layers (tile or image): their generated node is detached and
|
|
205
|
-
* destroyed.
|
|
206
|
-
* - Unchanged layers: keep their existing node (stable identity).
|
|
207
|
-
* - Added layers (tile or image): a new node is created and assigned to the
|
|
208
|
-
* first band whose definition selects it (by a currently-unambiguous id or
|
|
209
|
-
* name), otherwise owned directly by the view.
|
|
210
|
-
* - Every band's children are re-ordered to the map's combined document
|
|
211
|
-
* order ({@link import('./TileMap').TileMap.renderableLayers}).
|
|
212
|
-
*
|
|
213
|
-
* Application actors are never touched, and bands keep their placement in the
|
|
214
|
-
* application scene graph.
|
|
215
|
-
*
|
|
216
|
-
* @throws If the view has been destroyed.
|
|
217
|
-
*/
|
|
218
|
-
refreshLayers() {
|
|
219
|
-
if (this._destroyed) throw new Error("Cannot refresh a destroyed TileMapView.");
|
|
220
|
-
const currentLayers = this._map.layers;
|
|
221
|
-
const currentIds = /* @__PURE__ */ new Set();
|
|
222
|
-
for (const layer of currentLayers) currentIds.add(layer.id);
|
|
223
|
-
for (const node of [...this._layerNodes]) if (!currentIds.has(node.layer.id)) this._removeTileNode(node);
|
|
224
|
-
const currentImageLayers = new Set(this._map.imageLayers);
|
|
225
|
-
for (const node of [...this._imageLayerNodes]) if (!currentImageLayers.has(node.layer)) this._removeImageNode(node);
|
|
226
|
-
const newOrder = [];
|
|
227
|
-
for (const layer of currentLayers) {
|
|
228
|
-
let node = this._layerNodeById.get(layer.id);
|
|
229
|
-
if (!node) {
|
|
230
|
-
node = new TileLayerNode(layer, { cullable: this._cullable });
|
|
231
|
-
node.pixelSnapMode = this._pixelSnapMode;
|
|
232
|
-
this._layerNodeById.set(layer.id, node);
|
|
233
|
-
this._assignNewNode(node, layer);
|
|
234
|
-
}
|
|
235
|
-
newOrder.push(node);
|
|
236
|
-
}
|
|
237
|
-
this._layerNodes.length = 0;
|
|
238
|
-
this._layerNodes.push(...newOrder);
|
|
239
|
-
const newImageOrder = [];
|
|
240
|
-
for (const imageLayer of this._map.imageLayers) {
|
|
241
|
-
let node = this._imageLayerNodes.find((candidate) => candidate.layer === imageLayer);
|
|
242
|
-
if (!node) {
|
|
243
|
-
node = new ImageLayerNode(imageLayer);
|
|
244
|
-
node.pixelSnapMode = this._pixelSnapMode;
|
|
245
|
-
this._imageLayerNodeById.set(imageLayer.id, node);
|
|
246
|
-
this._assignNewNode(node, imageLayer);
|
|
247
|
-
}
|
|
248
|
-
newImageOrder.push(node);
|
|
249
|
-
}
|
|
250
|
-
this._imageLayerNodes.length = 0;
|
|
251
|
-
this._imageLayerNodes.push(...newImageOrder);
|
|
252
|
-
const documentIndex = /* @__PURE__ */ new Map();
|
|
253
|
-
for (const [index, layer] of this._map.renderableLayers.entries()) documentIndex.set(layer, index);
|
|
254
|
-
for (const band of this._bands) band._reorder(documentIndex);
|
|
255
|
-
this._directLayerNodes.length = 0;
|
|
256
|
-
for (const node of newOrder) if (!this._nodeBand.has(node)) this._directLayerNodes.push(node);
|
|
257
|
-
return this;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Destroy the view: every band, generated tile-layer node, and generated
|
|
261
|
-
* {@link ImageLayerNode} is destroyed (and detached from its application
|
|
262
|
-
* parent), freeing cached chunk geometry. Banded nodes are destroyed by
|
|
263
|
-
* their band; unbanded ones by the view directly. Idempotent. Application
|
|
264
|
-
* actors, sibling content, the {@link TileMap}, its {@link TileLayer}s and
|
|
265
|
-
* image layers, and Loader-owned textures all survive.
|
|
266
|
-
*/
|
|
267
|
-
destroy() {
|
|
268
|
-
if (this._destroyed) return;
|
|
269
|
-
this._destroyed = true;
|
|
270
|
-
for (const band of this._bands) band.destroy();
|
|
271
|
-
for (const node of this._directLayerNodes) {
|
|
272
|
-
node.parent?.removeChild(node);
|
|
273
|
-
node.destroy();
|
|
274
|
-
}
|
|
275
|
-
for (const node of this._imageLayerNodes) {
|
|
276
|
-
if (this._nodeBand.has(node)) continue;
|
|
277
|
-
node.parent?.removeChild(node);
|
|
278
|
-
node.destroy();
|
|
279
|
-
}
|
|
280
|
-
this._bands.length = 0;
|
|
281
|
-
this._bandByName.clear();
|
|
282
|
-
this._bandDefs.length = 0;
|
|
283
|
-
this._directLayerNodes.length = 0;
|
|
284
|
-
this._layerNodes.length = 0;
|
|
285
|
-
this._layerNodeById.clear();
|
|
286
|
-
this._nodeBand.clear();
|
|
287
|
-
this._imageLayerNodes.length = 0;
|
|
288
|
-
this._imageLayerNodeById.clear();
|
|
289
|
-
}
|
|
290
|
-
/** Resolve one band definition into a {@link TileMapBand} and record it. */
|
|
291
|
-
_defineBand(name, selectors) {
|
|
292
|
-
const members = /* @__PURE__ */ new Set();
|
|
293
|
-
for (const selector of selectors) {
|
|
294
|
-
const layer = this._resolveSelector(name, selector);
|
|
295
|
-
if (members.has(layer)) throw new Error(`TileMapView band "${name}" lists layer ${layer.id} more than once.`);
|
|
296
|
-
const existing = this._nodeFor(layer);
|
|
297
|
-
if (existing && this._nodeBand.has(existing)) throw new Error(`TileMapView layer ${layer.id} is assigned to multiple bands ("${this._nodeBand.get(existing).name}" and "${name}").`);
|
|
298
|
-
members.add(layer);
|
|
299
|
-
}
|
|
300
|
-
const orderedNodes = [];
|
|
301
|
-
for (const layer of this._map.renderableLayers) if (members.has(layer)) orderedNodes.push(this._nodeFor(layer));
|
|
302
|
-
const band = new TileMapBand(name, orderedNodes);
|
|
303
|
-
for (const node of orderedNodes) this._nodeBand.set(node, band);
|
|
304
|
-
this._bands.push(band);
|
|
305
|
-
this._bandByName.set(name, band);
|
|
306
|
-
this._bandDefs.push({
|
|
307
|
-
name,
|
|
308
|
-
selectors: Object.freeze([...selectors])
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Resolve a single selector to a tile or image layer instance, throwing on
|
|
313
|
-
* unknown/ambiguous. Instances (not ids) disambiguate fallback-ordered maps
|
|
314
|
-
* in which a tile layer and an image layer share an id.
|
|
315
|
-
*/
|
|
316
|
-
_resolveSelector(bandName, selector) {
|
|
317
|
-
if (typeof selector === "number") {
|
|
318
|
-
const tileLayer = this._map.getTileLayerById(selector);
|
|
319
|
-
const imageLayer = this._map.imageLayers.find((layer) => layer.id === selector);
|
|
320
|
-
if (tileLayer && imageLayer) throw new Error(`TileMapView band "${bandName}": layer id ${selector} is ambiguous (a tile layer and an image layer share it); reference it by a unique name instead.`);
|
|
321
|
-
const layer = tileLayer ?? imageLayer;
|
|
322
|
-
if (!layer) throw new Error(`TileMapView band "${bandName}": no layer with id ${selector} in map "${this._map.name}".`);
|
|
323
|
-
return layer;
|
|
324
|
-
}
|
|
325
|
-
const matches = [...this._map.layers.filter((layer) => layer.name === selector), ...this._map.imageLayers.filter((layer) => layer.name === selector)];
|
|
326
|
-
if (matches.length === 0) throw new Error(`TileMapView band "${bandName}": no layer named "${selector}" in map "${this._map.name}".`);
|
|
327
|
-
if (matches.length > 1) throw new Error(`TileMapView band "${bandName}": layer name "${selector}" is ambiguous (${matches.length} layers share it); reference it by id instead.`);
|
|
328
|
-
return matches[0];
|
|
329
|
-
}
|
|
330
|
-
/** The canonical node for a tile or image layer instance, if one exists. */
|
|
331
|
-
_nodeFor(layer) {
|
|
332
|
-
if (layer instanceof ImageLayer) return this._imageLayerNodes.find((node) => node.layer === layer);
|
|
333
|
-
return this._layerNodeById.get(layer.id);
|
|
334
|
-
}
|
|
335
|
-
/** Assign a freshly created node to the first band that selects its layer. */
|
|
336
|
-
_assignNewNode(node, layer) {
|
|
337
|
-
for (const def of this._bandDefs) if (this._definitionSelects(def, layer)) {
|
|
338
|
-
const band = this._bandByName.get(def.name);
|
|
339
|
-
band._adopt(node);
|
|
340
|
-
this._nodeBand.set(node, band);
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Whether a band definition selects the given layer - only by a selector
|
|
346
|
-
* that is currently unambiguous (a unique name, or an id not shared across
|
|
347
|
-
* kinds), mirroring {@link _resolveSelector}'s construction-time rules.
|
|
348
|
-
*/
|
|
349
|
-
_definitionSelects(def, layer) {
|
|
350
|
-
for (const selector of def.selectors) if (typeof selector === "number") {
|
|
351
|
-
if (selector === layer.id && !this._isCrossKindId(selector)) return true;
|
|
352
|
-
} else if (selector === layer.name) {
|
|
353
|
-
if (this._map.layers.filter((other) => other.name === selector).length + this._map.imageLayers.filter((other) => other.name === selector).length === 1) return true;
|
|
354
|
-
}
|
|
355
|
-
return false;
|
|
356
|
-
}
|
|
357
|
-
/** Whether an id currently belongs to both a tile layer and an image layer. */
|
|
358
|
-
_isCrossKindId(id) {
|
|
359
|
-
return this._map.getTileLayerById(id) !== void 0 && this._map.imageLayers.some((layer) => layer.id === id);
|
|
360
|
-
}
|
|
361
|
-
/** Detach + destroy a tile node, dropping it from bands and registries. */
|
|
362
|
-
_removeTileNode(node) {
|
|
363
|
-
this._releaseFromOwner(node);
|
|
364
|
-
node.parent?.removeChild(node);
|
|
365
|
-
this._layerNodeById.delete(node.layer.id);
|
|
366
|
-
const orderIndex = this._layerNodes.indexOf(node);
|
|
367
|
-
if (orderIndex !== -1) this._layerNodes.splice(orderIndex, 1);
|
|
368
|
-
node.destroy();
|
|
369
|
-
}
|
|
370
|
-
/** Detach + destroy an image node, dropping it from bands and registries. */
|
|
371
|
-
_removeImageNode(node) {
|
|
372
|
-
this._releaseFromOwner(node);
|
|
373
|
-
node.parent?.removeChild(node);
|
|
374
|
-
if (this._imageLayerNodeById.get(node.layer.id) === node) this._imageLayerNodeById.delete(node.layer.id);
|
|
375
|
-
const orderIndex = this._imageLayerNodes.indexOf(node);
|
|
376
|
-
if (orderIndex !== -1) this._imageLayerNodes.splice(orderIndex, 1);
|
|
377
|
-
node.destroy();
|
|
378
|
-
}
|
|
379
|
-
/** Release a node from its band, or from the view's direct-ownership list. */
|
|
380
|
-
_releaseFromOwner(node) {
|
|
381
|
-
const band = this._nodeBand.get(node);
|
|
382
|
-
if (band) {
|
|
383
|
-
band._release(node);
|
|
384
|
-
this._nodeBand.delete(node);
|
|
385
|
-
} else if (node instanceof TileLayerNode) {
|
|
386
|
-
const directIndex = this._directLayerNodes.indexOf(node);
|
|
387
|
-
if (directIndex !== -1) this._directLayerNodes.splice(directIndex, 1);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
//#endregion
|
|
393
|
-
export { TileMapView };
|
|
394
|
-
//# sourceMappingURL=TileMapView.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TileMapView.js","names":[],"sources":["../../src/TileMapView.ts"],"sourcesContent":["import { PixelSnapMode } from '@codexo/exojs/renderer-sdk';\n\nimport { ImageLayer } from './ImageLayer';\nimport { ImageLayerNode } from './ImageLayerNode';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport type { TileLayer } from './TileLayer';\nimport { TileLayerNode } from './TileLayerNode';\nimport type { TileMap } from './TileMap';\nimport { TileMapBand } from './TileMapBand';\n\n/**\n * A layer selector inside a {@link TileMapBandDefinition}: either a stable\n * layer **id** (`number`) or a **unique** layer **name** (`string`). Selectors\n * resolve across the map's tile **and** image layers. Names that are shared by\n * more than one layer (of either kind) are rejected as ambiguous - reference\n * such layers by id. An id shared by a tile layer and an image layer (possible\n * only in fallback-ordered maps, which never validated cross-kind uniqueness)\n * is equally ambiguous - reference such layers by a unique name.\n * @advanced\n */\nexport type TileLayerSelector = number | string;\n\n/**\n * The layers composing one band, by id or unique name, in any order. Tile and\n * image layers may be freely mixed. Rendering order always follows the map's\n * combined document order ({@link import('./TileMap').TileMap.renderableLayers})\n * regardless of the order listed here - a definition *selects* layers, it never\n * reorders them. The band's name is the key it is registered under in\n * {@link TileMapViewOptions.bands}.\n * @advanced\n */\nexport type TileMapBandDefinition = readonly TileLayerSelector[];\n\n/**\n * Options for a {@link TileMapView}.\n * @advanced\n */\nexport interface TileMapViewOptions {\n /**\n * Named bands, keyed by band name (keys are unique, so duplicate band names\n * cannot occur). Each value lists the layers that compose the band - tile\n * and image layers alike. Layers not listed in any band remain reachable\n * through {@link TileMapView.getLayerNodeById} and friends and are owned\n * directly by the view (no implicit fallback band). The definition is copied\n * and frozen; mutating the caller's object afterwards does not change band\n * assignments.\n *\n * @throws (at construction) on an unknown layer id, an unknown or ambiguous\n * layer name, a cross-kind ambiguous layer id, a layer listed twice within\n * one band, or a layer assigned to more than one band.\n */\n readonly bands?: Readonly<Record<string, TileMapBandDefinition>>;\n /**\n * Whether the generated {@link TileLayerNode}s' chunks participate in\n * per-chunk view culling. Forwarded to every layer node. Default `true`.\n */\n readonly cullable?: boolean;\n}\n\ninterface ResolvedBandDef {\n readonly name: string;\n readonly selectors: TileMapBandDefinition;\n}\n\n/**\n * Groups a {@link TileMap}'s layers into independently placeable scene nodes so\n * application actors can be interleaved **between** tile layers.\n *\n * A view produces exactly one canonical {@link TileLayerNode} per map layer\n * (stable identity, map document order) and, optionally, named {@link TileMapBand}s\n * grouping subsets of those nodes. The application parents the bands / layer\n * nodes wherever it wants - typically as siblings of its own actor containers:\n *\n * ```ts\n * const view = map.createView({ bands: { ground: ['background', 'ground'], roof: ['roofs'] } });\n * worldRoot.addChild(view.band('ground'), actors, view.band('roof'));\n * // or without bands:\n * worldRoot.addChild(view.getLayerNodeById(groundId)!, actors, view.getLayerNodeById(roofId)!);\n * ```\n *\n * **Actors are application-owned siblings.** A `TileMapView` never adopts or\n * destroys actors. The view is a helper, not a scene node - it does not own the\n * world container, the {@link TileMap}, the {@link TileLayer}s, or tileset\n * textures.\n *\n * **Ownership:** the view owns its generated layer nodes and bands. A layer\n * assigned to a band is owned by that band; an unbanded layer is owned by the\n * view directly. {@link TileMapView.destroy} destroys every band and layer node\n * (detaching them from their application parents) but leaves actors, the map,\n * its layers, and Loader-owned textures untouched. There is no map-replacement\n * mutation API: to swap maps, destroy the old view, construct a new one, and\n * re-parent its bands - the actor tree is never involved.\n *\n * **Image layers.** A view also produces exactly one canonical\n * {@link ImageLayerNode} per {@link TileMap.imageLayers} entry (stable identity,\n * map document order), reachable through {@link imageLayerNodes},\n * {@link getImageLayerNodeById}, and {@link getImageLayerNodeByName}. Image\n * layers are selectable in {@link TileMapViewOptions.bands} exactly like tile\n * layers: a band member list may mix both kinds, and the band stacks its\n * members by the map's combined document order\n * ({@link import('./TileMap').TileMap.renderableLayers}). A banded image node\n * is owned by its band; an unbanded one is owned by the view directly, and the\n * application parents it wherever the image belongs in draw order - the same\n * way actors are interleaved.\n *\n * @advanced\n */\nexport class TileMapView {\n private readonly _map: TileMap;\n private readonly _cullable: boolean;\n\n /** All canonical tile-layer nodes, in map document order. */\n private readonly _layerNodes: TileLayerNode[] = [];\n /** Tile layer id → its canonical layer node. */\n private readonly _layerNodeById = new Map<number, TileLayerNode>();\n\n /** Bands in definition (insertion) order. */\n private readonly _bands: TileMapBand[] = [];\n /** Band name → band. */\n private readonly _bandByName = new Map<string, TileMapBand>();\n /** Original band definitions (frozen) for re-resolution on refresh. */\n private readonly _bandDefs: ResolvedBandDef[] = [];\n /** Layer node → its owning band (absent = view-owned / unbanded). */\n private readonly _nodeBand = new Map<TileLayerNode | ImageLayerNode, TileMapBand>();\n /** Unbanded tile-layer nodes owned directly by the view, in map document order. */\n private readonly _directLayerNodes: TileLayerNode[] = [];\n\n /** All canonical image layer nodes, in map document order. */\n private readonly _imageLayerNodes: ImageLayerNode[] = [];\n /** Image layer id → its canonical image layer node. */\n private readonly _imageLayerNodeById = new Map<number, ImageLayerNode>();\n\n private _destroyed = false;\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.Geometry;\n\n /**\n * @param map The runtime map to compose. Referenced, never owned.\n * @param options Band definitions and culling.\n * @throws When a band definition references an unknown/ambiguous layer or\n * assigns a layer twice / to multiple bands.\n */\n public constructor(map: TileMap, options?: TileMapViewOptions) {\n this._map = map;\n this._cullable = options?.cullable ?? true;\n\n for (const layer of map.layers) {\n const node = new TileLayerNode(layer, { cullable: this._cullable });\n\n this._layerNodes.push(node);\n this._layerNodeById.set(layer.id, node);\n }\n\n for (const imageLayer of map.imageLayers) {\n const imageNode = new ImageLayerNode(imageLayer);\n\n this._imageLayerNodes.push(imageNode);\n this._imageLayerNodeById.set(imageLayer.id, imageNode);\n }\n\n if (options?.bands) {\n for (const [name, selectors] of Object.entries(options.bands)) {\n this._defineBand(name, selectors);\n }\n }\n\n for (const node of this._layerNodes) {\n if (!this._nodeBand.has(node)) {\n this._directLayerNodes.push(node);\n }\n }\n }\n\n /** The runtime map this view composes. Referenced, never owned. */\n public get map(): TileMap {\n return this._map;\n }\n\n /** All canonical tile-layer nodes, one per map tile layer, in map document order. */\n public get layers(): readonly TileLayerNode[] {\n return this._layerNodes;\n }\n\n /** The bands, in definition (insertion) order. */\n public get bands(): readonly TileMapBand[] {\n return this._bands;\n }\n\n /** Whether this view has been destroyed. */\n public get destroyed(): boolean {\n return this._destroyed;\n }\n\n /**\n * Render-only pixel-snap mode applied to every layer node this view owns (and\n * forwarded to every chunk drawable, current and rebuilt by\n * {@link refreshLayers}). Snaps tile chunk origins to the active render\n * target's device-pixel grid for crisp tiles; with integer tile pitch the grid\n * stays exact and adjacent chunks cannot drift apart. Purely visual - tile\n * data, layer offsets, chunk revisions, and culling are unchanged. Setting the\n * current value is a no-op; an invalid value throws and leaves the prior mode\n * 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 for (const node of this._imageLayerNodes) {\n node.pixelSnapMode = mode;\n }\n }\n\n /**\n * The canonical layer node for the **tile** layer with the given **id**, or\n * `undefined`. Tile ids are authoritative and unique - this is the\n * unambiguous lookup. The returned node may be reparented into the caller's\n * own containers; the view still tracks it for refresh and destruction.\n */\n public getLayerNodeById(id: number): TileLayerNode | undefined {\n return this._layerNodeById.get(id);\n }\n\n /**\n * Every canonical tile-layer node whose layer has the given **name**, in map\n * document order. Layer names are not guaranteed unique, so this returns an\n * array (empty when no layer matches). Prefer {@link getLayerNodeById} when\n * you have the id.\n */\n public getLayerNodesByName(name: string): readonly TileLayerNode[] {\n return this._layerNodes.filter(node => node.layer.name === name);\n }\n\n /** All canonical image layer nodes, one per map image layer, in map document order. */\n public get imageLayerNodes(): readonly ImageLayerNode[] {\n return this._imageLayerNodes;\n }\n\n /**\n * The canonical image layer node for the image layer with the given **id**,\n * or `undefined`. Ids are authoritative and unique - this is the unambiguous\n * lookup. The returned node may be reparented into the caller's own\n * containers; the view still tracks it for refresh and destruction.\n */\n public getImageLayerNodeById(id: number): ImageLayerNode | undefined {\n return this._imageLayerNodeById.get(id);\n }\n\n /**\n * The canonical image layer node for the image layer with the given\n * **name**, or `undefined` if no image layer has that name. Prefer\n * {@link getImageLayerNodeById} when you have the id.\n * @throws If more than one image layer shares that name (reference such\n * layers by id instead).\n */\n public getImageLayerNodeByName(name: string): ImageLayerNode | undefined {\n const matches = this._map.imageLayers.filter(layer => layer.name === name);\n\n if (matches.length === 0) {\n return undefined;\n }\n\n if (matches.length > 1) {\n throw new Error(`TileMapView image layer name \"${name}\" is ambiguous ` + `(${matches.length} image layers share it); reference it by id instead.`);\n }\n\n return this._imageLayerNodeById.get(matches[0]!.id);\n }\n\n /**\n * The band registered under `name`.\n * @throws If no band with that name was defined.\n */\n public band(name: string): TileMapBand {\n const band = this._bandByName.get(name);\n\n if (!band) {\n throw new Error(\n `TileMapView has no band named \"${name}\". Defined bands: ${this._bands.length > 0 ? this._bands.map(b => `\"${b.name}\"`).join(', ') : '(none)'}.`,\n );\n }\n\n return band;\n }\n\n /** Whether a band with the given name was defined. */\n public hasBand(name: string): boolean {\n return this._bandByName.has(name);\n }\n\n /**\n * Rebuild the view after **structural** map changes (tile or image layers\n * added to or removed from the map). Ordinary tile edits and chunk\n * creation/removal do NOT need this - those are handled by chunk revisions\n * and {@link TileLayerNode.refresh} respectively.\n *\n * - Removed layers (tile or image): their generated node is detached and\n * destroyed.\n * - Unchanged layers: keep their existing node (stable identity).\n * - Added layers (tile or image): a new node is created and assigned to the\n * first band whose definition selects it (by a currently-unambiguous id or\n * name), otherwise owned directly by the view.\n * - Every band's children are re-ordered to the map's combined document\n * order ({@link import('./TileMap').TileMap.renderableLayers}).\n *\n * Application actors are never touched, and bands keep their placement in the\n * application scene graph.\n *\n * @throws If the view has been destroyed.\n */\n public refreshLayers(): this {\n if (this._destroyed) {\n throw new Error('Cannot refresh a destroyed TileMapView.');\n }\n\n const currentLayers = this._map.layers;\n const currentIds = new Set<number>();\n\n for (const layer of currentLayers) {\n currentIds.add(layer.id);\n }\n\n // 1. Remove nodes whose layer no longer exists.\n for (const node of [...this._layerNodes]) {\n if (!currentIds.has(node.layer.id)) {\n this._removeTileNode(node);\n }\n }\n\n const currentImageLayers = new Set(this._map.imageLayers);\n\n for (const node of [...this._imageLayerNodes]) {\n if (!currentImageLayers.has(node.layer)) {\n this._removeImageNode(node);\n }\n }\n\n // 2. Re-derive the doc-ordered node lists, creating + assigning new nodes.\n const newOrder: TileLayerNode[] = [];\n\n for (const layer of currentLayers) {\n let node = this._layerNodeById.get(layer.id);\n\n if (!node) {\n node = new TileLayerNode(layer, { cullable: this._cullable });\n // Unconditional: a node built after the view was set to `None` has to\n // inherit that too, not just a non-default mode.\n node.pixelSnapMode = this._pixelSnapMode;\n\n this._layerNodeById.set(layer.id, node);\n this._assignNewNode(node, layer);\n }\n\n newOrder.push(node);\n }\n\n this._layerNodes.length = 0;\n this._layerNodes.push(...newOrder);\n\n const newImageOrder: ImageLayerNode[] = [];\n\n for (const imageLayer of this._map.imageLayers) {\n let node = this._imageLayerNodes.find(candidate => candidate.layer === imageLayer);\n\n if (!node) {\n node = new ImageLayerNode(imageLayer);\n // Unconditional: a node built after the view was set to `None` has to\n // inherit that too, not just a non-default mode.\n node.pixelSnapMode = this._pixelSnapMode;\n\n this._imageLayerNodeById.set(imageLayer.id, node);\n this._assignNewNode(node, imageLayer);\n }\n\n newImageOrder.push(node);\n }\n\n this._imageLayerNodes.length = 0;\n this._imageLayerNodes.push(...newImageOrder);\n\n // 3. Re-order each band's children to the combined document order. Keyed\n // by layer instance: fallback-ordered maps may share an id across kinds.\n const documentIndex = new Map<TileLayer | ImageLayer, number>();\n\n for (const [index, layer] of this._map.renderableLayers.entries()) {\n documentIndex.set(layer, index);\n }\n\n for (const band of this._bands) {\n band._reorder(documentIndex);\n }\n\n // 4. Rebuild the unbanded set in doc order.\n this._directLayerNodes.length = 0;\n\n for (const node of newOrder) {\n if (!this._nodeBand.has(node)) {\n this._directLayerNodes.push(node);\n }\n }\n\n return this;\n }\n\n /**\n * Destroy the view: every band, generated tile-layer node, and generated\n * {@link ImageLayerNode} is destroyed (and detached from its application\n * parent), freeing cached chunk geometry. Banded nodes are destroyed by\n * their band; unbanded ones by the view directly. Idempotent. Application\n * actors, sibling content, the {@link TileMap}, its {@link TileLayer}s and\n * image layers, and Loader-owned textures all survive.\n */\n public destroy(): void {\n if (this._destroyed) {\n return;\n }\n\n this._destroyed = true;\n\n for (const band of this._bands) {\n band.destroy();\n }\n\n for (const node of this._directLayerNodes) {\n node.parent?.removeChild(node);\n node.destroy();\n }\n\n for (const node of this._imageLayerNodes) {\n if (this._nodeBand.has(node)) {\n continue; // Owned and already destroyed by its band.\n }\n\n node.parent?.removeChild(node);\n node.destroy();\n }\n\n this._bands.length = 0;\n this._bandByName.clear();\n this._bandDefs.length = 0;\n this._directLayerNodes.length = 0;\n this._layerNodes.length = 0;\n this._layerNodeById.clear();\n this._nodeBand.clear();\n this._imageLayerNodes.length = 0;\n this._imageLayerNodeById.clear();\n }\n\n // ── Internals ──────────────────────────────────────────────────────────\n\n /** Resolve one band definition into a {@link TileMapBand} and record it. */\n private _defineBand(name: string, selectors: TileMapBandDefinition): void {\n const members = new Set<TileLayer | ImageLayer>();\n\n for (const selector of selectors) {\n const layer = this._resolveSelector(name, selector);\n\n if (members.has(layer)) {\n throw new Error(`TileMapView band \"${name}\" lists layer ${layer.id} more than once.`);\n }\n\n const existing = this._nodeFor(layer);\n\n if (existing && this._nodeBand.has(existing)) {\n throw new Error(`TileMapView layer ${layer.id} is assigned to multiple bands ` + `(\"${this._nodeBand.get(existing)!.name}\" and \"${name}\").`);\n }\n\n members.add(layer);\n }\n\n // Order members by combined document order (membership selects; doc order\n // renders - tile and image members interleave).\n const orderedNodes: Array<TileLayerNode | ImageLayerNode> = [];\n\n for (const layer of this._map.renderableLayers) {\n if (members.has(layer)) {\n orderedNodes.push(this._nodeFor(layer)!);\n }\n }\n\n const band = new TileMapBand(name, orderedNodes);\n\n for (const node of orderedNodes) {\n this._nodeBand.set(node, band);\n }\n\n this._bands.push(band);\n this._bandByName.set(name, band);\n this._bandDefs.push({ name, selectors: Object.freeze([...selectors]) });\n }\n\n /**\n * Resolve a single selector to a tile or image layer instance, throwing on\n * unknown/ambiguous. Instances (not ids) disambiguate fallback-ordered maps\n * in which a tile layer and an image layer share an id.\n */\n private _resolveSelector(bandName: string, selector: TileLayerSelector): TileLayer | ImageLayer {\n if (typeof selector === 'number') {\n const tileLayer = this._map.getTileLayerById(selector);\n const imageLayer = this._map.imageLayers.find(layer => layer.id === selector);\n\n if (tileLayer && imageLayer) {\n throw new Error(\n `TileMapView band \"${bandName}\": layer id ${selector} is ambiguous ` +\n `(a tile layer and an image layer share it); reference it by a unique name instead.`,\n );\n }\n\n const layer = tileLayer ?? imageLayer;\n\n if (!layer) {\n throw new Error(`TileMapView band \"${bandName}\": no layer with id ${selector} in map \"${this._map.name}\".`);\n }\n\n return layer;\n }\n\n const matches: Array<TileLayer | ImageLayer> = [\n ...this._map.layers.filter(layer => layer.name === selector),\n ...this._map.imageLayers.filter(layer => layer.name === selector),\n ];\n\n if (matches.length === 0) {\n throw new Error(`TileMapView band \"${bandName}\": no layer named \"${selector}\" in map \"${this._map.name}\".`);\n }\n\n if (matches.length > 1) {\n throw new Error(\n `TileMapView band \"${bandName}\": layer name \"${selector}\" is ambiguous ` + `(${matches.length} layers share it); reference it by id instead.`,\n );\n }\n\n return matches[0]!;\n }\n\n /** The canonical node for a tile or image layer instance, if one exists. */\n private _nodeFor(layer: TileLayer | ImageLayer): TileLayerNode | ImageLayerNode | undefined {\n if (layer instanceof ImageLayer) {\n // Instance scan rather than the id map: image ids are not validated\n // unique, and fallback maps may collide with tile ids anyway.\n return this._imageLayerNodes.find(node => node.layer === layer);\n }\n\n return this._layerNodeById.get(layer.id);\n }\n\n /** Assign a freshly created node to the first band that selects its layer. */\n private _assignNewNode(node: TileLayerNode | ImageLayerNode, layer: TileLayer | ImageLayer): void {\n for (const def of this._bandDefs) {\n if (this._definitionSelects(def, layer)) {\n const band = this._bandByName.get(def.name)!;\n\n band._adopt(node);\n this._nodeBand.set(node, band);\n\n return;\n }\n }\n }\n\n /**\n * Whether a band definition selects the given layer - only by a selector\n * that is currently unambiguous (a unique name, or an id not shared across\n * kinds), mirroring {@link _resolveSelector}'s construction-time rules.\n */\n private _definitionSelects(def: ResolvedBandDef, layer: TileLayer | ImageLayer): boolean {\n for (const selector of def.selectors) {\n if (typeof selector === 'number') {\n if (selector === layer.id && !this._isCrossKindId(selector)) {\n return true;\n }\n } else if (selector === layer.name) {\n const sameName =\n this._map.layers.filter(other => other.name === selector).length + this._map.imageLayers.filter(other => other.name === selector).length;\n\n if (sameName === 1) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n /** Whether an id currently belongs to both a tile layer and an image layer. */\n private _isCrossKindId(id: number): boolean {\n return this._map.getTileLayerById(id) !== undefined && this._map.imageLayers.some(layer => layer.id === id);\n }\n\n /** Detach + destroy a tile node, dropping it from bands and registries. */\n private _removeTileNode(node: TileLayerNode): void {\n this._releaseFromOwner(node);\n\n node.parent?.removeChild(node);\n this._layerNodeById.delete(node.layer.id);\n\n const orderIndex = this._layerNodes.indexOf(node);\n\n if (orderIndex !== -1) {\n this._layerNodes.splice(orderIndex, 1);\n }\n\n node.destroy();\n }\n\n /** Detach + destroy an image node, dropping it from bands and registries. */\n private _removeImageNode(node: ImageLayerNode): void {\n this._releaseFromOwner(node);\n\n node.parent?.removeChild(node);\n\n if (this._imageLayerNodeById.get(node.layer.id) === node) {\n this._imageLayerNodeById.delete(node.layer.id);\n }\n\n const orderIndex = this._imageLayerNodes.indexOf(node);\n\n if (orderIndex !== -1) {\n this._imageLayerNodes.splice(orderIndex, 1);\n }\n\n node.destroy();\n }\n\n /** Release a node from its band, or from the view's direct-ownership list. */\n private _releaseFromOwner(node: TileLayerNode | ImageLayerNode): void {\n const band = this._nodeBand.get(node);\n\n if (band) {\n band._release(node);\n this._nodeBand.delete(node);\n } else if (node instanceof TileLayerNode) {\n const directIndex = this._directLayerNodes.indexOf(node);\n\n if (directIndex !== -1) {\n this._directLayerNodes.splice(directIndex, 1);\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2GA,IAAa,cAAb,MAAyB;CACvB,AAAiB;CACjB,AAAiB;;CAGjB,AAAiB,cAA+B,CAAC;;CAEjD,AAAiB,iCAAiB,IAAI,IAA2B;;CAGjE,AAAiB,SAAwB,CAAC;;CAE1C,AAAiB,8BAAc,IAAI,IAAyB;;CAE5D,AAAiB,YAA+B,CAAC;;CAEjD,AAAiB,4BAAY,IAAI,IAAiD;;CAElF,AAAiB,oBAAqC,CAAC;;CAGvD,AAAiB,mBAAqC,CAAC;;CAEvD,AAAiB,sCAAsB,IAAI,IAA4B;CAEvE,AAAQ,aAAa;CACrB,AAAQ,iBAAgC,cAAc;;;;;;;CAQtD,AAAO,YAAY,KAAc,SAA8B;EAC7D,KAAK,OAAO;EACZ,KAAK,YAAY,SAAS,YAAY;EAEtC,KAAK,MAAM,SAAS,IAAI,QAAQ;GAC9B,MAAM,OAAO,IAAI,cAAc,OAAO,EAAE,UAAU,KAAK,UAAU,CAAC;GAElE,KAAK,YAAY,KAAK,IAAI;GAC1B,KAAK,eAAe,IAAI,MAAM,IAAI,IAAI;EACxC;EAEA,KAAK,MA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ClB,KAAK,kBAAkB,OAAO,aAAa,CAAC;EAEhD;CACF;AACF"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { TileMapObject } from './ObjectLayer';
|
|
2
|
-
/** Immutable grid geometry shared by a map and its independently usable layers. */
|
|
3
|
-
export interface TileProjectionOptions {
|
|
4
|
-
/** Orthogonal is the default. Isometric cells are diamonds with the given pixel dimensions. */
|
|
5
|
-
readonly orientation?: 'orthogonal' | 'isometric';
|
|
6
|
-
readonly tileWidth: number;
|
|
7
|
-
readonly tileHeight: number;
|
|
8
|
-
/** Display position of grid vertex (0, 0). Defaults to zero. */
|
|
9
|
-
readonly originX?: number;
|
|
10
|
-
readonly originY?: number;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Converts between grid vertices, display pixels and unprojected logical pixels.
|
|
14
|
-
* Isometric logical cells are squares of side `tileHeight`; orthogonal logical
|
|
15
|
-
* coordinates are display coordinates before the origin translation.
|
|
16
|
-
*/
|
|
17
|
-
export declare class TileProjection {
|
|
18
|
-
readonly orientation: 'orthogonal' | 'isometric';
|
|
19
|
-
readonly tileWidth: number;
|
|
20
|
-
readonly tileHeight: number;
|
|
21
|
-
readonly originX: number;
|
|
22
|
-
readonly originY: number;
|
|
23
|
-
constructor(options: TileProjectionOptions);
|
|
24
|
-
/** Width of a cell in the unprojected simulation space. */
|
|
25
|
-
get logicalTileWidth(): number;
|
|
26
|
-
get logicalTileHeight(): number;
|
|
27
|
-
/** Maps a grid vertex, including fractional coordinates, to display pixels. */
|
|
28
|
-
tileToPixel(tx: number, ty: number): {
|
|
29
|
-
x: number;
|
|
30
|
-
y: number;
|
|
31
|
-
};
|
|
32
|
-
/** Picks the half-open cell containing a display point; negative cells are valid. */
|
|
33
|
-
pixelToTile(x: number, y: number): {
|
|
34
|
-
tx: number;
|
|
35
|
-
ty: number;
|
|
36
|
-
};
|
|
37
|
-
/** Projects a logical position; layer offsets and scene transforms are separate. */
|
|
38
|
-
logicalToPixel(x: number, y: number): {
|
|
39
|
-
x: number;
|
|
40
|
-
y: number;
|
|
41
|
-
};
|
|
42
|
-
/** Inverts display projection without quantizing to a cell. */
|
|
43
|
-
pixelToLogical(x: number, y: number): {
|
|
44
|
-
x: number;
|
|
45
|
-
y: number;
|
|
46
|
-
};
|
|
47
|
-
/** Display AABB of a cell region, excluding artwork overhang and layer offsets. */
|
|
48
|
-
getBounds(tx: number, ty: number, width: number, height: number): {
|
|
49
|
-
x: number;
|
|
50
|
-
y: number;
|
|
51
|
-
width: number;
|
|
52
|
-
height: number;
|
|
53
|
-
};
|
|
54
|
-
/** Projects logical object geometry; image and text dimensions stay in display pixels. */
|
|
55
|
-
projectObject(object: TileMapObject): TileMapObject;
|
|
56
|
-
/** Inverts object geometry into logical space; affine ellipses remain exact. */
|
|
57
|
-
unprojectObject(object: TileMapObject): TileMapObject;
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=TileProjection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TileProjection.d.ts","sourceRoot":"","sources":["../../src/TileProjection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAInD,mFAAmF;AACnF,MAAM,WAAW,qBAAqB;IACpC,+FAA+F;IAC/F,QAAQ,CAAC,WAAW,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,gEAAgE;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,qBAAa,cAAc;IACzB,SAAgB,WAAW,EAAE,YAAY,GAAG,WAAW,CAAC;IACxD,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,UAAU,EAAE,MAAM,CAAC;I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@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { validatePositiveInteger } from "./types.js";
|
|
2
|
-
import { projectObject } from "./projectObject.js";
|
|
3
|
-
|
|
4
|
-
//#region src/TileProjection.ts
|
|
5
|
-
/**
|
|
6
|
-
* Converts between grid vertices, display pixels and unprojected logical pixels.
|
|
7
|
-
* Isometric logical cells are squares of side `tileHeight`; orthogonal logical
|
|
8
|
-
* coordinates are display coordinates before the origin translation.
|
|
9
|
-
*/
|
|
10
|
-
var TileProjection = class {
|
|
11
|
-
orientation;
|
|
12
|
-
tileWidth;
|
|
13
|
-
tileHeight;
|
|
14
|
-
originX;
|
|
15
|
-
originY;
|
|
16
|
-
constructor(options) {
|
|
17
|
-
validatePositiveInteger(options.tileWidth, "projection.tileWidth");
|
|
18
|
-
validatePositiveInteger(options.tileHeight, "projection.tileHeight");
|
|
19
|
-
this.orientation = options.orientation ?? "orthogonal";
|
|
20
|
-
this.tileWidth = options.tileWidth;
|
|
21
|
-
this.tileHeight = options.tileHeight;
|
|
22
|
-
this.originX = options.originX ?? 0;
|
|
23
|
-
this.originY = options.originY ?? 0;
|
|
24
|
-
if (!Number.isFinite(this.originX) || !Number.isFinite(this.originY)) throw new Error("TileProjection origin must be finite.");
|
|
25
|
-
}
|
|
26
|
-
/** Width of a cell in the unprojected simulation space. */
|
|
27
|
-
get logicalTileWidth() {
|
|
28
|
-
return this.orientation === "isometric" ? this.tileHeight : this.tileWidth;
|
|
29
|
-
}
|
|
30
|
-
get logicalTileHeight() {
|
|
31
|
-
return this.tileHeight;
|
|
32
|
-
}
|
|
33
|
-
/** Maps a grid vertex, including fractional coordinates, to display pixels. */
|
|
34
|
-
tileToPixel(tx, ty) {
|
|
35
|
-
return this.orientation === "isometric" ? {
|
|
36
|
-
x: this.originX + (tx - ty) * this.tileWidth / 2,
|
|
37
|
-
y: this.originY + (tx + ty) * this.tileHeight / 2
|
|
38
|
-
} : {
|
|
39
|
-
x: this.originX + tx * this.tileWidth,
|
|
40
|
-
y: this.originY + ty * this.tileHeight
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/** Picks the half-open cell containing a display point; negative cells are valid. */
|
|
44
|
-
pixelToTile(x, y) {
|
|
45
|
-
const logical = this.pixelToLogical(x, y);
|
|
46
|
-
return {
|
|
47
|
-
tx: Math.floor(logical.x / this.logicalTileWidth),
|
|
48
|
-
ty: Math.floor(logical.y / this.logicalTileHeight)
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
/** Projects a logical position; layer offsets and scene transforms are separate. */
|
|
52
|
-
logicalToPixel(x, y) {
|
|
53
|
-
return this.tileToPixel(x / this.logicalTileWidth, y / this.logicalTileHeight);
|
|
54
|
-
}
|
|
55
|
-
/** Inverts display projection without quantizing to a cell. */
|
|
56
|
-
pixelToLogical(x, y) {
|
|
57
|
-
const dx = x - this.originX;
|
|
58
|
-
const dy = y - this.originY;
|
|
59
|
-
return this.orientation === "isometric" ? {
|
|
60
|
-
x: dy + dx * this.tileHeight / this.tileWidth,
|
|
61
|
-
y: dy - dx * this.tileHeight / this.tileWidth
|
|
62
|
-
} : {
|
|
63
|
-
x: dx,
|
|
64
|
-
y: dy
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
/** Display AABB of a cell region, excluding artwork overhang and layer offsets. */
|
|
68
|
-
getBounds(tx, ty, width, height) {
|
|
69
|
-
const top = this.tileToPixel(tx, ty);
|
|
70
|
-
if (this.orientation === "orthogonal") return {
|
|
71
|
-
...top,
|
|
72
|
-
width: width * this.tileWidth,
|
|
73
|
-
height: height * this.tileHeight
|
|
74
|
-
};
|
|
75
|
-
return {
|
|
76
|
-
x: top.x - height * this.tileWidth / 2,
|
|
77
|
-
y: top.y,
|
|
78
|
-
width: (width + height) * this.tileWidth / 2,
|
|
79
|
-
height: (width + height) * this.tileHeight / 2
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/** Projects logical object geometry; image and text dimensions stay in display pixels. */
|
|
83
|
-
projectObject(object) {
|
|
84
|
-
if (this.orientation === "orthogonal") return object.kind === "tile" ? projectObject(object, 1, 0, 0, 1, this.originX, this.originY) : {
|
|
85
|
-
...object,
|
|
86
|
-
x: object.x + this.originX,
|
|
87
|
-
y: object.y + this.originY
|
|
88
|
-
};
|
|
89
|
-
const ratio = this.tileWidth / (2 * this.tileHeight);
|
|
90
|
-
return projectObject(object, ratio, .5, -ratio, .5, this.originX, this.originY);
|
|
91
|
-
}
|
|
92
|
-
/** Inverts object geometry into logical space; affine ellipses remain exact. */
|
|
93
|
-
unprojectObject(object) {
|
|
94
|
-
if (this.orientation === "orthogonal") return object.kind === "tile" ? projectObject(object, 1, 0, 0, 1, -this.originX, -this.originY) : {
|
|
95
|
-
...object,
|
|
96
|
-
x: object.x - this.originX,
|
|
97
|
-
y: object.y - this.originY
|
|
98
|
-
};
|
|
99
|
-
const ratio = this.tileHeight / this.tileWidth;
|
|
100
|
-
return projectObject(object, ratio, -ratio, 1, 1, -this.originY - this.originX * ratio, -this.originY + this.originX * ratio);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
//#endregion
|
|
105
|
-
export { TileProjection };
|
|
106
|
-
//# sourceMappingURL=TileProjection.js.map
|