@minicode-dev/chat 0.1.12 → 0.1.14

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 (107) hide show
  1. package/CHANGELOG.md +112 -5
  2. package/README.md +401 -309
  3. package/assets/sounds/effects/avalanche.mp3 +0 -0
  4. package/assets/sounds/racing/car_boost.mp3 +0 -0
  5. package/assets/sounds/racing/car_boost.ogg +0 -0
  6. package/assets/sounds/racing/car_bump.mp3 +0 -0
  7. package/assets/sounds/racing/car_bump.ogg +0 -0
  8. package/assets/sounds/racing/car_drift_loop.mp3 +0 -0
  9. package/assets/sounds/racing/car_drift_loop.ogg +0 -0
  10. package/assets/sounds/racing/car_engine_loop.mp3 +0 -0
  11. package/assets/sounds/racing/car_engine_loop.ogg +0 -0
  12. package/assets/sounds/racing/car_engine_start.mp3 +0 -0
  13. package/assets/sounds/racing/car_engine_start.ogg +0 -0
  14. package/assets/sounds/racing/countdown_beep.mp3 +0 -0
  15. package/assets/sounds/racing/countdown_beep.ogg +0 -0
  16. package/assets/sounds/racing/countdown_go.mp3 +0 -0
  17. package/assets/sounds/racing/countdown_go.ogg +0 -0
  18. package/assets/sounds/racing/final_lap.mp3 +0 -0
  19. package/assets/sounds/racing/final_lap.ogg +0 -0
  20. package/assets/sounds/racing/finish_line.mp3 +0 -0
  21. package/assets/sounds/racing/finish_line.ogg +0 -0
  22. package/assets/sounds/racing/lap_complete.mp3 +0 -0
  23. package/assets/sounds/racing/lap_complete.ogg +0 -0
  24. package/assets/sounds/racing/music_circuit.mp3 +0 -0
  25. package/assets/sounds/racing/music_circuit.ogg +0 -0
  26. package/assets/sounds/racing/music_final_lap.mp3 +0 -0
  27. package/assets/sounds/racing/music_final_lap.ogg +0 -0
  28. package/assets/sounds/racing/race_defeat.mp3 +0 -0
  29. package/assets/sounds/racing/race_defeat.ogg +0 -0
  30. package/assets/sounds/racing/race_victory.mp3 +0 -0
  31. package/assets/sounds/racing/race_victory.ogg +0 -0
  32. package/assets/sounds/tanks/barrel_explode.mp3 +0 -0
  33. package/assets/sounds/tanks/barrel_explode.ogg +0 -0
  34. package/assets/sounds/tanks/crate_break.mp3 +0 -0
  35. package/assets/sounds/tanks/crate_break.ogg +0 -0
  36. package/assets/sounds/tanks/health_pickup.mp3 +0 -0
  37. package/assets/sounds/tanks/health_pickup.ogg +0 -0
  38. package/assets/sounds/tanks/last_life.mp3 +0 -0
  39. package/assets/sounds/tanks/last_life.ogg +0 -0
  40. package/assets/sounds/tanks/life_lost.mp3 +0 -0
  41. package/assets/sounds/tanks/life_lost.ogg +0 -0
  42. package/assets/sounds/tanks/respawn.mp3 +0 -0
  43. package/assets/sounds/tanks/respawn.ogg +0 -0
  44. package/assets/sounds/tanks/shield_end.mp3 +0 -0
  45. package/assets/sounds/tanks/shield_end.ogg +0 -0
  46. package/assets/sounds/tanks/shield_loop.mp3 +0 -0
  47. package/assets/sounds/tanks/shield_loop.ogg +0 -0
  48. package/assets/sounds/tanks/wall_hit.mp3 +0 -0
  49. package/assets/sounds/tanks/wall_hit.ogg +0 -0
  50. package/dist/chunks/{BattleshipGameCard-iRk8d4vR.js → BattleshipGameCard-B-B4r7lK.js} +146 -144
  51. package/dist/chunks/{BattleshipGameCard-iRk8d4vR.js.map → BattleshipGameCard-B-B4r7lK.js.map} +1 -1
  52. package/dist/chunks/{ChatContext-DjIEifGY.js → ChatContext-DQtKsR6Z.js} +2 -2
  53. package/dist/chunks/{ChatContext-DjIEifGY.js.map → ChatContext-DQtKsR6Z.js.map} +1 -1
  54. package/dist/chunks/RacingLiveGameCard-c1G7uoDI.js +1654 -0
  55. package/dist/chunks/RacingLiveGameCard-c1G7uoDI.js.map +1 -0
  56. package/dist/chunks/{TanksGameCard-B47ZQcSr.js → TanksGameCard-CvTaF7tu.js} +164 -162
  57. package/dist/chunks/{TanksGameCard-B47ZQcSr.js.map → TanksGameCard-CvTaF7tu.js.map} +1 -1
  58. package/dist/chunks/TanksLiveGameCard-COr9Oay5.js +1011 -0
  59. package/dist/chunks/TanksLiveGameCard-COr9Oay5.js.map +1 -0
  60. package/dist/chunks/avalancheScene3d-Z5QyZIid.js +1299 -0
  61. package/dist/chunks/avalancheScene3d-Z5QyZIid.js.map +1 -0
  62. package/dist/chunks/connect4Sounds-DmD-E9kX.js +235 -0
  63. package/dist/chunks/connect4Sounds-DmD-E9kX.js.map +1 -0
  64. package/dist/chunks/connectionStore-DwgIUl30.js +13 -0
  65. package/dist/chunks/connectionStore-DwgIUl30.js.map +1 -0
  66. package/dist/chunks/createLiveScene-CWBunxPi.js +367 -0
  67. package/dist/chunks/createLiveScene-CWBunxPi.js.map +1 -0
  68. package/dist/chunks/createRaceScene-C7Rw89kj.js +305 -0
  69. package/dist/chunks/createRaceScene-C7Rw89kj.js.map +1 -0
  70. package/dist/chunks/{createTankScene-CV7Brxmt.js → createTankScene-yhX6la27.js} +150 -147
  71. package/dist/chunks/{createTankScene-CV7Brxmt.js.map → createTankScene-yhX6la27.js.map} +1 -1
  72. package/dist/chunks/decor-CyyCnmct.js +418 -0
  73. package/dist/chunks/decor-CyyCnmct.js.map +1 -0
  74. package/dist/chunks/fx-1ZwzmPWj.js +458 -0
  75. package/dist/chunks/fx-1ZwzmPWj.js.map +1 -0
  76. package/dist/chunks/fx-UZwhOmdl.js +584 -0
  77. package/dist/chunks/fx-UZwhOmdl.js.map +1 -0
  78. package/dist/chunks/gameStatus-BChd29yI.js +62 -0
  79. package/dist/chunks/gameStatus-BChd29yI.js.map +1 -0
  80. package/dist/chunks/{connect4Sounds-Cv0q31VW.js → games-BvYTWgaR.js} +814 -951
  81. package/dist/chunks/games-BvYTWgaR.js.map +1 -0
  82. package/dist/chunks/rolldown-runtime-CGnMp29N.js +10 -0
  83. package/dist/chunks/tank-DjEQ4FXF.js +553 -0
  84. package/dist/chunks/tank-DjEQ4FXF.js.map +1 -0
  85. package/dist/chunks/tanks-live-BcKmrhnV.js +261 -0
  86. package/dist/chunks/tanks-live-BcKmrhnV.js.map +1 -0
  87. package/dist/chunks/{tanksSounds-CUNDIOal.js → tanksSounds-DwjfSp3W.js} +43 -11
  88. package/dist/chunks/tanksSounds-DwjfSp3W.js.map +1 -0
  89. package/dist/chunks/track-BcnnpnAm.js +259 -0
  90. package/dist/chunks/track-BcnnpnAm.js.map +1 -0
  91. package/dist/chunks/util-DwI9bfS7.js +57 -0
  92. package/dist/chunks/util-DwI9bfS7.js.map +1 -0
  93. package/dist/index.js +2176 -1592
  94. package/dist/index.js.map +1 -1
  95. package/dist/styles.css +1 -1
  96. package/index.d.ts +4 -2
  97. package/package.json +1 -1
  98. package/dist/chunks/TanksLiveGameCard-DGsnMD3j.js +0 -1225
  99. package/dist/chunks/TanksLiveGameCard-DGsnMD3j.js.map +0 -1
  100. package/dist/chunks/connect4Sounds-Cv0q31VW.js.map +0 -1
  101. package/dist/chunks/createLiveScene-BqI7qV4n.js +0 -364
  102. package/dist/chunks/createLiveScene-BqI7qV4n.js.map +0 -1
  103. package/dist/chunks/fx-BHsl4S_J.js +0 -1470
  104. package/dist/chunks/fx-BHsl4S_J.js.map +0 -1
  105. package/dist/chunks/gameStatus-Cu1Z8un9.js +0 -69
  106. package/dist/chunks/gameStatus-Cu1Z8un9.js.map +0 -1
  107. package/dist/chunks/tanksSounds-CUNDIOal.js.map +0 -1
@@ -1,11 +1,9 @@
1
- import { a as e, c as t, i as n, n as r, r as i, s as a, t as o } from "./board-DXKuIZ1I.js";
2
- import { useSyncExternalStore as s } from "react";
3
- import { createStore as c } from "zustand/vanilla";
4
- import { useStore as l } from "zustand";
5
- import { Volume2 as u, VolumeX as d } from "lucide-react";
6
- import { jsx as f, jsxs as p } from "react/jsx-runtime";
1
+ import { i as e, o as t, r as n, t as r } from "./track-BcnnpnAm.js";
2
+ import { a as i, c as a, i as o, n as s, r as c, s as l, t as u } from "./board-DXKuIZ1I.js";
3
+ import { createStore as d } from "zustand/vanilla";
4
+ import { useStore as f } from "zustand";
7
5
  // src/core/ids/randomUuid.js
