@kbve/laser 0.0.8 → 0.1.2

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.
Files changed (69) hide show
  1. package/README.md +40 -10
  2. package/laser.es.js +872 -0
  3. package/package.json +54 -24
  4. package/src/index.d.ts +0 -19
  5. package/src/index.js +0 -37
  6. package/src/index.js.map +0 -1
  7. package/src/lib/animations/TypewriterComponent.d.ts +0 -8
  8. package/src/lib/animations/TypewriterComponent.js +0 -53
  9. package/src/lib/animations/TypewriterComponent.js.map +0 -1
  10. package/src/lib/constants.d.ts +0 -2
  11. package/src/lib/constants.js +0 -6
  12. package/src/lib/constants.js.map +0 -1
  13. package/src/lib/eventhandler.d.ts +0 -31
  14. package/src/lib/eventhandler.js +0 -45
  15. package/src/lib/eventhandler.js.map +0 -1
  16. package/src/lib/icon/CollapseIcon.d.ts +0 -4
  17. package/src/lib/icon/CollapseIcon.js +0 -10
  18. package/src/lib/icon/CollapseIcon.js.map +0 -1
  19. package/src/lib/icon/ExpandIcon.d.ts +0 -4
  20. package/src/lib/icon/ExpandIcon.js +0 -10
  21. package/src/lib/icon/ExpandIcon.js.map +0 -1
  22. package/src/lib/laser.d.ts +0 -1
  23. package/src/lib/laser.js +0 -8
  24. package/src/lib/laser.js.map +0 -1
  25. package/src/lib/localdb.d.ts +0 -55
  26. package/src/lib/localdb.js +0 -592
  27. package/src/lib/localdb.js.map +0 -1
  28. package/src/lib/minigame/dice/MinigameDice.d.ts +0 -4
  29. package/src/lib/minigame/dice/MinigameDice.js +0 -85
  30. package/src/lib/minigame/dice/MinigameDice.js.map +0 -1
  31. package/src/lib/phaser/map/mapdatabase.d.ts +0 -1
  32. package/src/lib/phaser/map/mapdatabase.js +0 -175
  33. package/src/lib/phaser/map/mapdatabase.js.map +0 -1
  34. package/src/lib/phaser/monster/bird.d.ts +0 -7
  35. package/src/lib/phaser/monster/bird.js +0 -44
  36. package/src/lib/phaser/monster/bird.js.map +0 -1
  37. package/src/lib/phaser/npc/chatbubble.d.ts +0 -10
  38. package/src/lib/phaser/npc/chatbubble.js +0 -78
  39. package/src/lib/phaser/npc/chatbubble.js.map +0 -1
  40. package/src/lib/phaser/npc/npcdatabase.d.ts +0 -59
  41. package/src/lib/phaser/npc/npcdatabase.js +0 -550
  42. package/src/lib/phaser/npc/npcdatabase.js.map +0 -1
  43. package/src/lib/phaser/npc/npchandler.d.ts +0 -21
  44. package/src/lib/phaser/npc/npchandler.js +0 -123
  45. package/src/lib/phaser/npc/npchandler.js.map +0 -1
  46. package/src/lib/phaser/npc/tooltipmenu.d.ts +0 -17
  47. package/src/lib/phaser/npc/tooltipmenu.js +0 -68
  48. package/src/lib/phaser/npc/tooltipmenu.js.map +0 -1
  49. package/src/lib/phaser/player/playercontroller.d.ts +0 -24
  50. package/src/lib/phaser/player/playercontroller.js +0 -219
  51. package/src/lib/phaser/player/playercontroller.js.map +0 -1
  52. package/src/lib/quadtree.d.ts +0 -23
  53. package/src/lib/quadtree.js +0 -123
  54. package/src/lib/quadtree.js.map +0 -1
  55. package/src/lib/regex.d.ts +0 -1
  56. package/src/lib/regex.js +0 -6
  57. package/src/lib/regex.js.map +0 -1
  58. package/src/lib/utils/debug.d.ts +0 -8
  59. package/src/lib/utils/debug.js +0 -46
  60. package/src/lib/utils/debug.js.map +0 -1
  61. package/src/lib/utils/loader.d.ts +0 -3
  62. package/src/lib/utils/loader.js +0 -87
  63. package/src/lib/utils/loader.js.map +0 -1
  64. package/src/lib/utils/ulid.d.ts +0 -1
  65. package/src/lib/utils/ulid.js +0 -38
  66. package/src/lib/utils/ulid.js.map +0 -1
  67. package/src/types.d.ts +0 -423
  68. package/src/types.js +0 -14
  69. package/src/types.js.map +0 -1
