@minicode-dev/chat 0.1.14 → 0.1.15
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.
- package/dist/chunks/{BattleshipGameCard-B-B4r7lK.js → BattleshipGameCard-8H-sBCsv.js} +3 -3
- package/dist/chunks/{BattleshipGameCard-B-B4r7lK.js.map → BattleshipGameCard-8H-sBCsv.js.map} +1 -1
- package/dist/chunks/{ChatContext-DQtKsR6Z.js → ChatContext-CVW58bzC.js} +2 -2
- package/dist/chunks/{ChatContext-DQtKsR6Z.js.map → ChatContext-CVW58bzC.js.map} +1 -1
- package/dist/chunks/{RacingLiveGameCard-c1G7uoDI.js → RacingLiveGameCard-8j9QLnxW.js} +4 -4
- package/dist/chunks/{RacingLiveGameCard-c1G7uoDI.js.map → RacingLiveGameCard-8j9QLnxW.js.map} +1 -1
- package/dist/chunks/{TanksGameCard-CvTaF7tu.js → TanksGameCard-DnCufSH6.js} +12 -12
- package/dist/chunks/{TanksGameCard-CvTaF7tu.js.map → TanksGameCard-DnCufSH6.js.map} +1 -1
- package/dist/chunks/TanksLiveGameCard-D_27Jomp.js +1274 -0
- package/dist/chunks/TanksLiveGameCard-D_27Jomp.js.map +1 -0
- package/dist/chunks/{avalancheScene3d-Z5QyZIid.js → avalancheScene3d-CIE2WKQn.js} +51 -50
- package/dist/chunks/{avalancheScene3d-Z5QyZIid.js.map → avalancheScene3d-CIE2WKQn.js.map} +1 -1
- package/dist/chunks/cars-D1PM7mVD.js +340 -0
- package/dist/chunks/cars-D1PM7mVD.js.map +1 -0
- package/dist/chunks/{connect4Sounds-DmD-E9kX.js → connect4Sounds-BqEHULjv.js} +2 -2
- package/dist/chunks/{connect4Sounds-DmD-E9kX.js.map → connect4Sounds-BqEHULjv.js.map} +1 -1
- package/dist/chunks/createLiveScene-MTGRv8rx.js +758 -0
- package/dist/chunks/createLiveScene-MTGRv8rx.js.map +1 -0
- package/dist/chunks/{createRaceScene-C7Rw89kj.js → createRaceScene-BiEtQsVs.js} +4 -3
- package/dist/chunks/{createRaceScene-C7Rw89kj.js.map → createRaceScene-BiEtQsVs.js.map} +1 -1
- package/dist/chunks/fx-DhXerGyt.js +248 -0
- package/dist/chunks/fx-DhXerGyt.js.map +1 -0
- package/dist/chunks/{games-BvYTWgaR.js → games-Bl_8raG6.js} +1147 -574
- package/dist/chunks/games-Bl_8raG6.js.map +1 -0
- package/dist/chunks/{tanksSounds-DwjfSp3W.js → tanksSounds-DTnidbiq.js} +5 -5
- package/dist/chunks/{tanksSounds-DwjfSp3W.js.map → tanksSounds-DTnidbiq.js.map} +1 -1
- package/dist/index.js +28 -28
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/chunks/TanksLiveGameCard-COr9Oay5.js +0 -1011
- package/dist/chunks/TanksLiveGameCard-COr9Oay5.js.map +0 -1
- package/dist/chunks/createLiveScene-CWBunxPi.js +0 -367
- package/dist/chunks/createLiveScene-CWBunxPi.js.map +0 -1
- package/dist/chunks/fx-UZwhOmdl.js +0 -584
- package/dist/chunks/fx-UZwhOmdl.js.map +0 -1
- package/dist/chunks/games-BvYTWgaR.js.map +0 -1
|
@@ -0,0 +1,1274 @@
|
|
|
1
|
+
import { t as e } from "./rolldown-runtime-CGnMp29N.js";
|
|
2
|
+
import { C as t, D as n, E as r, O as i, S as a, T as o, a as s, b as c, v as l, w as u, x as d, y as f } from "./games-Bl_8raG6.js";
|
|
3
|
+
import { n as p, o as ee, s as m } from "./createPeerLink-DBVs_yvQ.js";
|
|
4
|
+
import { t as h } from "./ChatContext-CVW58bzC.js";
|
|
5
|
+
import { o as g } from "./connect4Sounds-BqEHULjv.js";
|
|
6
|
+
import { n as _, r as v, t as te } from "./tanks-live-BcKmrhnV.js";
|
|
7
|
+
import { a as ne, c as re, i as y, n as ie, o as b, r as ae, s as x, t as S } from "./tanksSounds-DTnidbiq.js";
|
|
8
|
+
import { memo as C, useContext as w, useEffect as T, useRef as E, useState as D } from "react";
|
|
9
|
+
import { AlertTriangle as O, CheckCircle2 as k, Link2 as oe, Loader2 as A, Settings2 as se } from "lucide-react";
|
|
10
|
+
import { Fragment as j, jsx as M, jsxs as N } from "react/jsx-runtime";
|
|
11
|
+
// src/games/tanks-live/net/createLiveMatch.js
|
|
12
|
+
var ce = Object.freeze({
|
|
13
|
+
respawnMs: 3e3,
|
|
14
|
+
shieldMs: 2e3
|
|
15
|
+
}), le = (e) => typeof e == "number" && Number.isFinite(e), ue = (e) => typeof e == "string" && e.length > 0 && e.length < 160;
|
|
16
|
+
function P({ game: e, selfId: s, isHost: h = String(s) === String(e.hostId), signaling: g, onChange: _ = () => {}, peerFactory: v = p, iceServers: te, iceTransportPolicy: ne, RTCPeerConnectionImpl: re } = {}) {
|
|
17
|
+
s = String(s);
|
|
18
|
+
let y = [String(e.hostId), String(e.guestId)];
|
|
19
|
+
if (!y.includes(s) || y[0] === y[1]) throw Error("Invalid live match players");
|
|
20
|
+
let ie = (te || []).some((e) => [e.urls].flat().some((e) => /^turns?:/i.test(String(e)))), b = y.find((e) => e !== s), ae = e.liveConfig ?? null, x = !ae, S = x ? d() : l(ae.mapId, ae.seed);
|
|
21
|
+
if (!x && S.hash !== ae.mapHash) throw Error("El mapa no coincide con la invitación");
|
|
22
|
+
let C = x ? 1 : ae.lives;
|
|
23
|
+
if (![
|
|
24
|
+
1,
|
|
25
|
+
3,
|
|
26
|
+
5
|
|
27
|
+
].includes(C)) throw Error("Vidas inválidas");
|
|
28
|
+
let w = (S.destructibles || []).map((e) => ({
|
|
29
|
+
id: e.id,
|
|
30
|
+
hp: e.hp
|
|
31
|
+
})), T = (e, t) => {
|
|
32
|
+
let n = a(e, t), r = S.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
|
+
}, E = (e) => (S.destructibles || []).find((t) => t.id === e), D = y.map(T), O = [], k = [], oe = {}, A = 0, se = 0, j = 0, M = 0, N = [C, C], P = [0, 0], F = [null, null], I = "connecting", L = null, R = !1, z = {
|
|
40
|
+
phase: "idle",
|
|
41
|
+
rtt: null,
|
|
42
|
+
route: null
|
|
43
|
+
}, B = !1, V = !1, H = null, U = [], W = null, G = null, de = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Set(), fe = /* @__PURE__ */ new Set(), q = () => D.find((e) => e.id === s), pe = () => D.find((e) => e.id === b), me = () => {
|
|
44
|
+
R || _({
|
|
45
|
+
status: I,
|
|
46
|
+
winner: L,
|
|
47
|
+
net: z
|
|
48
|
+
});
|
|
49
|
+
}, J = (e) => {
|
|
50
|
+
k.push(e), k.length > 200 && k.shift();
|
|
51
|
+
}, Y = (t) => $.sendEvent({
|
|
52
|
+
...t,
|
|
53
|
+
g: e.gameId,
|
|
54
|
+
r: j
|
|
55
|
+
}), X = (e) => {
|
|
56
|
+
K.add(e), K.size > 2048 && K.delete(K.values().next().value);
|
|
57
|
+
}, Z = (e) => Math.max(0, Math.round(P[e] - A)), he = () => ({
|
|
58
|
+
k: "snapshot",
|
|
59
|
+
hp: D.map((e) => e.hp),
|
|
60
|
+
status: I,
|
|
61
|
+
winner: L,
|
|
62
|
+
reason: H,
|
|
63
|
+
...x ? {} : {
|
|
64
|
+
lives: [...N],
|
|
65
|
+
shield: [0, 1].map(Z),
|
|
66
|
+
destructibles: (S.destructibles || []).map((e) => ({
|
|
67
|
+
id: e.id,
|
|
68
|
+
hp: e.hp
|
|
69
|
+
}))
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
function ge() {
|
|
73
|
+
(S.destructibles || []).forEach((e, t) => {
|
|
74
|
+
e.hp = w[t].hp, e.alive = !0;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function _e(e) {
|
|
78
|
+
let t = T(y[e], e);
|
|
79
|
+
Object.assign(D[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
|
+
}), F[e] = null, P[e] = A + ce.shieldMs, y[e] === b && (U = [], G = null, W = null), J({
|
|
88
|
+
k: "respawn",
|
|
89
|
+
target: y[e],
|
|
90
|
+
x: t.x,
|
|
91
|
+
z: t.z,
|
|
92
|
+
shield: ce.shieldMs
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function ve(e, t) {
|
|
96
|
+
N[e] = t, J({
|
|
97
|
+
k: "life_lost",
|
|
98
|
+
target: y[e],
|
|
99
|
+
lives: [...N]
|
|
100
|
+
}), t === 1 && C > 1 && J({
|
|
101
|
+
k: "last_life",
|
|
102
|
+
target: y[e]
|
|
103
|
+
}), F[e] = t > 0 ? A + ce.respawnMs : null;
|
|
104
|
+
}
|
|
105
|
+
function Q(e, t) {
|
|
106
|
+
x ? N[e] = 0 : (ve(e, Math.max(0, N[e] - 1)), Y({
|
|
107
|
+
k: "life_lost",
|
|
108
|
+
target: y[e],
|
|
109
|
+
lives: [...N]
|
|
110
|
+
}));
|
|
111
|
+
let n = {
|
|
112
|
+
k: "destroyed",
|
|
113
|
+
target: y[e]
|
|
114
|
+
};
|
|
115
|
+
if (Y(n), J(n), N[e] === 0 && I === "playing") {
|
|
116
|
+
let n = t === y[e] ? y[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 = y.indexOf(t);
|
|
127
|
+
e < 0 || !D[e].alive || P[e] > A || (D[e].hp = Math.max(0, D[e].hp - r), D[e].alive = D[e].hp > 0, D[e].alive || n.push(e));
|
|
128
|
+
}
|
|
129
|
+
return () => n.forEach((e) => Q(e, t));
|
|
130
|
+
}
|
|
131
|
+
function be() {
|
|
132
|
+
D = y.map(T), O = [], N = [C, C], P = [0, 0], F = [null, null], ge(), U = [], W = null, G = null, de.clear(), K.clear(), fe.clear(), V = !1, H = null, L = null, I = z.phase === "connected" ? "playing" : "connecting", J({ k: "rematch" }), me();
|
|
133
|
+
}
|
|
134
|
+
function xe(e, t = !1) {
|
|
135
|
+
(I !== "over" || t && L !== e) && (I = "over", L = e, O = [], $.clearManualTurn?.(), J({
|
|
136
|
+
k: "over",
|
|
137
|
+
winner: L
|
|
138
|
+
}), me());
|
|
139
|
+
}
|
|
140
|
+
function Se(e, t, n) {
|
|
141
|
+
if (I !== "playing" || !ue(t.id) || K.has(t.id)) return !1;
|
|
142
|
+
let r = D.find((t) => t.id === e);
|
|
143
|
+
if (!r?.alive || A - (de.get(e) ?? -Infinity) < f.reloadMs - 20 || ![
|
|
144
|
+
t.x,
|
|
145
|
+
t.z,
|
|
146
|
+
t.yaw
|
|
147
|
+
].every(le) || Math.hypot(t.x - (e === b && G ? G.x : r.x), t.z - (e === b && G ? G.z : r.z)) > 6) return !1;
|
|
148
|
+
X(t.id), de.set(e, A);
|
|
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 O.push(i), J(i), n && Y({
|
|
159
|
+
...t,
|
|
160
|
+
k: "fire"
|
|
161
|
+
}), !0;
|
|
162
|
+
}
|
|
163
|
+
function Ce(t) {
|
|
164
|
+
if (R || I !== "playing" || t?.g !== e.gameId || t.r !== j || !Array.isArray(t.p) || t.p.length !== 5 || !t.p.every(le)) return;
|
|
165
|
+
let [n, r, a, o, s] = t.p;
|
|
166
|
+
if (!pe().alive || !i(n, r, {
|
|
167
|
+
...S,
|
|
168
|
+
destructibles: []
|
|
169
|
+
}) || Math.abs(s) > f.speed + .1 || Math.abs(a) > 1e6 || Math.abs(o) > 1e6) return;
|
|
170
|
+
let c = W === null ? .1 : Math.max(0, (A - W) / 1e3), l = G || pe();
|
|
171
|
+
if (Math.hypot(n - l.x, r - l.z) > f.speed * c + 3) return;
|
|
172
|
+
let u = {
|
|
173
|
+
...pe(),
|
|
174
|
+
x: n,
|
|
175
|
+
z: r,
|
|
176
|
+
yaw: a,
|
|
177
|
+
turretYaw: o,
|
|
178
|
+
speed: s
|
|
179
|
+
};
|
|
180
|
+
G = u, W = A, U.push({
|
|
181
|
+
time: A,
|
|
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 <= C), Ee = (e) => Te(e.lives) && Array.isArray(e.shield) && e.shield.length === 2 && e.shield.every((e) => Number.isInteger(e) && e >= 0 && e <= ce.shieldMs) && Array.isArray(e.destructibles) && e.destructibles.length === w.length && e.destructibles.every((e, t) => e && we(e, ["id", "hp"]) && e.id === w[t].id && Number.isInteger(e.hp) && e.hp >= 0 && e.hp <= w[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(t) {
|
|
203
|
+
if (R || !t || t.g !== e.gameId || !Number.isInteger(t.r)) return;
|
|
204
|
+
if (t.k === "round" && !h && I === "over" && fe.has(s) && t.r === j + 1) {
|
|
205
|
+
j = t.r, be();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (t.r !== j) return;
|
|
209
|
+
if (t.k === "sync" && h) {
|
|
210
|
+
Y(he());
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (t.k === "snapshot" && !h && Array.isArray(t.hp) && t.hp.length === 2 && t.hp.every((e) => Number.isInteger(e) && e >= 0 && e <= 100)) {
|
|
214
|
+
if (!x && !Ee(t)) return;
|
|
215
|
+
let e = x ? N : t.lives, n = t.status === "playing" && t.winner === null && t.hp.every((t, n) => t > 0 || !x && e[n] > 0), r = t.status === "over" && y.includes(t.winner) && (t.hp[1 - y.indexOf(t.winner)] === 0 && e[1 - y.indexOf(t.winner)] === (x ? N[1 - y.indexOf(t.winner)] : 0) || t.reason === "resigned");
|
|
216
|
+
if (!n && !r) return;
|
|
217
|
+
x || (t.destructibles.forEach((e, t) => {
|
|
218
|
+
let n = S.destructibles[t];
|
|
219
|
+
n.hp = e.hp, n.alive = e.hp > 0;
|
|
220
|
+
}), D.forEach((e, n) => {
|
|
221
|
+
let r = e.hp === 0;
|
|
222
|
+
N[n] = t.lives[n], r && t.hp[n] > 0 && _e(n), P[n] = t.shield[n] ? A + t.shield[n] : 0, t.hp[n] === 0 && N[n] > 0 && F[n] === null && (F[n] = A + ce.respawnMs);
|
|
223
|
+
})), D.forEach((e, n) => {
|
|
224
|
+
e.hp = t.hp[n], e.alive = e.hp > 0;
|
|
225
|
+
}), r && (V = !1, H = t.reason, xe(t.winner, !0));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (t.k === "resign") {
|
|
229
|
+
H = "resigned", xe(s, h), h && Y(he());
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (t.k === "rematch" && I === "over") {
|
|
233
|
+
fe.add(b), ke();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (I !== "playing" || (t.k === "fire" && Se(b, t, !1), !h && t.k === "hit" && ue(t.id) && !K.has(`hit:${t.id}`) && y.includes(t.target) && Array.isArray(t.hp) && t.hp.length === 2 && t.hp.every((e, t) => Number.isInteger(e) && e >= 0 && e <= D[t].hp) && [t.x, t.z].every(le) && (X(`hit:${t.id}`), D.forEach((e, n) => {
|
|
237
|
+
e.hp = t.hp[n], e.alive = e.hp > 0;
|
|
238
|
+
}), O = O.filter((e) => e.id !== t.id), J(t)), !h && t.k === "destroyed" && y.includes(t.target) && !K.has(`destroyed:${t.target}:${N[y.indexOf(t.target)]}`) && D.find((e) => e.id === t.target).hp === 0 && (X(`destroyed:${t.target}:${N[y.indexOf(t.target)]}`), J(t)), !h && t.k === "over" && y.includes(t.winner) && D.find((e) => e.id !== t.winner).hp === 0 && (x || N[1 - y.indexOf(t.winner)] === 0) && xe(t.winner), h || x)) return;
|
|
239
|
+
let n = y.indexOf(t.target);
|
|
240
|
+
if (t.k === "life_lost" && n >= 0 && D[n].hp === 0 && Te(t.lives) && t.lives[n] === N[n] - 1 && t.lives[1 - n] === N[1 - n] && ve(n, t.lives[n]), t.k === "respawn" && n >= 0 && D[n].hp === 0 && N[n] > 0 && we(t, [
|
|
241
|
+
"k",
|
|
242
|
+
"target",
|
|
243
|
+
"g",
|
|
244
|
+
"r"
|
|
245
|
+
]) && _e(n), t.k === "destructible_hit" && ue(t.id) && !K.has(`dh:${t.id}`) && we(t, [
|
|
246
|
+
"k",
|
|
247
|
+
"id",
|
|
248
|
+
"target",
|
|
249
|
+
"hp",
|
|
250
|
+
"x",
|
|
251
|
+
"z",
|
|
252
|
+
"g",
|
|
253
|
+
"r"
|
|
254
|
+
]) && [t.x, t.z].every(le)) {
|
|
255
|
+
let e = E(t.target);
|
|
256
|
+
if (!r(e) || !Number.isInteger(t.hp) || t.hp < 0 || t.hp >= e.hp) return;
|
|
257
|
+
X(`dh:${t.id}`), e.hp = t.hp, e.alive = t.hp > 0, O = O.filter((e) => e.id !== t.id), De(e, t.id, t.x, t.z);
|
|
258
|
+
}
|
|
259
|
+
if (t.k === "barrel_explode" && we(t, [
|
|
260
|
+
"k",
|
|
261
|
+
"target",
|
|
262
|
+
"chained",
|
|
263
|
+
"hp",
|
|
264
|
+
"g",
|
|
265
|
+
"r"
|
|
266
|
+
]) && !K.has(`be:${t.target}`)) {
|
|
267
|
+
let e = E(t.target), n = t.chained === null ? null : E(t.chained);
|
|
268
|
+
if (e?.kind !== "barrel" || r(e) || t.chained !== null && (n?.kind !== "barrel" || !r(n) || n === e) || !Array.isArray(t.hp) || t.hp.length !== 2 || !t.hp.every((e, t) => Number.isInteger(e) && e >= 0 && e <= D[t].hp)) return;
|
|
269
|
+
X(`be:${t.target}`), n && (n.hp = 0, n.alive = !1), D.forEach((e, n) => {
|
|
270
|
+
e.hp = t.hp[n], e.alive = e.hp > 0;
|
|
271
|
+
}), J({
|
|
272
|
+
k: "barrel_explode",
|
|
273
|
+
id: e.id,
|
|
274
|
+
x: e.x,
|
|
275
|
+
z: e.z,
|
|
276
|
+
chained: n ? {
|
|
277
|
+
id: n.id,
|
|
278
|
+
x: n.x,
|
|
279
|
+
z: n.z
|
|
280
|
+
} : null,
|
|
281
|
+
hp: [...t.hp]
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
let $ = v({
|
|
286
|
+
configurationAuthority: h,
|
|
287
|
+
signaling: g && {
|
|
288
|
+
send(t) {
|
|
289
|
+
let n = ee(t);
|
|
290
|
+
if (!n) return Promise.reject(/* @__PURE__ */ Error("Invalid live signal"));
|
|
291
|
+
let r = m({
|
|
292
|
+
...n,
|
|
293
|
+
liveGame: e.gameId
|
|
294
|
+
});
|
|
295
|
+
return r ? g.send(r) : Promise.reject(/* @__PURE__ */ Error("Live signal too large"));
|
|
296
|
+
},
|
|
297
|
+
subscribe(t) {
|
|
298
|
+
return g.subscribe((n) => {
|
|
299
|
+
ee(n?.text)?.liveGame === e.gameId && t(n);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
selfId: s,
|
|
304
|
+
peerId: b,
|
|
305
|
+
roomId: e.roomId,
|
|
306
|
+
iceServers: te,
|
|
307
|
+
iceTransportPolicy: ne,
|
|
308
|
+
RTCPeerConnectionImpl: re,
|
|
309
|
+
onMove: Ce,
|
|
310
|
+
onEvent: Oe,
|
|
311
|
+
onChange(e) {
|
|
312
|
+
let t = z.phase;
|
|
313
|
+
if (z = e, e.phase === "connected") {
|
|
314
|
+
let e = B;
|
|
315
|
+
B = !0, I !== "over" && (I = "playing"), t !== "connected" && queueMicrotask(() => {
|
|
316
|
+
R || (V && Y({ k: "resign" }), h && e ? Y(he()) : h || Y({ k: "sync" }));
|
|
317
|
+
});
|
|
318
|
+
} else I !== "over" && (I = B ? "disconnected" : "connecting");
|
|
319
|
+
me();
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
function ke() {
|
|
323
|
+
h && fe.size === 2 && (j++, Y({ k: "round" }), be());
|
|
324
|
+
}
|
|
325
|
+
return h ? $.connect() : $.setListening(!0), {
|
|
326
|
+
setInput(e) {
|
|
327
|
+
oe = { ...e };
|
|
328
|
+
},
|
|
329
|
+
step(r) {
|
|
330
|
+
if (R) return;
|
|
331
|
+
let i = Math.max(0, Math.min(Number(r) || 0, 100));
|
|
332
|
+
if (A += i, I !== "playing") return;
|
|
333
|
+
let a = i / 1e3;
|
|
334
|
+
for (let e = 0; e < 2; e++) P[e] && A >= P[e] && (P[e] = 0, J({
|
|
335
|
+
k: "shield_end",
|
|
336
|
+
target: y[e]
|
|
337
|
+
})), h && F[e] !== null && A >= F[e] && N[e] > 0 && (_e(e), Y({
|
|
338
|
+
k: "respawn",
|
|
339
|
+
target: y[e]
|
|
340
|
+
}));
|
|
341
|
+
let l = A - 100;
|
|
342
|
+
for (; U.length > 1 && U[1].time <= l;) U.shift();
|
|
343
|
+
if (U.length) {
|
|
344
|
+
let e = U[0], t = U[1] || e, n = o(e.pose, t.pose, t.time === e.time ? 1 : (l - 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 = a; e > 0; e -= .016) n(q(), oe, Math.min(e, .016), S);
|
|
354
|
+
oe.fire && Se(s, {
|
|
355
|
+
id: `${s}:${j}:${++M}`,
|
|
356
|
+
x: q().x,
|
|
357
|
+
z: q().z,
|
|
358
|
+
yaw: q().turretYaw,
|
|
359
|
+
t: A
|
|
360
|
+
}, !0);
|
|
361
|
+
let d = z.rtt > 250 || z.move?.lossPct > 15 ? 10 : z.rtt > 100 ? 15 : 20;
|
|
362
|
+
if (A >= se) {
|
|
363
|
+
se = A + 1e3 / d;
|
|
364
|
+
let t = q();
|
|
365
|
+
$.sendMove({
|
|
366
|
+
g: e.gameId,
|
|
367
|
+
r: j,
|
|
368
|
+
p: [
|
|
369
|
+
t.x,
|
|
370
|
+
t.z,
|
|
371
|
+
t.yaw,
|
|
372
|
+
t.turretYaw,
|
|
373
|
+
t.speed
|
|
374
|
+
],
|
|
375
|
+
t: A
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
O = O.filter((e) => {
|
|
379
|
+
let n = c(e, a, S, D);
|
|
380
|
+
if (!n) return !0;
|
|
381
|
+
if (h && n.target && I === "playing" && P[y.indexOf(n.target)] > A) J({
|
|
382
|
+
k: "impact",
|
|
383
|
+
kind: "shield",
|
|
384
|
+
target: n.target,
|
|
385
|
+
x: e.x,
|
|
386
|
+
z: e.z
|
|
387
|
+
});
|
|
388
|
+
else if (h && n.target && I === "playing") {
|
|
389
|
+
let t = D.find((e) => e.id === n.target);
|
|
390
|
+
t.hp = Math.max(0, t.hp - f.damage), t.alive = t.hp > 0;
|
|
391
|
+
let r = {
|
|
392
|
+
k: "hit",
|
|
393
|
+
id: e.id,
|
|
394
|
+
target: t.id,
|
|
395
|
+
dmg: f.damage,
|
|
396
|
+
hp: D.map((e) => e.hp),
|
|
397
|
+
x: e.x,
|
|
398
|
+
z: e.z
|
|
399
|
+
};
|
|
400
|
+
Y(r), J(r), t.alive || Q(y.indexOf(t.id), e.owner);
|
|
401
|
+
} else if (h && n.kind === "destructible" && I === "playing") {
|
|
402
|
+
let r = E(n.id), i = t(S, n.id, 1);
|
|
403
|
+
if (Y({
|
|
404
|
+
k: "destructible_hit",
|
|
405
|
+
id: e.id,
|
|
406
|
+
target: n.id,
|
|
407
|
+
hp: i.hp,
|
|
408
|
+
x: e.x,
|
|
409
|
+
z: e.z
|
|
410
|
+
}), De(r, e.id, e.x, e.z), i.destroyed && r.kind === "barrel") {
|
|
411
|
+
let t = u(S, r.id, D), n = ye(t.hits, e.owner), i = {
|
|
412
|
+
k: "barrel_explode",
|
|
413
|
+
target: r.id,
|
|
414
|
+
chained: t.chained?.id ?? null,
|
|
415
|
+
hp: D.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: t.chained,
|
|
423
|
+
hp: [...i.hp]
|
|
424
|
+
}), n();
|
|
425
|
+
}
|
|
426
|
+
} else J({
|
|
427
|
+
k: "impact",
|
|
428
|
+
kind: n.kind,
|
|
429
|
+
x: e.x,
|
|
430
|
+
z: e.z
|
|
431
|
+
}), n.shape === "rect" && J({
|
|
432
|
+
k: "wall_hit",
|
|
433
|
+
id: n.id,
|
|
434
|
+
kind: n.obstacleKind,
|
|
435
|
+
x: e.x,
|
|
436
|
+
z: e.z
|
|
437
|
+
});
|
|
438
|
+
return !1;
|
|
439
|
+
});
|
|
440
|
+
},
|
|
441
|
+
getRender() {
|
|
442
|
+
let e = {
|
|
443
|
+
arena: S,
|
|
444
|
+
map: S,
|
|
445
|
+
maxLives: C,
|
|
446
|
+
lives: [...N],
|
|
447
|
+
shield: [0, 1].map(Z),
|
|
448
|
+
respawn: F.map((e) => e === null ? null : Math.max(0, Math.round(e - A))),
|
|
449
|
+
destructibles: (S.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: r(e)
|
|
457
|
+
})),
|
|
458
|
+
tanks: D.map((e) => ({
|
|
459
|
+
...e,
|
|
460
|
+
self: e.id === s,
|
|
461
|
+
reload: Math.min(1, (A - (de.get(e.id) ?? -Infinity)) / f.reloadMs)
|
|
462
|
+
})),
|
|
463
|
+
shells: O.map((e) => ({ ...e })),
|
|
464
|
+
events: k,
|
|
465
|
+
status: I,
|
|
466
|
+
winner: L,
|
|
467
|
+
net: {
|
|
468
|
+
...z,
|
|
469
|
+
turnConfigured: z.turnConfigured ?? ie
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
return k = [], e;
|
|
473
|
+
},
|
|
474
|
+
configureTurn(e, t) {
|
|
475
|
+
return R || I === "over" ? Promise.reject(/* @__PURE__ */ Error("La partida ya terminó.")) : $.configureTurn(e, t);
|
|
476
|
+
},
|
|
477
|
+
reconnect() {
|
|
478
|
+
!R && I !== "over" && ($.requestReconnect ? $.requestReconnect() : $.connect());
|
|
479
|
+
},
|
|
480
|
+
rematch() {
|
|
481
|
+
!R && I === "over" && (fe.add(s), Y({ k: "rematch" }), ke());
|
|
482
|
+
},
|
|
483
|
+
resign() {
|
|
484
|
+
!R && I !== "over" && (V = !0, H = "resigned", Y({ k: "resign" }), xe(b));
|
|
485
|
+
},
|
|
486
|
+
destroy() {
|
|
487
|
+
R || (R = !0, $.destroy(), O = [], U = [], k = []);
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
var F = 180 / Math.PI, I = (e, t) => Number.isFinite(e) ? e : t;
|
|
492
|
+
function L(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 R({
|
|
495
|
+
minX: n.minX,
|
|
496
|
+
minZ: n.minZ,
|
|
497
|
+
maxX: n.maxX,
|
|
498
|
+
maxZ: n.maxZ
|
|
499
|
+
});
|
|
500
|
+
let r = I(t.width, I(t.size, 120)), i = I(t.depth, I(t.height, I(t.size, r)));
|
|
501
|
+
return R(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 R(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 z(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: I(e.r, I(e.radius, 1.5)),
|
|
527
|
+
kind: e.kind === "tree" ? "tree" : "rock"
|
|
528
|
+
}));
|
|
529
|
+
}
|
|
530
|
+
var B = (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 (B(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: I(e.w, 2),
|
|
617
|
+
d: I(e.d, 2),
|
|
618
|
+
rot: I(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: I(e.r, I(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: I(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 = B(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 = L(t), a = me(t) ? t : null, o = a ? be[a.id] : {
|
|
730
|
+
bg: "#152519",
|
|
731
|
+
ground: "#526348"
|
|
732
|
+
}, s = a ? Y(t) : z(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__ */ e({ default: () => je }), Te = (e, t) => {
|
|
774
|
+
s.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__ */ M("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__ */ M("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 = w(h)?.config?.webrtc, o = s((t) => t.games[e]), c = E(i);
|
|
798
|
+
c.current = i;
|
|
799
|
+
let l = E(null), u = E(null), d = E(null), f = E({
|
|
800
|
+
throttle: 0,
|
|
801
|
+
steer: 0,
|
|
802
|
+
fire: !1
|
|
803
|
+
}), [p, ee] = D(null), [m, C] = D(""), [ce, le] = D(!1), [ue, F] = D("loading"), [I, L] = D(!1), [R, z] = D(0), V = p?.net?.phase === "connected";
|
|
804
|
+
T(() => {
|
|
805
|
+
if (!o || o.status !== "active" || V) {
|
|
806
|
+
z(0);
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
let e = Date.now(), t = setInterval(() => z(Date.now() - e), 1e3);
|
|
810
|
+
return () => clearInterval(t);
|
|
811
|
+
}, [
|
|
812
|
+
e,
|
|
813
|
+
o?.status,
|
|
814
|
+
V
|
|
815
|
+
]), T(() => {
|
|
816
|
+
L(!1);
|
|
817
|
+
}, [e, o?.status]), T(() => {
|
|
818
|
+
i ? (Ee(f.current), x()) : d.current?.resize();
|
|
819
|
+
}, [i]);
|
|
820
|
+
let H = ["active", "won"].includes(o?.status), [W, G] = D(null);
|
|
821
|
+
if (T(() => {
|
|
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" && le(!0);
|
|
829
|
+
}
|
|
830
|
+
}, r = () => {
|
|
831
|
+
e || (t = Ce(l.current, n), d.current = t, F("2d"));
|
|
832
|
+
};
|
|
833
|
+
return ce ? r() : import("./createLiveScene-MTGRv8rx.js").then(({ createLiveScene: i }) => {
|
|
834
|
+
if (!e) try {
|
|
835
|
+
t = i(l.current, n), d.current = t, F("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
|
+
ce
|
|
846
|
+
]), T(() => {
|
|
847
|
+
if (!H || o.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
|
+
b();
|
|
850
|
+
let _;
|
|
851
|
+
try {
|
|
852
|
+
let n = s.getState().createLiveSignaling(e);
|
|
853
|
+
_ = P({
|
|
854
|
+
iceServers: a?.iceServers,
|
|
855
|
+
iceTransportPolicy: a?.iceTransportPolicy,
|
|
856
|
+
game: o,
|
|
857
|
+
selfId: String(t),
|
|
858
|
+
isHost: String(o.hostId) === String(t),
|
|
859
|
+
signaling: n
|
|
860
|
+
}), u.current = _;
|
|
861
|
+
} catch (e) {
|
|
862
|
+
C(e.message || "No se pudo iniciar WebRTC");
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
G(Oe(_.getRender()));
|
|
866
|
+
let v = null, te = !1;
|
|
867
|
+
function S() {
|
|
868
|
+
g.clear(), Ee(f.current), x();
|
|
869
|
+
}
|
|
870
|
+
function w(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 T = (e) => w(e, !0), E = (e) => w(e, !1), D = l.current;
|
|
884
|
+
D.addEventListener("keydown", T), D.addEventListener("keyup", E), D.addEventListener("blur", S);
|
|
885
|
+
let O = () => {
|
|
886
|
+
document.hidden && S();
|
|
887
|
+
};
|
|
888
|
+
document.addEventListener("visibilitychange", O), ie({ type: "engine_start" }, e);
|
|
889
|
+
function k(t) {
|
|
890
|
+
if (n) return;
|
|
891
|
+
let a = Math.min(80, t - i);
|
|
892
|
+
i = t;
|
|
893
|
+
let o = c.current || document.hidden;
|
|
894
|
+
_.setInput(o ? {
|
|
895
|
+
throttle: 0,
|
|
896
|
+
steer: 0,
|
|
897
|
+
fire: !1
|
|
898
|
+
} : f.current), _.step(a);
|
|
899
|
+
let l = _.getRender();
|
|
900
|
+
if (o || d.current?.render(l, a), o && (g.clear(), h.reset(), x(), te = !1), !o) for (let e of l.events || []) for (let t of K(e)) ie(t, e.id);
|
|
901
|
+
if (!o) for (let e of l.events || []) for (let t of ye(e, l)) y(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) && (B(e) === "life_lost" && (v = t + (Number.isFinite(e.respawnMs) ? e.respawnMs : De)), B(e) === "respawn" && (v = null));
|
|
906
|
+
}
|
|
907
|
+
u?.alive !== !1 && v != null && t >= v && (v = null);
|
|
908
|
+
let b = !o && l.status === "playing" && u?.alive !== !1 && _e(l, u) > 0;
|
|
909
|
+
b !== te && (te = b, b ? ne("shield_loop") : re("shield_loop"));
|
|
910
|
+
let S = u ? l.tanks.indexOf(u) : -1, C = Number.isFinite(l.respawn?.[S]) ? l.respawn[S] : v != null && l.status === "playing" ? Math.max(0, v - t) : 0;
|
|
911
|
+
if (!o) for (let e of h.update(U(l.tanks), a)) ie(e);
|
|
912
|
+
let w = fe(l);
|
|
913
|
+
w && !m && (v = null, ee({
|
|
914
|
+
...l,
|
|
915
|
+
respawnIn: 0
|
|
916
|
+
}), m = w, o || ae(m, e), s.getState().liveFinish?.(e, l.winner)), t - p > 100 && (p = t, ee({
|
|
917
|
+
...l,
|
|
918
|
+
respawnIn: C
|
|
919
|
+
})), r = requestAnimationFrame(k);
|
|
920
|
+
}
|
|
921
|
+
return r = requestAnimationFrame(k), () => {
|
|
922
|
+
n = !0, cancelAnimationFrame(r), S(), _.destroy(), u.current = null, D.removeEventListener("keydown", T), D.removeEventListener("keyup", E), D.removeEventListener("blur", S), document.removeEventListener("visibilitychange", O);
|
|
923
|
+
};
|
|
924
|
+
}, [
|
|
925
|
+
H,
|
|
926
|
+
e,
|
|
927
|
+
t
|
|
928
|
+
]), !o) return null;
|
|
929
|
+
let q = String(t) === String(o.guestId), Y = p?.status === "over" || o.status === "won", X = p?.net, Z = X?.manualTurn, he = [
|
|
930
|
+
"waiting_peer",
|
|
931
|
+
"sharing",
|
|
932
|
+
"applying"
|
|
933
|
+
].includes(Z?.status), Q = !V && (R >= 12e3 || X?.phase === "failed" || X?.ice === "failed" || Z?.status === "failed" || !!m), 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__ */ N("section", {
|
|
958
|
+
className: `chat-game-card tl-card${H ? " tl-card--active" : ""}`,
|
|
959
|
+
"aria-label": "Tanques LIVE 3D",
|
|
960
|
+
children: [
|
|
961
|
+
/* @__PURE__ */ N("header", {
|
|
962
|
+
className: "tl-header",
|
|
963
|
+
children: [/* @__PURE__ */ M("strong", { children: "Tanques LIVE 3D" }), /* @__PURE__ */ N("div", {
|
|
964
|
+
className: "tl-header-actions",
|
|
965
|
+
children: [
|
|
966
|
+
/* @__PURE__ */ M(g, { manager: S() }),
|
|
967
|
+
n && /* @__PURE__ */ M("button", {
|
|
968
|
+
onClick: n,
|
|
969
|
+
"aria-label": "Minimizar",
|
|
970
|
+
children: "−"
|
|
971
|
+
}),
|
|
972
|
+
r && /* @__PURE__ */ M("button", {
|
|
973
|
+
onClick: r,
|
|
974
|
+
"aria-label": "Ocultar",
|
|
975
|
+
children: "×"
|
|
976
|
+
})
|
|
977
|
+
]
|
|
978
|
+
})]
|
|
979
|
+
}),
|
|
980
|
+
o.status === "invited" && /* @__PURE__ */ N("div", {
|
|
981
|
+
className: "tl-invite",
|
|
982
|
+
children: [
|
|
983
|
+
/* @__PURE__ */ M("span", {
|
|
984
|
+
className: "tl-invite-icon",
|
|
985
|
+
"aria-hidden": "true",
|
|
986
|
+
children: "🪖"
|
|
987
|
+
}),
|
|
988
|
+
/* @__PURE__ */ M("strong", { children: q ? "¿Listo para combatir?" : "Invitación enviada" }),
|
|
989
|
+
/* @__PURE__ */ M("p", { children: q ? "Te invitaron a un combate en tiempo real." : "Esperando que el rival acepte…" }),
|
|
990
|
+
q && /* @__PURE__ */ N("div", {
|
|
991
|
+
className: "tl-invite-actions",
|
|
992
|
+
children: [/* @__PURE__ */ M("button", {
|
|
993
|
+
className: "tl-button-primary",
|
|
994
|
+
onClick: () => Te(e, "game_accept"),
|
|
995
|
+
children: "Aceptar combate"
|
|
996
|
+
}), /* @__PURE__ */ M("button", {
|
|
997
|
+
onClick: () => Te(e, "game_decline"),
|
|
998
|
+
children: "Rechazar"
|
|
999
|
+
})]
|
|
1000
|
+
})
|
|
1001
|
+
]
|
|
1002
|
+
}),
|
|
1003
|
+
H && !Y && /* @__PURE__ */ N("div", {
|
|
1004
|
+
className: `tl-connection tl-connection--${V ? "connected" : Q ? "problem" : "pending"}`,
|
|
1005
|
+
children: [
|
|
1006
|
+
/* @__PURE__ */ N("div", {
|
|
1007
|
+
className: "tl-connection-heading",
|
|
1008
|
+
children: [
|
|
1009
|
+
V ? /* @__PURE__ */ M(k, {
|
|
1010
|
+
size: 18,
|
|
1011
|
+
"aria-hidden": "true"
|
|
1012
|
+
}) : Q ? /* @__PURE__ */ M(O, {
|
|
1013
|
+
size: 18,
|
|
1014
|
+
"aria-hidden": "true"
|
|
1015
|
+
}) : /* @__PURE__ */ M(A, {
|
|
1016
|
+
size: 18,
|
|
1017
|
+
className: "tl-connection-spinner",
|
|
1018
|
+
"aria-hidden": "true"
|
|
1019
|
+
}),
|
|
1020
|
+
/* @__PURE__ */ N("div", { children: [/* @__PURE__ */ M("strong", { children: Q ? "Problemas de conexión" : ke(X, !1) }), Q && /* @__PURE__ */ M("p", { children: "No pudimos establecer una conexión con el otro jugador. Puedes configurar una conexión alternativa para continuar." })] }),
|
|
1021
|
+
Ae && /* @__PURE__ */ M("span", {
|
|
1022
|
+
className: "tl-route-badge",
|
|
1023
|
+
children: Ae
|
|
1024
|
+
})
|
|
1025
|
+
]
|
|
1026
|
+
}),
|
|
1027
|
+
!V && /* @__PURE__ */ M("p", {
|
|
1028
|
+
className: "tl-connection-message",
|
|
1029
|
+
role: "status",
|
|
1030
|
+
children: Q ? ke(X, R >= 12e3) : _(X)
|
|
1031
|
+
}),
|
|
1032
|
+
Z?.status === "synchronized" && /* @__PURE__ */ M("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__ */ M("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__ */ N("div", {
|
|
1043
|
+
className: "tl-connection-actions",
|
|
1044
|
+
children: [/* @__PURE__ */ N("button", {
|
|
1045
|
+
type: "button",
|
|
1046
|
+
className: Q ? "tl-button-primary" : "",
|
|
1047
|
+
onClick: () => L(!0),
|
|
1048
|
+
children: [/* @__PURE__ */ M(se, {
|
|
1049
|
+
size: 15,
|
|
1050
|
+
"aria-hidden": "true"
|
|
1051
|
+
}), "Configurar conexión alternativa"]
|
|
1052
|
+
}), !V && /* @__PURE__ */ N("button", {
|
|
1053
|
+
type: "button",
|
|
1054
|
+
disabled: he,
|
|
1055
|
+
onClick: () => u.current?.reconnect(),
|
|
1056
|
+
children: [/* @__PURE__ */ M(oe, {
|
|
1057
|
+
size: 15,
|
|
1058
|
+
"aria-hidden": "true"
|
|
1059
|
+
}), "Reintentar conexión"]
|
|
1060
|
+
})]
|
|
1061
|
+
})
|
|
1062
|
+
]
|
|
1063
|
+
}),
|
|
1064
|
+
/* @__PURE__ */ M(v, {
|
|
1065
|
+
open: I && H && !Y,
|
|
1066
|
+
onClose: () => L(!1),
|
|
1067
|
+
onApply: je,
|
|
1068
|
+
manualTurn: Z
|
|
1069
|
+
}),
|
|
1070
|
+
(H || p) && /* @__PURE__ */ N(j, { children: [
|
|
1071
|
+
/* @__PURE__ */ N("div", {
|
|
1072
|
+
className: "tl-hud",
|
|
1073
|
+
children: [
|
|
1074
|
+
(p?.tanks || []).map((e) => /* @__PURE__ */ N("span", { children: [
|
|
1075
|
+
e.self ? "Tú" : "Rival",
|
|
1076
|
+
" ",
|
|
1077
|
+
/* @__PURE__ */ M("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__ */ M($, {
|
|
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__ */ M("span", {
|
|
1092
|
+
className: "tl-shield-badge",
|
|
1093
|
+
title: "Escudo activo",
|
|
1094
|
+
children: "🛡️"
|
|
1095
|
+
})
|
|
1096
|
+
] }, e.id)),
|
|
1097
|
+
be && /* @__PURE__ */ N("span", {
|
|
1098
|
+
className: "tl-map",
|
|
1099
|
+
children: [
|
|
1100
|
+
pe[be.id],
|
|
1101
|
+
" ",
|
|
1102
|
+
J(be)
|
|
1103
|
+
]
|
|
1104
|
+
}),
|
|
1105
|
+
/* @__PURE__ */ N("span", {
|
|
1106
|
+
role: "status",
|
|
1107
|
+
children: [
|
|
1108
|
+
V ? Ae || "Conectado" : ke(X, R >= 12e3),
|
|
1109
|
+
" ",
|
|
1110
|
+
Number.isFinite(X?.rtt) ? `· ${Math.round(X.rtt)} ms` : ""
|
|
1111
|
+
]
|
|
1112
|
+
})
|
|
1113
|
+
]
|
|
1114
|
+
}),
|
|
1115
|
+
we > 0 && !Y && /* @__PURE__ */ N("div", {
|
|
1116
|
+
className: "tl-respawn",
|
|
1117
|
+
role: "status",
|
|
1118
|
+
children: [
|
|
1119
|
+
"Reapareces en ",
|
|
1120
|
+
we,
|
|
1121
|
+
" s…"
|
|
1122
|
+
]
|
|
1123
|
+
}),
|
|
1124
|
+
/* @__PURE__ */ M("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__ */ N("div", {
|
|
1144
|
+
className: "tl-controls",
|
|
1145
|
+
children: [
|
|
1146
|
+
/* @__PURE__ */ M("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__ */ N("div", {
|
|
1166
|
+
className: "tl-drive",
|
|
1167
|
+
"aria-label": "Controles de conducción",
|
|
1168
|
+
children: [
|
|
1169
|
+
/* @__PURE__ */ M("button", {
|
|
1170
|
+
"aria-label": "Avanzar",
|
|
1171
|
+
...Ne("throttle", 1),
|
|
1172
|
+
children: "▲"
|
|
1173
|
+
}),
|
|
1174
|
+
/* @__PURE__ */ M("button", {
|
|
1175
|
+
"aria-label": "Girar izquierda",
|
|
1176
|
+
...Ne("steer", -1),
|
|
1177
|
+
children: "◀"
|
|
1178
|
+
}),
|
|
1179
|
+
/* @__PURE__ */ M("button", {
|
|
1180
|
+
"aria-label": "Retroceder",
|
|
1181
|
+
...Ne("throttle", -1),
|
|
1182
|
+
children: "▼"
|
|
1183
|
+
}),
|
|
1184
|
+
/* @__PURE__ */ M("button", {
|
|
1185
|
+
"aria-label": "Girar derecha",
|
|
1186
|
+
...Ne("steer", 1),
|
|
1187
|
+
children: "▶"
|
|
1188
|
+
})
|
|
1189
|
+
]
|
|
1190
|
+
}),
|
|
1191
|
+
/* @__PURE__ */ M("button", {
|
|
1192
|
+
className: "tl-fire",
|
|
1193
|
+
...Ne("fire", !0),
|
|
1194
|
+
children: "Disparar"
|
|
1195
|
+
})
|
|
1196
|
+
]
|
|
1197
|
+
}),
|
|
1198
|
+
/* @__PURE__ */ M("div", {
|
|
1199
|
+
className: "tl-reload",
|
|
1200
|
+
children: /* @__PURE__ */ N("label", { children: [
|
|
1201
|
+
"Recarga ",
|
|
1202
|
+
/* @__PURE__ */ M("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__ */ M("small", { children: "WASD / flechas · ratón o toca la arena para apuntar · espacio / clic para disparar" }),
|
|
1211
|
+
/* @__PURE__ */ M("button", {
|
|
1212
|
+
onClick: () => le((e) => !e),
|
|
1213
|
+
children: ue === "2d" ? "Probar 3D" : "Vista 2D"
|
|
1214
|
+
})
|
|
1215
|
+
] }),
|
|
1216
|
+
Y && /* @__PURE__ */ N("p", {
|
|
1217
|
+
role: "status",
|
|
1218
|
+
children: [
|
|
1219
|
+
String(p?.winner ?? o.winnerId) === String(t) ? "¡Victoria!" : "Fin del combate",
|
|
1220
|
+
" ",
|
|
1221
|
+
/* @__PURE__ */ M("button", {
|
|
1222
|
+
onClick: () => {
|
|
1223
|
+
Promise.resolve(s.getState().liveRematch?.(e)).catch(() => {});
|
|
1224
|
+
},
|
|
1225
|
+
children: "Revancha"
|
|
1226
|
+
}),
|
|
1227
|
+
be && /* @__PURE__ */ M("button", {
|
|
1228
|
+
onClick: () => {
|
|
1229
|
+
Promise.resolve(s.getState().liveRematch?.(e, { newMap: !0 })).catch(() => {});
|
|
1230
|
+
},
|
|
1231
|
+
children: "Revancha en otro mapa 🎲"
|
|
1232
|
+
})
|
|
1233
|
+
]
|
|
1234
|
+
}),
|
|
1235
|
+
H && /* @__PURE__ */ N("details", {
|
|
1236
|
+
className: "tl-diagnostics",
|
|
1237
|
+
children: [/* @__PURE__ */ M("summary", { children: "Diagnóstico de conexión" }), /* @__PURE__ */ M("pre", { children: JSON.stringify(te(p?.net), null, 2) })]
|
|
1238
|
+
}),
|
|
1239
|
+
H && !Y && /* @__PURE__ */ M("button", {
|
|
1240
|
+
onClick: () => u.current?.resign(),
|
|
1241
|
+
children: "Rendirse"
|
|
1242
|
+
}),
|
|
1243
|
+
o.pending && /* @__PURE__ */ M("p", {
|
|
1244
|
+
role: "status",
|
|
1245
|
+
children: "Enviando…"
|
|
1246
|
+
}),
|
|
1247
|
+
o.pendingEvent && o.error && /* @__PURE__ */ M("button", {
|
|
1248
|
+
onClick: () => {
|
|
1249
|
+
s.getState().retry(e).catch(() => {});
|
|
1250
|
+
},
|
|
1251
|
+
children: "Reintentar envío"
|
|
1252
|
+
}),
|
|
1253
|
+
m && /* @__PURE__ */ M("p", {
|
|
1254
|
+
role: "alert",
|
|
1255
|
+
children: m
|
|
1256
|
+
}),
|
|
1257
|
+
o.error && /* @__PURE__ */ M("p", {
|
|
1258
|
+
role: "alert",
|
|
1259
|
+
children: o.error
|
|
1260
|
+
}),
|
|
1261
|
+
!["closed", "declined"].includes(o.status) && /* @__PURE__ */ M("footer", {
|
|
1262
|
+
className: "tl-footer",
|
|
1263
|
+
children: /* @__PURE__ */ M("button", {
|
|
1264
|
+
onClick: () => Te(e, "game_end"),
|
|
1265
|
+
children: "Cerrar partida"
|
|
1266
|
+
})
|
|
1267
|
+
})
|
|
1268
|
+
]
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
var je = C(Ae);
|
|
1272
|
+
export { W as a, X as c, V as d, je as default, H as f, z as i, Y as l, F as n, B as o, G as p, L as r, me as s, we as t, _e as u };
|
|
1273
|
+
|
|
1274
|
+
//# sourceMappingURL=TanksLiveGameCard-D_27Jomp.js.map
|