@kbve/laser 0.1.0 → 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 +839 -361
  2. package/package.json +2 -2
package/laser.es.js CHANGED
@@ -1,376 +1,854 @@
1
- import { jsxs as m, jsx as b } from "react/jsx-runtime";
2
- import { createContext as D, useContext as P, forwardRef as S, useRef as p, useState as k, useImperativeHandle as E, useEffect as w, useMemo as I } from "react";
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";
3
2
  import c from "phaser";
4
- import { Canvas as C, useFrame as K } from "@react-three/fiber";
5
- import { addComponent as X, addEntity as Y, createWorld as N, hasComponent as Q, query as tt, removeEntity as et } from "bitecs";
6
- import { RAPIER as it, createRapierPhysics as rt } from "@phaserjs/rapier-connector";
7
- class A {
8
- handlers = /* @__PURE__ */ new Map();
9
- on(t, e) {
10
- let s = this.handlers.get(t);
11
- return s || (s = /* @__PURE__ */ new Set(), this.handlers.set(t, s)), s.add(e), () => {
12
- s.delete(e);
13
- };
14
- }
15
- off(t, e) {
16
- this.handlers.get(t)?.delete(e);
17
- }
18
- emit(t, e) {
19
- this.handlers.get(t)?.forEach((s) => {
20
- s(e);
21
- });
22
- }
23
- clear() {
24
- this.handlers.clear();
25
- }
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";
7
+ export * from "bitecs";
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;
26
104
  }
27
- const f = new A();
28
- class d {
29
- bounds;
30
- capacity;
31
- points;
32
- divided;
33
- cache;
34
- northeast;
35
- northwest;
36
- southeast;
37
- southwest;
38
- constructor(t, e = 4) {
39
- this.bounds = t, this.capacity = e, this.points = [], this.divided = !1, this.cache = /* @__PURE__ */ new Map();
40
- }
41
- subdivide() {
42
- const { xMin: t, yMin: e, xMax: s, yMax: i } = this.bounds, n = (s - t) / 2, o = (i - e) / 2, a = t, h = e;
43
- this.northeast = new d(
44
- { xMin: a + n, xMax: a + 2 * n, yMin: e, yMax: h + o },
45
- this.capacity
46
- ), this.northwest = new d(
47
- { xMin: t, xMax: a + n, yMin: e, yMax: h + o },
48
- this.capacity
49
- ), this.southeast = new d(
50
- { xMin: a + n, xMax: a + 2 * n, yMin: h + o, yMax: h + 2 * o },
51
- this.capacity
52
- ), this.southwest = new d(
53
- { xMin: t, xMax: a + n, yMin: h + o, yMax: h + 2 * o },
54
- this.capacity
55
- ), this.divided = !0;
56
- }
57
- insert(t) {
58
- 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;
59
- }
60
- contains(t) {
61
- const { xMin: e, yMin: s, xMax: i, yMax: n } = this.bounds;
62
- return t.xMin >= e && t.xMax <= i && t.yMin >= s && t.yMax <= n;
63
- }
64
- queryRange(t, e = []) {
65
- if (!this.intersects(t))
66
- return e;
67
- for (const s of this.points)
68
- this.isWithinBounds(s.bounds, t) && e.push(s);
69
- return this.divided && (this.northwest?.queryRange(t, e), this.northeast?.queryRange(t, e), this.southwest?.queryRange(t, e), this.southeast?.queryRange(t, e)), e;
70
- }
71
- query(t, e = []) {
72
- const s = `${t.x},${t.y}`, i = this.cache.get(s);
73
- if (i)
74
- return i;
75
- if (!this.intersects({
76
- xMin: t.x,
77
- xMax: t.x,
78
- yMin: t.y,
79
- yMax: t.y
80
- }))
81
- return e;
82
- for (const n of this.points)
83
- this.isWithinRange(t, n.bounds) && e.push(n);
84
- 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(s, e), e;
85
- }
86
- intersects(t) {
87
- const { xMin: e, yMin: s, xMax: i, yMax: n } = this.bounds;
88
- return !(t.xMin > i || t.xMax < e || t.yMin > n || t.yMax < s);
89
- }
90
- isWithinBounds(t, e) {
91
- return t.xMax >= e.xMin && t.xMin <= e.xMax && t.yMax >= e.yMin && t.yMin <= e.yMax;
92
- }
93
- isWithinRange(t, e) {
94
- return t.x >= e.xMin && t.x <= e.xMax && t.y >= e.yMin && t.y <= e.yMax;
95
- }
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
+ ]);
96
190
  }