8
- function m(e = globalThis.crypto) {
6
+ function p(e = globalThis.crypto) {
9
7
  if (typeof e?.randomUUID == "function") return e.randomUUID();
10
8
  let t = /* @__PURE__ */ new Uint8Array(16);
11
9
  if (typeof e?.getRandomValues == "function") e.getRandomValues(t);
@@ -15,18 +13,18 @@ function m(e = globalThis.crypto) {
15
13
  return `${n.slice(0, 8)}-${n.slice(8, 12)}-${n.slice(12, 16)}-${n.slice(16, 20)}-${n.slice(20)}`;
16
14
  }
17
15
  // src/games/tanks-live/session.js
18
- var h = (e) => typeof e == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e), g = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
19
- function _(e) {
16
+ var m = (e) => typeof e == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e), h = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
17
+ function g(e) {
20
18
  let t = e.data;
21
19
  switch (e.type) {
22
- case "game_invite": return g(t.opponent_id) && t.rules_version === 1 && (t.rematch_of === void 0 || h(t.rematch_of));
20
+ case "game_invite": return h(t.opponent_id) && t.rules_version === 1 && (t.rematch_of === void 0 || m(t.rematch_of));
23
21
  case "game_accept":
24
- case "game_decline": return h(t.invite_event_id);
22
+ case "game_decline": return m(t.invite_event_id);
25
23
  case "game_end": return t.reason === "closed";
26
24
  default: return !1;
27
25
  }
28
26
  }
29
- function v(e, t) {
27
+ function _(e, t) {
30
28
  return {
31
29
  ...e,
32
30
  game: "tanks_live",
@@ -40,7 +38,7 @@ function v(e, t) {
40
38
  acceptEventId: null
41
39
  };
42
40
  }
43
- function y(e, t, n) {
41
+ function v(e, t, n) {
44
42
  return [e.hostId, e.guestId].includes(n) ? t.type === "game_end" ? ["closed", "declined"].includes(e.status) ? e : {
45
43
  ...e,
46
44
  status: "closed",
@@ -57,30 +55,113 @@ function y(e, t, n) {
57
55
  lastEventId: t.event_id
58
56
  } : e : e;
59
57
  }
58
+ // src/games/racing-live/session.js
59
+ var y = (e) => typeof e == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e), b = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, x = (e) => typeof e == "object" && !!e && !Array.isArray(e), S = (e, t) => Object.keys(e).every((e) => t.includes(e)), ee = (e) => typeof e == "string" && /^racing-v1-[0-9a-f]{8}$/.test(e), te = (e) => Number.isInteger(e) && e >= 0 && e <= 4294967295;
60
+ function ne(n) {
61
+ let i = n?.data;
62
+ if (!x(i)) return !1;
63
+ switch (n.type) {
64
+ case "game_invite": return S(i, [
65
+ "opponent_id",
66
+ "rules_version",
67
+ "mode",
68
+ "map_id",
69
+ "seed",
70
+ "track_hash",
71
+ "laps",
72
+ "speed_class",
73
+ "rematch_of"
74
+ ]) && b(i.opponent_id) && i.rules_version === 1 && i.mode === "classic" && i.map_id === "neon_city" && te(i.seed) && (i.speed_class === void 0 || t(i.speed_class) !== null) && i.laps === (t(i.speed_class)?.laps ?? e.laps) && ee(i.track_hash) && (i.rematch_of === void 0 || y(i.rematch_of)) && i.track_hash === r(i.map_id, i.seed, { speedClass: i.speed_class }).trackHash;
75
+ case "game_accept": return S(i, ["invite_event_id", "track_hash"]) && y(i.invite_event_id) && ee(i.track_hash);
76
+ case "game_decline": return S(i, ["invite_event_id"]) && y(i.invite_event_id);
77
+ case "game_end": return S(i, ["reason"]) && i.reason === "closed";
78
+ default: return !1;
79
+ }
80
+ }
81
+ function re({ opponentId: i, seed: a = 0, rematchOf: o, speedClass: s = n } = {}) {
82
+ let c = t(s);
83
+ if (!b(i) || !te(a) || o !== void 0 && !y(o) || s !== null && !c) throw TypeError("Configuración de invitación de carrera inválida");
84
+ return {
85
+ opponent_id: i,
86
+ rules_version: 1,
87
+ mode: "classic",
88
+ map_id: "neon_city",
89
+ seed: a,
90
+ track_hash: r("neon_city", a, { speedClass: c?.id }).trackHash,
91
+ laps: c?.laps ?? e.laps,
92
+ ...c ? { speed_class: c.id } : {},
93
+ ...o === void 0 ? {} : { rematch_of: o }
94
+ };
95
+ }
96
+ function ie(e, t) {
97
+ if (!ne({
98
+ type: "game_invite",
99
+ data: t
100
+ })) throw TypeError("Configuración de carrera inválida");
101
+ return {
102
+ ...e,
103
+ game: "racing_live",
104
+ status: "invited",
105
+ turnId: null,
106
+ winnerId: null,
107
+ raceConfig: {
108
+ mode: t.mode,
109
+ mapId: t.map_id,
110
+ seed: t.seed,
111
+ trackHash: t.track_hash,
112
+ laps: t.laps,
113
+ rulesVersion: t.rules_version,
114
+ speedClass: t.speed_class ?? null
115
+ },
116
+ rematchOf: t.rematch_of ?? null,
117
+ pending: !1,
118
+ pendingEvent: null,
119
+ error: "",
120
+ acceptEventId: null
121
+ };
122
+ }
123
+ function ae(e, t, n) {
124
+ return !e || t?.game !== "racing_live" || t.game_id !== e.gameId || ![e.hostId, e.guestId].includes(n) || !ne(t) ? e : t.type === "game_end" ? ["closed", "declined"].includes(e.status) ? e : {
125
+ ...e,
126
+ status: "closed",
127
+ closedBy: n,
128
+ lastEventId: t.event_id,
129
+ error: ""
130
+ } : e.status !== "invited" || n !== e.guestId || t.data.invite_event_id !== e.inviteEventId ? e : t.type === "game_decline" ? {
131
+ ...e,
132
+ status: "declined",
133
+ lastEventId: t.event_id
134
+ } : t.type === "game_accept" && t.data.track_hash === e.raceConfig.trackHash ? {
135
+ ...e,
136
+ status: "active",
137
+ acceptEventId: t.event_id,
138
+ lastEventId: t.event_id
139
+ } : e;
140
+ }
60
141
  // src/net/webrtc/rtcSignals.js
61
- var b = /* @__PURE__ */ new Set(), x = {
142
+ var oe = /* @__PURE__ */ new Set(), se = {
62
143
  emit(e) {
63
- b.forEach((t) => {
144
+ oe.forEach((t) => {
64
145
  try {
65
146
  t(e);
66
147
  } catch {}
67
148
  });
68
149
  },
69
150
  subscribe(e) {
70
- return b.add(e), () => b.delete(e);
151
+ return oe.add(e), () => oe.delete(e);
71
152
  }
72
- }, S = ({ send: e, roomId: t }) => ({
153
+ }, ce = ({ send: e, roomId: t }) => ({
73
154
  send: (n) => e(t, n),
74
- subscribe: (e) => x.subscribe((n) => {
155
+ subscribe: (e) => se.subscribe((n) => {
75
156
  String(n.roomId) === String(t) && e(n);
76
157
  })
77
- }), ee = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, te = /^[0-9a-f]{16}$/, C = /^[0-9a-f]{32}$/, ne = /^[0-9a-f]{64}$/, re = (e) => typeof e == "object" && !!e && !Array.isArray(e), ie = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, w = (e) => typeof e == "string" && ee.test(e), T = (e, t, n) => Number.isInteger(e) && e >= t && e <= n, E = Object.freeze([
158
+ }), le = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, ue = /^[0-9a-f]{16}$/, de = /^[0-9a-f]{32}$/, fe = /^[0-9a-f]{64}$/, pe = (e) => typeof e == "object" && !!e && !Array.isArray(e), me = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, C = (e) => typeof e == "string" && le.test(e), w = (e, t, n) => Number.isInteger(e) && e >= t && e <= n, he = Object.freeze([
78
159
  "standard",
79
160
  "heavy",
80
161
  "cluster"
81
- ]), ae = (e) => T(e, 1, 120), oe = (e) => T(e.move, -16, 16) && T(e.yaw, 0, 359) && T(e.pitch, 5, 80) && T(e.power, 0, 100) && T(e.ammo, 0, E.length - 1);
82
- function se(e) {
83
- return Array.isArray(e) ? e[0] === 1 ? e.length === 6 && oe({
162
+ ]), ge = (e) => w(e, 1, 120), _e = (e) => w(e.move, -16, 16) && w(e.yaw, 0, 359) && w(e.pitch, 5, 80) && w(e.power, 0, 100) && w(e.ammo, 0, he.length - 1);
163
+ function ve(e) {
164
+ return Array.isArray(e) ? e[0] === 1 ? e.length === 6 && _e({
84
165
  move: e[1],
85
166
  yaw: e[2],
86
167
  pitch: e[3],
@@ -88,92 +169,93 @@ function se(e) {
88
169
  ammo: e[5]
89
170
  }) : e[0] === 2 ? e.length === 1 : e[0] === 3 && e.length === 2 && (e[1] === 0 || e[1] === 1) : !1;
90
171
  }
91
- var D = (e) => Array.isArray(e.log) && e.log.length <= 120 && e.log.every(se) && w(e.head) && (e.accept_event_id === void 0 ? e.log.length === 0 && e.seed_b === void 0 && e.seed_a === void 0 : w(e.accept_event_id) && typeof e.seed_b == "string" && C.test(e.seed_b)) && (e.seed_a === void 0 ? e.log.length === 0 : C.test(e.seed_a) && w(e.seed_event_id));
92
- function O(e) {
172
+ var ye = (e) => Array.isArray(e.log) && e.log.length <= 120 && e.log.every(ve) && C(e.head) && (e.accept_event_id === void 0 ? e.log.length === 0 && e.seed_b === void 0 && e.seed_a === void 0 : C(e.accept_event_id) && typeof e.seed_b == "string" && de.test(e.seed_b)) && (e.seed_a === void 0 ? e.log.length === 0 : de.test(e.seed_a) && C(e.seed_event_id));
173
+ function be(e) {
93
174
  let t = e.data;
94
175
  switch (e.type) {
95
- case "game_invite": return ie(t.opponent_id) && t.rules_version === 1 && typeof t.seed_commit == "string" && ne.test(t.seed_commit) && (t.first_player_id === void 0 || ie(t.first_player_id)) && (t.rematch_of === void 0 || w(t.rematch_of));
96
- case "game_accept": return w(t.invite_event_id) && typeof t.seed_b == "string" && C.test(t.seed_b);
97
- case "game_decline": return w(t.invite_event_id);
176
+ case "game_invite": return me(t.opponent_id) && t.rules_version === 1 && typeof t.seed_commit == "string" && fe.test(t.seed_commit) && (t.first_player_id === void 0 || me(t.first_player_id)) && (t.rematch_of === void 0 || C(t.rematch_of));
177
+ case "game_accept": return C(t.invite_event_id) && typeof t.seed_b == "string" && de.test(t.seed_b);
178
+ case "game_decline": return C(t.invite_event_id);
98
179
  case "game_end": return t.reason === "closed";
99
- case "tk_seed": return typeof t.seed_a == "string" && C.test(t.seed_a);
100
- case "tk_turn": return ae(t.ply) && w(t.prev_event_id) && oe(t) && typeof t.hash == "string" && te.test(t.hash);
180
+ case "tk_seed": return typeof t.seed_a == "string" && de.test(t.seed_a);
181
+ case "tk_turn": return ge(t.ply) && C(t.prev_event_id) && _e(t) && typeof t.hash == "string" && ue.test(t.hash);
101
182
  case "tk_skip":
102
- case "tk_resign": return ae(t.ply) && w(t.prev_event_id);
103
- case "tk_sync_request": return re(t) && D(t);
104
- case "tk_sync_state": return re(t) && D(t) && w(t.request_event_id);
183
+ case "tk_resign": return ge(t.ply) && C(t.prev_event_id);
184
+ case "tk_sync_request": return pe(t) && ye(t);
185
+ case "tk_sync_state": return pe(t) && ye(t) && C(t.request_event_id);
105
186
  default: return !1;
106
187
  }
107
188
  }
108
189
  // src/games/shared/protocol.js
109
- var ce = "LIRA_GAME_V1:", le = 4096, ue = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, de = (e) => typeof e == "object" && !!e && !Array.isArray(e), fe = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, k = (e) => typeof e == "string" && ue.test(e), pe = (e) => Array.isArray(e) && e.length <= 42 && e.every((e) => Array.isArray(e) && e.length === 2 && Number.isInteger(e[0]) && e[0] >= 0 && e[0] < 7 && k(e[1])) && new Set(e.map((e) => e[1])).size === e.length, me = (e) => pe(e.moves) && e.rev === e.moves.length && (e.accept_event_id === void 0 ? e.moves.length === 0 : k(e.accept_event_id)), he = [
190
+ var xe = "LIRA_GAME_V1:", Se = 4096, Ce = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, we = (e) => typeof e == "object" && !!e && !Array.isArray(e), T = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, E = (e) => typeof e == "string" && Ce.test(e), Te = (e) => Array.isArray(e) && e.length <= 42 && e.every((e) => Array.isArray(e) && e.length === 2 && Number.isInteger(e[0]) && e[0] >= 0 && e[0] < 7 && E(e[1])) && new Set(e.map((e) => e[1])).size === e.length, Ee = (e) => Te(e.moves) && e.rev === e.moves.length && (e.accept_event_id === void 0 ? e.moves.length === 0 : E(e.accept_event_id)), D = [
110
191
  "carrier",
111
192
  "battleship",
112
193
  "cruiser",
113
194
  "submarine",
114
195
  "destroyer"
115
- ], A = (e) => Number.isInteger(e) && e >= 0 && e < 10, ge = (e) => typeof e == "string" && /^[0-9a-f]{64}$/.test(e), _e = (e) => Number.isInteger(e) && e >= 1 && e <= 200, ve = (e) => e === null || de(e) && he.includes(e.ship_id) && Array.isArray(e.cells) && e.cells.length >= 2 && e.cells.length <= 5 && e.cells.every((e) => Array.isArray(e) && e.length === 2 && A(e[0]) && A(e[1])), ye = (e) => Array.isArray(e) && e.length === he.length && e.every((e) => de(e) && he.includes(e.ship_id) && A(e.row) && A(e.col) && (e.orientation === "horizontal" || e.orientation === "vertical")) && new Set(e.map((e) => e.ship_id)).size === e.length, be = (e, t) => Array.isArray(e) && A(e[0]) && A(e[1]) && (e.length === 2 && t || e.length === 3 && (e[2] === 0 || e[2] === 1) || e.length === 7 && e[2] === 2 && Number.isInteger(e[3]) && e[3] >= 0 && e[3] < he.length && A(e[4]) && A(e[5]) && (e[6] === 0 || e[6] === 1)), xe = (e) => Array.isArray(e.commits) && e.commits.length === 2 && e.commits.every((e) => e === null || ge(e)) && Array.isArray(e.log) && e.log.length <= 200 && e.log.every((t, n) => be(t, n === e.log.length - 1)) && k(e.head) && (e.accept_event_id === void 0 ? e.commits.every((e) => e === null) && e.log.length === 0 : k(e.accept_event_id)) && (e.log.length === 0 || e.commits.every(Boolean));
116
- function Se(e) {
196
+ ], O = (e) => Number.isInteger(e) && e >= 0 && e < 10, De = (e) => typeof e == "string" && /^[0-9a-f]{64}$/.test(e), Oe = (e) => Number.isInteger(e) && e >= 1 && e <= 200, ke = (e) => e === null || we(e) && D.includes(e.ship_id) && Array.isArray(e.cells) && e.cells.length >= 2 && e.cells.length <= 5 && e.cells.every((e) => Array.isArray(e) && e.length === 2 && O(e[0]) && O(e[1])), Ae = (e) => Array.isArray(e) && e.length === D.length && e.every((e) => we(e) && D.includes(e.ship_id) && O(e.row) && O(e.col) && (e.orientation === "horizontal" || e.orientation === "vertical")) && new Set(e.map((e) => e.ship_id)).size === e.length, je = (e, t) => Array.isArray(e) && O(e[0]) && O(e[1]) && (e.length === 2 && t || e.length === 3 && (e[2] === 0 || e[2] === 1) || e.length === 7 && e[2] === 2 && Number.isInteger(e[3]) && e[3] >= 0 && e[3] < D.length && O(e[4]) && O(e[5]) && (e[6] === 0 || e[6] === 1)), Me = (e) => Array.isArray(e.commits) && e.commits.length === 2 && e.commits.every((e) => e === null || De(e)) && Array.isArray(e.log) && e.log.length <= 200 && e.log.every((t, n) => je(t, n === e.log.length - 1)) && E(e.head) && (e.accept_event_id === void 0 ? e.commits.every((e) => e === null) && e.log.length === 0 : E(e.accept_event_id)) && (e.log.length === 0 || e.commits.every(Boolean));
197
+ function Ne(e) {
117
198
  let t = e.data;
118
199
  switch (e.type) {
119
- case "game_invite": return fe(t.opponent_id) && t.rules_version === 1;
200
+ case "game_invite": return T(t.opponent_id) && t.rules_version === 1;
120
201
  case "game_accept":
121
- case "game_decline": return k(t.invite_event_id);
122
- case "game_end": return ["closed", "win"].includes(t.reason) && (t.winner_id === void 0 || fe(t.winner_id));
123
- case "bs_commit": return ge(t.commitment);
124
- case "bs_fire": return _e(t.ply) && A(t.row) && A(t.col) && k(t.prev_event_id);
125
- case "bs_result": return _e(t.ply) && A(t.row) && A(t.col) && ["hit", "miss"].includes(t.result) && ve(t.sunk) && typeof t.defeated == "boolean" && (t.result === "hit" || t.sunk === null && !t.defeated);
126
- case "bs_reveal": return ye(t.fleet) && typeof t.salt == "string" && /^[0-9a-f]{32}$/.test(t.salt);
127
- case "bs_sync_request": return xe(t);
128
- case "bs_sync_state": return xe(t) && k(t.request_event_id);
202
+ case "game_decline": return E(t.invite_event_id);
203
+ case "game_end": return ["closed", "win"].includes(t.reason) && (t.winner_id === void 0 || T(t.winner_id));
204
+ case "bs_commit": return De(t.commitment);
205
+ case "bs_fire": return Oe(t.ply) && O(t.row) && O(t.col) && E(t.prev_event_id);
206
+ case "bs_result": return Oe(t.ply) && O(t.row) && O(t.col) && ["hit", "miss"].includes(t.result) && ke(t.sunk) && typeof t.defeated == "boolean" && (t.result === "hit" || t.sunk === null && !t.defeated);
207
+ case "bs_reveal": return Ae(t.fleet) && typeof t.salt == "string" && /^[0-9a-f]{32}$/.test(t.salt);
208
+ case "bs_sync_request": return Me(t);
209
+ case "bs_sync_state": return Me(t) && E(t.request_event_id);
129
210
  default: return !1;
130
211
  }
131
212
  }
132
- function Ce(e) {
213
+ function Pe(e) {
133
214
  return typeof e == "string" && e.startsWith("LIRA_GAME_V1:");
134
215
  }
135
- function we(e) {
216
+ function Fe(e) {
136
217
  let t = e.data;
137
218
  switch (e.type) {
138
- case "game_invite": return fe(t.opponent_id) && t.rules_version === 1;
219
+ case "game_invite": return T(t.opponent_id) && t.rules_version === 1;
139
220
  case "game_accept":
140
- case "game_decline": return k(t.invite_event_id);
141
- case "game_move": return Number.isInteger(t.column) && t.column >= 0 && t.column < 7 && Number.isInteger(t.ply) && t.ply >= 1 && t.ply <= 42 && k(t.prev_event_id);
221
+ case "game_decline": return E(t.invite_event_id);
222
+ case "game_move": return Number.isInteger(t.column) && t.column >= 0 && t.column < 7 && Number.isInteger(t.ply) && t.ply >= 1 && t.ply <= 42 && E(t.prev_event_id);
142
223
  case "game_end": return [
143
224
  "closed",
144
225
  "win",
145
226
  "draw"
146
- ].includes(t.reason) && (t.winner_id === void 0 || fe(t.winner_id)) && (t.final_move_event_id === void 0 || k(t.final_move_event_id)) && (t.reason !== "win" || fe(t.winner_id) && k(t.final_move_event_id)) && (t.reason !== "draw" || k(t.final_move_event_id));
147
- case "game_resync_request": return me(t);
148
- case "game_resync_state": return me(t) && k(t.request_event_id);
227
+ ].includes(t.reason) && (t.winner_id === void 0 || T(t.winner_id)) && (t.final_move_event_id === void 0 || E(t.final_move_event_id)) && (t.reason !== "win" || T(t.winner_id) && E(t.final_move_event_id)) && (t.reason !== "draw" || E(t.final_move_event_id));
228
+ case "game_resync_request": return Ee(t);
229
+ case "game_resync_state": return Ee(t) && E(t.request_event_id);
149
230
  default: return !1;
150
231
  }
151
232
  }
152
- var Te = {
153
- connect4: we,
154
- battleship: Se,
155
- tanks: O,
156
- tanks_live: _
157
- }, Ee = Object.freeze(Object.keys(Te));
158
- function De(e) {
159
- return !de(e) || e.version !== 1 || !Object.hasOwn(Te, e.game) || !k(e.game_id) || !k(e.event_id) || !de(e.data) ? !1 : Te[e.game](e);
160
- }
161
- function Oe(e) {
162
- if (!Ce(e) || e.length > le) return null;
233
+ var Ie = {
234
+ connect4: Fe,
235
+ battleship: Ne,
236
+ tanks: be,
237
+ tanks_live: g,
238
+ racing_live: ne
239
+ }, Le = Object.freeze(Object.keys(Ie));
240
+ function Re(e) {
241
+ return !we(e) || e.version !== 1 || !Object.hasOwn(Ie, e.game) || !E(e.game_id) || !E(e.event_id) || !we(e.data) ? !1 : Ie[e.game](e);
242
+ }
243
+ function ze(e) {
244
+ if (!Pe(e) || e.length > Se) return null;
163
245
  try {
164
246
  let t = JSON.parse(e.slice(13));
165
- return De(t) ? t : null;
247
+ return Re(t) ? t : null;
166
248
  } catch {
167
249
  return null;
168
250
  }
169
251
  }
170
- function ke(e) {
171
- if (!De(e)) throw Error("Evento de juego inválido");
172
- let t = ce + JSON.stringify(e);
173
- if (t.length > le) throw Error("Evento de juego demasiado grande");
252
+ function Be(e) {
253
+ if (!Re(e)) throw Error("Evento de juego inválido");
254
+ let t = xe + JSON.stringify(e);
255
+ if (t.length > Se) throw Error("Evento de juego demasiado grande");
174
256
  return t;
175
257
  }
176
- function j(e, { game_id: t, data: n, event_id: r = m(), game: i = "connect4" }) {
258
+ function k(e, { game_id: t, data: n, event_id: r = p(), game: i = "connect4" }) {
177
259
  let a = {
178
260
  version: 1,
179
261
  game: i,
@@ -182,22 +264,22 @@ function j(e, { game_id: t, data: n, event_id: r = m(), game: i = "connect4" })
182
264
  type: e,
183
265
  data: n
184
266
  };
185
- if (!De(a)) throw Error("Evento de juego inválido");
267
+ if (!Re(a)) throw Error("Evento de juego inválido");
186
268
  return a;
187
269
  }
188
- function Ae() {
270
+ function Ve() {
189
271
  return Array.from({ length: 6 }, () => Array(7).fill(null));
190
272
  }
191
- var je = [
273
+ var He = [
192
274
  [0, 1],
193
275
  [1, 0],
194
276
  [1, 1],
195
277
  [1, -1]
196
278
  ];
197
- function Me(e) {
279
+ function Ue(e) {
198
280
  for (let t = 0; t < 6; t += 1) for (let n = 0; n < 7; n += 1) {
199
281
  let r = e[t][n];
200
- if (r != null) for (let [i, a] of je) {
282
+ if (r != null) for (let [i, a] of He) {
201
283
  let o = [];
202
284
  for (let s = 0; s < 4; s += 1) {
203
285
  let c = t + i * s, l = n + a * s;
@@ -209,40 +291,40 @@ function Me(e) {
209
291
  }
210
292
  return [];
211
293
  }
212
- function Ne(e) {
213
- let t = Me(e);
294
+ function We(e) {
295
+ let t = Ue(e);
214
296
  return t.length ? e[t[0][0]][t[0][1]] : null;
215
297
  }
216
- function Pe(e) {
298
+ function Ge(e) {
217
299
  return e[0].every((e) => e !== null);
218
300
  }
219
- function Fe(e, t, n) {
220
- if (!Number.isInteger(t) || t < 0 || t >= 7 || n == null || Ne(e) !== null) return null;
301
+ function Ke(e, t, n) {
302
+ if (!Number.isInteger(t) || t < 0 || t >= 7 || n == null || We(e) !== null) return null;
221
303
  let r = 5;
222
304
  for (; r >= 0 && e[r][t] !== null;) --r;
223
305
  if (r < 0) return null;
224
306
  let i = e.map((e) => e.slice());
225
307
  i[r][t] = n;
226
- let a = Me(i), o = a.length ? i[a[0][0]][a[0][1]] : null;
308
+ let a = Ue(i), o = a.length ? i[a[0][0]][a[0][1]] : null;
227
309
  return {
228
310
  board: i,
229
311
  row: r,
230
312
  column: t,
231
313
  winner: o,
232
- draw: o === null && Pe(i),
314
+ draw: o === null && Ge(i),
233
315
  winningCells: a
234
316
  };
235
317
  }
236
318
  // src/games/battleship/logic/game.js
237
- var Ie = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
238
- function Le({ gameId: e, players: t, firstPlayerId: n = t?.[0] } = {}) {
239
- if (!Ie(e) || !Array.isArray(t) || t.length !== 2 || !t.every(Ie) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
319
+ var qe = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
320
+ function Je({ gameId: e, players: t, firstPlayerId: n = t?.[0] } = {}) {
321
+ if (!qe(e) || !Array.isArray(t) || t.length !== 2 || !t.every(qe) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
240
322
  return {
241
323
  game: "battleship",
242
324
  rulesVersion: 1,
243
325
  gameId: e,
244
326
  players: t.slice(),
245
- boards: [r(), r()],
327
+ boards: [s(), s()],
246
328
  ready: [!1, !1],
247
329
  phase: "placement",
248
330
  turnId: null,
@@ -253,72 +335,72 @@ function Le({ gameId: e, players: t, firstPlayerId: n = t?.[0] } = {}) {
253
335
  revision: 0
254
336
  };
255
337
  }
256
- function Re(n, r) {
257
- if (!n || !r || typeof r != "object" || n.phase === "finished" || r.gameId !== void 0 && r.gameId !== n.gameId || r.expectedRevision !== void 0 && r.expectedRevision !== n.revision) return n;
258
- let o = n.players.indexOf(r.playerId);
259
- if (o < 0) return n;
260
- let s = n.boards[o];
261
- if (n.phase === "placement") {
262
- if (n.ready[o]) return n;
263
- if (r.type === "place_ship" || r.type === "remove_ship") {
264
- let e = r.type === "place_ship" ? a(s, r) : t(s, r.shipId);
265
- if (!e.ok) return n;
266
- let i = n.boards.slice();
267
- return i[o] = e.board, {
268
- ...n,
269
- boards: i,
270
- revision: n.revision + 1
338
+ function Ye(e, t) {
339
+ if (!e || !t || typeof t != "object" || e.phase === "finished" || t.gameId !== void 0 && t.gameId !== e.gameId || t.expectedRevision !== void 0 && t.expectedRevision !== e.revision) return e;
340
+ let n = e.players.indexOf(t.playerId);
341
+ if (n < 0) return e;
342
+ let r = e.boards[n];
343
+ if (e.phase === "placement") {
344
+ if (e.ready[n]) return e;
345
+ if (t.type === "place_ship" || t.type === "remove_ship") {
346
+ let i = t.type === "place_ship" ? l(r, t) : a(r, t.shipId);
347
+ if (!i.ok) return e;
348
+ let o = e.boards.slice();
349
+ return o[n] = i.board, {
350
+ ...e,
351
+ boards: o,
352
+ revision: e.revision + 1
271
353
  };
272
354
  }
273
- if (r.type === "ready" && e(s)) {
274
- let e = n.ready.slice();
275
- e[o] = !0;
276
- let t = e.every(Boolean);
355
+ if (t.type === "ready" && i(r)) {
356
+ let t = e.ready.slice();
357
+ t[n] = !0;
358
+ let r = t.every(Boolean);
277
359
  return {
278
- ...n,
279
- ready: e,
280
- phase: t ? "playing" : "placement",
281
- turnId: t ? n.firstPlayerId : null,
282
- revision: n.revision + 1
360
+ ...e,
361
+ ready: t,
362
+ phase: r ? "playing" : "placement",
363
+ turnId: r ? e.firstPlayerId : null,
364
+ revision: e.revision + 1
283
365
  };
284
366
  }
285
- return n;
367
+ return e;
286
368
  }
287
- if (n.phase !== "playing" || r.type !== "fire" || r.playerId !== n.turnId) return n;
288
- let c = 1 - o, l = i(n.boards[c], r);
289
- if (!l.ok) return n;
290
- let u = n.boards.slice();
291
- return u[c] = l.board, {
292
- ...n,
369
+ if (e.phase !== "playing" || t.type !== "fire" || t.playerId !== e.turnId) return e;
370
+ let o = 1 - n, s = c(e.boards[o], t);
371
+ if (!s.ok) return e;
372
+ let u = e.boards.slice();
373
+ return u[o] = s.board, {
374
+ ...e,
293
375
  boards: u,
294
- revision: n.revision + 1,
295
- shotCount: n.shotCount + 1,
296
- phase: l.defeated ? "finished" : "playing",
297
- turnId: l.defeated ? null : n.players[c],
298
- winnerId: l.defeated ? r.playerId : null,
376
+ revision: e.revision + 1,
377
+ shotCount: e.shotCount + 1,
378
+ phase: s.defeated ? "finished" : "playing",
379
+ turnId: s.defeated ? null : e.players[o],
380
+ winnerId: s.defeated ? t.playerId : null,
299
381
  lastShot: {
300
- playerId: r.playerId,
301
- targetId: n.players[c],
302
- row: r.row,
303
- col: r.col,
304
- result: l.result,
305
- shipId: l.shipId,
306
- sunk: l.sunk,
307
- defeated: l.defeated
382
+ playerId: t.playerId,
383
+ targetId: e.players[o],
384
+ row: t.row,
385
+ col: t.col,
386
+ result: s.result,
387
+ shipId: s.shipId,
388
+ sunk: s.sunk,
389
+ defeated: s.defeated
308
390
  }
309
391
  };
310
392
  }
311
393
  // src/games/battleship/net/session.js
312
- var ze = o.reduce((e, t) => e + t.size, 0), Be = /^[0-9a-f]{32}$/, Ve = [
394
+ var Xe = u.reduce((e, t) => e + t.size, 0), Ze = /^[0-9a-f]{32}$/, Qe = [
313
395
  "won",
314
396
  "closed",
315
397
  "declined"
316
- ], M = "La partida perdió sincronización. Se intentará resincronizar.", He = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", Ue = "El rival envió un resultado imposible para ese disparo.", We = "Tu flota no está disponible en este dispositivo; no se pueden responder disparos.", Ge = () => Array.from({ length: 10 }, () => Array(10).fill(null)), Ke = (e, t, n, r) => e.map((e, i) => i === t ? e.map((e, t) => t === n ? r : e) : e), qe = (e) => e.reduce((e, t) => e + t.filter((e) => e === "hit").length, 0), Je = (e) => e.reduce((e, t) => e + t.filter((e) => e !== null).length, 0), Ye = (e, t) => t % 2 == 1 ? e.hostId : e.guestId, Xe = (e, t) => t === e.hostId ? e.guestId : e.hostId, Ze = (e, t) => t === e.hostId ? "hostCommitment" : "guestCommitment", N = (e, t) => ({
398
+ ], A = "La partida perdió sincronización. Se intentará resincronizar.", $e = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", et = "El rival envió un resultado imposible para ese disparo.", tt = "Tu flota no está disponible en este dispositivo; no se pueden responder disparos.", nt = () => Array.from({ length: 10 }, () => Array(10).fill(null)), rt = (e, t, n, r) => e.map((e, i) => i === t ? e.map((e, t) => t === n ? r : e) : e), it = (e) => e.reduce((e, t) => e + t.filter((e) => e === "hit").length, 0), at = (e) => e.reduce((e, t) => e + t.filter((e) => e !== null).length, 0), ot = (e, t) => t % 2 == 1 ? e.hostId : e.guestId, st = (e, t) => t === e.hostId ? e.guestId : e.hostId, ct = (e, t) => t === e.hostId ? "hostCommitment" : "guestCommitment", j = (e, t) => ({
317
399
  ...e,
318
400
  status: "conflict",
319
401
  error: t
320
- }), Qe = (e) => `${e.row},${e.col}`, $e = (e, t) => e.row - t.row || e.col - t.col, et = (e, t) => e.length === t.length && e.map(Qe).sort().join("|") === t.map(Qe).sort().join("|");
321
- function tt(e) {
402
+ }), lt = (e) => `${e.row},${e.col}`, ut = (e, t) => e.row - t.row || e.col - t.col, dt = (e, t) => e.length === t.length && e.map(lt).sort().join("|") === t.map(lt).sort().join("|");
403
+ function ft(e) {
322
404
  return {
323
405
  ...e,
324
406
  game: "battleship",
@@ -327,8 +409,8 @@ function tt(e) {
327
409
  myFleet: [],
328
410
  myReady: !1,
329
411
  opponentReady: !1,
330
- incomingShots: Ge(),
331
- targetShots: Ge(),
412
+ incomingShots: nt(),
413
+ targetShots: nt(),
332
414
  sunkEnemyShips: [],
333
415
  pendingShot: null,
334
416
  lastShot: null,
@@ -350,7 +432,7 @@ function tt(e) {
350
432
  sync: e.sync ?? null
351
433
  };
352
434
  }
353
- var nt = (e) => e?.game === "battleship" && ["invited", "placement"].includes(e.status) && !e.myReady, rt = (e) => e?.status === "active" && e.turnId === e.ownId && !e.pendingShot, it = (e) => ({
435
+ var pt = (e) => e?.game === "battleship" && ["invited", "placement"].includes(e.status) && !e.myReady, mt = (e) => e?.status === "active" && e.turnId === e.ownId && !e.pendingShot, ht = (e) => ({
354
436
  id: e.id,
355
437
  size: e.size,
356
438
  orientation: e.orientation,
@@ -358,33 +440,33 @@ var nt = (e) => e?.game === "battleship" && ["invited", "placement"].includes(e.
358
440
  row: e.row,
359
441
  col: e.col
360
442
  }))
361
- }), at = (e) => ({
443
+ }), gt = (e) => ({
362
444
  shipId: e.id,
363
445
  row: e.cells[0].row,
364
446
  col: e.cells[0].col,
365
447
  orientation: e.orientation
366
448
  });
367
- function ot(e) {
449
+ function _t(e) {
368
450
  return !e || typeof e != "object" ? null : typeof e.ship_id == "string" ? {
369
451
  shipId: e.ship_id,
370
452
  row: e.row,
371
453
  col: e.col,
372
454
  orientation: e.orientation
373
- } : typeof e.id == "string" && Array.isArray(e.cells) && e.cells.length ? at(e) : null;
455
+ } : typeof e.id == "string" && Array.isArray(e.cells) && e.cells.length ? gt(e) : null;
374
456
  }
375
- function st(e) {
457
+ function vt(e) {
376
458
  if (!Array.isArray(e)) return null;
377
- let t = r();
459
+ let t = s();
378
460
  for (let n of e) {
379
- let e = ot(n), r = e && a(t, e);
461
+ let e = _t(n), r = e && l(t, e);
380
462
  if (!r?.ok) return null;
381
463
  t = r.board;
382
464
  }
383
465
  return t;
384
466
  }
385
- function ct(e) {
467
+ function M(e) {
386
468
  if (!Array.isArray(e)) return null;
387
- let t = e.map(ot);
469
+ let t = e.map(_t);
388
470
  return t.some((e) => !e) ? null : t.map(({ shipId: e, row: t, col: n, orientation: r }) => ({
389
471
  ship_id: e,
390
472
  row: t,
@@ -392,86 +474,86 @@ function ct(e) {
392
474
  orientation: r
393
475
  })).sort((e, t) => e.ship_id < t.ship_id ? -1 : +(e.ship_id > t.ship_id));
394
476
  }
395
- function lt(t) {
396
- let n = st(t);
397
- return n && e(n) ? n.ships.map(it) : null;
477
+ function yt(e) {
478
+ let t = vt(e);
479
+ return t && i(t) ? t.ships.map(ht) : null;
398
480
  }
399
- var ut = (e) => !!lt(e);
400
- function dt(t) {
401
- let n = st(t?.myFleet);
402
- return n && e(n) ? {
403
- ...n,
404
- shots: t.incomingShots.map((e) => e.slice())
481
+ var bt = (e) => !!yt(e);
482
+ function xt(e) {
483
+ let t = vt(e?.myFleet);
484
+ return t && i(t) ? {
485
+ ...t,
486
+ shots: e.incomingShots.map((e) => e.slice())
405
487
  } : null;
406
488
  }
407
- function ft(e, { shipId: t, row: n, col: r, orientation: i } = {}) {
408
- if (!nt(e)) return e;
409
- let o = st(e.myFleet.filter((e) => e.id !== t)), s = o && a(o, {
489
+ function St(e, { shipId: t, row: n, col: r, orientation: i } = {}) {
490
+ if (!pt(e)) return e;
491
+ let a = vt(e.myFleet.filter((e) => e.id !== t)), o = a && l(a, {
410
492
  shipId: t,
411
493
  row: n,
412
494
  col: r,
413
495
  orientation: i
414
496
  });
415
- return s?.ok ? {
497
+ return o?.ok ? {
416
498
  ...e,
417
- myFleet: s.board.ships.map(it)
499
+ myFleet: o.board.ships.map(ht)
418
500
  } : e;
419
501
  }
420
- function pt(e, t) {
421
- return !nt(e) || !e.myFleet.some((e) => e.id === t) ? e : {
502
+ function Ct(e, t) {
503
+ return !pt(e) || !e.myFleet.some((e) => e.id === t) ? e : {
422
504
  ...e,
423
505
  myFleet: e.myFleet.filter((e) => e.id !== t)
424
506
  };
425
507
  }
426
- function mt(e) {
508
+ function wt(e) {
427
509
  let t = Math.floor(4294967296 / e) * e, n = /* @__PURE__ */ new Uint32Array(1);
428
510
  do
429
511
  globalThis.crypto.getRandomValues(n);
430
512
  while (n[0] >= t);
431
513
  return n[0] % e;
432
514
  }
433
- function ht(t = mt) {
434
- for (let n = 0; n < 50; n += 1) {
435
- let n = r();
436
- for (let e of o) for (let r = 0; r < 300; r += 1) {
437
- let r = a(n, {
438
- shipId: e.id,
439
- row: t(10),
440
- col: t(10),
441
- orientation: t(2) === 0 ? "horizontal" : "vertical"
515
+ function Tt(e = wt) {
516
+ for (let t = 0; t < 50; t += 1) {
517
+ let t = s();
518
+ for (let n of u) for (let r = 0; r < 300; r += 1) {
519
+ let r = l(t, {
520
+ shipId: n.id,
521
+ row: e(10),
522
+ col: e(10),
523
+ orientation: e(2) === 0 ? "horizontal" : "vertical"
442
524
  });
443
525
  if (r.ok) {
444
- n = r.board;
526
+ t = r.board;
445
527
  break;
446
528
  }
447
529
  }
448
- if (e(n)) return n.ships.map(it);
530
+ if (i(t)) return t.ships.map(ht);
449
531
  }
450
532
  throw Error("No se pudo generar una flota aleatoria.");
451
533
  }
452
- var gt = (e, t) => nt(e) ? {
534
+ var Et = (e, t) => pt(e) ? {
453
535
  ...e,
454
- myFleet: ht(t)
455
- } : e, _t = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
456
- function vt() {
536
+ myFleet: Tt(t)
537
+ } : e, Dt = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
538
+ function Ot() {
457
539
  let e = /* @__PURE__ */ new Uint8Array(16);
458
- return globalThis.crypto.getRandomValues(e), _t(e);
540
+ return globalThis.crypto.getRandomValues(e), Dt(e);
459
541
  }
460
- function yt(e, t) {
461
- let n = ct(e);
542
+ function kt(e, t) {
543
+ let n = M(e);
462
544
  if (!n || typeof t != "string") throw TypeError("Flota inválida");
463
545
  return JSON.stringify({
464
546
  fleet: n,
465
547
  salt: t
466
548
  });
467
549
  }
468
- async function bt(e, t) {
469
- let n = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(yt(e, t)));
470
- return _t(new Uint8Array(n));
550
+ async function At(e, t) {
551
+ let n = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(kt(e, t)));
552
+ return Dt(new Uint8Array(n));
471
553
  }
472
- function xt(e, t) {
554
+ function jt(e, t) {
473
555
  if (!e || !t) return null;
474
- let n = i(e, {
556
+ let n = c(e, {
475
557
  row: t.row,
476
558
  col: t.col
477
559
  });
@@ -489,61 +571,61 @@ function xt(e, t) {
489
571
  defeated: n.defeated
490
572
  };
491
573
  }
492
- function St(e) {
493
- let t = o.find((t) => t.id === e?.ship_id);
574
+ function Mt(e) {
575
+ let t = u.find((t) => t.id === e?.ship_id);
494
576
  if (!t || !Array.isArray(e.cells) || e.cells.length !== t.size) return null;
495
- let r = e.cells.map((e) => Array.isArray(e) ? {
577
+ let n = e.cells.map((e) => Array.isArray(e) ? {
496
578
  row: e[0],
497
579
  col: e[1]
498
580
  } : null);
499
- if (r.some((e) => !n(e))) return null;
500
- r.sort($e);
501
- let i = r.every((e, t) => e.row === r[0].row && e.col === r[0].col + t), a = r.every((e, t) => e.col === r[0].col && e.row === r[0].row + t);
502
- return !i && !a ? null : {
581
+ if (n.some((e) => !o(e))) return null;
582
+ n.sort(ut);
583
+ let r = n.every((e, t) => e.row === n[0].row && e.col === n[0].col + t), i = n.every((e, t) => e.col === n[0].col && e.row === n[0].row + t);
584
+ return !r && !i ? null : {
503
585
  id: t.id,
504
586
  size: t.size,
505
- orientation: i ? "horizontal" : "vertical",
506
- cells: r,
587
+ orientation: r ? "horizontal" : "vertical",
588
+ cells: n,
507
589
  sunk: !0
508
590
  };
509
591
  }
510
- function Ct(e, t) {
511
- let { row: n, col: r, result: i, sunk: a } = t, s = !!t.defeated;
592
+ function Nt(e, t) {
593
+ let { row: n, col: r, result: i, sunk: a } = t, o = !!t.defeated;
512
594
  if (i !== "hit" && i !== "miss" || e.targetShots[n][r] !== null) return null;
513
- let c = Ke(e.targetShots, n, r, i), l = qe(c), u = null;
595
+ let s = rt(e.targetShots, n, r, i), c = it(s), l = null;
514
596
  if (a) {
515
- if (u = i === "hit" ? St(a) : null, !u || e.sunkEnemyShips.some((e) => e.id === u.id)) return null;
516
- let t = new Set(e.sunkEnemyShips.flatMap((e) => e.cells.map(Qe)));
517
- if (!u.cells.some((e) => e.row === n && e.col === r) || u.cells.some((e) => c[e.row][e.col] !== "hit" || t.has(Qe(e)))) return null;
597
+ if (l = i === "hit" ? Mt(a) : null, !l || e.sunkEnemyShips.some((e) => e.id === l.id)) return null;
598
+ let t = new Set(e.sunkEnemyShips.flatMap((e) => e.cells.map(lt)));
599
+ if (!l.cells.some((e) => e.row === n && e.col === r) || l.cells.some((e) => s[e.row][e.col] !== "hit" || t.has(lt(e)))) return null;
518
600
  }
519
- let d = e.sunkEnemyShips.length + +!!u;
520
- return l > ze || s !== (l === ze) || s !== (d === o.length) || !s && ze - l > 100 - Je(c) ? null : {
521
- shots: c,
522
- ship: u
601
+ let d = e.sunkEnemyShips.length + +!!l;
602
+ return c > Xe || o !== (c === Xe) || o !== (d === u.length) || !o && Xe - c > 100 - at(s) ? null : {
603
+ shots: s,
604
+ ship: l
523
605
  };
524
606
  }
525
- function wt(e, t) {
526
- let n = xt(dt(e), t);
607
+ function Pt(e, t) {
608
+ let n = jt(xt(e), t);
527
609
  if (!n || n.result !== t.result || n.defeated !== !!t.defeated || !!n.sunk != !!t.sunk) return null;
528
- let r = n.sunk ? St(n.sunk) : null;
529
- return r && (t.sunk.ship_id !== r.id || !et(r.cells, t.sunk.cells.map(([e, t]) => ({
610
+ let r = n.sunk ? Mt(n.sunk) : null;
611
+ return r && (t.sunk.ship_id !== r.id || !dt(r.cells, t.sunk.cells.map(([e, t]) => ({
530
612
  row: e,
531
613
  col: t
532
614
  })))) ? null : {
533
- shots: Ke(e.incomingShots, t.row, t.col, t.result),
615
+ shots: rt(e.incomingShots, t.row, t.col, t.result),
534
616
  ship: r
535
617
  };
536
618
  }
537
- function Tt(e, t, n, r) {
538
- let i = Ze(e, t);
619
+ function Ft(e, t, n, r) {
620
+ let i = ct(e, t);
539
621
  if (e[i]) return e[i] === n ? e : null;
540
622
  let a = {
541
623
  ...e,
542
624
  [i]: n
543
625
  };
544
626
  if (t === e.ownId) {
545
- let t = r?.commitment === n ? lt(r.fleet) : null;
546
- t && Be.test(r.salt ?? "") ? a = {
627
+ let t = r?.commitment === n ? yt(r.fleet) : null;
628
+ t && Ze.test(r.salt ?? "") ? a = {
547
629
  ...a,
548
630
  myFleet: t,
549
631
  mySalt: r.salt,
@@ -553,7 +635,7 @@ function Tt(e, t, n, r) {
553
635
  myFleet: [],
554
636
  mySalt: null,
555
637
  myCommitment: n,
556
- error: We
638
+ error: tt
557
639
  }), a.myReady = !0;
558
640
  } else a.opponentReady = !0;
559
641
  return a.hostCommitment && a.guestCommitment && (a = {
@@ -564,24 +646,24 @@ function Tt(e, t, n, r) {
564
646
  pendingShot: null
565
647
  }), a;
566
648
  }
567
- function Et(e, t, { row: r, col: i, ply: a }, o) {
649
+ function It(e, t, { row: n, col: r, ply: i }, a) {
568
650
  let s = t === e.ownId ? e.targetShots : e.incomingShots;
569
- return !n({
570
- row: r,
571
- col: i
572
- }) || s[r][i] !== null ? null : {
651
+ return !o({
652
+ row: n,
653
+ col: r
654
+ }) || s[n][r] !== null ? null : {
573
655
  ...e,
574
656
  pendingShot: {
575
- row: r,
576
- col: i,
577
- ply: a,
657
+ row: n,
658
+ col: r,
659
+ ply: i,
578
660
  by: t
579
661
  },
580
- lastEventId: o ?? e.lastEventId
662
+ lastEventId: a ?? e.lastEventId
581
663
  };
582
664
  }
583
- function Dt(e, t, n, r) {
584
- let i = e.pendingShot, a = t === e.ownId, o = a ? wt(e, n) : Ct(e, n);
665
+ function Lt(e, t, n, r) {
666
+ let i = e.pendingShot, a = t === e.ownId, o = a ? Pt(e, n) : Nt(e, n);
585
667
  if (!o) return null;
586
668
  let s = !!n.defeated, c = {
587
669
  ply: i.ply,
@@ -611,21 +693,21 @@ function Dt(e, t, n, r) {
611
693
  verification: s ? "pending" : e.verification
612
694
  };
613
695
  }
614
- function Ot(e, t, n) {
696
+ function Rt(e, t, n) {
615
697
  let { ply: r, row: i, col: a, prev_event_id: o } = t.data;
616
- return n === Ye(e, r) ? e.status === "active" ? r <= e.ply ? e : e.pendingShot ? r === e.pendingShot.ply ? e : N(e, M) : r > e.ply + 1 ? N(e, M) : n === e.turnId ? o === e.lastEventId ? Et(e, n, {
698
+ return n === ot(e, r) ? e.status === "active" ? r <= e.ply ? e : e.pendingShot ? r === e.pendingShot.ply ? e : j(e, A) : r > e.ply + 1 ? j(e, A) : n === e.turnId ? o === e.lastEventId ? It(e, n, {
617
699
  row: i,
618
700
  col: a,
619
701
  ply: r
620
- }, t.event_id) ?? e : N(e, M) : e : N(e, e.status === "invited" ? He : M) : e;
702
+ }, t.event_id) ?? e : j(e, A) : e : j(e, e.status === "invited" ? $e : A) : e;
621
703
  }
622
- function kt(e, t, n) {
704
+ function zt(e, t, n) {
623
705
  let { ply: r, row: i, col: a } = t.data;
624
- if (e.status !== "active") return e.status === "placement" ? N(e, M) : e;
706
+ if (e.status !== "active") return e.status === "placement" ? j(e, A) : e;
625
707
  let o = e.pendingShot;
626
- return o ? r === o.ply ? n === o.by ? e : i !== o.row || a !== o.col ? n === e.ownId ? e : N(e, "El rival respondió a un disparo distinto.") : Dt(e, n, t.data, t.event_id) || (n === e.ownId ? e : N(e, Ue)) : r < o.ply ? e : N(e, M) : r <= e.ply ? e : N(e, M);
708
+ return o ? r === o.ply ? n === o.by ? e : i !== o.row || a !== o.col ? n === e.ownId ? e : j(e, "El rival respondió a un disparo distinto.") : Lt(e, n, t.data, t.event_id) || (n === e.ownId ? e : j(e, et)) : r < o.ply ? e : j(e, A) : r <= e.ply ? e : j(e, A);
627
709
  }
628
- function At(e, t, n) {
710
+ function Bt(e, t, n) {
629
711
  return !e.winnerId || !["won", "closed"].includes(e.status) ? e : n === e.ownId ? e.myRevealSent ? e : {
630
712
  ...e,
631
713
  myRevealSent: !0
@@ -638,7 +720,7 @@ function At(e, t, n) {
638
720
  verification: "pending"
639
721
  };
640
722
  }
641
- function jt(e, t, n, r = {}) {
723
+ function Vt(e, t, n, r = {}) {
642
724
  if (!e || e.game !== "battleship" || t?.game !== "battleship" || t.game_id !== e.gameId || n !== e.hostId && n !== e.guestId) return e;
643
725
  let i = t.data;
644
726
  if (t.type === "game_end") return i.reason !== "closed" || [
@@ -651,8 +733,8 @@ function jt(e, t, n, r = {}) {
651
733
  closedBy: n,
652
734
  error: ""
653
735
  };
654
- if (t.type === "bs_reveal") return At(e, i, n);
655
- if (Ve.includes(e.status) || e.status === "conflict") return e;
736
+ if (t.type === "bs_reveal") return Bt(e, i, n);
737
+ if (Qe.includes(e.status) || e.status === "conflict") return e;
656
738
  switch (t.type) {
657
739
  case "game_accept":
658
740
  case "game_decline": return n !== e.guestId || e.status !== "invited" || i.invite_event_id !== e.inviteEventId ? e : t.type === "game_accept" ? {
@@ -665,32 +747,32 @@ function jt(e, t, n, r = {}) {
665
747
  status: "declined",
666
748
  lastEventId: t.event_id
667
749
  };
668
- case "bs_commit": return e.status === "invited" ? N(e, He) : e.status === "placement" ? Tt(e, n, i.commitment, r.stored) ?? e : e;
669
- case "bs_fire": return Ot(e, t, n);
670
- case "bs_result": return kt(e, t, n);
750
+ case "bs_commit": return e.status === "invited" ? j(e, $e) : e.status === "placement" ? Ft(e, n, i.commitment, r.stored) ?? e : e;
751
+ case "bs_fire": return Rt(e, t, n);
752
+ case "bs_result": return zt(e, t, n);
671
753
  default: return e;
672
754
  }
673
755
  }
674
- function Mt(e, t) {
675
- let n = Le({
756
+ function Ht(e, t) {
757
+ let n = Je({
676
758
  gameId: String(e.gameId),
677
759
  players: [e.hostId, e.guestId],
678
760
  firstPlayerId: e.hostId
679
761
  });
680
762
  for (let e of n.players) {
681
- for (let r of t[e]) n = Re(n, {
763
+ for (let r of t[e]) n = Ye(n, {
682
764
  type: "place_ship",
683
765
  playerId: e,
684
- ...at(r)
766
+ ...gt(r)
685
767
  });
686
- n = Re(n, {
768
+ n = Ye(n, {
687
769
  type: "ready",
688
770
  playerId: e
689
771
  });
690
772
  }
691
773
  if (n.phase !== "playing") return !1;
692
774
  for (let t of e.shots) {
693
- let e = Re(n, {
775
+ let e = Ye(n, {
694
776
  type: "fire",
695
777
  playerId: t.by,
696
778
  row: t.row,
@@ -701,30 +783,30 @@ function Mt(e, t) {
701
783
  if (r.result !== t.result || r.defeated !== t.defeated || r.sunk !== !!t.sunk) return !1;
702
784
  if (t.sunk) {
703
785
  let n = e.boards[e.players.indexOf(r.targetId)].ships.find((e) => e.id === r.shipId);
704
- if (t.sunk.id !== r.shipId || !et(n.cells, t.sunk.cells)) return !1;
786
+ if (t.sunk.id !== r.shipId || !dt(n.cells, t.sunk.cells)) return !1;
705
787
  }
706
788
  n = e;
707
789
  }
708
790
  return !e.winnerId || n.winnerId === e.winnerId;
709
791
  }
710
- async function Nt(e, t = e?.opponentReveal) {
792
+ async function Ut(e, t = e?.opponentReveal) {
711
793
  if (!e || !t) return "pending";
712
- let n = Xe(e, e.ownId), r = e[Ze(e, n)], i = lt(t.fleet);
713
- if (!r || !i || typeof t.salt != "string" || !Be.test(t.salt)) return "mismatch";
794
+ let n = st(e, e.ownId), r = e[ct(e, n)], i = yt(t.fleet);
795
+ if (!r || !i || typeof t.salt != "string" || !Ze.test(t.salt)) return "mismatch";
714
796
  let a;
715
797
  try {
716
- a = await bt(t.fleet, t.salt);
798
+ a = await At(t.fleet, t.salt);
717
799
  } catch {
718
800
  return "mismatch";
719
801
  }
720
802
  if (a !== r) return "mismatch";
721
- let o = lt(e.myFleet);
722
- return o ? Mt(e, {
803
+ let o = yt(e.myFleet);
804
+ return o ? Ht(e, {
723
805
  [e.ownId]: o,
724
806
  [n]: i
725
807
  }) ? "ok" : "mismatch" : "pending";
726
808
  }
727
- var Pt = (e) => {
809
+ var Wt = (e) => {
728
810
  if (e.result === "miss") return [
729
811
  e.row,
730
812
  e.col,
@@ -740,19 +822,19 @@ var Pt = (e) => {
740
822
  e.row,
741
823
  e.col,
742
824
  2,
743
- o.findIndex((t) => t.id === e.sunk.id),
825
+ u.findIndex((t) => t.id === e.sunk.id),
744
826
  t.row,
745
827
  t.col,
746
828
  +(e.sunk.orientation === "vertical")
747
829
  ];
748
830
  };
749
- function Ft(e) {
831
+ function Gt(e) {
750
832
  if (!e.acceptEventId) return {
751
833
  commits: [null, null],
752
834
  log: [],
753
835
  head: e.inviteEventId
754
836
  };
755
- let t = e.shots.map(Pt);
837
+ let t = e.shots.map(Wt);
756
838
  return e.pendingShot && t.push([e.pendingShot.row, e.pendingShot.col]), {
757
839
  accept_event_id: e.acceptEventId,
758
840
  commits: [e.hostCommitment ?? null, e.guestCommitment ?? null],
@@ -760,7 +842,7 @@ function Ft(e) {
760
842
  head: e.lastEventId
761
843
  };
762
844
  }
763
- function It(e, t) {
845
+ function Kt(e, t) {
764
846
  let n = e.accept_event_id ?? null, r = t.accept_event_id ?? null;
765
847
  if (n && r && n !== r) return "diverged";
766
848
  let i = /* @__PURE__ */ new Set();
@@ -780,7 +862,7 @@ function It(e, t) {
780
862
  }
781
863
  return a.length !== o.length && i.add(a.length < o.length ? "behind" : "ahead"), i.size === 2 ? "mixed" : i.size === 1 ? [...i][0] : a.length && e.head !== t.head ? "diverged" : "equal";
782
864
  }
783
- function Lt(e, t) {
865
+ function qt(e, t) {
784
866
  if ((e.log ?? []).length || (t.log ?? []).length) return null;
785
867
  let n = e.accept_event_id ?? t.accept_event_id;
786
868
  return n ? {
@@ -790,15 +872,15 @@ function Lt(e, t) {
790
872
  head: n
791
873
  } : null;
792
874
  }
793
- function Rt(e, t, n = {}) {
875
+ function Jt(e, t, n = {}) {
794
876
  let r = {
795
877
  ...e,
796
878
  status: "invited",
797
879
  turnId: null,
798
880
  myReady: !1,
799
881
  opponentReady: !1,
800
- incomingShots: Ge(),
801
- targetShots: Ge(),
882
+ incomingShots: nt(),
883
+ targetShots: nt(),
802
884
  sunkEnemyShips: [],
803
885
  pendingShot: null,
804
886
  lastShot: null,
@@ -819,30 +901,30 @@ function Rt(e, t, n = {}) {
819
901
  lastEventId: e.inviteEventId
820
902
  };
821
903
  if (t.accept_event_id === e.inviteEventId) return null;
822
- let s = e.ownId === e.hostId ? 0 : 1;
823
- if (e.myCommitment && a[s] && a[s] !== e.myCommitment && n.stored?.commitment !== a[s]) return null;
824
- let c = {
904
+ let o = e.ownId === e.hostId ? 0 : 1;
905
+ if (e.myCommitment && a[o] && a[o] !== e.myCommitment && n.stored?.commitment !== a[o]) return null;
906
+ let s = {
825
907
  ...r,
826
908
  status: "placement",
827
909
  acceptEventId: t.accept_event_id,
828
910
  lastEventId: t.accept_event_id
829
911
  };
830
- for (let [t, r] of [e.hostId, e.guestId].entries()) if (a[t] && (c = Tt(c, r, a[t], n.stored), !c)) return null;
831
- if (i.length && c.status !== "active") return null;
912
+ for (let [t, r] of [e.hostId, e.guestId].entries()) if (a[t] && (s = Ft(s, r, a[t], n.stored), !s)) return null;
913
+ if (i.length && s.status !== "active") return null;
832
914
  for (let e = 0; e < i.length; e += 1) {
833
915
  let t = i[e], n = e + 1;
834
- if (c = Et(c, Ye(c, n), {
916
+ if (s = It(s, ot(s, n), {
835
917
  row: t[0],
836
918
  col: t[1],
837
919
  ply: n
838
- }, null), !c) return null;
920
+ }, null), !s) return null;
839
921
  if (t.length === 2) {
840
922
  if (e !== i.length - 1) return null;
841
923
  break;
842
924
  }
843
- let r = Xe(c, c.pendingShot.by), a = null;
925
+ let r = st(s, s.pendingShot.by), a = null;
844
926
  if (t[2] === 2) {
845
- let e = o[t[3]];
927
+ let e = u[t[3]];
846
928
  if (!e) return null;
847
929
  let n = t[6] === 1;
848
930
  a = {
@@ -850,27 +932,27 @@ function Rt(e, t, n = {}) {
850
932
  cells: Array.from({ length: e.size }, (e, r) => [t[4] + (n ? r : 0), t[5] + (n ? 0 : r)])
851
933
  };
852
934
  }
853
- let s = qe(r === c.ownId ? c.incomingShots : c.targetShots) + (t[2] === 0 ? 0 : 1);
854
- if (c = Dt(c, r, {
935
+ let o = it(r === s.ownId ? s.incomingShots : s.targetShots) + (t[2] === 0 ? 0 : 1);
936
+ if (s = Lt(s, r, {
855
937
  ply: n,
856
938
  row: t[0],
857
939
  col: t[1],
858
940
  result: t[2] === 0 ? "miss" : "hit",
859
941
  sunk: a,
860
- defeated: s === ze
861
- }, null), !c || c.status === "won" && e !== i.length - 1) return null;
942
+ defeated: o === Xe
943
+ }, null), !s || s.status === "won" && e !== i.length - 1) return null;
862
944
  }
863
- return !i.length && t.head !== t.accept_event_id ? null : (c = {
864
- ...c,
945
+ return !i.length && t.head !== t.accept_event_id ? null : (s = {
946
+ ...s,
865
947
  lastEventId: t.head
866
- }, c.winnerId && e.winnerId === c.winnerId && (c = {
867
- ...c,
948
+ }, s.winnerId && e.winnerId === s.winnerId && (s = {
949
+ ...s,
868
950
  myRevealSent: e.myRevealSent,
869
951
  opponentReveal: e.opponentReveal,
870
952
  verification: e.verification
871
- }), c);
953
+ }), s);
872
954
  }
873
- function zt(e, t) {
955
+ function Yt(e, t) {
874
956
  if (!e || !t) return !1;
875
957
  let n = e.log?.[(t.data?.ply ?? 0) - 1];
876
958
  switch (t.type) {
@@ -881,37 +963,37 @@ function zt(e, t) {
881
963
  default: return !1;
882
964
  }
883
965
  }
884
- function Bt(e, t) {
966
+ function Xt(e, t) {
885
967
  let n = { ...e };
886
968
  return t.acceptEventId && (n[t.acceptEventId] = !0), t.lastEventId && (n[t.lastEventId] = !0), n;
887
969
  }
888
970
  // src/games/battleship/net/fleetStorage.js
889
- var Vt = "lira:bs:", Ht = 12096e5, Ut = (e, t) => `${Vt}${e}:${t}`, Wt = () => {
971
+ var Zt = "lira:bs:", Qt = 12096e5, $t = (e, t) => `${Zt}${e}:${t}`, en = () => {
890
972
  try {
891
973
  return globalThis.localStorage ?? null;
892
974
  } catch {
893
975
  return null;
894
976
  }
895
977
  };
896
- function Gt(e) {
978
+ function tn(e) {
897
979
  return typeof e == "object" && !!e && Array.isArray(e.fleet) && e.fleet.length === 5 && typeof e.salt == "string" && /^[0-9a-f]{32}$/.test(e.salt) && typeof e.commitment == "string" && /^[0-9a-f]{64}$/.test(e.commitment);
898
980
  }
899
- function Kt(e) {
981
+ function nn(e) {
900
982
  let t = Date.now();
901
983
  for (let n = e.length - 1; n >= 0; --n) {
902
984
  let r = e.key(n);
903
- if (r?.startsWith(Vt)) try {
985
+ if (r?.startsWith(Zt)) try {
904
986
  let n = JSON.parse(e.getItem(r));
905
- Gt(n) && t - n.savedAt < Ht || e.removeItem(r);
987
+ tn(n) && t - n.savedAt < Qt || e.removeItem(r);
906
988
  } catch {
907
989
  e.removeItem(r);
908
990
  }
909
991
  }
910
992
  }
911
- function qt(e, t, { fleet: n, salt: r, commitment: i }) {
993
+ function rn(e, t, { fleet: n, salt: r, commitment: i }) {
912
994
  try {
913
- let a = Wt();
914
- return a ? (Kt(a), a.setItem(Ut(e, t), JSON.stringify({
995
+ let a = en();
996
+ return a ? (nn(a), a.setItem($t(e, t), JSON.stringify({
915
997
  fleet: n,
916
998
  salt: r,
917
999
  commitment: i,
@@ -921,10 +1003,10 @@ function qt(e, t, { fleet: n, salt: r, commitment: i }) {
921
1003
  return !1;
922
1004
  }
923
1005
  }
924
- function Jt(e, t) {
1006
+ function an(e, t) {
925
1007
  try {
926
- let n = JSON.parse(Wt()?.getItem(Ut(e, t)) ?? "null");
927
- return Gt(n) ? {
1008
+ let n = JSON.parse(en()?.getItem($t(e, t)) ?? "null");
1009
+ return tn(n) ? {
928
1010
  fleet: n.fleet,
929
1011
  salt: n.salt,
930
1012
  commitment: n.commitment
@@ -934,20 +1016,20 @@ function Jt(e, t) {
934
1016
  }
935
1017
  }
936
1018
  // src/games/tanks/logic/constants.js
937
- var P = 1e5, Yt = 160 * P, F = 2 * P, Xt = 20 * P;
938
- 2 * P;
939
- var Zt = 1 * P;
940
- 4 * P, 4 * P;
941
- var Qt = 18e4, $t = 25e4, en = 5e4, I = 25e3, tn = 60 * P, nn = 4 * P, L = Object.freeze({
1019
+ var N = 1e5, on = 160 * N, P = 2 * N, sn = 20 * N;
1020
+ 2 * N;
1021
+ var cn = 1 * N;
1022
+ 4 * N, 4 * N;
1023
+ var ln = 18e4, un = 25e4, dn = 5e4, F = 25e3, fn = 60 * N, pn = 4 * N, I = Object.freeze({
942
1024
  move: Object.freeze([-16, 16]),
943
1025
  yaw: Object.freeze([0, 359]),
944
1026
  pitch: Object.freeze([5, 80]),
945
1027
  power: Object.freeze([0, 100])
946
- }), R = Object.freeze({
1028
+ }), L = Object.freeze({
947
1029
  standard: Object.freeze({
948
1030
  id: "standard",
949
1031
  cost: 0,
950
- radius: 6 * P,
1032
+ radius: 6 * N,
951
1033
  maxDmg: 40,
952
1034
  depth: 15e4,
953
1035
  speedPct: 100
@@ -955,7 +1037,7 @@ var Qt = 18e4, $t = 25e4, en = 5e4, I = 25e3, tn = 60 * P, nn = 4 * P, L = Objec
955
1037
  heavy: Object.freeze({
956
1038
  id: "heavy",
957
1039
  cost: 1,
958
- radius: 8 * P,
1040
+ radius: 8 * N,
959
1041
  maxDmg: 55,
960
1042
  depth: 25e4,
961
1043
  speedPct: 85
@@ -963,16 +1045,16 @@ var Qt = 18e4, $t = 25e4, en = 5e4, I = 25e3, tn = 60 * P, nn = 4 * P, L = Objec
963
1045
  cluster: Object.freeze({
964
1046
  id: "cluster",
965
1047
  cost: 1,
966
- radius: 4 * P,
1048
+ radius: 4 * N,
967
1049
  maxDmg: 15,
968
1050
  depth: 8e4,
969
1051
  speedPct: 100
970
1052
  })
971
- }), rn = Object.freeze({
972
- radius: 4 * P,
1053
+ }), mn = Object.freeze({
1054
+ radius: 4 * N,
973
1055
  maxDmg: 15,
974
1056
  depth: 8e4
975
- }), an = Object.freeze([
1057
+ }), hn = Object.freeze([
976
1058
  Object.freeze([
977
1059
  0,
978
1060
  0,
@@ -998,10 +1080,10 @@ var Qt = 18e4, $t = 25e4, en = 5e4, I = 25e3, tn = 60 * P, nn = 4 * P, L = Objec
998
1080
  0,
999
1081
  -6e3
1000
1082
  ])
1001
- ]), on = Object.freeze({
1083
+ ]), gn = Object.freeze({
1002
1084
  heavy: 2,
1003
1085
  cluster: 2
1004
- }), sn = Object.freeze([
1086
+ }), _n = Object.freeze([
1005
1087
  0,
1006
1088
  17452,
1007
1089
  34899,
@@ -1093,20 +1175,20 @@ var Qt = 18e4, $t = 25e4, en = 5e4, I = 25e3, tn = 60 * P, nn = 4 * P, L = Objec
1093
1175
  999391,
1094
1176
  999848,
1095
1177
  1e6
1096
- ]), cn = 1e6;
1097
- function ln(e) {
1178
+ ]), vn = 1e6;
1179
+ function yn(e) {
1098
1180
  let t = (e % 360 + 360) % 360;
1099
- return t <= 90 ? sn[t] : t <= 180 ? sn[180 - t] : t <= 270 ? -sn[t - 180] : -sn[360 - t];
1181
+ return t <= 90 ? _n[t] : t <= 180 ? _n[180 - t] : t <= 270 ? -_n[t - 180] : -_n[360 - t];
1100
1182
  }
1101
- function un(e) {
1102
- return ln(e + 90);
1183
+ function bn(e) {
1184
+ return yn(e + 90);
1103
1185
  }
1104
- function z(e, t) {
1105
- return Math.trunc(e * t / cn);
1186
+ function R(e, t) {
1187
+ return Math.trunc(e * t / vn);
1106
1188
  }
1107
1189
  // src/games/tanks/logic/rng.js
1108
- var dn = (e) => Number.isInteger(e) && e >= 0 && e <= 4294967295;
1109
- function fn(e) {
1190
+ var xn = (e) => Number.isInteger(e) && e >= 0 && e <= 4294967295;
1191
+ function Sn(e) {
1110
1192
  let t = e >>> 0;
1111
1193
  return function() {
1112
1194
  t = t + 1831565813 >>> 0;
@@ -1114,48 +1196,48 @@ function fn(e) {
1114
1196
  return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), (e ^ e >>> 14) >>> 0;
1115
1197
  };
1116
1198
  }
1117
- function B(e, t, n) {
1199
+ function z(e, t, n) {
1118
1200
  return t + e() % (n - t + 1);
1119
1201
  }
1120
- function pn(e, t) {
1121
- let n = fn((e ^ Math.imul(t, 2654435761)) >>> 0);
1202
+ function Cn(e, t) {
1203
+ let n = Sn((e ^ Math.imul(t, 2654435761)) >>> 0);
1122
1204
  return {
1123
- x: B(n, -40, 40),
1124
- z: B(n, -40, 40)
1205
+ x: z(n, -40, 40),
1206
+ z: z(n, -40, 40)
1125
1207
  };
1126
1208
  }
1127
1209
  // src/games/tanks/logic/terrain.js
1128
- var V = (e, t, n) => e < t ? t : e > n ? n : e, H = (e, t, n, r) => e + Math.trunc((t - e) * n / r);
1129
- function U(e, t, n) {
1130
- let r = V(t, 0, Yt), i = V(n, 0, Yt), a = Math.min(Math.trunc(r / F), 79), o = Math.min(Math.trunc(i / F), 79), s = r - a * F, c = i - o * F, l = o * 81;
1131
- return H(H(e[l + a], e[l + a + 1], s, F), H(e[l + 81 + a], e[l + 81 + a + 1], s, F), c, F);
1210
+ var B = (e, t, n) => e < t ? t : e > n ? n : e, V = (e, t, n, r) => e + Math.trunc((t - e) * n / r);
1211
+ function H(e, t, n) {
1212
+ let r = B(t, 0, on), i = B(n, 0, on), a = Math.min(Math.trunc(r / P), 79), o = Math.min(Math.trunc(i / P), 79), s = r - a * P, c = i - o * P, l = o * 81;
1213
+ return V(V(e[l + a], e[l + a + 1], s, P), V(e[l + 81 + a], e[l + 81 + a + 1], s, P), c, P);
1132
1214
  }
1133
- function mn(e, t, n, r) {
1215
+ function wn(e, t, n, r) {
1134
1216
  let i = Math.trunc(80 / t) + 1, a = [];
1135
- for (let t = 0; t < i * i; t += 1) a.push(B(e, n, r) * 1e3);
1217
+ for (let t = 0; t < i * i; t += 1) a.push(z(e, n, r) * 1e3);
1136
1218
  return {
1137
1219
  n: i,
1138
1220
  step: t,
1139
1221
  values: a
1140
1222
  };
1141
1223
  }
1142
- function hn({ n: e, step: t, values: n }, r, i) {
1224
+ function Tn({ n: e, step: t, values: n }, r, i) {
1143
1225
  let a = Math.min(Math.trunc(r / t), e - 2), o = Math.min(Math.trunc(i / t), e - 2), s = r - a * t, c = i - o * t, l = (t, r) => n[r * e + t];
1144
- return H(H(l(a, o), l(a + 1, o), s, t), H(l(a, o + 1), l(a + 1, o + 1), s, t), c, t);
1226
+ return V(V(l(a, o), l(a + 1, o), s, t), V(l(a, o + 1), l(a + 1, o + 1), s, t), c, t);
1145
1227
  }
1146
- function gn(e) {
1228
+ function En(e) {
1147
1229
  let t = new Int32Array(e.length);
1148
1230
  for (let n = 0; n < 81; n += 1) for (let r = 0; r < 81; r += 1) {
1149
1231
  let i = 0;
1150
- for (let t = -1; t <= 1; t += 1) for (let a = -1; a <= 1; a += 1) i += e[V(n + t, 0, 80) * 81 + V(r + a, 0, 80)];
1232
+ for (let t = -1; t <= 1; t += 1) for (let a = -1; a <= 1; a += 1) i += e[B(n + t, 0, 80) * 81 + B(r + a, 0, 80)];
1151
1233
  t[n * 81 + r] = Math.trunc(i / 9);
1152
1234
  }
1153
1235
  return t;
1154
1236
  }
1155
- function _n(e, t, n, r, i) {
1156
- let a = U(e, t, n), o = r * r, s = i * i;
1237
+ function Dn(e, t, n, r, i) {
1238
+ let a = H(e, t, n), o = r * r, s = i * i;
1157
1239
  for (let r = 0; r < 81; r += 1) for (let c = 0; c < 81; c += 1) {
1158
- let l = c * F - t, u = r * F - n;
1240
+ let l = c * P - t, u = r * P - n;
1159
1241
  if (l > i || l < -i || u > i || u < -i) continue;
1160
1242
  let d = l * l + u * u;
1161
1243
  if (d >= s) continue;
@@ -1167,44 +1249,44 @@ function _n(e, t, n, r, i) {
1167
1249
  }
1168
1250
  }
1169
1251
  }
1170
- var W = (e, t, n) => B(e, t, n) * (P / 2), vn = (e, t, n, r, i) => {
1252
+ var U = (e, t, n) => z(e, t, n) * (N / 2), On = (e, t, n, r, i) => {
1171
1253
  let a = e - n, o = t - r;
1172
1254
  return a > i || a < -i || o > i || o < -i ? !1 : a * a + o * o < i * i;
1173
- }, yn = (e, t, n, r) => t >= e.x - e.w / 2 - r && t <= e.x + e.w / 2 + r && n >= e.z - e.d / 2 - r && n <= e.z + e.d / 2 + r;
1174
- function bn(e) {
1175
- let t = fn(e), n = mn(t, 20, 0, 1200), r = mn(t, 10, -250, 250), i = mn(t, 4, -60, 60), a = /* @__PURE__ */ new Int32Array(6561);
1255
+ }, kn = (e, t, n, r) => t >= e.x - e.w / 2 - r && t <= e.x + e.w / 2 + r && n >= e.z - e.d / 2 - r && n <= e.z + e.d / 2 + r;
1256
+ function An(e) {
1257
+ let t = Sn(e), n = wn(t, 20, 0, 1200), r = wn(t, 10, -250, 250), i = wn(t, 4, -60, 60), a = /* @__PURE__ */ new Int32Array(6561);
1176
1258
  for (let e = 0; e < 81; e += 1) for (let t = 0; t < 81; t += 1) {
1177
- let o = 3 * P + hn(n, t, e) + hn(r, t, e) + hn(i, t, e);
1178
- a[e * 81 + t] = V(o, 0, Xt);
1259
+ let o = 3 * N + Tn(n, t, e) + Tn(r, t, e) + Tn(i, t, e);
1260
+ a[e * 81 + t] = B(o, 0, sn);
1179
1261
  }
1180
- a = gn(gn(a));
1262
+ a = En(En(a));
1181
1263
  let o = [{
1182
- x: 20 * P + W(t, -4, 4),
1183
- z: 80 * P + W(t, -40, 40)
1264
+ x: 20 * N + U(t, -4, 4),
1265
+ z: 80 * N + U(t, -40, 40)
1184
1266
  }, {
1185
- x: 140 * P + W(t, -4, 4),
1186
- z: 80 * P + W(t, -40, 40)
1267
+ x: 140 * N + U(t, -4, 4),
1268
+ z: 80 * N + U(t, -40, 40)
1187
1269
  }];
1188
- for (let e of o) _n(a, e.x, e.z, nn, nn + 3 * P);
1189
- let s = [], c = B(t, 4, 6);
1270
+ for (let e of o) Dn(a, e.x, e.z, pn, pn + 3 * N);
1271
+ let s = [], c = z(t, 4, 6);
1190
1272
  for (let e = 0; e < 200 && s.length < c; e += 1) {
1191
- let e = t() % 2 == 0 ? "rock" : "wall", n = W(t, 4, 12), r = W(t, 4, 12);
1192
- e === "wall" && (n >= r ? r = 2 * P : n = 2 * P);
1193
- let i = W(t, 4, 10), c = W(t, 100, 220), l = W(t, 40, 280), u = 12 * P + (n > r ? n : r);
1194
- if (o.some((e) => vn(e.x, e.z, c, l, u))) continue;
1273
+ let e = t() % 2 == 0 ? "rock" : "wall", n = U(t, 4, 12), r = U(t, 4, 12);
1274
+ e === "wall" && (n >= r ? r = 2 * N : n = 2 * N);
1275
+ let i = U(t, 4, 10), c = U(t, 100, 220), l = U(t, 40, 280), u = 12 * N + (n > r ? n : r);
1276
+ if (o.some((e) => On(e.x, e.z, c, l, u))) continue;
1195
1277
  let d = {
1196
1278
  x: c,
1197
1279
  z: l,
1198
1280
  w: n,
1199
1281
  d: r
1200
1282
  };
1201
- if (s.some((e) => yn(e, c, l, (n > r ? n : r) + 4e5))) continue;
1283
+ if (s.some((e) => kn(e, c, l, (n > r ? n : r) + 4e5))) continue;
1202
1284
  let f = [
1203
1285
  [-1, -1],
1204
1286
  [1, -1],
1205
1287
  [-1, 1],
1206
1288
  [1, 1]
1207
- ].map(([e, t]) => U(a, c + e * n / 2, l + t * r / 2)), p = Math.min(U(a, c, l), ...f);
1289
+ ].map(([e, t]) => H(a, c + e * n / 2, l + t * r / 2)), p = Math.min(H(a, c, l), ...f);
1208
1290
  s.push({
1209
1291
  id: s.length,
1210
1292
  kind: e,
@@ -1213,10 +1295,10 @@ function bn(e) {
1213
1295
  y: p
1214
1296
  });
1215
1297
  }
1216
- let l = [], u = B(t, 30, 60);
1298
+ let l = [], u = z(t, 30, 60);
1217
1299
  for (let e = 0; e < u * 10 && l.length < u; e += 1) {
1218
- let e = W(t, 4, 316), n = W(t, 4, 316), r = t() % 3 == 0 ? "rock" : "tree", i = B(t, 80, 140);
1219
- o.some((t) => vn(t.x, t.z, e, n, 1e6)) || s.some((t) => yn(t, e, n, 2e5)) || l.push({
1300
+ let e = U(t, 4, 316), n = U(t, 4, 316), r = t() % 3 == 0 ? "rock" : "tree", i = z(t, 80, 140);
1301
+ o.some((t) => On(t.x, t.z, e, n, 1e6)) || s.some((t) => kn(t, e, n, 2e5)) || l.push({
1220
1302
  id: l.length,
1221
1303
  kind: r,
1222
1304
  x: e,
@@ -1231,10 +1313,10 @@ function bn(e) {
1231
1313
  decor: l
1232
1314
  };
1233
1315
  }
1234
- function xn(e, { x: t, z: n, radius: r, depth: i }) {
1235
- let a = r * r, o = (e) => V(Math.trunc(e / F) - 1, 0, 80);
1316
+ function jn(e, { x: t, z: n, radius: r, depth: i }) {
1317
+ let a = r * r, o = (e) => B(Math.trunc(e / P) - 1, 0, 80);
1236
1318
  for (let s = o(n - r); s <= o(n + r) + 2 && s < 81; s += 1) for (let c = o(t - r); c <= o(t + r) + 2 && c < 81; c += 1) {
1237
- let o = c * F - t, l = s * F - n;
1319
+ let o = c * P - t, l = s * P - n;
1238
1320
  if (o > r || o < -r || l > r || l < -r) continue;
1239
1321
  let u = o * o + l * l;
1240
1322
  if (u >= a) continue;
@@ -1243,29 +1325,29 @@ function xn(e, { x: t, z: n, radius: r, depth: i }) {
1243
1325
  }
1244
1326
  return e;
1245
1327
  }
1246
- function Sn(e, t) {
1247
- return e.filter((e) => !t.some((t) => vn(t.x, t.z, e.x, e.z, t.radius)));
1328
+ function Mn(e, t) {
1329
+ return e.filter((e) => !t.some((t) => On(t.x, t.z, e.x, e.z, t.radius)));
1248
1330
  }
1249
1331
  // src/games/tanks/logic/ballistics.js
1250
- function Cn(e, t) {
1251
- return Math.trunc((2e4 + 600 * e) * R[t].speedPct / 100);
1332
+ function Nn(e, t) {
1333
+ return Math.trunc((2e4 + 600 * e) * L[t].speedPct / 100);
1252
1334
  }
1253
- function wn(e, { yaw: t, pitch: n, power: r, ammo: i }) {
1254
- let a = un(n), o = ln(n), s = un(t), c = ln(t), l = z($t, a), u = Cn(r, i), d = z(u, a);
1335
+ function Pn(e, { yaw: t, pitch: n, power: r, ammo: i }) {
1336
+ let a = bn(n), o = yn(n), s = bn(t), c = yn(t), l = R(un, a), u = Nn(r, i), d = R(u, a);
1255
1337
  return {
1256
- x: e.x + z(l, s),
1257
- y: e.y + Qt + z($t, o),
1258
- z: e.z + z(l, c),
1259
- vx: z(d, s),
1260
- vy: z(u, o),
1261
- vz: z(d, c)
1338
+ x: e.x + R(l, s),
1339
+ y: e.y + ln + R(un, o),
1340
+ z: e.z + R(l, c),
1341
+ vx: R(d, s),
1342
+ vy: R(u, o),
1343
+ vz: R(d, c)
1262
1344
  };
1263
1345
  }
1264
- function Tn(e, t, n, r, i, a, o) {
1346
+ function Fn(e, t, n, r, i, a, o) {
1265
1347
  let s = e - r, c = t - i, l = n - a;
1266
1348
  return s > o || s < -o || c > o || c < -o || l > o || l < -o ? !1 : s * s + c * c + l * l < o * o;
1267
1349
  }
1268
- function En(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600, split: o = !1 }) {
1350
+ function In(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600, split: o = !1 }) {
1269
1351
  let { x: s, y: c, z: l, vx: u, vy: d, vz: f } = e, p = [
1270
1352
  s,
1271
1353
  c,
@@ -1275,7 +1357,7 @@ function En(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
1275
1357
  let a = d;
1276
1358
  u += t.x, d -= 392, f += t.z, s += u, c += d, l += f;
1277
1359
  let m = null;
1278
- for (let e of r) if (Tn(s, c, l, e.x, e.y + 1e5, e.z, 2e5)) {
1360
+ for (let e of r) if (Fn(s, c, l, e.x, e.y + 1e5, e.z, 2e5)) {
1279
1361
  m = {
1280
1362
  x: s,
1281
1363
  y: c,
@@ -1286,7 +1368,7 @@ function En(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
1286
1368
  break;
1287
1369
  }
1288
1370
  if (!m) {
1289
- let e = i.find((e) => c <= e.y + e.h && yn(e, s, l, 0));
1371
+ let e = i.find((e) => c <= e.y + e.h && kn(e, s, l, 0));
1290
1372
  e && (m = {
1291
1373
  x: s,
1292
1374
  y: c,
@@ -1301,7 +1383,7 @@ function En(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
1301
1383
  z: l,
1302
1384
  kind: "out"
1303
1385
  }), !m) {
1304
- let e = U(n, s, l);
1386
+ let e = H(n, s, l);
1305
1387
  c <= e && (m = {
1306
1388
  x: s,
1307
1389
  y: e,
@@ -1342,7 +1424,7 @@ function En(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
1342
1424
  }
1343
1425
  };
1344
1426
  }
1345
- var Dn = (e, t, n, r) => ({
1427
+ var Ln = (e, t, n, r) => ({
1346
1428
  role: e,
1347
1429
  startTick: t,
1348
1430
  samples: n.samples,
@@ -1352,17 +1434,17 @@ var Dn = (e, t, n, r) => ({
1352
1434
  maxDmg: n.impact.kind === "split" ? 0 : r.maxDmg,
1353
1435
  depth: n.impact.kind === "split" ? 0 : r.depth
1354
1436
  });
1355
- function On(e, t, n) {
1356
- let r = wn(e, t);
1357
- if (t.ammo !== "cluster") return [Dn("main", 0, En(r, n), R[t.ammo])];
1358
- let i = En(r, {
1437
+ function Rn(e, t, n) {
1438
+ let r = Pn(e, t);
1439
+ if (t.ammo !== "cluster") return [Ln("main", 0, In(r, n), L[t.ammo])];
1440
+ let i = In(r, {
1359
1441
  ...n,
1360
1442
  split: !0
1361
- }), a = [Dn("carrier", 0, i, rn)];
1443
+ }), a = [Ln("carrier", 0, i, mn)];
1362
1444
  if (i.impact.kind !== "split") return a;
1363
1445
  let o = (n.maxTicks ?? 600) - i.ticks;
1364
- for (let [e, t, r] of an) {
1365
- let { x: s, y: c, z: l } = i.impact, { vx: u, vy: d, vz: f } = i.velocity, p = En({
1446
+ for (let [e, t, r] of hn) {
1447
+ let { x: s, y: c, z: l } = i.impact, { vx: u, vy: d, vz: f } = i.velocity, p = In({
1366
1448
  x: s,
1367
1449
  y: c,
1368
1450
  z: l,
@@ -1374,18 +1456,18 @@ function On(e, t, n) {
1374
1456
  maxTicks: o,
1375
1457
  split: !1
1376
1458
  });
1377
- a.push(Dn("bomblet", i.ticks, p, rn));
1459
+ a.push(Ln("bomblet", i.ticks, p, mn));
1378
1460
  }
1379
1461
  return a;
1380
1462
  }
1381
- function kn(e, t) {
1463
+ function zn(e, t) {
1382
1464
  let n = t.map(() => 0);
1383
1465
  for (let r of e) {
1384
1466
  let { impact: e, radius: i, maxDmg: a } = r;
1385
1467
  if (e.kind === "out" || e.kind === "split") continue;
1386
1468
  let o = i * i;
1387
1469
  t.forEach((t, r) => {
1388
- let s = t.y + Zt;
1470
+ let s = t.y + cn;
1389
1471
  e.kind === "tank" && e.tankId === t.id && (n[r] += 25);
1390
1472
  let c = e.x - t.x, l = e.y - s, u = e.z - t.z;
1391
1473
  if (c >= i || c <= -i || l >= i || l <= -i || u >= i || u <= -i) return;
@@ -1395,7 +1477,7 @@ function kn(e, t) {
1395
1477
  }
1396
1478
  return n;
1397
1479
  }
1398
- function An(e) {
1480
+ function Bn(e) {
1399
1481
  return e.filter((e) => e.impact.kind !== "out" && e.impact.kind !== "split").map((e) => ({
1400
1482
  x: e.impact.x,
1401
1483
  z: e.impact.z,
@@ -1404,8 +1486,8 @@ function An(e) {
1404
1486
  }));
1405
1487
  }
1406
1488
  // src/games/tanks/logic/movement.js
1407
- function jn(e, t, { heights: n, obstacles: r, others: i }) {
1408
- let a = t < 0 ? -1 : 1, o = (t < 0 ? -t : t) * (en / I), s = Math.min(o, Math.trunc(e.fuel / I)), c = a * z(I, un(e.hullYaw)), l = a * z(I, ln(e.hullYaw)), { x: u, z: d } = e, f = U(n, u, d), p = [{
1489
+ function Vn(e, t, { heights: n, obstacles: r, others: i }) {
1490
+ let a = t < 0 ? -1 : 1, o = (t < 0 ? -t : t) * (dn / F), s = Math.min(o, Math.trunc(e.fuel / F)), c = a * R(F, bn(e.hullYaw)), l = a * R(F, yn(e.hullYaw)), { x: u, z: d } = e, f = H(n, u, d), p = [{
1409
1491
  x: u,
1410
1492
  y: f,
1411
1493
  z: d
@@ -1416,7 +1498,7 @@ function jn(e, t, { heights: n, obstacles: r, others: i }) {
1416
1498
  h = "border";
1417
1499
  break;
1418
1500
  }
1419
- if (r.some((n) => yn(n, e, t, 2e5))) {
1501
+ if (r.some((n) => kn(n, e, t, 2e5))) {
1420
1502
  h = "obstacle";
1421
1503
  break;
1422
1504
  }
@@ -1427,7 +1509,7 @@ function jn(e, t, { heights: n, obstacles: r, others: i }) {
1427
1509
  h = "tank";
1428
1510
  break;
1429
1511
  }
1430
- let a = U(n, e, t);
1512
+ let a = H(n, e, t);
1431
1513
  if ((a > f ? a - f : f - a) * 1e3 > 175e5) {
1432
1514
  h = "slope";
1433
1515
  break;
@@ -1447,29 +1529,29 @@ function jn(e, t, { heights: n, obstacles: r, others: i }) {
1447
1529
  x: u,
1448
1530
  y: f,
1449
1531
  z: d,
1450
- used: m * I,
1532
+ used: m * F,
1451
1533
  stop: h
1452
1534
  };
1453
1535
  }
1454
1536
  // src/games/tanks/logic/game.js
1455
- var Mn = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, G = (e) => ({
1537
+ var Hn = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, W = (e) => ({
1456
1538
  ok: !1,
1457
1539
  reason: e
1458
- }), Nn = (e, [t, n]) => Number.isInteger(e) && e >= t && e <= n;
1459
- function Pn({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {}) {
1460
- if (!Mn(e) || !Array.isArray(t) || t.length !== 2 || !t.every(Mn) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
1461
- if (!dn(r)) throw TypeError("Supply an integer seed in 0..0xffffffff.");
1462
- let { heights: i, spawns: a, obstacles: o, decor: s } = bn(r), c = t.map((e, t) => ({
1540
+ }), Un = (e, [t, n]) => Number.isInteger(e) && e >= t && e <= n;
1541
+ function Wn({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {}) {
1542
+ if (!Hn(e) || !Array.isArray(t) || t.length !== 2 || !t.every(Hn) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
1543
+ if (!xn(r)) throw TypeError("Supply an integer seed in 0..0xffffffff.");
1544
+ let { heights: i, spawns: a, obstacles: o, decor: s } = An(r), c = t.map((e, t) => ({
1463
1545
  id: e,
1464
1546
  x: a[t].x,
1465
- y: U(i, a[t].x, a[t].z),
1547
+ y: H(i, a[t].x, a[t].z),
1466
1548
  z: a[t].z,
1467
1549
  hullYaw: t === 0 ? 0 : 180,
1468
1550
  yaw: t === 0 ? 0 : 180,
1469
1551
  pitch: 30,
1470
1552
  hp: 100,
1471
- fuel: tn,
1472
- ammo: { ...on },
1553
+ fuel: fn,
1554
+ ammo: { ...gn },
1473
1555
  skips: 0
1474
1556
  }));
1475
1557
  return {
@@ -1495,24 +1577,24 @@ function Pn({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {})
1495
1577
  revision: 0
1496
1578
  };
1497
1579
  }
1498
- function Fn(e, t) {
1499
- return !e || !t || typeof t != "object" ? G("invalid_action") : e.phase === "finished" ? G("game_finished") : t.gameId !== void 0 && t.gameId !== e.gameId ? G("wrong_game") : t.expectedRevision !== void 0 && t.expectedRevision !== e.revision ? G("stale_revision") : e.players.includes(t.playerId) ? { ok: !0 } : G("unknown_player");
1580
+ function Gn(e, t) {
1581
+ return !e || !t || typeof t != "object" ? W("invalid_action") : e.phase === "finished" ? W("game_finished") : t.gameId !== void 0 && t.gameId !== e.gameId ? W("wrong_game") : t.expectedRevision !== void 0 && t.expectedRevision !== e.revision ? W("stale_revision") : e.players.includes(t.playerId) ? { ok: !0 } : W("unknown_player");
1500
1582
  }
1501
- function In(e, t) {
1502
- let n = Fn(e, t);
1583
+ function Kn(e, t) {
1584
+ let n = Gn(e, t);
1503
1585
  if (!n.ok) return n;
1504
1586
  let r = e.players.indexOf(t.playerId);
1505
- if (r !== e.turnIndex) return G("not_your_turn");
1506
- if (!Nn(t.move, L.move)) return G("invalid_move");
1507
- if (!Nn(t.yaw, L.yaw)) return G("invalid_yaw");
1508
- if (!Nn(t.pitch, L.pitch)) return G("invalid_pitch");
1509
- if (!Nn(t.power, L.power)) return G("invalid_power");
1510
- if (typeof t.ammo != "string" || !Object.hasOwn(R, t.ammo)) return G("unknown_ammo");
1511
- let i = R[t.ammo].cost;
1512
- return i > 0 && e.tanks[r].ammo[t.ammo] < i ? G("out_of_ammo") : { ok: !0 };
1513
- }
1514
- function Ln(e, t, { maxTicks: n = 600 } = {}) {
1515
- let r = e.players.indexOf(t.playerId), i = e.tanks[r], a = e.tanks[1 - r], o = pn(e.seed, e.ply), s = jn(i, t.move ?? 0, {
1587
+ if (r !== e.turnIndex) return W("not_your_turn");
1588
+ if (!Un(t.move, I.move)) return W("invalid_move");
1589
+ if (!Un(t.yaw, I.yaw)) return W("invalid_yaw");
1590
+ if (!Un(t.pitch, I.pitch)) return W("invalid_pitch");
1591
+ if (!Un(t.power, I.power)) return W("invalid_power");
1592
+ if (typeof t.ammo != "string" || !Object.hasOwn(L, t.ammo)) return W("unknown_ammo");
1593
+ let i = L[t.ammo].cost;
1594
+ return i > 0 && e.tanks[r].ammo[t.ammo] < i ? W("out_of_ammo") : { ok: !0 };
1595
+ }
1596
+ function qn(e, t, { maxTicks: n = 600 } = {}) {
1597
+ let r = e.players.indexOf(t.playerId), i = e.tanks[r], a = e.tanks[1 - r], o = Cn(e.seed, e.ply), s = Vn(i, t.move ?? 0, {
1516
1598
  heights: e.heights,
1517
1599
  obstacles: e.obstacles,
1518
1600
  others: [a]
@@ -1528,13 +1610,13 @@ function Ln(e, t, { maxTicks: n = 600 } = {}) {
1528
1610
  x: e.x,
1529
1611
  y: e.y,
1530
1612
  z: e.z
1531
- }), u = On(c, t, {
1613
+ }), u = Rn(c, t, {
1532
1614
  wind: o,
1533
1615
  heights: e.heights,
1534
1616
  tanks: l,
1535
1617
  obstacles: e.obstacles,
1536
1618
  maxTicks: n
1537
- }), d = kn(u, l), f = {};
1619
+ }), d = zn(u, l), f = {};
1538
1620
  return e.players.forEach((e, t) => {
1539
1621
  f[e] = d[t];
1540
1622
  }), {
@@ -1545,11 +1627,11 @@ function Ln(e, t, { maxTicks: n = 600 } = {}) {
1545
1627
  tankAfter: c,
1546
1628
  shots: u,
1547
1629
  damage: f,
1548
- craters: An(u),
1630
+ craters: Bn(u),
1549
1631
  wind: o
1550
1632
  };
1551
1633
  }
1552
- function Rn(e, t, n, r) {
1634
+ function G(e, t, n, r) {
1553
1635
  return {
1554
1636
  ...e,
1555
1637
  ...r,
@@ -1560,7 +1642,7 @@ function Rn(e, t, n, r) {
1560
1642
  revision: e.revision + 1
1561
1643
  };
1562
1644
  }
1563
- function zn(e, t) {
1645
+ function Jn(e, t) {
1564
1646
  let n = e.turnIndex, r = {
1565
1647
  playerId: t.playerId,
1566
1648
  move: t.move,
@@ -1568,23 +1650,23 @@ function zn(e, t) {
1568
1650
  pitch: t.pitch,
1569
1651
  power: t.power,
1570
1652
  ammo: t.ammo
1571
- }, i = Ln(e, r), a = e.heights;
1653
+ }, i = qn(e, r), a = e.heights;
1572
1654
  if (i.craters.length) {
1573
1655
  a = Int32Array.from(e.heights);
1574
- for (let e of i.craters) xn(a, e);
1656
+ for (let e of i.craters) jn(a, e);
1575
1657
  }
1576
- let o = i.craters.length ? Sn(e.decor, i.craters) : e.decor, s = e.tanks.map((e, t) => {
1658
+ let o = i.craters.length ? Mn(e.decor, i.craters) : e.decor, s = e.tanks.map((e, t) => {
1577
1659
  let o = t === n ? i.tankAfter : e, s = {
1578
1660
  ...e,
1579
1661
  ammo: { ...e.ammo },
1580
1662
  x: o.x,
1581
1663
  z: o.z,
1582
- y: U(a, o.x, o.z),
1664
+ y: H(a, o.x, o.z),
1583
1665
  hp: Math.max(0, e.hp - i.damage[e.id])
1584
1666
  };
1585
1667
  if (t === n) {
1586
1668
  s.fuel = e.fuel - i.fuelUsed, s.yaw = r.yaw, s.pitch = r.pitch, s.skips = 0;
1587
- let t = R[r.ammo].cost;
1669
+ let t = L[r.ammo].cost;
1588
1670
  t > 0 && (s.ammo[r.ammo] -= t);
1589
1671
  }
1590
1672
  return s;
@@ -1603,23 +1685,23 @@ function zn(e, t) {
1603
1685
  ...i
1604
1686
  }
1605
1687
  }, l = s.map((e) => e.hp === 0);
1606
- if (l[0] && l[1]) return Rn(c, -1, "destroyed");
1607
- if (l[0] || l[1]) return Rn(c, +!!l[0], "destroyed");
1688
+ if (l[0] && l[1]) return G(c, -1, "destroyed");
1689
+ if (l[0] || l[1]) return G(c, +!!l[0], "destroyed");
1608
1690
  if (c.shots >= c.maxShots) {
1609
1691
  let [e, t] = s.map((e) => e.hp);
1610
- return Rn(c, e === t ? -1 : e > t ? 0 : 1, "max_shots");
1692
+ return G(c, e === t ? -1 : e > t ? 0 : 1, "max_shots");
1611
1693
  }
1612
1694
  return {
1613
1695
  ...c,
1614
1696
  revision: e.revision + 1
1615
1697
  };
1616
1698
  }
1617
- function Bn(e, t) {
1699
+ function Yn(e, t) {
1618
1700
  if (!t || typeof t != "object") return e;
1619
- if (t.type === "turn") return In(e, t).ok ? zn(e, t) : e;
1620
- if (!Fn(e, t).ok) return e;
1701
+ if (t.type === "turn") return Kn(e, t).ok ? Jn(e, t) : e;
1702
+ if (!Gn(e, t).ok) return e;
1621
1703
  let n = e.players.indexOf(t.playerId);
1622
- if (t.type === "resign") return Rn(e, 1 - n, "resign");
1704
+ if (t.type === "resign") return G(e, 1 - n, "resign");
1623
1705
  if (t.type === "skip") {
1624
1706
  if (n !== e.turnIndex || t.reason !== void 0 && t.reason !== "timeout") return e;
1625
1707
  let r = e.tanks[n].skips + 1, i = e.tanks.map((e, t) => t === n ? {
@@ -1636,22 +1718,22 @@ function Bn(e, t) {
1636
1718
  playerId: t.playerId
1637
1719
  }
1638
1720
  };
1639
- return r >= 3 ? Rn(a, 1 - n, "timeout") : {
1721
+ return r >= 3 ? G(a, 1 - n, "timeout") : {
1640
1722
  ...a,
1641
1723
  revision: e.revision + 1
1642
1724
  };
1643
1725
  }
1644
1726
  return e;
1645
1727
  }
1646
- function Vn(e, t) {
1728
+ function Xn(e, t) {
1647
1729
  let n = (e.lo ^ t) >>> 0, r = n * 435, i = r >>> 0, a = (r - i) / 4294967296;
1648
1730
  e.hi = Math.imul(e.hi, 435) + a + (n << 8) >>> 0, e.lo = i;
1649
1731
  }
1650
- function Hn(e, t) {
1732
+ function Zn(e, t) {
1651
1733
  let n = t | 0;
1652
- Vn(e, n & 255), Vn(e, n >>> 8 & 255), Vn(e, n >>> 16 & 255), Vn(e, n >>> 24 & 255);
1734
+ Xn(e, n & 255), Xn(e, n >>> 8 & 255), Xn(e, n >>> 16 & 255), Xn(e, n >>> 24 & 255);
1653
1735
  }
1654
- function Un(e) {
1736
+ function Qn(e) {
1655
1737
  let t = {
1656
1738
  hi: 3421674724,
1657
1739
  lo: 2216829733
@@ -1668,11 +1750,11 @@ function Un(e) {
1668
1750
  ];
1669
1751
  for (let t of e.tanks) i.push(t.x, t.y, t.z, t.hp, t.fuel, t.ammo.heavy, t.ammo.cluster, t.skips, t.yaw, t.pitch);
1670
1752
  i.push(n, e.decor.length);
1671
- for (let e of i) Hn(t, e);
1753
+ for (let e of i) Zn(t, e);
1672
1754
  return t.hi.toString(16).padStart(8, "0") + t.lo.toString(16).padStart(8, "0");
1673
1755
  }
1674
1756
  // src/games/tanks/net/sha256.js
1675
- var Wn = new Uint32Array([
1757
+ var $n = new Uint32Array([
1676
1758
  1116352408,
1677
1759
  1899447441,
1678
1760
  3049323471,
@@ -1738,7 +1820,7 @@ var Wn = new Uint32Array([
1738
1820
  3204031479,
1739
1821
  3329325298
1740
1822
  ]), K = (e, t) => e >>> t | e << 32 - t;
1741
- function Gn(e) {
1823
+ function er(e) {
1742
1824
  let t = new TextEncoder().encode(String(e)), n = t.length, r = new Uint8Array((n + 9 >> 6) + 1 << 6);
1743
1825
  r.set(t), r[n] = 128;
1744
1826
  let i = new DataView(r.buffer);
@@ -1761,7 +1843,7 @@ function Gn(e) {
1761
1843
  }
1762
1844
  let [t, n, r, s, c, l, u, d] = a;
1763
1845
  for (let e = 0; e < 64; e += 1) {
1764
- let i = d + (K(c, 6) ^ K(c, 11) ^ K(c, 25)) + (c & l ^ ~c & u) + Wn[e] + o[e] >>> 0, a = (K(t, 2) ^ K(t, 13) ^ K(t, 22)) + (t & n ^ t & r ^ n & r) >>> 0;
1846
+ let i = d + (K(c, 6) ^ K(c, 11) ^ K(c, 25)) + (c & l ^ ~c & u) + $n[e] + o[e] >>> 0, a = (K(t, 2) ^ K(t, 13) ^ K(t, 22)) + (t & n ^ t & r ^ n & r) >>> 0;
1765
1847
  d = u, u = l, l = c, c = s + i >>> 0, s = r, r = n, n = t, t = i + a >>> 0;
1766
1848
  }
1767
1849
  a[0] += t, a[1] += n, a[2] += r, a[3] += s, a[4] += c, a[5] += l, a[6] += u, a[7] += d;
@@ -1769,22 +1851,22 @@ function Gn(e) {
1769
1851
  return Array.from(a, (e) => e.toString(16).padStart(8, "0")).join("");
1770
1852
  }
1771
1853
  // src/games/tanks/net/session.js
1772
- var Kn = "La partida perdió sincronización. Se intentará resincronizar.", qn = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", Jn = "El rival reveló una semilla que no coincide con su invitación.", Yn = "Los resultados del disparo no coinciden entre dispositivos.", Xn = [
1854
+ var tr = "La partida perdió sincronización. Se intentará resincronizar.", nr = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", rr = "El rival reveló una semilla que no coincide con su invitación.", ir = "Los resultados del disparo no coinciden entre dispositivos.", ar = [
1773
1855
  "won",
1774
1856
  "draw",
1775
1857
  "closed",
1776
1858
  "declined"
1777
- ], Zn = (e, t) => ({
1859
+ ], q = (e, t) => ({
1778
1860
  ...e,
1779
1861
  status: "conflict",
1780
1862
  error: t
1781
- }), Qn = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
1782
- function $n() {
1863
+ }), or = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
1864
+ function sr() {
1783
1865
  let e = /* @__PURE__ */ new Uint8Array(16);
1784
- return globalThis.crypto.getRandomValues(e), Qn(e);
1866
+ return globalThis.crypto.getRandomValues(e), or(e);
1785
1867
  }
1786
- var er = (e) => Gn(`lira-tanks-seed:${e}`), tr = (e, t) => parseInt(Gn(`lira-tanks-map:${e}:${t}`).slice(0, 8), 16) >>> 0;
1787
- function nr(e, t) {
1868
+ var cr = (e) => er(`lira-tanks-seed:${e}`), lr = (e, t) => parseInt(er(`lira-tanks-map:${e}:${t}`).slice(0, 8), 16) >>> 0;
1869
+ function ur(e, t) {
1788
1870
  let n = t.first_player_id === e.guestId ? e.guestId : e.hostId;
1789
1871
  return {
1790
1872
  ...e,
@@ -1811,21 +1893,21 @@ function nr(e, t) {
1811
1893
  sync: e.sync ?? null
1812
1894
  };
1813
1895
  }
1814
- var q = (e) => [e.hostId, e.guestId], rr = (e) => e.logic && e.logic.phase === "playing" ? q(e)[e.logic.turnIndex] : null, ir = (e) => e?.status === "active" && !e.pendingEvent && rr(e) === e.ownId, ar = (e, t, n) => e === "tk_turn" ? [
1896
+ var J = (e) => [e.hostId, e.guestId], dr = (e) => e.logic && e.logic.phase === "playing" ? J(e)[e.logic.turnIndex] : null, fr = (e) => e?.status === "active" && !e.pendingEvent && dr(e) === e.ownId, pr = (e, t, n) => e === "tk_turn" ? [
1815
1897
  1,
1816
1898
  t.move,
1817
1899
  t.yaw,
1818
1900
  t.pitch,
1819
1901
  t.power,
1820
1902
  t.ammo
1821
- ] : e === "tk_skip" ? [2] : [3, n], or = (e, t) => e.length === t.length && e.every((e, n) => e === t[n]);
1822
- function sr(e, t) {
1823
- let n = q(e);
1903
+ ] : e === "tk_skip" ? [2] : [3, n], mr = (e, t) => e.length === t.length && e.every((e, n) => e === t[n]);
1904
+ function hr(e, t) {
1905
+ let n = J(e);
1824
1906
  if (t[0] === 3) return {
1825
1907
  type: "resign",
1826
1908
  playerId: n[t[1]]
1827
1909
  };
1828
- let r = rr(e);
1910
+ let r = dr(e);
1829
1911
  return t[0] === 2 ? {
1830
1912
  type: "skip",
1831
1913
  playerId: r,
@@ -1837,11 +1919,11 @@ function sr(e, t) {
1837
1919
  yaw: t[2],
1838
1920
  pitch: t[3],
1839
1921
  power: t[4],
1840
- ammo: E[t[5]]
1922
+ ammo: he[t[5]]
1841
1923
  };
1842
1924
  }
1843
- function cr(e, t, n, r) {
1844
- let i = Bn(e.logic, sr(e, t));
1925
+ function gr(e, t, n, r) {
1926
+ let i = Yn(e.logic, hr(e, t));
1845
1927
  if (i === e.logic) return null;
1846
1928
  let a = i.phase === "finished";
1847
1929
  return {
@@ -1856,19 +1938,19 @@ function cr(e, t, n, r) {
1856
1938
  author: r,
1857
1939
  turn: i.lastTurn ?? null
1858
1940
  },
1859
- turnId: a ? null : q(e)[i.turnIndex],
1941
+ turnId: a ? null : J(e)[i.turnIndex],
1860
1942
  status: a ? i.result === "draw" ? "draw" : "won" : "active",
1861
1943
  winnerId: i.winnerId ?? null,
1862
1944
  result: i.result ?? null
1863
1945
  };
1864
1946
  }
1865
- function lr(e, t, n) {
1866
- if (er(t) !== e.seedCommit) return null;
1867
- let r = Pn({
1947
+ function _r(e, t, n) {
1948
+ if (cr(t) !== e.seedCommit) return null;
1949
+ let r = Wn({
1868
1950
  gameId: e.gameId,
1869
- players: q(e),
1951
+ players: J(e),
1870
1952
  firstPlayerId: e.firstPlayerId,
1871
- seed: tr(t, e.seedB)
1953
+ seed: lr(t, e.seedB)
1872
1954
  });
1873
1955
  return {
1874
1956
  ...e,
@@ -1880,11 +1962,11 @@ function lr(e, t, n) {
1880
1962
  lastEventId: n,
1881
1963
  lastAction: null,
1882
1964
  status: "active",
1883
- turnId: q(e)[r.turnIndex],
1965
+ turnId: J(e)[r.turnIndex],
1884
1966
  error: ""
1885
1967
  };
1886
1968
  }
1887
- function ur(e, t, n) {
1969
+ function vr(e, t, n) {
1888
1970
  if (![e.hostId, e.guestId].includes(n)) return e;
1889
1971
  let r = t.data;
1890
1972
  if (t.type === "game_end") return ["closed", "declined"].includes(e.status) ? e : {
@@ -1893,7 +1975,7 @@ function ur(e, t, n) {
1893
1975
  closedBy: n,
1894
1976
  error: ""
1895
1977
  };
1896
- if (Xn.includes(e.status) || e.status === "conflict") return e;
1978
+ if (ar.includes(e.status) || e.status === "conflict") return e;
1897
1979
  if (t.type === "game_accept" || t.type === "game_decline") return n !== e.guestId || e.status !== "invited" || r.invite_event_id !== e.inviteEventId ? e : t.type === "game_decline" ? {
1898
1980
  ...e,
1899
1981
  status: "declined",
@@ -1905,22 +1987,22 @@ function ur(e, t, n) {
1905
1987
  acceptEventId: t.event_id,
1906
1988
  lastEventId: t.event_id
1907
1989
  };
1908
- if (t.type === "tk_seed") return n !== e.hostId || e.status !== "seeding" ? e : lr(e, r.seed_a, t.event_id) ?? Zn(e, Jn);
1990
+ if (t.type === "tk_seed") return n !== e.hostId || e.status !== "seeding" ? e : _r(e, r.seed_a, t.event_id) ?? q(e, rr);
1909
1991
  if (![
1910
1992
  "tk_turn",
1911
1993
  "tk_skip",
1912
1994
  "tk_resign"
1913
1995
  ].includes(t.type)) return e;
1914
- if (e.status !== "active") return Zn(e, qn);
1915
- let i = q(e).indexOf(n), a = ar(t.type, r, i);
1916
- if (r.ply <= e.ply) return or(e.log[r.ply - 1] ?? [], a) ? e : Zn(e, Kn);
1917
- if (r.ply > e.ply + 1 || r.prev_event_id !== e.lastEventId) return Zn(e, Kn);
1918
- if (t.type !== "tk_resign" && n !== rr(e)) return e;
1919
- let o = cr(e, a, t.event_id, n);
1920
- return o ? t.type === "tk_turn" && Un(o.logic) !== r.hash ? Zn(e, Yn) : o : e;
1921
- }
1922
- function dr(e, t) {
1923
- if (!ir(e)) return null;
1996
+ if (e.status !== "active") return q(e, nr);
1997
+ let i = J(e).indexOf(n), a = pr(t.type, r, i);
1998
+ if (r.ply <= e.ply) return mr(e.log[r.ply - 1] ?? [], a) ? e : q(e, tr);
1999
+ if (r.ply > e.ply + 1 || r.prev_event_id !== e.lastEventId) return q(e, tr);
2000
+ if (t.type !== "tk_resign" && n !== dr(e)) return e;
2001
+ let o = gr(e, a, t.event_id, n);
2002
+ return o ? t.type === "tk_turn" && Qn(o.logic) !== r.hash ? q(e, ir) : o : e;
2003
+ }
2004
+ function yr(e, t) {
2005
+ if (!fr(e)) return null;
1924
2006
  let n = {
1925
2007
  ply: e.ply + 1,
1926
2008
  prev_event_id: e.lastEventId,
@@ -1928,16 +2010,16 @@ function dr(e, t) {
1928
2010
  yaw: t.yaw,
1929
2011
  pitch: t.pitch,
1930
2012
  power: t.power,
1931
- ammo: E.indexOf(t.ammo)
2013
+ ammo: he.indexOf(t.ammo)
1932
2014
  };
1933
2015
  if (n.ammo < 0) return null;
1934
- let r = cr(e, ar("tk_turn", n), "local", e.ownId);
2016
+ let r = gr(e, pr("tk_turn", n), "local", e.ownId);
1935
2017
  return r ? {
1936
2018
  ...n,
1937
- hash: Un(r.logic)
2019
+ hash: Qn(r.logic)
1938
2020
  } : null;
1939
2021
  }
1940
- function fr(e) {
2022
+ function br(e) {
1941
2023
  let t = {
1942
2024
  log: e.log ?? [],
1943
2025
  head: e.lastEventId
@@ -1950,14 +2032,14 @@ function fr(e) {
1950
2032
  seed_event_id: e.seedEventId
1951
2033
  }), t;
1952
2034
  }
1953
- function pr(e, t) {
2035
+ function xr(e, t) {
1954
2036
  if (e.accept_event_id && t.accept_event_id && e.accept_event_id !== t.accept_event_id || e.seed_a && t.seed_a && e.seed_a !== t.seed_a) return "diverged";
1955
2037
  let n = Math.min(e.log.length, t.log.length);
1956
- for (let r = 0; r < n; r += 1) if (!or(e.log[r], t.log[r])) return "diverged";
2038
+ for (let r = 0; r < n; r += 1) if (!mr(e.log[r], t.log[r])) return "diverged";
1957
2039
  let r = (e) => (e.seed_a ? 2 : +!!e.accept_event_id) * 1e3 + e.log.length;
1958
2040
  return r(e) === r(t) ? e.log.length === t.log.length && e.head !== t.head && e.log.length > 0 ? "diverged" : "equal" : r(e) < r(t) ? "behind" : "ahead";
1959
2041
  }
1960
- function mr(e, t) {
2042
+ function Sr(e, t) {
1961
2043
  let n = {
1962
2044
  ...e,
1963
2045
  status: "invited",
@@ -1987,16 +2069,16 @@ function mr(e, t) {
1987
2069
  seedB: t.seed_b,
1988
2070
  lastEventId: t.accept_event_id
1989
2071
  }, !t.seed_a) return n;
1990
- if (n = lr(n, t.seed_a, t.seed_event_id), !n) return null;
2072
+ if (n = _r(n, t.seed_a, t.seed_event_id), !n) return null;
1991
2073
  for (let e = 0; e < t.log.length; e += 1) {
1992
2074
  let r = t.log[e];
1993
- if (!se(r)) return null;
1994
- let i = e === t.log.length - 1, a = r[0] === 3 ? q(n)[r[1]] : rr(n);
1995
- if (n = cr(n, r, i ? t.head : `${t.seed_event_id}:${e + 1}`, a), !n) return null;
2075
+ if (!ve(r)) return null;
2076
+ let i = e === t.log.length - 1, a = r[0] === 3 ? J(n)[r[1]] : dr(n);
2077
+ if (n = gr(n, r, i ? t.head : `${t.seed_event_id}:${e + 1}`, a), !n) return null;
1996
2078
  }
1997
2079
  return n;
1998
2080
  }
1999
- function hr(e, t) {
2081
+ function Cr(e, t) {
2000
2082
  if (!t) return !1;
2001
2083
  if (t.type === "tk_seed") return e.seed_a === t.data.seed_a;
2002
2084
  if (t.type === "game_accept") return e.accept_event_id === t.event_id;
@@ -2006,9 +2088,9 @@ function hr(e, t) {
2006
2088
  "tk_resign"
2007
2089
  ].includes(t.type)) return !1;
2008
2090
  let n = e.log[t.data.ply - 1];
2009
- return !!n && n[0] === ar(t.type, t.data, 0)[0];
2091
+ return !!n && n[0] === pr(t.type, t.data, 0)[0];
2010
2092
  }
2011
- function gr(e, t) {
2093
+ function wr(e, t) {
2012
2094
  let n = { ...e };
2013
2095
  return [
2014
2096
  t.acceptEventId,
@@ -2018,7 +2100,7 @@ function gr(e, t) {
2018
2100
  e && (n[e] = !0);
2019
2101
  }), n;
2020
2102
  }
2021
- function _r(e) {
2103
+ function Tr(e) {
2022
2104
  return {
2023
2105
  gameId: e.gameId,
2024
2106
  roomId: e.roomId,
@@ -2031,22 +2113,22 @@ function _r(e) {
2031
2113
  inviteEventId: e.inviteEventId,
2032
2114
  createdAt: e.createdAt,
2033
2115
  status: e.status,
2034
- ...fr(e)
2116
+ ...br(e)
2035
2117
  };
2036
2118
  }
2037
2119
  // src/games/tanks/net/tankStorage.js
2038
- var vr = "lira:tk:", yr = 6048e5, br = 20, xr = (e, t) => `${vr}${e}:${t}`, Sr = () => {
2120
+ var Er = "lira:tk:", Dr = 6048e5, Or = 20, kr = (e, t) => `${Er}${e}:${t}`, Ar = () => {
2039
2121
  try {
2040
2122
  return globalThis.localStorage ?? null;
2041
2123
  } catch {
2042
2124
  return null;
2043
2125
  }
2044
2126
  };
2045
- function Cr(e) {
2127
+ function jr(e) {
2046
2128
  let t = [];
2047
2129
  for (let n = 0; n < e.length; n += 1) {
2048
2130
  let r = e.key(n);
2049
- if (r?.startsWith(vr)) try {
2131
+ if (r?.startsWith(Er)) try {
2050
2132
  let n = JSON.parse(e.getItem(r));
2051
2133
  t.push({
2052
2134
  key: r,
@@ -2061,61 +2143,61 @@ function Cr(e) {
2061
2143
  }
2062
2144
  return t;
2063
2145
  }
2064
- function wr(e) {
2065
- let t = Date.now(), n = Cr(e);
2066
- n.filter(({ value: e }) => !e || !(t - e.savedAt < yr)).forEach(({ key: t }) => e.removeItem(t));
2067
- let r = n.filter(({ value: e }) => e && t - e.savedAt < yr).sort((e, t) => e.value.savedAt - t.value.savedAt);
2068
- r.slice(0, Math.max(0, r.length - br)).forEach(({ key: t }) => e.removeItem(t));
2146
+ function Mr(e) {
2147
+ let t = Date.now(), n = jr(e);
2148
+ n.filter(({ value: e }) => !e || !(t - e.savedAt < Dr)).forEach(({ key: t }) => e.removeItem(t));
2149
+ let r = n.filter(({ value: e }) => e && t - e.savedAt < Dr).sort((e, t) => e.value.savedAt - t.value.savedAt);
2150
+ r.slice(0, Math.max(0, r.length - Or)).forEach(({ key: t }) => e.removeItem(t));
2069
2151
  }
2070
- function Tr(e, t, n) {
2152
+ function Nr(e, t, n) {
2071
2153
  try {
2072
- let r = Sr();
2154
+ let r = Ar();
2073
2155
  if (!r) return !1;
2074
- let i = Er(e, t) ?? {};
2075
- return r.setItem(xr(e, t), JSON.stringify({
2156
+ let i = Pr(e, t) ?? {};
2157
+ return r.setItem(kr(e, t), JSON.stringify({
2076
2158
  ...i,
2077
2159
  ...n,
2078
2160
  savedAt: Date.now()
2079
- })), wr(r), !0;
2161
+ })), Mr(r), !0;
2080
2162
  } catch {
2081
2163
  return !1;
2082
2164
  }
2083
2165
  }
2084
- function Er(e, t) {
2166
+ function Pr(e, t) {
2085
2167
  try {
2086
- let n = JSON.parse(Sr()?.getItem(xr(e, t)) ?? "null");
2087
- return !n || typeof n != "object" || !(Date.now() - n.savedAt < yr) || n.seedA !== void 0 && !/^[0-9a-f]{32}$/.test(n.seedA) ? null : n;
2168
+ let n = JSON.parse(Ar()?.getItem(kr(e, t)) ?? "null");
2169
+ return !n || typeof n != "object" || !(Date.now() - n.savedAt < Dr) || n.seedA !== void 0 && !/^[0-9a-f]{32}$/.test(n.seedA) ? null : n;
2088
2170
  } catch {
2089
2171
  return null;
2090
2172
  }
2091
2173
  }
2092
- function Dr(e) {
2174
+ function Fr(e) {
2093
2175
  try {
2094
- let t = Sr();
2095
- return t ? Cr(t).filter(({ key: t, value: n }) => t.startsWith(`${vr}${e}:`) && n?.snapshot && Date.now() - n.savedAt < yr).map(({ value: e }) => e).sort((e, t) => t.savedAt - e.savedAt) : [];
2176
+ let t = Ar();
2177
+ return t ? jr(t).filter(({ key: t, value: n }) => t.startsWith(`${Er}${e}:`) && n?.snapshot && Date.now() - n.savedAt < Dr).map(({ value: e }) => e).sort((e, t) => t.savedAt - e.savedAt) : [];
2096
2178
  } catch {
2097
2179
  return [];
2098
2180
  }
2099
2181
  }
2100
2182
  // src/games/shared/useChatGames.js
2101
- var Or = Ee, J = (e) => e?.game ?? "connect4", kr = (e) => J(e) === "battleship", Ar = (e) => J(e) === "tanks", jr = 250, Y = (e) => [
2183
+ var Ir = Le, Y = (e) => e?.game ?? "connect4", Lr = (e) => Y(e) === "battleship", X = (e) => Y(e) === "tanks", Rr = (e) => ["tanks_live", "racing_live"].includes(Y(e)), zr = 250, Z = (e) => [
2102
2184
  "won",
2103
2185
  "draw",
2104
2186
  "closed",
2105
2187
  "declined"
2106
- ].includes(e.status), Mr = (e, t, n) => JSON.stringify([
2188
+ ].includes(e.status), Br = (e, t, n) => JSON.stringify([
2107
2189
  e,
2108
2190
  String(t),
2109
2191
  n
2110
- ]), Nr = (e) => {
2111
- let t = Object.keys(e).filter((t) => Y(e[t]));
2192
+ ]), Vr = (e) => {
2193
+ let t = Object.keys(e).filter((t) => Z(e[t]));
2112
2194
  if (t.length <= 80) return e;
2113
2195
  let n = { ...e };
2114
2196
  return t.slice(0, t.length - 80).forEach((e) => {
2115
2197
  delete n[e];
2116
2198
  }), n;
2117
2199
  };
2118
- function Pr(e, t, n) {
2200
+ function Hr(e, t, n) {
2119
2201
  if (![e.hostId, e.guestId].includes(n)) return e;
2120
2202
  if (t.type === "game_end" && t.data.reason === "closed") return ["closed", "declined"].includes(e.status) ? e : {
2121
2203
  ...e,
@@ -2123,7 +2205,7 @@ function Pr(e, t, n) {
2123
2205
  closedBy: n,
2124
2206
  error: ""
2125
2207
  };
2126
- if (Y(e) || e.status === "conflict") return e;
2208
+ if (Z(e) || e.status === "conflict") return e;
2127
2209
  if (t.type === "game_accept" || t.type === "game_decline") return n !== e.guestId || e.status !== "invited" || t.data.invite_event_id !== e.inviteEventId ? e : {
2128
2210
  ...e,
2129
2211
  status: t.type === "game_accept" ? "active" : "declined",
@@ -2144,7 +2226,7 @@ function Pr(e, t, n) {
2144
2226
  error: "La partida perdió sincronización. Ciérrala y envía una nueva invitación."
2145
2227
  };
2146
2228
  if (n !== e.turnId) return e;
2147
- let o = Fe(e.board, a, n);
2229
+ let o = Ke(e.board, a, n);
2148
2230
  return o ? {
2149
2231
  ...e,
2150
2232
  board: o.board,
@@ -2162,7 +2244,7 @@ function Pr(e, t, n) {
2162
2244
  turnId: n === e.hostId ? e.guestId : e.hostId
2163
2245
  } : e;
2164
2246
  }
2165
- var Fr = 8e3, Ir = {
2247
+ var Ur = 8e3, Q = {
2166
2248
  status: "idle",
2167
2249
  requestId: null,
2168
2250
  requestedAt: 0,
@@ -2171,14 +2253,14 @@ var Fr = 8e3, Ir = {
2171
2253
  replies: [],
2172
2254
  offer: null,
2173
2255
  message: ""
2174
- }, Lr = (e) => [
2256
+ }, Wr = (e) => [
2175
2257
  "game_resync_request",
2176
2258
  "game_resync_state",
2177
2259
  "bs_sync_request",
2178
2260
  "bs_sync_state",
2179
2261
  "tk_sync_request",
2180
2262
  "tk_sync_state"
2181
- ].includes(e), Rr = (e) => e.acceptEventId ? {
2263
+ ].includes(e), Gr = (e) => e.acceptEventId ? {
2182
2264
  accept_event_id: e.acceptEventId,
2183
2265
  moves: e.moves ?? [],
2184
2266
  rev: (e.moves ?? []).length
@@ -2186,10 +2268,10 @@ var Fr = 8e3, Ir = {
2186
2268
  moves: [],
2187
2269
  rev: 0
2188
2270
  };
2189
- function zr(e, t, n) {
2271
+ function Kr(e, t, n) {
2190
2272
  let r = {
2191
2273
  ...e,
2192
- board: Ae(),
2274
+ board: Ve(),
2193
2275
  ply: 0,
2194
2276
  turnId: e.hostId,
2195
2277
  winnerId: null,
@@ -2215,7 +2297,7 @@ function zr(e, t, n) {
2215
2297
  let [r, o] = n[t];
2216
2298
  if (a.has(o)) return null;
2217
2299
  a.add(o);
2218
- let s = t % 2 == 0 ? e.hostId : e.guestId, c = Pr(i, {
2300
+ let s = t % 2 == 0 ? e.hostId : e.guestId, c = Hr(i, {
2219
2301
  type: "game_move",
2220
2302
  event_id: o,
2221
2303
  data: {
@@ -2229,18 +2311,18 @@ function zr(e, t, n) {
2229
2311
  }
2230
2312
  return i;
2231
2313
  }
2232
- function Br(e, t) {
2314
+ function qr(e, t) {
2233
2315
  if (e.acceptEventId && t.acceptEventId && e.acceptEventId !== t.acceptEventId) return "diverged";
2234
2316
  let n = Math.min(e.moves.length, t.moves.length);
2235
2317
  for (let r = 0; r < n; r += 1) if (e.moves[r][0] !== t.moves[r][0] || e.moves[r][1] !== t.moves[r][1]) return "diverged";
2236
2318
  return e.moves.length === t.moves.length ? e.acceptEventId && !t.acceptEventId ? "ahead" : !e.acceptEventId && t.acceptEventId ? "behind" : "equal" : e.moves.length < t.moves.length ? "behind" : "ahead";
2237
2319
  }
2238
- var Vr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEvent.event_id : null, Hr = {
2320
+ var Jr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEvent.event_id : null, Yr = {
2239
2321
  requestType: "game_resync_request",
2240
2322
  stateType: "game_resync_state",
2241
- historyOf: Rr,
2242
- rebuild: (e, t) => zr(e, t.accept_event_id ?? null, t.moves),
2243
- compare: (e, t) => Br({
2323
+ historyOf: Gr,
2324
+ rebuild: (e, t) => Kr(e, t.accept_event_id ?? null, t.moves),
2325
+ compare: (e, t) => qr({
2244
2326
  acceptEventId: e.acceptEventId ?? null,
2245
2327
  moves: e.moves ?? []
2246
2328
  }, {
@@ -2252,7 +2334,7 @@ var Vr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
2252
2334
  moves: e.moves
2253
2335
  }),
2254
2336
  covers: (e, t) => {
2255
- let n = Vr(e);
2337
+ let n = Jr(e);
2256
2338
  return !!(n && t.moves?.some((e) => e[1] === n));
2257
2339
  },
2258
2340
  markSeen: (e, t) => {
@@ -2262,40 +2344,40 @@ var Vr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
2262
2344
  }), n;
2263
2345
  },
2264
2346
  merge: () => null
2265
- }, Ur = (e) => ({
2347
+ }, Xr = (e) => ({
2266
2348
  requestType: "bs_sync_request",
2267
2349
  stateType: "bs_sync_state",
2268
- historyOf: Ft,
2269
- rebuild: (t, n) => Rt(t, n, { stored: e(t.scope, t.gameId) }),
2270
- compare: (e, t) => It(Ft(e), t),
2350
+ historyOf: Gt,
2351
+ rebuild: (t, n) => Jt(t, n, { stored: e(t.scope, t.gameId) }),
2352
+ compare: (e, t) => Kt(Gt(e), t),
2271
2353
  offerOf: (e) => ({
2272
2354
  accept_event_id: e.accept_event_id,
2273
2355
  commits: e.commits,
2274
2356
  log: e.log,
2275
2357
  head: e.head
2276
2358
  }),
2277
- covers: (e, t) => !!(e.pendingEvent && !e.pending && zt(t, e.pendingEvent)),
2278
- markSeen: Bt,
2279
- merge: (e, t) => Lt(Ft(e), t)
2280
- }), Wr = {
2359
+ covers: (e, t) => !!(e.pendingEvent && !e.pending && Yt(t, e.pendingEvent)),
2360
+ markSeen: Xt,
2361
+ merge: (e, t) => qt(Gt(e), t)
2362
+ }), Zr = {
2281
2363
  requestType: "tk_sync_request",
2282
2364
  stateType: "tk_sync_state",
2283
- historyOf: fr,
2284
- rebuild: mr,
2285
- compare: (e, t) => pr(fr(e), t),
2365
+ historyOf: br,
2366
+ rebuild: Sr,
2367
+ compare: (e, t) => xr(br(e), t),
2286
2368
  offerOf: (e) => ({
2287
2369
  ...e,
2288
2370
  request_event_id: void 0
2289
2371
  }),
2290
- covers: (e, t) => !!(e.pendingEvent && !e.pending && hr(t, e.pendingEvent)),
2291
- markSeen: gr,
2372
+ covers: (e, t) => !!(e.pendingEvent && !e.pending && Cr(t, e.pendingEvent)),
2373
+ markSeen: wr,
2292
2374
  merge: () => null
2293
- }, Gr = (e) => ({
2375
+ }, Qr = (e) => ({
2294
2376
  ...e,
2295
2377
  game: "connect4",
2296
2378
  turnId: e.hostId,
2297
2379
  status: "invited",
2298
- board: Ae(),
2380
+ board: Ve(),
2299
2381
  ply: 0,
2300
2382
  winnerId: null,
2301
2383
  lastMove: null,
@@ -2304,49 +2386,53 @@ var Vr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
2304
2386
  pendingEvent: null,
2305
2387
  acceptEventId: null,
2306
2388
  moves: []
2307
- }), Kr = (e, t, n) => j(t, {
2389
+ }), $r = (e, t, n) => k(t, {
2308
2390
  game_id: e.gameId,
2309
2391
  data: n,
2310
- game: J(e)
2392
+ game: Y(e)
2311
2393
  });
2312
- function qr() {
2313
- let e = null, t = /* @__PURE__ */ new Map(), n = (e, n) => t.get(`${e}:${n}`) ?? Jt(e, n), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), s = Ur(n), l = /* @__PURE__ */ new Map(), u = (e, t) => l.get(`${e}:${t}`) ?? Er(e, t)?.seedA ?? null, d = {
2394
+ function ei() {
2395
+ let e = null, t = /* @__PURE__ */ new Map(), n = (e, n) => t.get(`${e}:${n}`) ?? an(e, n), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), s = Xr(n), c = /* @__PURE__ */ new Map(), l = (e, t) => c.get(`${e}:${t}`) ?? Pr(e, t)?.seedA ?? null, u = {
2314
2396
  connect4: {
2315
- create: (e) => Gr(e),
2316
- apply: (e, t, n) => Pr(e, t, n),
2317
- sync: Hr
2397
+ create: (e) => Qr(e),
2398
+ apply: (e, t, n) => Hr(e, t, n),
2399
+ sync: Yr
2318
2400
  },
2319
2401
  battleship: {
2320
- create: (e) => tt(e),
2321
- apply: (e, t, r, i) => jt(e, t, r, { stored: t.type === "bs_commit" && r === i ? n(e.scope, e.gameId) : null }),
2402
+ create: (e) => ft(e),
2403
+ apply: (e, t, r, i) => Vt(e, t, r, { stored: t.type === "bs_commit" && r === i ? n(e.scope, e.gameId) : null }),
2322
2404
  sync: s,
2323
2405
  after: (e, t) => t().bsScheduleEffects(e)
2324
2406
  },
2407
+ racing_live: {
2408
+ create: (e, t) => ie(e, t.data),
2409
+ apply: ae
2410
+ },
2325
2411
  tanks_live: {
2326
- create: (e, t) => v(e, t.data),
2327
- apply: y
2412
+ create: (e, t) => _(e, t.data),
2413
+ apply: v
2328
2414
  },
2329
2415
  tanks: {
2330
- create: (e, t) => nr(e, t.data),
2331
- apply: (e, t, n) => ur(e, t, n),
2332
- sync: Wr,
2416
+ create: (e, t) => ur(e, t.data),
2417
+ apply: (e, t, n) => vr(e, t, n),
2418
+ sync: Zr,
2333
2419
  after: (e, t) => t().tkScheduleEffects(e)
2334
2420
  }
2335
- }, f = (e) => d[J(e)] ?? null, p = (e) => f(e)?.sync ?? Hr;
2336
- return c((s, c) => ({
2421
+ }, f = (e) => u[Y(e)] ?? null, m = (e) => f(e)?.sync ?? Yr;
2422
+ return d((s, d) => ({
2337
2423
  games: {},
2338
2424
  configureTransport: (t) => {
2339
2425
  e = t;
2340
2426
  },
2341
2427
  clear: () => {
2342
- r.forEach((e) => clearTimeout(e)), r.clear(), o.forEach((e) => clearTimeout(e)), o.clear(), t.clear(), l.clear(), i.clear(), a.clear(), s({ games: {} });
2428
+ r.forEach((e) => clearTimeout(e)), r.clear(), o.forEach((e) => clearTimeout(e)), o.clear(), t.clear(), c.clear(), i.clear(), a.clear(), s({ games: {} });
2343
2429
  },
2344
- markDisconnected: (e) => s((t) => ({ games: Object.fromEntries(Object.entries(t.games).map(([t, n]) => [t, n.scope === e && n.game !== "tanks_live" && !Y(n) ? {
2430
+ markDisconnected: (e) => s((t) => ({ games: Object.fromEntries(Object.entries(t.games).map(([t, n]) => [t, n.scope === e && !Rr(n) && !Z(n) ? {
2345
2431
  ...n,
2346
2432
  status: "conflict",
2347
2433
  error: "Conexión interrumpida. Se intentará resincronizar al reconectar.",
2348
2434
  sync: {
2349
- ...Ir,
2435
+ ...Q,
2350
2436
  ...n.sync,
2351
2437
  status: "idle",
2352
2438
  auto: !1
@@ -2356,19 +2442,19 @@ function qr() {
2356
2442
  let i = typeof n == "object" ? n : {
2357
2443
  scope: n,
2358
2444
  currentUserId: r
2359
- }, o = i?.scope ?? e?.getScope?.(), l = String(i?.currentUserId ?? e?.getUserId?.() ?? ""), u = t.data ?? t.payload, f = u && typeof u == "object" ? {
2360
- ...u,
2445
+ }, o = i?.scope ?? e?.getScope?.(), c = String(i?.currentUserId ?? e?.getUserId?.() ?? ""), l = t.data ?? t.payload, f = l && typeof l == "object" ? {
2446
+ ...l,
2361
2447
  ...t
2362
2448
  } : t, p = f.message ?? f.text;
2363
2449
  if (typeof p != "string" || !p.startsWith("LIRA_GAME_V1:")) return !1;
2364
- let m = Oe(p), h = String(f.room_id ?? ""), g = String(f.user_id ?? "");
2365
- if (!m || !o || !l || !g || !h.startsWith("private_")) return !0;
2450
+ let m = ze(p), h = String(f.room_id ?? ""), g = String(f.user_id ?? "");
2451
+ if (!m || !o || !c || !g || !h.startsWith("private_")) return !0;
2366
2452
  let _ = h.slice(8).split("_");
2367
- if (_.length !== 2 || !_.includes(l) || !_.includes(g)) return !0;
2368
- let v = Mr(o, h, m.game_id), y = c().games[v];
2369
- if (y && J(y) !== m.game) return !0;
2370
- if (Lr(m.type)) return y && !y.seen[m.event_id] && c().handleResync(v, m, g, l), !0;
2371
- if (!y && m.type !== "game_invite" && m.game === "tanks" && c().restoreTanks(o, m.game_id)) return c().ingest(t, n, r);
2453
+ if (_.length !== 2 || !_.includes(c) || !_.includes(g)) return !0;
2454
+ let v = Br(o, h, m.game_id), y = d().games[v];
2455
+ if (y && Y(y) !== m.game) return !0;
2456
+ if (Wr(m.type)) return y && !y.seen[m.event_id] && d().handleResync(v, m, g, c), !0;
2457
+ if (!y && m.type !== "game_invite" && m.game === "tanks" && d().restoreTanks(o, m.game_id)) return d().ingest(t, n, r);
2372
2458
  if (!y && m.type !== "game_invite") {
2373
2459
  let e = Date.now();
2374
2460
  for (let [t, n] of a) e - n.at > 3e4 && a.delete(t);
@@ -2383,7 +2469,7 @@ function qr() {
2383
2469
  }), a.set(v, t), !0;
2384
2470
  }
2385
2471
  if (y?.seen[m.event_id]) return !0;
2386
- let b = y, x = d[m.game];
2472
+ let b = y, x = u[m.game];
2387
2473
  if (!x) return !0;
2388
2474
  if (m.type === "game_invite") {
2389
2475
  let e = m.data.opponent_id;
@@ -2394,16 +2480,16 @@ function qr() {
2394
2480
  game_id: m.game_id,
2395
2481
  scope: o,
2396
2482
  roomId: h,
2397
- ownId: l,
2483
+ ownId: c,
2398
2484
  hostId: g,
2399
2485
  guestId: e,
2400
2486
  createdAt: f.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
2401
2487
  inviteEventId: m.event_id,
2402
2488
  lastEventId: m.event_id,
2403
2489
  seen: {},
2404
- sync: { ...Ir }
2490
+ sync: { ...Q }
2405
2491
  }, m);
2406
- } else y && (b = x.apply(y, m, g, l));
2492
+ } else y && (b = x.apply(y, m, g, c));
2407
2493
  if (!b || b === y) return !0;
2408
2494
  if (b = {
2409
2495
  ...b,
@@ -2417,7 +2503,7 @@ function qr() {
2417
2503
  [v]: b
2418
2504
  };
2419
2505
  if (m.type === "game_invite") {
2420
- let e = Object.values(t).filter((e) => e.scope === o && e.roomId === h && !Y(e)), n = e.sort((e, t) => e.gameId < t.gameId ? -1 : +(e.gameId > t.gameId))[0];
2506
+ let e = Object.values(t).filter((e) => e.scope === o && e.roomId === h && !Z(e)), n = e.sort((e, t) => e.gameId < t.gameId ? -1 : +(e.gameId > t.gameId))[0];
2421
2507
  e.forEach((e) => {
2422
2508
  e.key !== n?.key && (t[e.key] = {
2423
2509
  ...e,
@@ -2426,47 +2512,52 @@ function qr() {
2426
2512
  });
2427
2513
  });
2428
2514
  }
2429
- return { games: Nr(t) };
2515
+ return { games: Vr(t) };
2430
2516
  }), b.status === "conflict" && y?.status !== "conflict" && queueMicrotask(() => {
2431
- c().requestResync(v, { auto: !0 });
2432
- }), c().afterGameChange(v), m.type === "game_invite") {
2517
+ d().requestResync(v, { auto: !0 });
2518
+ }), d().afterGameChange(v), m.type === "game_invite") {
2433
2519
  let e = a.get(v);
2434
- a.delete(v), e && Date.now() - e.at <= 3e4 && e.messages.forEach((e) => c().ingest(e.message, o, l));
2520
+ a.delete(v), e && Date.now() - e.at <= 3e4 && e.messages.forEach((e) => d().ingest(e.message, o, c));
2435
2521
  }
2436
2522
  return !0;
2437
2523
  },
2438
- invite: async ({ roomId: t, opponentId: n, gameType: r = "connect4", firstPlayerId: i, rematchOf: a }) => {
2524
+ invite: async ({ roomId: t, opponentId: n, gameType: r = "connect4", firstPlayerId: i, rematchOf: a, speedClass: o }) => {
2439
2525
  if (!e) throw Error("Chat no disponible");
2440
- if (!Or.includes(r)) throw Error("Juego no disponible");
2441
- let o = e.getScope();
2526
+ if (!Ir.includes(r)) throw Error("Juego no disponible");
2527
+ let s = e.getScope();
2442
2528
  if (!String(e.getUserId() ?? "") || !String(t).startsWith("private_")) throw Error("Abre un chat privado para jugar.");
2443
- if (Object.values(c().games).some((e) => e.scope === o && e.roomId === String(t) && (!Y(e) || e.pendingEvent))) throw Error("Cierra la partida actual antes de invitar.");
2444
- let s = m(), u = {
2529
+ if (Object.values(d().games).some((e) => e.scope === s && e.roomId === String(t) && (!Z(e) || e.pendingEvent))) throw Error("Cierra la partida actual antes de invitar.");
2530
+ let l = p(), u = r === "racing_live" ? re({
2531
+ opponentId: String(n),
2532
+ seed: parseInt(l.slice(0, 8), 16),
2533
+ rematchOf: a,
2534
+ ...o === void 0 ? {} : { speedClass: o }
2535
+ }) : {
2445
2536
  opponent_id: String(n),
2446
2537
  rules_version: 1
2447
2538
  };
2448
2539
  if (r === "tanks") {
2449
- let e = $n();
2450
- l.set(`${o}:${s}`, e), Tr(o, s, { seedA: e }), u.seed_commit = er(e), i != null && (u.first_player_id = String(i)), a && (u.rematch_of = a);
2540
+ let e = sr();
2541
+ c.set(`${s}:${l}`, e), Nr(s, l, { seedA: e }), u.seed_commit = cr(e), i != null && (u.first_player_id = String(i)), a && (u.rematch_of = a);
2451
2542
  }
2452
2543
  r === "tanks_live" && a && (u.rematch_of = a);
2453
- let d = j("game_invite", {
2454
- game_id: s,
2544
+ let f = k("game_invite", {
2545
+ game_id: l,
2455
2546
  data: u,
2456
2547
  game: r
2457
2548
  });
2458
- return c().sendEvent(t, d);
2549
+ return d().sendEvent(t, f);
2459
2550
  },
2460
2551
  act: async (t, n, r = {}) => {
2461
- let i = c().games[t], a = String(e?.getUserId?.() ?? "");
2552
+ let i = d().games[t], a = String(e?.getUserId?.() ?? "");
2462
2553
  if (!i || i.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2463
2554
  if (n !== "game_end" && (i.pending || i.pendingEvent)) throw Error("Reintenta el envío pendiente antes de continuar.");
2464
2555
  let o = r;
2465
2556
  if (n === "game_accept" || n === "game_decline") {
2466
2557
  if (i.status !== "invited" || a !== i.guestId) return;
2467
- o = { invite_event_id: i.inviteEventId }, n === "game_accept" && Ar(i) && (o.seed_b = $n());
2558
+ o = { invite_event_id: i.inviteEventId }, n === "game_accept" && X(i) && (o.seed_b = sr()), n === "game_accept" && i.game === "racing_live" && (o.track_hash = i.raceConfig.trackHash);
2468
2559
  } else if (n === "game_move") {
2469
- if (J(i) !== "connect4" || i.status !== "active" || a !== i.turnId || !Fe(i.board, r.column, a)) return;
2560
+ if (Y(i) !== "connect4" || i.status !== "active" || a !== i.turnId || !Ke(i.board, r.column, a)) return;
2470
2561
  o = {
2471
2562
  column: r.column,
2472
2563
  ply: i.ply + 1,
@@ -2474,51 +2565,51 @@ function qr() {
2474
2565
  };
2475
2566
  } else if (n === "game_end") o = { reason: "closed" };
2476
2567
  else return;
2477
- return c().sendEvent(i.roomId, j(n, {
2568
+ return d().sendEvent(i.roomId, k(n, {
2478
2569
  game_id: i.gameId,
2479
2570
  data: o,
2480
- game: J(i)
2571
+ game: Y(i)
2481
2572
  }));
2482
2573
  },
2483
2574
  bsUpdateLocal: (e, t) => {
2484
- let n = c().games[e];
2485
- if (!kr(n)) return !1;
2575
+ let n = d().games[e];
2576
+ if (!Lr(n)) return !1;
2486
2577
  let r = t(n);
2487
2578
  return r !== n && (s((t) => t.games[e] === n ? { games: {
2488
2579
  ...t.games,
2489
2580
  [e]: r
2490
- } } : t), c().games[e] === r);
2581
+ } } : t), d().games[e] === r);
2491
2582
  },
2492
- bsPlaceShip: (e, t) => c().bsUpdateLocal(e, (e) => ft(e, t)),
2493
- bsRemoveShip: (e, t) => c().bsUpdateLocal(e, (e) => pt(e, t)),
2494
- bsRandomFleet: (e) => c().bsUpdateLocal(e, (e) => gt(e)),
2583
+ bsPlaceShip: (e, t) => d().bsUpdateLocal(e, (e) => St(e, t)),
2584
+ bsRemoveShip: (e, t) => d().bsUpdateLocal(e, (e) => Ct(e, t)),
2585
+ bsRandomFleet: (e) => d().bsUpdateLocal(e, (e) => Et(e)),
2495
2586
  bsReady: async (n) => {
2496
- let r = c().games[n];
2497
- if (!kr(r) || r.status !== "placement" || r.myReady) return;
2587
+ let r = d().games[n];
2588
+ if (!Lr(r) || r.status !== "placement" || r.myReady) return;
2498
2589
  if (r.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2499
2590
  if (r.pending || r.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
2500
- let i = ct(r.myFleet);
2501
- if (!ut(i)) throw Error("Coloca los cinco barcos antes de continuar.");
2502
- let a = vt(), o = await bt(i, a), s = c().games[n];
2503
- if (!(!s || s.myReady || s.status !== "placement" || s.pending || s.pendingEvent || JSON.stringify(ct(s.myFleet)) !== JSON.stringify(i))) return t.set(`${r.scope}:${r.gameId}`, {
2591
+ let i = M(r.myFleet);
2592
+ if (!bt(i)) throw Error("Coloca los cinco barcos antes de continuar.");
2593
+ let a = Ot(), o = await At(i, a), s = d().games[n];
2594
+ if (!(!s || s.myReady || s.status !== "placement" || s.pending || s.pendingEvent || JSON.stringify(M(s.myFleet)) !== JSON.stringify(i))) return t.set(`${r.scope}:${r.gameId}`, {
2504
2595
  fleet: i,
2505
2596
  salt: a,
2506
2597
  commitment: o
2507
- }), qt(r.scope, r.gameId, {
2598
+ }), rn(r.scope, r.gameId, {
2508
2599
  fleet: i,
2509
2600
  salt: a,
2510
2601
  commitment: o
2511
- }), c().sendEvent(r.roomId, j("bs_commit", {
2602
+ }), d().sendEvent(r.roomId, k("bs_commit", {
2512
2603
  game_id: r.gameId,
2513
2604
  data: { commitment: o },
2514
2605
  game: "battleship"
2515
2606
  }));
2516
2607
  },
2517
2608
  bsFire: async (t, { row: n, col: r } = {}) => {
2518
- let i = c().games[t];
2519
- if (!kr(i) || i.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2609
+ let i = d().games[t];
2610
+ if (!Lr(i) || i.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2520
2611
  if (i.pending || i.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
2521
- if (rt(i) && i.targetShots[n]?.[r] === null) return c().sendEvent(i.roomId, j("bs_fire", {
2612
+ if (mt(i) && i.targetShots[n]?.[r] === null) return d().sendEvent(i.roomId, k("bs_fire", {
2522
2613
  game_id: i.gameId,
2523
2614
  data: {
2524
2615
  ply: i.ply + 1,
@@ -2531,15 +2622,15 @@ function qr() {
2531
2622
  },
2532
2623
  bsScheduleEffects: (e) => {
2533
2624
  r.has(e) || r.set(e, setTimeout(() => {
2534
- r.delete(e), c().bsRunEffects(e);
2535
- }, jr));
2625
+ r.delete(e), d().bsRunEffects(e);
2626
+ }, zr));
2536
2627
  },
2537
2628
  bsRunEffects: (t) => {
2538
- let r = c().games[t];
2539
- if (!kr(r) || !e || r.scope !== e.getScope?.()) return;
2629
+ let r = d().games[t];
2630
+ if (!Lr(r) || !e || r.scope !== e.getScope?.()) return;
2540
2631
  if (r.opponentReveal && r.verification === "pending" && !i.has(t)) {
2541
2632
  let e = r.opponentReveal;
2542
- i.add(t), Nt(r, e).then((n) => s((r) => {
2633
+ i.add(t), Ut(r, e).then((n) => s((r) => {
2543
2634
  let i = r.games[t];
2544
2635
  return !i || i.opponentReveal !== e || i.verification === n ? r : { games: {
2545
2636
  ...r.games,
@@ -2554,14 +2645,14 @@ function qr() {
2554
2645
  }
2555
2646
  if (r.pending || r.pendingEvent) return;
2556
2647
  let a = (e, t) => {
2557
- c().sendEvent(r.roomId, j(e, {
2648
+ d().sendEvent(r.roomId, k(e, {
2558
2649
  game_id: r.gameId,
2559
2650
  data: t,
2560
2651
  game: "battleship"
2561
2652
  })).catch(() => {});
2562
2653
  };
2563
2654
  if (r.status === "active" && r.pendingShot && r.pendingShot.by !== r.ownId) {
2564
- let e = xt(dt(r), r.pendingShot);
2655
+ let e = jt(xt(r), r.pendingShot);
2565
2656
  e ? a("bs_result", e) : r.error || s((e) => ({ games: {
2566
2657
  ...e.games,
2567
2658
  [t]: {
@@ -2573,31 +2664,31 @@ function qr() {
2573
2664
  }
2574
2665
  let o = String(r.winnerId) !== String(r.ownId) || !!r.opponentReveal;
2575
2666
  if (r.winnerId && ["won", "closed"].includes(r.status) && !r.myRevealSent && o) {
2576
- let e = ct(r.myFleet), t = r.mySalt ?? n(r.scope, r.gameId)?.salt;
2577
- ut(e) && t && a("bs_reveal", {
2667
+ let e = M(r.myFleet), t = r.mySalt ?? n(r.scope, r.gameId)?.salt;
2668
+ bt(e) && t && a("bs_reveal", {
2578
2669
  fleet: e,
2579
2670
  salt: t
2580
2671
  });
2581
2672
  }
2582
2673
  },
2583
2674
  afterGameChange: (e) => {
2584
- let t = c().games[e];
2585
- f(t)?.after?.(e, c);
2675
+ let t = d().games[e];
2676
+ f(t)?.after?.(e, d);
2586
2677
  },
2587
2678
  tkTurn: async (t, n) => {
2588
- let r = c().games[t];
2589
- if (!Ar(r) || r.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2679
+ let r = d().games[t];
2680
+ if (!X(r) || r.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2590
2681
  if (r.pending || r.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
2591
- let i = dr(r, n);
2592
- if (i) return c().sendEvent(r.roomId, j("tk_turn", {
2682
+ let i = yr(r, n);
2683
+ if (i) return d().sendEvent(r.roomId, k("tk_turn", {
2593
2684
  game_id: r.gameId,
2594
2685
  data: i,
2595
2686
  game: "tanks"
2596
2687
  }));
2597
2688
  },
2598
2689
  tkSkip: async (t) => {
2599
- let n = c().games[t];
2600
- if (Ar(n) && ir(n) && n.scope === e?.getScope?.()) return c().sendEvent(n.roomId, j("tk_skip", {
2690
+ let n = d().games[t];
2691
+ if (X(n) && fr(n) && n.scope === e?.getScope?.()) return d().sendEvent(n.roomId, k("tk_skip", {
2601
2692
  game_id: n.gameId,
2602
2693
  data: {
2603
2694
  ply: n.ply + 1,
@@ -2607,8 +2698,8 @@ function qr() {
2607
2698
  }));
2608
2699
  },
2609
2700
  tkResign: async (t) => {
2610
- let n = c().games[t];
2611
- if (!(!Ar(n) || n.status !== "active" || n.pending || n.pendingEvent || n.scope !== e?.getScope?.())) return c().sendEvent(n.roomId, j("tk_resign", {
2701
+ let n = d().games[t];
2702
+ if (!(!X(n) || n.status !== "active" || n.pending || n.pendingEvent || n.scope !== e?.getScope?.())) return d().sendEvent(n.roomId, k("tk_resign", {
2612
2703
  game_id: n.gameId,
2613
2704
  data: {
2614
2705
  ply: n.ply + 1,
@@ -2619,14 +2710,14 @@ function qr() {
2619
2710
  },
2620
2711
  tkScheduleEffects: (e) => {
2621
2712
  r.has(e) || r.set(e, setTimeout(() => {
2622
- r.delete(e), c().tkRunEffects(e);
2623
- }, jr));
2713
+ r.delete(e), d().tkRunEffects(e);
2714
+ }, zr));
2624
2715
  },
2625
2716
  tkRunEffects: (t) => {
2626
- let n = c().games[t];
2627
- if (!Ar(n) || (Tr(n.scope, n.gameId, { snapshot: _r(n) }), !e || n.scope !== e.getScope?.() || n.pending || n.pendingEvent) || n.status !== "seeding" || n.ownId !== n.hostId) return;
2628
- let r = u(n.scope, n.gameId);
2629
- r ? c().sendEvent(n.roomId, j("tk_seed", {
2717
+ let n = d().games[t];
2718
+ if (!X(n) || (Nr(n.scope, n.gameId, { snapshot: Tr(n) }), !e || n.scope !== e.getScope?.() || n.pending || n.pendingEvent) || n.status !== "seeding" || n.ownId !== n.hostId) return;
2719
+ let r = l(n.scope, n.gameId);
2720
+ r ? d().sendEvent(n.roomId, k("tk_seed", {
2630
2721
  game_id: n.gameId,
2631
2722
  data: { seed_a: r },
2632
2723
  game: "tanks"
@@ -2640,16 +2731,16 @@ function qr() {
2640
2731
  },
2641
2732
  restoreTanks: (e, t) => {
2642
2733
  let n = !1;
2643
- return Dr(e).forEach(({ snapshot: r }) => {
2734
+ return Fr(e).forEach(({ snapshot: r }) => {
2644
2735
  if (!r || t && r.gameId !== t || [
2645
2736
  "closed",
2646
2737
  "declined",
2647
2738
  "won",
2648
2739
  "draw"
2649
2740
  ].includes(r.status)) return;
2650
- let i = Mr(e, r.roomId, r.gameId);
2651
- if (c().games[i]) return;
2652
- let a = mr(nr({
2741
+ let i = Br(e, r.roomId, r.gameId);
2742
+ if (d().games[i]) return;
2743
+ let a = Sr(ur({
2653
2744
  key: i,
2654
2745
  gameId: r.gameId,
2655
2746
  game_id: r.gameId,
@@ -2662,7 +2753,7 @@ function qr() {
2662
2753
  inviteEventId: r.inviteEventId,
2663
2754
  lastEventId: r.inviteEventId,
2664
2755
  seen: {},
2665
- sync: { ...Ir }
2756
+ sync: { ...Q }
2666
2757
  }, {
2667
2758
  seed_commit: r.seedCommit,
2668
2759
  first_player_id: r.firstPlayerId,
@@ -2672,32 +2763,32 @@ function qr() {
2672
2763
  n = !0;
2673
2764
  let o = {
2674
2765
  ...a,
2675
- seen: gr({ [r.inviteEventId]: !0 }, a),
2766
+ seen: wr({ [r.inviteEventId]: !0 }, a),
2676
2767
  status: "conflict",
2677
2768
  error: "Partida recuperada en este dispositivo. Sincronizando con el rival…"
2678
2769
  };
2679
- s((e) => ({ games: Nr({
2770
+ s((e) => ({ games: Vr({
2680
2771
  ...e.games,
2681
2772
  [i]: o
2682
2773
  }) })), queueMicrotask(() => {
2683
- c().requestResync(i, { auto: !0 });
2774
+ d().requestResync(i, { auto: !0 });
2684
2775
  });
2685
2776
  }), n;
2686
2777
  },
2687
2778
  createLiveSignaling: (t) => {
2688
- let n = c().games[t];
2689
- if (n?.game !== "tanks_live" || n.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2779
+ let n = d().games[t];
2780
+ if (!["tanks_live", "racing_live"].includes(n?.game) || n.scope !== e?.getScope?.()) throw Error("Partida no disponible");
2690
2781
  let r = e;
2691
- return S({
2782
+ return ce({
2692
2783
  roomId: n.roomId,
2693
2784
  send: (n, i) => {
2694
- if (e !== r || c().games[t]?.scope !== r.getScope()) throw Error("La sesión cambió");
2785
+ if (e !== r || d().games[t]?.scope !== r.getScope()) throw Error("La sesión cambió");
2695
2786
  return r.send(n, i);
2696
2787
  }
2697
2788
  });
2698
2789
  },
2699
2790
  liveFinish: (t, n) => {
2700
- let r = c().games[t];
2791
+ let r = d().games[t];
2701
2792
  r?.game === "tanks_live" && r.scope === e?.getScope?.() && r.status === "active" && [r.hostId, r.guestId].includes(String(n)) && s((e) => ({ games: {
2702
2793
  ...e.games,
2703
2794
  [t]: {
@@ -2708,8 +2799,8 @@ function qr() {
2708
2799
  } }));
2709
2800
  },
2710
2801
  liveRematch: (t) => {
2711
- let n = c().games[t];
2712
- if (n?.game === "tanks_live" && n.scope === e?.getScope?.() && Y(n)) return c().invite({
2802
+ let n = d().games[t];
2803
+ if (n?.game === "tanks_live" && n.scope === e?.getScope?.() && Z(n)) return d().invite({
2713
2804
  roomId: n.roomId,
2714
2805
  opponentId: n.ownId === n.hostId ? n.guestId : n.hostId,
2715
2806
  gameType: "tanks_live",
@@ -2718,13 +2809,13 @@ function qr() {
2718
2809
  },
2719
2810
  sendEvent: async (t, n) => {
2720
2811
  if (!e) throw Error("Chat no disponible");
2721
- let r = e, i = r.getScope(), a = String(r.getUserId() ?? ""), o = Mr(i, t, n.game_id), l = ke(n);
2722
- if (c().ingest({
2812
+ let r = e, i = r.getScope(), a = String(r.getUserId() ?? ""), o = Br(i, t, n.game_id), c = Be(n);
2813
+ if (d().ingest({
2723
2814
  room_id: t,
2724
2815
  user_id: a,
2725
- message: l
2726
- }, i, a), !c().games[o]?.seen[n.event_id]) throw Error("Evento de partida inválido");
2727
- let u = (e, t = !0) => s((r) => {
2816
+ message: c
2817
+ }, i, a), !d().games[o]?.seen[n.event_id]) throw Error("Evento de partida inválido");
2818
+ let l = (e, t = !0) => s((r) => {
2728
2819
  let i = r.games[o];
2729
2820
  return !i || t && i.pendingEvent?.event_id !== n.event_id ? r : { games: {
2730
2821
  ...r.games,
@@ -2734,18 +2825,18 @@ function qr() {
2734
2825
  }
2735
2826
  } };
2736
2827
  });
2737
- u({
2828
+ l({
2738
2829
  pending: !0,
2739
2830
  pendingEvent: n,
2740
2831
  error: ""
2741
2832
  }, !1);
2742
2833
  try {
2743
- await r.send(t, l), u({
2834
+ await r.send(t, c), l({
2744
2835
  pending: !1,
2745
2836
  pendingEvent: null
2746
- }), c().afterGameChange(o);
2837
+ }), d().afterGameChange(o);
2747
2838
  } catch (e) {
2748
- throw u({
2839
+ throw l({
2749
2840
  pending: !1,
2750
2841
  error: e.message || "No se pudo enviar. Reintenta el mismo evento."
2751
2842
  }), e;
@@ -2753,36 +2844,36 @@ function qr() {
2753
2844
  return o;
2754
2845
  },
2755
2846
  handleResync: (e, t, n, r) => {
2756
- let i = c().games[e], a = p(i), o = {
2847
+ let i = d().games[e], a = m(i), o = {
2757
2848
  ...i.seen,
2758
2849
  [t.event_id]: !0
2759
- }, l = (t) => {
2850
+ }, c = (t) => {
2760
2851
  s((n) => ({ games: {
2761
2852
  ...n.games,
2762
2853
  [e]: t
2763
- } })), c().afterGameChange(e);
2854
+ } })), d().afterGameChange(e);
2764
2855
  };
2765
2856
  if (n === r || ![i.hostId, i.guestId].includes(n) || ["closed", "declined"].includes(i.status)) {
2766
- l({
2857
+ c({
2767
2858
  ...i,
2768
2859
  seen: o
2769
2860
  });
2770
2861
  return;
2771
2862
  }
2772
- let u = {
2773
- ...Ir,
2863
+ let l = {
2864
+ ...Q,
2774
2865
  ...i.sync
2775
2866
  };
2776
2867
  if (![a.requestType, a.stateType].includes(t.type)) {
2777
- l({
2868
+ c({
2778
2869
  ...i,
2779
2870
  seen: o
2780
2871
  });
2781
2872
  return;
2782
2873
  }
2783
- let d = t.type === a.stateType;
2784
- if (d && !u.outgoing.includes(t.data.request_event_id)) {
2785
- l({
2874
+ let u = t.type === a.stateType;
2875
+ if (u && !l.outgoing.includes(t.data.request_event_id)) {
2876
+ c({
2786
2877
  ...i,
2787
2878
  seen: o
2788
2879
  });
@@ -2790,25 +2881,25 @@ function qr() {
2790
2881
  }
2791
2882
  let f = a.rebuild(i, t.data);
2792
2883
  if (!f) {
2793
- l({
2884
+ c({
2794
2885
  ...i,
2795
2886
  seen: o,
2796
- sync: d ? {
2797
- ...u,
2887
+ sync: u ? {
2888
+ ...l,
2798
2889
  status: "failed",
2799
2890
  message: "El rival envió un estado de partida inválido."
2800
- } : u
2891
+ } : l
2801
2892
  });
2802
2893
  return;
2803
2894
  }
2804
- let m = a.compare(i, t.data), h = {
2805
- ...u,
2895
+ let p = a.compare(i, t.data), h = {
2896
+ ...l,
2806
2897
  status: "ok",
2807
2898
  offer: null,
2808
2899
  auto: !1,
2809
2900
  message: ""
2810
- }, g, _ = !d, v = !1, y = m === "mixed" ? a.merge(i, t.data) : null;
2811
- if (m === "equal" || m === "behind") g = {
2901
+ }, g, _ = !u, v = !1, y = p === "mixed" ? a.merge(i, t.data) : null;
2902
+ if (p === "equal" || p === "behind") g = {
2812
2903
  ...f,
2813
2904
  sync: h
2814
2905
  }, a.covers(i, t.data) && (g = {
@@ -2823,12 +2914,12 @@ function qr() {
2823
2914
  } : {
2824
2915
  ...i,
2825
2916
  sync: {
2826
- ...u,
2917
+ ...l,
2827
2918
  status: "failed",
2828
2919
  message: "No se pudo reconstruir la partida local."
2829
2920
  }
2830
2921
  }, _ = !!e, v = !!e;
2831
- } else if (m === "ahead" || n === i.guestId) {
2922
+ } else if (p === "ahead" || n === i.guestId) {
2832
2923
  let e = a.rebuild(i, a.historyOf(i));
2833
2924
  g = e ? {
2834
2925
  ...e,
@@ -2836,7 +2927,7 @@ function qr() {
2836
2927
  } : {
2837
2928
  ...i,
2838
2929
  sync: {
2839
- ...u,
2930
+ ...l,
2840
2931
  status: "failed",
2841
2932
  message: "No se pudo reconstruir la partida local."
2842
2933
  }
@@ -2846,7 +2937,7 @@ function qr() {
2846
2937
  status: "conflict",
2847
2938
  error: "El anfitrión tiene otra versión de la partida. Revísala antes de aceptarla.",
2848
2939
  sync: {
2849
- ...u,
2940
+ ...l,
2850
2941
  status: "incompatible",
2851
2942
  offer: a.offerOf(t.data),
2852
2943
  message: ""
@@ -2858,7 +2949,7 @@ function qr() {
2858
2949
  };
2859
2950
  let b = Date.now(), x = g.sync.replies.filter((e) => b - e < 3e4), S = null;
2860
2951
  if (_ && x.length < 6) try {
2861
- S = Kr(i, a.stateType, {
2952
+ S = $r(i, a.stateType, {
2862
2953
  ...a.historyOf(g),
2863
2954
  request_event_id: t.event_id
2864
2955
  });
@@ -2876,10 +2967,10 @@ function qr() {
2876
2967
  replies: [...x, b],
2877
2968
  outgoing: [...g.sync.outgoing, S.event_id].slice(-8)
2878
2969
  }
2879
- }), l(g), S && c().sendResync(e, S).then(() => {
2970
+ }), c(g), S && d().sendResync(e, S).then(() => {
2880
2971
  v && (s((t) => {
2881
2972
  let n = t.games[e];
2882
- return !n || !p(n).covers(n, p(n).historyOf(n)) ? t : { games: {
2973
+ return !n || !m(n).covers(n, m(n).historyOf(n)) ? t : { games: {
2883
2974
  ...t.games,
2884
2975
  [e]: {
2885
2976
  ...n,
@@ -2887,29 +2978,29 @@ function qr() {
2887
2978
  error: ""
2888
2979
  }
2889
2980
  } };
2890
- }), c().afterGameChange(e));
2981
+ }), d().afterGameChange(e));
2891
2982
  }).catch(() => {});
2892
2983
  },
2893
2984
  sendResync: async (t, n) => {
2894
- let r = c().games[t];
2985
+ let r = d().games[t];
2895
2986
  if (!e || !r || r.scope !== e.getScope?.()) throw Error("Chat no disponible");
2896
- await e.send(r.roomId, ke(n));
2987
+ await e.send(r.roomId, Be(n));
2897
2988
  },
2898
2989
  requestResync: async (t, { auto: n = !1 } = {}) => {
2899
- let r = c().games[t];
2900
- if (!r || r.game === "tanks_live" || !e || ["closed", "declined"].includes(r.status) || r.scope !== e.getScope?.()) return;
2990
+ let r = d().games[t];
2991
+ if (!r || Rr(r) || !e || ["closed", "declined"].includes(r.status) || r.scope !== e.getScope?.()) return;
2901
2992
  let i = {
2902
- ...Ir,
2993
+ ...Q,
2903
2994
  ...r.sync
2904
2995
  };
2905
- if (i.status === "requesting" && Date.now() - i.requestedAt < Fr || n && i.auto) return;
2996
+ if (i.status === "requesting" && Date.now() - i.requestedAt < Ur || n && i.auto) return;
2906
2997
  let a;
2907
2998
  try {
2908
- a = Kr(r, p(r).requestType, p(r).historyOf(r));
2999
+ a = $r(r, m(r).requestType, m(r).historyOf(r));
2909
3000
  } catch {
2910
3001
  return;
2911
3002
  }
2912
- let l = (e) => s((n) => {
3003
+ let c = (e) => s((n) => {
2913
3004
  let r = n.games[t];
2914
3005
  return r?.sync?.requestId !== a.event_id || r.sync.status !== "requesting" ? n : { games: {
2915
3006
  ...n.games,
@@ -2945,20 +3036,20 @@ function qr() {
2945
3036
  }
2946
3037
  } } : e;
2947
3038
  });
2948
- let u = setTimeout(() => {
2949
- o.delete(u), l("El rival no respondió a la sincronización. Reintenta cuando esté conectado.");
2950
- }, Fr);
2951
- o.add(u);
3039
+ let l = setTimeout(() => {
3040
+ o.delete(l), c("El rival no respondió a la sincronización. Reintenta cuando esté conectado.");
3041
+ }, Ur);
3042
+ o.add(l);
2952
3043
  try {
2953
- await c().sendResync(t, a);
3044
+ await d().sendResync(t, a);
2954
3045
  } catch (e) {
2955
- l(e.message || "No se pudo enviar la solicitud de sincronización.");
3046
+ c(e.message || "No se pudo enviar la solicitud de sincronización.");
2956
3047
  }
2957
3048
  },
2958
3049
  adoptResyncOffer: (e) => {
2959
- let t = c().games[e], n = t?.sync?.offer;
3050
+ let t = d().games[e], n = t?.sync?.offer;
2960
3051
  if (!n || t.sync.status !== "incompatible") return !1;
2961
- let r = p(t), i = r.rebuild(t, n);
3052
+ let r = m(t), i = r.rebuild(t, n);
2962
3053
  return s((n) => ({ games: {
2963
3054
  ...n.games,
2964
3055
  [e]: i ? {
@@ -2982,264 +3073,36 @@ function qr() {
2982
3073
  message: "El estado del anfitrión ya no es válido."
2983
3074
  }
2984
3075
  }
2985
- } })), i && c().afterGameChange(e), !!i;
3076
+ } })), i && d().afterGameChange(e), !!i;
2986
3077
  },
2987
3078
  resyncConflicts: (e) => {
2988
- c().restoreTanks(e), Object.values(c().games).filter((t) => t.scope === e && t.status === "conflict").forEach((e) => {
2989
- c().requestResync(e.key, { auto: !0 });
3079
+ d().restoreTanks(e), Object.values(d().games).filter((t) => t.scope === e && t.status === "conflict").forEach((e) => {
3080
+ d().requestResync(e.key, { auto: !0 });
2990
3081
  });
2991
3082
  },
2992
3083
  retry: (t) => {
2993
- let n = c().games[t];
2994
- return !n?.pendingEvent || n.pending ? Promise.resolve() : n.scope === e?.getScope?.() ? c().sendEvent(n.roomId, n.pendingEvent) : Promise.reject(/* @__PURE__ */ Error("La sesión de esta partida ya no está activa."));
3084
+ let n = d().games[t];
3085
+ return !n?.pendingEvent || n.pending ? Promise.resolve() : n.scope === e?.getScope?.() ? d().sendEvent(n.roomId, n.pendingEvent) : Promise.reject(/* @__PURE__ */ Error("La sesión de esta partida ya no está activa."));
2995
3086
  }
2996
3087
  }));
2997
3088
  }
2998
- var X = qr(), Jr = (e) => l(X, e);
2999
- Object.assign(Jr, {
3000
- getState: X.getState,
3001
- setState: X.setState,
3002
- subscribe: X.subscribe
3089
+ var $ = ei(), ti = (e) => f($, e);
3090
+ Object.assign(ti, {
3091
+ getState: $.getState,
3092
+ setState: $.setState,
3093
+ subscribe: $.subscribe
3003
3094
  });
3004
3095
  // src/assets/chatAssets.js
3005
- var Yr = "/sounds", Xr = Yr, Zr = (e) => String(e).replace(/\/+$/, "");
3006
- function Qr(e) {
3007
- Xr = e == null ? Yr : Zr(e);
3008
- }
3009
- function $r() {
3010
- return Xr;
3011
- }
3012
- function ei(e) {
3013
- return `${Xr}/${String(e).replace(/^\/+/, "")}`;
3014
- }
3015
- // src/audio/useSoundSettings.js
3016
- function ti(e) {
3017
- return s(e.subscribe, e.getSettings, e.getSettings);
3018
- }
3019
- // src/games/shared/GameSoundControls.jsx
3020
- function ni({ manager: e }) {
3021
- let { volume: t, muted: n } = ti(e), r = n || t === 0;
3022
- return /* @__PURE__ */ p("div", {
3023
- className: "chat-game-sound",
3024
- children: [/* @__PURE__ */ f("button", {
3025
- type: "button",
3026
- className: "chat-game-sound-toggle",
3027
- onClick: e.toggleMuted,
3028
- "aria-pressed": r,
3029
- "aria-label": r ? "Activar sonido del juego" : "Silenciar sonido del juego",
3030
- title: r ? "Activar sonido" : "Silenciar",
3031
- children: f(r ? d : u, { size: 15 })
3032
- }), /* @__PURE__ */ f("input", {
3033
- type: "range",
3034
- min: "0",
3035
- max: "100",
3036
- step: "5",
3037
- value: Math.round((n ? 0 : t) * 100),
3038
- onChange: (t) => e.setVolume(Number(t.target.value) / 100),
3039
- "aria-label": "Volumen del juego"
3040
- })]
3041
- });
3096
+ var ni = "/sounds", ri = ni, ii = (e) => String(e).replace(/\/+$/, "");
3097
+ function ai(e) {
3098
+ ri = e == null ? ni : ii(e);
3042
3099
  }
3043
- // src/audio/createSoundManager.js
3044
- var ri = [
3045
- "pointerdown",
3046
- "keydown",
3047
- "touchend"
3048
- ], ii = 300, ai = 800, oi = (e) => Math.min(1, Math.max(0, Number(e) || 0));
3049
- function si(e, t) {
3050
- try {
3051
- let n = JSON.parse(localStorage.getItem(e) ?? "null");
3052
- if (n && typeof n == "object") return {
3053
- volume: oi(n.volume ?? t.volume),
3054
- muted: !!n.muted
3055
- };
3056
- } catch {}
3057
- return {
3058
- volume: oi(t.volume),
3059
- muted: !1
3060
- };
3100
+ function oi() {
3101
+ return ri;
3061
3102
  }
3062
- var ci = 1.5, li = .6;
3063
- function ui({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .6, settingsFrom: a = null }) {
3064
- let o = `lira.sound.${e}`, s = typeof window < "u" ? window.AudioContext || window.webkitAudioContext : null, c = a ? a.getSettings() : si(o, { volume: i }), l = null, u = null, d = !1, f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set(), _ = /* @__PURE__ */ new Set(), v = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), b = !1, x = !1, S = null, ee = (e) => `${String(typeof t == "function" ? t() : t).replace(/\/$/, "")}/${n[e]}`, te = (e) => (f.has(e) || f.set(e, fetch(ee(e)).then((e) => e.ok ? e.arrayBuffer() : null).catch(() => null)), f.get(e)), C = () => {
3065
- if (!s) return null;
3066
- if (!l) try {
3067
- l = new s(), u = l.createGain(), u.gain.value = c.muted ? 0 : c.volume, u.connect(l.destination);
3068
- } catch {
3069
- return l = null, null;
3070
- }
3071
- return l.state === "suspended" && l.resume().catch(() => {}), l;
3072
- }, ne = (e) => {
3073
- if (m.has(e) || !n[e]) return Promise.resolve(null);
3074
- if (!p.has(e)) {
3075
- let t = C();
3076
- if (!t) return Promise.resolve(null);
3077
- p.set(e, te(e).then((e) => e ? new Promise((n) => {
3078
- t.decodeAudioData(e.slice(0), n, () => n(null))?.catch?.(() => n(null));
3079
- }) : null).then((t) => (t || m.add(e), t)).catch(() => (m.add(e), null)));
3080
- }
3081
- return p.get(e);
3082
- }, re = (e) => oi(r[e] ?? 1), ie = (e) => {
3083
- if (!_.has(e) || v.has(e) || !d) return;
3084
- let t = C();
3085
- if (!t) return;
3086
- let n = {};
3087
- v.set(e, n), ne(e).then((r) => {
3088
- if (v.get(e) === n) {
3089
- if (!r || t.state === "closed") v.delete(e);
3090
- else try {
3091
- let { fadeIn: n = ci, trim: i = 0 } = y.get(e) ?? {}, a = t.createGain();
3092
- a.gain.setValueAtTime(0, t.currentTime), a.gain.linearRampToValueAtTime(re(e), t.currentTime + n), a.connect(u);
3093
- let o = t.createBufferSource();
3094
- o.buffer = r, o.loop = !0, i > 0 && r.duration > i * 4 && (o.loopStart = i, o.loopEnd = r.duration - i), o.connect(a), o.start(0, i > 0 && r.duration > i * 4 ? i : 0), v.set(e, {
3095
- source: o,
3096
- level: a
3097
- });
3098
- } catch {
3099
- v.delete(e);
3100
- }
3101
- }
3102
- });
3103
- }, w = (e) => {
3104
- let t = v.get(e);
3105
- if (v.delete(e), t?.source && l) try {
3106
- let n = y.get(e)?.fadeOut ?? li, r = l.currentTime;
3107
- t.level.gain.cancelScheduledValues(r), t.level.gain.setValueAtTime(t.level.gain.value, r), t.level.gain.linearRampToValueAtTime(0, r + n), t.source.stop(r + n + .05);
3108
- } catch {}
3109
- }, T = () => {
3110
- d || (d = !0, E(), C() && Object.keys(n).forEach((e) => {
3111
- f.has(e) && ne(e);
3112
- }), _.forEach(ie));
3113
- };
3114
- function E() {
3115
- x && (x = !1, ri.forEach((e) => window.removeEventListener(e, T, !0)));
3116
- }
3117
- let ae = (e) => !h.has(e) && (h.add(e), h.size > ii && h.delete(h.values().next().value), !0), oe = () => g.forEach((e) => e()), se = (e) => {
3118
- c = e, u && (u.gain.value = c.muted ? 0 : c.volume), oe();
3119
- }, D = (e) => {
3120
- let t = {
3121
- volume: oi(e.volume ?? c.volume),
3122
- muted: e.muted ?? c.muted
3123
- };
3124
- try {
3125
- localStorage.setItem(o, JSON.stringify(t));
3126
- } catch {}
3127
- se(t);
3128
- }, O = () => {
3129
- b || (b = !0, a && (c = a.getSettings(), S = a.subscribe(() => se(a.getSettings()))), !(typeof window > "u" || d) && (typeof navigator < "u" && navigator.userActivation?.hasBeenActive ? d = !0 : (x = !0, ri.forEach((e) => window.addEventListener(e, T, {
3130
- capture: !0,
3131
- passive: !0
3132
- })))));
3133
- };
3134
- return {
3135
- start: O,
3136
- dispose: () => {
3137
- E(), S && (S(), S = null), b = !1, _.clear(), v.forEach((e) => {
3138
- try {
3139
- e?.source?.stop();
3140
- } catch {}
3141
- }), v.clear(), p.clear();
3142
- let e = l;
3143
- l = null, u = null, e && e.state !== "closed" && e.close().catch(() => {});
3144
- },
3145
- preload(e = Object.keys(n)) {
3146
- O(), e.forEach((e) => {
3147
- n[e] && !m.has(e) && (te(e), l && ne(e));
3148
- });
3149
- },
3150
- play(e, { key: t } = {}) {
3151
- if (O(), t != null && !ae(`${e}:${t}`) || !n[e] || m.has(e) || !d || c.muted || c.volume === 0) return !1;
3152
- let r = C();
3153
- if (!r) return !1;
3154
- let i = Date.now();
3155
- return ne(e).then((t) => {
3156
- if (!(!t || r.state === "closed" || Date.now() - i > ai)) try {
3157
- let n = r.createBufferSource();
3158
- n.buffer = t;
3159
- let i = re(e);
3160
- if (i === 1) n.connect(u);
3161
- else {
3162
- let e = r.createGain();
3163
- e.gain.value = i, n.connect(e), e.connect(u);
3164
- }
3165
- n.start();
3166
- } catch {}
3167
- }), !0;
3168
- },
3169
- markPlayed(e, t) {
3170
- ae(`${e}:${t}`);
3171
- },
3172
- startLoop(e, t) {
3173
- O(), n[e] && !m.has(e) && (t && y.set(e, t), _.add(e), ie(e));
3174
- },
3175
- stopLoop(e) {
3176
- _.delete(e), w(e);
3177
- },
3178
- getSettings: () => a && !b ? a.getSettings() : c,
3179
- setVolume: a ? a.setVolume : (e) => D({
3180
- volume: e,
3181
- muted: oi(e) === 0 && c.muted
3182
- }),
3183
- setMuted: a ? a.setMuted : (e) => D({ muted: !!e }),
3184
- toggleMuted: a ? a.toggleMuted : () => D({ muted: !c.muted }),
3185
- subscribe(e) {
3186
- return O(), g.add(e), () => g.delete(e);
3187
- }
3188
- };
3189
- }
3190
- // src/games/connect4/connect4Sounds.js
3191
- var Z = ui({
3192
- id: "connect4",
3193
- baseUrl: () => ei("connect4"),
3194
- sounds: {
3195
- invite: "invite.ogg",
3196
- start: "start.ogg",
3197
- drop: "drop.ogg",
3198
- turn: "turn.ogg",
3199
- win: "win.ogg",
3200
- lose: "lose.ogg",
3201
- draw: "draw.ogg",
3202
- close: "close.ogg"
3203
- }
3204
- }), di = 140, Q = /* @__PURE__ */ new Map(), fi = /* @__PURE__ */ new Set(), $ = null, pi = (e, t) => e != null && t != null && String(e) === String(t), mi = () => typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
3205
- function hi(e, t) {
3206
- e.status === "won" ? Z.play(pi(e.winnerId, e.ownId) ? "win" : "lose", { key: t }) : e.status === "draw" ? Z.play("draw", { key: t }) : e.status === "active" && pi(e.turnId, e.ownId) && Z.play("turn", { key: t });
3207
- }
3208
- function gi(e) {
3209
- let t = Q.get(e);
3210
- if (!t) return;
3211
- clearTimeout(t.timer), Q.delete(e), Z.play("drop", { key: e });
3212
- let n = setTimeout(() => {
3213
- fi.delete(n), hi(t.game, e);
3214
- }, di);
3215
- fi.add(n);
3216
- }
3217
- function _i(e) {
3218
- let t = e.lastMove?.eventId;
3219
- if (!t || Q.has(t)) return;
3220
- let n = mi() ? 0 : 440;
3221
- Q.set(t, {
3222
- game: e,
3223
- timer: setTimeout(() => gi(t), n)
3224
- });
3225
- }
3226
- function vi(e, t) {
3227
- t ? t.status === "invited" && e.status === "active" ? Z.play("start", { key: e.lastEventId }) : e.ply > t.ply ? _i(e) : (e.status === "closed" && e.closedBy != null || e.status === "declined") && t.status !== e.status && Z.play("close", { key: e.gameId }) : e.status === "invited" && pi(e.guestId, e.ownId) && Z.play("invite", { key: e.inviteEventId });
3228
- }
3229
- var yi = () => $ != null;
3230
- function bi() {
3231
- if ($) return $;
3232
- Z.start();
3233
- let e = Jr.subscribe((e, t) => {
3234
- e.games !== t.games && Object.entries(e.games).forEach(([e, n]) => {
3235
- let r = t.games[e];
3236
- n.game && n.game !== "connect4" || n !== r && n.ownId != null && vi(n, r);
3237
- });
3238
- }), t = () => {
3239
- $ === t && ($ = null, e(), Q.forEach(({ timer: e }) => clearTimeout(e)), Q.clear(), fi.forEach(clearTimeout), fi.clear());
3240
- };
3241
- return $ = t, t;
3103
+ function si(e) {
3104
+ return `${ri}/${String(e).replace(/^\/+/, "")}`;
3242
3105
  }
3243
- export { x as C, S, L as _, ui as a, ce as b, $r as c, Jr as d, ir as f, R as g, pn as h, bi as i, Qr as l, En as m, yi as n, ni as o, wn as p, gi as r, ei as s, Z as t, X as u, Yt as v, m as w, Ce as x, P as y };
3106
+ export { se as _, ti as a, In as c, I as d, on as f, ce as g, Pe as h, $ as i, Cn as l, xe as m, oi as n, fr as o, N as p, ai as r, Pn as s, si as t, L as u, p as v };
3244
3107
 
3245
- //# sourceMappingURL=connect4Sounds-Cv0q31VW.js.map
3108
+ //# sourceMappingURL=games-BvYTWgaR.js.map