mudlet-map-renderer 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ import { MapState } from '../MapState';
2
+ import { ViewportBounds } from '../types/Settings';
3
+ import { Shape } from '../scene/Shape';
4
+ import { Direction8 } from '../labelPlacement';
5
+ import { SceneOverlay, SceneOverlayContext } from './SceneOverlay';
6
+ export interface Waypoint {
7
+ roomId: number;
8
+ /** Label text. An array renders as stacked lines in one bubble. */
9
+ label: string | string[];
10
+ /** Marker / accent colour (hex). Default amber. */
11
+ color?: string;
12
+ /** Optional preferred label direction (nudge only). */
13
+ preferred?: Direction8;
14
+ /**
15
+ * Optional click handler. Fired when the waypoint's bubble is clicked.
16
+ * Wire pointer hits to it via {@link WaypointOverlay.hitTest} (see below).
17
+ * Waypoints without a handler are inert.
18
+ */
19
+ onClick?: (waypoint: Waypoint) => void;
20
+ }
21
+ /**
22
+ * Persistent named markers anchored to rooms (shops, banks, quest givers …),
23
+ * with auto-placed labels that dodge neighbouring rooms, exits, and each other
24
+ * via {@link placeLabels}. A {@link SceneOverlay}, so it renders on the
25
+ * interactive canvas and in every export.
26
+ *
27
+ * A room may carry more than one waypoint (e.g. a transport stop served by two
28
+ * routes): the list is flat, so push several entries with the same `roomId` and
29
+ * each gets its own auto-placed bubble. Alternatively give one waypoint a
30
+ * multi-line `label` to list them in a single bubble.
31
+ *
32
+ * Waypoints can be clickable. Bubbles are overlay-layer shapes, so they are not
33
+ * part of the renderer's {@link HitTester}; the overlay instead records the
34
+ * rects it places and resolves them via {@link hitTest}. Wire pointer clicks to
35
+ * it by converting the cursor to world space:
36
+ *
37
+ * ```ts
38
+ * const waypoints = new WaypointOverlay();
39
+ * waypoints.add({ roomId: 42, label: 'Bank', onClick: wp => console.log(wp.roomId) });
40
+ * renderer.addSceneOverlay('waypoints', waypoints);
41
+ *
42
+ * container.addEventListener('click', e => {
43
+ * const p = renderer.camera.clientToMapPoint(e.clientX, e.clientY, container.getBoundingClientRect());
44
+ * if (!p) return;
45
+ * const wp = waypoints.hitTest(p.x, p.y);
46
+ * wp?.onClick?.(wp);
47
+ * });
48
+ * ```
49
+ */
50
+ export declare class WaypointOverlay implements SceneOverlay {
51
+ private waypoints;
52
+ private ctx?;
53
+ /** Bubble rects from the last render, for click hit-testing (world space). */
54
+ private placed;
55
+ set(list: Waypoint[]): void;
56
+ add(waypoint: Waypoint): void;
57
+ /** Remove every waypoint anchored to this room. */
58
+ remove(roomId: number): void;
59
+ has(roomId: number): boolean;
60
+ /**
61
+ * Topmost waypoint whose bubble contains the given **world-space** point, or
62
+ * `undefined`. Hit-tests the bubbles placed by the last {@link render} (in
63
+ * reverse, so later-drawn bubbles win). Convert a pointer position to world
64
+ * space with `renderer.camera.clientToMapPoint(...)` before calling.
65
+ */
66
+ hitTest(worldX: number, worldY: number): Waypoint | undefined;
67
+ attach(ctx: SceneOverlayContext): void;
68
+ detach(): void;
69
+ render(state: MapState, _bounds: ViewportBounds): Shape[];
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mudlet-map-renderer",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "url": "https://github.com/Delwing/mudlet-map-renderer"