97
- const g = D(null);
98
- function R() {
99
- const r = P(g);
100
- if (!r)
101
- throw new Error(
102
- "usePhaserGame must be used within a <PhaserGame> component"
103
- );
104
- return r;
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
+ });
313
+ }
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;
330
+ }
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);
334
+ }
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));
341
+ }
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;
379
+ }
380
+ //#endregion
381
+ //#region packages/npm/laser/src/lib/phaser/monsters/bird.ts
382
+ function re(e) {
383
+ return +e[e.length - 1];
384
+ }
385
+ function ie(e) {
386
+ return e.startsWith("monster_bird_") && !e.startsWith("monster_bird_shadow");
387
+ }
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;
395
+ }
396
+ function O(e) {
397
+ return D(e, 0, 0, 61, 47);
398
+ }
399
+ function k(e) {
400
+ return D(e, 22, 47, 16, 10);
401
+ }
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
+ });
413
+ }
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
+ });
105
433
  }
106
- const z = S(
107
- function({ config: t, onReady: e, onDestroy: s, className: i, style: n, children: o }, a) {
108
- const h = p(null), l = p(null), [y, x] = k("idle");
109
- E(
110
- a,
111
- () => ({
112
- game: l.current,
113
- status: y
114
- }),
115
- [y]
116
- ), w(() => {
117
- if (!h.current) return;
118
- x("booting");
119
- const u = new c.Game({
120
- type: c.AUTO,
121
- width: t.width ?? 800,
122
- height: t.height ?? 600,
123
- parent: h.current,
124
- scene: t.scenes,
125
- physics: t.physics,
126
- plugins: t.plugins,
127
- scale: t.scale,
128
- backgroundColor: t.backgroundColor,
129
- transparent: t.transparent
130
- });
131
- return l.current = u, u.events.once("ready", () => {
132
- x("running"), f.emit("game:ready", { game: u }), e?.(u);
133
- }), () => {
134
- x("destroyed"), f.emit("game:destroy", void 0), s?.(), u.destroy(!0), l.current = null;
135
- };
136
- }, [t, e, s]);
137
- const v = I(
138
- () => ({ game: l.current, status: y }),
139
- [y]
140
- );
141
- return /* @__PURE__ */ m(g.Provider, { value: v, children: [
142
- /* @__PURE__ */ b("div", { ref: h, className: i, style: n }),
143
- o
144
- ] });
145
- }
146
- );
147
- function T(r, t, e) {
148
- const { game: s } = R(), i = p(t);
149
- i.current = t, w(() => {
150
- if (!s) return;
151
- const n = (...o) => i.current(...o);
152
- if (e) {
153
- const o = s.scene.getScene(e);
154
- if (o)
155
- return o.events.on(r, n), () => {
156
- o.events.off(r, n);
157
- };
158
- } else
159
- return s.events.on(r, n), () => {
160
- s.events.off(r, n);
161
- };
162
- }, [s, r, e]);
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
+ }
163
442
  }
