mudlet-map-renderer 2.0.0 → 2.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 +14 -0
- package/dist/{MapReader-mU_4JWv_.js → MapReader-Brzg-X7T.js} +1 -1
- package/dist/{MapReader-mU_4JWv_.js.map → MapReader-Brzg-X7T.js.map} +1 -1
- package/dist/MapState.d.ts +6 -1
- package/dist/SvgTypes.d.ts +1 -1
- package/dist/assets/worker-DtQws85m.js.map +1 -0
- package/dist/binary.mjs +1 -1
- package/dist/export/CanvasExporter.d.ts +1 -1
- package/dist/export/flushSceneShapes.d.ts +1 -1
- package/dist/flushSceneShapes-Duhi0OQv.js +2937 -0
- package/dist/flushSceneShapes-Duhi0OQv.js.map +1 -0
- package/dist/hit/HitTester.d.ts +19 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +880 -3380
- package/dist/index.mjs.map +1 -1
- package/dist/offscreen.mjs +355 -0
- package/dist/offscreen.mjs.map +1 -0
- package/dist/overlay/SceneOverlay.d.ts +16 -3
- package/dist/rendering/KonvaRenderBackend.d.ts +5 -1
- package/dist/rendering/MapRenderer.d.ts +18 -4
- package/dist/rendering/offscreen/OffscreenCanvasBackend.d.ts +109 -0
- package/dist/rendering/offscreen/index.d.ts +11 -0
- package/dist/rendering/offscreen/protocol.d.ts +100 -0
- package/dist/rendering/offscreen/renderFrame.d.ts +28 -0
- package/dist/rendering/offscreen/serializeTransform.d.ts +20 -0
- package/dist/rendering/offscreen/worker.d.ts +15 -0
- package/dist/scene/OverlayStyle.d.ts +7 -3
- package/dist/scene/Shape.d.ts +7 -0
- package/dist/scene/elements/OverlayLayout.d.ts +3 -0
- package/dist/style/Style.d.ts +12 -0
- package/dist/style/index.d.ts +10 -1
- package/dist/style/shape/GraphPaperStyle.d.ts +16 -0
- package/dist/style/shape/StainedGlassStyle.d.ts +15 -0
- package/dist/style/shape/TopographicStyle.d.ts +14 -0
- package/dist/style/shape/WatercolorStyle.d.ts +32 -0
- package/dist/style/shape/index.d.ts +5 -0
- package/dist/style/shape/paintMap.d.ts +8 -0
- package/dist/types/Settings.d.ts +11 -3
- package/package.json +6 -1
|
@@ -0,0 +1,2937 @@
|
|
|
1
|
+
import e from "konva";
|
|
2
|
+
//#region src/utils/color.ts
|
|
3
|
+
function t(e) {
|
|
4
|
+
let t, n, r, i = e.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
|
|
5
|
+
if (i) t = parseInt(i[1]) / 255, n = parseInt(i[2]) / 255, r = parseInt(i[3]) / 255;
|
|
6
|
+
else if (e.startsWith("#") && e.length >= 7) t = parseInt(e.slice(1, 3), 16) / 255, n = parseInt(e.slice(3, 5), 16) / 255, r = parseInt(e.slice(5, 7), 16) / 255;
|
|
7
|
+
else return .5;
|
|
8
|
+
return (Math.max(t, n, r) + Math.min(t, n, r)) / 2;
|
|
9
|
+
}
|
|
10
|
+
function n(e, t) {
|
|
11
|
+
let n, r, i, a = e.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
|
|
12
|
+
if (a) n = parseInt(a[1]), r = parseInt(a[2]), i = parseInt(a[3]);
|
|
13
|
+
else if (e.startsWith("#") && e.length >= 7) n = parseInt(e.slice(1, 3), 16), r = parseInt(e.slice(3, 5), 16), i = parseInt(e.slice(5, 7), 16);
|
|
14
|
+
else return e;
|
|
15
|
+
return n = Math.round(n * (1 - t)), r = Math.round(r * (1 - t)), i = Math.round(i * (1 - t)), `rgb(${n}, ${r}, ${i})`;
|
|
16
|
+
}
|
|
17
|
+
function r(e, t) {
|
|
18
|
+
let n, r, i, a = e.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
|
|
19
|
+
if (a) n = parseInt(a[1]), r = parseInt(a[2]), i = parseInt(a[3]);
|
|
20
|
+
else if (e.startsWith("#") && e.length >= 7) n = parseInt(e.slice(1, 3), 16), r = parseInt(e.slice(3, 5), 16), i = parseInt(e.slice(5, 7), 16);
|
|
21
|
+
else return e;
|
|
22
|
+
return n = Math.min(255, Math.round(n + (255 - n) * t)), r = Math.min(255, Math.round(r + (255 - r) * t)), i = Math.min(255, Math.round(i + (255 - i) * t)), `rgb(${n}, ${r}, ${i})`;
|
|
23
|
+
}
|
|
24
|
+
var i = {
|
|
25
|
+
black: [
|
|
26
|
+
0,
|
|
27
|
+
0,
|
|
28
|
+
0
|
|
29
|
+
],
|
|
30
|
+
white: [
|
|
31
|
+
255,
|
|
32
|
+
255,
|
|
33
|
+
255
|
|
34
|
+
],
|
|
35
|
+
red: [
|
|
36
|
+
255,
|
|
37
|
+
0,
|
|
38
|
+
0
|
|
39
|
+
],
|
|
40
|
+
green: [
|
|
41
|
+
0,
|
|
42
|
+
128,
|
|
43
|
+
0
|
|
44
|
+
],
|
|
45
|
+
lime: [
|
|
46
|
+
0,
|
|
47
|
+
255,
|
|
48
|
+
0
|
|
49
|
+
],
|
|
50
|
+
blue: [
|
|
51
|
+
0,
|
|
52
|
+
0,
|
|
53
|
+
255
|
|
54
|
+
],
|
|
55
|
+
yellow: [
|
|
56
|
+
255,
|
|
57
|
+
255,
|
|
58
|
+
0
|
|
59
|
+
],
|
|
60
|
+
cyan: [
|
|
61
|
+
0,
|
|
62
|
+
255,
|
|
63
|
+
255
|
|
64
|
+
],
|
|
65
|
+
aqua: [
|
|
66
|
+
0,
|
|
67
|
+
255,
|
|
68
|
+
255
|
|
69
|
+
],
|
|
70
|
+
magenta: [
|
|
71
|
+
255,
|
|
72
|
+
0,
|
|
73
|
+
255
|
|
74
|
+
],
|
|
75
|
+
fuchsia: [
|
|
76
|
+
255,
|
|
77
|
+
0,
|
|
78
|
+
255
|
|
79
|
+
],
|
|
80
|
+
silver: [
|
|
81
|
+
192,
|
|
82
|
+
192,
|
|
83
|
+
192
|
|
84
|
+
],
|
|
85
|
+
gray: [
|
|
86
|
+
128,
|
|
87
|
+
128,
|
|
88
|
+
128
|
|
89
|
+
],
|
|
90
|
+
grey: [
|
|
91
|
+
128,
|
|
92
|
+
128,
|
|
93
|
+
128
|
|
94
|
+
],
|
|
95
|
+
maroon: [
|
|
96
|
+
128,
|
|
97
|
+
0,
|
|
98
|
+
0
|
|
99
|
+
],
|
|
100
|
+
olive: [
|
|
101
|
+
128,
|
|
102
|
+
128,
|
|
103
|
+
0
|
|
104
|
+
],
|
|
105
|
+
purple: [
|
|
106
|
+
128,
|
|
107
|
+
0,
|
|
108
|
+
128
|
|
109
|
+
],
|
|
110
|
+
teal: [
|
|
111
|
+
0,
|
|
112
|
+
128,
|
|
113
|
+
128
|
|
114
|
+
],
|
|
115
|
+
navy: [
|
|
116
|
+
0,
|
|
117
|
+
0,
|
|
118
|
+
128
|
|
119
|
+
],
|
|
120
|
+
orange: [
|
|
121
|
+
255,
|
|
122
|
+
165,
|
|
123
|
+
0
|
|
124
|
+
],
|
|
125
|
+
pink: [
|
|
126
|
+
255,
|
|
127
|
+
192,
|
|
128
|
+
203
|
|
129
|
+
],
|
|
130
|
+
gold: [
|
|
131
|
+
255,
|
|
132
|
+
215,
|
|
133
|
+
0
|
|
134
|
+
],
|
|
135
|
+
brown: [
|
|
136
|
+
165,
|
|
137
|
+
42,
|
|
138
|
+
42
|
|
139
|
+
],
|
|
140
|
+
violet: [
|
|
141
|
+
238,
|
|
142
|
+
130,
|
|
143
|
+
238
|
|
144
|
+
],
|
|
145
|
+
indigo: [
|
|
146
|
+
75,
|
|
147
|
+
0,
|
|
148
|
+
130
|
|
149
|
+
],
|
|
150
|
+
transparent: [
|
|
151
|
+
0,
|
|
152
|
+
0,
|
|
153
|
+
0
|
|
154
|
+
]
|
|
155
|
+
};
|
|
156
|
+
function a(e, t) {
|
|
157
|
+
let n = e.trim();
|
|
158
|
+
if (n.startsWith("#")) {
|
|
159
|
+
let r, i, a;
|
|
160
|
+
if (n.length === 4) r = parseInt(n[1] + n[1], 16), i = parseInt(n[2] + n[2], 16), a = parseInt(n[3] + n[3], 16);
|
|
161
|
+
else if (n.length >= 7) r = parseInt(n.slice(1, 3), 16), i = parseInt(n.slice(3, 5), 16), a = parseInt(n.slice(5, 7), 16);
|
|
162
|
+
else return e;
|
|
163
|
+
return Number.isNaN(r) || Number.isNaN(i) || Number.isNaN(a) ? e : `rgba(${r}, ${i}, ${a}, ${t})`;
|
|
164
|
+
}
|
|
165
|
+
let r = n.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)$/i);
|
|
166
|
+
if (r) return `rgba(${parseInt(r[1], 10)}, ${parseInt(r[2], 10)}, ${parseInt(r[3], 10)}, ${r[4] === void 0 ? t : parseFloat(r[4]) * t})`;
|
|
167
|
+
let a = i[n.toLowerCase()];
|
|
168
|
+
return a ? `rgba(${a[0]}, ${a[1]}, ${a[2]}, ${t})` : e;
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/TypedEventEmitter.ts
|
|
172
|
+
var o = class {
|
|
173
|
+
constructor(e) {
|
|
174
|
+
this.listeners = /* @__PURE__ */ new Map(), this.container = e;
|
|
175
|
+
}
|
|
176
|
+
on(e, t) {
|
|
177
|
+
let n = this.listeners.get(e);
|
|
178
|
+
n || (n = /* @__PURE__ */ new Set(), this.listeners.set(e, n)), n.add(t);
|
|
179
|
+
}
|
|
180
|
+
off(e, t) {
|
|
181
|
+
this.listeners.get(e)?.delete(t);
|
|
182
|
+
}
|
|
183
|
+
removeAllListeners() {
|
|
184
|
+
this.listeners.clear();
|
|
185
|
+
}
|
|
186
|
+
emit(e, t) {
|
|
187
|
+
this.listeners.get(e)?.forEach((e) => e(t)), this.container && this.container.dispatchEvent(new CustomEvent(e, { detail: t }));
|
|
188
|
+
}
|
|
189
|
+
}, s = {
|
|
190
|
+
isVisible: () => !0,
|
|
191
|
+
getVersion: () => 0
|
|
192
|
+
};
|
|
193
|
+
function c(e, t, n, r) {
|
|
194
|
+
let i = e.isVisible(n), a = e.isVisible(r);
|
|
195
|
+
return i && a ? "full" : i || a ? "stub" : "hidden";
|
|
196
|
+
}
|
|
197
|
+
function l(e) {
|
|
198
|
+
return e < .5 ? 2 * e * e : -1 + (4 - 2 * e) * e;
|
|
199
|
+
}
|
|
200
|
+
var u = class e extends o {
|
|
201
|
+
constructor(e, t) {
|
|
202
|
+
super(), this.zoom = 1, this.minZoom = .05, this.position = {
|
|
203
|
+
x: 0,
|
|
204
|
+
y: 0
|
|
205
|
+
}, this.centerOnResize = !0, this.dragging = !1, this.dragStart = {
|
|
206
|
+
x: 0,
|
|
207
|
+
y: 0
|
|
208
|
+
}, this.positionAtDragStart = {
|
|
209
|
+
x: 0,
|
|
210
|
+
y: 0
|
|
211
|
+
}, this.batchDepth = 0, this.batchDirty = !1, this.width = e, this.height = t;
|
|
212
|
+
}
|
|
213
|
+
getScale() {
|
|
214
|
+
return 75 * this.zoom;
|
|
215
|
+
}
|
|
216
|
+
setZoom(e) {
|
|
217
|
+
let t = Math.max(this.minZoom, e);
|
|
218
|
+
return this.zoom === t ? !1 : (this.zoom = t, this.notify(), !0);
|
|
219
|
+
}
|
|
220
|
+
zoomToCenter(e) {
|
|
221
|
+
let t = Math.max(this.minZoom, e);
|
|
222
|
+
if (this.zoom === t) return !1;
|
|
223
|
+
let n = this.getScale(), r = this.width / 2, i = this.height / 2, a = {
|
|
224
|
+
x: (r - this.position.x) / n,
|
|
225
|
+
y: (i - this.position.y) / n
|
|
226
|
+
};
|
|
227
|
+
this.zoom = t;
|
|
228
|
+
let o = this.getScale();
|
|
229
|
+
return this.position = {
|
|
230
|
+
x: r - a.x * o,
|
|
231
|
+
y: i - a.y * o
|
|
232
|
+
}, this.notify(), !0;
|
|
233
|
+
}
|
|
234
|
+
zoomToPoint(e, t, n) {
|
|
235
|
+
let r = this.getScale(), i = {
|
|
236
|
+
x: (t - this.position.x) / r,
|
|
237
|
+
y: (n - this.position.y) / r
|
|
238
|
+
}, a = Math.max(this.minZoom, e);
|
|
239
|
+
if (this.zoom === a) return !1;
|
|
240
|
+
this.zoom = a;
|
|
241
|
+
let o = this.getScale();
|
|
242
|
+
return this.position = {
|
|
243
|
+
x: t - i.x * o,
|
|
244
|
+
y: n - i.y * o
|
|
245
|
+
}, this.notify(), !0;
|
|
246
|
+
}
|
|
247
|
+
getViewportBounds() {
|
|
248
|
+
let e = this.getScale();
|
|
249
|
+
return {
|
|
250
|
+
minX: (0 - this.position.x) / e,
|
|
251
|
+
maxX: (this.width - this.position.x) / e,
|
|
252
|
+
minY: (0 - this.position.y) / e,
|
|
253
|
+
maxY: (this.height - this.position.y) / e
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
getCullingViewport(e) {
|
|
257
|
+
if (!e) return this.getViewportBounds();
|
|
258
|
+
let t = this.getScale(), n = this.position;
|
|
259
|
+
return {
|
|
260
|
+
minX: (e.x - n.x) / t,
|
|
261
|
+
maxX: (e.x + e.width - n.x) / t,
|
|
262
|
+
minY: (e.y - n.y) / t,
|
|
263
|
+
maxY: (e.y + e.height - n.y) / t
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
static forMapBounds(t, n, r, i) {
|
|
267
|
+
let a = new e((n - t) * 75, (i - r) * 75);
|
|
268
|
+
return a.zoom = 1, a.position = {
|
|
269
|
+
x: -t * 75,
|
|
270
|
+
y: -r * 75
|
|
271
|
+
}, a;
|
|
272
|
+
}
|
|
273
|
+
static forRenderCamera(t, n, r, i, a) {
|
|
274
|
+
let o = new e(t, n);
|
|
275
|
+
return o.zoom = r / 75, o.position = {
|
|
276
|
+
x: i,
|
|
277
|
+
y: a
|
|
278
|
+
}, o;
|
|
279
|
+
}
|
|
280
|
+
clientToMapPoint(e, t, n) {
|
|
281
|
+
let r = e - (n?.left ?? 0), i = t - (n?.top ?? 0), a = this.getScale();
|
|
282
|
+
return a ? {
|
|
283
|
+
x: (r - this.position.x) / a,
|
|
284
|
+
y: (i - this.position.y) / a
|
|
285
|
+
} : null;
|
|
286
|
+
}
|
|
287
|
+
panToMapPoint(e, t) {
|
|
288
|
+
let n = this.getScale();
|
|
289
|
+
this.position = {
|
|
290
|
+
x: this.width / 2 - e * n,
|
|
291
|
+
y: this.height / 2 - t * n
|
|
292
|
+
}, this.notify();
|
|
293
|
+
}
|
|
294
|
+
panToMapPointAnimated(e, t, n) {
|
|
295
|
+
if (n) {
|
|
296
|
+
this.panToMapPoint(e, t);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
let r = { ...this.position }, i = this.getScale(), a = {
|
|
300
|
+
x: this.width / 2 - e * i,
|
|
301
|
+
y: this.height / 2 - t * i
|
|
302
|
+
};
|
|
303
|
+
this.animate(200, (e) => {
|
|
304
|
+
this.position = {
|
|
305
|
+
x: r.x + (a.x - r.x) * e,
|
|
306
|
+
y: r.y + (a.y - r.y) * e
|
|
307
|
+
};
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
computeFitZoom(e, t, n, r, i) {
|
|
311
|
+
let a = t - e, o = r - n;
|
|
312
|
+
if (a <= 0 || o <= 0) return this.zoom;
|
|
313
|
+
let s = i?.top ?? 0, c = i?.right ?? 0, l = i?.bottom ?? 0, u = i?.left ?? 0, d = Math.max(1, this.width - u - c), f = Math.max(1, this.height - s - l), p = d / ((a + 4) * 75), m = f / ((o + 4) * 75);
|
|
314
|
+
return Math.min(p, m);
|
|
315
|
+
}
|
|
316
|
+
fitToMapBounds(e, t, n, r, i) {
|
|
317
|
+
let a = t - e, o = r - n;
|
|
318
|
+
if (a <= 0 || o <= 0) return;
|
|
319
|
+
let s = i?.top ?? 0, c = i?.left ?? 0, l = Math.max(1, this.width - c - (i?.right ?? 0)), u = Math.max(1, this.height - s - (i?.bottom ?? 0));
|
|
320
|
+
this.zoom = this.computeFitZoom(e, t, n, r, i), this.minZoom = this.zoom;
|
|
321
|
+
let d = this.getScale(), f = (e + t) / 2, p = (n + r) / 2;
|
|
322
|
+
this.position = {
|
|
323
|
+
x: c + l / 2 - f * d,
|
|
324
|
+
y: s + u / 2 - p * d
|
|
325
|
+
}, this.notify();
|
|
326
|
+
}
|
|
327
|
+
setSize(e, t) {
|
|
328
|
+
this.width = e, this.height = t, this.notify();
|
|
329
|
+
}
|
|
330
|
+
startDrag(e, t) {
|
|
331
|
+
this.cancelAnimation(), this.dragging = !0, this.dragStart = {
|
|
332
|
+
x: e,
|
|
333
|
+
y: t
|
|
334
|
+
}, this.positionAtDragStart = { ...this.position };
|
|
335
|
+
}
|
|
336
|
+
updateDrag(e, t) {
|
|
337
|
+
this.dragging && (this.position = {
|
|
338
|
+
x: this.positionAtDragStart.x + (e - this.dragStart.x),
|
|
339
|
+
y: this.positionAtDragStart.y + (t - this.dragStart.y)
|
|
340
|
+
}, this.notify());
|
|
341
|
+
}
|
|
342
|
+
endDrag() {
|
|
343
|
+
this.dragging = !1;
|
|
344
|
+
}
|
|
345
|
+
isDragging() {
|
|
346
|
+
return this.dragging;
|
|
347
|
+
}
|
|
348
|
+
animate(e, t) {
|
|
349
|
+
this.cancelAnimation();
|
|
350
|
+
let n = performance.now(), r = typeof requestAnimationFrame < "u" ? requestAnimationFrame : (e) => setTimeout(() => e(performance.now()), 16), i = (a) => {
|
|
351
|
+
let o = a - n, s = Math.min(o / e, 1);
|
|
352
|
+
t(l(s)), this.notify(), s < 1 ? this.animationId = r(i) : this.animationId = void 0;
|
|
353
|
+
};
|
|
354
|
+
this.animationId = r(i);
|
|
355
|
+
}
|
|
356
|
+
cancelAnimation() {
|
|
357
|
+
this.animationId !== void 0 && ((typeof cancelAnimationFrame < "u" ? cancelAnimationFrame : (e) => clearTimeout(e))(this.animationId), this.animationId = void 0);
|
|
358
|
+
}
|
|
359
|
+
isAnimating() {
|
|
360
|
+
return this.animationId !== void 0;
|
|
361
|
+
}
|
|
362
|
+
batch(e) {
|
|
363
|
+
this.batchDepth++;
|
|
364
|
+
try {
|
|
365
|
+
return e();
|
|
366
|
+
} finally {
|
|
367
|
+
this.batchDepth--, this.batchDepth === 0 && this.batchDirty && (this.batchDirty = !1, this.emit("change", void 0));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
notify() {
|
|
371
|
+
if (this.batchDepth > 0) {
|
|
372
|
+
this.batchDirty = !0;
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
this.emit("change", void 0);
|
|
376
|
+
}
|
|
377
|
+
}, d = (e, t) => ({
|
|
378
|
+
x: e,
|
|
379
|
+
y: t
|
|
380
|
+
}), f = class {
|
|
381
|
+
constructor(e, t) {
|
|
382
|
+
this.settings = e, this.onCullingNeeded = t, this.cullingScheduled = !1, this.coordinateTransform = d;
|
|
383
|
+
}
|
|
384
|
+
setCoordinateTransform(e) {
|
|
385
|
+
this.coordinateTransform = e;
|
|
386
|
+
}
|
|
387
|
+
getCoordinateTransform() {
|
|
388
|
+
return this.coordinateTransform;
|
|
389
|
+
}
|
|
390
|
+
scheduleCulling() {
|
|
391
|
+
if (this.cullingScheduled) return;
|
|
392
|
+
this.cullingScheduled = !0;
|
|
393
|
+
let e = () => {
|
|
394
|
+
this.cullingScheduled = !1, this.onCullingNeeded();
|
|
395
|
+
};
|
|
396
|
+
typeof requestAnimationFrame < "u" ? requestAnimationFrame(e) : e();
|
|
397
|
+
}
|
|
398
|
+
updateCulling() {
|
|
399
|
+
this.onCullingNeeded();
|
|
400
|
+
}
|
|
401
|
+
}, p = [
|
|
402
|
+
"north",
|
|
403
|
+
"south",
|
|
404
|
+
"east",
|
|
405
|
+
"west",
|
|
406
|
+
"northeast",
|
|
407
|
+
"northwest",
|
|
408
|
+
"southeast",
|
|
409
|
+
"southwest"
|
|
410
|
+
], m = {
|
|
411
|
+
n: "north",
|
|
412
|
+
s: "south",
|
|
413
|
+
e: "east",
|
|
414
|
+
w: "west",
|
|
415
|
+
ne: "northeast",
|
|
416
|
+
nw: "northwest",
|
|
417
|
+
se: "southeast",
|
|
418
|
+
sw: "southwest"
|
|
419
|
+
}, h = {
|
|
420
|
+
north: "n",
|
|
421
|
+
south: "s",
|
|
422
|
+
east: "e",
|
|
423
|
+
west: "w",
|
|
424
|
+
northeast: "ne",
|
|
425
|
+
northwest: "nw",
|
|
426
|
+
southeast: "se",
|
|
427
|
+
southwest: "sw",
|
|
428
|
+
up: "u",
|
|
429
|
+
down: "d",
|
|
430
|
+
in: "i",
|
|
431
|
+
out: "o"
|
|
432
|
+
}, g = {
|
|
433
|
+
north: {
|
|
434
|
+
x: 0,
|
|
435
|
+
y: -1
|
|
436
|
+
},
|
|
437
|
+
south: {
|
|
438
|
+
x: 0,
|
|
439
|
+
y: 1
|
|
440
|
+
},
|
|
441
|
+
east: {
|
|
442
|
+
x: 1,
|
|
443
|
+
y: 0
|
|
444
|
+
},
|
|
445
|
+
west: {
|
|
446
|
+
x: -1,
|
|
447
|
+
y: 0
|
|
448
|
+
},
|
|
449
|
+
northeast: {
|
|
450
|
+
x: 1,
|
|
451
|
+
y: -1
|
|
452
|
+
},
|
|
453
|
+
northwest: {
|
|
454
|
+
x: -1,
|
|
455
|
+
y: -1
|
|
456
|
+
},
|
|
457
|
+
southeast: {
|
|
458
|
+
x: 1,
|
|
459
|
+
y: 1
|
|
460
|
+
},
|
|
461
|
+
southwest: {
|
|
462
|
+
x: -1,
|
|
463
|
+
y: 1
|
|
464
|
+
}
|
|
465
|
+
}, _ = [
|
|
466
|
+
"north",
|
|
467
|
+
"south",
|
|
468
|
+
"east",
|
|
469
|
+
"west",
|
|
470
|
+
"northeast",
|
|
471
|
+
"northwest",
|
|
472
|
+
"southeast",
|
|
473
|
+
"southwest"
|
|
474
|
+
], v = {
|
|
475
|
+
north: "south",
|
|
476
|
+
south: "north",
|
|
477
|
+
east: "west",
|
|
478
|
+
west: "east",
|
|
479
|
+
northeast: "southwest",
|
|
480
|
+
northwest: "southeast",
|
|
481
|
+
southeast: "northwest",
|
|
482
|
+
southwest: "northeast"
|
|
483
|
+
};
|
|
484
|
+
function y(e) {
|
|
485
|
+
return e ? Object.prototype.hasOwnProperty.call(g, e) : !1;
|
|
486
|
+
}
|
|
487
|
+
function b(e, t, n, r = 1) {
|
|
488
|
+
if (!y(n)) return {
|
|
489
|
+
x: e,
|
|
490
|
+
y: t
|
|
491
|
+
};
|
|
492
|
+
let i = g[n];
|
|
493
|
+
return {
|
|
494
|
+
x: e + i.x * r,
|
|
495
|
+
y: t + i.y * r
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function x(e, t, n, r = 1, i = 0) {
|
|
499
|
+
if (!y(n)) return {
|
|
500
|
+
x: e,
|
|
501
|
+
y: t
|
|
502
|
+
};
|
|
503
|
+
let a = g[n];
|
|
504
|
+
if (!(a.x !== 0 && a.y !== 0) || i <= 0) return b(e, t, n, r);
|
|
505
|
+
let o = r - i + i / Math.SQRT2;
|
|
506
|
+
return {
|
|
507
|
+
x: e + a.x * o,
|
|
508
|
+
y: t + a.y * o
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function S(e, t, n, r = 1) {
|
|
512
|
+
if (!y(n)) return {
|
|
513
|
+
x: e,
|
|
514
|
+
y: t
|
|
515
|
+
};
|
|
516
|
+
let i = g[n], a = Math.atan2(i.y, i.x);
|
|
517
|
+
return {
|
|
518
|
+
x: e + Math.cos(a) * r,
|
|
519
|
+
y: t + Math.sin(a) * r
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region src/ExitRenderer.ts
|
|
524
|
+
var C = {
|
|
525
|
+
OPEN_DOOR: "rgb(10, 155, 10)",
|
|
526
|
+
CLOSED_DOOR: "rgb(226, 205, 59)",
|
|
527
|
+
LOCKED_DOOR: "rgb(155, 10, 10)",
|
|
528
|
+
ONE_WAY_FILL: "rgb(155, 10, 10)"
|
|
529
|
+
};
|
|
530
|
+
function w(e) {
|
|
531
|
+
switch (e) {
|
|
532
|
+
case 1: return C.OPEN_DOOR;
|
|
533
|
+
case 2: return C.CLOSED_DOOR;
|
|
534
|
+
default: return C.LOCKED_DOOR;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
var T = class {
|
|
538
|
+
constructor(e, t) {
|
|
539
|
+
this.mapReader = e, this.settings = t;
|
|
540
|
+
}
|
|
541
|
+
getRoomEdgePoint(e, t, n, r) {
|
|
542
|
+
let i = r - (this.settings.borders ? this.settings.lineWidth / 2 : 0);
|
|
543
|
+
return this.settings.roomShape === "circle" ? S(e, t, n, i) : this.settings.roomShape === "roundedRectangle" ? x(e, t, n, i, this.settings.roomSize * .2) : b(e, t, n, i);
|
|
544
|
+
}
|
|
545
|
+
renderData(e, t) {
|
|
546
|
+
return this.renderDataWithColor(e, this.settings.lineColor, t);
|
|
547
|
+
}
|
|
548
|
+
renderDataWithColor(e, t, n) {
|
|
549
|
+
let r = e.aDir && p.includes(e.aDir), i = e.bDir && p.includes(e.bDir);
|
|
550
|
+
if (r && i) return this.renderTwoWayExitData(e, t, n);
|
|
551
|
+
if (r || i) {
|
|
552
|
+
let n = r ? "a" : "b";
|
|
553
|
+
return this.renderOneWayExitData(e, t, n);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
renderTwoWayExitData(e, t, n) {
|
|
557
|
+
let r = this.mapReader.getRoom(e.a), i = this.mapReader.getRoom(e.b);
|
|
558
|
+
if (!r || !i || !e.aDir || !e.bDir || r.customLines[h[e.aDir]] && i.customLines[h[e.bDir]] || r.z !== i.z && (n !== i.z && r.customLines[h[e.aDir]] || n !== r.z && i.customLines[h[e.bDir]])) return;
|
|
559
|
+
let a = this.getRoomEdgePoint(r.x, r.y, e.aDir, this.settings.roomSize / 2), o = this.getRoomEdgePoint(i.x, i.y, e.bDir, this.settings.roomSize / 2), s = [
|
|
560
|
+
a.x,
|
|
561
|
+
a.y,
|
|
562
|
+
o.x,
|
|
563
|
+
o.y
|
|
564
|
+
], c = [{
|
|
565
|
+
points: s,
|
|
566
|
+
stroke: t,
|
|
567
|
+
strokeWidth: this.settings.lineWidth
|
|
568
|
+
}], l = [], u = r.doors[h[e.aDir]] ?? i.doors[h[e.bDir]];
|
|
569
|
+
if (u) {
|
|
570
|
+
let e = s[0] + (s[2] - s[0]) / 2, t = s[1] + (s[3] - s[1]) / 2;
|
|
571
|
+
l.push({
|
|
572
|
+
x: e - this.settings.roomSize / 4,
|
|
573
|
+
y: t - this.settings.roomSize / 4,
|
|
574
|
+
width: this.settings.roomSize / 2,
|
|
575
|
+
height: this.settings.roomSize / 2,
|
|
576
|
+
stroke: w(u),
|
|
577
|
+
strokeWidth: this.settings.lineWidth
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
let d = Math.min(s[0], s[2]), f = Math.max(s[0], s[2]), p = Math.min(s[1], s[3]), m = Math.max(s[1], s[3]), g = (r.z === i.z ? void 0 : r.z === n ? i.id : r.id) ?? (r.area === i.area ? void 0 : i.id), _ = g === void 0 ? {} : {
|
|
581
|
+
from: {
|
|
582
|
+
x: r.x,
|
|
583
|
+
y: r.y
|
|
584
|
+
},
|
|
585
|
+
tip: {
|
|
586
|
+
x: o.x,
|
|
587
|
+
y: o.y
|
|
588
|
+
},
|
|
589
|
+
arrowColor: this.mapReader.getColorValue(i.env)
|
|
590
|
+
};
|
|
591
|
+
return {
|
|
592
|
+
lines: c,
|
|
593
|
+
arrows: [],
|
|
594
|
+
doors: l,
|
|
595
|
+
bounds: {
|
|
596
|
+
x: d,
|
|
597
|
+
y: p,
|
|
598
|
+
width: f - d,
|
|
599
|
+
height: m - p
|
|
600
|
+
},
|
|
601
|
+
targetRoomId: g,
|
|
602
|
+
..._
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
renderOneWayExitData(e, t, n) {
|
|
606
|
+
let r = n === "a" || !n && e.aDir, i = r ? this.mapReader.getRoom(e.a) : this.mapReader.getRoom(e.b), a = r ? this.mapReader.getRoom(e.b) : this.mapReader.getRoom(e.a), o = r ? e.aDir : e.bDir;
|
|
607
|
+
if (!o || !i || !a || !p.includes(o) || i.customLines[h[o] || o]) return;
|
|
608
|
+
if (i.area != a.area && o) {
|
|
609
|
+
let e = this.mapReader.getColorValue(a.env), t = this.getRoomEdgePoint(i.x, i.y, o, this.settings.roomSize / 2), n = b(i.x, i.y, o, this.settings.roomSize * 1.5), r = e;
|
|
610
|
+
return {
|
|
611
|
+
lines: [],
|
|
612
|
+
arrows: [{
|
|
613
|
+
points: [
|
|
614
|
+
t.x,
|
|
615
|
+
t.y,
|
|
616
|
+
n.x,
|
|
617
|
+
n.y
|
|
618
|
+
],
|
|
619
|
+
pointerLength: .3,
|
|
620
|
+
pointerWidth: .3,
|
|
621
|
+
strokeWidth: this.settings.lineWidth * 1.4,
|
|
622
|
+
stroke: r,
|
|
623
|
+
fill: r
|
|
624
|
+
}],
|
|
625
|
+
doors: [],
|
|
626
|
+
bounds: {
|
|
627
|
+
x: Math.min(t.x, n.x),
|
|
628
|
+
y: Math.min(t.y, n.y),
|
|
629
|
+
width: Math.abs(n.x - t.x),
|
|
630
|
+
height: Math.abs(n.y - t.y)
|
|
631
|
+
},
|
|
632
|
+
targetRoomId: a.id,
|
|
633
|
+
from: {
|
|
634
|
+
x: i.x,
|
|
635
|
+
y: i.y
|
|
636
|
+
},
|
|
637
|
+
tip: {
|
|
638
|
+
x: n.x,
|
|
639
|
+
y: n.y
|
|
640
|
+
},
|
|
641
|
+
arrowColor: r
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
let s = a.area !== i.area || a.z !== i.z, c = {
|
|
645
|
+
x: a.x,
|
|
646
|
+
y: a.y
|
|
647
|
+
};
|
|
648
|
+
s && (c = b(i.x, i.y, o, this.settings.roomSize / 2));
|
|
649
|
+
let l = b(i.x, i.y, o, .3), u = l.x - (l.x - c.x) / 2, d = l.y - (l.y - c.y) / 2, f = this.getRoomEdgePoint(i.x, i.y, o, this.settings.roomSize / 2), m = [
|
|
650
|
+
f.x,
|
|
651
|
+
f.y,
|
|
652
|
+
c.x,
|
|
653
|
+
c.y
|
|
654
|
+
], g = [
|
|
655
|
+
f.x,
|
|
656
|
+
c.x,
|
|
657
|
+
u
|
|
658
|
+
], _ = [
|
|
659
|
+
f.y,
|
|
660
|
+
c.y,
|
|
661
|
+
d
|
|
662
|
+
], v = Math.min(...g), y = Math.max(...g), x = Math.min(..._), S = Math.max(..._);
|
|
663
|
+
return {
|
|
664
|
+
lines: [{
|
|
665
|
+
points: m,
|
|
666
|
+
stroke: t,
|
|
667
|
+
strokeWidth: this.settings.lineWidth,
|
|
668
|
+
dash: [.1, .05]
|
|
669
|
+
}],
|
|
670
|
+
arrows: [{
|
|
671
|
+
points: [
|
|
672
|
+
m[0],
|
|
673
|
+
m[1],
|
|
674
|
+
u,
|
|
675
|
+
d
|
|
676
|
+
],
|
|
677
|
+
pointerLength: .5,
|
|
678
|
+
pointerWidth: .35,
|
|
679
|
+
strokeWidth: this.settings.lineWidth * 1.4,
|
|
680
|
+
stroke: t,
|
|
681
|
+
fill: C.ONE_WAY_FILL,
|
|
682
|
+
dash: [.1, .05]
|
|
683
|
+
}],
|
|
684
|
+
doors: [],
|
|
685
|
+
bounds: {
|
|
686
|
+
x: v,
|
|
687
|
+
y: x,
|
|
688
|
+
width: y - v,
|
|
689
|
+
height: S - x
|
|
690
|
+
},
|
|
691
|
+
...s ? { targetRoomId: a.id } : {}
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
getInnerExitAreaTargets(e) {
|
|
695
|
+
let t = [
|
|
696
|
+
"up",
|
|
697
|
+
"down",
|
|
698
|
+
"in",
|
|
699
|
+
"out"
|
|
700
|
+
], n = this.settings.roomSize, r = [];
|
|
701
|
+
for (let i of t) {
|
|
702
|
+
let t = e.exits[i];
|
|
703
|
+
if (t === void 0) continue;
|
|
704
|
+
let a = this.mapReader.getRoom(t);
|
|
705
|
+
!a || a.area === e.area || r.push({
|
|
706
|
+
bounds: {
|
|
707
|
+
x: e.x - n / 4,
|
|
708
|
+
y: e.y - n / 4,
|
|
709
|
+
width: n / 2,
|
|
710
|
+
height: n / 2
|
|
711
|
+
},
|
|
712
|
+
targetRoomId: t,
|
|
713
|
+
from: {
|
|
714
|
+
x: e.x,
|
|
715
|
+
y: e.y
|
|
716
|
+
},
|
|
717
|
+
tip: {
|
|
718
|
+
x: e.x,
|
|
719
|
+
y: e.y
|
|
720
|
+
},
|
|
721
|
+
arrowColor: this.mapReader.getColorValue(a.env)
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
return r;
|
|
725
|
+
}
|
|
726
|
+
getSpecialExitAreaTargets(e) {
|
|
727
|
+
let t = [], n = {
|
|
728
|
+
u: "up",
|
|
729
|
+
d: "down",
|
|
730
|
+
i: "in",
|
|
731
|
+
o: "out"
|
|
732
|
+
};
|
|
733
|
+
for (let [r, i] of Object.entries(e.customLines)) {
|
|
734
|
+
let a = e.specialExits[r];
|
|
735
|
+
if (a === void 0) {
|
|
736
|
+
let t = m[r] ?? n[r];
|
|
737
|
+
t && (a = e.exits[t] ?? e.specialExits[t]);
|
|
738
|
+
}
|
|
739
|
+
if (a === void 0 && (a = e.exits[r] ?? e.specialExits[r]), a === void 0) continue;
|
|
740
|
+
let o = this.mapReader.getRoom(a);
|
|
741
|
+
if (!o || o.area === e.area && o.z === e.z) continue;
|
|
742
|
+
let s = [e.x, e.y];
|
|
743
|
+
i.points.reduce((e, t) => (e.push(t.x, -t.y), e), s);
|
|
744
|
+
let c = Infinity, l = Infinity, u = -Infinity, d = -Infinity;
|
|
745
|
+
for (let e = 0; e < s.length; e += 2) c = Math.min(c, s[e]), u = Math.max(u, s[e]), l = Math.min(l, s[e + 1]), d = Math.max(d, s[e + 1]);
|
|
746
|
+
let f = s.length - 2, p = {
|
|
747
|
+
x: s[f],
|
|
748
|
+
y: s[f + 1]
|
|
749
|
+
};
|
|
750
|
+
t.push({
|
|
751
|
+
bounds: {
|
|
752
|
+
x: c,
|
|
753
|
+
y: l,
|
|
754
|
+
width: u - c,
|
|
755
|
+
height: d - l
|
|
756
|
+
},
|
|
757
|
+
targetRoomId: a,
|
|
758
|
+
from: {
|
|
759
|
+
x: e.x,
|
|
760
|
+
y: e.y
|
|
761
|
+
},
|
|
762
|
+
tip: p,
|
|
763
|
+
arrowColor: this.mapReader.getColorValue(o.env)
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
return t;
|
|
767
|
+
}
|
|
768
|
+
}, E = {
|
|
769
|
+
1: "north",
|
|
770
|
+
2: "northeast",
|
|
771
|
+
3: "northwest",
|
|
772
|
+
4: "east",
|
|
773
|
+
5: "west",
|
|
774
|
+
6: "south",
|
|
775
|
+
7: "southeast",
|
|
776
|
+
8: "southwest",
|
|
777
|
+
9: "up",
|
|
778
|
+
10: "down",
|
|
779
|
+
11: "in",
|
|
780
|
+
12: "out"
|
|
781
|
+
};
|
|
782
|
+
function D(e, t, n, r, i) {
|
|
783
|
+
return e.roomShape === "circle" ? S(t, n, r, i) : e.roomShape === "roundedRectangle" ? x(t, n, r, i, e.roomSize * .2) : b(t, n, r, i);
|
|
784
|
+
}
|
|
785
|
+
function O(e, t, n) {
|
|
786
|
+
let r = [];
|
|
787
|
+
for (let i of e.stubs) {
|
|
788
|
+
let a = E[i];
|
|
789
|
+
if (!a) continue;
|
|
790
|
+
let o = D(t, e.x, e.y, a, t.roomSize / 2), s = b(e.x, e.y, a, t.roomSize / 2 + .5);
|
|
791
|
+
r.push({
|
|
792
|
+
roomId: e.id,
|
|
793
|
+
direction: a,
|
|
794
|
+
x1: o.x,
|
|
795
|
+
y1: o.y,
|
|
796
|
+
x2: s.x,
|
|
797
|
+
y2: s.y,
|
|
798
|
+
stroke: n ?? t.lineColor,
|
|
799
|
+
strokeWidth: t.lineWidth
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
return r;
|
|
803
|
+
}
|
|
804
|
+
//#endregion
|
|
805
|
+
//#region src/scene/SpecialExitStyle.ts
|
|
806
|
+
var k = {
|
|
807
|
+
1: "rgb(10, 155, 10)",
|
|
808
|
+
2: "rgb(226, 205, 59)",
|
|
809
|
+
3: "rgb(155, 10, 10)"
|
|
810
|
+
};
|
|
811
|
+
function A(e, t, n) {
|
|
812
|
+
let r = [];
|
|
813
|
+
for (let [i, a] of Object.entries(e.customLines)) {
|
|
814
|
+
let o = [e.x, e.y];
|
|
815
|
+
for (let e of a.points) o.push(e.x, -e.y);
|
|
816
|
+
let s = n ?? `rgb(${a.attributes.color.r}, ${a.attributes.color.g}, ${a.attributes.color.b})`, c;
|
|
817
|
+
a.attributes.style === "dot line" ? c = [.05, .05] : a.attributes.style === "dash line" ? c = [.4, .2] : a.attributes.style === "dash dot line" ? c = [
|
|
818
|
+
.4,
|
|
819
|
+
.15,
|
|
820
|
+
.05,
|
|
821
|
+
.15
|
|
822
|
+
] : a.attributes.style === "dash dot dot line" && (c = [
|
|
823
|
+
.4,
|
|
824
|
+
.15,
|
|
825
|
+
.05,
|
|
826
|
+
.15,
|
|
827
|
+
.05,
|
|
828
|
+
.15
|
|
829
|
+
]);
|
|
830
|
+
let l = {
|
|
831
|
+
points: o,
|
|
832
|
+
stroke: s,
|
|
833
|
+
strokeWidth: t.lineWidth,
|
|
834
|
+
dash: c
|
|
835
|
+
}, u;
|
|
836
|
+
if (a.attributes.arrow && o.length >= 4) {
|
|
837
|
+
let e = o.length - 2, n = o[e], r = o[e + 1], i = o[e - 2], a = o[e - 1], c = Math.atan2(r - a, n - i), l = .3, d = .1;
|
|
838
|
+
u = {
|
|
839
|
+
tipX: n,
|
|
840
|
+
tipY: r,
|
|
841
|
+
x1: n - l * Math.cos(c - Math.atan2(d, l)),
|
|
842
|
+
y1: r - l * Math.sin(c - Math.atan2(d, l)),
|
|
843
|
+
x2: n - l * Math.cos(c + Math.atan2(d, l)),
|
|
844
|
+
y2: r - l * Math.sin(c + Math.atan2(d, l)),
|
|
845
|
+
fill: s,
|
|
846
|
+
stroke: s,
|
|
847
|
+
strokeWidth: t.lineWidth
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
let d, f = e.doors[i];
|
|
851
|
+
if (f && o.length >= 4) {
|
|
852
|
+
let e = o[0] + (o[2] - o[0]) / 2, n = o[1] + (o[3] - o[1]) / 2, r = t.roomSize / 2;
|
|
853
|
+
d = {
|
|
854
|
+
x: e - r / 2,
|
|
855
|
+
y: n - r / 2,
|
|
856
|
+
width: r,
|
|
857
|
+
height: r,
|
|
858
|
+
stroke: k[f] ?? k[3],
|
|
859
|
+
strokeWidth: t.lineWidth
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
r.push({
|
|
863
|
+
dir: i,
|
|
864
|
+
line: l,
|
|
865
|
+
arrow: u,
|
|
866
|
+
door: d
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
return r;
|
|
870
|
+
}
|
|
871
|
+
//#endregion
|
|
872
|
+
//#region src/utils/textMeasure.ts
|
|
873
|
+
var j = 72, M = 200, N = 120, P = /* @__PURE__ */ new Map(), F = null;
|
|
874
|
+
function I() {
|
|
875
|
+
return F || (F = e.Util.createCanvasElement(), F.width = M, F.height = M), F;
|
|
876
|
+
}
|
|
877
|
+
function ee(e, t) {
|
|
878
|
+
let n = `${e}::${t}`, r = P.get(n);
|
|
879
|
+
if (r !== void 0) return r;
|
|
880
|
+
let i = I().getContext("2d", { willReadFrequently: !0 }), a = `bold ${j}px ${t}`;
|
|
881
|
+
i.clearRect(0, 0, M, M), i.font = a, i.textBaseline = "alphabetic", i.textAlign = "center", i.fillStyle = "#ffffff", i.fillText(e, M / 2, N);
|
|
882
|
+
let { data: o } = i.getImageData(0, 0, M, M), s = M, c = -1;
|
|
883
|
+
for (let e = 0; e < M; e++) for (let t = 0; t < M; t++) o[(e * M + t) * 4 + 3] > 16 && (e < s && (s = e), e > c && (c = e));
|
|
884
|
+
if (c === -1) {
|
|
885
|
+
let e = {
|
|
886
|
+
baselineRatio: .35,
|
|
887
|
+
konvaCorrectionRatio: 0
|
|
888
|
+
};
|
|
889
|
+
return P.set(n, e), e;
|
|
890
|
+
}
|
|
891
|
+
let l = (N - s - Math.max(0, c - N)) / 2 / j, u = i.measureText("M"), d = {
|
|
892
|
+
baselineRatio: l,
|
|
893
|
+
konvaCorrectionRatio: ((u.fontBoundingBoxAscent ?? u.actualBoundingBoxAscent ?? 0) - (u.fontBoundingBoxDescent ?? u.actualBoundingBoxDescent ?? 0)) / 2 / j - l
|
|
894
|
+
};
|
|
895
|
+
return P.set(n, d), d;
|
|
896
|
+
}
|
|
897
|
+
//#endregion
|
|
898
|
+
//#region src/scene/RoomStyle.ts
|
|
899
|
+
function te(e, t, i, a) {
|
|
900
|
+
let o = t.getColorValue(e.env), s = i.coloredMode ? n(o, .5) : i.frameMode ? i.backgroundColor : o, c = i.coloredMode ? r(o, .1) : o;
|
|
901
|
+
return {
|
|
902
|
+
fillColor: s,
|
|
903
|
+
strokeColor: a ? i.frameMode || i.coloredMode ? c : a : i.frameMode || i.coloredMode ? c : i.lineColor,
|
|
904
|
+
borderWidth: i.borders ? i.lineWidth : 0,
|
|
905
|
+
symbolColor: e.userData?.["system.fallback_symbol_color"] ?? (i.frameMode || i.coloredMode ? c : t.getSymbolColor(e.env)),
|
|
906
|
+
envColor: o
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
function ne(e, t) {
|
|
910
|
+
if (!t.emboss) return null;
|
|
911
|
+
let i = t.roomSize, a = t.borders ? t.lineWidth / 2 : 0, o = t.lineWidth, s = r(e, .35), c = n(e, .45);
|
|
912
|
+
if (t.roomShape === "circle") {
|
|
913
|
+
let e = i / 2, t = i / 2, n = i / 2 - a, r = [];
|
|
914
|
+
for (let i = 0; i <= 48; i++) {
|
|
915
|
+
let a = i / 48 * 360 * Math.PI / 180;
|
|
916
|
+
r.push(e + Math.cos(a) * n, t + Math.sin(a) * n);
|
|
917
|
+
}
|
|
918
|
+
let l = [];
|
|
919
|
+
for (let r = 0; r <= 19; r++) {
|
|
920
|
+
let i = (200 + r / 19 * 140) * Math.PI / 180;
|
|
921
|
+
l.push(e + Math.cos(i) * n, t + Math.sin(i) * n);
|
|
922
|
+
}
|
|
923
|
+
return {
|
|
924
|
+
shadow: {
|
|
925
|
+
points: r,
|
|
926
|
+
stroke: c,
|
|
927
|
+
strokeWidth: o,
|
|
928
|
+
lineCap: "round",
|
|
929
|
+
lineJoin: "round"
|
|
930
|
+
},
|
|
931
|
+
highlight: {
|
|
932
|
+
points: l,
|
|
933
|
+
stroke: s,
|
|
934
|
+
strokeWidth: o,
|
|
935
|
+
lineCap: "round",
|
|
936
|
+
lineJoin: "round"
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
if (t.roomShape === "roundedRectangle") {
|
|
941
|
+
let e = (i - a * 2) * .2, t = a, n = a, r = i - a, l = i - a, u = [];
|
|
942
|
+
for (let n = 0; n <= 10 / 2; n++) {
|
|
943
|
+
let r = (135 + n / (10 / 2) * 45) * Math.PI / 180;
|
|
944
|
+
u.push(t + e + Math.cos(r) * e, l - e + Math.sin(r) * e);
|
|
945
|
+
}
|
|
946
|
+
for (let r = 1; r <= 10; r++) {
|
|
947
|
+
let i = (180 + r / 10 * 90) * Math.PI / 180;
|
|
948
|
+
u.push(t + e + Math.cos(i) * e, n + e + Math.sin(i) * e);
|
|
949
|
+
}
|
|
950
|
+
for (let t = 1; t <= 10 / 2; t++) {
|
|
951
|
+
let i = (270 + t / (10 / 2) * 45) * Math.PI / 180;
|
|
952
|
+
u.push(r - e + Math.cos(i) * e, n + e + Math.sin(i) * e);
|
|
953
|
+
}
|
|
954
|
+
let d = u.slice(), f = [];
|
|
955
|
+
for (let t = 0; t <= 10 / 2; t++) {
|
|
956
|
+
let i = (315 + t / (10 / 2) * 45) * Math.PI / 180;
|
|
957
|
+
f.push(r - e + Math.cos(i) * e, n + e + Math.sin(i) * e);
|
|
958
|
+
}
|
|
959
|
+
for (let t = 1; t <= 10; t++) {
|
|
960
|
+
let n = t / 10 * 90 * Math.PI / 180;
|
|
961
|
+
f.push(r - e + Math.cos(n) * e, l - e + Math.sin(n) * e);
|
|
962
|
+
}
|
|
963
|
+
for (let n = 1; n <= 10 / 2; n++) {
|
|
964
|
+
let r = (90 + n / (10 / 2) * 45) * Math.PI / 180;
|
|
965
|
+
f.push(t + e + Math.cos(r) * e, l - e + Math.sin(r) * e);
|
|
966
|
+
}
|
|
967
|
+
return {
|
|
968
|
+
highlight: {
|
|
969
|
+
points: d,
|
|
970
|
+
stroke: s,
|
|
971
|
+
strokeWidth: o,
|
|
972
|
+
lineCap: "round",
|
|
973
|
+
lineJoin: "round"
|
|
974
|
+
},
|
|
975
|
+
shadow: {
|
|
976
|
+
points: f,
|
|
977
|
+
stroke: c,
|
|
978
|
+
strokeWidth: o,
|
|
979
|
+
lineCap: "round",
|
|
980
|
+
lineJoin: "round"
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
return {
|
|
985
|
+
highlight: {
|
|
986
|
+
points: [
|
|
987
|
+
a,
|
|
988
|
+
i - a,
|
|
989
|
+
a,
|
|
990
|
+
a,
|
|
991
|
+
i - a,
|
|
992
|
+
a
|
|
993
|
+
],
|
|
994
|
+
stroke: s,
|
|
995
|
+
strokeWidth: o
|
|
996
|
+
},
|
|
997
|
+
shadow: {
|
|
998
|
+
points: [
|
|
999
|
+
a,
|
|
1000
|
+
i - a,
|
|
1001
|
+
i - a,
|
|
1002
|
+
i - a,
|
|
1003
|
+
i - a,
|
|
1004
|
+
a
|
|
1005
|
+
],
|
|
1006
|
+
stroke: c,
|
|
1007
|
+
strokeWidth: o
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
//#endregion
|
|
1012
|
+
//#region src/scene/elements/RoomLayout.ts
|
|
1013
|
+
function L(e, t, r, i) {
|
|
1014
|
+
let { fillColor: a, strokeColor: o, borderWidth: s, symbolColor: c } = te(e, t, r, i.strokeOverride), l = r.roomSize, u = [], d = ne(a, r), f = d ? 0 : s, p = r.coloredMode && f > 0 && i.flatPipeline, m = (e) => r.roomShape === "roundedRectangle" ? Math.max(0, (l - 2 * e) * .2) : 0;
|
|
1015
|
+
if (p) {
|
|
1016
|
+
let e = [n(o, .5), o], t = s * 2;
|
|
1017
|
+
r.roomShape === "circle" ? u.push({
|
|
1018
|
+
type: "circle",
|
|
1019
|
+
cx: l / 2,
|
|
1020
|
+
cy: l / 2,
|
|
1021
|
+
radius: l / 2 - t,
|
|
1022
|
+
paint: { fill: a }
|
|
1023
|
+
}) : u.push({
|
|
1024
|
+
type: "rect",
|
|
1025
|
+
x: t,
|
|
1026
|
+
y: t,
|
|
1027
|
+
width: l - t * 2,
|
|
1028
|
+
height: l - t * 2,
|
|
1029
|
+
cornerRadius: m(t),
|
|
1030
|
+
paint: { fill: a }
|
|
1031
|
+
});
|
|
1032
|
+
for (let t = 0; t < e.length; t++) {
|
|
1033
|
+
let n = s / 2 + t * s;
|
|
1034
|
+
r.roomShape === "circle" ? u.push({
|
|
1035
|
+
type: "circle",
|
|
1036
|
+
cx: l / 2,
|
|
1037
|
+
cy: l / 2,
|
|
1038
|
+
radius: l / 2 - n,
|
|
1039
|
+
paint: {
|
|
1040
|
+
stroke: e[t],
|
|
1041
|
+
strokeWidth: s
|
|
1042
|
+
}
|
|
1043
|
+
}) : u.push({
|
|
1044
|
+
type: "rect",
|
|
1045
|
+
x: n,
|
|
1046
|
+
y: n,
|
|
1047
|
+
width: l - n * 2,
|
|
1048
|
+
height: l - n * 2,
|
|
1049
|
+
cornerRadius: m(n),
|
|
1050
|
+
paint: {
|
|
1051
|
+
stroke: e[t],
|
|
1052
|
+
strokeWidth: s
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
} else r.roomShape === "circle" ? u.push({
|
|
1057
|
+
type: "circle",
|
|
1058
|
+
cx: l / 2,
|
|
1059
|
+
cy: l / 2,
|
|
1060
|
+
radius: l / 2,
|
|
1061
|
+
paint: {
|
|
1062
|
+
fill: a,
|
|
1063
|
+
stroke: f ? o : void 0,
|
|
1064
|
+
strokeWidth: f
|
|
1065
|
+
}
|
|
1066
|
+
}) : u.push({
|
|
1067
|
+
type: "rect",
|
|
1068
|
+
x: 0,
|
|
1069
|
+
y: 0,
|
|
1070
|
+
width: l,
|
|
1071
|
+
height: l,
|
|
1072
|
+
cornerRadius: r.roomShape === "roundedRectangle" ? l * .2 : 0,
|
|
1073
|
+
paint: {
|
|
1074
|
+
fill: a,
|
|
1075
|
+
stroke: f ? o : void 0,
|
|
1076
|
+
strokeWidth: f
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
1079
|
+
if (d && (u.push({
|
|
1080
|
+
type: "line",
|
|
1081
|
+
points: d.shadow.points,
|
|
1082
|
+
paint: {
|
|
1083
|
+
stroke: d.shadow.stroke,
|
|
1084
|
+
strokeWidth: d.shadow.strokeWidth
|
|
1085
|
+
},
|
|
1086
|
+
lineCap: d.shadow.lineCap,
|
|
1087
|
+
lineJoin: d.shadow.lineJoin
|
|
1088
|
+
}), u.push({
|
|
1089
|
+
type: "line",
|
|
1090
|
+
points: d.highlight.points,
|
|
1091
|
+
paint: {
|
|
1092
|
+
stroke: d.highlight.stroke,
|
|
1093
|
+
strokeWidth: d.highlight.strokeWidth
|
|
1094
|
+
},
|
|
1095
|
+
lineCap: d.highlight.lineCap,
|
|
1096
|
+
lineJoin: d.shadow.lineJoin
|
|
1097
|
+
})), e.roomChar) {
|
|
1098
|
+
let t = l * .75, { baselineRatio: n, konvaCorrectionRatio: i } = ee(e.roomChar, r.fontFamily), a = Math.max(l, e.roomChar.length * t * .8), o = (a - l) / 2;
|
|
1099
|
+
u.push({
|
|
1100
|
+
type: "text",
|
|
1101
|
+
x: -o,
|
|
1102
|
+
y: 0,
|
|
1103
|
+
text: e.roomChar,
|
|
1104
|
+
fontSize: t,
|
|
1105
|
+
fontFamily: r.fontFamily,
|
|
1106
|
+
fontStyle: "bold",
|
|
1107
|
+
fill: c,
|
|
1108
|
+
align: "center",
|
|
1109
|
+
verticalAlign: "middle",
|
|
1110
|
+
width: a,
|
|
1111
|
+
height: l,
|
|
1112
|
+
baselineRatio: n,
|
|
1113
|
+
konvaCorrectionRatio: i
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
return {
|
|
1117
|
+
type: "group",
|
|
1118
|
+
x: e.x - l / 2,
|
|
1119
|
+
y: e.y - l / 2,
|
|
1120
|
+
layer: "room",
|
|
1121
|
+
hit: {
|
|
1122
|
+
kind: "room",
|
|
1123
|
+
id: e.id,
|
|
1124
|
+
payload: e
|
|
1125
|
+
},
|
|
1126
|
+
children: u
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
//#endregion
|
|
1130
|
+
//#region src/scene/InnerExitStyle.ts
|
|
1131
|
+
var re = [
|
|
1132
|
+
"up",
|
|
1133
|
+
"down",
|
|
1134
|
+
"in",
|
|
1135
|
+
"out"
|
|
1136
|
+
];
|
|
1137
|
+
function ie(e, t, n, r) {
|
|
1138
|
+
let i = r * Math.PI / 180, a = [];
|
|
1139
|
+
for (let r = 0; r < 3; r++) {
|
|
1140
|
+
let o = 2 * Math.PI * r / 3 - Math.PI / 2, s = Math.cos(o) * n * 1.4, c = Math.sin(o) * n * .8, l = s * Math.cos(i) - c * Math.sin(i), u = s * Math.sin(i) + c * Math.cos(i);
|
|
1141
|
+
a.push(e + l, t + u);
|
|
1142
|
+
}
|
|
1143
|
+
return a;
|
|
1144
|
+
}
|
|
1145
|
+
function ae(e, t, n) {
|
|
1146
|
+
let r = e.userData?.["system.fallback_symbol_color"];
|
|
1147
|
+
return {
|
|
1148
|
+
symbolColor: r ?? (n.frameMode || n.coloredMode ? t.getColorValue(e.env) : t.getSymbolColor(e.env)),
|
|
1149
|
+
symbolFill: r ?? (n.frameMode || n.coloredMode ? t.getColorValue(e.env) : t.getSymbolColor(e.env, .6))
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
var R = {
|
|
1153
|
+
1: "rgb(10, 155, 10)",
|
|
1154
|
+
2: "rgb(226, 205, 59)",
|
|
1155
|
+
3: "rgb(155, 10, 10)"
|
|
1156
|
+
};
|
|
1157
|
+
function z(e, t, n) {
|
|
1158
|
+
let r = n.roomSize, i = r / 5, a = (e, t, n) => ({
|
|
1159
|
+
cx: e,
|
|
1160
|
+
cy: t,
|
|
1161
|
+
vertices: ie(e, t, i, n)
|
|
1162
|
+
});
|
|
1163
|
+
switch (t) {
|
|
1164
|
+
case "up": {
|
|
1165
|
+
let t = b(e.x, e.y, "south", r / 4);
|
|
1166
|
+
return [a(t.x, t.y, 0)];
|
|
1167
|
+
}
|
|
1168
|
+
case "down": {
|
|
1169
|
+
let t = b(e.x, e.y, "north", r / 4);
|
|
1170
|
+
return [a(t.x, t.y, 180)];
|
|
1171
|
+
}
|
|
1172
|
+
case "in": {
|
|
1173
|
+
let t = b(e.x, e.y, "west", r / 4), n = b(e.x, e.y, "east", r / 4);
|
|
1174
|
+
return [a(t.x, t.y, 90), a(n.x, n.y, -90)];
|
|
1175
|
+
}
|
|
1176
|
+
case "out": {
|
|
1177
|
+
let t = b(e.x, e.y, "west", r / 4), n = b(e.x, e.y, "east", r / 4);
|
|
1178
|
+
return [a(t.x, t.y, -90), a(n.x, n.y, 90)];
|
|
1179
|
+
}
|
|
1180
|
+
default: return [];
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
function oe(e, t, n) {
|
|
1184
|
+
let r = [], { symbolColor: i, symbolFill: a } = ae(e, t, n);
|
|
1185
|
+
for (let t of re) {
|
|
1186
|
+
if (!e.exits[t]) continue;
|
|
1187
|
+
let o = e.doors[t], s = o === void 0 ? i : R[o] ?? R[3];
|
|
1188
|
+
for (let i of z(e, t, n)) r.push({
|
|
1189
|
+
cx: i.cx,
|
|
1190
|
+
cy: i.cy,
|
|
1191
|
+
vertices: i.vertices,
|
|
1192
|
+
fill: a,
|
|
1193
|
+
stroke: s,
|
|
1194
|
+
strokeWidth: n.lineWidth
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
return { triangles: r };
|
|
1198
|
+
}
|
|
1199
|
+
//#endregion
|
|
1200
|
+
//#region src/scene/elements/ExitLayout.ts
|
|
1201
|
+
function B(e, t, n) {
|
|
1202
|
+
let r = n.roomSize, i = e.x - r / 2, a = e.y - r / 2, { triangles: o } = oe(e, t, n);
|
|
1203
|
+
return o.map((e) => {
|
|
1204
|
+
let t = Array(e.vertices.length);
|
|
1205
|
+
for (let n = 0; n < e.vertices.length; n += 2) t[n] = e.vertices[n] - i, t[n + 1] = e.vertices[n + 1] - a;
|
|
1206
|
+
return {
|
|
1207
|
+
type: "polygon",
|
|
1208
|
+
vertices: t,
|
|
1209
|
+
paint: {
|
|
1210
|
+
fill: e.fill,
|
|
1211
|
+
stroke: e.stroke,
|
|
1212
|
+
strokeWidth: e.strokeWidth
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
function V(e, t) {
|
|
1218
|
+
let n = [];
|
|
1219
|
+
for (let t of e.lines) n.push({
|
|
1220
|
+
type: "line",
|
|
1221
|
+
points: t.points,
|
|
1222
|
+
paint: {
|
|
1223
|
+
stroke: t.stroke,
|
|
1224
|
+
strokeWidth: t.strokeWidth,
|
|
1225
|
+
dash: t.dash
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
for (let t of e.arrows) se(n, t);
|
|
1229
|
+
for (let t of e.doors) n.push({
|
|
1230
|
+
type: "rect",
|
|
1231
|
+
x: t.x,
|
|
1232
|
+
y: t.y,
|
|
1233
|
+
width: t.width,
|
|
1234
|
+
height: t.height,
|
|
1235
|
+
paint: {
|
|
1236
|
+
stroke: t.stroke,
|
|
1237
|
+
strokeWidth: t.strokeWidth
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
return {
|
|
1241
|
+
type: "group",
|
|
1242
|
+
x: 0,
|
|
1243
|
+
y: 0,
|
|
1244
|
+
layer: "link",
|
|
1245
|
+
...t ? { hit: t } : {},
|
|
1246
|
+
children: n
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
function se(e, t) {
|
|
1250
|
+
e.push({
|
|
1251
|
+
type: "line",
|
|
1252
|
+
points: t.points,
|
|
1253
|
+
paint: {
|
|
1254
|
+
stroke: t.stroke,
|
|
1255
|
+
strokeWidth: t.strokeWidth,
|
|
1256
|
+
dash: t.dash
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
let n = t.points.length - 2, r = t.points[n], i = t.points[n + 1], a = t.points[n - 2], o = t.points[n - 1], s = Math.atan2(i - o, r - a), c = t.pointerLength, l = t.pointerWidth / 2, u = r - c * Math.cos(s - Math.atan2(l, c)), d = i - c * Math.sin(s - Math.atan2(l, c)), f = r - c * Math.cos(s + Math.atan2(l, c)), p = i - c * Math.sin(s + Math.atan2(l, c));
|
|
1260
|
+
e.push({
|
|
1261
|
+
type: "polygon",
|
|
1262
|
+
vertices: [
|
|
1263
|
+
r,
|
|
1264
|
+
i,
|
|
1265
|
+
u,
|
|
1266
|
+
d,
|
|
1267
|
+
f,
|
|
1268
|
+
p
|
|
1269
|
+
],
|
|
1270
|
+
paint: {
|
|
1271
|
+
fill: t.fill,
|
|
1272
|
+
stroke: t.stroke,
|
|
1273
|
+
strokeWidth: t.strokeWidth
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
//#endregion
|
|
1278
|
+
//#region src/scene/elements/SpecialExitLayout.ts
|
|
1279
|
+
function H(e, t) {
|
|
1280
|
+
let n = [];
|
|
1281
|
+
if (n.push({
|
|
1282
|
+
type: "line",
|
|
1283
|
+
points: e.line.points,
|
|
1284
|
+
paint: {
|
|
1285
|
+
stroke: e.line.stroke,
|
|
1286
|
+
strokeWidth: e.line.strokeWidth,
|
|
1287
|
+
dash: e.line.dash
|
|
1288
|
+
}
|
|
1289
|
+
}), e.arrow) {
|
|
1290
|
+
let t = e.arrow;
|
|
1291
|
+
n.push({
|
|
1292
|
+
type: "polygon",
|
|
1293
|
+
vertices: [
|
|
1294
|
+
t.tipX,
|
|
1295
|
+
t.tipY,
|
|
1296
|
+
t.x1,
|
|
1297
|
+
t.y1,
|
|
1298
|
+
t.x2,
|
|
1299
|
+
t.y2
|
|
1300
|
+
],
|
|
1301
|
+
paint: {
|
|
1302
|
+
fill: t.fill,
|
|
1303
|
+
stroke: t.stroke,
|
|
1304
|
+
strokeWidth: t.strokeWidth
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
if (e.door) {
|
|
1309
|
+
let t = e.door;
|
|
1310
|
+
n.push({
|
|
1311
|
+
type: "rect",
|
|
1312
|
+
x: t.x,
|
|
1313
|
+
y: t.y,
|
|
1314
|
+
width: t.width,
|
|
1315
|
+
height: t.height,
|
|
1316
|
+
paint: {
|
|
1317
|
+
stroke: t.stroke,
|
|
1318
|
+
strokeWidth: t.strokeWidth
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
return {
|
|
1323
|
+
type: "group",
|
|
1324
|
+
x: 0,
|
|
1325
|
+
y: 0,
|
|
1326
|
+
layer: "link",
|
|
1327
|
+
hit: {
|
|
1328
|
+
kind: "specialExit",
|
|
1329
|
+
id: `${t}:${e.dir}`,
|
|
1330
|
+
payload: {
|
|
1331
|
+
roomId: t,
|
|
1332
|
+
exitName: e.dir
|
|
1333
|
+
}
|
|
1334
|
+
},
|
|
1335
|
+
children: n
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
//#endregion
|
|
1339
|
+
//#region src/scene/elements/StubLayout.ts
|
|
1340
|
+
function U(e) {
|
|
1341
|
+
return {
|
|
1342
|
+
type: "group",
|
|
1343
|
+
x: 0,
|
|
1344
|
+
y: 0,
|
|
1345
|
+
layer: "link",
|
|
1346
|
+
hit: {
|
|
1347
|
+
kind: "stub",
|
|
1348
|
+
id: `${e.roomId}:${e.direction}`,
|
|
1349
|
+
payload: e
|
|
1350
|
+
},
|
|
1351
|
+
children: [{
|
|
1352
|
+
type: "line",
|
|
1353
|
+
points: [
|
|
1354
|
+
e.x1,
|
|
1355
|
+
e.y1,
|
|
1356
|
+
e.x2,
|
|
1357
|
+
e.y2
|
|
1358
|
+
],
|
|
1359
|
+
paint: {
|
|
1360
|
+
stroke: e.stroke,
|
|
1361
|
+
strokeWidth: e.strokeWidth
|
|
1362
|
+
}
|
|
1363
|
+
}]
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1366
|
+
//#endregion
|
|
1367
|
+
//#region src/scene/elements/LabelLayout.ts
|
|
1368
|
+
function W(e) {
|
|
1369
|
+
let t = (e?.alpha ?? 255) / 255, n = (e) => Math.min(255, Math.max(0, e ?? 0));
|
|
1370
|
+
return `rgba(${n(e?.r)}, ${n(e?.g)}, ${n(e?.b)}, ${t})`;
|
|
1371
|
+
}
|
|
1372
|
+
function ce(e, t) {
|
|
1373
|
+
if (t.labelRenderMode === "none") return null;
|
|
1374
|
+
let n = e.X, r = -e.Y, i = !!e.noScaling, a = i ? n : 0, o = i ? r : 0, s = i ? 0 : n, c = i ? 0 : r;
|
|
1375
|
+
if (t.labelRenderMode === "image" && e.pixMap) return {
|
|
1376
|
+
type: "group",
|
|
1377
|
+
x: a,
|
|
1378
|
+
y: o,
|
|
1379
|
+
layer: e.showOnTop ? "top" : "link",
|
|
1380
|
+
noScale: i,
|
|
1381
|
+
hit: {
|
|
1382
|
+
kind: "label",
|
|
1383
|
+
payload: e
|
|
1384
|
+
},
|
|
1385
|
+
children: [{
|
|
1386
|
+
type: "image",
|
|
1387
|
+
x: s,
|
|
1388
|
+
y: c,
|
|
1389
|
+
width: e.Width,
|
|
1390
|
+
height: e.Height,
|
|
1391
|
+
src: `data:image/png;base64,${e.pixMap}`
|
|
1392
|
+
}]
|
|
1393
|
+
};
|
|
1394
|
+
let l = [];
|
|
1395
|
+
if ((e.BgColor?.alpha ?? 0) > 0 && !t.transparentLabels && l.push({
|
|
1396
|
+
type: "rect",
|
|
1397
|
+
x: s,
|
|
1398
|
+
y: c,
|
|
1399
|
+
width: e.Width,
|
|
1400
|
+
height: e.Height,
|
|
1401
|
+
paint: { fill: W(e.BgColor) }
|
|
1402
|
+
}), e.Text) {
|
|
1403
|
+
let t = Math.min(.75, e.Width / Math.max(e.Text.length / 2, 1)), n = Math.max(.1, Math.min(t, Math.max(e.Height * .9, .1)));
|
|
1404
|
+
l.push({
|
|
1405
|
+
type: "text",
|
|
1406
|
+
x: s,
|
|
1407
|
+
y: c,
|
|
1408
|
+
width: e.Width,
|
|
1409
|
+
height: e.Height,
|
|
1410
|
+
text: e.Text,
|
|
1411
|
+
fontSize: n,
|
|
1412
|
+
fill: W(e.FgColor),
|
|
1413
|
+
align: "center",
|
|
1414
|
+
verticalAlign: "middle"
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
return {
|
|
1418
|
+
type: "group",
|
|
1419
|
+
x: a,
|
|
1420
|
+
y: o,
|
|
1421
|
+
layer: e.showOnTop ? "top" : "link",
|
|
1422
|
+
noScale: i,
|
|
1423
|
+
hit: {
|
|
1424
|
+
kind: "label",
|
|
1425
|
+
payload: e
|
|
1426
|
+
},
|
|
1427
|
+
children: l
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
//#endregion
|
|
1431
|
+
//#region src/ScenePipeline.ts
|
|
1432
|
+
function le(e, t) {
|
|
1433
|
+
let n = G(e);
|
|
1434
|
+
return n ? `rgba(${n.r}, ${n.g}, ${n.b}, ${t})` : e;
|
|
1435
|
+
}
|
|
1436
|
+
function G(e) {
|
|
1437
|
+
let t = e.match(/(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);
|
|
1438
|
+
if (t) return {
|
|
1439
|
+
r: +t[1],
|
|
1440
|
+
g: +t[2],
|
|
1441
|
+
b: +t[3]
|
|
1442
|
+
};
|
|
1443
|
+
if (e.startsWith("#") && e.length >= 7) return {
|
|
1444
|
+
r: parseInt(e.slice(1, 3), 16),
|
|
1445
|
+
g: parseInt(e.slice(3, 5), 16),
|
|
1446
|
+
b: parseInt(e.slice(5, 7), 16)
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
function ue(e, t, n) {
|
|
1450
|
+
let r = G(e), i = G(t);
|
|
1451
|
+
return !r || !i ? e : `rgb(${Math.round(r.r * n + i.r * (1 - n))}, ${Math.round(r.g * n + i.g * (1 - n))}, ${Math.round(r.b * n + i.b * (1 - n))})`;
|
|
1452
|
+
}
|
|
1453
|
+
function de(e, t) {
|
|
1454
|
+
let n = t * t, r = [];
|
|
1455
|
+
outer: for (let t of e) {
|
|
1456
|
+
for (let e of r) for (let r of e) {
|
|
1457
|
+
let i = t.tip.x - r.tip.x, a = t.tip.y - r.tip.y;
|
|
1458
|
+
if (i * i + a * a <= n) {
|
|
1459
|
+
e.push(t);
|
|
1460
|
+
continue outer;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
r.push([t]);
|
|
1464
|
+
}
|
|
1465
|
+
return r;
|
|
1466
|
+
}
|
|
1467
|
+
var fe = class {
|
|
1468
|
+
constructor(e, t) {
|
|
1469
|
+
this.linkShapes = [], this.roomShapes = [], this.topLabelShapes = [], this.labelShapeRefs = [], this.specialExitShapeRefs = [], this.stubShapeRefs = [], this.areaExitLabelShapeRefs = [], this.mapReader = e, this.settings = t, this.exitRenderer = new T(e, t);
|
|
1470
|
+
}
|
|
1471
|
+
buildScene(e, t, n, r = s) {
|
|
1472
|
+
this.linkShapes = [], this.roomShapes = [], this.topLabelShapes = [], this.labelShapeRefs = [], this.specialExitShapeRefs = [], this.stubShapeRefs = [], this.areaExitLabelShapeRefs = [], this.renderLabels(t.getLabels(), e.getAreaId());
|
|
1473
|
+
let i = this.renderLinkExits(e.getLinkExits(n), n, r), a = (t.getRooms() ?? []).filter((e) => r.isVisible(e)), o = this.renderRooms(a, n);
|
|
1474
|
+
this.renderAreaName(e, t);
|
|
1475
|
+
let c = [...i.areaExitHitZones, ...o.areaExitHitZones], l = this.renderAreaExitLabels(c, e.getAreaId(), a, i.standaloneExitShapeRefs.map((e) => e.bounds));
|
|
1476
|
+
c.push(...l);
|
|
1477
|
+
let u = [
|
|
1478
|
+
...this.linkShapes,
|
|
1479
|
+
...this.roomShapes,
|
|
1480
|
+
...this.topLabelShapes
|
|
1481
|
+
];
|
|
1482
|
+
return {
|
|
1483
|
+
roomShapeRefs: o.roomShapeRefs,
|
|
1484
|
+
standaloneExitShapeRefs: i.standaloneExitShapeRefs,
|
|
1485
|
+
labelShapeRefs: this.labelShapeRefs,
|
|
1486
|
+
specialExitShapeRefs: this.specialExitShapeRefs,
|
|
1487
|
+
stubShapeRefs: this.stubShapeRefs,
|
|
1488
|
+
areaExitLabelShapeRefs: this.areaExitLabelShapeRefs,
|
|
1489
|
+
areaExitHitZones: c,
|
|
1490
|
+
drawnExits: i.drawnExits,
|
|
1491
|
+
drawnSpecialExits: o.drawnSpecialExits,
|
|
1492
|
+
drawnStubs: o.drawnStubs,
|
|
1493
|
+
hitShapes: u,
|
|
1494
|
+
sceneShapes: {
|
|
1495
|
+
grid: [],
|
|
1496
|
+
link: this.linkShapes,
|
|
1497
|
+
room: this.roomShapes,
|
|
1498
|
+
topLabel: this.topLabelShapes
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
getEffectiveBounds(e, t) {
|
|
1503
|
+
return this.settings.uniformLevelSize ? e.getFullBounds() : t.getBounds();
|
|
1504
|
+
}
|
|
1505
|
+
renderRooms(e, t) {
|
|
1506
|
+
let n = /* @__PURE__ */ new Map(), r = [], i = [], a = [], o = [];
|
|
1507
|
+
e.forEach((e) => {
|
|
1508
|
+
let t = L(e, this.mapReader, this.settings, { flatPipeline: !0 });
|
|
1509
|
+
t.children.push(...B(e, this.mapReader, this.settings));
|
|
1510
|
+
for (let t of A(e, this.settings)) {
|
|
1511
|
+
let n = H(t, e.id);
|
|
1512
|
+
this.linkShapes.push(n);
|
|
1513
|
+
let r = t.line.points, a = Infinity, o = Infinity, s = -Infinity, c = -Infinity;
|
|
1514
|
+
for (let e = 0; e < r.length; e += 2) r[e] < a && (a = r[e]), r[e] > s && (s = r[e]), r[e + 1] < o && (o = r[e + 1]), r[e + 1] > c && (c = r[e + 1]);
|
|
1515
|
+
let l = {
|
|
1516
|
+
x: a,
|
|
1517
|
+
y: o,
|
|
1518
|
+
width: s - a,
|
|
1519
|
+
height: c - o
|
|
1520
|
+
};
|
|
1521
|
+
i.push({
|
|
1522
|
+
roomId: e.id,
|
|
1523
|
+
exitName: t.dir,
|
|
1524
|
+
points: r,
|
|
1525
|
+
stroke: t.line.stroke,
|
|
1526
|
+
strokeWidth: t.line.strokeWidth,
|
|
1527
|
+
dash: t.line.dash,
|
|
1528
|
+
hasArrow: !!t.arrow,
|
|
1529
|
+
arrowTip: t.arrow ? {
|
|
1530
|
+
x: t.arrow.tipX,
|
|
1531
|
+
y: t.arrow.tipY
|
|
1532
|
+
} : void 0,
|
|
1533
|
+
bounds: l
|
|
1534
|
+
}), this.specialExitShapeRefs.push({
|
|
1535
|
+
shape: n,
|
|
1536
|
+
bounds: l
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
this.exitRenderer.getSpecialExitAreaTargets(e).forEach((e) => {
|
|
1540
|
+
r.push({
|
|
1541
|
+
bounds: e.bounds,
|
|
1542
|
+
targetRoomId: e.targetRoomId,
|
|
1543
|
+
from: e.from,
|
|
1544
|
+
tip: e.tip,
|
|
1545
|
+
arrowColor: e.arrowColor
|
|
1546
|
+
});
|
|
1547
|
+
}), this.exitRenderer.getInnerExitAreaTargets(e).forEach((e) => {
|
|
1548
|
+
r.push({
|
|
1549
|
+
bounds: e.bounds,
|
|
1550
|
+
targetRoomId: e.targetRoomId,
|
|
1551
|
+
from: e.from,
|
|
1552
|
+
tip: e.tip,
|
|
1553
|
+
arrowColor: e.arrowColor
|
|
1554
|
+
});
|
|
1555
|
+
});
|
|
1556
|
+
for (let t of O(e, this.settings)) {
|
|
1557
|
+
let e = U(t);
|
|
1558
|
+
this.linkShapes.push(e), a.push({
|
|
1559
|
+
roomId: t.roomId,
|
|
1560
|
+
direction: t.direction,
|
|
1561
|
+
x1: t.x1,
|
|
1562
|
+
y1: t.y1,
|
|
1563
|
+
x2: t.x2,
|
|
1564
|
+
y2: t.y2,
|
|
1565
|
+
stroke: t.stroke,
|
|
1566
|
+
strokeWidth: t.strokeWidth
|
|
1567
|
+
}), this.stubShapeRefs.push({
|
|
1568
|
+
shape: e,
|
|
1569
|
+
bounds: {
|
|
1570
|
+
x: Math.min(t.x1, t.x2),
|
|
1571
|
+
y: Math.min(t.y1, t.y2),
|
|
1572
|
+
width: Math.abs(t.x2 - t.x1),
|
|
1573
|
+
height: Math.abs(t.y2 - t.y1)
|
|
1574
|
+
}
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
o.push([e, t]), n.set(e.id, {
|
|
1578
|
+
room: e,
|
|
1579
|
+
shape: t
|
|
1580
|
+
});
|
|
1581
|
+
});
|
|
1582
|
+
for (let [, e] of o) this.roomShapes.push(e);
|
|
1583
|
+
return {
|
|
1584
|
+
roomShapeRefs: n,
|
|
1585
|
+
areaExitHitZones: r,
|
|
1586
|
+
drawnSpecialExits: i,
|
|
1587
|
+
drawnStubs: a
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
renderLinkExits(e, t, n) {
|
|
1591
|
+
let r = [], i = [], a = [];
|
|
1592
|
+
return e.forEach((e) => {
|
|
1593
|
+
let o = this.mapReader.getRoom(e.a), s = this.mapReader.getRoom(e.b);
|
|
1594
|
+
if (!o || !s) return;
|
|
1595
|
+
let l = n.getExitTreatment ? n.getExitTreatment(e, o, s) : c(n, e, o, s);
|
|
1596
|
+
if (l === "hidden") return;
|
|
1597
|
+
if (l === "stub") {
|
|
1598
|
+
let t = this.buildLensStub(e, o, s, n);
|
|
1599
|
+
t && this.emitLensStub(t);
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1602
|
+
let u = this.exitRenderer.renderData(e, t);
|
|
1603
|
+
if (!u) return;
|
|
1604
|
+
let d = V(u, {
|
|
1605
|
+
kind: "exit",
|
|
1606
|
+
id: `${e.a}:${e.b}:${e.aDir ?? ""}:${e.bDir ?? ""}`,
|
|
1607
|
+
payload: {
|
|
1608
|
+
a: e.a,
|
|
1609
|
+
b: e.b,
|
|
1610
|
+
aDir: e.aDir,
|
|
1611
|
+
bDir: e.bDir,
|
|
1612
|
+
kind: e.kind ?? "exit"
|
|
1613
|
+
}
|
|
1614
|
+
});
|
|
1615
|
+
this.linkShapes.push(d), r.push({
|
|
1616
|
+
shape: d,
|
|
1617
|
+
bounds: u.bounds,
|
|
1618
|
+
targetRoomId: u.targetRoomId
|
|
1619
|
+
}), a.push({
|
|
1620
|
+
a: e.a,
|
|
1621
|
+
b: e.b,
|
|
1622
|
+
aDir: e.aDir,
|
|
1623
|
+
bDir: e.bDir,
|
|
1624
|
+
kind: e.kind ?? "exit",
|
|
1625
|
+
zIndex: e.zIndex,
|
|
1626
|
+
data: u
|
|
1627
|
+
}), u.targetRoomId !== void 0 && i.push({
|
|
1628
|
+
bounds: u.bounds,
|
|
1629
|
+
targetRoomId: u.targetRoomId,
|
|
1630
|
+
from: u.from,
|
|
1631
|
+
tip: u.tip,
|
|
1632
|
+
arrowColor: u.arrowColor
|
|
1633
|
+
});
|
|
1634
|
+
}), {
|
|
1635
|
+
standaloneExitShapeRefs: r,
|
|
1636
|
+
areaExitHitZones: i,
|
|
1637
|
+
drawnExits: a
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
buildLensStub(e, t, n, r) {
|
|
1641
|
+
let i = r.isVisible(t);
|
|
1642
|
+
if (i === r.isVisible(n)) return;
|
|
1643
|
+
let a = i ? t : n, o = i ? e.aDir : e.bDir;
|
|
1644
|
+
if (!o || !p.includes(o) || a.customLines[h[o]]) return;
|
|
1645
|
+
let s = this.settings.roomSize, c = this.getRoomEdgePoint(a.x, a.y, o, s / 2), l = b(a.x, a.y, o, s / 2 + .5);
|
|
1646
|
+
return {
|
|
1647
|
+
roomId: a.id,
|
|
1648
|
+
direction: o,
|
|
1649
|
+
x1: c.x,
|
|
1650
|
+
y1: c.y,
|
|
1651
|
+
x2: l.x,
|
|
1652
|
+
y2: l.y,
|
|
1653
|
+
stroke: this.settings.lineColor,
|
|
1654
|
+
strokeWidth: this.settings.lineWidth
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
emitLensStub(e) {
|
|
1658
|
+
let t = U(e);
|
|
1659
|
+
this.linkShapes.push(t), this.stubShapeRefs.push({
|
|
1660
|
+
shape: t,
|
|
1661
|
+
bounds: {
|
|
1662
|
+
x: Math.min(e.x1, e.x2),
|
|
1663
|
+
y: Math.min(e.y1, e.y2),
|
|
1664
|
+
width: Math.abs(e.x2 - e.x1),
|
|
1665
|
+
height: Math.abs(e.y2 - e.y1)
|
|
1666
|
+
}
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
getRoomEdgePoint(e, t, n, r) {
|
|
1670
|
+
return this.settings.roomShape === "circle" ? S(e, t, n, r) : this.settings.roomShape === "roundedRectangle" ? x(e, t, n, r, this.settings.roomSize * .2) : b(e, t, n, r);
|
|
1671
|
+
}
|
|
1672
|
+
buildExitShape(e) {
|
|
1673
|
+
return V(e);
|
|
1674
|
+
}
|
|
1675
|
+
renderLabels(e, t) {
|
|
1676
|
+
for (let n of e) {
|
|
1677
|
+
let e = ce(n, this.settings);
|
|
1678
|
+
e && (e.hit = {
|
|
1679
|
+
kind: "label",
|
|
1680
|
+
id: n.labelId,
|
|
1681
|
+
payload: {
|
|
1682
|
+
label: n,
|
|
1683
|
+
areaId: t
|
|
1684
|
+
}
|
|
1685
|
+
}, n.showOnTop ? this.topLabelShapes.push(e) : this.linkShapes.push(e), n.noScaling || this.labelShapeRefs.push({
|
|
1686
|
+
shape: e,
|
|
1687
|
+
bounds: {
|
|
1688
|
+
x: n.X,
|
|
1689
|
+
y: -n.Y,
|
|
1690
|
+
width: n.Width,
|
|
1691
|
+
height: n.Height
|
|
1692
|
+
}
|
|
1693
|
+
}));
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
renderAreaExitLabels(e, n, r, i) {
|
|
1697
|
+
let a = [];
|
|
1698
|
+
if (!this.settings.areaExitLabels || e.length === 0) return a;
|
|
1699
|
+
let o = /* @__PURE__ */ new Map();
|
|
1700
|
+
for (let t of e) {
|
|
1701
|
+
if (!t.tip || !t.from) continue;
|
|
1702
|
+
let e = this.mapReader.getRoom(t.targetRoomId);
|
|
1703
|
+
if (!e || e.area === n) continue;
|
|
1704
|
+
let r = t.tip.x - t.from.x, i = t.tip.y - t.from.y, a = Math.hypot(r, i) || 1, s = {
|
|
1705
|
+
tip: t.tip,
|
|
1706
|
+
dir: {
|
|
1707
|
+
x: r / a,
|
|
1708
|
+
y: i / a
|
|
1709
|
+
},
|
|
1710
|
+
color: t.arrowColor ?? "white",
|
|
1711
|
+
bounds: t.bounds,
|
|
1712
|
+
targetRoomId: t.targetRoomId
|
|
1713
|
+
}, c = o.get(e.area);
|
|
1714
|
+
c ? c.push(s) : o.set(e.area, [s]);
|
|
1715
|
+
}
|
|
1716
|
+
let s = this.settings.areaExitLabelFontSize, c = s * .6, l = s * .333, u = s * .55, d = s * 1.1, f = s * .6, p = .35, m = s * .1, h = this.settings.roomSize, g = r.map((e) => ({
|
|
1717
|
+
x: e.x - h / 2,
|
|
1718
|
+
y: e.y - h / 2,
|
|
1719
|
+
width: h,
|
|
1720
|
+
height: h
|
|
1721
|
+
})), _ = e.map((e) => e.bounds), v = (e, t, n) => {
|
|
1722
|
+
let r = Math.max(0, Math.max(e.x, t.x) - Math.min(e.x + e.w, t.x + t.w)), i = Math.max(0, Math.max(e.y, t.y) - Math.min(e.y + e.h, t.y + t.h));
|
|
1723
|
+
return Math.hypot(r, i) <= n;
|
|
1724
|
+
}, y = (e, t, n, r, i) => {
|
|
1725
|
+
for (let a of i) if (e < a.x + a.width && e + n > a.x && t < a.y + a.height && t + r > a.y) return !0;
|
|
1726
|
+
return !1;
|
|
1727
|
+
}, b = [
|
|
1728
|
+
[0, 1],
|
|
1729
|
+
[0, -1],
|
|
1730
|
+
[1, 0],
|
|
1731
|
+
[-1, 0],
|
|
1732
|
+
[.707, .707],
|
|
1733
|
+
[-.707, .707],
|
|
1734
|
+
[.707, -.707],
|
|
1735
|
+
[-.707, -.707]
|
|
1736
|
+
], x = (e, t, n) => {
|
|
1737
|
+
let r = t.length * u + c * 2, a = d + l * 2, o = 0, s = 0, f = 0, p = 0, m = Infinity, h = -Infinity, v = Infinity, x = -Infinity, S = /* @__PURE__ */ new Map();
|
|
1738
|
+
for (let t of e) o += t.tip.x, s += t.tip.y, f += t.dir.x, p += t.dir.y, t.tip.x < m && (m = t.tip.x), t.tip.x > h && (h = t.tip.x), t.tip.y < v && (v = t.tip.y), t.tip.y > x && (x = t.tip.y), S.set(t.color, (S.get(t.color) ?? 0) + 1);
|
|
1739
|
+
let C = e.length, w = Math.hypot(f, p), T = w > 0 ? f / w : 0, E = w > 0 ? p / w : 0, D = 0;
|
|
1740
|
+
for (let t = 0; t < e.length; t++) for (let n = t + 1; n < e.length; n++) {
|
|
1741
|
+
let r = e[t].tip.x - e[n].tip.x, i = e[t].tip.y - e[n].tip.y, a = Math.hypot(r, i);
|
|
1742
|
+
a > D && (D = a);
|
|
1743
|
+
}
|
|
1744
|
+
let O = D > 3, k = w / C >= .4, A = n?.x ?? (O ? (m + h) / 2 : o / C), j = n?.y ?? (O ? (v + x) / 2 : s / C), M = "white", N = 0;
|
|
1745
|
+
for (let [e, t] of S) t > N && (M = e, N = t);
|
|
1746
|
+
let P = g.concat(_).concat(i), F = (e, t, n = 0) => .5 + n + Math.abs(e) * r / 2 + Math.abs(t) * a / 2, I = [];
|
|
1747
|
+
if (k) {
|
|
1748
|
+
let e = F(T, E);
|
|
1749
|
+
I.push({
|
|
1750
|
+
x: A + T * e,
|
|
1751
|
+
y: j + E * e
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
I.push({
|
|
1755
|
+
x: A,
|
|
1756
|
+
y: j
|
|
1757
|
+
});
|
|
1758
|
+
for (let e of [
|
|
1759
|
+
0,
|
|
1760
|
+
.6,
|
|
1761
|
+
1.4
|
|
1762
|
+
]) for (let [t, n] of b) {
|
|
1763
|
+
let r = F(t, n, e);
|
|
1764
|
+
I.push({
|
|
1765
|
+
x: A + t * r,
|
|
1766
|
+
y: j + n * r
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
for (let t of I) {
|
|
1770
|
+
let n = t.x - r / 2, i = t.y - a / 2;
|
|
1771
|
+
if (!y(n, i, r, a, P)) return {
|
|
1772
|
+
cluster: e,
|
|
1773
|
+
boxX: n,
|
|
1774
|
+
boxY: i,
|
|
1775
|
+
boxW: r,
|
|
1776
|
+
boxH: a,
|
|
1777
|
+
color: M
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
for (let [e, n] of o) {
|
|
1782
|
+
let r = this.mapReader.getArea(e)?.getAreaName() || `Area ${e}`, i = de(n, 10).map((e) => x(e, r)).filter((e) => e !== void 0), o = !0;
|
|
1783
|
+
for (; o && i.length > 1;) {
|
|
1784
|
+
o = !1;
|
|
1785
|
+
outer: for (let e = 0; e < i.length; e++) for (let t = e + 1; t < i.length; t++) {
|
|
1786
|
+
let n = {
|
|
1787
|
+
x: i[e].boxX,
|
|
1788
|
+
y: i[e].boxY,
|
|
1789
|
+
w: i[e].boxW,
|
|
1790
|
+
h: i[e].boxH
|
|
1791
|
+
}, a = {
|
|
1792
|
+
x: i[t].boxX,
|
|
1793
|
+
y: i[t].boxY,
|
|
1794
|
+
w: i[t].boxW,
|
|
1795
|
+
h: i[t].boxH
|
|
1796
|
+
};
|
|
1797
|
+
if (v(n, a, 2)) {
|
|
1798
|
+
let s = [...i[e].cluster, ...i[t].cluster], c = x(s, r, {
|
|
1799
|
+
x: (n.x + n.w / 2 + a.x + a.w / 2) / 2,
|
|
1800
|
+
y: (n.y + n.h / 2 + a.y + a.h / 2) / 2
|
|
1801
|
+
}) ?? x(s, r);
|
|
1802
|
+
c ? (i[e] = c, i.splice(t, 1)) : (i.splice(t, 1), i.splice(e, 1)), o = !0;
|
|
1803
|
+
break outer;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
for (let e of i) {
|
|
1808
|
+
let n = le(e.color, p), i = t(ue(e.color, this.settings.backgroundColor, p)) > .55 ? "#000" : "#fff", o = {
|
|
1809
|
+
type: "group",
|
|
1810
|
+
x: 0,
|
|
1811
|
+
y: 0,
|
|
1812
|
+
layer: "room",
|
|
1813
|
+
hit: {
|
|
1814
|
+
kind: "areaExit",
|
|
1815
|
+
id: e.cluster[0].targetRoomId,
|
|
1816
|
+
payload: { targetRoomId: e.cluster[0].targetRoomId }
|
|
1817
|
+
},
|
|
1818
|
+
children: [{
|
|
1819
|
+
type: "rect",
|
|
1820
|
+
x: e.boxX,
|
|
1821
|
+
y: e.boxY,
|
|
1822
|
+
width: e.boxW,
|
|
1823
|
+
height: e.boxH,
|
|
1824
|
+
cornerRadius: f,
|
|
1825
|
+
paint: {
|
|
1826
|
+
fill: n,
|
|
1827
|
+
stroke: e.color,
|
|
1828
|
+
strokeWidth: m
|
|
1829
|
+
}
|
|
1830
|
+
}, {
|
|
1831
|
+
type: "text",
|
|
1832
|
+
x: e.boxX + c,
|
|
1833
|
+
y: e.boxY + l,
|
|
1834
|
+
width: e.boxW - c * 2,
|
|
1835
|
+
height: e.boxH - l * 2,
|
|
1836
|
+
text: r,
|
|
1837
|
+
fontSize: s,
|
|
1838
|
+
fontFamily: this.settings.fontFamily,
|
|
1839
|
+
fill: i,
|
|
1840
|
+
align: "center",
|
|
1841
|
+
verticalAlign: "middle"
|
|
1842
|
+
}]
|
|
1843
|
+
}, u = {
|
|
1844
|
+
x: e.boxX,
|
|
1845
|
+
y: e.boxY,
|
|
1846
|
+
width: e.boxW,
|
|
1847
|
+
height: e.boxH
|
|
1848
|
+
};
|
|
1849
|
+
this.roomShapes.push(o), this.areaExitLabelShapeRefs.push({
|
|
1850
|
+
shape: o,
|
|
1851
|
+
bounds: u
|
|
1852
|
+
}), a.push({
|
|
1853
|
+
bounds: u,
|
|
1854
|
+
targetRoomId: e.cluster[0].targetRoomId
|
|
1855
|
+
});
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
return a;
|
|
1859
|
+
}
|
|
1860
|
+
renderAreaName(e, t) {
|
|
1861
|
+
if (!this.settings.areaName) return;
|
|
1862
|
+
let n = e.getAreaName();
|
|
1863
|
+
if (!n) return;
|
|
1864
|
+
let r = this.getEffectiveBounds(e, t), i = {
|
|
1865
|
+
type: "group",
|
|
1866
|
+
x: 0,
|
|
1867
|
+
y: 0,
|
|
1868
|
+
layer: "room",
|
|
1869
|
+
children: [{
|
|
1870
|
+
type: "text",
|
|
1871
|
+
x: r.minX - 3.5,
|
|
1872
|
+
y: r.minY - 4.5,
|
|
1873
|
+
text: n,
|
|
1874
|
+
fontSize: 2.5,
|
|
1875
|
+
fontFamily: this.settings.fontFamily,
|
|
1876
|
+
fill: this.settings.lineColor
|
|
1877
|
+
}]
|
|
1878
|
+
};
|
|
1879
|
+
this.roomShapes.push(i);
|
|
1880
|
+
}
|
|
1881
|
+
}, pe = class {
|
|
1882
|
+
setCursor(e) {
|
|
1883
|
+
this.container.dataset.editorCursor || (this.container.style.cursor = e);
|
|
1884
|
+
}
|
|
1885
|
+
constructor(e, t, n, r, i) {
|
|
1886
|
+
this.cleanupFns = [], this.destroyed = !1, this.container = e, this.camera = t, this.state = n, this.hitTest = r, this.events = i, this.initViewportEvents(), this.initMapEvents();
|
|
1887
|
+
}
|
|
1888
|
+
destroy() {
|
|
1889
|
+
if (!this.destroyed) {
|
|
1890
|
+
this.destroyed = !0;
|
|
1891
|
+
for (let e of this.cleanupFns) e();
|
|
1892
|
+
this.cleanupFns.length = 0;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
listen(e, t, n, r) {
|
|
1896
|
+
e.addEventListener(t, n, r), this.cleanupFns.push(() => e.removeEventListener(t, n, r));
|
|
1897
|
+
}
|
|
1898
|
+
initViewportEvents() {
|
|
1899
|
+
let e = this.container, t = this.camera, n = 1.1, r = () => {
|
|
1900
|
+
t.batch(() => {
|
|
1901
|
+
if (t.setSize(e.clientWidth, e.clientHeight), t.centerOnResize && this.state.positionRoomId) {
|
|
1902
|
+
let e = this.state.mapReader.getRoom(this.state.positionRoomId);
|
|
1903
|
+
e && t.panToMapPoint(e.x, e.y);
|
|
1904
|
+
}
|
|
1905
|
+
});
|
|
1906
|
+
};
|
|
1907
|
+
typeof window < "u" && this.listen(window, "resize", r), this.listen(e, "resize", r);
|
|
1908
|
+
let i = !1, a;
|
|
1909
|
+
this.listen(e, "pointerdown", (n) => {
|
|
1910
|
+
if (n.button !== 0 || n.pointerType === "touch") return;
|
|
1911
|
+
i = !0, a = n.pointerId, e.setPointerCapture(n.pointerId);
|
|
1912
|
+
let r = e.getBoundingClientRect();
|
|
1913
|
+
t.startDrag(n.clientX - r.left, n.clientY - r.top);
|
|
1914
|
+
}), this.listen(e, "pointermove", (n) => {
|
|
1915
|
+
if (!i || n.pointerId !== a) return;
|
|
1916
|
+
let r = e.getBoundingClientRect();
|
|
1917
|
+
t.updateDrag(n.clientX - r.left, n.clientY - r.top), this.events.emit("pan", t.getViewportBounds());
|
|
1918
|
+
}), this.listen(e, "pointerup", (e) => {
|
|
1919
|
+
e.pointerId === a && (i = !1, a = void 0, t.endDrag(), this.events.emit("pan", t.getViewportBounds()));
|
|
1920
|
+
}), this.listen(e, "pointercancel", (e) => {
|
|
1921
|
+
e.pointerId === a && (i = !1, a = void 0, t.endDrag());
|
|
1922
|
+
});
|
|
1923
|
+
let o;
|
|
1924
|
+
this.listen(e, "touchstart", (n) => {
|
|
1925
|
+
if (n.touches.length === 1) {
|
|
1926
|
+
let r = n.touches[0];
|
|
1927
|
+
o = r.identifier;
|
|
1928
|
+
let i = e.getBoundingClientRect();
|
|
1929
|
+
t.startDrag(r.clientX - i.left, r.clientY - i.top);
|
|
1930
|
+
} else t.isDragging() && t.endDrag(), o = void 0;
|
|
1931
|
+
}, { passive: !0 }), this.listen(e, "touchmove", (n) => {
|
|
1932
|
+
let r = n.touches;
|
|
1933
|
+
if (r.length >= 2) {
|
|
1934
|
+
n.preventDefault(), t.isDragging() && t.endDrag(), o = void 0;
|
|
1935
|
+
let i = e.getBoundingClientRect(), a = {
|
|
1936
|
+
x: r[0].clientX - i.left,
|
|
1937
|
+
y: r[0].clientY - i.top
|
|
1938
|
+
}, s = {
|
|
1939
|
+
x: r[1].clientX - i.left,
|
|
1940
|
+
y: r[1].clientY - i.top
|
|
1941
|
+
};
|
|
1942
|
+
this.handlePinch(a, s);
|
|
1943
|
+
return;
|
|
1944
|
+
}
|
|
1945
|
+
if (r.length === 1 && o === r[0].identifier) {
|
|
1946
|
+
let n = r[0], i = e.getBoundingClientRect();
|
|
1947
|
+
t.updateDrag(n.clientX - i.left, n.clientY - i.top), this.events.emit("pan", t.getViewportBounds());
|
|
1948
|
+
}
|
|
1949
|
+
}), this.listen(e, "touchend", (n) => {
|
|
1950
|
+
if (this.lastPinchDistance = void 0, n.touches.length === 0) t.isDragging() && (t.endDrag(), this.events.emit("pan", t.getViewportBounds())), o = void 0;
|
|
1951
|
+
else if (n.touches.length === 1) {
|
|
1952
|
+
let r = n.touches[0];
|
|
1953
|
+
o = r.identifier;
|
|
1954
|
+
let i = e.getBoundingClientRect();
|
|
1955
|
+
t.startDrag(r.clientX - i.left, r.clientY - i.top);
|
|
1956
|
+
}
|
|
1957
|
+
}, { passive: !0 }), this.listen(e, "touchcancel", () => {
|
|
1958
|
+
this.lastPinchDistance = void 0, t.isDragging() && t.endDrag(), o = void 0;
|
|
1959
|
+
}, { passive: !0 }), this.listen(e, "wheel", (r) => {
|
|
1960
|
+
r.preventDefault();
|
|
1961
|
+
let i = e.getBoundingClientRect(), a = r.clientX - i.left, o = r.clientY - i.top, s = r.deltaY > 0 ? -1 : 1;
|
|
1962
|
+
r.ctrlKey && (s = -s);
|
|
1963
|
+
let c = s > 0 ? t.zoom * n : t.zoom / n;
|
|
1964
|
+
t.zoomToPoint(c, a, o) && (this.events.emit("zoom", { zoom: t.zoom }), this.events.emit("pan", t.getViewportBounds()));
|
|
1965
|
+
}, { passive: !1 });
|
|
1966
|
+
}
|
|
1967
|
+
handlePinch(e, t) {
|
|
1968
|
+
let n = Math.hypot(e.x - t.x, e.y - t.y);
|
|
1969
|
+
if (this.lastPinchDistance === void 0 || this.lastPinchDistance === 0 || n === 0) {
|
|
1970
|
+
this.lastPinchDistance = n;
|
|
1971
|
+
return;
|
|
1972
|
+
}
|
|
1973
|
+
let r = (e.x + t.x) / 2, i = (e.y + t.y) / 2, a = this.camera.zoom * (n / this.lastPinchDistance);
|
|
1974
|
+
this.camera.zoomToPoint(a, r, i) && (this.events.emit("zoom", { zoom: this.camera.zoom }), this.events.emit("pan", this.camera.getViewportBounds())), this.lastPinchDistance = n;
|
|
1975
|
+
}
|
|
1976
|
+
initMapEvents() {
|
|
1977
|
+
let e = this.container, t = null;
|
|
1978
|
+
this.listen(e, "mousemove", (e) => {
|
|
1979
|
+
let n = this.pickAtClientPoint(e.clientX, e.clientY)?.kind ?? null;
|
|
1980
|
+
n !== t && (t = n, this.setCursor(n === "room" || n === "areaExit" ? "pointer" : "auto"));
|
|
1981
|
+
}), this.listen(e, "mouseleave", () => {
|
|
1982
|
+
t = null, this.setCursor("auto");
|
|
1983
|
+
});
|
|
1984
|
+
let n = null;
|
|
1985
|
+
this.listen(e, "mousedown", (e) => {
|
|
1986
|
+
e.button === 0 && (n = {
|
|
1987
|
+
x: e.clientX,
|
|
1988
|
+
y: e.clientY
|
|
1989
|
+
});
|
|
1990
|
+
}), this.listen(e, "mouseup", (e) => {
|
|
1991
|
+
if (e.button !== 0 || !n) return;
|
|
1992
|
+
let t = e.clientX - n.x, r = e.clientY - n.y;
|
|
1993
|
+
if (n = null, t * t + r * r > 25) return;
|
|
1994
|
+
let i = this.pickAtClientPoint(e.clientX, e.clientY);
|
|
1995
|
+
if (i?.kind === "room") {
|
|
1996
|
+
this.emitRoomClickEvent(i.id, e.clientX, e.clientY);
|
|
1997
|
+
return;
|
|
1998
|
+
}
|
|
1999
|
+
if (i?.kind === "areaExit") {
|
|
2000
|
+
let t = i.payload?.targetRoomId ?? i.id;
|
|
2001
|
+
this.emitAreaExitClickEvent(t, e.clientX, e.clientY);
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
this.emitMapClickEvent();
|
|
2005
|
+
}), this.listen(e, "contextmenu", (e) => {
|
|
2006
|
+
let t = this.pickAtClientPoint(e.clientX, e.clientY);
|
|
2007
|
+
t?.kind === "room" && (e.preventDefault(), this.emitRoomContextEvent(t.id, e.clientX, e.clientY));
|
|
2008
|
+
});
|
|
2009
|
+
let r, i, a = () => {
|
|
2010
|
+
r !== void 0 && (window.clearTimeout(r), r = void 0), i = void 0;
|
|
2011
|
+
};
|
|
2012
|
+
this.listen(e, "touchstart", (e) => {
|
|
2013
|
+
if (a(), e.touches.length > 1) return;
|
|
2014
|
+
let t = e.touches[0];
|
|
2015
|
+
t && this.pickAtClientPoint(t.clientX, t.clientY)?.kind === "room" && (i = {
|
|
2016
|
+
clientX: t.clientX,
|
|
2017
|
+
clientY: t.clientY
|
|
2018
|
+
}, r = window.setTimeout(() => {
|
|
2019
|
+
if (i) {
|
|
2020
|
+
let e = this.pickAtClientPoint(i.clientX, i.clientY);
|
|
2021
|
+
e?.kind === "room" && this.emitRoomContextEvent(e.id, i.clientX, i.clientY);
|
|
2022
|
+
}
|
|
2023
|
+
a();
|
|
2024
|
+
}, 500));
|
|
2025
|
+
}, { passive: !0 }), this.listen(e, "touchend", () => a(), { passive: !0 }), this.listen(e, "touchcancel", () => a(), { passive: !0 }), this.listen(e, "touchmove", (e) => {
|
|
2026
|
+
if (!i) return;
|
|
2027
|
+
let t = e.touches[0];
|
|
2028
|
+
if (!t) {
|
|
2029
|
+
a();
|
|
2030
|
+
return;
|
|
2031
|
+
}
|
|
2032
|
+
let n = t.clientX - i.clientX, r = t.clientY - i.clientY;
|
|
2033
|
+
n * n + r * r > 100 && a();
|
|
2034
|
+
}, { passive: !0 });
|
|
2035
|
+
}
|
|
2036
|
+
pickAtClientPoint(e, t) {
|
|
2037
|
+
let n = this.hitTest.clientToMapPoint(e, t);
|
|
2038
|
+
return n ? this.hitTest.pickAtPoint(n.x, n.y) : null;
|
|
2039
|
+
}
|
|
2040
|
+
emitRoomClickEvent(e, t, n) {
|
|
2041
|
+
let r = this.container.getBoundingClientRect();
|
|
2042
|
+
this.events.emit("roomclick", {
|
|
2043
|
+
roomId: e,
|
|
2044
|
+
position: {
|
|
2045
|
+
x: t - r.left,
|
|
2046
|
+
y: n - r.top
|
|
2047
|
+
}
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
emitRoomContextEvent(e, t, n) {
|
|
2051
|
+
let r = this.container.getBoundingClientRect();
|
|
2052
|
+
this.events.emit("roomcontextmenu", {
|
|
2053
|
+
roomId: e,
|
|
2054
|
+
position: {
|
|
2055
|
+
x: t - r.left,
|
|
2056
|
+
y: n - r.top
|
|
2057
|
+
}
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
emitAreaExitClickEvent(e, t, n) {
|
|
2061
|
+
let r = this.container.getBoundingClientRect();
|
|
2062
|
+
this.events.emit("areaexitclick", {
|
|
2063
|
+
targetRoomId: e,
|
|
2064
|
+
position: {
|
|
2065
|
+
x: t - r.left,
|
|
2066
|
+
y: n - r.top
|
|
2067
|
+
}
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
emitMapClickEvent() {
|
|
2071
|
+
this.events.emit("mapclick", void 0);
|
|
2072
|
+
}
|
|
2073
|
+
}, K = [
|
|
2074
|
+
"up",
|
|
2075
|
+
"down",
|
|
2076
|
+
"in",
|
|
2077
|
+
"out"
|
|
2078
|
+
];
|
|
2079
|
+
function q(e, t, n, r, i) {
|
|
2080
|
+
return e.roomShape === "circle" ? S(t, n, r, i) : e.roomShape === "roundedRectangle" ? x(t, n, r, i, e.roomSize * .2) : b(t, n, r, i);
|
|
2081
|
+
}
|
|
2082
|
+
function me(e, t, n) {
|
|
2083
|
+
for (let [e, r] of Object.entries(t.exits)) if (r === n.id) {
|
|
2084
|
+
let r = e;
|
|
2085
|
+
if (K.includes(r)) {
|
|
2086
|
+
let e = h[r];
|
|
2087
|
+
return {
|
|
2088
|
+
type: "inner",
|
|
2089
|
+
fromDir: r,
|
|
2090
|
+
customLineKey: t.customLines[e] ? e : t.customLines[r] ? r : void 0,
|
|
2091
|
+
fromRoom: t,
|
|
2092
|
+
toRoom: n
|
|
2093
|
+
};
|
|
2094
|
+
}
|
|
2095
|
+
let i = h[r];
|
|
2096
|
+
return t.customLines[i] ? {
|
|
2097
|
+
type: "special",
|
|
2098
|
+
fromDir: r,
|
|
2099
|
+
customLineKey: i,
|
|
2100
|
+
fromRoom: t,
|
|
2101
|
+
toRoom: n
|
|
2102
|
+
} : t.customLines[r] ? {
|
|
2103
|
+
type: "special",
|
|
2104
|
+
fromDir: r,
|
|
2105
|
+
customLineKey: r,
|
|
2106
|
+
fromRoom: t,
|
|
2107
|
+
toRoom: n
|
|
2108
|
+
} : {
|
|
2109
|
+
type: "regular",
|
|
2110
|
+
fromDir: r,
|
|
2111
|
+
toDir: he(n, t.id),
|
|
2112
|
+
fromRoom: t,
|
|
2113
|
+
toRoom: n
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
for (let [e, r] of Object.entries(t.specialExits)) if (r === n.id) return t.customLines[e] ? {
|
|
2117
|
+
type: "special",
|
|
2118
|
+
customLineKey: e,
|
|
2119
|
+
fromRoom: t,
|
|
2120
|
+
toRoom: n
|
|
2121
|
+
} : {
|
|
2122
|
+
type: "inner",
|
|
2123
|
+
fromRoom: t,
|
|
2124
|
+
toRoom: n
|
|
2125
|
+
};
|
|
2126
|
+
for (let [e, r] of Object.entries(n.exits)) if (r === t.id) {
|
|
2127
|
+
let r = e;
|
|
2128
|
+
if (K.includes(r)) {
|
|
2129
|
+
let e = h[r];
|
|
2130
|
+
return {
|
|
2131
|
+
type: "inner",
|
|
2132
|
+
toDir: r,
|
|
2133
|
+
customLineKey: n.customLines[e] ? e : n.customLines[r] ? r : void 0,
|
|
2134
|
+
fromRoom: t,
|
|
2135
|
+
toRoom: n
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
let i = h[r];
|
|
2139
|
+
return n.customLines[i] ? {
|
|
2140
|
+
type: "special",
|
|
2141
|
+
toDir: r,
|
|
2142
|
+
customLineKey: i,
|
|
2143
|
+
fromRoom: t,
|
|
2144
|
+
toRoom: n
|
|
2145
|
+
} : n.customLines[r] ? {
|
|
2146
|
+
type: "special",
|
|
2147
|
+
toDir: r,
|
|
2148
|
+
customLineKey: r,
|
|
2149
|
+
fromRoom: t,
|
|
2150
|
+
toRoom: n
|
|
2151
|
+
} : {
|
|
2152
|
+
type: "regular",
|
|
2153
|
+
toDir: r,
|
|
2154
|
+
fromRoom: t,
|
|
2155
|
+
toRoom: n
|
|
2156
|
+
};
|
|
2157
|
+
}
|
|
2158
|
+
for (let [e, r] of Object.entries(n.specialExits)) if (r === t.id) return n.customLines[e] ? {
|
|
2159
|
+
type: "special",
|
|
2160
|
+
customLineKey: e,
|
|
2161
|
+
fromRoom: t,
|
|
2162
|
+
toRoom: n
|
|
2163
|
+
} : {
|
|
2164
|
+
type: "inner",
|
|
2165
|
+
fromRoom: t,
|
|
2166
|
+
toRoom: n
|
|
2167
|
+
};
|
|
2168
|
+
return {
|
|
2169
|
+
type: "none",
|
|
2170
|
+
fromRoom: t,
|
|
2171
|
+
toRoom: n
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
function he(e, t) {
|
|
2175
|
+
for (let [n, r] of Object.entries(e.exits)) if (r === t) return n;
|
|
2176
|
+
}
|
|
2177
|
+
function J(e, t, n) {
|
|
2178
|
+
return e ? e.area === t && e.z === n : !1;
|
|
2179
|
+
}
|
|
2180
|
+
function ge(e, t) {
|
|
2181
|
+
for (let [n, r] of Object.entries(e.exits)) if (r === t.id) return { direction: n };
|
|
2182
|
+
for (let [n, r] of Object.entries(e.specialExits)) if (r === t.id) return;
|
|
2183
|
+
}
|
|
2184
|
+
function _e(e, t) {
|
|
2185
|
+
for (let n of _) if (e.exits[n] === t.id) return n;
|
|
2186
|
+
for (let n of _) if (t.exits[n] === e.id) return v[n];
|
|
2187
|
+
}
|
|
2188
|
+
function ve(e, t, n) {
|
|
2189
|
+
let { fromRoom: r, toRoom: i, fromDir: a, toDir: o } = t;
|
|
2190
|
+
if (n.length === 0 && n.push(r.x, r.y), a && p.includes(a)) {
|
|
2191
|
+
let t = q(e, r.x, r.y, a, e.roomSize / 2);
|
|
2192
|
+
n.push(t.x, t.y);
|
|
2193
|
+
}
|
|
2194
|
+
if (o && p.includes(o)) {
|
|
2195
|
+
let t = q(e, i.x, i.y, o, e.roomSize / 2);
|
|
2196
|
+
n.push(t.x, t.y);
|
|
2197
|
+
}
|
|
2198
|
+
n.push(i.x, i.y);
|
|
2199
|
+
}
|
|
2200
|
+
function ye(e, t) {
|
|
2201
|
+
let { fromRoom: n, toRoom: r, customLineKey: i } = e, a = n, o;
|
|
2202
|
+
i && (o = n.customLines[i], o || (o = r.customLines[i], a = r)), t.length === 0 && t.push(a.x, a.y), o && o.points.forEach((e) => {
|
|
2203
|
+
t.push(e.x, -e.y);
|
|
2204
|
+
}), t.push(r.x, r.y);
|
|
2205
|
+
}
|
|
2206
|
+
function Y(e, t, n, r, i) {
|
|
2207
|
+
let a = [], o = [], s = [], c = n.map((t) => e.getRoom(t)).filter((e) => e !== void 0), l = [], u = () => {
|
|
2208
|
+
l.length >= 4 && a.push({ points: [...l] }), l = [];
|
|
2209
|
+
}, d = (e) => {
|
|
2210
|
+
let { fromRoom: t, toRoom: n, fromDir: r, toDir: i, customLineKey: a } = e;
|
|
2211
|
+
if (a) {
|
|
2212
|
+
let e = t, r = t.customLines[a];
|
|
2213
|
+
if (r || (r = n.customLines[a], e = n), r) {
|
|
2214
|
+
let t = [e.x, e.y];
|
|
2215
|
+
r.points.forEach((e) => {
|
|
2216
|
+
t.push(e.x, -e.y);
|
|
2217
|
+
}), s.push({ points: t });
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
r && K.includes(r) && o.push({
|
|
2221
|
+
room: t,
|
|
2222
|
+
direction: r
|
|
2223
|
+
}), i && K.includes(i) && o.push({
|
|
2224
|
+
room: n,
|
|
2225
|
+
direction: i
|
|
2226
|
+
});
|
|
2227
|
+
};
|
|
2228
|
+
for (let n = 0; n < c.length - 1; n++) {
|
|
2229
|
+
let a = c[n], s = c[n + 1], f = J(a, r, i), m = J(s, r, i);
|
|
2230
|
+
if (!f && !m) {
|
|
2231
|
+
u();
|
|
2232
|
+
continue;
|
|
2233
|
+
}
|
|
2234
|
+
if (f && m) {
|
|
2235
|
+
let n = me(e, a, s);
|
|
2236
|
+
switch (n.type) {
|
|
2237
|
+
case "regular":
|
|
2238
|
+
ve(t, n, l);
|
|
2239
|
+
break;
|
|
2240
|
+
case "special":
|
|
2241
|
+
ye(n, l);
|
|
2242
|
+
break;
|
|
2243
|
+
case "inner":
|
|
2244
|
+
u(), d(n);
|
|
2245
|
+
break;
|
|
2246
|
+
case "none":
|
|
2247
|
+
l.length === 0 && l.push(a.x, a.y), l.push(s.x, s.y);
|
|
2248
|
+
break;
|
|
2249
|
+
}
|
|
2250
|
+
} else {
|
|
2251
|
+
let e = f ? a : s, n = f ? s : a, r = ge(e, n);
|
|
2252
|
+
if (r) {
|
|
2253
|
+
if (K.includes(r.direction)) u(), o.push({
|
|
2254
|
+
room: e,
|
|
2255
|
+
direction: r.direction
|
|
2256
|
+
});
|
|
2257
|
+
else if (p.includes(r.direction)) {
|
|
2258
|
+
l.length === 0 && l.push(e.x, e.y);
|
|
2259
|
+
let n = q(t, e.x, e.y, r.direction, t.roomSize / 2), i = b(e.x, e.y, r.direction, t.roomSize);
|
|
2260
|
+
l.push(n.x, n.y, i.x, i.y), u();
|
|
2261
|
+
}
|
|
2262
|
+
} else {
|
|
2263
|
+
let r = _e(e, n);
|
|
2264
|
+
if (r) {
|
|
2265
|
+
l.length === 0 && l.push(e.x, e.y);
|
|
2266
|
+
let n = q(t, e.x, e.y, r, t.roomSize / 2), i = b(e.x, e.y, r, t.roomSize);
|
|
2267
|
+
l.push(n.x, n.y, i.x, i.y), u();
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
return u(), {
|
|
2273
|
+
segments: a,
|
|
2274
|
+
innerMarkers: o,
|
|
2275
|
+
customLines: s
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
//#endregion
|
|
2279
|
+
//#region src/scene/OverlayStyle.ts
|
|
2280
|
+
function be(e, t) {
|
|
2281
|
+
let n = e.shape ?? "match";
|
|
2282
|
+
return n === "match" ? (e.matchRoomShape ?? !0) && t !== "circle" ? t === "roundedRectangle" ? "roundedRectangle" : "rectangle" : "circle" : n;
|
|
2283
|
+
}
|
|
2284
|
+
function X(e, t, n) {
|
|
2285
|
+
let r = n.highlight, i = n.roomSize, a = r.sizeFactor, o = be(r, n.roomShape), s = Array.isArray(t) ? t.length > 0 ? [...t] : ["#ffffff"] : [t];
|
|
2286
|
+
return {
|
|
2287
|
+
shape: o === "circle" ? "circle" : "rect",
|
|
2288
|
+
cx: e.x,
|
|
2289
|
+
cy: e.y,
|
|
2290
|
+
size: i / 2 * a,
|
|
2291
|
+
cornerRadius: o === "roundedRectangle" ? i * a * .2 : 0,
|
|
2292
|
+
colors: s,
|
|
2293
|
+
strokeAlpha: r.strokeAlpha,
|
|
2294
|
+
strokeWidth: r.strokeWidth,
|
|
2295
|
+
fillAlpha: r.fillAlpha,
|
|
2296
|
+
dash: r.dash,
|
|
2297
|
+
dashEnabled: r.dashEnabled
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
function xe(e, t) {
|
|
2301
|
+
let n = t.playerMarker, r = t.roomSize * n.sizeFactor, i = n.matchRoomShape && t.roomShape !== "circle";
|
|
2302
|
+
return {
|
|
2303
|
+
shape: i ? "rect" : "circle",
|
|
2304
|
+
cx: e.x,
|
|
2305
|
+
cy: e.y,
|
|
2306
|
+
size: r / 2,
|
|
2307
|
+
cornerRadius: i && t.roomShape === "roundedRectangle" ? r * .2 : 0,
|
|
2308
|
+
strokeColor: n.strokeColor,
|
|
2309
|
+
strokeWidth: n.strokeWidth,
|
|
2310
|
+
strokeAlpha: n.strokeAlpha,
|
|
2311
|
+
fillColor: n.fillColor,
|
|
2312
|
+
fillAlpha: n.fillAlpha,
|
|
2313
|
+
dash: n.dash,
|
|
2314
|
+
dashEnabled: n.dashEnabled
|
|
2315
|
+
};
|
|
2316
|
+
}
|
|
2317
|
+
function Z(e, t, n, r, i, a) {
|
|
2318
|
+
let o = Y(e, t, n, i, a), s = t.lineWidth, c = [];
|
|
2319
|
+
for (let e of o.segments) e.points.length >= 4 && c.push({ points: e.points });
|
|
2320
|
+
for (let e of o.customLines) e.points.length >= 4 && c.push({ points: e.points });
|
|
2321
|
+
let l = [];
|
|
2322
|
+
for (let e of o.innerMarkers) for (let n of z(e.room, e.direction, t)) l.push({ vertices: n.vertices });
|
|
2323
|
+
return {
|
|
2324
|
+
segments: c,
|
|
2325
|
+
triangles: l,
|
|
2326
|
+
color: r,
|
|
2327
|
+
outlineWidth: s * 8,
|
|
2328
|
+
lineWidth: s * 4
|
|
2329
|
+
};
|
|
2330
|
+
}
|
|
2331
|
+
//#endregion
|
|
2332
|
+
//#region src/scene/elements/OverlayLayout.ts
|
|
2333
|
+
function Se(e) {
|
|
2334
|
+
if (e.colors.length > 1) return Ce(e);
|
|
2335
|
+
let t = e.colors[0], n = a(t, e.strokeAlpha), r = e.fillAlpha > 0 ? a(t, e.fillAlpha) : void 0;
|
|
2336
|
+
if (e.shape === "circle") return {
|
|
2337
|
+
type: "circle",
|
|
2338
|
+
cx: e.cx,
|
|
2339
|
+
cy: e.cy,
|
|
2340
|
+
radius: e.size,
|
|
2341
|
+
paint: {
|
|
2342
|
+
fill: r,
|
|
2343
|
+
stroke: n,
|
|
2344
|
+
strokeWidth: e.strokeWidth,
|
|
2345
|
+
dash: e.dash,
|
|
2346
|
+
dashEnabled: e.dashEnabled
|
|
2347
|
+
},
|
|
2348
|
+
layer: "overlay"
|
|
2349
|
+
};
|
|
2350
|
+
if (e.cornerRadius > 0) return {
|
|
2351
|
+
type: "rect",
|
|
2352
|
+
x: e.cx - e.size,
|
|
2353
|
+
y: e.cy - e.size,
|
|
2354
|
+
width: e.size * 2,
|
|
2355
|
+
height: e.size * 2,
|
|
2356
|
+
cornerRadius: e.cornerRadius,
|
|
2357
|
+
paint: {
|
|
2358
|
+
fill: r,
|
|
2359
|
+
stroke: n,
|
|
2360
|
+
strokeWidth: e.strokeWidth,
|
|
2361
|
+
dash: e.dash,
|
|
2362
|
+
dashEnabled: e.dashEnabled
|
|
2363
|
+
},
|
|
2364
|
+
layer: "overlay"
|
|
2365
|
+
};
|
|
2366
|
+
let i = e.cx - e.size, o = e.cy - e.size, s = e.cx + e.size, c = e.cy + e.size, l = [
|
|
2367
|
+
[
|
|
2368
|
+
i,
|
|
2369
|
+
o,
|
|
2370
|
+
s,
|
|
2371
|
+
o
|
|
2372
|
+
],
|
|
2373
|
+
[
|
|
2374
|
+
s,
|
|
2375
|
+
o,
|
|
2376
|
+
s,
|
|
2377
|
+
c
|
|
2378
|
+
],
|
|
2379
|
+
[
|
|
2380
|
+
s,
|
|
2381
|
+
c,
|
|
2382
|
+
i,
|
|
2383
|
+
c
|
|
2384
|
+
],
|
|
2385
|
+
[
|
|
2386
|
+
i,
|
|
2387
|
+
c,
|
|
2388
|
+
i,
|
|
2389
|
+
o
|
|
2390
|
+
]
|
|
2391
|
+
], u = [];
|
|
2392
|
+
r && u.push({
|
|
2393
|
+
type: "rect",
|
|
2394
|
+
x: i,
|
|
2395
|
+
y: o,
|
|
2396
|
+
width: e.size * 2,
|
|
2397
|
+
height: e.size * 2,
|
|
2398
|
+
cornerRadius: e.cornerRadius,
|
|
2399
|
+
paint: { fill: r },
|
|
2400
|
+
layer: "overlay"
|
|
2401
|
+
});
|
|
2402
|
+
for (let t of l) u.push({
|
|
2403
|
+
type: "line",
|
|
2404
|
+
points: t,
|
|
2405
|
+
paint: {
|
|
2406
|
+
stroke: n,
|
|
2407
|
+
strokeWidth: e.strokeWidth,
|
|
2408
|
+
dash: e.dash,
|
|
2409
|
+
dashEnabled: e.dashEnabled
|
|
2410
|
+
},
|
|
2411
|
+
lineCap: "butt",
|
|
2412
|
+
layer: "overlay"
|
|
2413
|
+
});
|
|
2414
|
+
return {
|
|
2415
|
+
type: "group",
|
|
2416
|
+
x: 0,
|
|
2417
|
+
y: 0,
|
|
2418
|
+
children: u,
|
|
2419
|
+
layer: "overlay"
|
|
2420
|
+
};
|
|
2421
|
+
}
|
|
2422
|
+
function Ce(e) {
|
|
2423
|
+
let t = e.colors.length, n = Math.PI * 2 / t, r = -Math.PI / 2, i = [];
|
|
2424
|
+
for (let o = 0; o < t; o++) {
|
|
2425
|
+
let t = e.colors[o], s = a(t, e.strokeAlpha), c = e.fillAlpha > 0 ? a(t, e.fillAlpha) : void 0, l = r + o * n, u = Te(e, l, l + n);
|
|
2426
|
+
if (c) {
|
|
2427
|
+
let t = [e.cx, e.cy];
|
|
2428
|
+
for (let [e, n] of u) t.push(e, n);
|
|
2429
|
+
i.push({
|
|
2430
|
+
type: "polygon",
|
|
2431
|
+
vertices: t,
|
|
2432
|
+
paint: { fill: c },
|
|
2433
|
+
layer: "overlay"
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
let d = [];
|
|
2437
|
+
for (let [e, t] of u) d.push(e, t);
|
|
2438
|
+
i.push({
|
|
2439
|
+
type: "line",
|
|
2440
|
+
points: d,
|
|
2441
|
+
paint: {
|
|
2442
|
+
stroke: s,
|
|
2443
|
+
strokeWidth: e.strokeWidth,
|
|
2444
|
+
dash: e.dash,
|
|
2445
|
+
dashEnabled: e.dashEnabled
|
|
2446
|
+
},
|
|
2447
|
+
lineCap: "butt",
|
|
2448
|
+
layer: "overlay"
|
|
2449
|
+
});
|
|
2450
|
+
}
|
|
2451
|
+
return {
|
|
2452
|
+
type: "group",
|
|
2453
|
+
x: 0,
|
|
2454
|
+
y: 0,
|
|
2455
|
+
children: i,
|
|
2456
|
+
layer: "overlay"
|
|
2457
|
+
};
|
|
2458
|
+
}
|
|
2459
|
+
function we(e, t) {
|
|
2460
|
+
let n = Math.cos(t), r = Math.sin(t);
|
|
2461
|
+
if (e.shape === "circle") return [e.cx + e.size * n, e.cy + e.size * r];
|
|
2462
|
+
let i = e.size, a = Math.max(Math.abs(n), Math.abs(r)), o = i / a * n, s = i / a * r, c = Math.min(e.cornerRadius, i), l = i - c;
|
|
2463
|
+
if (c > 0 && Math.abs(o) > l && Math.abs(s) > l) {
|
|
2464
|
+
let t = Math.sign(o) * l, i = Math.sign(s) * l, a = t * n + i * r, u = t * t + i * i, d = a + Math.sqrt(Math.max(0, a * a - (u - c * c)));
|
|
2465
|
+
return [e.cx + d * n, e.cy + d * r];
|
|
2466
|
+
}
|
|
2467
|
+
return [e.cx + o, e.cy + s];
|
|
2468
|
+
}
|
|
2469
|
+
function Te(e, t, n) {
|
|
2470
|
+
let r = [t], i = e.shape !== "circle" && e.cornerRadius > 0;
|
|
2471
|
+
if (e.shape === "circle" || i) {
|
|
2472
|
+
let e = i ? Math.PI / 36 : Math.PI / 18, a = Math.max(1, Math.ceil((n - t) / e));
|
|
2473
|
+
for (let e = 1; e < a; e++) r.push(t + (n - t) * e / a);
|
|
2474
|
+
} else {
|
|
2475
|
+
let e = Math.PI / 2, i = Math.PI / 4, a = Math.ceil((t - i) / e), o = Math.floor((n - i) / e);
|
|
2476
|
+
for (let s = a; s <= o; s++) {
|
|
2477
|
+
let a = i + s * e;
|
|
2478
|
+
a > t + 1e-9 && a < n - 1e-9 && r.push(a);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
return r.push(n), r.sort((e, t) => e - t), r.map((t) => we(e, t));
|
|
2482
|
+
}
|
|
2483
|
+
function Ee(e) {
|
|
2484
|
+
let t = a(e.strokeColor, e.strokeAlpha), n = e.fillAlpha > 0 ? a(e.fillColor, e.fillAlpha) : void 0;
|
|
2485
|
+
return e.shape === "circle" ? {
|
|
2486
|
+
type: "circle",
|
|
2487
|
+
cx: e.cx,
|
|
2488
|
+
cy: e.cy,
|
|
2489
|
+
radius: e.size,
|
|
2490
|
+
paint: {
|
|
2491
|
+
fill: n,
|
|
2492
|
+
stroke: t,
|
|
2493
|
+
strokeWidth: e.strokeWidth,
|
|
2494
|
+
dash: e.dash,
|
|
2495
|
+
dashEnabled: e.dashEnabled
|
|
2496
|
+
},
|
|
2497
|
+
layer: "overlay"
|
|
2498
|
+
} : {
|
|
2499
|
+
type: "rect",
|
|
2500
|
+
x: e.cx - e.size,
|
|
2501
|
+
y: e.cy - e.size,
|
|
2502
|
+
width: e.size * 2,
|
|
2503
|
+
height: e.size * 2,
|
|
2504
|
+
cornerRadius: e.cornerRadius,
|
|
2505
|
+
paint: {
|
|
2506
|
+
fill: n,
|
|
2507
|
+
stroke: t,
|
|
2508
|
+
strokeWidth: e.strokeWidth,
|
|
2509
|
+
dash: e.dash,
|
|
2510
|
+
dashEnabled: e.dashEnabled
|
|
2511
|
+
},
|
|
2512
|
+
layer: "overlay"
|
|
2513
|
+
};
|
|
2514
|
+
}
|
|
2515
|
+
function De(e) {
|
|
2516
|
+
let t = [];
|
|
2517
|
+
for (let n of e.segments) t.push({
|
|
2518
|
+
type: "line",
|
|
2519
|
+
points: n.points,
|
|
2520
|
+
paint: {
|
|
2521
|
+
stroke: "black",
|
|
2522
|
+
strokeWidth: e.outlineWidth,
|
|
2523
|
+
alpha: .8
|
|
2524
|
+
},
|
|
2525
|
+
lineCap: "round",
|
|
2526
|
+
lineJoin: "round",
|
|
2527
|
+
layer: "overlay"
|
|
2528
|
+
}), t.push({
|
|
2529
|
+
type: "line",
|
|
2530
|
+
points: n.points,
|
|
2531
|
+
paint: {
|
|
2532
|
+
stroke: e.color,
|
|
2533
|
+
strokeWidth: e.lineWidth,
|
|
2534
|
+
alpha: .8
|
|
2535
|
+
},
|
|
2536
|
+
lineCap: "round",
|
|
2537
|
+
lineJoin: "round",
|
|
2538
|
+
layer: "overlay"
|
|
2539
|
+
});
|
|
2540
|
+
for (let n of e.triangles) t.push({
|
|
2541
|
+
type: "polygon",
|
|
2542
|
+
vertices: n.vertices,
|
|
2543
|
+
paint: {
|
|
2544
|
+
fill: e.color,
|
|
2545
|
+
stroke: "black",
|
|
2546
|
+
strokeWidth: e.outlineWidth / 4
|
|
2547
|
+
},
|
|
2548
|
+
layer: "overlay"
|
|
2549
|
+
});
|
|
2550
|
+
return t;
|
|
2551
|
+
}
|
|
2552
|
+
//#endregion
|
|
2553
|
+
//#region src/hit/HitTester.ts
|
|
2554
|
+
var Oe = {
|
|
2555
|
+
areaExit: 110,
|
|
2556
|
+
room: 100,
|
|
2557
|
+
label: 80,
|
|
2558
|
+
specialExit: 60,
|
|
2559
|
+
exit: 40,
|
|
2560
|
+
stub: 20
|
|
2561
|
+
}, ke = {
|
|
2562
|
+
room: .3,
|
|
2563
|
+
areaExit: 1,
|
|
2564
|
+
label: 1,
|
|
2565
|
+
specialExit: .5,
|
|
2566
|
+
exit: .35,
|
|
2567
|
+
stub: .3
|
|
2568
|
+
}, Ae = (e, t) => ({
|
|
2569
|
+
x: e,
|
|
2570
|
+
y: t
|
|
2571
|
+
}), je = class {
|
|
2572
|
+
constructor() {
|
|
2573
|
+
this.entries = [], this.bucketSize = 5, this.roomSize = 1, this.spatialIndex = /* @__PURE__ */ new Map(), this.transform = Ae;
|
|
2574
|
+
}
|
|
2575
|
+
build(e, t, n, r) {
|
|
2576
|
+
this.clear(), this.roomSize = t, this.bucketSize = Math.max(t * 10, 5), this.transform = n ?? Ae, this.layerOffset = r, this.collectHitShapes(e, 0, 0);
|
|
2577
|
+
}
|
|
2578
|
+
clear() {
|
|
2579
|
+
this.entries = [], this.spatialIndex.clear();
|
|
2580
|
+
}
|
|
2581
|
+
pick(e, t) {
|
|
2582
|
+
let n = null, r = Infinity, i = Infinity, a = -Infinity;
|
|
2583
|
+
return this.forEachCandidate(e, t, (o, s) => {
|
|
2584
|
+
let c = e - o.cx, l = t - o.cy, u = c * c + l * l;
|
|
2585
|
+
(o.priority > a || o.priority === a && s < r || o.priority === a && s === r && u < i) && (n = o, r = s, i = u, a = o.priority);
|
|
2586
|
+
}), n ? this.toResult(n, r) : null;
|
|
2587
|
+
}
|
|
2588
|
+
pickAll(e, t) {
|
|
2589
|
+
let n = [];
|
|
2590
|
+
return this.forEachCandidate(e, t, (e, t) => {
|
|
2591
|
+
n.push({
|
|
2592
|
+
entry: e,
|
|
2593
|
+
dist: t
|
|
2594
|
+
});
|
|
2595
|
+
}), n.sort((e, t) => t.entry.priority - e.entry.priority || e.dist - t.dist), n.map((e) => this.toResult(e.entry, e.dist));
|
|
2596
|
+
}
|
|
2597
|
+
pickInRect(e, t, n, r, i) {
|
|
2598
|
+
let a = Math.min(e, n), o = Math.max(e, n), s = Math.min(t, r), c = Math.max(t, r), l = [];
|
|
2599
|
+
for (let e of this.entries) i && !i.includes(e.info.kind) || e.cx < a || e.cx > o || e.cy < s || e.cy > c || l.push(this.toResult(e, 0));
|
|
2600
|
+
return l.sort((e, t) => t.priority - e.priority), l;
|
|
2601
|
+
}
|
|
2602
|
+
findRoomAtPoint(e, t) {
|
|
2603
|
+
let n = this.pick(e, t);
|
|
2604
|
+
return !n || n.kind !== "room" ? null : n.payload ?? null;
|
|
2605
|
+
}
|
|
2606
|
+
debugEntries() {
|
|
2607
|
+
return this.entries.map((e) => ({
|
|
2608
|
+
kind: e.info.kind,
|
|
2609
|
+
geoms: e.geoms,
|
|
2610
|
+
marginRadius: e.margin * this.roomSize,
|
|
2611
|
+
minX: e.rMinX,
|
|
2612
|
+
maxX: e.rMaxX,
|
|
2613
|
+
minY: e.rMinY,
|
|
2614
|
+
maxY: e.rMaxY
|
|
2615
|
+
}));
|
|
2616
|
+
}
|
|
2617
|
+
forEachCandidate(e, t, n) {
|
|
2618
|
+
let r = Math.floor(e / this.bucketSize), i = Math.floor(t / this.bucketSize), a = /* @__PURE__ */ new Set();
|
|
2619
|
+
for (let o = -1; o <= 1; o++) for (let s = -1; s <= 1; s++) {
|
|
2620
|
+
let c = this.spatialIndex.get(ze(r + o, i + s));
|
|
2621
|
+
if (c) for (let r of c) {
|
|
2622
|
+
if (a.has(r)) continue;
|
|
2623
|
+
a.add(r);
|
|
2624
|
+
let i = r.margin * this.roomSize;
|
|
2625
|
+
if (e < r.rMinX - i || e > r.rMaxX + i || t < r.rMinY - i || t > r.rMaxY + i) continue;
|
|
2626
|
+
let o = Pe(r, e, t);
|
|
2627
|
+
o > i || n(r, o);
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
toResult(e, t) {
|
|
2632
|
+
return {
|
|
2633
|
+
kind: e.info.kind,
|
|
2634
|
+
id: e.info.id,
|
|
2635
|
+
payload: e.info.payload,
|
|
2636
|
+
distance: t,
|
|
2637
|
+
priority: e.priority,
|
|
2638
|
+
centerX: e.cx,
|
|
2639
|
+
centerY: e.cy
|
|
2640
|
+
};
|
|
2641
|
+
}
|
|
2642
|
+
collectHitShapes(e, t, n) {
|
|
2643
|
+
for (let r of e) {
|
|
2644
|
+
if (r.hit) {
|
|
2645
|
+
let e = [], i = Me();
|
|
2646
|
+
Ne(r, t, n, this.entryTransform(r.layer), e, i), e.length > 0 && i.minX <= i.maxX && this.indexEntry(i, e, r.hit);
|
|
2647
|
+
}
|
|
2648
|
+
r.type === "group" && this.collectHitShapes(r.children, t + r.x, n + r.y);
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
entryTransform(e) {
|
|
2652
|
+
let t = this.layerOffset?.(e);
|
|
2653
|
+
if (!t || t.x === 0 && t.y === 0) return this.transform;
|
|
2654
|
+
let n = this.transform;
|
|
2655
|
+
return (e, r) => {
|
|
2656
|
+
let i = n(e, r);
|
|
2657
|
+
return {
|
|
2658
|
+
x: i.x + t.x,
|
|
2659
|
+
y: i.y + t.y
|
|
2660
|
+
};
|
|
2661
|
+
};
|
|
2662
|
+
}
|
|
2663
|
+
indexEntry(e, t, n) {
|
|
2664
|
+
let r = n.margin ?? ke[n.kind] ?? 1, i = n.priority ?? Oe[n.kind] ?? 50, a = (e.minX + e.maxX) / 2, o = (e.minY + e.maxY) / 2, s = {
|
|
2665
|
+
info: n,
|
|
2666
|
+
margin: r,
|
|
2667
|
+
priority: i,
|
|
2668
|
+
rMinX: e.minX,
|
|
2669
|
+
rMaxX: e.maxX,
|
|
2670
|
+
rMinY: e.minY,
|
|
2671
|
+
rMaxY: e.maxY,
|
|
2672
|
+
cx: a,
|
|
2673
|
+
cy: o,
|
|
2674
|
+
geoms: t
|
|
2675
|
+
};
|
|
2676
|
+
this.entries.push(s);
|
|
2677
|
+
let c = this.bucketSize, l = Math.floor(e.minX / c), u = Math.floor(e.maxX / c), d = Math.floor(e.minY / c), f = Math.floor(e.maxY / c);
|
|
2678
|
+
for (let e = l; e <= u; e++) for (let t = d; t <= f; t++) {
|
|
2679
|
+
let n = ze(e, t), r = this.spatialIndex.get(n);
|
|
2680
|
+
r || (r = [], this.spatialIndex.set(n, r)), r.push(s);
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
};
|
|
2684
|
+
function Me() {
|
|
2685
|
+
return {
|
|
2686
|
+
minX: Infinity,
|
|
2687
|
+
minY: Infinity,
|
|
2688
|
+
maxX: -Infinity,
|
|
2689
|
+
maxY: -Infinity
|
|
2690
|
+
};
|
|
2691
|
+
}
|
|
2692
|
+
function Q(e, t, n) {
|
|
2693
|
+
t < e.minX && (e.minX = t), t > e.maxX && (e.maxX = t), n < e.minY && (e.minY = n), n > e.maxY && (e.maxY = n);
|
|
2694
|
+
}
|
|
2695
|
+
function Ne(e, t, n, r, i, a) {
|
|
2696
|
+
if (e.type === "group") {
|
|
2697
|
+
for (let o of e.children) o.hit || $(o, t + e.x, n + e.y, r, i, a);
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
$(e, t, n, r, i, a);
|
|
2701
|
+
}
|
|
2702
|
+
function $(e, t, n, r, i, a) {
|
|
2703
|
+
switch (e.type) {
|
|
2704
|
+
case "rect":
|
|
2705
|
+
case "image": {
|
|
2706
|
+
let o = r(t + e.x, n + e.y), s = r(t + e.x + e.width, n + e.y), c = r(t + e.x + e.width, n + e.y + e.height), l = r(t + e.x, n + e.y + e.height), u = [
|
|
2707
|
+
o.x,
|
|
2708
|
+
o.y,
|
|
2709
|
+
s.x,
|
|
2710
|
+
s.y,
|
|
2711
|
+
c.x,
|
|
2712
|
+
c.y,
|
|
2713
|
+
l.x,
|
|
2714
|
+
l.y
|
|
2715
|
+
];
|
|
2716
|
+
i.push({
|
|
2717
|
+
type: "polyline",
|
|
2718
|
+
pts: u,
|
|
2719
|
+
closed: !0
|
|
2720
|
+
});
|
|
2721
|
+
for (let e = 0; e < u.length; e += 2) Q(a, u[e], u[e + 1]);
|
|
2722
|
+
return;
|
|
2723
|
+
}
|
|
2724
|
+
case "text": {
|
|
2725
|
+
let o = e.width ?? 0, s = e.height ?? 0;
|
|
2726
|
+
if (o === 0 || s === 0) {
|
|
2727
|
+
let i = r(t + e.x, n + e.y);
|
|
2728
|
+
Q(a, i.x, i.y);
|
|
2729
|
+
return;
|
|
2730
|
+
}
|
|
2731
|
+
let c = r(t + e.x, n + e.y), l = r(t + e.x + o, n + e.y), u = r(t + e.x + o, n + e.y + s), d = r(t + e.x, n + e.y + s), f = [
|
|
2732
|
+
c.x,
|
|
2733
|
+
c.y,
|
|
2734
|
+
l.x,
|
|
2735
|
+
l.y,
|
|
2736
|
+
u.x,
|
|
2737
|
+
u.y,
|
|
2738
|
+
d.x,
|
|
2739
|
+
d.y
|
|
2740
|
+
];
|
|
2741
|
+
i.push({
|
|
2742
|
+
type: "polyline",
|
|
2743
|
+
pts: f,
|
|
2744
|
+
closed: !0
|
|
2745
|
+
});
|
|
2746
|
+
for (let e = 0; e < f.length; e += 2) Q(a, f[e], f[e + 1]);
|
|
2747
|
+
return;
|
|
2748
|
+
}
|
|
2749
|
+
case "circle": {
|
|
2750
|
+
let o = r(t + e.cx, n + e.cy);
|
|
2751
|
+
i.push({
|
|
2752
|
+
type: "circle",
|
|
2753
|
+
cx: o.x,
|
|
2754
|
+
cy: o.y,
|
|
2755
|
+
r: e.radius
|
|
2756
|
+
}), Q(a, o.x - e.radius, o.y - e.radius), Q(a, o.x + e.radius, o.y + e.radius);
|
|
2757
|
+
return;
|
|
2758
|
+
}
|
|
2759
|
+
case "line": {
|
|
2760
|
+
let o = [];
|
|
2761
|
+
for (let i = 0; i < e.points.length; i += 2) {
|
|
2762
|
+
let s = r(t + e.points[i], n + e.points[i + 1]);
|
|
2763
|
+
o.push(s.x, s.y), Q(a, s.x, s.y);
|
|
2764
|
+
}
|
|
2765
|
+
o.length >= 2 && i.push({
|
|
2766
|
+
type: "polyline",
|
|
2767
|
+
pts: o,
|
|
2768
|
+
closed: !1
|
|
2769
|
+
});
|
|
2770
|
+
return;
|
|
2771
|
+
}
|
|
2772
|
+
case "polygon": {
|
|
2773
|
+
let o = [];
|
|
2774
|
+
for (let i = 0; i < e.vertices.length; i += 2) {
|
|
2775
|
+
let s = r(t + e.vertices[i], n + e.vertices[i + 1]);
|
|
2776
|
+
o.push(s.x, s.y), Q(a, s.x, s.y);
|
|
2777
|
+
}
|
|
2778
|
+
o.length >= 2 && i.push({
|
|
2779
|
+
type: "polyline",
|
|
2780
|
+
pts: o,
|
|
2781
|
+
closed: !0
|
|
2782
|
+
});
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2785
|
+
case "group":
|
|
2786
|
+
for (let o of e.children) o.hit || $(o, t + e.x, n + e.y, r, i, a);
|
|
2787
|
+
return;
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
function Pe(e, t, n) {
|
|
2791
|
+
let r = Infinity;
|
|
2792
|
+
for (let i of e.geoms) {
|
|
2793
|
+
let e = Fe(i, t, n);
|
|
2794
|
+
if (e < r && (r = e), r === 0) return 0;
|
|
2795
|
+
}
|
|
2796
|
+
return r;
|
|
2797
|
+
}
|
|
2798
|
+
function Fe(e, t, n) {
|
|
2799
|
+
if (e.type === "circle") {
|
|
2800
|
+
let r = t - e.cx, i = n - e.cy;
|
|
2801
|
+
return Math.max(0, Math.hypot(r, i) - e.r);
|
|
2802
|
+
}
|
|
2803
|
+
return e.closed && Re(e.pts, t, n) ? 0 : Ie(e.pts, t, n, e.closed);
|
|
2804
|
+
}
|
|
2805
|
+
function Ie(e, t, n, r) {
|
|
2806
|
+
let i = e.length / 2;
|
|
2807
|
+
if (i < 2) return i === 1 ? Math.hypot(t - e[0], n - e[1]) : Infinity;
|
|
2808
|
+
let a = Infinity, o = r ? i : i - 1;
|
|
2809
|
+
for (let r = 0; r < o; r++) {
|
|
2810
|
+
let o = r * 2, s = (r + 1) % i * 2, c = Le(t, n, e[o], e[o + 1], e[s], e[s + 1]);
|
|
2811
|
+
c < a && (a = c);
|
|
2812
|
+
}
|
|
2813
|
+
return a;
|
|
2814
|
+
}
|
|
2815
|
+
function Le(e, t, n, r, i, a) {
|
|
2816
|
+
let o = i - n, s = a - r, c = o * o + s * s, l = c === 0 ? 0 : ((e - n) * o + (t - r) * s) / c;
|
|
2817
|
+
l < 0 ? l = 0 : l > 1 && (l = 1);
|
|
2818
|
+
let u = n + l * o, d = r + l * s;
|
|
2819
|
+
return Math.hypot(e - u, t - d);
|
|
2820
|
+
}
|
|
2821
|
+
function Re(e, t, n) {
|
|
2822
|
+
let r = !1, i = e.length / 2;
|
|
2823
|
+
for (let a = 0, o = i - 1; a < i; o = a++) {
|
|
2824
|
+
let i = e[a * 2], s = e[a * 2 + 1], c = e[o * 2], l = e[o * 2 + 1], u = l - s || 1e-12;
|
|
2825
|
+
s > n != l > n && t < (c - i) * (n - s) / u + i && (r = !r);
|
|
2826
|
+
}
|
|
2827
|
+
return r;
|
|
2828
|
+
}
|
|
2829
|
+
function ze(e, t) {
|
|
2830
|
+
return e * 1000003 + t;
|
|
2831
|
+
}
|
|
2832
|
+
//#endregion
|
|
2833
|
+
//#region src/style/Style.ts
|
|
2834
|
+
var Be = { transform: (e) => e };
|
|
2835
|
+
function Ve(...e) {
|
|
2836
|
+
return e.length === 0 ? Be : e.length === 1 ? e[0] : {
|
|
2837
|
+
transform(t, n) {
|
|
2838
|
+
let r = [t];
|
|
2839
|
+
for (let t of e) {
|
|
2840
|
+
let e = [];
|
|
2841
|
+
for (let i of r) {
|
|
2842
|
+
let r = t.transform(i, n);
|
|
2843
|
+
Array.isArray(r) ? e.push(...r) : e.push(r);
|
|
2844
|
+
}
|
|
2845
|
+
r = e;
|
|
2846
|
+
}
|
|
2847
|
+
return r;
|
|
2848
|
+
},
|
|
2849
|
+
worldToScene(t, n) {
|
|
2850
|
+
let r = {
|
|
2851
|
+
x: t,
|
|
2852
|
+
y: n
|
|
2853
|
+
};
|
|
2854
|
+
for (let t of e) t.worldToScene && (r = t.worldToScene(r.x, r.y));
|
|
2855
|
+
return r;
|
|
2856
|
+
},
|
|
2857
|
+
sceneToWorld(t, n) {
|
|
2858
|
+
let r = {
|
|
2859
|
+
x: t,
|
|
2860
|
+
y: n
|
|
2861
|
+
};
|
|
2862
|
+
for (let t = e.length - 1; t >= 0; t--) {
|
|
2863
|
+
let n = e[t];
|
|
2864
|
+
n.sceneToWorld && (r = n.sceneToWorld(r.x, r.y));
|
|
2865
|
+
}
|
|
2866
|
+
return r;
|
|
2867
|
+
},
|
|
2868
|
+
sceneLayerOffset(t) {
|
|
2869
|
+
let n = 0, r = 0;
|
|
2870
|
+
for (let i of e) {
|
|
2871
|
+
if (!i.sceneLayerOffset) continue;
|
|
2872
|
+
let e = i.sceneLayerOffset(t);
|
|
2873
|
+
n += e.x, r += e.y;
|
|
2874
|
+
}
|
|
2875
|
+
return {
|
|
2876
|
+
x: n,
|
|
2877
|
+
y: r
|
|
2878
|
+
};
|
|
2879
|
+
}
|
|
2880
|
+
};
|
|
2881
|
+
}
|
|
2882
|
+
//#endregion
|
|
2883
|
+
//#region src/style/applyStyle.ts
|
|
2884
|
+
function He(e, t, n) {
|
|
2885
|
+
let r = [];
|
|
2886
|
+
for (let i of e) {
|
|
2887
|
+
let e = Ue(i, t, n);
|
|
2888
|
+
Array.isArray(e) ? r.push(...e) : r.push(e);
|
|
2889
|
+
}
|
|
2890
|
+
return r;
|
|
2891
|
+
}
|
|
2892
|
+
function Ue(e, t, n) {
|
|
2893
|
+
if (e.type === "group") {
|
|
2894
|
+
let r = [];
|
|
2895
|
+
for (let i of e.children) {
|
|
2896
|
+
let e = Ue(i, t, n);
|
|
2897
|
+
Array.isArray(e) ? r.push(...e) : r.push(e);
|
|
2898
|
+
}
|
|
2899
|
+
return t.transform({
|
|
2900
|
+
...e,
|
|
2901
|
+
children: r
|
|
2902
|
+
}, n);
|
|
2903
|
+
}
|
|
2904
|
+
return t.transform(e, n);
|
|
2905
|
+
}
|
|
2906
|
+
//#endregion
|
|
2907
|
+
//#region src/export/flushSceneShapes.ts
|
|
2908
|
+
function We(e, t, n) {
|
|
2909
|
+
n(e.grid), n(e.link), n(e.room), n(Ge(t.state, t.overlays));
|
|
2910
|
+
for (let e of t.sceneOverlays) {
|
|
2911
|
+
let r = e.render(t.state, t.viewportBounds);
|
|
2912
|
+
r && n(Array.isArray(r) ? r : [r], e.sceneSpace);
|
|
2913
|
+
}
|
|
2914
|
+
n(e.topLabel);
|
|
2915
|
+
}
|
|
2916
|
+
function Ge(e, t) {
|
|
2917
|
+
let n = e.getOverlaysForArea(t);
|
|
2918
|
+
if (!n) return [];
|
|
2919
|
+
let r = e.settings, i = [];
|
|
2920
|
+
if (n.paths) for (let t of n.paths) {
|
|
2921
|
+
let n = Z(e.mapReader, r, t.locations, t.color, e.currentArea, e.currentZIndex);
|
|
2922
|
+
i.push(...De(n));
|
|
2923
|
+
}
|
|
2924
|
+
if (n.highlights) for (let t of n.highlights) {
|
|
2925
|
+
let n = e.mapReader.getRoom(t.roomId);
|
|
2926
|
+
n && i.push(Se(X(n, t.color, r)));
|
|
2927
|
+
}
|
|
2928
|
+
if (n.position) {
|
|
2929
|
+
let t = e.mapReader.getRoom(n.position.roomId);
|
|
2930
|
+
t && i.push(Ee(xe(t, r)));
|
|
2931
|
+
}
|
|
2932
|
+
return i;
|
|
2933
|
+
}
|
|
2934
|
+
//#endregion
|
|
2935
|
+
export { t as A, _ as C, s as D, u as E, a as M, r as N, c as O, v as S, d as T, H as _, Be as a, A as b, De as c, Z as d, xe as f, U as g, fe as h, Ve as i, n as j, o as k, Ee as l, pe as m, We as n, je as o, Y as p, He as r, Se as s, Ge as t, X as u, B as v, f as w, O as x, L as y };
|
|
2936
|
+
|
|
2937
|
+
//# sourceMappingURL=flushSceneShapes-Duhi0OQv.js.map
|