@minicode-dev/chat 0.1.14 → 0.1.16

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 (66) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/chunks/{BattleshipGameCard-B-B4r7lK.js → BattleshipGameCard-DwNzgH5G.js} +199 -199
  3. package/dist/chunks/{BattleshipGameCard-B-B4r7lK.js.map → BattleshipGameCard-DwNzgH5G.js.map} +1 -1
  4. package/dist/chunks/{BattleshipPrototype-CmQd5AUO.js → BattleshipPrototype-CSQxQJt5.js} +52 -52
  5. package/dist/chunks/{BattleshipPrototype-CmQd5AUO.js.map → BattleshipPrototype-CSQxQJt5.js.map} +1 -1
  6. package/dist/chunks/{ChatContext-DQtKsR6Z.js → ChatContext-D5rqvt5D.js} +2 -2
  7. package/dist/chunks/{ChatContext-DQtKsR6Z.js.map → ChatContext-D5rqvt5D.js.map} +1 -1
  8. package/dist/chunks/RacingLiveGameCard-_wvhDRlG.js +1873 -0
  9. package/dist/chunks/RacingLiveGameCard-_wvhDRlG.js.map +1 -0
  10. package/dist/chunks/{TanksGameCard-CvTaF7tu.js → TanksGameCard-B-gtDYYg.js} +144 -144
  11. package/dist/chunks/{TanksGameCard-CvTaF7tu.js.map → TanksGameCard-B-gtDYYg.js.map} +1 -1
  12. package/dist/chunks/TanksLiveGameCard-DXgd1J2Y.js +1274 -0
  13. package/dist/chunks/TanksLiveGameCard-DXgd1J2Y.js.map +1 -0
  14. package/dist/chunks/{avalancheScene3d-Z5QyZIid.js → avalancheScene3d-CNbQyGUd.js} +51 -50
  15. package/dist/chunks/{avalancheScene3d-Z5QyZIid.js.map → avalancheScene3d-CNbQyGUd.js.map} +1 -1
  16. package/dist/chunks/cars-D1PM7mVD.js +340 -0
  17. package/dist/chunks/cars-D1PM7mVD.js.map +1 -0
  18. package/dist/chunks/{connect4Sounds-DmD-E9kX.js → connect4Sounds-3a6h7gUC.js} +8 -8
  19. package/dist/chunks/{connect4Sounds-DmD-E9kX.js.map → connect4Sounds-3a6h7gUC.js.map} +1 -1
  20. package/dist/chunks/createLiveScene-jrzyQogh.js +756 -0
  21. package/dist/chunks/createLiveScene-jrzyQogh.js.map +1 -0
  22. package/dist/chunks/createRaceScene-C-aw0dlX.js +291 -0
  23. package/dist/chunks/createRaceScene-C-aw0dlX.js.map +1 -0
  24. package/dist/chunks/{createTankScene-yhX6la27.js → createTankScene-6asWHKFf.js} +123 -125
  25. package/dist/chunks/{createTankScene-yhX6la27.js.map → createTankScene-6asWHKFf.js.map} +1 -1
  26. package/dist/chunks/fx-BNJvJYOu.js +871 -0
  27. package/dist/chunks/fx-BNJvJYOu.js.map +1 -0
  28. package/dist/chunks/fx-DhXerGyt.js +248 -0
  29. package/dist/chunks/fx-DhXerGyt.js.map +1 -0
  30. package/dist/chunks/{games-BvYTWgaR.js → games-D_9SiSBT.js} +1261 -677
  31. package/dist/chunks/games-D_9SiSBT.js.map +1 -0
  32. package/dist/chunks/tank-DIn6Jyt8.js +605 -0
  33. package/dist/chunks/tank-DIn6Jyt8.js.map +1 -0
  34. package/dist/chunks/{tanks-live-BcKmrhnV.js → tanks-live-BRhYW4MG.js} +36 -36
  35. package/dist/chunks/{tanks-live-BcKmrhnV.js.map → tanks-live-BRhYW4MG.js.map} +1 -1
  36. package/dist/chunks/{tanksSounds-DwjfSp3W.js → tanksSounds-tYPzje61.js} +5 -5
  37. package/dist/chunks/{tanksSounds-DwjfSp3W.js.map → tanksSounds-tYPzje61.js.map} +1 -1
  38. package/dist/chunks/track-C1TWWT19.js +557 -0
  39. package/dist/chunks/track-C1TWWT19.js.map +1 -0
  40. package/dist/index.js +4244 -4028
  41. package/dist/index.js.map +1 -1
  42. package/dist/styles.css +1 -1
  43. package/index.d.ts +2 -0
  44. package/package.json +1 -1
  45. package/dist/chunks/RacingLiveGameCard-c1G7uoDI.js +0 -1654
  46. package/dist/chunks/RacingLiveGameCard-c1G7uoDI.js.map +0 -1
  47. package/dist/chunks/TanksLiveGameCard-COr9Oay5.js +0 -1011
  48. package/dist/chunks/TanksLiveGameCard-COr9Oay5.js.map +0 -1
  49. package/dist/chunks/createLiveScene-CWBunxPi.js +0 -367
  50. package/dist/chunks/createLiveScene-CWBunxPi.js.map +0 -1
  51. package/dist/chunks/createRaceScene-C7Rw89kj.js +0 -305
  52. package/dist/chunks/createRaceScene-C7Rw89kj.js.map +0 -1
  53. package/dist/chunks/decor-CyyCnmct.js +0 -418
  54. package/dist/chunks/decor-CyyCnmct.js.map +0 -1
  55. package/dist/chunks/fx-1ZwzmPWj.js +0 -458
  56. package/dist/chunks/fx-1ZwzmPWj.js.map +0 -1
  57. package/dist/chunks/fx-UZwhOmdl.js +0 -584
  58. package/dist/chunks/fx-UZwhOmdl.js.map +0 -1
  59. package/dist/chunks/games-BvYTWgaR.js.map +0 -1
  60. package/dist/chunks/rolldown-runtime-CGnMp29N.js +0 -10
  61. package/dist/chunks/tank-DjEQ4FXF.js +0 -553
  62. package/dist/chunks/tank-DjEQ4FXF.js.map +0 -1
  63. package/dist/chunks/track-BcnnpnAm.js +0 -259
  64. package/dist/chunks/track-BcnnpnAm.js.map +0 -1
  65. package/dist/chunks/util-DwI9bfS7.js +0 -57
  66. package/dist/chunks/util-DwI9bfS7.js.map +0 -1