164
- class j {
165
- scene;
166
- base;
167
- thumb;
168
- radius;
169
- deadZone;
170
- _direction = null;
171
- _isActive = !1;
172
- fixed;
173
- activePointer = null;
174
- constructor(t, e) {
175
- this.scene = t, this.radius = e?.radius ?? 60, this.deadZone = e?.deadZone ?? 0.25, this.fixed = e?.fixed ?? !0;
176
- const s = e?.x ?? 120, i = e?.y ?? t.scale.height - 120;
177
- this.base = t.add.circle(
178
- s,
179
- i,
180
- this.radius,
181
- e?.baseColor ?? 8947848,
182
- e?.baseAlpha ?? 0.35
183
- ).setDepth(100).setScrollFactor(0), this.thumb = t.add.circle(
184
- s,
185
- i,
186
- this.radius * 0.4,
187
- e?.thumbColor ?? 16777215,
188
- e?.thumbAlpha ?? 0.5
189
- ).setDepth(101).setScrollFactor(0), this.setupInput();
190
- }
191
- setupInput() {
192
- this.scene.input.on("pointerdown", (t) => {
193
- if (this.activePointer) return;
194
- const e = t.x - this.base.x, s = t.y - this.base.y, i = Math.sqrt(e * e + s * s);
195
- this.fixed && i > 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);
196
- }), this.scene.input.on("pointermove", (t) => {
197
- t === this.activePointer && this.updateThumb(t.x, t.y);
198
- }), this.scene.input.on("pointerup", (t) => {
199
- t === this.activePointer && this.resetThumb();
200
- });
201
- }
202
- updateThumb(t, e) {
203
- const s = t - this.base.x, i = e - this.base.y, n = Math.sqrt(s * s + i * i), o = Math.min(n, this.radius), a = Math.atan2(i, s);
204
- if (this.thumb.setPosition(
205
- this.base.x + Math.cos(a) * o,
206
- this.base.y + Math.sin(a) * o
207
- ), o / this.radius < this.deadZone) {
208
- this._direction = null;
209
- return;
210
- }
211
- this._direction = this.angleToDirection(a);
212
- }
213
- angleToDirection(t) {
214
- let e = t * 180 / Math.PI;
215
- 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";
216
- }
217
- resetThumb() {
218
- this.thumb.setPosition(this.base.x, this.base.y), this._direction = null, this._isActive = !1, this.activePointer = null;
219
- }
220
- get direction() {
221
- return this._direction;
222
- }
223
- get isActive() {
224
- return this._isActive;
225
- }
226
- setVisible(t) {
227
- return this.base.setVisible(t), this.thumb.setVisible(t), this;
228
- }
229
- destroy() {
230
- this.base.destroy(), this.thumb.destroy();
231
- }
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;
232
450
  }