package/laser.es.js ADDED
@@ -0,0 +1,872 @@
1
+ import { jsxs as I, jsx as D } from "react/jsx-runtime";
2
+ import { createContext as v, useContext as O, forwardRef as K, useRef as g, useState as j, useImperativeHandle as L, useEffect as R, useMemo as N } from "react";
3
+ import x from "phaser";
4
+ import { Canvas as q, useFrame as F } from "@react-three/fiber";
5
+ import { query as P } from "bitecs";
6
+ export * from "bitecs";
7
+ import { RAPIER as Ht, createRapierPhysics as zt } from "@phaserjs/rapier-connector";
8
+ class S {
9
+ handlers = /* @__PURE__ */ new Map();
10
+ on(t, e) {
11
+ let i = this.handlers.get(t);
12
+ return i || (i = /* @__PURE__ */ new Set(), this.handlers.set(t, i)), i.add(e), () => {
13
+ i.delete(e);
14
+ };
15
+ }
16
+ off(t, e) {
17
+ this.handlers.get(t)?.delete(e);
18
+ }
19
+ emit(t, e) {
20
+ this.handlers.get(t)?.forEach((i) => {
21
+ i(e);
22
+ });
23
+ }
24
+ clear() {
25
+ this.handlers.clear();
26
+ }
27
+ }
28
+ const E = new S();
29
+ class M {
30
+ bounds;
31
+ capacity;
32
+ points;
33
+ divided;
34
+ cache;
35
+ northeast;
36
+ northwest;
37
+ southeast;
38
+ southwest;
39
+ constructor(t, e = 4) {
40
+ this.bounds = t, this.capacity = e, this.points = [], this.divided = !1, this.cache = /* @__PURE__ */ new Map();
41
+ }
42
+ subdivide() {
43
+ const { xMin: t, yMin: e, xMax: i, yMax: n } = this.bounds, r = (i - t) / 2, a = (n - e) / 2, o = t, h = e;
44
+ this.northeast = new M(
45
+ { xMin: o + r, xMax: o + 2 * r, yMin: e, yMax: h + a },
46
+ this.capacity
47
+ ), this.northwest = new M(
48
+ { xMin: t, xMax: o + r, yMin: e, yMax: h + a },
49
+ this.capacity
50
+ ), this.southeast = new M(
51
+ { xMin: o + r, xMax: o + 2 * r, yMin: h + a, yMax: h + 2 * a },
52
+ this.capacity
53
+ ), this.southwest = new M(
54
+ { xMin: t, xMax: o + r, yMin: h + a, yMax: h + 2 * a },
55
+ this.capacity
56
+ ), this.divided = !0;
57
+ }
58
+ insert(t) {
59
+ return this.contains(t.bounds) ? this.points.length < this.capacity ? (this.points.push(t), !0) : (this.divided || this.subdivide(), !!(this.northeast?.insert(t) || this.northwest?.insert(t) || this.southeast?.insert(t) || this.southwest?.insert(t))) : !1;
60
+ }
61
+ contains(t) {
62
+ const { xMin: e, yMin: i, xMax: n, yMax: r } = this.bounds;
63
+ return t.xMin >= e && t.xMax <= n && t.yMin >= i && t.yMax <= r;
64
+ }
65
+ queryRange(t, e = []) {
66
+ if (!this.intersects(t))
67
+ return e;
68
+ for (const i of this.points)
69
+ this.isWithinBounds(i.bounds, t) && e.push(i);
70
+ return this.divided && (this.northwest?.queryRange(t, e), this.northeast?.queryRange(t, e), this.southwest?.queryRange(t, e), this.southeast?.queryRange(t, e)), e;
71
+ }
72
+ query(t, e = []) {
73
+ const i = `${t.x},${t.y}`, n = this.cache.get(i);
74
+ if (n)
75
+ return n;
76
+ if (!this.intersects({
77
+ xMin: t.x,
78
+ xMax: t.x,
79
+ yMin: t.y,
80
+ yMax: t.y
81
+ }))
82
+ return e;
83
+ for (const r of this.points)
84
+ this.isWithinRange(t, r.bounds) && e.push(r);
85
+ return this.divided && (this.northwest?.query(t, e), this.northeast?.query(t, e), this.southwest?.query(t, e), this.southeast?.query(t, e)), this.cache.set(i, e), e;
86
+ }
87
+ intersects(t) {
88
+ const { xMin: e, yMin: i, xMax: n, yMax: r } = this.bounds;
89
+ return !(t.xMin > n || t.xMax < e || t.yMin > r || t.yMax < i);
90
+ }
91
+ isWithinBounds(t, e) {
92
+ return t.xMax >= e.xMin && t.xMin <= e.xMax && t.yMax >= e.yMin && t.yMin <= e.yMax;
93
+ }
94
+ isWithinRange(t, e) {
95
+ return t.x >= e.xMin && t.x <= e.xMax && t.y >= e.yMin && t.y <= e.yMax;
96
+ }
97
+ }
98
+ const T = v(null);
99
+ function U() {
100
+ const s = O(T);
101
+ if (!s)
102
+ throw new Error(
103
+ "usePhaserGame must be used within a <PhaserGame> component"
104
+ );
105
+ return s;
106
+ }
107
+ const lt = K(
108
+ function({ config: t, onReady: e, onDestroy: i, className: n, style: r, children: a }, o) {
109
+ const h = g(null), c = g(null), p = g(null), [l, u] = j("idle");
110
+ L(
111
+ o,
112
+ () => ({
113
+ game: c.current,
114
+ status: l
115
+ }),
116
+ [l]
117
+ ), R(() => {
118
+ if (!h.current) return;
119
+ const m = h.current;
120
+ if (p.current !== null && (window.clearTimeout(p.current), p.current = null), c.current) {
121
+ const f = c.current.canvas;
122
+ return f && f.parentElement !== m && m.appendChild(f), u(c.current.isBooted ? "running" : "booting"), w;
123
+ }
124
+ u("booting");
125
+ const k = {
126
+ type: x.AUTO,
127
+ width: t.width ?? 800,
128
+ height: t.height ?? 600,
129
+ parent: m,
130
+ scene: t.scenes,
131
+ backgroundColor: t.backgroundColor,
132
+ transparent: t.transparent,
133
+ ...t.physics && { physics: t.physics },
134
+ ...t.plugins && { plugins: t.plugins },
135
+ ...t.scale && { scale: t.scale },
136
+ ...t.input && { input: t.input },
137
+ ...t.render || t.pixelArt ? {
138
+ render: t.pixelArt ? {
139
+ pixelArt: !0,
140
+ antialias: !1,
141
+ ...t.render
142
+ } : t.render
143
+ } : {},
144
+ ...t.dom && { dom: t.dom },
145
+ ...t.audio && { audio: t.audio },
146
+ ...t.callbacks && { callbacks: t.callbacks },
147
+ ...t.fps && { fps: t.fps }
148
+ }, y = new x.Game(k);
149
+ return c.current = y, y.events.once("ready", () => {
150
+ c.current === y && (u("running"), E.emit("game:ready", { game: y }), e?.(y));
151
+ }), w;
152
+ function w() {
153
+ p.current = window.setTimeout(() => {
154
+ p.current = null;
155
+ const f = c.current;
156
+ f && (u("destroyed"), E.emit("game:destroy", void 0), i?.(), f.destroy(!0), c.current = null);
157
+ }, 0);
158
+ }
159
+ }, [t, e, i]);
160
+ const d = N(
161
+ () => ({ game: c.current, status: l }),
162
+ [l]
163
+ );
164
+ return /* @__PURE__ */ I(T.Provider, { value: d, children: [
165
+ /* @__PURE__ */ D("div", { ref: h, className: n, style: r }),
166
+ a
167
+ ] });
168
+ }
169
+ );
170
+ function dt(s, t, e) {
171
+ const { game: i } = U(), n = g(t);
172
+ n.current = t, R(() => {
173
+ if (!i) return;
174
+ const r = (...a) => n.current(...a);
175
+ if (e) {
176
+ const a = i.scene.getScene(e);
177
+ if (a)
178
+ return a.events.on(s, r), () => {
179
+ a.events.off(s, r);
180
+ };
181
+ } else
182
+ return i.events.on(s, r), () => {
183
+ i.events.off(s, r);
184
+ };
185
+ }, [i, s, e]);
186
+ }
187
+ class W {
188
+ scene;
189
+ base;
190
+ thumb;
191
+ radius;
192
+ deadZone;
193
+ _direction = null;
194
+ _isActive = !1;
195
+ fixed;
196
+ activePointer = null;
197
+ constructor(t, e) {
198
+ this.scene = t, this.radius = e?.radius ?? 60, this.deadZone = e?.deadZone ?? 0.25, this.fixed = e?.fixed ?? !0;
199
+ const i = e?.x ?? 120, n = e?.y ?? t.scale.height - 120;
200
+ this.base = t.add.circle(
201
+ i,
202
+ n,
203
+ this.radius,
204
+ e?.baseColor ?? 8947848,
205
+ e?.baseAlpha ?? 0.35
206
+ ).setDepth(100).setScrollFactor(0), this.thumb = t.add.circle(
207
+ i,
208
+ n,
209
+ this.radius * 0.4,
210
+ e?.thumbColor ?? 16777215,
211
+ e?.thumbAlpha ?? 0.5
212
+ ).setDepth(101).setScrollFactor(0), this.setupInput();
213
+ }
214
+ setupInput() {
215
+ this.scene.input.on("pointerdown", (t) => {
216
+ if (this.activePointer) return;
217
+ const e = t.x - this.base.x, i = t.y - this.base.y, n = Math.sqrt(e * e + i * i);
218
+ this.fixed && n > this.radius * 2 || (this.fixed || (this.base.setPosition(t.x, t.y), this.thumb.setPosition(t.x, t.y)), this.activePointer = t, this._isActive = !0);
219
+ }), this.scene.input.on("pointermove", (t) => {
220
+ t === this.activePointer && this.updateThumb(t.x, t.y);
221
+ }), this.scene.input.on("pointerup", (t) => {
222
+ t === this.activePointer && this.resetThumb();
223
+ });
224
+ }
225
+ updateThumb(t, e) {
226
+ const i = t - this.base.x, n = e - this.base.y, r = Math.sqrt(i * i + n * n), a = Math.min(r, this.radius), o = Math.atan2(n, i);
227
+ if (this.thumb.setPosition(
228
+ this.base.x + Math.cos(o) * a,
229
+ this.base.y + Math.sin(o) * a
230
+ ), a / this.radius < this.deadZone) {
231
+ this._direction = null;
232
+ return;
233
+ }
234
+ this._direction = this.angleToDirection(o);
235
+ }
236
+ angleToDirection(t) {
237
+ let e = t * 180 / Math.PI;
238
+ return e < 0 && (e += 360), e >= 337.5 || e < 22.5 ? "right" : e >= 22.5 && e < 67.5 ? "down-right" : e >= 67.5 && e < 112.5 ? "down" : e >= 112.5 && e < 157.5 ? "down-left" : e >= 157.5 && e < 202.5 ? "left" : e >= 202.5 && e < 247.5 ? "up-left" : e >= 247.5 && e < 292.5 ? "up" : "up-right";
239
+ }
240
+ resetThumb() {
241
+ this.thumb.setPosition(this.base.x, this.base.y), this._direction = null, this._isActive = !1, this.activePointer = null;
242
+ }
243
+ get direction() {
244
+ return this._direction;
245
+ }
246
+ get isActive() {
247
+ return this._isActive;
248
+ }
249
+ setVisible(t) {
250
+ return this.base.setVisible(t), this.thumb.setVisible(t), this;
251
+ }
252
+ destroy() {
253
+ this.base.destroy(), this.thumb.destroy();
254
+ }
255
+ }
256
+ class pt {
257
+ scene;
258
+ gridEngine;
259
+ quadtree;
260
+ cursor;
261
+ wasdKeys;
262
+ tooltip;
263
+ tileSize;
264
+ playerId;
265
+ joystick = null;
266
+ constructor(t, e, i, n) {
267
+ if (this.scene = t, this.gridEngine = e, this.quadtree = i, this.tileSize = n?.tileSize ?? 48, this.playerId = n?.playerId ?? "player", this.cursor = this.scene.input.keyboard?.createCursorKeys(), this.initializeWASDKeys(), this.tooltip = this.scene.add.text(0, 0, "Press [F]", {
268
+ font: "16px Arial",
269
+ backgroundColor: "#000000"
270
+ }).setDepth(4).setPadding(3, 2, 2, 3).setVisible(!1), n?.joystick) {
271
+ const r = typeof n.joystick == "object" ? n.joystick : void 0;
272
+ this.joystick = new W(t, r);
273
+ }
274
+ }
275
+ initializeWASDKeys() {
276
+ const t = this.scene.input.keyboard;
277
+ t && (this.wasdKeys = {
278
+ W: t.addKey(x.Input.Keyboard.KeyCodes.W),
279
+ A: t.addKey(x.Input.Keyboard.KeyCodes.A),
280
+ S: t.addKey(x.Input.Keyboard.KeyCodes.S),
281
+ D: t.addKey(x.Input.Keyboard.KeyCodes.D)
282
+ });
283
+ }
284
+ checkForNearbyObjects() {
285
+ const t = this.gridEngine.getPosition(this.playerId), e = t.x * this.tileSize, i = t.y * this.tileSize, n = this.quadtree.query(t);
286
+ n.length > 0 ? (this.tooltip.setPosition(e, i - 60).setVisible(!0), E.emit("player:nearby", {
287
+ position: t,
288
+ ranges: n
289
+ })) : this.tooltip.setVisible(!1);
290
+ }
291
+ getPlayerPosition() {
292
+ return this.gridEngine.getPosition(this.playerId);
293
+ }
294
+ handleMovement() {
295
+ if (this.scene.input.keyboard?.addKey("F").isDown) {
296
+ const i = this.gridEngine.getPosition(
297
+ this.playerId
298
+ ), n = this.quadtree.query(i);
299
+ if (n.length > 0) {
300
+ E.emit("player:interact", {
301
+ position: i,
302
+ ranges: n
303
+ });
304
+ for (const r of n)
305
+ r.action();
306
+ }
307
+ }
308
+ if (this.joystick?.isActive && this.joystick.direction) {
309
+ this.gridEngine.move(this.playerId, this.joystick.direction), this.checkForNearbyObjects();
310
+ return;
311
+ }
312
+ if (!this.cursor) {
313
+ this.checkForNearbyObjects();
314
+ return;
315
+ }
316
+ const t = this.cursor, e = this.wasdKeys;
317
+ (t.left.isDown || e.A.isDown) && (t.up.isDown || e.W.isDown) ? this.gridEngine.move(this.playerId, "up-left") : (t.left.isDown || e.A.isDown) && (t.down.isDown || e.S.isDown) ? this.gridEngine.move(this.playerId, "down-left") : (t.right.isDown || e.D.isDown) && (t.up.isDown || e.W.isDown) ? this.gridEngine.move(this.playerId, "up-right") : (t.right.isDown || e.D.isDown) && (t.down.isDown || e.S.isDown) ? this.gridEngine.move(this.playerId, "down-right") : t.left.isDown || e.A.isDown ? this.gridEngine.move(this.playerId, "left") : t.right.isDown || e.D.isDown ? this.gridEngine.move(this.playerId, "right") : t.up.isDown || e.W.isDown ? this.gridEngine.move(this.playerId, "up") : (t.down.isDown || e.S.isDown) && this.gridEngine.move(this.playerId, "down"), this.checkForNearbyObjects();
318
+ }
319
+ }
320
+ function mt(s, t, e = 16739179) {
321
+ t.setTint(16777215).setTintMode(x.TintModes.FILL), s.time.delayedCall(60, () => t.setTint(e)), s.time.delayedCall(180, () => {
322
+ t.clearTint(), t.setTintMode(x.TintModes.MULTIPLY);
323
+ });
324
+ }
325
+ function yt(s, t, e, i, n, r) {
326
+ const a = s.add.text(t, e, i, {
327
+ fontFamily: "monospace",
328
+ fontSize: "14px",
329
+ color: n,
330
+ stroke: "#000000",
331
+ strokeThickness: 3
332
+ }).setOrigin(0.5, 1).setDepth(r);
333
+ return s.tweens.add({
334
+ targets: a,
335
+ y: e - 28,
336
+ alpha: 0,
337
+ duration: 900,
338
+ ease: "Cubic.easeOut",
339
+ onComplete: () => a.destroy()
340
+ }), a;
341
+ }
342
+ function ft(s, t, e, i, n, r = 26) {
343
+ const a = Math.max(0, Math.min(1, i / n));
344
+ s.clear(), s.fillStyle(0, 0.6), s.fillRect(t - r / 2, e, r, 4), s.fillStyle(a > 0.5 ? 4906624 : a > 0.25 ? 16498468 : 16281969, 1), s.fillRect(t - r / 2 + 0.5, e + 0.5, (r - 1) * a, 3);
345
+ }
346
+ function xt(s, { min: t = 0.6, max: e = 2.2, step: i = 0.2 } = {}) {
347
+ const n = (r) => {
348
+ const a = s.cameras.main;
349
+ a.setZoom(x.Math.Clamp(a.zoom + r, t, e));
350
+ };
351
+ s.input.keyboard?.on("keydown-PLUS", () => n(i)), s.input.keyboard?.on("keydown-MINUS", () => n(-i)), s.input.on(
352
+ "wheel",
353
+ (r, a, o, h) => n(h > 0 ? -i * 0.75 : i * 0.75)
354
+ );
355
+ }
356
+ function bt(s, t, e, i = 64) {
357
+ if (s.x === t.x && s.y === t.y || e(t.x, t.y))
358
+ return [];
359
+ const n = (d, m) => `${d},${m}`, r = /* @__PURE__ */ new Map();
360
+ r.set(n(s.x, s.y), null);
361
+ const a = [s], o = [
362
+ [0, -1],
363
+ [0, 1],
364
+ [-1, 0],
365
+ [1, 0]
366
+ ], h = (i * 2 + 1) ** 2;
367
+ let c = 0, p = !1;
368
+ for (; a.length; ) {
369
+ if (++c > h) return [];
370
+ const d = a.shift();
371
+ if (d.x === t.x && d.y === t.y) {
372
+ p = !0;
373
+ break;
374
+ }
375
+ for (const [m, k] of o) {
376
+ const y = d.x + m, w = d.y + k, f = n(y, w);
377
+ r.has(f) || e(y, w) || (r.set(f, n(d.x, d.y)), a.push({ x: y, y: w }));
378
+ }
379
+ }
380
+ if (!p) return [];
381
+ const l = [];
382
+ let u = n(t.x, t.y);
383
+ for (; u && u !== n(s.x, s.y); ) {
384
+ const [d, m] = u.split(",").map(Number);
385
+ if (l.push({ x: d, y: m }), u = r.get(u) ?? null, l.length > i) return [];
386
+ }
387
+ return l.reverse(), l;
388
+ }
389
+ function wt(s) {
390
+ return +s[s.length - 1];
391
+ }
392
+ function Mt(s) {
393
+ return s.startsWith("monster_bird_") && !s.startsWith("monster_bird_shadow");
394
+ }
395
+ function C(s, t, e, i, n) {
396
+ const r = [];
397
+ for (let a = 0; a < 10; a++) {
398
+ const o = s.add.sprite(0, 0, "monster_bird");
399
+ o.setCrop(t, e, i, n), o.scale = 3, r.push(o);
400
+ }
401
+ return r;
402
+ }
403
+ function gt(s) {
404
+ return C(s, 0, 0, 61, 47);
405
+ }
406
+ function Et(s) {
407
+ return C(s, 22, 47, 16, 10);
408
+ }
409
+ function kt(s) {
410
+ s.anims.create({
411
+ key: "bird",
412
+ frames: s.anims.generateFrameNumbers("monster_bird", {
413
+ start: 0,
414
+ end: 2
415
+ }),
416
+ frameRate: 10,
417
+ repeat: -1,
418
+ yoyo: !0
419
+ });
420
+ }
421
+ const St = ({
422
+ children: s,
423
+ className: t,
424
+ ...e
425
+ }) => /* @__PURE__ */ I(
426
+ q,
427
+ {
428
+ camera: { position: [0, 0, 5] },
429
+ ...e,
430
+ className: t,
431
+ children: [
432
+ /* @__PURE__ */ D("ambientLight", { intensity: 1.5 }),
433
+ s
434
+ ]
435
+ }
436
+ );
437
+ function At(s) {
438
+ const t = g(s);
439
+ t.current = s, F((e, i) => {
440
+ t.current(i, e.clock.elapsedTime);
441
+ });
442
+ }
443
+ function* It(s, t, e, i, n, r) {
444
+ const a = r * r;
445
+ for (const o of P(s, t)) {
446
+ const h = e.x[o] - i, c = e.y[o] - n;
447
+ h * h + c * c <= a && (yield o);
448
+ }
449
+ }
450
+ function Dt(s, t, e, i, n, r) {
451
+ const a = r * r;
452
+ let o = -1, h = a;
453
+ for (const c of P(s, t)) {
454
+ const p = e.x[c] - i, l = e.y[c] - n, u = p * p + l * l;
455
+ u <= h && (h = u, o = c);
456
+ }
457
+ return o >= 0 ? o : null;
458
+ }
459
+ class Rt {
460
+ map = /* @__PURE__ */ new Map();
461
+ set(t, e) {
462
+ this.map.set(t, e);
463
+ }
464
+ get(t) {
465
+ return this.map.get(t);
466
+ }
467
+ delete(t) {
468
+ const e = this.map.get(t);
469
+ return this.map.delete(t), e;
470
+ }
471
+ has(t) {
472
+ return this.map.has(t);
473
+ }
474
+ values() {
475
+ return this.map.values();
476
+ }
477
+ entries() {
478
+ return this.map.entries();
479
+ }
480
+ clear() {
481
+ this.map.clear();
482
+ }
483
+ get size() {
484
+ return this.map.size;
485
+ }
486
+ }
487
+ const H = 1e3, z = 15e3;
488
+ function B(s, t, e) {
489
+ const i = t.trim();
490
+ return e ? s === 1e3 ? "disconnected" : i || `server dropped connection (code ${s})` : s === 1006 ? "cannot reach server — down or rejected" : i || `connection refused (code ${s})`;
491
+ }
492
+ class _ {
493
+ ws = null;
494
+ closed = !1;
495
+ attempts = 0;
496
+ everOpened = !1;
497
+ timer = 0;
498
+ state = { status: "connecting", attempts: 0 };
499
+ opts;
500
+ handlers;
501
+ constructor(t, e) {
502
+ this.opts = {
503
+ maxAttempts: 0,
504
+ baseDelayMs: H,
505
+ maxDelayMs: z,
506
+ closeReason: B,
507
+ ...t
508
+ }, this.handlers = e;
509
+ }
510
+ getState() {
511
+ return this.state;
512
+ }
513
+ isOpen() {
514
+ return this.ws?.readyState === WebSocket.OPEN;
515
+ }
516
+ send(t) {
517
+ this.isOpen() && this.ws.send(t);
518
+ }
519
+ connect() {
520
+ if (this.ws || this.closed) return;
521
+ this.everOpened = !1, this.setState({
522
+ status: this.attempts === 0 ? "connecting" : "reconnecting",
523
+ attempts: this.attempts,
524
+ reason: this.state.reason
525
+ });
526
+ const t = typeof this.opts.url == "function" ? this.opts.url() : this.opts.url, e = new WebSocket(t);
527
+ this.ws = e, e.addEventListener("open", () => {
528
+ this.attempts = 0, this.everOpened = !0, this.setState({ status: "connected", attempts: 0 }), this.handlers.onOpen?.(e);
529
+ }), e.addEventListener(
530
+ "message",
531
+ (i) => this.handlers.onMessage?.(i)
532
+ ), e.addEventListener("close", (i) => {
533
+ this.ws = null;
534
+ const n = this.opts.closeReason(
535
+ i.code,
536
+ i.reason,
537
+ this.everOpened
538
+ );
539
+ if (this.closed) {
540
+ this.setState({ status: "closed", attempts: this.attempts });
541
+ return;
542
+ }
543
+ if (this.opts.shouldReconnect && !this.opts.shouldReconnect()) {
544
+ this.setState({
545
+ status: "closed",
546
+ attempts: this.attempts,
547
+ reason: n
548
+ });
549
+ return;
550
+ }
551
+ if (this.attempts += 1, this.opts.maxAttempts > 0 && this.attempts > this.opts.maxAttempts) {
552
+ this.setState({
553
+ status: "closed",
554
+ attempts: this.attempts,
555
+ reason: n
556
+ });
557
+ return;
558
+ }
559
+ const r = Math.min(
560
+ this.opts.baseDelayMs * 2 ** (this.attempts - 1),
561
+ this.opts.maxDelayMs
562
+ );
563
+ this.setState({
564
+ status: "reconnecting",
565
+ attempts: this.attempts,
566
+ reason: n,
567
+ nextRetryMs: r
568
+ }), this.timer = window.setTimeout(() => this.connect(), r);
569
+ });
570
+ }
571
+ close() {
572
+ this.closed = !0, window.clearTimeout(this.timer), this.ws?.close(), this.ws = null, this.setState({ status: "closed", attempts: this.attempts });
573
+ }
574
+ setState(t) {
575
+ this.state = t, this.handlers.onState?.(t);
576
+ }
577
+ }
578
+ const J = 9, Pt = 1, Tt = 2, V = 1, $ = 2, G = 3, Z = 5, Y = 6, X = 7, Ct = 8, _t = 9, Q = 10, tt = 11, vt = 0, Ot = 1, Kt = 2, et = ["spades", "hearts", "diamonds", "clubs"], st = [
579
+ "A",
580
+ "2",
581
+ "3",
582
+ "4",
583
+ "5",
584
+ "6",
585
+ "7",
586
+ "8",
587
+ "9",
588
+ "10",
589
+ "J",
590
+ "Q",
591
+ "K"
592
+ ], it = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10];
593
+ function jt(s) {
594
+ const t = s & 15, e = s >> 4 & 3;
595
+ return {
596
+ suit: et[e],
597
+ rank: st[t],
598
+ points: it[t],
599
+ red: e === 1 || e === 2
600
+ };
601
+ }
602
+ const Lt = 65535;
603
+ function b(s) {
604
+ try {
605
+ return JSON.parse(
606
+ new TextDecoder().decode(Uint8Array.from(s))
607
+ );
608
+ } catch {
609
+ return null;
610
+ }
611
+ }
612
+ function nt(s, t) {
613
+ return {
614
+ JoinMatch: {
615
+ protocol: J,
616
+ jwt: s,
617
+ kbve_username: t
618
+ }
619
+ };
620
+ }
621
+ function rt(s, t) {
622
+ return { Frame: { client_tick: s, inputs: t } };
623
+ }
624
+ class Nt {
625
+ clientTick = 0;
626
+ terminal = !1;
627
+ bus = new S();
628
+ opts;
629
+ socket;
630
+ constructor(t) {
631
+ this.opts = t, this.socket = new _(
632
+ {
633
+ url: t.url,
634
+ maxAttempts: t.maxReconnects ?? 3,
635
+ baseDelayMs: 1500,
636
+ shouldReconnect: () => !this.terminal
637
+ },
638
+ {
639
+ onOpen: () => {
640
+ this.send(nt(this.opts.jwt, this.opts.kbveUsername)), this.bus.emit("open", void 0);
641
+ },
642
+ onMessage: (e) => this.handleMessage(e),
643
+ onState: (e) => {
644
+ this.bus.emit("state", e), e.status === "closed" && this.bus.emit("close", void 0);
645
+ }
646
+ }
647
+ );
648
+ }
649
+ on(t, e) {
650
+ return this.bus.on(t, e);
651
+ }
652
+ getState() {
653
+ return this.socket.getState();
654
+ }
655
+ connect() {
656
+ this.socket.connect();
657
+ }
658
+ /** Stop reconnecting — the server turned us away for good. */
659
+ markTerminal() {
660
+ this.terminal = !0;
661
+ }
662
+ handleMessage(t) {
663
+ let e;
664
+ try {
665
+ e = JSON.parse(
666
+ typeof t.data == "string" ? t.data : String(t.data)
667
+ );
668
+ } catch {
669
+ return;
670
+ }
671
+ "Welcome" in e ? this.bus.emit("welcome", e.Welcome) : "Snapshot" in e ? this.bus.emit("snapshot", e.Snapshot) : "Ephemeral" in e ? this.handleEphemeral(e.Ephemeral) : "Reject" in e && (this.terminal = !0, this.bus.emit("reject", e.Reject.reason));
672
+ }
673
+ handleEphemeral(t) {
674
+ if (this.bus.emit("ephemeral", t), t.kind === V) {
675
+ const e = b(t.payload);
676
+ e && this.bus.emit("inventory", e);
677
+ } else if (t.kind === $) {
678
+ const e = b(t.payload);
679
+ e && this.bus.emit("combat", e);
680
+ } else if (t.kind === G) {
681
+ const e = b(t.payload);
682
+ e && this.bus.emit("pickup", e);
683
+ } else if (t.kind === Z) {
684
+ const e = b(t.payload);
685
+ e && this.bus.emit("itemUsed", e);
686
+ } else if (t.kind === Y) {
687
+ const e = b(t.payload);
688
+ e && this.bus.emit("equipped", e);
689
+ } else if (t.kind === X) {
690
+ const e = b(t.payload);
691
+ e && this.bus.emit("stats", e);
692
+ } else if (t.kind === Q) {
693
+ const e = b(t.payload);
694
+ e && this.bus.emit("shop", e);
695
+ } else if (t.kind === tt) {
696
+ const e = b(
697
+ t.payload
698
+ );
699
+ e && this.bus.emit("blackjackState", e);
700
+ }
701
+ }
702
+ send(t) {
703
+ this.socket.send(JSON.stringify(t));
704
+ }
705
+ sendInputs(t) {
706
+ !this.socket.isOpen() || t.length === 0 || (this.clientTick += 1, this.send(rt(this.clientTick, t)));
707
+ }
708
+ step(t) {
709
+ this.sendInputs([{ Step: { dir: t } }]);
710
+ }
711
+ moveTo(t) {
712
+ this.sendInputs([{ MoveTo: { tile: t } }]);
713
+ }
714
+ action(t, e) {
715
+ this.sendInputs([{ Action: { id: t, target: e } }]);
716
+ }
717
+ heartbeat() {
718
+ this.sendInputs([{ Heartbeat: { client_tick: this.clientTick } }]);
719
+ }
720
+ useItem(t) {
721
+ this.sendInputs([{ UseItem: { item_ref: t } }]);
722
+ }
723
+ equipItem(t) {
724
+ this.sendInputs([{ EquipItem: { item_ref: t } }]);
725
+ }
726
+ buyItem(t, e, i) {
727
+ this.sendInputs([{ BuyItem: { npc: t, item_ref: e, qty: i } }]);
728
+ }
729
+ sellItem(t, e, i) {
730
+ this.sendInputs([{ SellItem: { npc: t, item_ref: e, qty: i } }]);
731
+ }
732
+ joinTable(t) {
733
+ this.sendInputs([{ JoinTable: { table_ref: t } }]);
734
+ }
735
+ leaveTable() {
736
+ this.sendInputs(["LeaveTable"]);
737
+ }
738
+ placeBet(t) {
739
+ this.sendInputs([{ PlaceBet: { amount: t } }]);
740
+ }
741
+ bjAction(t) {
742
+ this.sendInputs([{ BjAction: { kind: t } }]);
743
+ }
744
+ face(t) {
745
+ this.sendInputs([{ Face: { facing: t } }]);
746
+ }
747
+ close() {
748
+ this.sendInputs(["Leave"]), this.socket.close();
749
+ }
750
+ }
751
+ const A = "chat";
752
+ class qt {
753
+ bus = new S();
754
+ opts;
755
+ socket;
756
+ constructor(t) {
757
+ this.opts = t, this.socket = new _(
758
+ {
759
+ url: () => {
760
+ const e = this.opts.url.includes("?") ? "&" : "?";
761
+ return `${this.opts.url}${e}game=${encodeURIComponent(
762
+ this.opts.game
763
+ )}&token=${encodeURIComponent(this.opts.jwt)}`;
764
+ },
765
+ shouldReconnect: () => !!this.opts.jwt
766
+ },
767
+ {
768
+ onOpen: () => this.bus.emit("open", void 0),
769
+ onMessage: (e) => this.handleMessage(e),
770
+ onState: (e) => {
771
+ this.bus.emit("status", e), e.status === "closed" && this.bus.emit("close", void 0);
772
+ }
773
+ }
774
+ );
775
+ }
776
+ on(t, e) {
777
+ return this.bus.on(t, e);
778
+ }
779
+ getState() {
780
+ return this.socket.getState();
781
+ }
782
+ connect() {
783
+ if (!this.opts.jwt) {
784
+ this.bus.emit("status", {
785
+ status: "closed",
786
+ attempts: 0,
787
+ reason: "missing auth token"
788
+ });
789
+ return;
790
+ }
791
+ this.socket.connect();
792
+ }
793
+ handleMessage(t) {
794
+ let e;
795
+ try {
796
+ e = JSON.parse(
797
+ typeof t.data == "string" ? t.data : String(t.data)
798
+ );
799
+ } catch {
800
+ return;
801
+ }
802
+ e.kind === A && (e.channel && e.channel !== this.opts.channel || this.bus.emit("message", { from: e.sender, text: e.content }));
803
+ }
804
+ send(t) {
805
+ const e = t.trim().slice(0, 200);
806
+ if (!e || !this.socket.isOpen()) return;
807
+ const i = {
808
+ kind: A,
809
+ sender: "",
810
+ platform: "",
811
+ channel: this.opts.channel,
812
+ content: e
813
+ };
814
+ this.socket.send(JSON.stringify(i));
815
+ }
816
+ close() {
817
+ this.socket.close();
818
+ }
819
+ }
820
+ export {
821
+ Pt as ACTION_ATTACK,
822
+ Tt as ACTION_PICKUP,
823
+ tt as EPHEMERAL_BLACKJACK,
824
+ $ as EPHEMERAL_COMBAT,
825
+ Y as EPHEMERAL_EQUIPPED,
826
+ V as EPHEMERAL_INVENTORY,
827
+ Z as EPHEMERAL_ITEM_USED,
828
+ G as EPHEMERAL_PICKUP,
829
+ Q as EPHEMERAL_SHOP,
830
+ X as EPHEMERAL_STATS,
831
+ Ct as EPHEMERAL_STATUS,
832
+ _t as EPHEMERAL_TRADE,
833
+ Nt as GameClient,
834
+ Kt as KIND_CAT_ITEM,
835
+ Ot as KIND_CAT_NPC,
836
+ vt as KIND_CAT_PLAYER,
837
+ S as LaserEventBus,
838
+ Lt as OWNER_NONE,
839
+ J as PROTOCOL_VERSION,
840
+ T as PhaserContext,
841
+ lt as PhaserGame,
842
+ pt as PlayerController,
843
+ M as Quadtree,
844
+ Ht as RAPIER,
845
+ qt as RealmChatClient,
846
+ _ as ReconnectingSocket,
847
+ Rt as SideMap,
848
+ St as Stage,
849
+ W as VirtualJoystick,
850
+ xt as attachCameraZoom,
851
+ kt as createBirdAnimation,
852
+ gt as createBirdSprites,
853
+ zt as createRapierPhysics,
854
+ Et as createShadowSprites,
855
+ jt as decodeCard,
856
+ b as decodeEphemeralPayload,
857
+ B as defaultCloseReason,
858
+ ft as drawHealthBar,
859
+ bt as findTilePath,
860
+ mt as flashEntity,
861
+ yt as floatingText,
862
+ wt as getBirdNum,
863
+ rt as inputFrame,
864
+ Mt as isBird,
865
+ nt as joinFrame,
866
+ E as laserEvents,
867
+ Dt as nearestInRange,
868
+ It as queryInRange,
869
+ At as useGameLoop,
870
+ dt as usePhaserEvent,
871
+ U as usePhaserGame
872
+ };