@kbve/laser 0.1.2 → 0.1.4

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