@@ -0,0 +1,1274 @@
1
+ import { C as e, D as t, E as n, O as r, S as i, T as a, a as o, b as s, v as c, w as l, x as u, y as d } from "./games-D_9SiSBT.js";
2
+ import { n as f, o as p, s as ee } from "./createPeerLink-DBVs_yvQ.js";
3
+ import { t as m } from "./ChatContext-D5rqvt5D.js";
4
+ import { o as h } from "./connect4Sounds-3a6h7gUC.js";
5
+ import { n as g, r as _, t as v } from "./tanks-live-BRhYW4MG.js";
6
+ import { c as y } from "./RacingLiveGameCard-_wvhDRlG.js";
7
+ import { a as te, c as ne, i as b, n as re, o as x, r as ie, s as S, t as C } from "./tanksSounds-tYPzje61.js";
8
+ import { memo as w, useContext as T, useEffect as E, useRef as D, useState as O } from "react";
9
+ import { Fragment as k, jsx as A, jsxs as j } from "react/jsx-runtime";
10
+ import { AlertTriangle as M, CheckCircle2 as ae, Link2 as N, Loader2 as oe, Settings2 as P } from "lucide-react";
11
+ // src/games/tanks-live/net/createLiveMatch.js
12
+ var se = Object.freeze({
13
+ respawnMs: 3e3,
14
+ shieldMs: 2e3
15
+ }), ce = (e) => typeof e == "number" && Number.isFinite(e), le = (e) => typeof e == "string" && e.length > 0 && e.length < 160;
16
+ function F({ game: o, selfId: m, isHost: h = String(m) === String(o.hostId), signaling: g, onChange: _ = () => {}, peerFactory: v = f, iceServers: y, iceTransportPolicy: te, RTCPeerConnectionImpl: ne } = {}) {
17
+ m = String(m);
18
+ let b = [String(o.hostId), String(o.guestId)];
19
+ if (!b.includes(m) || b[0] === b[1]) throw Error("Invalid live match players");
20
+ let re = (y || []).some((e) => [e.urls].flat().some((e) => /^turns?:/i.test(String(e)))), x = b.find((e) => e !== m), ie = o.liveConfig ?? null, S = !ie, C = S ? u() : c(ie.mapId, ie.seed);
21
+ if (!S && C.hash !== ie.mapHash) throw Error("El mapa no coincide con la invitación");
22
+ let w = S ? 1 : ie.lives;
23
+ if (![
24
+ 1,
25
+ 3,
26
+ 5
27
+ ].includes(w)) throw Error("Vidas inválidas");
28
+ let T = (C.destructibles || []).map((e) => ({
29
+ id: e.id,
30
+ hp: e.hp
31
+ })), E = (e, t) => {
32
+ let n = i(e, t), r = C.spawns?.[t];
33
+ return r && Object.assign(n, {
34
+ x: r.x,
35
+ z: r.z,
36
+ yaw: r.yaw,
37
+ turretYaw: r.yaw
38
+ }), n;
39
+ }, D = (e) => (C.destructibles || []).find((t) => t.id === e), O = b.map(E), k = [], A = [], j = {}, M = 0, ae = 0, N = 0, oe = 0, P = [w, w], F = [0, 0], I = [null, null], L = "connecting", R = null, z = !1, B = {
40
+ phase: "idle",
41
+ rtt: null,
42
+ route: null
43
+ }, ue = !1, V = !1, H = null, U = [], W = null, G = null, de = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Set(), fe = /* @__PURE__ */ new Set(), q = () => O.find((e) => e.id === m), pe = () => O.find((e) => e.id === x), me = () => {
44
+ z || _({
45
+ status: L,
46
+ winner: R,
47
+ net: B
48
+ });
49
+ }, J = (e) => {
50
+ A.push(e), A.length > 200 && A.shift();
51
+ }, Y = (e) => $.sendEvent({
52
+ ...e,
53
+ g: o.gameId,
54
+ r: N
55
+ }), X = (e) => {
56
+ K.add(e), K.size > 2048 && K.delete(K.values().next().value);
57
+ }, Z = (e) => Math.max(0, Math.round(F[e] - M)), he = () => ({
58
+ k: "snapshot",
59
+ hp: O.map((e) => e.hp),
60
+ status: L,
61
+ winner: R,
62
+ reason: H,
63
+ ...S ? {} : {
64
+ lives: [...P],
65
+ shield: [0, 1].map(Z),
66
+ destructibles: (C.destructibles || []).map((e) => ({
67
+ id: e.id,
68
+ hp: e.hp
69
+ }))
70
+ }
71
+ });
72
+ function ge() {
73
+ (C.destructibles || []).forEach((e, t) => {
74
+ e.hp = T[t].hp, e.alive = !0;
75
+ });
76
+ }
77
+ function _e(e) {
78
+ let t = E(b[e], e);
79
+ Object.assign(O[e], {
80
+ x: t.x,
81
+ z: t.z,
82
+ yaw: t.yaw,
83
+ turretYaw: t.turretYaw,
84
+ speed: 0,
85
+ hp: 100,
86
+ alive: !0
87
+ }), I[e] = null, F[e] = M + se.shieldMs, b[e] === x && (U = [], G = null, W = null), J({
88
+ k: "respawn",
89
+ target: b[e],
90
+ x: t.x,
91
+ z: t.z,
92
+ shield: se.shieldMs
93
+ });
94
+ }
95
+ function ve(e, t) {
96
+ P[e] = t, J({
97
+ k: "life_lost",
98
+ target: b[e],
99
+ lives: [...P]
100
+ }), t === 1 && w > 1 && J({
101
+ k: "last_life",
102
+ target: b[e]
103
+ }), I[e] = t > 0 ? M + se.respawnMs : null;
104
+ }
105
+ function Q(e, t) {
106
+ S ? P[e] = 0 : (ve(e, Math.max(0, P[e] - 1)), Y({
107
+ k: "life_lost",
108
+ target: b[e],
109
+ lives: [...P]
110
+ }));
111
+ let n = {
112
+ k: "destroyed",
113
+ target: b[e]
114
+ };
115
+ if (Y(n), J(n), P[e] === 0 && L === "playing") {
116
+ let n = t === b[e] ? b[1 - e] : t;
117
+ Y({
118
+ k: "over",
119
+ winner: n
120
+ }), xe(n);
121
+ }
122
+ }
123
+ function ye(e, t) {
124
+ let n = [];
125
+ for (let { id: t, dmg: r } of e) {
126
+ let e = b.indexOf(t);
127
+ e < 0 || !O[e].alive || F[e] > M || (O[e].hp = Math.max(0, O[e].hp - r), O[e].alive = O[e].hp > 0, O[e].alive || n.push(e));
128
+ }
129
+ return () => n.forEach((e) => Q(e, t));
130
+ }
131
+ function be() {
132
+ O = b.map(E), k = [], P = [w, w], F = [0, 0], I = [null, null], ge(), U = [], W = null, G = null, de.clear(), K.clear(), fe.clear(), V = !1, H = null, R = null, L = B.phase === "connected" ? "playing" : "connecting", J({ k: "rematch" }), me();
133
+ }
134
+ function xe(e, t = !1) {
135
+ (L !== "over" || t && R !== e) && (L = "over", R = e, k = [], $.clearManualTurn?.(), J({
136
+ k: "over",
137
+ winner: R
138
+ }), me());
139
+ }
140
+ function Se(e, t, n) {
141
+ if (L !== "playing" || !le(t.id) || K.has(t.id)) return !1;
142
+ let r = O.find((t) => t.id === e);
143
+ if (!r?.alive || M - (de.get(e) ?? -Infinity) < d.reloadMs - 20 || ![
144
+ t.x,
145
+ t.z,
146
+ t.yaw
147
+ ].every(ce) || Math.hypot(t.x - (e === x && G ? G.x : r.x), t.z - (e === x && G ? G.z : r.z)) > 6) return !1;
148
+ X(t.id), de.set(e, M);
149
+ let i = {
150
+ ...t,
151
+ k: "fire",
152
+ owner: e,
153
+ x: t.x + Math.cos(t.yaw) * 2.8,
154
+ z: t.z + Math.sin(t.yaw) * 2.8,
155
+ y: 1.4,
156
+ age: 0
157
+ };
158
+ return k.push(i), J(i), n && Y({
159
+ ...t,
160
+ k: "fire"
161
+ }), !0;
162
+ }
163
+ function Ce(e) {
164
+ if (z || L !== "playing" || e?.g !== o.gameId || e.r !== N || !Array.isArray(e.p) || e.p.length !== 5 || !e.p.every(ce)) return;
165
+ let [t, n, i, a, s] = e.p;
166
+ if (!pe().alive || !r(t, n, {
167
+ ...C,
168
+ destructibles: []
169
+ }) || Math.abs(s) > d.speed + .1 || Math.abs(i) > 1e6 || Math.abs(a) > 1e6) return;
170
+ let c = W === null ? .1 : Math.max(0, (M - W) / 1e3), l = G || pe();
171
+ if (Math.hypot(t - l.x, n - l.z) > d.speed * c + 3) return;
172
+ let u = {
173
+ ...pe(),
174
+ x: t,
175
+ z: n,
176
+ yaw: i,
177
+ turretYaw: a,
178
+ speed: s
179
+ };
180
+ G = u, W = M, U.push({
181
+ time: M,
182
+ pose: u
183
+ }), U.length > 30 && U.shift();
184
+ }
185
+ let we = (e, t) => Object.keys(e).every((e) => t.includes(e)), Te = (e) => Array.isArray(e) && e.length === 2 && e.every((e) => Number.isInteger(e) && e >= 0 && e <= w), Ee = (e) => Te(e.lives) && Array.isArray(e.shield) && e.shield.length === 2 && e.shield.every((e) => Number.isInteger(e) && e >= 0 && e <= se.shieldMs) && Array.isArray(e.destructibles) && e.destructibles.length === T.length && e.destructibles.every((e, t) => e && we(e, ["id", "hp"]) && e.id === T[t].id && Number.isInteger(e.hp) && e.hp >= 0 && e.hp <= T[t].hp);
186
+ function De(e, t, n, r) {
187
+ J({
188
+ k: "destructible_hit",
189
+ id: t,
190
+ target: e.id,
191
+ kind: e.kind,
192
+ hp: e.hp,
193
+ x: n,
194
+ z: r
195
+ }), e.hp === 0 && e.kind === "crate" && J({
196
+ k: "crate_break",
197
+ id: e.id,
198
+ x: e.x,
199
+ z: e.z
200
+ });
201
+ }
202
+ function Oe(e) {
203
+ if (z || !e || e.g !== o.gameId || !Number.isInteger(e.r)) return;
204
+ if (e.k === "round" && !h && L === "over" && fe.has(m) && e.r === N + 1) {
205
+ N = e.r, be();
206
+ return;
207
+ }
208
+ if (e.r !== N) return;
209
+ if (e.k === "sync" && h) {
210
+ Y(he());
211
+ return;
212
+ }
213
+ if (e.k === "snapshot" && !h && Array.isArray(e.hp) && e.hp.length === 2 && e.hp.every((e) => Number.isInteger(e) && e >= 0 && e <= 100)) {
214
+ if (!S && !Ee(e)) return;
215
+ let t = S ? P : e.lives, n = e.status === "playing" && e.winner === null && e.hp.every((e, n) => e > 0 || !S && t[n] > 0), r = e.status === "over" && b.includes(e.winner) && (e.hp[1 - b.indexOf(e.winner)] === 0 && t[1 - b.indexOf(e.winner)] === (S ? P[1 - b.indexOf(e.winner)] : 0) || e.reason === "resigned");
216
+ if (!n && !r) return;
217
+ S || (e.destructibles.forEach((e, t) => {
218
+ let n = C.destructibles[t];
219
+ n.hp = e.hp, n.alive = e.hp > 0;
220
+ }), O.forEach((t, n) => {
221
+ let r = t.hp === 0;
222
+ P[n] = e.lives[n], r && e.hp[n] > 0 && _e(n), F[n] = e.shield[n] ? M + e.shield[n] : 0, e.hp[n] === 0 && P[n] > 0 && I[n] === null && (I[n] = M + se.respawnMs);
223
+ })), O.forEach((t, n) => {
224
+ t.hp = e.hp[n], t.alive = t.hp > 0;
225
+ }), r && (V = !1, H = e.reason, xe(e.winner, !0));
226
+ return;
227
+ }
228
+ if (e.k === "resign") {
229
+ H = "resigned", xe(m, h), h && Y(he());
230
+ return;
231
+ }
232
+ if (e.k === "rematch" && L === "over") {
233
+ fe.add(x), ke();
234
+ return;
235
+ }
236
+ if (L !== "playing" || (e.k === "fire" && Se(x, e, !1), !h && e.k === "hit" && le(e.id) && !K.has(`hit:${e.id}`) && b.includes(e.target) && Array.isArray(e.hp) && e.hp.length === 2 && e.hp.every((e, t) => Number.isInteger(e) && e >= 0 && e <= O[t].hp) && [e.x, e.z].every(ce) && (X(`hit:${e.id}`), O.forEach((t, n) => {
237
+ t.hp = e.hp[n], t.alive = t.hp > 0;
238
+ }), k = k.filter((t) => t.id !== e.id), J(e)), !h && e.k === "destroyed" && b.includes(e.target) && !K.has(`destroyed:${e.target}:${P[b.indexOf(e.target)]}`) && O.find((t) => t.id === e.target).hp === 0 && (X(`destroyed:${e.target}:${P[b.indexOf(e.target)]}`), J(e)), !h && e.k === "over" && b.includes(e.winner) && O.find((t) => t.id !== e.winner).hp === 0 && (S || P[1 - b.indexOf(e.winner)] === 0) && xe(e.winner), h || S)) return;
239
+ let t = b.indexOf(e.target);
240
+ if (e.k === "life_lost" && t >= 0 && O[t].hp === 0 && Te(e.lives) && e.lives[t] === P[t] - 1 && e.lives[1 - t] === P[1 - t] && ve(t, e.lives[t]), e.k === "respawn" && t >= 0 && O[t].hp === 0 && P[t] > 0 && we(e, [
241
+ "k",
242
+ "target",
243
+ "g",
244
+ "r"
245
+ ]) && _e(t), e.k === "destructible_hit" && le(e.id) && !K.has(`dh:${e.id}`) && we(e, [
246
+ "k",
247
+ "id",
248
+ "target",
249
+ "hp",
250
+ "x",
251
+ "z",
252
+ "g",
253
+ "r"
254
+ ]) && [e.x, e.z].every(ce)) {
255
+ let t = D(e.target);
256
+ if (!n(t) || !Number.isInteger(e.hp) || e.hp < 0 || e.hp >= t.hp) return;
257
+ X(`dh:${e.id}`), t.hp = e.hp, t.alive = e.hp > 0, k = k.filter((t) => t.id !== e.id), De(t, e.id, e.x, e.z);
258
+ }
259
+ if (e.k === "barrel_explode" && we(e, [
260
+ "k",
261
+ "target",
262
+ "chained",
263
+ "hp",
264
+ "g",
265
+ "r"
266
+ ]) && !K.has(`be:${e.target}`)) {
267
+ let t = D(e.target), r = e.chained === null ? null : D(e.chained);
268
+ if (t?.kind !== "barrel" || n(t) || e.chained !== null && (r?.kind !== "barrel" || !n(r) || r === t) || !Array.isArray(e.hp) || e.hp.length !== 2 || !e.hp.every((e, t) => Number.isInteger(e) && e >= 0 && e <= O[t].hp)) return;
269
+ X(`be:${e.target}`), r && (r.hp = 0, r.alive = !1), O.forEach((t, n) => {
270
+ t.hp = e.hp[n], t.alive = t.hp > 0;
271
+ }), J({
272
+ k: "barrel_explode",
273
+ id: t.id,
274
+ x: t.x,
275
+ z: t.z,
276
+ chained: r ? {
277
+ id: r.id,
278
+ x: r.x,
279
+ z: r.z
280
+ } : null,
281
+ hp: [...e.hp]
282
+ });
283
+ }
284
+ }
285
+ let $ = v({
286
+ configurationAuthority: h,
287
+ signaling: g && {
288
+ send(e) {
289
+ let t = p(e);
290
+ if (!t) return Promise.reject(/* @__PURE__ */ Error("Invalid live signal"));
291
+ let n = ee({
292
+ ...t,
293
+ liveGame: o.gameId
294
+ });
295
+ return n ? g.send(n) : Promise.reject(/* @__PURE__ */ Error("Live signal too large"));
296
+ },
297
+ subscribe(e) {
298
+ return g.subscribe((t) => {
299
+ p(t?.text)?.liveGame === o.gameId && e(t);
300
+ });
301
+ }
302
+ },
303
+ selfId: m,
304
+ peerId: x,
305
+ roomId: o.roomId,
306
+ iceServers: y,
307
+ iceTransportPolicy: te,
308
+ RTCPeerConnectionImpl: ne,
309
+ onMove: Ce,
310
+ onEvent: Oe,
311
+ onChange(e) {
312
+ let t = B.phase;
313
+ if (B = e, e.phase === "connected") {
314
+ let e = ue;
315
+ ue = !0, L !== "over" && (L = "playing"), t !== "connected" && queueMicrotask(() => {
316
+ z || (V && Y({ k: "resign" }), h && e ? Y(he()) : h || Y({ k: "sync" }));
317
+ });
318
+ } else L !== "over" && (L = ue ? "disconnected" : "connecting");
319
+ me();
320
+ }
321
+ });
322
+ function ke() {
323
+ h && fe.size === 2 && (N++, Y({ k: "round" }), be());
324
+ }
325
+ return h ? $.connect() : $.setListening(!0), {
326
+ setInput(e) {
327
+ j = { ...e };
328
+ },
329
+ step(n) {
330
+ if (z) return;
331
+ let r = Math.max(0, Math.min(Number(n) || 0, 100));
332
+ if (M += r, L !== "playing") return;
333
+ let i = r / 1e3;
334
+ for (let e = 0; e < 2; e++) F[e] && M >= F[e] && (F[e] = 0, J({
335
+ k: "shield_end",
336
+ target: b[e]
337
+ })), h && I[e] !== null && M >= I[e] && P[e] > 0 && (_e(e), Y({
338
+ k: "respawn",
339
+ target: b[e]
340
+ }));
341
+ let c = M - 100;
342
+ for (; U.length > 1 && U[1].time <= c;) U.shift();
343
+ if (U.length) {
344
+ let e = U[0], t = U[1] || e, n = a(e.pose, t.pose, t.time === e.time ? 1 : (c - e.time) / (t.time - e.time));
345
+ for (let e of [
346
+ "x",
347
+ "z",
348
+ "yaw",
349
+ "turretYaw",
350
+ "speed"
351
+ ]) pe()[e] = n[e];
352
+ }
353
+ for (let e = i; e > 0; e -= .016) t(q(), j, Math.min(e, .016), C);
354
+ j.fire && Se(m, {
355
+ id: `${m}:${N}:${++oe}`,
356
+ x: q().x,
357
+ z: q().z,
358
+ yaw: q().turretYaw,
359
+ t: M
360
+ }, !0);
361
+ let u = B.rtt > 250 || B.move?.lossPct > 15 ? 10 : B.rtt > 100 ? 15 : 20;
362
+ if (M >= ae) {
363
+ ae = M + 1e3 / u;
364
+ let e = q();
365
+ $.sendMove({
366
+ g: o.gameId,
367
+ r: N,
368
+ p: [
369
+ e.x,
370
+ e.z,
371
+ e.yaw,
372
+ e.turretYaw,
373
+ e.speed
374
+ ],
375
+ t: M
376
+ });
377
+ }
378
+ k = k.filter((t) => {
379
+ let n = s(t, i, C, O);
380
+ if (!n) return !0;
381
+ if (h && n.target && L === "playing" && F[b.indexOf(n.target)] > M) J({
382
+ k: "impact",
383
+ kind: "shield",
384
+ target: n.target,
385
+ x: t.x,
386
+ z: t.z
387
+ });
388
+ else if (h && n.target && L === "playing") {
389
+ let e = O.find((e) => e.id === n.target);
390
+ e.hp = Math.max(0, e.hp - d.damage), e.alive = e.hp > 0;
391
+ let r = {
392
+ k: "hit",
393
+ id: t.id,
394
+ target: e.id,
395
+ dmg: d.damage,
396
+ hp: O.map((e) => e.hp),
397
+ x: t.x,
398
+ z: t.z
399
+ };
400
+ Y(r), J(r), e.alive || Q(b.indexOf(e.id), t.owner);
401
+ } else if (h && n.kind === "destructible" && L === "playing") {
402
+ let r = D(n.id), i = e(C, n.id, 1);
403
+ if (Y({
404
+ k: "destructible_hit",
405
+ id: t.id,
406
+ target: n.id,
407
+ hp: i.hp,
408
+ x: t.x,
409
+ z: t.z
410
+ }), De(r, t.id, t.x, t.z), i.destroyed && r.kind === "barrel") {
411
+ let e = l(C, r.id, O), n = ye(e.hits, t.owner), i = {
412
+ k: "barrel_explode",
413
+ target: r.id,
414
+ chained: e.chained?.id ?? null,
415
+ hp: O.map((e) => e.hp)
416
+ };
417
+ Y(i), J({
418
+ k: "barrel_explode",
419
+ id: r.id,
420
+ x: r.x,
421
+ z: r.z,
422
+ chained: e.chained,
423
+ hp: [...i.hp]
424
+ }), n();
425
+ }
426
+ } else J({
427
+ k: "impact",
428
+ kind: n.kind,
429
+ x: t.x,
430
+ z: t.z
431
+ }), n.shape === "rect" && J({
432
+ k: "wall_hit",
433
+ id: n.id,
434
+ kind: n.obstacleKind,
435
+ x: t.x,
436
+ z: t.z
437
+ });
438
+ return !1;
439
+ });
440
+ },
441
+ getRender() {
442
+ let e = {
443
+ arena: C,
444
+ map: C,
445
+ maxLives: w,
446
+ lives: [...P],
447
+ shield: [0, 1].map(Z),
448
+ respawn: I.map((e) => e === null ? null : Math.max(0, Math.round(e - M))),
449
+ destructibles: (C.destructibles || []).map((e) => ({
450
+ id: e.id,
451
+ kind: e.kind,
452
+ x: e.x,
453
+ z: e.z,
454
+ r: e.r,
455
+ hp: e.hp,
456
+ alive: n(e)
457
+ })),
458
+ tanks: O.map((e) => ({
459
+ ...e,
460
+ self: e.id === m,
461
+ reload: Math.min(1, (M - (de.get(e.id) ?? -Infinity)) / d.reloadMs)
462
+ })),
463
+ shells: k.map((e) => ({ ...e })),
464
+ events: A,
465
+ status: L,
466
+ winner: R,
467
+ net: {
468
+ ...B,
469
+ turnConfigured: B.turnConfigured ?? re
470
+ }
471
+ };
472
+ return A = [], e;
473
+ },
474
+ configureTurn(e, t) {
475
+ return z || L === "over" ? Promise.reject(/* @__PURE__ */ Error("La partida ya terminó.")) : $.configureTurn(e, t);
476
+ },
477
+ reconnect() {
478
+ !z && L !== "over" && ($.requestReconnect ? $.requestReconnect() : $.connect());
479
+ },
480
+ rematch() {
481
+ !z && L === "over" && (fe.add(m), Y({ k: "rematch" }), ke());
482
+ },
483
+ resign() {
484
+ !z && L !== "over" && (V = !0, H = "resigned", Y({ k: "resign" }), xe(x));
485
+ },
486
+ destroy() {
487
+ z || (z = !0, $.destroy(), k = [], U = [], A = []);
488
+ }
489
+ };
490
+ }
491
+ var I = 180 / Math.PI, L = (e, t) => Number.isFinite(e) ? e : t;
492
+ function R(e) {
493
+ let t = e || {}, n = t.bounds || t;
494
+ if (Number.isFinite(n.minX) && Number.isFinite(n.maxX) && Number.isFinite(n.minZ) && Number.isFinite(n.maxZ)) return z({
495
+ minX: n.minX,
496
+ minZ: n.minZ,
497
+ maxX: n.maxX,
498
+ maxZ: n.maxZ
499
+ });
500
+ let r = L(t.width, L(t.size, 120)), i = L(t.depth, L(t.height, L(t.size, r)));
501
+ return z(t.centered === !0 || t.origin === "center" ? {
502
+ minX: -r / 2,
503
+ minZ: -i / 2,
504
+ maxX: r / 2,
505
+ maxZ: i / 2
506
+ } : {
507
+ minX: 0,
508
+ minZ: 0,
509
+ maxX: r,
510
+ maxZ: i
511
+ });
512
+ }
513
+ function z(e) {
514
+ return {
515
+ ...e,
516
+ width: e.maxX - e.minX,
517
+ depth: e.maxZ - e.minZ,
518
+ cx: (e.minX + e.maxX) / 2,
519
+ cz: (e.minZ + e.maxZ) / 2
520
+ };
521
+ }
522
+ function B(e) {
523
+ return (e?.obstacles || []).filter((e) => Number.isFinite(e?.x) && Number.isFinite(e?.z)).map((e) => ({
524
+ x: e.x,
525
+ z: e.z,
526
+ r: L(e.r, L(e.radius, 1.5)),
527
+ kind: e.kind === "tree" ? "tree" : "rock"
528
+ }));
529
+ }
530
+ var ue = (e) => e ? e.k ?? e.type ?? null : null;
531
+ function V(e, t) {
532
+ let n = t || [], r = e?.tank ?? e?.by ?? e?.owner ?? e?.from;
533
+ if (r != null) {
534
+ let e = n.find((e) => String(e.id) === String(r));
535
+ if (e) return e;
536
+ }
537
+ if (!Number.isFinite(e?.x) || !Number.isFinite(e?.z)) return null;
538
+ let i = null, a = Infinity;
539
+ for (let t of n) {
540
+ let n = (t.x - e.x) ** 2 + (t.z - e.z) ** 2;
541
+ n < a && (a = n, i = t);
542
+ }
543
+ return i;
544
+ }
545
+ var H = (e, t) => t == null ? null : (e || []).find((e) => String(e.id) === String(t)) || null, U = (e) => (e || []).find((e) => e.self) || null, W = (e, t = !0) => !t || e <= 25 ? 2 : +(e <= 50), G = (e) => {
546
+ let t = e % (Math.PI * 2);
547
+ return t > Math.PI && (t -= Math.PI * 2), t < -Math.PI && (t += Math.PI * 2), t;
548
+ };
549
+ function de({ moveSpeed: e = .6, turnSpeed: t = .35, holdMs: n = 160 } = {}) {
550
+ let r = null, i = !1, a = !1, o = 0, s = 0;
551
+ return {
552
+ update(c, l) {
553
+ let u = [];
554
+ if (!c || c.alive === !1) return i && u.push({ type: "move_end" }), a && u.push({ type: "turret_end" }), i = a = !1, r = null, u;
555
+ let d = Math.max(1, l) / 1e3;
556
+ if (r) {
557
+ let f = Math.hypot(c.x - r.x, c.z - r.z) / d, p = Math.abs(G((c.yaw ?? 0) - r.yaw)) / d, ee = Math.abs(G((c.turretYaw ?? 0) - (c.yaw ?? 0) - r.rel)) / d, m = f > e || p > t;
558
+ o = m ? 0 : o + l, m && !i ? (i = !0, u.push({ type: "move_start" })) : !m && i && o >= n && (i = !1, u.push({ type: "move_end" }));
559
+ let h = ee > t;
560
+ s = h ? 0 : s + l, h && !a ? (a = !0, u.push({ type: "turret_start" })) : !h && a && s >= n && (a = !1, u.push({ type: "turret_end" }));
561
+ }
562
+ return r = {
563
+ x: c.x,
564
+ z: c.z,
565
+ yaw: c.yaw ?? 0,
566
+ rel: G((c.turretYaw ?? 0) - (c.yaw ?? 0))
567
+ }, u;
568
+ },
569
+ reset() {
570
+ r = null, i = a = !1, o = s = 0;
571
+ },
572
+ get moving() {
573
+ return i;
574
+ },
575
+ get turning() {
576
+ return a;
577
+ }
578
+ };
579
+ }
580
+ function K(e) {
581
+ switch (ue(e)) {
582
+ case "fire": return [{ type: "fire" }, { type: "projectile_start" }];
583
+ case "impact": return [{
584
+ type: "impact",
585
+ kind: e.kind === "obstacle" ? "obstacle" : "terrain"
586
+ }];
587
+ case "hit": return [{ type: "tank_hit" }];
588
+ case "destroyed": return [{ type: "destroyed" }];
589
+ default: return [];
590
+ }
591
+ }
592
+ function fe(e) {
593
+ if (!e || e.status !== "over") return null;
594
+ let t = U(e.tanks);
595
+ return !t || e.winner == null ? null : String(e.winner) === String(t.id) ? "victory" : "defeat";
596
+ }
597
+ var q = {
598
+ meadow: "Pradera",
599
+ forest: "Bosque",
600
+ desert: "Desierto",
601
+ ruins: "Ciudad en ruinas",
602
+ arctic: "Ártico"
603
+ }, pe = {
604
+ meadow: "🌿",
605
+ forest: "🌲",
606
+ desert: "🏜️",
607
+ ruins: "🏚️",
608
+ arctic: "❄️"
609
+ }, me = (e) => !!(e && typeof e.id == "string" && q[e.id]), J = (e) => me(e) ? q[e.id] : null;
610
+ function Y(e) {
611
+ return (e?.obstacles || []).filter((e) => Number.isFinite(e?.x) && Number.isFinite(e?.z)).map((e) => e.shape === "rect" ? {
612
+ id: e.id,
613
+ shape: "rect",
614
+ x: e.x,
615
+ z: e.z,
616
+ w: L(e.w, 2),
617
+ d: L(e.d, 2),
618
+ rot: L(e.rot, 0),
619
+ kind: e.kind || "wall"
620
+ } : {
621
+ id: e.id,
622
+ shape: "circle",
623
+ x: e.x,
624
+ z: e.z,
625
+ r: L(e.r, L(e.radius, 1.5)),
626
+ kind: e.kind || "rock"
627
+ });
628
+ }
629
+ function X(e) {
630
+ return (e?.destructibles || []).filter((e) => e?.id != null && Number.isFinite(e.x) && Number.isFinite(e.z)).map((e) => ({
631
+ id: String(e.id),
632
+ x: e.x,
633
+ z: e.z,
634
+ r: L(e.r, e.kind === "barrel" ? .9 : 1.2),
635
+ kind: e.kind === "barrel" ? "barrel" : "crate"
636
+ }));
637
+ }
638
+ function Z(e) {
639
+ let t = /* @__PURE__ */ new Set();
640
+ for (let n of e?.destructibles || []) n && n.id != null && (n.alive === !1 || Number.isFinite(n.hp) && n.hp <= 0) && t.add(String(n.id));
641
+ return t;
642
+ }
643
+ var he = (e, t) => (e?.tanks || []).findIndex((e) => String(e.id) === String(t?.id));
644
+ function ge(e, t) {
645
+ if (Number.isFinite(t?.lives)) return t.lives;
646
+ let n = he(e, t), r = Array.isArray(e?.lives) && n >= 0 ? e.lives[n] : void 0;
647
+ return Number.isFinite(r) ? r : null;
648
+ }
649
+ function _e(e, t) {
650
+ if (Number.isFinite(t?.shield)) return Math.max(0, t.shield);
651
+ if (t?.shield === !0) return 1;
652
+ let n = he(e, t), r = Array.isArray(e?.shield) && n >= 0 ? e.shield[n] : 0;
653
+ return Number.isFinite(r) ? Math.max(0, r) : +(r === !0);
654
+ }
655
+ function ve(e) {
656
+ let t = Number(e?.maxLives ?? e?.map?.lives ?? e?.arena?.lives);
657
+ if (Number.isFinite(t) && t > 0) return t;
658
+ let n = (e?.tanks || []).map((t) => ge(e, t)).filter(Number.isFinite);
659
+ return n.length ? Math.max(...n) : null;
660
+ }
661
+ var Q = /* @__PURE__ */ new Set([
662
+ "respawn",
663
+ "shield_end",
664
+ "last_life",
665
+ "health_pickup"
666
+ ]);
667
+ function ye(e, t) {
668
+ let n = ue(e), r = e?.target ?? e?.tank ?? e?.id, i = U(t?.tanks), a = i != null && r != null && String(r) === String(i.id);
669
+ switch (n) {
670
+ case "life_lost": return ["life_lost"];
671
+ case "crate_break": return ["crate_break"];
672
+ case "barrel_explode": return ["barrel_explode"];
673
+ case "wall_hit": return ["wall_hit"];
674
+ case "pickup":
675
+ case "health_pickup": return a || r == null ? ["health_pickup"] : [];
676
+ default: return Q.has(n) && (a || r == null) ? [n] : [];
677
+ }
678
+ }
679
+ // src/games/tanks-live/scene/createLiveScene2d.js
680
+ var be = {
681
+ meadow: {
682
+ bg: "#152519",
683
+ ground: "#526348"
684
+ },
685
+ forest: {
686
+ bg: "#10200f",
687
+ ground: "#3f5a33"
688
+ },
689
+ desert: {
690
+ bg: "#3a2e1c",
691
+ ground: "#c9a86c"
692
+ },
693
+ ruins: {
694
+ bg: "#24221f",
695
+ ground: "#7a7266"
696
+ },
697
+ arctic: {
698
+ bg: "#2a3846",
699
+ ground: "#dfe9f2"
700
+ }
701
+ }, xe = {
702
+ tree: "#24472d",
703
+ rock: "#929285",
704
+ log: "#6b4a2e",
705
+ ice: "#a9dcef",
706
+ wall: "#9a8f84",
707
+ house: "#a8927a",
708
+ car: "#6b4a35",
709
+ ice_block: "#bfe6f5",
710
+ low: "#a89468"
711
+ }, Se = {
712
+ grass: "#4f7a34",
713
+ weed: "#5e6b33",
714
+ dry_grass: "#a8935a",
715
+ flower: "#e8d24a",
716
+ bush: "#2f5a27",
717
+ pebble: "#8d877e",
718
+ rubble: "#6e675e",
719
+ bones: "#ece2cc",
720
+ snow: "#ffffff",
721
+ ice_shard: "#a9dcef",
722
+ cactus: "#3f7a36"
723
+ };
724
+ function Ce(e, { arena: t } = {}) {
725
+ let n = document.createElement("canvas");
726
+ n.style.cssText = "width:100%;height:100%;display:block", e.appendChild(n);
727
+ let r = n.getContext("2d");
728
+ if (!r) throw n.remove(), Error("Canvas 2D unavailable");
729
+ let i = R(t), a = me(t) ? t : null, o = a ? be[a.id] : {
730
+ bg: "#152519",
731
+ ground: "#526348"
732
+ }, s = a ? Y(t) : B(t).map((e) => ({
733
+ ...e,
734
+ shape: "circle"
735
+ })), c = a ? X(t) : [], l = a ? (t.decor || []).filter((e) => Se[e?.kind] && Number.isFinite(e.x) && Number.isFinite(e.z)) : [], u = 0, d = 1, f = 1, p = 1, ee = 0, m = 0;
736
+ function h() {
737
+ d = Math.max(1, e.clientWidth), f = Math.max(1, e.clientHeight);
738
+ let t = Math.min(window.devicePixelRatio || 1, 2);
739
+ n.width = d * t, n.height = f * t, r.setTransform(t, 0, 0, t, 0, 0), p = Math.min(d / i.width, f / i.depth), ee = (d - i.width * p) / 2, m = (f - i.depth * p) / 2;
740
+ }
741
+ h();
742
+ let g = typeof ResizeObserver == "function" ? new ResizeObserver(h) : null;
743
+ return g?.observe(e), {
744
+ kind: "2d",
745
+ resize: h,
746
+ screenToGround(e, t) {
747
+ return {
748
+ x: ((e + 1) * d / 2 - ee) / p + i.minX,
749
+ z: ((1 - t) * f / 2 - m) / p + i.minZ
750
+ };
751
+ },
752
+ render(e, t = 16) {
753
+ u += (Number(t) || 16) / 1e3, r.fillStyle = o.bg, r.fillRect(0, 0, d, f), r.save(), r.translate(ee, m), r.scale(p, p), r.translate(-i.minX, -i.minZ), r.fillStyle = o.ground, r.fillRect(i.minX, i.minZ, i.width, i.depth);
754
+ for (let e of l) r.fillStyle = Se[e.kind], r.beginPath(), r.arc(e.x, e.z, .35 * (Number(e.s) || 1), 0, Math.PI * 2), r.fill();
755
+ for (let e of s) r.fillStyle = xe[e.kind] || "#929285", e.shape === "rect" ? (r.save(), r.translate(e.x, e.z), r.rotate(e.rot), r.fillRect(-e.w / 2, -e.d / 2, e.w, e.d), e.kind === "low" && (r.strokeStyle = "#6f5f3c", r.lineWidth = .25, r.strokeRect(-e.w / 2, -e.d / 2, e.w, e.d)), r.restore()) : (r.beginPath(), r.arc(e.x, e.z, e.r, 0, Math.PI * 2), r.fill());
756
+ let n = Z(e);
757
+ for (let e of c) n.has(e.id) || (e.kind === "barrel" ? (r.fillStyle = "#c62d24", r.beginPath(), r.arc(e.x, e.z, e.r, 0, Math.PI * 2), r.fill(), r.strokeStyle = "#3a2a24", r.lineWidth = .25, r.stroke()) : (r.fillStyle = "#a7773f", r.fillRect(e.x - e.r * .8, e.z - e.r * .8, e.r * 1.6, e.r * 1.6), r.strokeStyle = "#5e3f1e", r.lineWidth = .2, r.strokeRect(e.x - e.r * .8, e.z - e.r * .8, e.r * 1.6, e.r * 1.6)));
758
+ for (let t of e.tanks || []) {
759
+ r.save(), r.translate(t.x, t.z), r.rotate(t.yaw), r.fillStyle = t.alive === !1 ? "#333" : t.color || "#73ce68", r.fillRect(-3, -1.8, 6, 3.6), r.restore(), r.save(), r.translate(t.x, t.z), r.rotate(t.turretYaw), r.strokeStyle = "#dce8cf", r.lineWidth = .8, r.beginPath(), r.moveTo(0, 0), r.lineTo(5, 0), r.stroke(), r.restore();
760
+ let n = t.alive === !1 ? 0 : _e(e, t);
761
+ n > 0 && (n > 500 || Math.floor(u * 8) % 2 == 0) && (r.fillStyle = "rgba(127,220,255,0.28)", r.strokeStyle = "#7fdcff", r.lineWidth = .35, r.beginPath(), r.arc(t.x, t.z, 4.6, 0, Math.PI * 2), r.fill(), r.stroke()), t.self && (r.strokeStyle = "#fff", r.lineWidth = .3, r.beginPath(), r.arc(t.x, t.z, 4, 0, Math.PI * 2), r.stroke());
762
+ }
763
+ r.fillStyle = "#ffe097";
764
+ for (let t of e.shells || []) r.beginPath(), r.arc(t.x, t.z, .7, 0, Math.PI * 2), r.fill();
765
+ r.restore();
766
+ },
767
+ dispose() {
768
+ g?.disconnect(), n.remove();
769
+ }
770
+ };
771
+ }
772
+ // src/games/tanks-live/TanksLiveGameCard.jsx
773
+ var we = /* @__PURE__ */ y({ default: () => je }), Te = (e, t) => {
774
+ o.getState().act(e, t).catch(() => {});
775
+ }, Ee = (e) => {
776
+ e.throttle = 0, e.steer = 0, e.fire = !1;
777
+ }, De = 3e3, Oe = (e) => me(e?.map) ? e.map : e?.arena;
778
+ function $({ lives: e, max: t, label: n }) {
779
+ if (!Number.isFinite(e)) return null;
780
+ let r = Math.max(e, t || e);
781
+ return /* @__PURE__ */ A("span", {
782
+ className: `tl-hearts${e === 1 && r > 1 ? " tl-hearts--last" : ""}`,
783
+ role: "img",
784
+ "aria-label": `${n}: ${e} ${e === 1 ? "vida" : "vidas"}`,
785
+ children: Array.from({ length: r }, (t, n) => /* @__PURE__ */ A("span", {
786
+ className: n < e ? "tl-heart" : "tl-heart tl-heart--lost",
787
+ "aria-hidden": "true",
788
+ children: n < e ? "❤️" : "🖤"
789
+ }, n))
790
+ });
791
+ }
792
+ function ke(e, t) {
793
+ let n = e?.manualTurn;
794
+ return n?.status === "applying" ? "Aplicando configuración…" : n?.status === "sharing" ? "Sincronizando con el otro jugador…" : n?.status === "waiting_peer" ? "Esperando al otro jugador para compartir la configuración…" : e?.phase === "connected" ? "¡Conexión establecida!" : n?.status === "failed" || e?.phase === "failed" || e?.ice === "failed" ? "No pudimos conectar. Puedes reintentar." : t ? "La conexión está tardando más de lo esperado" : e?.phase === "restarting" || e?.phase === "reconnecting" ? "Reconectando…" : e?.phase === "listening" ? "Esperando la conexión del otro jugador…" : e?.phase === "calling" ? "Buscando al otro jugador…" : e?.phase === "negotiating" ? "Buscando una conexión entre los jugadores…" : "Preparando partida…";
795
+ }
796
+ function Ae({ gameKey: e, currentUserId: t, onMinimize: n, onDismiss: r, suspended: i = !1 }) {
797
+ let a = T(m)?.config?.webrtc, s = o((t) => t.games[e]), c = D(i);
798
+ c.current = i;
799
+ let l = D(null), u = D(null), d = D(null), f = D({
800
+ throttle: 0,
801
+ steer: 0,
802
+ fire: !1
803
+ }), [p, ee] = O(null), [y, w] = O(""), [se, ce] = O(!1), [le, I] = O("loading"), [L, R] = O(!1), [z, B] = O(0), V = p?.net?.phase === "connected";
804
+ E(() => {
805
+ if (!s || s.status !== "active" || V) {
806
+ B(0);
807
+ return;
808
+ }
809
+ let e = Date.now(), t = setInterval(() => B(Date.now() - e), 1e3);
810
+ return () => clearInterval(t);
811
+ }, [
812
+ e,
813
+ s?.status,
814
+ V
815
+ ]), E(() => {
816
+ R(!1);
817
+ }, [e, s?.status]), E(() => {
818
+ i ? (Ee(f.current), S()) : d.current?.resize();
819
+ }, [i]);
820
+ let H = ["active", "won"].includes(s?.status), [W, G] = O(null);
821
+ if (E(() => {
822
+ if (!H || !W || !l.current) return;
823
+ let e = !1, t = null, n = {
824
+ arena: W,
825
+ lowPower: matchMedia("(pointer: coarse)").matches,
826
+ reducedMotion: matchMedia("(prefers-reduced-motion: reduce)").matches,
827
+ onEvent: (e) => {
828
+ e.type === "context_lost" && ce(!0);
829
+ }
830
+ }, r = () => {
831
+ e || (t = Ce(l.current, n), d.current = t, I("2d"));
832
+ };
833
+ return se ? r() : import("./createLiveScene-jrzyQogh.js").then(({ createLiveScene: i }) => {
834
+ if (!e) try {
835
+ t = i(l.current, n), d.current = t, I("3d");
836
+ } catch {
837
+ r();
838
+ }
839
+ }).catch(r), () => {
840
+ e = !0, t?.dispose(), d.current === t && (d.current = null);
841
+ };
842
+ }, [
843
+ H,
844
+ W,
845
+ se
846
+ ]), E(() => {
847
+ if (!H || s.status !== "active" || !l.current) return;
848
+ let n = !1, r = 0, i = performance.now(), p = 0, m = null, h = de(), g = /* @__PURE__ */ new Set();
849
+ x();
850
+ let _;
851
+ try {
852
+ let n = o.getState().createLiveSignaling(e);
853
+ _ = F({
854
+ iceServers: a?.iceServers,
855
+ iceTransportPolicy: a?.iceTransportPolicy,
856
+ game: s,
857
+ selfId: String(t),
858
+ isHost: String(s.hostId) === String(t),
859
+ signaling: n
860
+ }), u.current = _;
861
+ } catch (e) {
862
+ w(e.message || "No se pudo iniciar WebRTC");
863
+ return;
864
+ }
865
+ G(Oe(_.getRender()));
866
+ let v = null, y = !1;
867
+ function C() {
868
+ g.clear(), Ee(f.current), S();
869
+ }
870
+ function T(e, t) {
871
+ /^(INPUT|TEXTAREA|SELECT)$/.test(e.target?.tagName) || [
872
+ "KeyW",
873
+ "KeyA",
874
+ "KeyS",
875
+ "KeyD",
876
+ "ArrowUp",
877
+ "ArrowDown",
878
+ "ArrowLeft",
879
+ "ArrowRight",
880
+ "Space"
881
+ ].includes(e.code) && (e.preventDefault(), t ? g.add(e.code) : g.delete(e.code), f.current.throttle = Number(g.has("KeyW") || g.has("ArrowUp")) - Number(g.has("KeyS") || g.has("ArrowDown")), f.current.steer = Number(g.has("KeyD") || g.has("ArrowRight")) - Number(g.has("KeyA") || g.has("ArrowLeft")), f.current.fire = g.has("Space"));
882
+ }
883
+ let E = (e) => T(e, !0), D = (e) => T(e, !1), O = l.current;
884
+ O.addEventListener("keydown", E), O.addEventListener("keyup", D), O.addEventListener("blur", C);
885
+ let k = () => {
886
+ document.hidden && C();
887
+ };
888
+ document.addEventListener("visibilitychange", k), re({ type: "engine_start" }, e);
889
+ function A(t) {
890
+ if (n) return;
891
+ let a = Math.min(80, t - i);
892
+ i = t;
893
+ let s = c.current || document.hidden;
894
+ _.setInput(s ? {
895
+ throttle: 0,
896
+ steer: 0,
897
+ fire: !1
898
+ } : f.current), _.step(a);
899
+ let l = _.getRender();
900
+ if (s || d.current?.render(l, a), s && (g.clear(), h.reset(), S(), y = !1), !s) for (let e of l.events || []) for (let t of K(e)) re(t, e.id);
901
+ if (!s) for (let e of l.events || []) for (let t of ye(e, l)) b(t);
902
+ let u = U(l.tanks);
903
+ for (let e of l.events || []) {
904
+ let n = e?.target ?? e?.tank;
905
+ u && n != null && String(n) === String(u.id) && (ue(e) === "life_lost" && (v = t + (Number.isFinite(e.respawnMs) ? e.respawnMs : De)), ue(e) === "respawn" && (v = null));
906
+ }
907
+ u?.alive !== !1 && v != null && t >= v && (v = null);
908
+ let x = !s && l.status === "playing" && u?.alive !== !1 && _e(l, u) > 0;
909
+ x !== y && (y = x, x ? te("shield_loop") : ne("shield_loop"));
910
+ let C = u ? l.tanks.indexOf(u) : -1, w = Number.isFinite(l.respawn?.[C]) ? l.respawn[C] : v != null && l.status === "playing" ? Math.max(0, v - t) : 0;
911
+ if (!s) for (let e of h.update(U(l.tanks), a)) re(e);
912
+ let T = fe(l);
913
+ T && !m && (v = null, ee({
914
+ ...l,
915
+ respawnIn: 0
916
+ }), m = T, s || ie(m, e), o.getState().liveFinish?.(e, l.winner)), t - p > 100 && (p = t, ee({
917
+ ...l,
918
+ respawnIn: w
919
+ })), r = requestAnimationFrame(A);
920
+ }
921
+ return r = requestAnimationFrame(A), () => {
922
+ n = !0, cancelAnimationFrame(r), C(), _.destroy(), u.current = null, O.removeEventListener("keydown", E), O.removeEventListener("keyup", D), O.removeEventListener("blur", C), document.removeEventListener("visibilitychange", k);
923
+ };
924
+ }, [
925
+ H,
926
+ e,
927
+ t
928
+ ]), !s) return null;
929
+ let q = String(t) === String(s.guestId), Y = p?.status === "over" || s.status === "won", X = p?.net, Z = X?.manualTurn, he = [
930
+ "waiting_peer",
931
+ "sharing",
932
+ "applying"
933
+ ].includes(Z?.status), Q = !V && (z >= 12e3 || X?.phase === "failed" || X?.ice === "failed" || Z?.status === "failed" || !!y), be = me(W) ? W : null, xe = ve(p), Se = (p?.tanks || []).some((e) => Number.isFinite(ge(p, e))) && (be != null || xe > 1), we = Math.ceil((p?.respawnIn || 0) / 1e3), Ae = V ? X?.route?.relay === !0 ? "TURN Relay" : X?.route?.relay === !1 ? "P2P" : null : null, je = async (e, t) => {
934
+ if (!u.current?.configureTurn) throw Error("La partida aún no está preparada. Espera un momento y vuelve a intentarlo.");
935
+ await u.current.configureTurn(e, t);
936
+ };
937
+ function Me(e) {
938
+ let t = l.current?.getBoundingClientRect(), n = U(p?.tanks);
939
+ if (!t || !n) return;
940
+ let r = d.current?.screenToGround((e.clientX - t.left) / t.width * 2 - 1, 1 - (e.clientY - t.top) / t.height * 2);
941
+ r && (f.current.turretYaw = Math.atan2(r.z - n.z, r.x - n.x));
942
+ }
943
+ let Ne = (e, t) => ({
944
+ onPointerDown: (n) => {
945
+ n.preventDefault(), n.currentTarget.setPointerCapture(n.pointerId), f.current[e] = t;
946
+ },
947
+ onPointerUp: () => {
948
+ f.current[e] = e !== "fire" && 0;
949
+ },
950
+ onPointerCancel: () => {
951
+ f.current[e] = e !== "fire" && 0;
952
+ },
953
+ onLostPointerCapture: () => {
954
+ f.current[e] = e !== "fire" && 0;
955
+ }
956
+ });
957
+ return /* @__PURE__ */ j("section", {
958
+ className: `chat-game-card tl-card${H ? " tl-card--active" : ""}`,
959
+ "aria-label": "Tanques LIVE 3D",
960
+ children: [
961
+ /* @__PURE__ */ j("header", {
962
+ className: "tl-header",
963
+ children: [/* @__PURE__ */ A("strong", { children: "Tanques LIVE 3D" }), /* @__PURE__ */ j("div", {
964
+ className: "tl-header-actions",
965
+ children: [
966
+ /* @__PURE__ */ A(h, { manager: C() }),
967
+ n && /* @__PURE__ */ A("button", {
968
+ onClick: n,
969
+ "aria-label": "Minimizar",
970
+ children: "−"
971
+ }),
972
+ r && /* @__PURE__ */ A("button", {
973
+ onClick: r,
974
+ "aria-label": "Ocultar",
975
+ children: "×"
976
+ })
977
+ ]
978
+ })]
979
+ }),
980
+ s.status === "invited" && /* @__PURE__ */ j("div", {
981
+ className: "tl-invite",
982
+ children: [
983
+ /* @__PURE__ */ A("span", {
984
+ className: "tl-invite-icon",
985
+ "aria-hidden": "true",
986
+ children: "🪖"
987
+ }),
988
+ /* @__PURE__ */ A("strong", { children: q ? "¿Listo para combatir?" : "Invitación enviada" }),
989
+ /* @__PURE__ */ A("p", { children: q ? "Te invitaron a un combate en tiempo real." : "Esperando que el rival acepte…" }),
990
+ q && /* @__PURE__ */ j("div", {
991
+ className: "tl-invite-actions",
992
+ children: [/* @__PURE__ */ A("button", {
993
+ className: "tl-button-primary",
994
+ onClick: () => Te(e, "game_accept"),
995
+ children: "Aceptar combate"
996
+ }), /* @__PURE__ */ A("button", {
997
+ onClick: () => Te(e, "game_decline"),
998
+ children: "Rechazar"
999
+ })]
1000
+ })
1001
+ ]
1002
+ }),
1003
+ H && !Y && /* @__PURE__ */ j("div", {
1004
+ className: `tl-connection tl-connection--${V ? "connected" : Q ? "problem" : "pending"}`,
1005
+ children: [
1006
+ /* @__PURE__ */ j("div", {
1007
+ className: "tl-connection-heading",
1008
+ children: [
1009
+ V ? /* @__PURE__ */ A(ae, {
1010
+ size: 18,
1011
+ "aria-hidden": "true"
1012
+ }) : Q ? /* @__PURE__ */ A(M, {
1013
+ size: 18,
1014
+ "aria-hidden": "true"
1015
+ }) : /* @__PURE__ */ A(oe, {
1016
+ size: 18,
1017
+ className: "tl-connection-spinner",
1018
+ "aria-hidden": "true"
1019
+ }),
1020
+ /* @__PURE__ */ j("div", { children: [/* @__PURE__ */ A("strong", { children: Q ? "Problemas de conexión" : ke(X, !1) }), Q && /* @__PURE__ */ A("p", { children: "No pudimos establecer una conexión con el otro jugador. Puedes configurar una conexión alternativa para continuar." })] }),
1021
+ Ae && /* @__PURE__ */ A("span", {
1022
+ className: "tl-route-badge",
1023
+ children: Ae
1024
+ })
1025
+ ]
1026
+ }),
1027
+ !V && /* @__PURE__ */ A("p", {
1028
+ className: "tl-connection-message",
1029
+ role: "status",
1030
+ children: Q ? ke(X, z >= 12e3) : g(X)
1031
+ }),
1032
+ Z?.status === "synchronized" && /* @__PURE__ */ A("p", {
1033
+ className: "tl-connection-shared",
1034
+ role: "status",
1035
+ children: Z.received ? "Configuración recibida del otro jugador y aplicada en ambos." : "Configuración compartida y aplicada en ambos jugadores."
1036
+ }),
1037
+ Z?.expiresAt != null && Z.expiresAt <= Date.now() && /* @__PURE__ */ A("p", {
1038
+ className: "tl-connection-expired",
1039
+ role: "status",
1040
+ children: "La validez indicada para las credenciales terminó. Introduce una configuración nueva si necesitas reconectar."
1041
+ }),
1042
+ /* @__PURE__ */ j("div", {
1043
+ className: "tl-connection-actions",
1044
+ children: [/* @__PURE__ */ j("button", {
1045
+ type: "button",
1046
+ className: Q ? "tl-button-primary" : "",
1047
+ onClick: () => R(!0),
1048
+ children: [/* @__PURE__ */ A(P, {
1049
+ size: 15,
1050
+ "aria-hidden": "true"
1051
+ }), "Configurar conexión alternativa"]
1052
+ }), !V && /* @__PURE__ */ j("button", {
1053
+ type: "button",
1054
+ disabled: he,
1055
+ onClick: () => u.current?.reconnect(),
1056
+ children: [/* @__PURE__ */ A(N, {
1057
+ size: 15,
1058
+ "aria-hidden": "true"
1059
+ }), "Reintentar conexión"]
1060
+ })]
1061
+ })
1062
+ ]
1063
+ }),
1064
+ /* @__PURE__ */ A(_, {
1065
+ open: L && H && !Y,
1066
+ onClose: () => R(!1),
1067
+ onApply: je,
1068
+ manualTurn: Z
1069
+ }),
1070
+ (H || p) && /* @__PURE__ */ j(k, { children: [
1071
+ /* @__PURE__ */ j("div", {
1072
+ className: "tl-hud",
1073
+ children: [
1074
+ (p?.tanks || []).map((e) => /* @__PURE__ */ j("span", { children: [
1075
+ e.self ? "Tú" : "Rival",
1076
+ " ",
1077
+ /* @__PURE__ */ A("meter", {
1078
+ min: "0",
1079
+ max: "100",
1080
+ value: e.hp,
1081
+ "aria-label": e.self ? "Tu vida" : "Vida del rival"
1082
+ }),
1083
+ " ",
1084
+ e.hp,
1085
+ " HP",
1086
+ Se && /* @__PURE__ */ A($, {
1087
+ lives: ge(p, e),
1088
+ max: xe,
1089
+ label: e.self ? "Tus vidas" : "Vidas del rival"
1090
+ }),
1091
+ _e(p, e) > 0 && e.alive !== !1 && /* @__PURE__ */ A("span", {
1092
+ className: "tl-shield-badge",
1093
+ title: "Escudo activo",
1094
+ children: "🛡️"
1095
+ })
1096
+ ] }, e.id)),
1097
+ be && /* @__PURE__ */ j("span", {
1098
+ className: "tl-map",
1099
+ children: [
1100
+ pe[be.id],
1101
+ " ",
1102
+ J(be)
1103
+ ]
1104
+ }),
1105
+ /* @__PURE__ */ j("span", {
1106
+ role: "status",
1107
+ children: [
1108
+ V ? Ae || "Conectado" : ke(X, z >= 12e3),
1109
+ " ",
1110
+ Number.isFinite(X?.rtt) ? `· ${Math.round(X.rtt)} ms` : ""
1111
+ ]
1112
+ })
1113
+ ]
1114
+ }),
1115
+ we > 0 && !Y && /* @__PURE__ */ j("div", {
1116
+ className: "tl-respawn",
1117
+ role: "status",
1118
+ children: [
1119
+ "Reapareces en ",
1120
+ we,
1121
+ " s…"
1122
+ ]
1123
+ }),
1124
+ /* @__PURE__ */ A("div", {
1125
+ className: "tl-stage",
1126
+ ref: l,
1127
+ tabIndex: 0,
1128
+ "aria-label": "Arena. WASD o flechas para conducir, ratón para apuntar, clic o espacio para disparar",
1129
+ onPointerMove: Me,
1130
+ onPointerDown: (e) => {
1131
+ Me(e), e.pointerType === "mouse" && (e.currentTarget.focus(), e.currentTarget.setPointerCapture(e.pointerId), Me(e), f.current.fire = !0);
1132
+ },
1133
+ onPointerUp: () => {
1134
+ f.current.fire = !1;
1135
+ },
1136
+ onPointerCancel: () => {
1137
+ Ee(f.current);
1138
+ },
1139
+ onLostPointerCapture: () => {
1140
+ f.current.fire = !1;
1141
+ }
1142
+ }),
1143
+ /* @__PURE__ */ j("div", {
1144
+ className: "tl-controls",
1145
+ children: [
1146
+ /* @__PURE__ */ A("div", {
1147
+ className: "tl-joystick",
1148
+ role: "group",
1149
+ "aria-label": "Joystick de conducción",
1150
+ onPointerDown: (e) => {
1151
+ e.preventDefault(), e.currentTarget.setPointerCapture(e.pointerId);
1152
+ let t = e.currentTarget.getBoundingClientRect();
1153
+ f.current.steer = Math.max(-1, Math.min(1, (e.clientX - t.left - t.width / 2) / (t.width / 2))), f.current.throttle = Math.max(-1, Math.min(1, -(e.clientY - t.top - t.height / 2) / (t.height / 2)));
1154
+ },
1155
+ onPointerMove: (e) => {
1156
+ if (!e.currentTarget.hasPointerCapture(e.pointerId)) return;
1157
+ let t = e.currentTarget.getBoundingClientRect();
1158
+ f.current.steer = Math.max(-1, Math.min(1, (e.clientX - t.left - t.width / 2) / (t.width / 2))), f.current.throttle = Math.max(-1, Math.min(1, -(e.clientY - t.top - t.height / 2) / (t.height / 2)));
1159
+ },
1160
+ onPointerUp: () => Ee(f.current),
1161
+ onPointerCancel: () => Ee(f.current),
1162
+ onLostPointerCapture: () => Ee(f.current),
1163
+ children: "✥"
1164
+ }),
1165
+ /* @__PURE__ */ j("div", {
1166
+ className: "tl-drive",
1167
+ "aria-label": "Controles de conducción",
1168
+ children: [
1169
+ /* @__PURE__ */ A("button", {
1170
+ "aria-label": "Avanzar",
1171
+ ...Ne("throttle", 1),
1172
+ children: "▲"
1173
+ }),
1174
+ /* @__PURE__ */ A("button", {
1175
+ "aria-label": "Girar izquierda",
1176
+ ...Ne("steer", -1),
1177
+ children: "◀"
1178
+ }),
1179
+ /* @__PURE__ */ A("button", {
1180
+ "aria-label": "Retroceder",
1181
+ ...Ne("throttle", -1),
1182
+ children: "▼"
1183
+ }),
1184
+ /* @__PURE__ */ A("button", {
1185
+ "aria-label": "Girar derecha",
1186
+ ...Ne("steer", 1),
1187
+ children: "▶"
1188
+ })
1189
+ ]
1190
+ }),
1191
+ /* @__PURE__ */ A("button", {
1192
+ className: "tl-fire",
1193
+ ...Ne("fire", !0),
1194
+ children: "Disparar"
1195
+ })
1196
+ ]
1197
+ }),
1198
+ /* @__PURE__ */ A("div", {
1199
+ className: "tl-reload",
1200
+ children: /* @__PURE__ */ j("label", { children: [
1201
+ "Recarga ",
1202
+ /* @__PURE__ */ A("progress", {
1203
+ max: "1",
1204
+ value: U(p?.tanks)?.reload ?? 1
1205
+ }),
1206
+ " ",
1207
+ (U(p?.tanks)?.reload ?? 1) >= 1 ? "Listo" : "Recargando…"
1208
+ ] })
1209
+ }),
1210
+ /* @__PURE__ */ A("small", { children: "WASD / flechas · ratón o toca la arena para apuntar · espacio / clic para disparar" }),
1211
+ /* @__PURE__ */ A("button", {
1212
+ onClick: () => ce((e) => !e),
1213
+ children: le === "2d" ? "Probar 3D" : "Vista 2D"
1214
+ })
1215
+ ] }),
1216
+ Y && /* @__PURE__ */ j("p", {
1217
+ role: "status",
1218
+ children: [
1219
+ String(p?.winner ?? s.winnerId) === String(t) ? "¡Victoria!" : "Fin del combate",
1220
+ " ",
1221
+ /* @__PURE__ */ A("button", {
1222
+ onClick: () => {
1223
+ Promise.resolve(o.getState().liveRematch?.(e)).catch(() => {});
1224
+ },
1225
+ children: "Revancha"
1226
+ }),
1227
+ be && /* @__PURE__ */ A("button", {
1228
+ onClick: () => {
1229
+ Promise.resolve(o.getState().liveRematch?.(e, { newMap: !0 })).catch(() => {});
1230
+ },
1231
+ children: "Revancha en otro mapa 🎲"
1232
+ })
1233
+ ]
1234
+ }),
1235
+ H && /* @__PURE__ */ j("details", {
1236
+ className: "tl-diagnostics",
1237
+ children: [/* @__PURE__ */ A("summary", { children: "Diagnóstico de conexión" }), /* @__PURE__ */ A("pre", { children: JSON.stringify(v(p?.net), null, 2) })]
1238
+ }),
1239
+ H && !Y && /* @__PURE__ */ A("button", {
1240
+ onClick: () => u.current?.resign(),
1241
+ children: "Rendirse"
1242
+ }),
1243
+ s.pending && /* @__PURE__ */ A("p", {
1244
+ role: "status",
1245
+ children: "Enviando…"
1246
+ }),
1247
+ s.pendingEvent && s.error && /* @__PURE__ */ A("button", {
1248
+ onClick: () => {
1249
+ o.getState().retry(e).catch(() => {});
1250
+ },
1251
+ children: "Reintentar envío"
1252
+ }),
1253
+ y && /* @__PURE__ */ A("p", {
1254
+ role: "alert",
1255
+ children: y
1256
+ }),
1257
+ s.error && /* @__PURE__ */ A("p", {
1258
+ role: "alert",
1259
+ children: s.error
1260
+ }),
1261
+ !["closed", "declined"].includes(s.status) && /* @__PURE__ */ A("footer", {
1262
+ className: "tl-footer",
1263
+ children: /* @__PURE__ */ A("button", {
1264
+ onClick: () => Te(e, "game_end"),
1265
+ children: "Cerrar partida"
1266
+ })
1267
+ })
1268
+ ]
1269
+ });
1270
+ }
1271
+ var je = w(Ae);
1272
+ export { W as a, X as c, V as d, je as default, H as f, B as i, Y as l, I as n, ue as o, G as p, R as r, me as s, we as t, _e as u };
1273
+
1274
+ //# sourceMappingURL=TanksLiveGameCard-DXgd1J2Y.js.map