233
- class V {
234
- scene;
235
- gridEngine;
236
- quadtree;
237
- cursor;
238
- wasdKeys;
239
- tooltip;
240
- tileSize;
241
- playerId;
242
- joystick = null;
243
- constructor(t, e, s, i) {
244
- if (this.scene = t, this.gridEngine = e, this.quadtree = s, this.tileSize = i?.tileSize ?? 48, this.playerId = i?.playerId ?? "player", this.cursor = this.scene.input.keyboard?.createCursorKeys(), this.initializeWASDKeys(), this.tooltip = this.scene.add.text(0, 0, "Press [F]", {
245
- font: "16px Arial",
246
- backgroundColor: "#000000"
247
- }).setDepth(4).setPadding(3, 2, 2, 3).setVisible(!1), i?.joystick) {
248
- const n = typeof i.joystick == "object" ? i.joystick : void 0;
249
- this.joystick = new j(t, n);
250
- }
251
- }
252
- initializeWASDKeys() {
253
- const t = this.scene.input.keyboard;
254
- t && (this.wasdKeys = {
255
- W: t.addKey(c.Input.Keyboard.KeyCodes.W),
256
- A: t.addKey(c.Input.Keyboard.KeyCodes.A),
257
- S: t.addKey(c.Input.Keyboard.KeyCodes.S),
258
- D: t.addKey(c.Input.Keyboard.KeyCodes.D)
259
- });
260
- }
261
- checkForNearbyObjects() {
262
- const t = this.gridEngine.getPosition(this.playerId), e = t.x * this.tileSize, s = t.y * this.tileSize, i = this.quadtree.query(t);
263
- i.length > 0 ? (this.tooltip.setPosition(e, s - 60).setVisible(!0), f.emit("player:nearby", {
264
- position: t,
265
- ranges: i
266
- })) : this.tooltip.setVisible(!1);
267
- }
268
- getPlayerPosition() {
269
- return this.gridEngine.getPosition(this.playerId);
270
- }
271
- handleMovement() {
272
- if (this.scene.input.keyboard?.addKey("F").isDown) {
273
- const s = this.gridEngine.getPosition(
274
- this.playerId
275
- ), i = this.quadtree.query(s);
276
- if (i.length > 0) {
277
- f.emit("player:interact", {
278
- position: s,
279
- ranges: i
280
- });
281
- for (const n of i)
282
- n.action();
283
- }
284
- }
285
- if (this.joystick?.isActive && this.joystick.direction) {
286
- this.gridEngine.move(this.playerId, this.joystick.direction), this.checkForNearbyObjects();
287
- return;
288
- }
289
- if (!this.cursor) {
290
- this.checkForNearbyObjects();
291
- return;
292
- }
293
- const t = this.cursor, e = this.wasdKeys;
294
- (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();
295
- }
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})`;
296
482
  }
297
- function G(r) {
298
- return +r[r.length - 1];
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
+ };
299
612
  }
300
- function O(r) {
301
- return r.startsWith("monster_bird_") && !r.startsWith("monster_bird_shadow");
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;
302
616
  }
303
- function M(r, t, e, s, i) {
304
- const n = [];
305
- for (let o = 0; o < 10; o++) {
306
- const a = r.add.sprite(0, 0, "monster_bird");
307
- a.setCrop(t, e, s, i), a.scale = 3, n.push(a);
308
- }
309
- return n;
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;
310
627
  }
311
- function Z(r) {
312
- return M(r, 0, 0, 61, 47);
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;
313
633
  }
314
- function L(r) {
315
- return M(r, 22, 47, 16, 10);
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
+ }
316
641
  }
317
- function B(r) {
318
- r.anims.create({
319
- key: "bird",
320
- frames: r.anims.generateFrameNumbers("monster_bird", {
321
- start: 0,
322
- end: 2
323
- }),
324
- frameRate: 10,
325
- repeat: -1,
326
- yoyo: !0
327
- });
642
+ function Q(e, t) {
643
+ return { JoinMatch: {
644
+ protocol: 10,
645
+ jwt: e,
646
+ kbve_username: t
647
+ } };
328
648
  }
329
- const $ = ({
330
- children: r,
331
- className: t,
332
- ...e
333
- }) => /* @__PURE__ */ m(
334
- C,
335
- {
336
- camera: { position: [0, 0, 5] },
337
- ...e,
338
- className: t,
339
- children: [
340
- /* @__PURE__ */ b("ambientLight", { intensity: 1.5 }),
341
- r
342
- ]
343
- }
344
- );
345
- function H(r) {
346
- const t = p(r);
347
- t.current = r, K((e, s) => {
348
- t.current(s, e.clock.elapsedTime);
349
- });
649
+ function $(e, t) {
650
+ return { Frame: {
651
+ client_tick: e,
652
+ inputs: t
653
+ } };
350
654
  }
351
- export {
352
- A as LaserEventBus,
353
- g as PhaserContext,
354
- z as PhaserGame,
355
- V as PlayerController,
356
- d as Quadtree,
357
- it as RAPIER,
358
- $ as Stage,
359
- j as VirtualJoystick,
360
- X as addComponent,
361
- Y as addEntity,
362
- B as createBirdAnimation,
363
- Z as createBirdSprites,
364
- rt as createRapierPhysics,
365
- L as createShadowSprites,
366
- N as createWorld,
367
- G as getBirdNum,
368
- Q as hasComponent,
369
- O as isBird,
370
- f as laserEvents,
371
- tt as query,
372
- et as removeEntity,
373
- H as useGameLoop,
374
- T as usePhaserEvent,
375
- R 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
+ }
376
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbve/laser",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "description": "Phaser + React Three Fiber integration layer for React 19",
5
5
  "keywords": [
6
6
  "phaser",
@@ -39,7 +39,7 @@
39
39
  "peerDependencies": {
40
40
  "react": ">=18.0.0",
41
41
  "react-dom": ">=18.0.0",
42
- "phaser": ">=3.80.0",
42
+ "phaser": ">=4.1.0",
43
43
  "three": ">=0.160.0",
44
44
  "@react-three/fiber": ">=9.0.0",
45
45
  "@react-three/drei": ">=10.0.0",