mudlet-map-renderer 1.0.0 → 1.2.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 +520 -0
- package/dist/AreaMapRenderer.d.ts +125 -0
- package/dist/CullingManager.d.ts +15 -0
- package/dist/ExitRenderer.d.ts +109 -0
- package/dist/InteractionHandler.d.ts +47 -0
- package/dist/MapGraph.d.ts +28 -0
- package/dist/MapReader-mU_4JWv_.js +224 -0
- package/dist/MapReader-mU_4JWv_.js.map +1 -0
- package/dist/MapState.d.ts +110 -0
- package/dist/PathData.d.ts +18 -0
- package/dist/PathFinder.d.ts +12 -0
- package/dist/ScenePipeline.d.ts +226 -0
- package/dist/SvgTypes.d.ts +21 -0
- package/dist/TypedEventEmitter.d.ts +17 -0
- package/dist/binary/BinaryMapReader.d.ts +36 -0
- package/dist/binary/index.d.ts +2 -0
- package/dist/binary.mjs +34 -0
- package/dist/binary.mjs.map +1 -0
- package/dist/camera/Camera.d.ts +118 -0
- package/dist/coord/CoordFn.d.ts +13 -0
- package/dist/directions.d.ts +25 -0
- package/dist/draw/DrawCommand.d.ts +104 -0
- package/dist/draw/DrawCommandBuilder.d.ts +19 -0
- package/dist/export/CanvasExporter.d.ts +71 -0
- package/dist/export/Exporter.d.ts +58 -0
- package/dist/export/PngExporter.d.ts +23 -0
- package/dist/export/SvgExporter.d.ts +19 -0
- package/dist/export/canvasToBytes.d.ts +19 -0
- package/dist/export/clipSceneToViewport.d.ts +48 -0
- package/dist/export/flushSceneShapes.d.ts +21 -0
- package/dist/export/sceneBounds.d.ts +24 -0
- package/dist/hit/HitTester.d.ts +101 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.mjs +6670 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lens/ExplorationLens.d.ts +29 -0
- package/dist/lens/RoomLens.d.ts +47 -0
- package/dist/lens/composeLenses.d.ts +31 -0
- package/dist/lens/index.d.ts +5 -0
- package/dist/overlay/AmbientLightOverlay.d.ts +32 -0
- package/dist/overlay/LiveEffect.d.ts +33 -0
- package/dist/overlay/SceneOverlay.d.ts +68 -0
- package/dist/reader/Area.d.ts +63 -0
- package/dist/reader/Exit.d.ts +15 -0
- package/dist/reader/MapReader.d.ts +34 -0
- package/dist/reader/Plane.d.ts +33 -0
- package/dist/render/CanvasRenderer.d.ts +17 -0
- package/dist/render/RecordingLayer.d.ts +158 -0
- package/dist/render/SvgRenderer.d.ts +7 -0
- package/dist/render/shapeToRecording.d.ts +3 -0
- package/dist/rendering/KonvaRenderBackend.d.ts +122 -0
- package/dist/rendering/MapRenderer.d.ts +213 -0
- package/dist/rendering/SceneManager.d.ts +54 -0
- package/dist/scene/AmbientLightStyle.d.ts +29 -0
- package/dist/scene/GridStyle.d.ts +21 -0
- package/dist/scene/InnerExitStyle.d.ts +24 -0
- package/dist/scene/OverlayStyle.d.ts +47 -0
- package/dist/scene/RoomStyle.d.ts +32 -0
- package/dist/scene/Shape.d.ts +151 -0
- package/dist/scene/SpecialExitStyle.d.ts +37 -0
- package/dist/scene/StubStyle.d.ts +15 -0
- package/dist/scene/elements/ExitLayout.d.ts +22 -0
- package/dist/scene/elements/GridLayout.d.ts +24 -0
- package/dist/scene/elements/LabelLayout.d.ts +11 -0
- package/dist/scene/elements/OverlayLayout.d.ts +14 -0
- package/dist/scene/elements/RoomLayout.d.ts +19 -0
- package/dist/scene/elements/SpecialExitLayout.d.ts +19 -0
- package/dist/scene/elements/StubLayout.d.ts +19 -0
- package/dist/style/Style.d.ts +60 -0
- package/dist/style/applyStyle.d.ts +3 -0
- package/dist/style/index.d.ts +21 -0
- package/dist/style/shape/BlueprintStyle.d.ts +11 -0
- package/dist/style/shape/ConstructionStyle.d.ts +17 -0
- package/dist/style/shape/IsometricStyle.d.ts +32 -0
- package/dist/style/shape/NeonStyle.d.ts +17 -0
- package/dist/style/shape/ParchmentStyle.d.ts +13 -0
- package/dist/style/shape/SciFiStyle.d.ts +16 -0
- package/dist/style/shape/SketchyStyle.d.ts +22 -0
- package/dist/style/shape/index.d.ts +25 -0
- package/dist/style/shape/paintMap.d.ts +25 -0
- package/dist/style/shape/wobble.d.ts +24 -0
- package/{src/types/MapData.ts → dist/types/MapData.d.ts} +70 -90
- package/dist/types/Settings.d.ts +206 -0
- package/dist/utils/color.d.ts +12 -0
- package/dist/utils/textMeasure.d.ts +38 -0
- package/package.json +67 -37
- package/demo/colors.json +0 -1
- package/demo/index.html +0 -102
- package/demo/main.ts +0 -389
- package/demo/mapExport.json +0 -1
- package/demo/tsconfig.json +0 -11
- package/src/ExitRenderer.ts +0 -275
- package/src/PathFinder.ts +0 -93
- package/src/PathRenderer.ts +0 -129
- package/src/Renderer.ts +0 -374
- package/src/directions.ts +0 -66
- package/src/index.ts +0 -4
- package/src/reader/Area.ts +0 -96
- package/src/reader/Exit.ts +0 -36
- package/src/reader/ExplorationArea.ts +0 -132
- package/src/reader/MapReader.ts +0 -123
- package/src/reader/Plane.ts +0 -42
- package/tsconfig.json +0 -17
- package/vercel.json +0 -5
- package/vite.config.ts +0 -29
- package/vite.demo.config.ts +0 -15
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { default as Konva } from 'konva';
|
|
2
|
+
import { RendererEventMap } from '../types/Settings';
|
|
3
|
+
import { DrawnExitEntry, DrawnSpecialExitEntry, DrawnStubEntry } from '../ScenePipeline';
|
|
4
|
+
import { MapState } from '../MapState';
|
|
5
|
+
import { Camera } from '../camera/Camera';
|
|
6
|
+
import { CullingManager } from '../CullingManager';
|
|
7
|
+
import { TypedEventEmitter } from '../TypedEventEmitter';
|
|
8
|
+
import { InteractiveBackend } from './MapRenderer';
|
|
9
|
+
import { CoordFn } from '../coord/CoordFn';
|
|
10
|
+
import { LiveEffect } from '../overlay/LiveEffect';
|
|
11
|
+
import { SceneOverlay } from '../overlay/SceneOverlay';
|
|
12
|
+
import { ExportCanvas } from '../export/Exporter';
|
|
13
|
+
import { HitTester } from '../hit/HitTester';
|
|
14
|
+
import { Style } from '../style/Style';
|
|
15
|
+
/**
|
|
16
|
+
* Konva rendering engine. Owns the full rendering pipeline:
|
|
17
|
+
* stage, layers, scene builder, culling, overlays.
|
|
18
|
+
*
|
|
19
|
+
* Camera is the source of truth for transform state.
|
|
20
|
+
* This backend subscribes to the camera's `change` event and applies state to the Konva stage.
|
|
21
|
+
*
|
|
22
|
+
* Works identically in both modes:
|
|
23
|
+
* - DOM container → stage attached to DOM, mouse/touch → camera
|
|
24
|
+
* - No container → headless stage, same camera/culling, no input
|
|
25
|
+
*/
|
|
26
|
+
export declare class KonvaRenderBackend implements InteractiveBackend {
|
|
27
|
+
readonly stage: Konva.Stage;
|
|
28
|
+
readonly gridLayer: Konva.Layer;
|
|
29
|
+
readonly linkLayer: Konva.Layer;
|
|
30
|
+
readonly roomLayer: Konva.Layer;
|
|
31
|
+
readonly topLabelLayer: Konva.Layer;
|
|
32
|
+
readonly overlayLayer: Konva.Layer;
|
|
33
|
+
readonly positionLayer: Konva.Layer;
|
|
34
|
+
readonly camera: Camera;
|
|
35
|
+
readonly culling: CullingManager;
|
|
36
|
+
readonly events: TypedEventEmitter<RendererEventMap>;
|
|
37
|
+
private readonly state;
|
|
38
|
+
private readonly container?;
|
|
39
|
+
private readonly positionLayerNode;
|
|
40
|
+
private readonly overlayLayerNode;
|
|
41
|
+
private gridLayerNode;
|
|
42
|
+
private topLabelLayerNode;
|
|
43
|
+
/** Snapped grid bounds last rendered onto gridLayerNode. */
|
|
44
|
+
private gridCachedBounds;
|
|
45
|
+
private sceneManager;
|
|
46
|
+
private currentStyle;
|
|
47
|
+
readonly hitTester: HitTester;
|
|
48
|
+
private lastHitShapes;
|
|
49
|
+
private shapeToDrawEntry;
|
|
50
|
+
private sceneNode;
|
|
51
|
+
/** Lookup from a pipeline-emitted shape to its recording node; rebuilt per buildScene. */
|
|
52
|
+
private shapeToGroup;
|
|
53
|
+
private positionMarker?;
|
|
54
|
+
private highlightShapes;
|
|
55
|
+
private pathShapes;
|
|
56
|
+
private currentRoomOverlay;
|
|
57
|
+
private areaExitHitZones;
|
|
58
|
+
private interactionHandler?;
|
|
59
|
+
private origSetSize?;
|
|
60
|
+
private cameraChangeHandler?;
|
|
61
|
+
private destroyed;
|
|
62
|
+
private _coordinateTransform;
|
|
63
|
+
private coordinateInverse;
|
|
64
|
+
get coordinateTransform(): CoordFn;
|
|
65
|
+
private liveEffects;
|
|
66
|
+
private sceneOverlays;
|
|
67
|
+
private sceneOverlayNodes;
|
|
68
|
+
private viewportSubscribers;
|
|
69
|
+
constructor(state: MapState, container?: HTMLDivElement);
|
|
70
|
+
setStyle(style: Style): void;
|
|
71
|
+
/** Pull forward/inverse coord transforms from the active shape Style. */
|
|
72
|
+
private applyStyleTransforms;
|
|
73
|
+
private styleContext;
|
|
74
|
+
private mapPoint;
|
|
75
|
+
get exitRenderer(): import('../ExitRenderer').default;
|
|
76
|
+
getDrawnExits(): readonly DrawnExitEntry[];
|
|
77
|
+
getDrawnSpecialExits(): readonly DrawnSpecialExitEntry[];
|
|
78
|
+
getDrawnStubs(): readonly DrawnStubEntry[];
|
|
79
|
+
destroy(): void;
|
|
80
|
+
updateBackground(): void;
|
|
81
|
+
exportCanvas(options?: {
|
|
82
|
+
pixelRatio?: number;
|
|
83
|
+
}): ExportCanvas | undefined;
|
|
84
|
+
private applyViewportToStage;
|
|
85
|
+
refresh(): void;
|
|
86
|
+
addLiveEffect(id: string, effect: LiveEffect): void;
|
|
87
|
+
removeLiveEffect(id: string): void;
|
|
88
|
+
addSceneOverlay(id: string, overlay: SceneOverlay): void;
|
|
89
|
+
removeSceneOverlay(id: string): void;
|
|
90
|
+
/** Iterable of scene overlays — used by exporters to apply them over static outputs. */
|
|
91
|
+
getSceneOverlays(): Iterable<SceneOverlay>;
|
|
92
|
+
private createOverlayContext;
|
|
93
|
+
private renderSceneOverlay;
|
|
94
|
+
private clearSceneOverlayNodes;
|
|
95
|
+
private subscribeToState;
|
|
96
|
+
private buildScene;
|
|
97
|
+
/** Wrap a non-group shape and walk to a recording node. */
|
|
98
|
+
private shapeToRecordingNode;
|
|
99
|
+
/**
|
|
100
|
+
* Run the active {@link Style} over `shape`, walk every result through
|
|
101
|
+
* {@link shapeToRecording}, and add it to `layerNode`. Returns the first
|
|
102
|
+
* emitted node (used as the cull-tracking / destroy handle).
|
|
103
|
+
*/
|
|
104
|
+
private addStyledShape;
|
|
105
|
+
/**
|
|
106
|
+
* Recompute and re-publish the grid lines for the given viewport.
|
|
107
|
+
* Cached against snapped grid bounds so per-frame redraws are cheap when
|
|
108
|
+
* the viewport hasn't crossed a grid step.
|
|
109
|
+
*/
|
|
110
|
+
private refreshGrid;
|
|
111
|
+
private onSceneBuilt;
|
|
112
|
+
private applyClipping;
|
|
113
|
+
private onPositionChanged;
|
|
114
|
+
private applyPositionMarker;
|
|
115
|
+
private clearCurrentRoomOverlay;
|
|
116
|
+
private updateCurrentRoomOverlay;
|
|
117
|
+
syncHighlight(roomId: number, color: string | undefined): void;
|
|
118
|
+
syncHighlights(): void;
|
|
119
|
+
syncPaths(): void;
|
|
120
|
+
private clearOverlayShapes;
|
|
121
|
+
private clearPathShapes;
|
|
122
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { IMapReader } from '../reader/MapReader';
|
|
2
|
+
import { IArea } from '../reader/Area';
|
|
3
|
+
import { RoomLens } from '../lens/RoomLens';
|
|
4
|
+
import { ViewportBounds, RendererEventMap, CullingMode, Settings } from '../types/Settings';
|
|
5
|
+
import { MapState } from '../MapState';
|
|
6
|
+
import { CoordFn } from '../coord/CoordFn';
|
|
7
|
+
import { Style } from '../style';
|
|
8
|
+
import { Camera } from '../camera/Camera';
|
|
9
|
+
import { CullingManager } from '../CullingManager';
|
|
10
|
+
import { TypedEventEmitter } from '../TypedEventEmitter';
|
|
11
|
+
import { SceneOverlay } from '../overlay/SceneOverlay';
|
|
12
|
+
import { LiveEffect } from '../overlay/LiveEffect';
|
|
13
|
+
import { Exporter, ExportCanvas } from '../export/Exporter';
|
|
14
|
+
import { DrawnExitEntry, DrawnSpecialExitEntry, DrawnStubEntry } from '../ScenePipeline';
|
|
15
|
+
import { HitTester, HitResult } from '../hit/HitTester';
|
|
16
|
+
/**
|
|
17
|
+
* Contract for interactive render backends.
|
|
18
|
+
*
|
|
19
|
+
* Engine-neutral surface — anything that requires a specific render engine
|
|
20
|
+
* (Konva layers for live effects, Konva.Stage for `toCanvas`) is intentionally
|
|
21
|
+
* not on this interface and lives only on the concrete backend.
|
|
22
|
+
*/
|
|
23
|
+
export interface InteractiveBackend {
|
|
24
|
+
readonly camera: Camera;
|
|
25
|
+
readonly culling: CullingManager;
|
|
26
|
+
readonly hitTester: HitTester;
|
|
27
|
+
readonly events: TypedEventEmitter<RendererEventMap>;
|
|
28
|
+
/** Forward map → render-space transform from the active style (identity for flat styles). */
|
|
29
|
+
readonly coordinateTransform: CoordFn;
|
|
30
|
+
/**
|
|
31
|
+
* Apply a target-agnostic {@link Style} to the live scene. The style
|
|
32
|
+
* transforms world-space shapes (paint, geometry, projection) before they
|
|
33
|
+
* are rasterized; the backend re-renders the current scene to reflect it.
|
|
34
|
+
*/
|
|
35
|
+
setStyle(style: Style): void;
|
|
36
|
+
updateBackground(): void;
|
|
37
|
+
refresh(): void;
|
|
38
|
+
/** Capture the current camera as a canvas with background fill. */
|
|
39
|
+
exportCanvas(options?: {
|
|
40
|
+
pixelRatio?: number;
|
|
41
|
+
}): ExportCanvas | undefined;
|
|
42
|
+
addSceneOverlay(id: string, overlay: SceneOverlay): void;
|
|
43
|
+
removeSceneOverlay(id: string): void;
|
|
44
|
+
getSceneOverlays(): Iterable<SceneOverlay>;
|
|
45
|
+
/**
|
|
46
|
+
* Snapshot of inter-room exits as drawn in the last `buildScene` call
|
|
47
|
+
* (polyline segments, arrows, bounds, dashes — exactly what the user
|
|
48
|
+
* sees). Empty before the first draw. The list already reflects the
|
|
49
|
+
* renderer's suppression rules, so anything drawn appears here and
|
|
50
|
+
* anything not drawn does not.
|
|
51
|
+
*/
|
|
52
|
+
getDrawnExits(): readonly DrawnExitEntry[];
|
|
53
|
+
/** Companion to {@link getDrawnExits} for custom-line special exits. */
|
|
54
|
+
getDrawnSpecialExits(): readonly DrawnSpecialExitEntry[];
|
|
55
|
+
/** Companion to {@link getDrawnExits} for one-way stub indicators. */
|
|
56
|
+
getDrawnStubs(): readonly DrawnStubEntry[];
|
|
57
|
+
destroy(): void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Unified map renderer facade.
|
|
61
|
+
*
|
|
62
|
+
* Public surface is intentionally narrow:
|
|
63
|
+
* - **State mutations** (`drawArea`, `setPosition`, `renderHighlight`, …) emit
|
|
64
|
+
* events through `MapState` that the interactive backend reacts to.
|
|
65
|
+
* - **{@link setStyle}** applies a target-agnostic visual transformation to the
|
|
66
|
+
* interactive canvas and every exporter.
|
|
67
|
+
* - **{@link export}** runs an {@link Exporter} plug-in and returns its output
|
|
68
|
+
* (SVG string, PNG data URL, canvas, PDF bytes, …). New formats are added by
|
|
69
|
+
* shipping new `Exporter<T>` implementations — no new methods on this class.
|
|
70
|
+
* - **{@link addSceneOverlay}** is target-agnostic and appears in every output.
|
|
71
|
+
* - **{@link addLiveEffect}** registers interactive-only animated effects (Konva
|
|
72
|
+
* canvas only; skipped by exporters).
|
|
73
|
+
*/
|
|
74
|
+
export declare class MapRenderer {
|
|
75
|
+
readonly state: MapState;
|
|
76
|
+
readonly backend: InteractiveBackend;
|
|
77
|
+
private currentStyle;
|
|
78
|
+
get settings(): Settings;
|
|
79
|
+
/** Camera owned by the active interactive backend. */
|
|
80
|
+
get camera(): Camera;
|
|
81
|
+
/** Culling manager owned by the active interactive backend. */
|
|
82
|
+
get culling(): CullingManager;
|
|
83
|
+
/** Hit-test index owned by the active interactive backend. */
|
|
84
|
+
get hitTester(): HitTester;
|
|
85
|
+
/** Renderer event emitter (room click, area exit click, zoom change, …). */
|
|
86
|
+
get events(): TypedEventEmitter<RendererEventMap>;
|
|
87
|
+
/**
|
|
88
|
+
* @param mapReader Map data source.
|
|
89
|
+
* @param settings Renderer settings. Defaults to `createSettings()`.
|
|
90
|
+
* @param container DOM element for interactive rendering. Omit for headless.
|
|
91
|
+
* @param backendFactory Optional factory that receives the `MapState` and returns
|
|
92
|
+
* a custom `InteractiveBackend`. When omitted, a `KonvaRenderBackend` is created.
|
|
93
|
+
*/
|
|
94
|
+
constructor(mapReader: IMapReader, settings?: Settings, container?: HTMLDivElement, backendFactory?: (state: MapState) => InteractiveBackend);
|
|
95
|
+
destroy(): void;
|
|
96
|
+
drawArea(id: number, zIndex: number): void;
|
|
97
|
+
getCurrentArea(): IArea | undefined;
|
|
98
|
+
setPosition(roomId: number, center?: boolean): void;
|
|
99
|
+
updatePositionMarker(roomId: number): void;
|
|
100
|
+
clearPosition(): void;
|
|
101
|
+
centerOn(roomId: number, instant?: boolean): void;
|
|
102
|
+
renderHighlight(roomId: number, color: string): void;
|
|
103
|
+
removeHighlight(roomId: number): void;
|
|
104
|
+
hasHighlight(roomId: number): boolean;
|
|
105
|
+
clearHighlights(): void;
|
|
106
|
+
renderPath(locations: number[], color?: string): void;
|
|
107
|
+
clearPaths(): void;
|
|
108
|
+
refreshCurrentRoomOverlay(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Replace the active visibility lens. Lenses filter which rooms (and how
|
|
111
|
+
* partially-visible exits) the renderer draws — exploration / fog-of-war
|
|
112
|
+
* is one example, guild/quest scope overlays are others. Compose multiple
|
|
113
|
+
* concerns with `composeLenses(...)`.
|
|
114
|
+
*
|
|
115
|
+
* Triggers an immediate rebuild. For mutations on a stateful lens (e.g.
|
|
116
|
+
* `ExplorationLens.addVisited`), call {@link refresh} explicitly.
|
|
117
|
+
*/
|
|
118
|
+
setLens(lens: RoomLens): void;
|
|
119
|
+
getLens(): RoomLens;
|
|
120
|
+
/**
|
|
121
|
+
* Apply a {@link Style} to the interactive canvas and every export path.
|
|
122
|
+
* The backend rebuilds the current scene under the new style — no explicit
|
|
123
|
+
* `refresh()` is needed.
|
|
124
|
+
*
|
|
125
|
+
* ```ts
|
|
126
|
+
* import {compose, Parchment, Sketchy} from 'mudlet-map-renderer';
|
|
127
|
+
* renderer.setStyle(compose(Parchment, Sketchy({jitter: 0.012, color: '#4a3728'})));
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* Pass `identityStyle` (or call {@link clearStyle}) to remove the current style.
|
|
131
|
+
*/
|
|
132
|
+
setStyle(style: Style): void;
|
|
133
|
+
/** Equivalent to `setStyle(identityStyle)`. */
|
|
134
|
+
clearStyle(): void;
|
|
135
|
+
/** Returns the style currently applied (defaults to identity). */
|
|
136
|
+
getStyle(): Style;
|
|
137
|
+
updateBackground(): void;
|
|
138
|
+
refresh(): void;
|
|
139
|
+
/** Target-agnostic overlay; appears in every output including exporters. */
|
|
140
|
+
addSceneOverlay(id: string, overlay: SceneOverlay): void;
|
|
141
|
+
removeSceneOverlay(id: string): void;
|
|
142
|
+
/**
|
|
143
|
+
* Register an interactive-only animated effect. No-ops when running with a
|
|
144
|
+
* non-Konva backend. Does not appear in SVG/PNG exports — use
|
|
145
|
+
* {@link addSceneOverlay} for overlays that must appear in exports.
|
|
146
|
+
*
|
|
147
|
+
* ```ts
|
|
148
|
+
* renderer.addLiveEffect('rain', new RainEffect());
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
addLiveEffect(id: string, effect: LiveEffect): void;
|
|
152
|
+
removeLiveEffect(id: string): void;
|
|
153
|
+
/**
|
|
154
|
+
* Hit-test a world-space map point against the current scene.
|
|
155
|
+
*
|
|
156
|
+
* Returns the nearest pickable shape at `(worldX, worldY)`, or `null`
|
|
157
|
+
* when no hittable shape is within range. Coordinates must be in the
|
|
158
|
+
* same flat map space as room positions — the method applies the active
|
|
159
|
+
* style's world→scene projection internally, so callers never need to
|
|
160
|
+
* think about Isometric mode.
|
|
161
|
+
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* const hit = renderer.hitTest(room.x, room.y);
|
|
164
|
+
* if (hit?.kind === 'room') console.log('room', hit.id);
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
hitTest(worldX: number, worldY: number): HitResult | null;
|
|
168
|
+
/**
|
|
169
|
+
* Polyline / arrow / bounds data for every inter-room exit the renderer
|
|
170
|
+
* drew on the last scene build. Intended for tools (e.g. editors) that
|
|
171
|
+
* need to hit-test against exactly what the user sees, including dash
|
|
172
|
+
* patterns, one-way arrows, and the renderer's suppression rules.
|
|
173
|
+
*/
|
|
174
|
+
getDrawnExits(): readonly DrawnExitEntry[];
|
|
175
|
+
/** Companion to {@link getDrawnExits} for custom-line special exits. */
|
|
176
|
+
getDrawnSpecialExits(): readonly DrawnSpecialExitEntry[];
|
|
177
|
+
/**
|
|
178
|
+
* Polyline data for every one-way stub indicator the renderer drew
|
|
179
|
+
* (one entry per direction in `room.stubs`). Coordinates are in
|
|
180
|
+
* render space and match what's on screen.
|
|
181
|
+
*/
|
|
182
|
+
getDrawnStubs(): readonly DrawnStubEntry[];
|
|
183
|
+
/**
|
|
184
|
+
* Run an {@link Exporter} against the current scene and return its output.
|
|
185
|
+
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* const svg = renderer.export(new SvgExporter({ padding: 5 }));
|
|
188
|
+
* const url = renderer.export(new PngExporter({ pixelRatio: 2 }));
|
|
189
|
+
* const blob = await renderer.export(new PngBlobExporter());
|
|
190
|
+
* const canvas = renderer.export(new CanvasExporter({ width, height }));
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export<T>(exporter: Exporter<T>): T;
|
|
194
|
+
on<K extends keyof RendererEventMap>(event: K, handler: (detail: RendererEventMap[K]) => void): void;
|
|
195
|
+
off<K extends keyof RendererEventMap>(event: K, handler: (detail: RendererEventMap[K]) => void): void;
|
|
196
|
+
setZoom(zoom: number): boolean;
|
|
197
|
+
zoomToCenter(zoom: number): boolean;
|
|
198
|
+
getZoom(): number;
|
|
199
|
+
getViewportBounds(): ViewportBounds;
|
|
200
|
+
getAreaBounds(): ViewportBounds | null;
|
|
201
|
+
fitArea(insets?: {
|
|
202
|
+
top?: number;
|
|
203
|
+
right?: number;
|
|
204
|
+
bottom?: number;
|
|
205
|
+
left?: number;
|
|
206
|
+
}): void;
|
|
207
|
+
get centerOnResize(): boolean;
|
|
208
|
+
set centerOnResize(value: boolean);
|
|
209
|
+
get minZoom(): number;
|
|
210
|
+
set minZoom(value: number);
|
|
211
|
+
setCullingMode(mode: CullingMode): void;
|
|
212
|
+
getCullingMode(): CullingMode;
|
|
213
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IArea } from '../reader/Area';
|
|
2
|
+
import { IPlane } from '../reader/Plane';
|
|
3
|
+
import { Settings } from '../types/Settings';
|
|
4
|
+
import { SceneBuildResult, SceneShapesByLayer, AreaExitHitZone, DrawnExitEntry, DrawnSpecialExitEntry, DrawnStubEntry } from '../ScenePipeline';
|
|
5
|
+
import { Camera } from '../camera/Camera';
|
|
6
|
+
import { CoordFn } from '../coord/CoordFn';
|
|
7
|
+
import { GroupShape, Shape } from '../scene/Shape';
|
|
8
|
+
import { IMapReader } from '../reader/MapReader';
|
|
9
|
+
import { RoomLens } from '../lens/RoomLens';
|
|
10
|
+
import { ExitDrawData } from '../ExitRenderer';
|
|
11
|
+
export interface CullStats {
|
|
12
|
+
visibleRooms: number;
|
|
13
|
+
totalRooms: number;
|
|
14
|
+
visibleExits: number;
|
|
15
|
+
}
|
|
16
|
+
export interface CullOutput {
|
|
17
|
+
shapes: SceneShapesByLayer;
|
|
18
|
+
stats: CullStats;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Encapsulates the scene build + cull pipeline for the interactive renderer.
|
|
22
|
+
*
|
|
23
|
+
* Owns {@link ScenePipeline} and the last {@link SceneBuildResult}. Backends
|
|
24
|
+
* call {@link rebuild} when the area/plane changes, then {@link cull} on each
|
|
25
|
+
* viewport update to get the currently-visible shapes. Neither the pipeline
|
|
26
|
+
* nor {@link clipSceneToViewport} need to be referenced outside this class.
|
|
27
|
+
*/
|
|
28
|
+
export declare class SceneManager {
|
|
29
|
+
private readonly camera;
|
|
30
|
+
private readonly settings;
|
|
31
|
+
private pipeline;
|
|
32
|
+
private lastBuildResult?;
|
|
33
|
+
private standaloneExitShapeSet;
|
|
34
|
+
constructor(camera: Camera, settings: Settings, mapReader: IMapReader);
|
|
35
|
+
get exitRenderer(): import('../ExitRenderer').default;
|
|
36
|
+
get lastResult(): SceneBuildResult | undefined;
|
|
37
|
+
get drawnExits(): readonly DrawnExitEntry[];
|
|
38
|
+
get drawnSpecialExits(): readonly DrawnSpecialExitEntry[];
|
|
39
|
+
get drawnStubs(): readonly DrawnStubEntry[];
|
|
40
|
+
get areaExitHitZones(): readonly AreaExitHitZone[];
|
|
41
|
+
get hitShapes(): readonly Shape[];
|
|
42
|
+
rebuild(area: IArea, plane: IPlane, zIndex: number, lens?: RoomLens): SceneBuildResult;
|
|
43
|
+
buildExitShape(data: ExitDrawData): GroupShape;
|
|
44
|
+
reset(): void;
|
|
45
|
+
resetPipeline(mapReader: IMapReader): void;
|
|
46
|
+
/**
|
|
47
|
+
* Lightweight cull for the interactive render path. Returns a
|
|
48
|
+
* `Map<Shape, boolean>` where absent shapes are unmanaged pass-throughs
|
|
49
|
+
* (always visible). Avoids the 12 Sets + 2 filtered arrays produced by
|
|
50
|
+
* the full {@link cull} path.
|
|
51
|
+
*/
|
|
52
|
+
cullInteractive(coordinateTransform?: CoordFn): Map<Shape, boolean>;
|
|
53
|
+
cull(coordinateTransform?: CoordFn): CullOutput;
|
|
54
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient light data: a single image containing a smooth radial vignette,
|
|
3
|
+
* positioned centered on the player.
|
|
4
|
+
*/
|
|
5
|
+
export type AmbientLightData = {
|
|
6
|
+
cx: number;
|
|
7
|
+
cy: number;
|
|
8
|
+
displaySize: number;
|
|
9
|
+
src: string;
|
|
10
|
+
};
|
|
11
|
+
/** Tunable parameters for the ambient light vignette. */
|
|
12
|
+
export type AmbientLightParams = {
|
|
13
|
+
color: string;
|
|
14
|
+
radius: number;
|
|
15
|
+
intensity: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Compute ambient light vignette for the given player position and viewport.
|
|
19
|
+
*
|
|
20
|
+
* Produces a single image overlay containing a smooth radial gradient:
|
|
21
|
+
* clear at center → full darkness at edges. The image is sized to always
|
|
22
|
+
* cover the entire visible viewport with margin.
|
|
23
|
+
*/
|
|
24
|
+
export declare function computeAmbientLight(cx: number, cy: number, viewportBounds: {
|
|
25
|
+
minX: number;
|
|
26
|
+
maxX: number;
|
|
27
|
+
minY: number;
|
|
28
|
+
maxY: number;
|
|
29
|
+
}, params: AmbientLightParams): AmbientLightData;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Settings } from '../types/Settings';
|
|
2
|
+
export type GridLineData = {
|
|
3
|
+
x1: number;
|
|
4
|
+
y1: number;
|
|
5
|
+
x2: number;
|
|
6
|
+
y2: number;
|
|
7
|
+
};
|
|
8
|
+
export type GridData = {
|
|
9
|
+
lines: GridLineData[];
|
|
10
|
+
stroke: string;
|
|
11
|
+
strokeWidth: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Compute grid lines for a given viewport bounds.
|
|
15
|
+
*/
|
|
16
|
+
export declare function computeGrid(settings: Settings, bounds: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
w: number;
|
|
20
|
+
h: number;
|
|
21
|
+
}): GridData;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Settings } from '../types/Settings';
|
|
2
|
+
import { IMapReader } from '../reader/MapReader';
|
|
3
|
+
export type TriangleData = {
|
|
4
|
+
cx: number;
|
|
5
|
+
cy: number;
|
|
6
|
+
/** Pre-computed polygon vertices (3 pairs of x,y) */
|
|
7
|
+
vertices: number[];
|
|
8
|
+
fill: string;
|
|
9
|
+
stroke: string;
|
|
10
|
+
strokeWidth: number;
|
|
11
|
+
};
|
|
12
|
+
export type InnerExitData = {
|
|
13
|
+
triangles: TriangleData[];
|
|
14
|
+
};
|
|
15
|
+
declare function computeTriangleVertices(cx: number, cy: number, radius: number, rotationDeg: number): number[];
|
|
16
|
+
/**
|
|
17
|
+
* Compute inner exit triangle data for a room.
|
|
18
|
+
* Returns pre-computed vertex positions so each backend just draws polygons.
|
|
19
|
+
*/
|
|
20
|
+
export declare function computeInnerExits(room: MapData.Room, mapReader: IMapReader, settings: Settings): InnerExitData;
|
|
21
|
+
/**
|
|
22
|
+
* Compute triangle vertices for a standalone triangle (used by path overlay markers).
|
|
23
|
+
*/
|
|
24
|
+
export { computeTriangleVertices };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Settings } from '../types/Settings';
|
|
2
|
+
import { IMapReader } from '../reader/MapReader';
|
|
3
|
+
export type HighlightData = {
|
|
4
|
+
shape: 'circle' | 'rect';
|
|
5
|
+
cx: number;
|
|
6
|
+
cy: number;
|
|
7
|
+
/** For circle: radius. For rect: half-size. */
|
|
8
|
+
size: number;
|
|
9
|
+
cornerRadius: number;
|
|
10
|
+
strokeColor: string;
|
|
11
|
+
strokeAlpha: number;
|
|
12
|
+
strokeWidth: number;
|
|
13
|
+
fillColor: string;
|
|
14
|
+
fillAlpha: number;
|
|
15
|
+
dash?: number[];
|
|
16
|
+
dashEnabled: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function computeHighlight(room: MapData.Room, color: string, settings: Settings): HighlightData;
|
|
19
|
+
export type PositionMarkerData = {
|
|
20
|
+
shape: 'circle' | 'rect';
|
|
21
|
+
cx: number;
|
|
22
|
+
cy: number;
|
|
23
|
+
size: number;
|
|
24
|
+
cornerRadius: number;
|
|
25
|
+
strokeColor: string;
|
|
26
|
+
strokeWidth: number;
|
|
27
|
+
strokeAlpha: number;
|
|
28
|
+
fillColor: string;
|
|
29
|
+
fillAlpha: number;
|
|
30
|
+
dash?: number[];
|
|
31
|
+
dashEnabled: boolean;
|
|
32
|
+
};
|
|
33
|
+
export declare function computePositionMarker(room: MapData.Room, settings: Settings): PositionMarkerData;
|
|
34
|
+
export type PathOverlaySegment = {
|
|
35
|
+
points: number[];
|
|
36
|
+
};
|
|
37
|
+
export type PathOverlayTriangle = {
|
|
38
|
+
vertices: number[];
|
|
39
|
+
};
|
|
40
|
+
export type PathOverlayData = {
|
|
41
|
+
segments: PathOverlaySegment[];
|
|
42
|
+
triangles: PathOverlayTriangle[];
|
|
43
|
+
color: string;
|
|
44
|
+
outlineWidth: number;
|
|
45
|
+
lineWidth: number;
|
|
46
|
+
};
|
|
47
|
+
export declare function computePathOverlay(mapReader: IMapReader, settings: Settings, locations: number[], color: string, areaId: number, zIndex: number): PathOverlayData;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Settings } from '../types/Settings';
|
|
2
|
+
import { IMapReader } from '../reader/MapReader';
|
|
3
|
+
export type RoomColors = {
|
|
4
|
+
fillColor: string;
|
|
5
|
+
strokeColor: string;
|
|
6
|
+
borderWidth: number;
|
|
7
|
+
symbolColor: string;
|
|
8
|
+
envColor: string;
|
|
9
|
+
};
|
|
10
|
+
export type EmbossEdge = {
|
|
11
|
+
points: number[];
|
|
12
|
+
stroke: string;
|
|
13
|
+
strokeWidth: number;
|
|
14
|
+
lineCap?: string;
|
|
15
|
+
lineJoin?: string;
|
|
16
|
+
};
|
|
17
|
+
export type EmbossStyle = {
|
|
18
|
+
highlight: EmbossEdge;
|
|
19
|
+
shadow: EmbossEdge;
|
|
20
|
+
} | null;
|
|
21
|
+
/**
|
|
22
|
+
* Compute the fill/stroke/border colors for a room based on env color and settings.
|
|
23
|
+
* This is the single source of truth — used by Konva renderer, SVG exporter, and Canvas exporter.
|
|
24
|
+
*/
|
|
25
|
+
export declare function computeRoomColors(room: MapData.Room, mapReader: IMapReader, settings: Settings, strokeOverride?: string): RoomColors;
|
|
26
|
+
/**
|
|
27
|
+
* Compute the emboss bevel for a room.
|
|
28
|
+
* Returns highlight (top+left) and shadow (bottom+right) edges using
|
|
29
|
+
* lightened/darkened versions of the fill color for a raised 3D look.
|
|
30
|
+
* Works for all room shapes: rectangle, roundedRectangle, and circle.
|
|
31
|
+
*/
|
|
32
|
+
export declare function computeEmboss(fillColor: string, settings: Settings): EmbossStyle;
|