@minicode-dev/chat 0.1.9 → 0.1.11
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/README.md +16 -0
- package/dist/chunks/{BattleshipGameCard-BFqA0cjT.js → BattleshipGameCard-iRk8d4vR.js} +2 -2
- package/dist/chunks/{BattleshipGameCard-BFqA0cjT.js.map → BattleshipGameCard-iRk8d4vR.js.map} +1 -1
- package/dist/chunks/{ChatContext-dty_KPDX.js → ChatContext-DjIEifGY.js} +2 -2
- package/dist/chunks/{ChatContext-dty_KPDX.js.map → ChatContext-DjIEifGY.js.map} +1 -1
- package/dist/chunks/{TanksGameCard-D0n-lzTs.js → TanksGameCard-B47ZQcSr.js} +4 -4
- package/dist/chunks/{TanksGameCard-D0n-lzTs.js.map → TanksGameCard-B47ZQcSr.js.map} +1 -1
- package/dist/chunks/{TanksLiveGameCard-BmNRXP66.js → TanksLiveGameCard-BNJqWt1z.js} +303 -237
- package/dist/chunks/TanksLiveGameCard-BNJqWt1z.js.map +1 -0
- package/dist/chunks/{WebRtcLab-B7xBlJy1.js → WebRtcLab-lijo_Rta.js} +2 -2
- package/dist/chunks/{WebRtcLab-B7xBlJy1.js.map → WebRtcLab-lijo_Rta.js.map} +1 -1
- package/dist/chunks/{connect4Sounds-BN7d_TM2.js → connect4Sounds-Cv0q31VW.js} +527 -517
- package/dist/chunks/connect4Sounds-Cv0q31VW.js.map +1 -0
- package/dist/chunks/{createLiveScene-CtYPcOPo.js → createLiveScene-CJQtq54t.js} +2 -2
- package/dist/chunks/{createLiveScene-CtYPcOPo.js.map → createLiveScene-CJQtq54t.js.map} +1 -1
- package/dist/chunks/{createPeerLink-qei05vpV.js → createPeerLink-CL7VZuHS.js} +5 -3
- package/dist/chunks/createPeerLink-CL7VZuHS.js.map +1 -0
- package/dist/chunks/{tanksSounds-C99OD2xD.js → tanksSounds-CUNDIOal.js} +3 -3
- package/dist/chunks/{tanksSounds-C99OD2xD.js.map → tanksSounds-CUNDIOal.js.map} +1 -1
- package/dist/index.js +1688 -1455
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/index.d.ts +3 -3
- package/package.json +1 -1
- package/dist/chunks/TanksLiveGameCard-BmNRXP66.js.map +0 -1
- package/dist/chunks/connect4Sounds-BN7d_TM2.js.map +0 -1
- package/dist/chunks/createPeerLink-qei05vpV.js.map +0 -1
|
@@ -4,19 +4,29 @@ import { createStore as c } from "zustand/vanilla";
|
|
|
4
4
|
import { useStore as l } from "zustand";
|
|
5
5
|
import { Volume2 as u, VolumeX as d } from "lucide-react";
|
|
6
6
|
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
7
|
+
// src/core/ids/randomUuid.js
|
|
8
|
+
function m(e = globalThis.crypto) {
|
|
9
|
+
if (typeof e?.randomUUID == "function") return e.randomUUID();
|
|
10
|
+
let t = /* @__PURE__ */ new Uint8Array(16);
|
|
11
|
+
if (typeof e?.getRandomValues == "function") e.getRandomValues(t);
|
|
12
|
+
else for (let e = 0; e < t.length; e += 1) t[e] = Math.floor(Math.random() * 256);
|
|
13
|
+
t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
|
|
14
|
+
let n = Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
15
|
+
return `${n.slice(0, 8)}-${n.slice(8, 12)}-${n.slice(12, 16)}-${n.slice(16, 20)}-${n.slice(20)}`;
|
|
16
|
+
}
|
|
7
17
|
// src/games/tanks-live/session.js
|
|
8
|
-
var
|
|
9
|
-
function
|
|
18
|
+
var h = (e) => typeof e == "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e), g = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
|
|
19
|
+
function _(e) {
|
|
10
20
|
let t = e.data;
|
|
11
21
|
switch (e.type) {
|
|
12
|
-
case "game_invite": return
|
|
22
|
+
case "game_invite": return g(t.opponent_id) && t.rules_version === 1 && (t.rematch_of === void 0 || h(t.rematch_of));
|
|
13
23
|
case "game_accept":
|
|
14
|
-
case "game_decline": return
|
|
24
|
+
case "game_decline": return h(t.invite_event_id);
|
|
15
25
|
case "game_end": return t.reason === "closed";
|
|
16
26
|
default: return !1;
|
|
17
27
|
}
|
|
18
28
|
}
|
|
19
|
-
function
|
|
29
|
+
function v(e, t) {
|
|
20
30
|
return {
|
|
21
31
|
...e,
|
|
22
32
|
game: "tanks_live",
|
|
@@ -30,7 +40,7 @@ function _(e, t) {
|
|
|
30
40
|
acceptEventId: null
|
|
31
41
|
};
|
|
32
42
|
}
|
|
33
|
-
function
|
|
43
|
+
function y(e, t, n) {
|
|
34
44
|
return [e.hostId, e.guestId].includes(n) ? t.type === "game_end" ? ["closed", "declined"].includes(e.status) ? e : {
|
|
35
45
|
...e,
|
|
36
46
|
status: "closed",
|
|
@@ -48,29 +58,29 @@ function v(e, t, n) {
|
|
|
48
58
|
} : e : e;
|
|
49
59
|
}
|
|
50
60
|
// src/net/webrtc/rtcSignals.js
|
|
51
|
-
var
|
|
61
|
+
var b = /* @__PURE__ */ new Set(), x = {
|
|
52
62
|
emit(e) {
|
|
53
|
-
|
|
63
|
+
b.forEach((t) => {
|
|
54
64
|
try {
|
|
55
65
|
t(e);
|
|
56
66
|
} catch {}
|
|
57
67
|
});
|
|
58
68
|
},
|
|
59
69
|
subscribe(e) {
|
|
60
|
-
return
|
|
70
|
+
return b.add(e), () => b.delete(e);
|
|
61
71
|
}
|
|
62
|
-
},
|
|
72
|
+
}, S = ({ send: e, roomId: t }) => ({
|
|
63
73
|
send: (n) => e(t, n),
|
|
64
|
-
subscribe: (e) =>
|
|
74
|
+
subscribe: (e) => x.subscribe((n) => {
|
|
65
75
|
String(n.roomId) === String(t) && e(n);
|
|
66
76
|
})
|
|
67
|
-
}),
|
|
77
|
+
}), ee = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, te = /^[0-9a-f]{16}$/, C = /^[0-9a-f]{32}$/, ne = /^[0-9a-f]{64}$/, re = (e) => typeof e == "object" && !!e && !Array.isArray(e), ie = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, w = (e) => typeof e == "string" && ee.test(e), T = (e, t, n) => Number.isInteger(e) && e >= t && e <= n, E = Object.freeze([
|
|
68
78
|
"standard",
|
|
69
79
|
"heavy",
|
|
70
80
|
"cluster"
|
|
71
|
-
]),
|
|
72
|
-
function
|
|
73
|
-
return Array.isArray(e) ? e[0] === 1 ? e.length === 6 &&
|
|
81
|
+
]), ae = (e) => T(e, 1, 120), oe = (e) => T(e.move, -16, 16) && T(e.yaw, 0, 359) && T(e.pitch, 5, 80) && T(e.power, 0, 100) && T(e.ammo, 0, E.length - 1);
|
|
82
|
+
function se(e) {
|
|
83
|
+
return Array.isArray(e) ? e[0] === 1 ? e.length === 6 && oe({
|
|
74
84
|
move: e[1],
|
|
75
85
|
yaw: e[2],
|
|
76
86
|
pitch: e[3],
|
|
@@ -78,92 +88,92 @@ function ie(e) {
|
|
|
78
88
|
ammo: e[5]
|
|
79
89
|
}) : e[0] === 2 ? e.length === 1 : e[0] === 3 && e.length === 2 && (e[1] === 0 || e[1] === 1) : !1;
|
|
80
90
|
}
|
|
81
|
-
var
|
|
82
|
-
function
|
|
91
|
+
var D = (e) => Array.isArray(e.log) && e.log.length <= 120 && e.log.every(se) && w(e.head) && (e.accept_event_id === void 0 ? e.log.length === 0 && e.seed_b === void 0 && e.seed_a === void 0 : w(e.accept_event_id) && typeof e.seed_b == "string" && C.test(e.seed_b)) && (e.seed_a === void 0 ? e.log.length === 0 : C.test(e.seed_a) && w(e.seed_event_id));
|
|
92
|
+
function O(e) {
|
|
83
93
|
let t = e.data;
|
|
84
94
|
switch (e.type) {
|
|
85
|
-
case "game_invite": return
|
|
86
|
-
case "game_accept": return
|
|
87
|
-
case "game_decline": return
|
|
95
|
+
case "game_invite": return ie(t.opponent_id) && t.rules_version === 1 && typeof t.seed_commit == "string" && ne.test(t.seed_commit) && (t.first_player_id === void 0 || ie(t.first_player_id)) && (t.rematch_of === void 0 || w(t.rematch_of));
|
|
96
|
+
case "game_accept": return w(t.invite_event_id) && typeof t.seed_b == "string" && C.test(t.seed_b);
|
|
97
|
+
case "game_decline": return w(t.invite_event_id);
|
|
88
98
|
case "game_end": return t.reason === "closed";
|
|
89
99
|
case "tk_seed": return typeof t.seed_a == "string" && C.test(t.seed_a);
|
|
90
|
-
case "tk_turn": return
|
|
100
|
+
case "tk_turn": return ae(t.ply) && w(t.prev_event_id) && oe(t) && typeof t.hash == "string" && te.test(t.hash);
|
|
91
101
|
case "tk_skip":
|
|
92
|
-
case "tk_resign": return
|
|
93
|
-
case "tk_sync_request": return
|
|
94
|
-
case "tk_sync_state": return
|
|
102
|
+
case "tk_resign": return ae(t.ply) && w(t.prev_event_id);
|
|
103
|
+
case "tk_sync_request": return re(t) && D(t);
|
|
104
|
+
case "tk_sync_state": return re(t) && D(t) && w(t.request_event_id);
|
|
95
105
|
default: return !1;
|
|
96
106
|
}
|
|
97
107
|
}
|
|
98
108
|
// src/games/shared/protocol.js
|
|
99
|
-
var
|
|
109
|
+
var ce = "LIRA_GAME_V1:", le = 4096, ue = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, de = (e) => typeof e == "object" && !!e && !Array.isArray(e), fe = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, k = (e) => typeof e == "string" && ue.test(e), pe = (e) => Array.isArray(e) && e.length <= 42 && e.every((e) => Array.isArray(e) && e.length === 2 && Number.isInteger(e[0]) && e[0] >= 0 && e[0] < 7 && k(e[1])) && new Set(e.map((e) => e[1])).size === e.length, me = (e) => pe(e.moves) && e.rev === e.moves.length && (e.accept_event_id === void 0 ? e.moves.length === 0 : k(e.accept_event_id)), he = [
|
|
100
110
|
"carrier",
|
|
101
111
|
"battleship",
|
|
102
112
|
"cruiser",
|
|
103
113
|
"submarine",
|
|
104
114
|
"destroyer"
|
|
105
|
-
],
|
|
106
|
-
function
|
|
115
|
+
], A = (e) => Number.isInteger(e) && e >= 0 && e < 10, ge = (e) => typeof e == "string" && /^[0-9a-f]{64}$/.test(e), _e = (e) => Number.isInteger(e) && e >= 1 && e <= 200, ve = (e) => e === null || de(e) && he.includes(e.ship_id) && Array.isArray(e.cells) && e.cells.length >= 2 && e.cells.length <= 5 && e.cells.every((e) => Array.isArray(e) && e.length === 2 && A(e[0]) && A(e[1])), ye = (e) => Array.isArray(e) && e.length === he.length && e.every((e) => de(e) && he.includes(e.ship_id) && A(e.row) && A(e.col) && (e.orientation === "horizontal" || e.orientation === "vertical")) && new Set(e.map((e) => e.ship_id)).size === e.length, be = (e, t) => Array.isArray(e) && A(e[0]) && A(e[1]) && (e.length === 2 && t || e.length === 3 && (e[2] === 0 || e[2] === 1) || e.length === 7 && e[2] === 2 && Number.isInteger(e[3]) && e[3] >= 0 && e[3] < he.length && A(e[4]) && A(e[5]) && (e[6] === 0 || e[6] === 1)), xe = (e) => Array.isArray(e.commits) && e.commits.length === 2 && e.commits.every((e) => e === null || ge(e)) && Array.isArray(e.log) && e.log.length <= 200 && e.log.every((t, n) => be(t, n === e.log.length - 1)) && k(e.head) && (e.accept_event_id === void 0 ? e.commits.every((e) => e === null) && e.log.length === 0 : k(e.accept_event_id)) && (e.log.length === 0 || e.commits.every(Boolean));
|
|
116
|
+
function Se(e) {
|
|
107
117
|
let t = e.data;
|
|
108
118
|
switch (e.type) {
|
|
109
|
-
case "game_invite": return
|
|
119
|
+
case "game_invite": return fe(t.opponent_id) && t.rules_version === 1;
|
|
110
120
|
case "game_accept":
|
|
111
|
-
case "game_decline": return
|
|
112
|
-
case "game_end": return ["closed", "win"].includes(t.reason) && (t.winner_id === void 0 ||
|
|
113
|
-
case "bs_commit": return
|
|
114
|
-
case "bs_fire": return
|
|
115
|
-
case "bs_result": return
|
|
116
|
-
case "bs_reveal": return
|
|
117
|
-
case "bs_sync_request": return
|
|
118
|
-
case "bs_sync_state": return
|
|
121
|
+
case "game_decline": return k(t.invite_event_id);
|
|
122
|
+
case "game_end": return ["closed", "win"].includes(t.reason) && (t.winner_id === void 0 || fe(t.winner_id));
|
|
123
|
+
case "bs_commit": return ge(t.commitment);
|
|
124
|
+
case "bs_fire": return _e(t.ply) && A(t.row) && A(t.col) && k(t.prev_event_id);
|
|
125
|
+
case "bs_result": return _e(t.ply) && A(t.row) && A(t.col) && ["hit", "miss"].includes(t.result) && ve(t.sunk) && typeof t.defeated == "boolean" && (t.result === "hit" || t.sunk === null && !t.defeated);
|
|
126
|
+
case "bs_reveal": return ye(t.fleet) && typeof t.salt == "string" && /^[0-9a-f]{32}$/.test(t.salt);
|
|
127
|
+
case "bs_sync_request": return xe(t);
|
|
128
|
+
case "bs_sync_state": return xe(t) && k(t.request_event_id);
|
|
119
129
|
default: return !1;
|
|
120
130
|
}
|
|
121
131
|
}
|
|
122
|
-
function
|
|
132
|
+
function Ce(e) {
|
|
123
133
|
return typeof e == "string" && e.startsWith("LIRA_GAME_V1:");
|
|
124
134
|
}
|
|
125
|
-
function
|
|
135
|
+
function we(e) {
|
|
126
136
|
let t = e.data;
|
|
127
137
|
switch (e.type) {
|
|
128
|
-
case "game_invite": return
|
|
138
|
+
case "game_invite": return fe(t.opponent_id) && t.rules_version === 1;
|
|
129
139
|
case "game_accept":
|
|
130
|
-
case "game_decline": return
|
|
131
|
-
case "game_move": return Number.isInteger(t.column) && t.column >= 0 && t.column < 7 && Number.isInteger(t.ply) && t.ply >= 1 && t.ply <= 42 &&
|
|
140
|
+
case "game_decline": return k(t.invite_event_id);
|
|
141
|
+
case "game_move": return Number.isInteger(t.column) && t.column >= 0 && t.column < 7 && Number.isInteger(t.ply) && t.ply >= 1 && t.ply <= 42 && k(t.prev_event_id);
|
|
132
142
|
case "game_end": return [
|
|
133
143
|
"closed",
|
|
134
144
|
"win",
|
|
135
145
|
"draw"
|
|
136
|
-
].includes(t.reason) && (t.winner_id === void 0 ||
|
|
137
|
-
case "game_resync_request": return
|
|
138
|
-
case "game_resync_state": return
|
|
146
|
+
].includes(t.reason) && (t.winner_id === void 0 || fe(t.winner_id)) && (t.final_move_event_id === void 0 || k(t.final_move_event_id)) && (t.reason !== "win" || fe(t.winner_id) && k(t.final_move_event_id)) && (t.reason !== "draw" || k(t.final_move_event_id));
|
|
147
|
+
case "game_resync_request": return me(t);
|
|
148
|
+
case "game_resync_state": return me(t) && k(t.request_event_id);
|
|
139
149
|
default: return !1;
|
|
140
150
|
}
|
|
141
151
|
}
|
|
142
|
-
var
|
|
143
|
-
connect4:
|
|
144
|
-
battleship:
|
|
145
|
-
tanks:
|
|
146
|
-
tanks_live:
|
|
147
|
-
},
|
|
148
|
-
function
|
|
149
|
-
return !
|
|
150
|
-
}
|
|
151
|
-
function
|
|
152
|
-
if (!
|
|
152
|
+
var Te = {
|
|
153
|
+
connect4: we,
|
|
154
|
+
battleship: Se,
|
|
155
|
+
tanks: O,
|
|
156
|
+
tanks_live: _
|
|
157
|
+
}, Ee = Object.freeze(Object.keys(Te));
|
|
158
|
+
function De(e) {
|
|
159
|
+
return !de(e) || e.version !== 1 || !Object.hasOwn(Te, e.game) || !k(e.game_id) || !k(e.event_id) || !de(e.data) ? !1 : Te[e.game](e);
|
|
160
|
+
}
|
|
161
|
+
function Oe(e) {
|
|
162
|
+
if (!Ce(e) || e.length > le) return null;
|
|
153
163
|
try {
|
|
154
164
|
let t = JSON.parse(e.slice(13));
|
|
155
|
-
return
|
|
165
|
+
return De(t) ? t : null;
|
|
156
166
|
} catch {
|
|
157
167
|
return null;
|
|
158
168
|
}
|
|
159
169
|
}
|
|
160
|
-
function
|
|
161
|
-
if (!
|
|
162
|
-
let t =
|
|
163
|
-
if (t.length >
|
|
170
|
+
function ke(e) {
|
|
171
|
+
if (!De(e)) throw Error("Evento de juego inválido");
|
|
172
|
+
let t = ce + JSON.stringify(e);
|
|
173
|
+
if (t.length > le) throw Error("Evento de juego demasiado grande");
|
|
164
174
|
return t;
|
|
165
175
|
}
|
|
166
|
-
function
|
|
176
|
+
function j(e, { game_id: t, data: n, event_id: r = m(), game: i = "connect4" }) {
|
|
167
177
|
let a = {
|
|
168
178
|
version: 1,
|
|
169
179
|
game: i,
|
|
@@ -172,22 +182,22 @@ function M(e, { game_id: t, data: n, event_id: r = crypto.randomUUID(), game: i
|
|
|
172
182
|
type: e,
|
|
173
183
|
data: n
|
|
174
184
|
};
|
|
175
|
-
if (!
|
|
185
|
+
if (!De(a)) throw Error("Evento de juego inválido");
|
|
176
186
|
return a;
|
|
177
187
|
}
|
|
178
|
-
function
|
|
188
|
+
function Ae() {
|
|
179
189
|
return Array.from({ length: 6 }, () => Array(7).fill(null));
|
|
180
190
|
}
|
|
181
|
-
var
|
|
191
|
+
var je = [
|
|
182
192
|
[0, 1],
|
|
183
193
|
[1, 0],
|
|
184
194
|
[1, 1],
|
|
185
195
|
[1, -1]
|
|
186
196
|
];
|
|
187
|
-
function
|
|
197
|
+
function Me(e) {
|
|
188
198
|
for (let t = 0; t < 6; t += 1) for (let n = 0; n < 7; n += 1) {
|
|
189
199
|
let r = e[t][n];
|
|
190
|
-
if (r != null) for (let [i, a] of
|
|
200
|
+
if (r != null) for (let [i, a] of je) {
|
|
191
201
|
let o = [];
|
|
192
202
|
for (let s = 0; s < 4; s += 1) {
|
|
193
203
|
let c = t + i * s, l = n + a * s;
|
|
@@ -199,34 +209,34 @@ function Ae(e) {
|
|
|
199
209
|
}
|
|
200
210
|
return [];
|
|
201
211
|
}
|
|
202
|
-
function
|
|
203
|
-
let t =
|
|
212
|
+
function Ne(e) {
|
|
213
|
+
let t = Me(e);
|
|
204
214
|
return t.length ? e[t[0][0]][t[0][1]] : null;
|
|
205
215
|
}
|
|
206
|
-
function
|
|
216
|
+
function Pe(e) {
|
|
207
217
|
return e[0].every((e) => e !== null);
|
|
208
218
|
}
|
|
209
|
-
function
|
|
210
|
-
if (!Number.isInteger(t) || t < 0 || t >= 7 || n == null ||
|
|
219
|
+
function Fe(e, t, n) {
|
|
220
|
+
if (!Number.isInteger(t) || t < 0 || t >= 7 || n == null || Ne(e) !== null) return null;
|
|
211
221
|
let r = 5;
|
|
212
222
|
for (; r >= 0 && e[r][t] !== null;) --r;
|
|
213
223
|
if (r < 0) return null;
|
|
214
224
|
let i = e.map((e) => e.slice());
|
|
215
225
|
i[r][t] = n;
|
|
216
|
-
let a =
|
|
226
|
+
let a = Me(i), o = a.length ? i[a[0][0]][a[0][1]] : null;
|
|
217
227
|
return {
|
|
218
228
|
board: i,
|
|
219
229
|
row: r,
|
|
220
230
|
column: t,
|
|
221
231
|
winner: o,
|
|
222
|
-
draw: o === null &&
|
|
232
|
+
draw: o === null && Pe(i),
|
|
223
233
|
winningCells: a
|
|
224
234
|
};
|
|
225
235
|
}
|
|
226
236
|
// src/games/battleship/logic/game.js
|
|
227
|
-
var
|
|
228
|
-
function
|
|
229
|
-
if (!
|
|
237
|
+
var Ie = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e;
|
|
238
|
+
function Le({ gameId: e, players: t, firstPlayerId: n = t?.[0] } = {}) {
|
|
239
|
+
if (!Ie(e) || !Array.isArray(t) || t.length !== 2 || !t.every(Ie) || t[0] === t[1] || !t.includes(n)) throw TypeError("Supply a gameId, two distinct player IDs and a valid firstPlayerId.");
|
|
230
240
|
return {
|
|
231
241
|
game: "battleship",
|
|
232
242
|
rulesVersion: 1,
|
|
@@ -243,7 +253,7 @@ function Fe({ gameId: e, players: t, firstPlayerId: n = t?.[0] } = {}) {
|
|
|
243
253
|
revision: 0
|
|
244
254
|
};
|
|
245
255
|
}
|
|
246
|
-
function
|
|
256
|
+
function Re(n, r) {
|
|
247
257
|
if (!n || !r || typeof r != "object" || n.phase === "finished" || r.gameId !== void 0 && r.gameId !== n.gameId || r.expectedRevision !== void 0 && r.expectedRevision !== n.revision) return n;
|
|
248
258
|
let o = n.players.indexOf(r.playerId);
|
|
249
259
|
if (o < 0) return n;
|
|
@@ -299,16 +309,16 @@ function Ie(n, r) {
|
|
|
299
309
|
};
|
|
300
310
|
}
|
|
301
311
|
// src/games/battleship/net/session.js
|
|
302
|
-
var
|
|
312
|
+
var ze = o.reduce((e, t) => e + t.size, 0), Be = /^[0-9a-f]{32}$/, Ve = [
|
|
303
313
|
"won",
|
|
304
314
|
"closed",
|
|
305
315
|
"declined"
|
|
306
|
-
],
|
|
316
|
+
], M = "La partida perdió sincronización. Se intentará resincronizar.", He = "Falta la aceptación de la partida. Ciérrala y vuelve a invitar.", Ue = "El rival envió un resultado imposible para ese disparo.", We = "Tu flota no está disponible en este dispositivo; no se pueden responder disparos.", Ge = () => Array.from({ length: 10 }, () => Array(10).fill(null)), Ke = (e, t, n, r) => e.map((e, i) => i === t ? e.map((e, t) => t === n ? r : e) : e), qe = (e) => e.reduce((e, t) => e + t.filter((e) => e === "hit").length, 0), Je = (e) => e.reduce((e, t) => e + t.filter((e) => e !== null).length, 0), Ye = (e, t) => t % 2 == 1 ? e.hostId : e.guestId, Xe = (e, t) => t === e.hostId ? e.guestId : e.hostId, Ze = (e, t) => t === e.hostId ? "hostCommitment" : "guestCommitment", N = (e, t) => ({
|
|
307
317
|
...e,
|
|
308
318
|
status: "conflict",
|
|
309
319
|
error: t
|
|
310
|
-
}),
|
|
311
|
-
function
|
|
320
|
+
}), Qe = (e) => `${e.row},${e.col}`, $e = (e, t) => e.row - t.row || e.col - t.col, et = (e, t) => e.length === t.length && e.map(Qe).sort().join("|") === t.map(Qe).sort().join("|");
|
|
321
|
+
function tt(e) {
|
|
312
322
|
return {
|
|
313
323
|
...e,
|
|
314
324
|
game: "battleship",
|
|
@@ -317,8 +327,8 @@ function $e(e) {
|
|
|
317
327
|
myFleet: [],
|
|
318
328
|
myReady: !1,
|
|
319
329
|
opponentReady: !1,
|
|
320
|
-
incomingShots:
|
|
321
|
-
targetShots:
|
|
330
|
+
incomingShots: Ge(),
|
|
331
|
+
targetShots: Ge(),
|
|
322
332
|
sunkEnemyShips: [],
|
|
323
333
|
pendingShot: null,
|
|
324
334
|
lastShot: null,
|
|
@@ -340,7 +350,7 @@ function $e(e) {
|
|
|
340
350
|
sync: e.sync ?? null
|
|
341
351
|
};
|
|
342
352
|
}
|
|
343
|
-
var
|
|
353
|
+
var nt = (e) => e?.game === "battleship" && ["invited", "placement"].includes(e.status) && !e.myReady, rt = (e) => e?.status === "active" && e.turnId === e.ownId && !e.pendingShot, it = (e) => ({
|
|
344
354
|
id: e.id,
|
|
345
355
|
size: e.size,
|
|
346
356
|
orientation: e.orientation,
|
|
@@ -348,33 +358,33 @@ var et = (e) => e?.game === "battleship" && ["invited", "placement"].includes(e.
|
|
|
348
358
|
row: e.row,
|
|
349
359
|
col: e.col
|
|
350
360
|
}))
|
|
351
|
-
}),
|
|
361
|
+
}), at = (e) => ({
|
|
352
362
|
shipId: e.id,
|
|
353
363
|
row: e.cells[0].row,
|
|
354
364
|
col: e.cells[0].col,
|
|
355
365
|
orientation: e.orientation
|
|
356
366
|
});
|
|
357
|
-
function
|
|
367
|
+
function ot(e) {
|
|
358
368
|
return !e || typeof e != "object" ? null : typeof e.ship_id == "string" ? {
|
|
359
369
|
shipId: e.ship_id,
|
|
360
370
|
row: e.row,
|
|
361
371
|
col: e.col,
|
|
362
372
|
orientation: e.orientation
|
|
363
|
-
} : typeof e.id == "string" && Array.isArray(e.cells) && e.cells.length ?
|
|
373
|
+
} : typeof e.id == "string" && Array.isArray(e.cells) && e.cells.length ? at(e) : null;
|
|
364
374
|
}
|
|
365
|
-
function
|
|
375
|
+
function st(e) {
|
|
366
376
|
if (!Array.isArray(e)) return null;
|
|
367
377
|
let t = r();
|
|
368
378
|
for (let n of e) {
|
|
369
|
-
let e =
|
|
379
|
+
let e = ot(n), r = e && a(t, e);
|
|
370
380
|
if (!r?.ok) return null;
|
|
371
381
|
t = r.board;
|
|
372
382
|
}
|
|
373
383
|
return t;
|
|
374
384
|
}
|
|
375
|
-
function
|
|
385
|
+
function ct(e) {
|
|
376
386
|
if (!Array.isArray(e)) return null;
|
|
377
|
-
let t = e.map(
|
|
387
|
+
let t = e.map(ot);
|
|
378
388
|
return t.some((e) => !e) ? null : t.map(({ shipId: e, row: t, col: n, orientation: r }) => ({
|
|
379
389
|
ship_id: e,
|
|
380
390
|
row: t,
|
|
@@ -382,21 +392,21 @@ function ot(e) {
|
|
|
382
392
|
orientation: r
|
|
383
393
|
})).sort((e, t) => e.ship_id < t.ship_id ? -1 : +(e.ship_id > t.ship_id));
|
|
384
394
|
}
|
|
385
|
-
function st(t) {
|
|
386
|
-
let n = at(t);
|
|
387
|
-
return n && e(n) ? n.ships.map(nt) : null;
|
|
388
|
-
}
|
|
389
|
-
var ct = (e) => !!st(e);
|
|
390
395
|
function lt(t) {
|
|
391
|
-
let n =
|
|
396
|
+
let n = st(t);
|
|
397
|
+
return n && e(n) ? n.ships.map(it) : null;
|
|
398
|
+
}
|
|
399
|
+
var ut = (e) => !!lt(e);
|
|
400
|
+
function dt(t) {
|
|
401
|
+
let n = st(t?.myFleet);
|
|
392
402
|
return n && e(n) ? {
|
|
393
403
|
...n,
|
|
394
404
|
shots: t.incomingShots.map((e) => e.slice())
|
|
395
405
|
} : null;
|
|
396
406
|
}
|
|
397
|
-
function
|
|
398
|
-
if (!
|
|
399
|
-
let o =
|
|
407
|
+
function ft(e, { shipId: t, row: n, col: r, orientation: i } = {}) {
|
|
408
|
+
if (!nt(e)) return e;
|
|
409
|
+
let o = st(e.myFleet.filter((e) => e.id !== t)), s = o && a(o, {
|
|
400
410
|
shipId: t,
|
|
401
411
|
row: n,
|
|
402
412
|
col: r,
|
|
@@ -404,23 +414,23 @@ function ut(e, { shipId: t, row: n, col: r, orientation: i } = {}) {
|
|
|
404
414
|
});
|
|
405
415
|
return s?.ok ? {
|
|
406
416
|
...e,
|
|
407
|
-
myFleet: s.board.ships.map(
|
|
417
|
+
myFleet: s.board.ships.map(it)
|
|
408
418
|
} : e;
|
|
409
419
|
}
|
|
410
|
-
function
|
|
411
|
-
return !
|
|
420
|
+
function pt(e, t) {
|
|
421
|
+
return !nt(e) || !e.myFleet.some((e) => e.id === t) ? e : {
|
|
412
422
|
...e,
|
|
413
423
|
myFleet: e.myFleet.filter((e) => e.id !== t)
|
|
414
424
|
};
|
|
415
425
|
}
|
|
416
|
-
function
|
|
426
|
+
function mt(e) {
|
|
417
427
|
let t = Math.floor(4294967296 / e) * e, n = /* @__PURE__ */ new Uint32Array(1);
|
|
418
428
|
do
|
|
419
429
|
globalThis.crypto.getRandomValues(n);
|
|
420
430
|
while (n[0] >= t);
|
|
421
431
|
return n[0] % e;
|
|
422
432
|
}
|
|
423
|
-
function
|
|
433
|
+
function ht(t = mt) {
|
|
424
434
|
for (let n = 0; n < 50; n += 1) {
|
|
425
435
|
let n = r();
|
|
426
436
|
for (let e of o) for (let r = 0; r < 300; r += 1) {
|
|
@@ -435,31 +445,31 @@ function pt(t = ft) {
|
|
|
435
445
|
break;
|
|
436
446
|
}
|
|
437
447
|
}
|
|
438
|
-
if (e(n)) return n.ships.map(
|
|
448
|
+
if (e(n)) return n.ships.map(it);
|
|
439
449
|
}
|
|
440
450
|
throw Error("No se pudo generar una flota aleatoria.");
|
|
441
451
|
}
|
|
442
|
-
var
|
|
452
|
+
var gt = (e, t) => nt(e) ? {
|
|
443
453
|
...e,
|
|
444
|
-
myFleet:
|
|
445
|
-
} : e,
|
|
446
|
-
function
|
|
454
|
+
myFleet: ht(t)
|
|
455
|
+
} : e, _t = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
456
|
+
function vt() {
|
|
447
457
|
let e = /* @__PURE__ */ new Uint8Array(16);
|
|
448
|
-
return globalThis.crypto.getRandomValues(e),
|
|
458
|
+
return globalThis.crypto.getRandomValues(e), _t(e);
|
|
449
459
|
}
|
|
450
|
-
function
|
|
451
|
-
let n =
|
|
460
|
+
function yt(e, t) {
|
|
461
|
+
let n = ct(e);
|
|
452
462
|
if (!n || typeof t != "string") throw TypeError("Flota inválida");
|
|
453
463
|
return JSON.stringify({
|
|
454
464
|
fleet: n,
|
|
455
465
|
salt: t
|
|
456
466
|
});
|
|
457
467
|
}
|
|
458
|
-
async function
|
|
459
|
-
let n = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(
|
|
460
|
-
return
|
|
468
|
+
async function bt(e, t) {
|
|
469
|
+
let n = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(yt(e, t)));
|
|
470
|
+
return _t(new Uint8Array(n));
|
|
461
471
|
}
|
|
462
|
-
function
|
|
472
|
+
function xt(e, t) {
|
|
463
473
|
if (!e || !t) return null;
|
|
464
474
|
let n = i(e, {
|
|
465
475
|
row: t.row,
|
|
@@ -479,7 +489,7 @@ function yt(e, t) {
|
|
|
479
489
|
defeated: n.defeated
|
|
480
490
|
};
|
|
481
491
|
}
|
|
482
|
-
function
|
|
492
|
+
function St(e) {
|
|
483
493
|
let t = o.find((t) => t.id === e?.ship_id);
|
|
484
494
|
if (!t || !Array.isArray(e.cells) || e.cells.length !== t.size) return null;
|
|
485
495
|
let r = e.cells.map((e) => Array.isArray(e) ? {
|
|
@@ -487,7 +497,7 @@ function bt(e) {
|
|
|
487
497
|
col: e[1]
|
|
488
498
|
} : null);
|
|
489
499
|
if (r.some((e) => !n(e))) return null;
|
|
490
|
-
r.sort(
|
|
500
|
+
r.sort($e);
|
|
491
501
|
let i = r.every((e, t) => e.row === r[0].row && e.col === r[0].col + t), a = r.every((e, t) => e.col === r[0].col && e.row === r[0].row + t);
|
|
492
502
|
return !i && !a ? null : {
|
|
493
503
|
id: t.id,
|
|
@@ -497,43 +507,43 @@ function bt(e) {
|
|
|
497
507
|
sunk: !0
|
|
498
508
|
};
|
|
499
509
|
}
|
|
500
|
-
function
|
|
510
|
+
function Ct(e, t) {
|
|
501
511
|
let { row: n, col: r, result: i, sunk: a } = t, s = !!t.defeated;
|
|
502
512
|
if (i !== "hit" && i !== "miss" || e.targetShots[n][r] !== null) return null;
|
|
503
|
-
let c =
|
|
513
|
+
let c = Ke(e.targetShots, n, r, i), l = qe(c), u = null;
|
|
504
514
|
if (a) {
|
|
505
|
-
if (u = i === "hit" ?
|
|
506
|
-
let t = new Set(e.sunkEnemyShips.flatMap((e) => e.cells.map(
|
|
507
|
-
if (!u.cells.some((e) => e.row === n && e.col === r) || u.cells.some((e) => c[e.row][e.col] !== "hit" || t.has(
|
|
515
|
+
if (u = i === "hit" ? St(a) : null, !u || e.sunkEnemyShips.some((e) => e.id === u.id)) return null;
|
|
516
|
+
let t = new Set(e.sunkEnemyShips.flatMap((e) => e.cells.map(Qe)));
|
|
517
|
+
if (!u.cells.some((e) => e.row === n && e.col === r) || u.cells.some((e) => c[e.row][e.col] !== "hit" || t.has(Qe(e)))) return null;
|
|
508
518
|
}
|
|
509
519
|
let d = e.sunkEnemyShips.length + +!!u;
|
|
510
|
-
return l >
|
|
520
|
+
return l > ze || s !== (l === ze) || s !== (d === o.length) || !s && ze - l > 100 - Je(c) ? null : {
|
|
511
521
|
shots: c,
|
|
512
522
|
ship: u
|
|
513
523
|
};
|
|
514
524
|
}
|
|
515
|
-
function
|
|
516
|
-
let n =
|
|
525
|
+
function wt(e, t) {
|
|
526
|
+
let n = xt(dt(e), t);
|
|
517
527
|
if (!n || n.result !== t.result || n.defeated !== !!t.defeated || !!n.sunk != !!t.sunk) return null;
|
|
518
|
-
let r = n.sunk ?
|
|
519
|
-
return r && (t.sunk.ship_id !== r.id || !
|
|
528
|
+
let r = n.sunk ? St(n.sunk) : null;
|
|
529
|
+
return r && (t.sunk.ship_id !== r.id || !et(r.cells, t.sunk.cells.map(([e, t]) => ({
|
|
520
530
|
row: e,
|
|
521
531
|
col: t
|
|
522
532
|
})))) ? null : {
|
|
523
|
-
shots:
|
|
533
|
+
shots: Ke(e.incomingShots, t.row, t.col, t.result),
|
|
524
534
|
ship: r
|
|
525
535
|
};
|
|
526
536
|
}
|
|
527
|
-
function
|
|
528
|
-
let i =
|
|
537
|
+
function Tt(e, t, n, r) {
|
|
538
|
+
let i = Ze(e, t);
|
|
529
539
|
if (e[i]) return e[i] === n ? e : null;
|
|
530
540
|
let a = {
|
|
531
541
|
...e,
|
|
532
542
|
[i]: n
|
|
533
543
|
};
|
|
534
544
|
if (t === e.ownId) {
|
|
535
|
-
let t = r?.commitment === n ?
|
|
536
|
-
t &&
|
|
545
|
+
let t = r?.commitment === n ? lt(r.fleet) : null;
|
|
546
|
+
t && Be.test(r.salt ?? "") ? a = {
|
|
537
547
|
...a,
|
|
538
548
|
myFleet: t,
|
|
539
549
|
mySalt: r.salt,
|
|
@@ -543,7 +553,7 @@ function Ct(e, t, n, r) {
|
|
|
543
553
|
myFleet: [],
|
|
544
554
|
mySalt: null,
|
|
545
555
|
myCommitment: n,
|
|
546
|
-
error:
|
|
556
|
+
error: We
|
|
547
557
|
}), a.myReady = !0;
|
|
548
558
|
} else a.opponentReady = !0;
|
|
549
559
|
return a.hostCommitment && a.guestCommitment && (a = {
|
|
@@ -554,7 +564,7 @@ function Ct(e, t, n, r) {
|
|
|
554
564
|
pendingShot: null
|
|
555
565
|
}), a;
|
|
556
566
|
}
|
|
557
|
-
function
|
|
567
|
+
function Et(e, t, { row: r, col: i, ply: a }, o) {
|
|
558
568
|
let s = t === e.ownId ? e.targetShots : e.incomingShots;
|
|
559
569
|
return !n({
|
|
560
570
|
row: r,
|
|
@@ -570,8 +580,8 @@ function wt(e, t, { row: r, col: i, ply: a }, o) {
|
|
|
570
580
|
lastEventId: o ?? e.lastEventId
|
|
571
581
|
};
|
|
572
582
|
}
|
|
573
|
-
function
|
|
574
|
-
let i = e.pendingShot, a = t === e.ownId, o = a ?
|
|
583
|
+
function Dt(e, t, n, r) {
|
|
584
|
+
let i = e.pendingShot, a = t === e.ownId, o = a ? wt(e, n) : Ct(e, n);
|
|
575
585
|
if (!o) return null;
|
|
576
586
|
let s = !!n.defeated, c = {
|
|
577
587
|
ply: i.ply,
|
|
@@ -601,21 +611,21 @@ function Tt(e, t, n, r) {
|
|
|
601
611
|
verification: s ? "pending" : e.verification
|
|
602
612
|
};
|
|
603
613
|
}
|
|
604
|
-
function
|
|
614
|
+
function Ot(e, t, n) {
|
|
605
615
|
let { ply: r, row: i, col: a, prev_event_id: o } = t.data;
|
|
606
|
-
return n ===
|
|
616
|
+
return n === Ye(e, r) ? e.status === "active" ? r <= e.ply ? e : e.pendingShot ? r === e.pendingShot.ply ? e : N(e, M) : r > e.ply + 1 ? N(e, M) : n === e.turnId ? o === e.lastEventId ? Et(e, n, {
|
|
607
617
|
row: i,
|
|
608
618
|
col: a,
|
|
609
619
|
ply: r
|
|
610
|
-
}, t.event_id) ?? e :
|
|
620
|
+
}, t.event_id) ?? e : N(e, M) : e : N(e, e.status === "invited" ? He : M) : e;
|
|
611
621
|
}
|
|
612
|
-
function
|
|
622
|
+
function kt(e, t, n) {
|
|
613
623
|
let { ply: r, row: i, col: a } = t.data;
|
|
614
|
-
if (e.status !== "active") return e.status === "placement" ?
|
|
624
|
+
if (e.status !== "active") return e.status === "placement" ? N(e, M) : e;
|
|
615
625
|
let o = e.pendingShot;
|
|
616
|
-
return o ? r === o.ply ? n === o.by ? e : i !== o.row || a !== o.col ? n === e.ownId ? e :
|
|
626
|
+
return o ? r === o.ply ? n === o.by ? e : i !== o.row || a !== o.col ? n === e.ownId ? e : N(e, "El rival respondió a un disparo distinto.") : Dt(e, n, t.data, t.event_id) || (n === e.ownId ? e : N(e, Ue)) : r < o.ply ? e : N(e, M) : r <= e.ply ? e : N(e, M);
|
|
617
627
|
}
|
|
618
|
-
function
|
|
628
|
+
function At(e, t, n) {
|
|
619
629
|
return !e.winnerId || !["won", "closed"].includes(e.status) ? e : n === e.ownId ? e.myRevealSent ? e : {
|
|
620
630
|
...e,
|
|
621
631
|
myRevealSent: !0
|
|
@@ -628,7 +638,7 @@ function Ot(e, t, n) {
|
|
|
628
638
|
verification: "pending"
|
|
629
639
|
};
|
|
630
640
|
}
|
|
631
|
-
function
|
|
641
|
+
function jt(e, t, n, r = {}) {
|
|
632
642
|
if (!e || e.game !== "battleship" || t?.game !== "battleship" || t.game_id !== e.gameId || n !== e.hostId && n !== e.guestId) return e;
|
|
633
643
|
let i = t.data;
|
|
634
644
|
if (t.type === "game_end") return i.reason !== "closed" || [
|
|
@@ -641,8 +651,8 @@ function kt(e, t, n, r = {}) {
|
|
|
641
651
|
closedBy: n,
|
|
642
652
|
error: ""
|
|
643
653
|
};
|
|
644
|
-
if (t.type === "bs_reveal") return
|
|
645
|
-
if (
|
|
654
|
+
if (t.type === "bs_reveal") return At(e, i, n);
|
|
655
|
+
if (Ve.includes(e.status) || e.status === "conflict") return e;
|
|
646
656
|
switch (t.type) {
|
|
647
657
|
case "game_accept":
|
|
648
658
|
case "game_decline": return n !== e.guestId || e.status !== "invited" || i.invite_event_id !== e.inviteEventId ? e : t.type === "game_accept" ? {
|
|
@@ -655,32 +665,32 @@ function kt(e, t, n, r = {}) {
|
|
|
655
665
|
status: "declined",
|
|
656
666
|
lastEventId: t.event_id
|
|
657
667
|
};
|
|
658
|
-
case "bs_commit": return e.status === "invited" ?
|
|
659
|
-
case "bs_fire": return
|
|
660
|
-
case "bs_result": return
|
|
668
|
+
case "bs_commit": return e.status === "invited" ? N(e, He) : e.status === "placement" ? Tt(e, n, i.commitment, r.stored) ?? e : e;
|
|
669
|
+
case "bs_fire": return Ot(e, t, n);
|
|
670
|
+
case "bs_result": return kt(e, t, n);
|
|
661
671
|
default: return e;
|
|
662
672
|
}
|
|
663
673
|
}
|
|
664
|
-
function
|
|
665
|
-
let n =
|
|
674
|
+
function Mt(e, t) {
|
|
675
|
+
let n = Le({
|
|
666
676
|
gameId: String(e.gameId),
|
|
667
677
|
players: [e.hostId, e.guestId],
|
|
668
678
|
firstPlayerId: e.hostId
|
|
669
679
|
});
|
|
670
680
|
for (let e of n.players) {
|
|
671
|
-
for (let r of t[e]) n =
|
|
681
|
+
for (let r of t[e]) n = Re(n, {
|
|
672
682
|
type: "place_ship",
|
|
673
683
|
playerId: e,
|
|
674
|
-
...
|
|
684
|
+
...at(r)
|
|
675
685
|
});
|
|
676
|
-
n =
|
|
686
|
+
n = Re(n, {
|
|
677
687
|
type: "ready",
|
|
678
688
|
playerId: e
|
|
679
689
|
});
|
|
680
690
|
}
|
|
681
691
|
if (n.phase !== "playing") return !1;
|
|
682
692
|
for (let t of e.shots) {
|
|
683
|
-
let e =
|
|
693
|
+
let e = Re(n, {
|
|
684
694
|
type: "fire",
|
|
685
695
|
playerId: t.by,
|
|
686
696
|
row: t.row,
|
|
@@ -691,30 +701,30 @@ function At(e, t) {
|
|
|
691
701
|
if (r.result !== t.result || r.defeated !== t.defeated || r.sunk !== !!t.sunk) return !1;
|
|
692
702
|
if (t.sunk) {
|
|
693
703
|
let n = e.boards[e.players.indexOf(r.targetId)].ships.find((e) => e.id === r.shipId);
|
|
694
|
-
if (t.sunk.id !== r.shipId || !
|
|
704
|
+
if (t.sunk.id !== r.shipId || !et(n.cells, t.sunk.cells)) return !1;
|
|
695
705
|
}
|
|
696
706
|
n = e;
|
|
697
707
|
}
|
|
698
708
|
return !e.winnerId || n.winnerId === e.winnerId;
|
|
699
709
|
}
|
|
700
|
-
async function
|
|
710
|
+
async function Nt(e, t = e?.opponentReveal) {
|
|
701
711
|
if (!e || !t) return "pending";
|
|
702
|
-
let n =
|
|
703
|
-
if (!r || !i || typeof t.salt != "string" || !
|
|
712
|
+
let n = Xe(e, e.ownId), r = e[Ze(e, n)], i = lt(t.fleet);
|
|
713
|
+
if (!r || !i || typeof t.salt != "string" || !Be.test(t.salt)) return "mismatch";
|
|
704
714
|
let a;
|
|
705
715
|
try {
|
|
706
|
-
a = await
|
|
716
|
+
a = await bt(t.fleet, t.salt);
|
|
707
717
|
} catch {
|
|
708
718
|
return "mismatch";
|
|
709
719
|
}
|
|
710
720
|
if (a !== r) return "mismatch";
|
|
711
|
-
let o =
|
|
712
|
-
return o ?
|
|
721
|
+
let o = lt(e.myFleet);
|
|
722
|
+
return o ? Mt(e, {
|
|
713
723
|
[e.ownId]: o,
|
|
714
724
|
[n]: i
|
|
715
725
|
}) ? "ok" : "mismatch" : "pending";
|
|
716
726
|
}
|
|
717
|
-
var
|
|
727
|
+
var Pt = (e) => {
|
|
718
728
|
if (e.result === "miss") return [
|
|
719
729
|
e.row,
|
|
720
730
|
e.col,
|
|
@@ -736,13 +746,13 @@ var Mt = (e) => {
|
|
|
736
746
|
+(e.sunk.orientation === "vertical")
|
|
737
747
|
];
|
|
738
748
|
};
|
|
739
|
-
function
|
|
749
|
+
function Ft(e) {
|
|
740
750
|
if (!e.acceptEventId) return {
|
|
741
751
|
commits: [null, null],
|
|
742
752
|
log: [],
|
|
743
753
|
head: e.inviteEventId
|
|
744
754
|
};
|
|
745
|
-
let t = e.shots.map(
|
|
755
|
+
let t = e.shots.map(Pt);
|
|
746
756
|
return e.pendingShot && t.push([e.pendingShot.row, e.pendingShot.col]), {
|
|
747
757
|
accept_event_id: e.acceptEventId,
|
|
748
758
|
commits: [e.hostCommitment ?? null, e.guestCommitment ?? null],
|
|
@@ -750,7 +760,7 @@ function Nt(e) {
|
|
|
750
760
|
head: e.lastEventId
|
|
751
761
|
};
|
|
752
762
|
}
|
|
753
|
-
function
|
|
763
|
+
function It(e, t) {
|
|
754
764
|
let n = e.accept_event_id ?? null, r = t.accept_event_id ?? null;
|
|
755
765
|
if (n && r && n !== r) return "diverged";
|
|
756
766
|
let i = /* @__PURE__ */ new Set();
|
|
@@ -770,7 +780,7 @@ function Pt(e, t) {
|
|
|
770
780
|
}
|
|
771
781
|
return a.length !== o.length && i.add(a.length < o.length ? "behind" : "ahead"), i.size === 2 ? "mixed" : i.size === 1 ? [...i][0] : a.length && e.head !== t.head ? "diverged" : "equal";
|
|
772
782
|
}
|
|
773
|
-
function
|
|
783
|
+
function Lt(e, t) {
|
|
774
784
|
if ((e.log ?? []).length || (t.log ?? []).length) return null;
|
|
775
785
|
let n = e.accept_event_id ?? t.accept_event_id;
|
|
776
786
|
return n ? {
|
|
@@ -780,15 +790,15 @@ function Ft(e, t) {
|
|
|
780
790
|
head: n
|
|
781
791
|
} : null;
|
|
782
792
|
}
|
|
783
|
-
function
|
|
793
|
+
function Rt(e, t, n = {}) {
|
|
784
794
|
let r = {
|
|
785
795
|
...e,
|
|
786
796
|
status: "invited",
|
|
787
797
|
turnId: null,
|
|
788
798
|
myReady: !1,
|
|
789
799
|
opponentReady: !1,
|
|
790
|
-
incomingShots:
|
|
791
|
-
targetShots:
|
|
800
|
+
incomingShots: Ge(),
|
|
801
|
+
targetShots: Ge(),
|
|
792
802
|
sunkEnemyShips: [],
|
|
793
803
|
pendingShot: null,
|
|
794
804
|
lastShot: null,
|
|
@@ -817,11 +827,11 @@ function It(e, t, n = {}) {
|
|
|
817
827
|
acceptEventId: t.accept_event_id,
|
|
818
828
|
lastEventId: t.accept_event_id
|
|
819
829
|
};
|
|
820
|
-
for (let [t, r] of [e.hostId, e.guestId].entries()) if (a[t] && (c =
|
|
830
|
+
for (let [t, r] of [e.hostId, e.guestId].entries()) if (a[t] && (c = Tt(c, r, a[t], n.stored), !c)) return null;
|
|
821
831
|
if (i.length && c.status !== "active") return null;
|
|
822
832
|
for (let e = 0; e < i.length; e += 1) {
|
|
823
833
|
let t = i[e], n = e + 1;
|
|
824
|
-
if (c =
|
|
834
|
+
if (c = Et(c, Ye(c, n), {
|
|
825
835
|
row: t[0],
|
|
826
836
|
col: t[1],
|
|
827
837
|
ply: n
|
|
@@ -830,7 +840,7 @@ function It(e, t, n = {}) {
|
|
|
830
840
|
if (e !== i.length - 1) return null;
|
|
831
841
|
break;
|
|
832
842
|
}
|
|
833
|
-
let r =
|
|
843
|
+
let r = Xe(c, c.pendingShot.by), a = null;
|
|
834
844
|
if (t[2] === 2) {
|
|
835
845
|
let e = o[t[3]];
|
|
836
846
|
if (!e) return null;
|
|
@@ -840,14 +850,14 @@ function It(e, t, n = {}) {
|
|
|
840
850
|
cells: Array.from({ length: e.size }, (e, r) => [t[4] + (n ? r : 0), t[5] + (n ? 0 : r)])
|
|
841
851
|
};
|
|
842
852
|
}
|
|
843
|
-
let s =
|
|
844
|
-
if (c =
|
|
853
|
+
let s = qe(r === c.ownId ? c.incomingShots : c.targetShots) + (t[2] === 0 ? 0 : 1);
|
|
854
|
+
if (c = Dt(c, r, {
|
|
845
855
|
ply: n,
|
|
846
856
|
row: t[0],
|
|
847
857
|
col: t[1],
|
|
848
858
|
result: t[2] === 0 ? "miss" : "hit",
|
|
849
859
|
sunk: a,
|
|
850
|
-
defeated: s ===
|
|
860
|
+
defeated: s === ze
|
|
851
861
|
}, null), !c || c.status === "won" && e !== i.length - 1) return null;
|
|
852
862
|
}
|
|
853
863
|
return !i.length && t.head !== t.accept_event_id ? null : (c = {
|
|
@@ -860,7 +870,7 @@ function It(e, t, n = {}) {
|
|
|
860
870
|
verification: e.verification
|
|
861
871
|
}), c);
|
|
862
872
|
}
|
|
863
|
-
function
|
|
873
|
+
function zt(e, t) {
|
|
864
874
|
if (!e || !t) return !1;
|
|
865
875
|
let n = e.log?.[(t.data?.ply ?? 0) - 1];
|
|
866
876
|
switch (t.type) {
|
|
@@ -871,37 +881,37 @@ function Lt(e, t) {
|
|
|
871
881
|
default: return !1;
|
|
872
882
|
}
|
|
873
883
|
}
|
|
874
|
-
function
|
|
884
|
+
function Bt(e, t) {
|
|
875
885
|
let n = { ...e };
|
|
876
886
|
return t.acceptEventId && (n[t.acceptEventId] = !0), t.lastEventId && (n[t.lastEventId] = !0), n;
|
|
877
887
|
}
|
|
878
888
|
// src/games/battleship/net/fleetStorage.js
|
|
879
|
-
var
|
|
889
|
+
var Vt = "lira:bs:", Ht = 12096e5, Ut = (e, t) => `${Vt}${e}:${t}`, Wt = () => {
|
|
880
890
|
try {
|
|
881
891
|
return globalThis.localStorage ?? null;
|
|
882
892
|
} catch {
|
|
883
893
|
return null;
|
|
884
894
|
}
|
|
885
895
|
};
|
|
886
|
-
function
|
|
896
|
+
function Gt(e) {
|
|
887
897
|
return typeof e == "object" && !!e && Array.isArray(e.fleet) && e.fleet.length === 5 && typeof e.salt == "string" && /^[0-9a-f]{32}$/.test(e.salt) && typeof e.commitment == "string" && /^[0-9a-f]{64}$/.test(e.commitment);
|
|
888
898
|
}
|
|
889
|
-
function
|
|
899
|
+
function Kt(e) {
|
|
890
900
|
let t = Date.now();
|
|
891
901
|
for (let n = e.length - 1; n >= 0; --n) {
|
|
892
902
|
let r = e.key(n);
|
|
893
|
-
if (r?.startsWith(
|
|
903
|
+
if (r?.startsWith(Vt)) try {
|
|
894
904
|
let n = JSON.parse(e.getItem(r));
|
|
895
|
-
|
|
905
|
+
Gt(n) && t - n.savedAt < Ht || e.removeItem(r);
|
|
896
906
|
} catch {
|
|
897
907
|
e.removeItem(r);
|
|
898
908
|
}
|
|
899
909
|
}
|
|
900
910
|
}
|
|
901
|
-
function
|
|
911
|
+
function qt(e, t, { fleet: n, salt: r, commitment: i }) {
|
|
902
912
|
try {
|
|
903
|
-
let a =
|
|
904
|
-
return a ? (
|
|
913
|
+
let a = Wt();
|
|
914
|
+
return a ? (Kt(a), a.setItem(Ut(e, t), JSON.stringify({
|
|
905
915
|
fleet: n,
|
|
906
916
|
salt: r,
|
|
907
917
|
commitment: i,
|
|
@@ -911,10 +921,10 @@ function Gt(e, t, { fleet: n, salt: r, commitment: i }) {
|
|
|
911
921
|
return !1;
|
|
912
922
|
}
|
|
913
923
|
}
|
|
914
|
-
function
|
|
924
|
+
function Jt(e, t) {
|
|
915
925
|
try {
|
|
916
|
-
let n = JSON.parse(
|
|
917
|
-
return
|
|
926
|
+
let n = JSON.parse(Wt()?.getItem(Ut(e, t)) ?? "null");
|
|
927
|
+
return Gt(n) ? {
|
|
918
928
|
fleet: n.fleet,
|
|
919
929
|
salt: n.salt,
|
|
920
930
|
commitment: n.commitment
|
|
@@ -924,20 +934,20 @@ function Kt(e, t) {
|
|
|
924
934
|
}
|
|
925
935
|
}
|
|
926
936
|
// src/games/tanks/logic/constants.js
|
|
927
|
-
var
|
|
928
|
-
2 *
|
|
929
|
-
var
|
|
930
|
-
4 *
|
|
931
|
-
var
|
|
937
|
+
var P = 1e5, Yt = 160 * P, F = 2 * P, Xt = 20 * P;
|
|
938
|
+
2 * P;
|
|
939
|
+
var Zt = 1 * P;
|
|
940
|
+
4 * P, 4 * P;
|
|
941
|
+
var Qt = 18e4, $t = 25e4, en = 5e4, I = 25e3, tn = 60 * P, nn = 4 * P, L = Object.freeze({
|
|
932
942
|
move: Object.freeze([-16, 16]),
|
|
933
943
|
yaw: Object.freeze([0, 359]),
|
|
934
944
|
pitch: Object.freeze([5, 80]),
|
|
935
945
|
power: Object.freeze([0, 100])
|
|
936
|
-
}),
|
|
946
|
+
}), R = Object.freeze({
|
|
937
947
|
standard: Object.freeze({
|
|
938
948
|
id: "standard",
|
|
939
949
|
cost: 0,
|
|
940
|
-
radius: 6 *
|
|
950
|
+
radius: 6 * P,
|
|
941
951
|
maxDmg: 40,
|
|
942
952
|
depth: 15e4,
|
|
943
953
|
speedPct: 100
|
|
@@ -945,7 +955,7 @@ var Xt = 18e4, Zt = 25e4, Qt = 5e4, $t = 25e3, en = 60 * F, tn = 4 * F, nn = Obj
|
|
|
945
955
|
heavy: Object.freeze({
|
|
946
956
|
id: "heavy",
|
|
947
957
|
cost: 1,
|
|
948
|
-
radius: 8 *
|
|
958
|
+
radius: 8 * P,
|
|
949
959
|
maxDmg: 55,
|
|
950
960
|
depth: 25e4,
|
|
951
961
|
speedPct: 85
|
|
@@ -953,13 +963,13 @@ var Xt = 18e4, Zt = 25e4, Qt = 5e4, $t = 25e3, en = 60 * F, tn = 4 * F, nn = Obj
|
|
|
953
963
|
cluster: Object.freeze({
|
|
954
964
|
id: "cluster",
|
|
955
965
|
cost: 1,
|
|
956
|
-
radius: 4 *
|
|
966
|
+
radius: 4 * P,
|
|
957
967
|
maxDmg: 15,
|
|
958
968
|
depth: 8e4,
|
|
959
969
|
speedPct: 100
|
|
960
970
|
})
|
|
961
971
|
}), rn = Object.freeze({
|
|
962
|
-
radius: 4 *
|
|
972
|
+
radius: 4 * P,
|
|
963
973
|
maxDmg: 15,
|
|
964
974
|
depth: 8e4
|
|
965
975
|
}), an = Object.freeze([
|
|
@@ -1091,7 +1101,7 @@ function ln(e) {
|
|
|
1091
1101
|
function un(e) {
|
|
1092
1102
|
return ln(e + 90);
|
|
1093
1103
|
}
|
|
1094
|
-
function
|
|
1104
|
+
function z(e, t) {
|
|
1095
1105
|
return Math.trunc(e * t / cn);
|
|
1096
1106
|
}
|
|
1097
1107
|
// src/games/tanks/logic/rng.js
|
|
@@ -1104,25 +1114,25 @@ function fn(e) {
|
|
|
1104
1114
|
return e = Math.imul(e ^ e >>> 15, e | 1), e ^= e + Math.imul(e ^ e >>> 7, e | 61), (e ^ e >>> 14) >>> 0;
|
|
1105
1115
|
};
|
|
1106
1116
|
}
|
|
1107
|
-
function
|
|
1117
|
+
function B(e, t, n) {
|
|
1108
1118
|
return t + e() % (n - t + 1);
|
|
1109
1119
|
}
|
|
1110
1120
|
function pn(e, t) {
|
|
1111
1121
|
let n = fn((e ^ Math.imul(t, 2654435761)) >>> 0);
|
|
1112
1122
|
return {
|
|
1113
|
-
x:
|
|
1114
|
-
z:
|
|
1123
|
+
x: B(n, -40, 40),
|
|
1124
|
+
z: B(n, -40, 40)
|
|
1115
1125
|
};
|
|
1116
1126
|
}
|
|
1117
1127
|
// src/games/tanks/logic/terrain.js
|
|
1118
|
-
var
|
|
1119
|
-
function
|
|
1120
|
-
let r =
|
|
1121
|
-
return
|
|
1128
|
+
var V = (e, t, n) => e < t ? t : e > n ? n : e, H = (e, t, n, r) => e + Math.trunc((t - e) * n / r);
|
|
1129
|
+
function U(e, t, n) {
|
|
1130
|
+
let r = V(t, 0, Yt), i = V(n, 0, Yt), a = Math.min(Math.trunc(r / F), 79), o = Math.min(Math.trunc(i / F), 79), s = r - a * F, c = i - o * F, l = o * 81;
|
|
1131
|
+
return H(H(e[l + a], e[l + a + 1], s, F), H(e[l + 81 + a], e[l + 81 + a + 1], s, F), c, F);
|
|
1122
1132
|
}
|
|
1123
1133
|
function mn(e, t, n, r) {
|
|
1124
1134
|
let i = Math.trunc(80 / t) + 1, a = [];
|
|
1125
|
-
for (let t = 0; t < i * i; t += 1) a.push(
|
|
1135
|
+
for (let t = 0; t < i * i; t += 1) a.push(B(e, n, r) * 1e3);
|
|
1126
1136
|
return {
|
|
1127
1137
|
n: i,
|
|
1128
1138
|
step: t,
|
|
@@ -1131,21 +1141,21 @@ function mn(e, t, n, r) {
|
|
|
1131
1141
|
}
|
|
1132
1142
|
function hn({ n: e, step: t, values: n }, r, i) {
|
|
1133
1143
|
let a = Math.min(Math.trunc(r / t), e - 2), o = Math.min(Math.trunc(i / t), e - 2), s = r - a * t, c = i - o * t, l = (t, r) => n[r * e + t];
|
|
1134
|
-
return
|
|
1144
|
+
return H(H(l(a, o), l(a + 1, o), s, t), H(l(a, o + 1), l(a + 1, o + 1), s, t), c, t);
|
|
1135
1145
|
}
|
|
1136
1146
|
function gn(e) {
|
|
1137
1147
|
let t = new Int32Array(e.length);
|
|
1138
1148
|
for (let n = 0; n < 81; n += 1) for (let r = 0; r < 81; r += 1) {
|
|
1139
1149
|
let i = 0;
|
|
1140
|
-
for (let t = -1; t <= 1; t += 1) for (let a = -1; a <= 1; a += 1) i += e[
|
|
1150
|
+
for (let t = -1; t <= 1; t += 1) for (let a = -1; a <= 1; a += 1) i += e[V(n + t, 0, 80) * 81 + V(r + a, 0, 80)];
|
|
1141
1151
|
t[n * 81 + r] = Math.trunc(i / 9);
|
|
1142
1152
|
}
|
|
1143
1153
|
return t;
|
|
1144
1154
|
}
|
|
1145
1155
|
function _n(e, t, n, r, i) {
|
|
1146
|
-
let a =
|
|
1156
|
+
let a = U(e, t, n), o = r * r, s = i * i;
|
|
1147
1157
|
for (let r = 0; r < 81; r += 1) for (let c = 0; c < 81; c += 1) {
|
|
1148
|
-
let l = c *
|
|
1158
|
+
let l = c * F - t, u = r * F - n;
|
|
1149
1159
|
if (l > i || l < -i || u > i || u < -i) continue;
|
|
1150
1160
|
let d = l * l + u * u;
|
|
1151
1161
|
if (d >= s) continue;
|
|
@@ -1157,30 +1167,30 @@ function _n(e, t, n, r, i) {
|
|
|
1157
1167
|
}
|
|
1158
1168
|
}
|
|
1159
1169
|
}
|
|
1160
|
-
var
|
|
1170
|
+
var W = (e, t, n) => B(e, t, n) * (P / 2), vn = (e, t, n, r, i) => {
|
|
1161
1171
|
let a = e - n, o = t - r;
|
|
1162
1172
|
return a > i || a < -i || o > i || o < -i ? !1 : a * a + o * o < i * i;
|
|
1163
1173
|
}, yn = (e, t, n, r) => t >= e.x - e.w / 2 - r && t <= e.x + e.w / 2 + r && n >= e.z - e.d / 2 - r && n <= e.z + e.d / 2 + r;
|
|
1164
1174
|
function bn(e) {
|
|
1165
1175
|
let t = fn(e), n = mn(t, 20, 0, 1200), r = mn(t, 10, -250, 250), i = mn(t, 4, -60, 60), a = /* @__PURE__ */ new Int32Array(6561);
|
|
1166
1176
|
for (let e = 0; e < 81; e += 1) for (let t = 0; t < 81; t += 1) {
|
|
1167
|
-
let o = 3 *
|
|
1168
|
-
a[e * 81 + t] =
|
|
1177
|
+
let o = 3 * P + hn(n, t, e) + hn(r, t, e) + hn(i, t, e);
|
|
1178
|
+
a[e * 81 + t] = V(o, 0, Xt);
|
|
1169
1179
|
}
|
|
1170
1180
|
a = gn(gn(a));
|
|
1171
1181
|
let o = [{
|
|
1172
|
-
x: 20 *
|
|
1173
|
-
z: 80 *
|
|
1182
|
+
x: 20 * P + W(t, -4, 4),
|
|
1183
|
+
z: 80 * P + W(t, -40, 40)
|
|
1174
1184
|
}, {
|
|
1175
|
-
x: 140 *
|
|
1176
|
-
z: 80 *
|
|
1185
|
+
x: 140 * P + W(t, -4, 4),
|
|
1186
|
+
z: 80 * P + W(t, -40, 40)
|
|
1177
1187
|
}];
|
|
1178
|
-
for (let e of o) _n(a, e.x, e.z,
|
|
1179
|
-
let s = [], c =
|
|
1188
|
+
for (let e of o) _n(a, e.x, e.z, nn, nn + 3 * P);
|
|
1189
|
+
let s = [], c = B(t, 4, 6);
|
|
1180
1190
|
for (let e = 0; e < 200 && s.length < c; e += 1) {
|
|
1181
|
-
let e = t() % 2 == 0 ? "rock" : "wall", n =
|
|
1182
|
-
e === "wall" && (n >= r ? r = 2 *
|
|
1183
|
-
let i =
|
|
1191
|
+
let e = t() % 2 == 0 ? "rock" : "wall", n = W(t, 4, 12), r = W(t, 4, 12);
|
|
1192
|
+
e === "wall" && (n >= r ? r = 2 * P : n = 2 * P);
|
|
1193
|
+
let i = W(t, 4, 10), c = W(t, 100, 220), l = W(t, 40, 280), u = 12 * P + (n > r ? n : r);
|
|
1184
1194
|
if (o.some((e) => vn(e.x, e.z, c, l, u))) continue;
|
|
1185
1195
|
let d = {
|
|
1186
1196
|
x: c,
|
|
@@ -1194,7 +1204,7 @@ function bn(e) {
|
|
|
1194
1204
|
[1, -1],
|
|
1195
1205
|
[-1, 1],
|
|
1196
1206
|
[1, 1]
|
|
1197
|
-
].map(([e, t]) =>
|
|
1207
|
+
].map(([e, t]) => U(a, c + e * n / 2, l + t * r / 2)), p = Math.min(U(a, c, l), ...f);
|
|
1198
1208
|
s.push({
|
|
1199
1209
|
id: s.length,
|
|
1200
1210
|
kind: e,
|
|
@@ -1203,9 +1213,9 @@ function bn(e) {
|
|
|
1203
1213
|
y: p
|
|
1204
1214
|
});
|
|
1205
1215
|
}
|
|
1206
|
-
let l = [], u =
|
|
1216
|
+
let l = [], u = B(t, 30, 60);
|
|
1207
1217
|
for (let e = 0; e < u * 10 && l.length < u; e += 1) {
|
|
1208
|
-
let e =
|
|
1218
|
+
let e = W(t, 4, 316), n = W(t, 4, 316), r = t() % 3 == 0 ? "rock" : "tree", i = B(t, 80, 140);
|
|
1209
1219
|
o.some((t) => vn(t.x, t.z, e, n, 1e6)) || s.some((t) => yn(t, e, n, 2e5)) || l.push({
|
|
1210
1220
|
id: l.length,
|
|
1211
1221
|
kind: r,
|
|
@@ -1222,9 +1232,9 @@ function bn(e) {
|
|
|
1222
1232
|
};
|
|
1223
1233
|
}
|
|
1224
1234
|
function xn(e, { x: t, z: n, radius: r, depth: i }) {
|
|
1225
|
-
let a = r * r, o = (e) =>
|
|
1235
|
+
let a = r * r, o = (e) => V(Math.trunc(e / F) - 1, 0, 80);
|
|
1226
1236
|
for (let s = o(n - r); s <= o(n + r) + 2 && s < 81; s += 1) for (let c = o(t - r); c <= o(t + r) + 2 && c < 81; c += 1) {
|
|
1227
|
-
let o = c *
|
|
1237
|
+
let o = c * F - t, l = s * F - n;
|
|
1228
1238
|
if (o > r || o < -r || l > r || l < -r) continue;
|
|
1229
1239
|
let u = o * o + l * l;
|
|
1230
1240
|
if (u >= a) continue;
|
|
@@ -1238,17 +1248,17 @@ function Sn(e, t) {
|
|
|
1238
1248
|
}
|
|
1239
1249
|
// src/games/tanks/logic/ballistics.js
|
|
1240
1250
|
function Cn(e, t) {
|
|
1241
|
-
return Math.trunc((2e4 + 600 * e) *
|
|
1251
|
+
return Math.trunc((2e4 + 600 * e) * R[t].speedPct / 100);
|
|
1242
1252
|
}
|
|
1243
1253
|
function wn(e, { yaw: t, pitch: n, power: r, ammo: i }) {
|
|
1244
|
-
let a = un(n), o = ln(n), s = un(t), c = ln(t), l =
|
|
1254
|
+
let a = un(n), o = ln(n), s = un(t), c = ln(t), l = z($t, a), u = Cn(r, i), d = z(u, a);
|
|
1245
1255
|
return {
|
|
1246
|
-
x: e.x +
|
|
1247
|
-
y: e.y +
|
|
1248
|
-
z: e.z +
|
|
1249
|
-
vx:
|
|
1250
|
-
vy:
|
|
1251
|
-
vz:
|
|
1256
|
+
x: e.x + z(l, s),
|
|
1257
|
+
y: e.y + Qt + z($t, o),
|
|
1258
|
+
z: e.z + z(l, c),
|
|
1259
|
+
vx: z(d, s),
|
|
1260
|
+
vy: z(u, o),
|
|
1261
|
+
vz: z(d, c)
|
|
1252
1262
|
};
|
|
1253
1263
|
}
|
|
1254
1264
|
function Tn(e, t, n, r, i, a, o) {
|
|
@@ -1291,7 +1301,7 @@ function En(e, { wind: t, heights: n, tanks: r, obstacles: i, maxTicks: a = 600,
|
|
|
1291
1301
|
z: l,
|
|
1292
1302
|
kind: "out"
|
|
1293
1303
|
}), !m) {
|
|
1294
|
-
let e =
|
|
1304
|
+
let e = U(n, s, l);
|
|
1295
1305
|
c <= e && (m = {
|
|
1296
1306
|
x: s,
|
|
1297
1307
|
y: e,
|
|
@@ -1344,7 +1354,7 @@ var Dn = (e, t, n, r) => ({
|
|
|
1344
1354
|
});
|
|
1345
1355
|
function On(e, t, n) {
|
|
1346
1356
|
let r = wn(e, t);
|
|
1347
|
-
if (t.ammo !== "cluster") return [Dn("main", 0, En(r, n),
|
|
1357
|
+
if (t.ammo !== "cluster") return [Dn("main", 0, En(r, n), R[t.ammo])];
|
|
1348
1358
|
let i = En(r, {
|
|
1349
1359
|
...n,
|
|
1350
1360
|
split: !0
|
|
@@ -1375,7 +1385,7 @@ function kn(e, t) {
|
|
|
1375
1385
|
if (e.kind === "out" || e.kind === "split") continue;
|
|
1376
1386
|
let o = i * i;
|
|
1377
1387
|
t.forEach((t, r) => {
|
|
1378
|
-
let s = t.y +
|
|
1388
|
+
let s = t.y + Zt;
|
|
1379
1389
|
e.kind === "tank" && e.tankId === t.id && (n[r] += 25);
|
|
1380
1390
|
let c = e.x - t.x, l = e.y - s, u = e.z - t.z;
|
|
1381
1391
|
if (c >= i || c <= -i || l >= i || l <= -i || u >= i || u <= -i) return;
|
|
@@ -1395,7 +1405,7 @@ function An(e) {
|
|
|
1395
1405
|
}
|
|
1396
1406
|
// src/games/tanks/logic/movement.js
|
|
1397
1407
|
function jn(e, t, { heights: n, obstacles: r, others: i }) {
|
|
1398
|
-
let a = t < 0 ? -1 : 1, o = (t < 0 ? -t : t) * (
|
|
1408
|
+
let a = t < 0 ? -1 : 1, o = (t < 0 ? -t : t) * (en / I), s = Math.min(o, Math.trunc(e.fuel / I)), c = a * z(I, un(e.hullYaw)), l = a * z(I, ln(e.hullYaw)), { x: u, z: d } = e, f = U(n, u, d), p = [{
|
|
1399
1409
|
x: u,
|
|
1400
1410
|
y: f,
|
|
1401
1411
|
z: d
|
|
@@ -1417,7 +1427,7 @@ function jn(e, t, { heights: n, obstacles: r, others: i }) {
|
|
|
1417
1427
|
h = "tank";
|
|
1418
1428
|
break;
|
|
1419
1429
|
}
|
|
1420
|
-
let a =
|
|
1430
|
+
let a = U(n, e, t);
|
|
1421
1431
|
if ((a > f ? a - f : f - a) * 1e3 > 175e5) {
|
|
1422
1432
|
h = "slope";
|
|
1423
1433
|
break;
|
|
@@ -1437,12 +1447,12 @@ function jn(e, t, { heights: n, obstacles: r, others: i }) {
|
|
|
1437
1447
|
x: u,
|
|
1438
1448
|
y: f,
|
|
1439
1449
|
z: d,
|
|
1440
|
-
used: m *
|
|
1450
|
+
used: m * I,
|
|
1441
1451
|
stop: h
|
|
1442
1452
|
};
|
|
1443
1453
|
}
|
|
1444
1454
|
// src/games/tanks/logic/game.js
|
|
1445
|
-
var Mn = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e,
|
|
1455
|
+
var Mn = (e) => typeof e == "string" && e.length > 0 && e.length <= 256 && e.trim() === e, G = (e) => ({
|
|
1446
1456
|
ok: !1,
|
|
1447
1457
|
reason: e
|
|
1448
1458
|
}), Nn = (e, [t, n]) => Number.isInteger(e) && e >= t && e <= n;
|
|
@@ -1452,13 +1462,13 @@ function Pn({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {})
|
|
|
1452
1462
|
let { heights: i, spawns: a, obstacles: o, decor: s } = bn(r), c = t.map((e, t) => ({
|
|
1453
1463
|
id: e,
|
|
1454
1464
|
x: a[t].x,
|
|
1455
|
-
y:
|
|
1465
|
+
y: U(i, a[t].x, a[t].z),
|
|
1456
1466
|
z: a[t].z,
|
|
1457
1467
|
hullYaw: t === 0 ? 0 : 180,
|
|
1458
1468
|
yaw: t === 0 ? 0 : 180,
|
|
1459
1469
|
pitch: 30,
|
|
1460
1470
|
hp: 100,
|
|
1461
|
-
fuel:
|
|
1471
|
+
fuel: tn,
|
|
1462
1472
|
ammo: { ...on },
|
|
1463
1473
|
skips: 0
|
|
1464
1474
|
}));
|
|
@@ -1486,20 +1496,20 @@ function Pn({ gameId: e, players: t, firstPlayerId: n = t?.[0], seed: r } = {})
|
|
|
1486
1496
|
};
|
|
1487
1497
|
}
|
|
1488
1498
|
function Fn(e, t) {
|
|
1489
|
-
return !e || !t || typeof t != "object" ?
|
|
1499
|
+
return !e || !t || typeof t != "object" ? G("invalid_action") : e.phase === "finished" ? G("game_finished") : t.gameId !== void 0 && t.gameId !== e.gameId ? G("wrong_game") : t.expectedRevision !== void 0 && t.expectedRevision !== e.revision ? G("stale_revision") : e.players.includes(t.playerId) ? { ok: !0 } : G("unknown_player");
|
|
1490
1500
|
}
|
|
1491
1501
|
function In(e, t) {
|
|
1492
1502
|
let n = Fn(e, t);
|
|
1493
1503
|
if (!n.ok) return n;
|
|
1494
1504
|
let r = e.players.indexOf(t.playerId);
|
|
1495
|
-
if (r !== e.turnIndex) return
|
|
1496
|
-
if (!Nn(t.move,
|
|
1497
|
-
if (!Nn(t.yaw,
|
|
1498
|
-
if (!Nn(t.pitch,
|
|
1499
|
-
if (!Nn(t.power,
|
|
1500
|
-
if (typeof t.ammo != "string" || !Object.hasOwn(
|
|
1501
|
-
let i =
|
|
1502
|
-
return i > 0 && e.tanks[r].ammo[t.ammo] < i ?
|
|
1505
|
+
if (r !== e.turnIndex) return G("not_your_turn");
|
|
1506
|
+
if (!Nn(t.move, L.move)) return G("invalid_move");
|
|
1507
|
+
if (!Nn(t.yaw, L.yaw)) return G("invalid_yaw");
|
|
1508
|
+
if (!Nn(t.pitch, L.pitch)) return G("invalid_pitch");
|
|
1509
|
+
if (!Nn(t.power, L.power)) return G("invalid_power");
|
|
1510
|
+
if (typeof t.ammo != "string" || !Object.hasOwn(R, t.ammo)) return G("unknown_ammo");
|
|
1511
|
+
let i = R[t.ammo].cost;
|
|
1512
|
+
return i > 0 && e.tanks[r].ammo[t.ammo] < i ? G("out_of_ammo") : { ok: !0 };
|
|
1503
1513
|
}
|
|
1504
1514
|
function Ln(e, t, { maxTicks: n = 600 } = {}) {
|
|
1505
1515
|
let r = e.players.indexOf(t.playerId), i = e.tanks[r], a = e.tanks[1 - r], o = pn(e.seed, e.ply), s = jn(i, t.move ?? 0, {
|
|
@@ -1569,12 +1579,12 @@ function zn(e, t) {
|
|
|
1569
1579
|
ammo: { ...e.ammo },
|
|
1570
1580
|
x: o.x,
|
|
1571
1581
|
z: o.z,
|
|
1572
|
-
y:
|
|
1582
|
+
y: U(a, o.x, o.z),
|
|
1573
1583
|
hp: Math.max(0, e.hp - i.damage[e.id])
|
|
1574
1584
|
};
|
|
1575
1585
|
if (t === n) {
|
|
1576
1586
|
s.fuel = e.fuel - i.fuelUsed, s.yaw = r.yaw, s.pitch = r.pitch, s.skips = 0;
|
|
1577
|
-
let t =
|
|
1587
|
+
let t = R[r.ammo].cost;
|
|
1578
1588
|
t > 0 && (s.ammo[r.ammo] -= t);
|
|
1579
1589
|
}
|
|
1580
1590
|
return s;
|
|
@@ -1727,7 +1737,7 @@ var Wn = new Uint32Array([
|
|
|
1727
1737
|
2756734187,
|
|
1728
1738
|
3204031479,
|
|
1729
1739
|
3329325298
|
|
1730
|
-
]),
|
|
1740
|
+
]), K = (e, t) => e >>> t | e << 32 - t;
|
|
1731
1741
|
function Gn(e) {
|
|
1732
1742
|
let t = new TextEncoder().encode(String(e)), n = t.length, r = new Uint8Array((n + 9 >> 6) + 1 << 6);
|
|
1733
1743
|
r.set(t), r[n] = 128;
|
|
@@ -1746,12 +1756,12 @@ function Gn(e) {
|
|
|
1746
1756
|
for (let e = 0; e < r.length; e += 64) {
|
|
1747
1757
|
for (let t = 0; t < 16; t += 1) o[t] = i.getUint32(e + t * 4);
|
|
1748
1758
|
for (let e = 16; e < 64; e += 1) {
|
|
1749
|
-
let t =
|
|
1759
|
+
let t = K(o[e - 15], 7) ^ K(o[e - 15], 18) ^ o[e - 15] >>> 3, n = K(o[e - 2], 17) ^ K(o[e - 2], 19) ^ o[e - 2] >>> 10;
|
|
1750
1760
|
o[e] = o[e - 16] + t + o[e - 7] + n >>> 0;
|
|
1751
1761
|
}
|
|
1752
1762
|
let [t, n, r, s, c, l, u, d] = a;
|
|
1753
1763
|
for (let e = 0; e < 64; e += 1) {
|
|
1754
|
-
let i = d + (
|
|
1764
|
+
let i = d + (K(c, 6) ^ K(c, 11) ^ K(c, 25)) + (c & l ^ ~c & u) + Wn[e] + o[e] >>> 0, a = (K(t, 2) ^ K(t, 13) ^ K(t, 22)) + (t & n ^ t & r ^ n & r) >>> 0;
|
|
1755
1765
|
d = u, u = l, l = c, c = s + i >>> 0, s = r, r = n, n = t, t = i + a >>> 0;
|
|
1756
1766
|
}
|
|
1757
1767
|
a[0] += t, a[1] += n, a[2] += r, a[3] += s, a[4] += c, a[5] += l, a[6] += u, a[7] += d;
|
|
@@ -1764,17 +1774,17 @@ var Kn = "La partida perdió sincronización. Se intentará resincronizar.", qn
|
|
|
1764
1774
|
"draw",
|
|
1765
1775
|
"closed",
|
|
1766
1776
|
"declined"
|
|
1767
|
-
],
|
|
1777
|
+
], Zn = (e, t) => ({
|
|
1768
1778
|
...e,
|
|
1769
1779
|
status: "conflict",
|
|
1770
1780
|
error: t
|
|
1771
|
-
}),
|
|
1772
|
-
function
|
|
1781
|
+
}), Qn = (e) => Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
1782
|
+
function $n() {
|
|
1773
1783
|
let e = /* @__PURE__ */ new Uint8Array(16);
|
|
1774
|
-
return globalThis.crypto.getRandomValues(e),
|
|
1784
|
+
return globalThis.crypto.getRandomValues(e), Qn(e);
|
|
1775
1785
|
}
|
|
1776
|
-
var
|
|
1777
|
-
function
|
|
1786
|
+
var er = (e) => Gn(`lira-tanks-seed:${e}`), tr = (e, t) => parseInt(Gn(`lira-tanks-map:${e}:${t}`).slice(0, 8), 16) >>> 0;
|
|
1787
|
+
function nr(e, t) {
|
|
1778
1788
|
let n = t.first_player_id === e.guestId ? e.guestId : e.hostId;
|
|
1779
1789
|
return {
|
|
1780
1790
|
...e,
|
|
@@ -1801,21 +1811,21 @@ function tr(e, t) {
|
|
|
1801
1811
|
sync: e.sync ?? null
|
|
1802
1812
|
};
|
|
1803
1813
|
}
|
|
1804
|
-
var q = (e) => [e.hostId, e.guestId],
|
|
1814
|
+
var q = (e) => [e.hostId, e.guestId], rr = (e) => e.logic && e.logic.phase === "playing" ? q(e)[e.logic.turnIndex] : null, ir = (e) => e?.status === "active" && !e.pendingEvent && rr(e) === e.ownId, ar = (e, t, n) => e === "tk_turn" ? [
|
|
1805
1815
|
1,
|
|
1806
1816
|
t.move,
|
|
1807
1817
|
t.yaw,
|
|
1808
1818
|
t.pitch,
|
|
1809
1819
|
t.power,
|
|
1810
1820
|
t.ammo
|
|
1811
|
-
] : e === "tk_skip" ? [2] : [3, n],
|
|
1812
|
-
function
|
|
1821
|
+
] : e === "tk_skip" ? [2] : [3, n], or = (e, t) => e.length === t.length && e.every((e, n) => e === t[n]);
|
|
1822
|
+
function sr(e, t) {
|
|
1813
1823
|
let n = q(e);
|
|
1814
1824
|
if (t[0] === 3) return {
|
|
1815
1825
|
type: "resign",
|
|
1816
1826
|
playerId: n[t[1]]
|
|
1817
1827
|
};
|
|
1818
|
-
let r =
|
|
1828
|
+
let r = rr(e);
|
|
1819
1829
|
return t[0] === 2 ? {
|
|
1820
1830
|
type: "skip",
|
|
1821
1831
|
playerId: r,
|
|
@@ -1827,11 +1837,11 @@ function or(e, t) {
|
|
|
1827
1837
|
yaw: t[2],
|
|
1828
1838
|
pitch: t[3],
|
|
1829
1839
|
power: t[4],
|
|
1830
|
-
ammo:
|
|
1840
|
+
ammo: E[t[5]]
|
|
1831
1841
|
};
|
|
1832
1842
|
}
|
|
1833
|
-
function
|
|
1834
|
-
let i = Bn(e.logic,
|
|
1843
|
+
function cr(e, t, n, r) {
|
|
1844
|
+
let i = Bn(e.logic, sr(e, t));
|
|
1835
1845
|
if (i === e.logic) return null;
|
|
1836
1846
|
let a = i.phase === "finished";
|
|
1837
1847
|
return {
|
|
@@ -1852,13 +1862,13 @@ function sr(e, t, n, r) {
|
|
|
1852
1862
|
result: i.result ?? null
|
|
1853
1863
|
};
|
|
1854
1864
|
}
|
|
1855
|
-
function
|
|
1856
|
-
if (
|
|
1865
|
+
function lr(e, t, n) {
|
|
1866
|
+
if (er(t) !== e.seedCommit) return null;
|
|
1857
1867
|
let r = Pn({
|
|
1858
1868
|
gameId: e.gameId,
|
|
1859
1869
|
players: q(e),
|
|
1860
1870
|
firstPlayerId: e.firstPlayerId,
|
|
1861
|
-
seed:
|
|
1871
|
+
seed: tr(t, e.seedB)
|
|
1862
1872
|
});
|
|
1863
1873
|
return {
|
|
1864
1874
|
...e,
|
|
@@ -1874,7 +1884,7 @@ function cr(e, t, n) {
|
|
|
1874
1884
|
error: ""
|
|
1875
1885
|
};
|
|
1876
1886
|
}
|
|
1877
|
-
function
|
|
1887
|
+
function ur(e, t, n) {
|
|
1878
1888
|
if (![e.hostId, e.guestId].includes(n)) return e;
|
|
1879
1889
|
let r = t.data;
|
|
1880
1890
|
if (t.type === "game_end") return ["closed", "declined"].includes(e.status) ? e : {
|
|
@@ -1895,22 +1905,22 @@ function lr(e, t, n) {
|
|
|
1895
1905
|
acceptEventId: t.event_id,
|
|
1896
1906
|
lastEventId: t.event_id
|
|
1897
1907
|
};
|
|
1898
|
-
if (t.type === "tk_seed") return n !== e.hostId || e.status !== "seeding" ? e :
|
|
1908
|
+
if (t.type === "tk_seed") return n !== e.hostId || e.status !== "seeding" ? e : lr(e, r.seed_a, t.event_id) ?? Zn(e, Jn);
|
|
1899
1909
|
if (![
|
|
1900
1910
|
"tk_turn",
|
|
1901
1911
|
"tk_skip",
|
|
1902
1912
|
"tk_resign"
|
|
1903
1913
|
].includes(t.type)) return e;
|
|
1904
|
-
if (e.status !== "active") return
|
|
1905
|
-
let i = q(e).indexOf(n), a =
|
|
1906
|
-
if (r.ply <= e.ply) return
|
|
1907
|
-
if (r.ply > e.ply + 1 || r.prev_event_id !== e.lastEventId) return
|
|
1908
|
-
if (t.type !== "tk_resign" && n !==
|
|
1909
|
-
let o =
|
|
1910
|
-
return o ? t.type === "tk_turn" && Un(o.logic) !== r.hash ?
|
|
1911
|
-
}
|
|
1912
|
-
function
|
|
1913
|
-
if (!
|
|
1914
|
+
if (e.status !== "active") return Zn(e, qn);
|
|
1915
|
+
let i = q(e).indexOf(n), a = ar(t.type, r, i);
|
|
1916
|
+
if (r.ply <= e.ply) return or(e.log[r.ply - 1] ?? [], a) ? e : Zn(e, Kn);
|
|
1917
|
+
if (r.ply > e.ply + 1 || r.prev_event_id !== e.lastEventId) return Zn(e, Kn);
|
|
1918
|
+
if (t.type !== "tk_resign" && n !== rr(e)) return e;
|
|
1919
|
+
let o = cr(e, a, t.event_id, n);
|
|
1920
|
+
return o ? t.type === "tk_turn" && Un(o.logic) !== r.hash ? Zn(e, Yn) : o : e;
|
|
1921
|
+
}
|
|
1922
|
+
function dr(e, t) {
|
|
1923
|
+
if (!ir(e)) return null;
|
|
1914
1924
|
let n = {
|
|
1915
1925
|
ply: e.ply + 1,
|
|
1916
1926
|
prev_event_id: e.lastEventId,
|
|
@@ -1918,16 +1928,16 @@ function ur(e, t) {
|
|
|
1918
1928
|
yaw: t.yaw,
|
|
1919
1929
|
pitch: t.pitch,
|
|
1920
1930
|
power: t.power,
|
|
1921
|
-
ammo:
|
|
1931
|
+
ammo: E.indexOf(t.ammo)
|
|
1922
1932
|
};
|
|
1923
1933
|
if (n.ammo < 0) return null;
|
|
1924
|
-
let r =
|
|
1934
|
+
let r = cr(e, ar("tk_turn", n), "local", e.ownId);
|
|
1925
1935
|
return r ? {
|
|
1926
1936
|
...n,
|
|
1927
1937
|
hash: Un(r.logic)
|
|
1928
1938
|
} : null;
|
|
1929
1939
|
}
|
|
1930
|
-
function
|
|
1940
|
+
function fr(e) {
|
|
1931
1941
|
let t = {
|
|
1932
1942
|
log: e.log ?? [],
|
|
1933
1943
|
head: e.lastEventId
|
|
@@ -1940,14 +1950,14 @@ function dr(e) {
|
|
|
1940
1950
|
seed_event_id: e.seedEventId
|
|
1941
1951
|
}), t;
|
|
1942
1952
|
}
|
|
1943
|
-
function
|
|
1953
|
+
function pr(e, t) {
|
|
1944
1954
|
if (e.accept_event_id && t.accept_event_id && e.accept_event_id !== t.accept_event_id || e.seed_a && t.seed_a && e.seed_a !== t.seed_a) return "diverged";
|
|
1945
1955
|
let n = Math.min(e.log.length, t.log.length);
|
|
1946
|
-
for (let r = 0; r < n; r += 1) if (!
|
|
1956
|
+
for (let r = 0; r < n; r += 1) if (!or(e.log[r], t.log[r])) return "diverged";
|
|
1947
1957
|
let r = (e) => (e.seed_a ? 2 : +!!e.accept_event_id) * 1e3 + e.log.length;
|
|
1948
1958
|
return r(e) === r(t) ? e.log.length === t.log.length && e.head !== t.head && e.log.length > 0 ? "diverged" : "equal" : r(e) < r(t) ? "behind" : "ahead";
|
|
1949
1959
|
}
|
|
1950
|
-
function
|
|
1960
|
+
function mr(e, t) {
|
|
1951
1961
|
let n = {
|
|
1952
1962
|
...e,
|
|
1953
1963
|
status: "invited",
|
|
@@ -1977,16 +1987,16 @@ function pr(e, t) {
|
|
|
1977
1987
|
seedB: t.seed_b,
|
|
1978
1988
|
lastEventId: t.accept_event_id
|
|
1979
1989
|
}, !t.seed_a) return n;
|
|
1980
|
-
if (n =
|
|
1990
|
+
if (n = lr(n, t.seed_a, t.seed_event_id), !n) return null;
|
|
1981
1991
|
for (let e = 0; e < t.log.length; e += 1) {
|
|
1982
1992
|
let r = t.log[e];
|
|
1983
|
-
if (!
|
|
1984
|
-
let i = e === t.log.length - 1, a = r[0] === 3 ? q(n)[r[1]] :
|
|
1985
|
-
if (n =
|
|
1993
|
+
if (!se(r)) return null;
|
|
1994
|
+
let i = e === t.log.length - 1, a = r[0] === 3 ? q(n)[r[1]] : rr(n);
|
|
1995
|
+
if (n = cr(n, r, i ? t.head : `${t.seed_event_id}:${e + 1}`, a), !n) return null;
|
|
1986
1996
|
}
|
|
1987
1997
|
return n;
|
|
1988
1998
|
}
|
|
1989
|
-
function
|
|
1999
|
+
function hr(e, t) {
|
|
1990
2000
|
if (!t) return !1;
|
|
1991
2001
|
if (t.type === "tk_seed") return e.seed_a === t.data.seed_a;
|
|
1992
2002
|
if (t.type === "game_accept") return e.accept_event_id === t.event_id;
|
|
@@ -1996,9 +2006,9 @@ function mr(e, t) {
|
|
|
1996
2006
|
"tk_resign"
|
|
1997
2007
|
].includes(t.type)) return !1;
|
|
1998
2008
|
let n = e.log[t.data.ply - 1];
|
|
1999
|
-
return !!n && n[0] ===
|
|
2009
|
+
return !!n && n[0] === ar(t.type, t.data, 0)[0];
|
|
2000
2010
|
}
|
|
2001
|
-
function
|
|
2011
|
+
function gr(e, t) {
|
|
2002
2012
|
let n = { ...e };
|
|
2003
2013
|
return [
|
|
2004
2014
|
t.acceptEventId,
|
|
@@ -2008,7 +2018,7 @@ function hr(e, t) {
|
|
|
2008
2018
|
e && (n[e] = !0);
|
|
2009
2019
|
}), n;
|
|
2010
2020
|
}
|
|
2011
|
-
function
|
|
2021
|
+
function _r(e) {
|
|
2012
2022
|
return {
|
|
2013
2023
|
gameId: e.gameId,
|
|
2014
2024
|
roomId: e.roomId,
|
|
@@ -2021,22 +2031,22 @@ function gr(e) {
|
|
|
2021
2031
|
inviteEventId: e.inviteEventId,
|
|
2022
2032
|
createdAt: e.createdAt,
|
|
2023
2033
|
status: e.status,
|
|
2024
|
-
...
|
|
2034
|
+
...fr(e)
|
|
2025
2035
|
};
|
|
2026
2036
|
}
|
|
2027
2037
|
// src/games/tanks/net/tankStorage.js
|
|
2028
|
-
var
|
|
2038
|
+
var vr = "lira:tk:", yr = 6048e5, br = 20, xr = (e, t) => `${vr}${e}:${t}`, Sr = () => {
|
|
2029
2039
|
try {
|
|
2030
2040
|
return globalThis.localStorage ?? null;
|
|
2031
2041
|
} catch {
|
|
2032
2042
|
return null;
|
|
2033
2043
|
}
|
|
2034
2044
|
};
|
|
2035
|
-
function
|
|
2045
|
+
function Cr(e) {
|
|
2036
2046
|
let t = [];
|
|
2037
2047
|
for (let n = 0; n < e.length; n += 1) {
|
|
2038
2048
|
let r = e.key(n);
|
|
2039
|
-
if (r?.startsWith(
|
|
2049
|
+
if (r?.startsWith(vr)) try {
|
|
2040
2050
|
let n = JSON.parse(e.getItem(r));
|
|
2041
2051
|
t.push({
|
|
2042
2052
|
key: r,
|
|
@@ -2051,61 +2061,61 @@ function Sr(e) {
|
|
|
2051
2061
|
}
|
|
2052
2062
|
return t;
|
|
2053
2063
|
}
|
|
2054
|
-
function
|
|
2055
|
-
let t = Date.now(), n =
|
|
2056
|
-
n.filter(({ value: e }) => !e || !(t - e.savedAt <
|
|
2057
|
-
let r = n.filter(({ value: e }) => e && t - e.savedAt <
|
|
2058
|
-
r.slice(0, Math.max(0, r.length -
|
|
2064
|
+
function wr(e) {
|
|
2065
|
+
let t = Date.now(), n = Cr(e);
|
|
2066
|
+
n.filter(({ value: e }) => !e || !(t - e.savedAt < yr)).forEach(({ key: t }) => e.removeItem(t));
|
|
2067
|
+
let r = n.filter(({ value: e }) => e && t - e.savedAt < yr).sort((e, t) => e.value.savedAt - t.value.savedAt);
|
|
2068
|
+
r.slice(0, Math.max(0, r.length - br)).forEach(({ key: t }) => e.removeItem(t));
|
|
2059
2069
|
}
|
|
2060
|
-
function
|
|
2070
|
+
function Tr(e, t, n) {
|
|
2061
2071
|
try {
|
|
2062
|
-
let r =
|
|
2072
|
+
let r = Sr();
|
|
2063
2073
|
if (!r) return !1;
|
|
2064
|
-
let i =
|
|
2065
|
-
return r.setItem(
|
|
2074
|
+
let i = Er(e, t) ?? {};
|
|
2075
|
+
return r.setItem(xr(e, t), JSON.stringify({
|
|
2066
2076
|
...i,
|
|
2067
2077
|
...n,
|
|
2068
2078
|
savedAt: Date.now()
|
|
2069
|
-
})),
|
|
2079
|
+
})), wr(r), !0;
|
|
2070
2080
|
} catch {
|
|
2071
2081
|
return !1;
|
|
2072
2082
|
}
|
|
2073
2083
|
}
|
|
2074
|
-
function
|
|
2084
|
+
function Er(e, t) {
|
|
2075
2085
|
try {
|
|
2076
|
-
let n = JSON.parse(
|
|
2077
|
-
return !n || typeof n != "object" || !(Date.now() - n.savedAt <
|
|
2086
|
+
let n = JSON.parse(Sr()?.getItem(xr(e, t)) ?? "null");
|
|
2087
|
+
return !n || typeof n != "object" || !(Date.now() - n.savedAt < yr) || n.seedA !== void 0 && !/^[0-9a-f]{32}$/.test(n.seedA) ? null : n;
|
|
2078
2088
|
} catch {
|
|
2079
2089
|
return null;
|
|
2080
2090
|
}
|
|
2081
2091
|
}
|
|
2082
|
-
function
|
|
2092
|
+
function Dr(e) {
|
|
2083
2093
|
try {
|
|
2084
|
-
let t =
|
|
2085
|
-
return t ?
|
|
2094
|
+
let t = Sr();
|
|
2095
|
+
return t ? Cr(t).filter(({ key: t, value: n }) => t.startsWith(`${vr}${e}:`) && n?.snapshot && Date.now() - n.savedAt < yr).map(({ value: e }) => e).sort((e, t) => t.savedAt - e.savedAt) : [];
|
|
2086
2096
|
} catch {
|
|
2087
2097
|
return [];
|
|
2088
2098
|
}
|
|
2089
2099
|
}
|
|
2090
2100
|
// src/games/shared/useChatGames.js
|
|
2091
|
-
var
|
|
2101
|
+
var Or = Ee, J = (e) => e?.game ?? "connect4", kr = (e) => J(e) === "battleship", Ar = (e) => J(e) === "tanks", jr = 250, Y = (e) => [
|
|
2092
2102
|
"won",
|
|
2093
2103
|
"draw",
|
|
2094
2104
|
"closed",
|
|
2095
2105
|
"declined"
|
|
2096
|
-
].includes(e.status),
|
|
2106
|
+
].includes(e.status), Mr = (e, t, n) => JSON.stringify([
|
|
2097
2107
|
e,
|
|
2098
2108
|
String(t),
|
|
2099
2109
|
n
|
|
2100
|
-
]),
|
|
2101
|
-
let t = Object.keys(e).filter((t) =>
|
|
2110
|
+
]), Nr = (e) => {
|
|
2111
|
+
let t = Object.keys(e).filter((t) => Y(e[t]));
|
|
2102
2112
|
if (t.length <= 80) return e;
|
|
2103
2113
|
let n = { ...e };
|
|
2104
2114
|
return t.slice(0, t.length - 80).forEach((e) => {
|
|
2105
2115
|
delete n[e];
|
|
2106
2116
|
}), n;
|
|
2107
2117
|
};
|
|
2108
|
-
function
|
|
2118
|
+
function Pr(e, t, n) {
|
|
2109
2119
|
if (![e.hostId, e.guestId].includes(n)) return e;
|
|
2110
2120
|
if (t.type === "game_end" && t.data.reason === "closed") return ["closed", "declined"].includes(e.status) ? e : {
|
|
2111
2121
|
...e,
|
|
@@ -2113,7 +2123,7 @@ function Mr(e, t, n) {
|
|
|
2113
2123
|
closedBy: n,
|
|
2114
2124
|
error: ""
|
|
2115
2125
|
};
|
|
2116
|
-
if (
|
|
2126
|
+
if (Y(e) || e.status === "conflict") return e;
|
|
2117
2127
|
if (t.type === "game_accept" || t.type === "game_decline") return n !== e.guestId || e.status !== "invited" || t.data.invite_event_id !== e.inviteEventId ? e : {
|
|
2118
2128
|
...e,
|
|
2119
2129
|
status: t.type === "game_accept" ? "active" : "declined",
|
|
@@ -2134,7 +2144,7 @@ function Mr(e, t, n) {
|
|
|
2134
2144
|
error: "La partida perdió sincronización. Ciérrala y envía una nueva invitación."
|
|
2135
2145
|
};
|
|
2136
2146
|
if (n !== e.turnId) return e;
|
|
2137
|
-
let o =
|
|
2147
|
+
let o = Fe(e.board, a, n);
|
|
2138
2148
|
return o ? {
|
|
2139
2149
|
...e,
|
|
2140
2150
|
board: o.board,
|
|
@@ -2152,7 +2162,7 @@ function Mr(e, t, n) {
|
|
|
2152
2162
|
turnId: n === e.hostId ? e.guestId : e.hostId
|
|
2153
2163
|
} : e;
|
|
2154
2164
|
}
|
|
2155
|
-
var
|
|
2165
|
+
var Fr = 8e3, Ir = {
|
|
2156
2166
|
status: "idle",
|
|
2157
2167
|
requestId: null,
|
|
2158
2168
|
requestedAt: 0,
|
|
@@ -2161,14 +2171,14 @@ var Nr = 8e3, Pr = {
|
|
|
2161
2171
|
replies: [],
|
|
2162
2172
|
offer: null,
|
|
2163
2173
|
message: ""
|
|
2164
|
-
},
|
|
2174
|
+
}, Lr = (e) => [
|
|
2165
2175
|
"game_resync_request",
|
|
2166
2176
|
"game_resync_state",
|
|
2167
2177
|
"bs_sync_request",
|
|
2168
2178
|
"bs_sync_state",
|
|
2169
2179
|
"tk_sync_request",
|
|
2170
2180
|
"tk_sync_state"
|
|
2171
|
-
].includes(e),
|
|
2181
|
+
].includes(e), Rr = (e) => e.acceptEventId ? {
|
|
2172
2182
|
accept_event_id: e.acceptEventId,
|
|
2173
2183
|
moves: e.moves ?? [],
|
|
2174
2184
|
rev: (e.moves ?? []).length
|
|
@@ -2176,10 +2186,10 @@ var Nr = 8e3, Pr = {
|
|
|
2176
2186
|
moves: [],
|
|
2177
2187
|
rev: 0
|
|
2178
2188
|
};
|
|
2179
|
-
function
|
|
2189
|
+
function zr(e, t, n) {
|
|
2180
2190
|
let r = {
|
|
2181
2191
|
...e,
|
|
2182
|
-
board:
|
|
2192
|
+
board: Ae(),
|
|
2183
2193
|
ply: 0,
|
|
2184
2194
|
turnId: e.hostId,
|
|
2185
2195
|
winnerId: null,
|
|
@@ -2205,7 +2215,7 @@ function Lr(e, t, n) {
|
|
|
2205
2215
|
let [r, o] = n[t];
|
|
2206
2216
|
if (a.has(o)) return null;
|
|
2207
2217
|
a.add(o);
|
|
2208
|
-
let s = t % 2 == 0 ? e.hostId : e.guestId, c =
|
|
2218
|
+
let s = t % 2 == 0 ? e.hostId : e.guestId, c = Pr(i, {
|
|
2209
2219
|
type: "game_move",
|
|
2210
2220
|
event_id: o,
|
|
2211
2221
|
data: {
|
|
@@ -2219,18 +2229,18 @@ function Lr(e, t, n) {
|
|
|
2219
2229
|
}
|
|
2220
2230
|
return i;
|
|
2221
2231
|
}
|
|
2222
|
-
function
|
|
2232
|
+
function Br(e, t) {
|
|
2223
2233
|
if (e.acceptEventId && t.acceptEventId && e.acceptEventId !== t.acceptEventId) return "diverged";
|
|
2224
2234
|
let n = Math.min(e.moves.length, t.moves.length);
|
|
2225
2235
|
for (let r = 0; r < n; r += 1) if (e.moves[r][0] !== t.moves[r][0] || e.moves[r][1] !== t.moves[r][1]) return "diverged";
|
|
2226
2236
|
return e.moves.length === t.moves.length ? e.acceptEventId && !t.acceptEventId ? "ahead" : !e.acceptEventId && t.acceptEventId ? "behind" : "equal" : e.moves.length < t.moves.length ? "behind" : "ahead";
|
|
2227
2237
|
}
|
|
2228
|
-
var
|
|
2238
|
+
var Vr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEvent.event_id : null, Hr = {
|
|
2229
2239
|
requestType: "game_resync_request",
|
|
2230
2240
|
stateType: "game_resync_state",
|
|
2231
|
-
historyOf:
|
|
2232
|
-
rebuild: (e, t) =>
|
|
2233
|
-
compare: (e, t) =>
|
|
2241
|
+
historyOf: Rr,
|
|
2242
|
+
rebuild: (e, t) => zr(e, t.accept_event_id ?? null, t.moves),
|
|
2243
|
+
compare: (e, t) => Br({
|
|
2234
2244
|
acceptEventId: e.acceptEventId ?? null,
|
|
2235
2245
|
moves: e.moves ?? []
|
|
2236
2246
|
}, {
|
|
@@ -2242,7 +2252,7 @@ var zr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
|
|
|
2242
2252
|
moves: e.moves
|
|
2243
2253
|
}),
|
|
2244
2254
|
covers: (e, t) => {
|
|
2245
|
-
let n =
|
|
2255
|
+
let n = Vr(e);
|
|
2246
2256
|
return !!(n && t.moves?.some((e) => e[1] === n));
|
|
2247
2257
|
},
|
|
2248
2258
|
markSeen: (e, t) => {
|
|
@@ -2252,40 +2262,40 @@ var zr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
|
|
|
2252
2262
|
}), n;
|
|
2253
2263
|
},
|
|
2254
2264
|
merge: () => null
|
|
2255
|
-
},
|
|
2265
|
+
}, Ur = (e) => ({
|
|
2256
2266
|
requestType: "bs_sync_request",
|
|
2257
2267
|
stateType: "bs_sync_state",
|
|
2258
|
-
historyOf:
|
|
2259
|
-
rebuild: (t, n) =>
|
|
2260
|
-
compare: (e, t) =>
|
|
2268
|
+
historyOf: Ft,
|
|
2269
|
+
rebuild: (t, n) => Rt(t, n, { stored: e(t.scope, t.gameId) }),
|
|
2270
|
+
compare: (e, t) => It(Ft(e), t),
|
|
2261
2271
|
offerOf: (e) => ({
|
|
2262
2272
|
accept_event_id: e.accept_event_id,
|
|
2263
2273
|
commits: e.commits,
|
|
2264
2274
|
log: e.log,
|
|
2265
2275
|
head: e.head
|
|
2266
2276
|
}),
|
|
2267
|
-
covers: (e, t) => !!(e.pendingEvent && !e.pending &&
|
|
2268
|
-
markSeen:
|
|
2269
|
-
merge: (e, t) => Ft(
|
|
2270
|
-
}),
|
|
2277
|
+
covers: (e, t) => !!(e.pendingEvent && !e.pending && zt(t, e.pendingEvent)),
|
|
2278
|
+
markSeen: Bt,
|
|
2279
|
+
merge: (e, t) => Lt(Ft(e), t)
|
|
2280
|
+
}), Wr = {
|
|
2271
2281
|
requestType: "tk_sync_request",
|
|
2272
2282
|
stateType: "tk_sync_state",
|
|
2273
|
-
historyOf:
|
|
2274
|
-
rebuild:
|
|
2275
|
-
compare: (e, t) => fr(
|
|
2283
|
+
historyOf: fr,
|
|
2284
|
+
rebuild: mr,
|
|
2285
|
+
compare: (e, t) => pr(fr(e), t),
|
|
2276
2286
|
offerOf: (e) => ({
|
|
2277
2287
|
...e,
|
|
2278
2288
|
request_event_id: void 0
|
|
2279
2289
|
}),
|
|
2280
|
-
covers: (e, t) => !!(e.pendingEvent && !e.pending &&
|
|
2281
|
-
markSeen:
|
|
2290
|
+
covers: (e, t) => !!(e.pendingEvent && !e.pending && hr(t, e.pendingEvent)),
|
|
2291
|
+
markSeen: gr,
|
|
2282
2292
|
merge: () => null
|
|
2283
|
-
},
|
|
2293
|
+
}, Gr = (e) => ({
|
|
2284
2294
|
...e,
|
|
2285
2295
|
game: "connect4",
|
|
2286
2296
|
turnId: e.hostId,
|
|
2287
2297
|
status: "invited",
|
|
2288
|
-
board:
|
|
2298
|
+
board: Ae(),
|
|
2289
2299
|
ply: 0,
|
|
2290
2300
|
winnerId: null,
|
|
2291
2301
|
lastMove: null,
|
|
@@ -2294,35 +2304,35 @@ var zr = (e) => e.pendingEvent?.type === "game_move" && !e.pending ? e.pendingEv
|
|
|
2294
2304
|
pendingEvent: null,
|
|
2295
2305
|
acceptEventId: null,
|
|
2296
2306
|
moves: []
|
|
2297
|
-
}),
|
|
2307
|
+
}), Kr = (e, t, n) => j(t, {
|
|
2298
2308
|
game_id: e.gameId,
|
|
2299
2309
|
data: n,
|
|
2300
2310
|
game: J(e)
|
|
2301
2311
|
});
|
|
2302
|
-
function
|
|
2303
|
-
let e = null, t = /* @__PURE__ */ new Map(), n = (e, n) => t.get(`${e}:${n}`) ??
|
|
2312
|
+
function qr() {
|
|
2313
|
+
let e = null, t = /* @__PURE__ */ new Map(), n = (e, n) => t.get(`${e}:${n}`) ?? Jt(e, n), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), s = Ur(n), l = /* @__PURE__ */ new Map(), u = (e, t) => l.get(`${e}:${t}`) ?? Er(e, t)?.seedA ?? null, d = {
|
|
2304
2314
|
connect4: {
|
|
2305
|
-
create: (e) =>
|
|
2306
|
-
apply: (e, t, n) =>
|
|
2307
|
-
sync:
|
|
2315
|
+
create: (e) => Gr(e),
|
|
2316
|
+
apply: (e, t, n) => Pr(e, t, n),
|
|
2317
|
+
sync: Hr
|
|
2308
2318
|
},
|
|
2309
2319
|
battleship: {
|
|
2310
|
-
create: (e) =>
|
|
2311
|
-
apply: (e, t, r, i) =>
|
|
2320
|
+
create: (e) => tt(e),
|
|
2321
|
+
apply: (e, t, r, i) => jt(e, t, r, { stored: t.type === "bs_commit" && r === i ? n(e.scope, e.gameId) : null }),
|
|
2312
2322
|
sync: s,
|
|
2313
2323
|
after: (e, t) => t().bsScheduleEffects(e)
|
|
2314
2324
|
},
|
|
2315
2325
|
tanks_live: {
|
|
2316
|
-
create: (e, t) =>
|
|
2317
|
-
apply:
|
|
2326
|
+
create: (e, t) => v(e, t.data),
|
|
2327
|
+
apply: y
|
|
2318
2328
|
},
|
|
2319
2329
|
tanks: {
|
|
2320
|
-
create: (e, t) =>
|
|
2321
|
-
apply: (e, t, n) =>
|
|
2322
|
-
sync:
|
|
2330
|
+
create: (e, t) => nr(e, t.data),
|
|
2331
|
+
apply: (e, t, n) => ur(e, t, n),
|
|
2332
|
+
sync: Wr,
|
|
2323
2333
|
after: (e, t) => t().tkScheduleEffects(e)
|
|
2324
2334
|
}
|
|
2325
|
-
}, f = (e) => d[J(e)] ?? null, p = (e) => f(e)?.sync ??
|
|
2335
|
+
}, f = (e) => d[J(e)] ?? null, p = (e) => f(e)?.sync ?? Hr;
|
|
2326
2336
|
return c((s, c) => ({
|
|
2327
2337
|
games: {},
|
|
2328
2338
|
configureTransport: (t) => {
|
|
@@ -2331,12 +2341,12 @@ function Gr() {
|
|
|
2331
2341
|
clear: () => {
|
|
2332
2342
|
r.forEach((e) => clearTimeout(e)), r.clear(), o.forEach((e) => clearTimeout(e)), o.clear(), t.clear(), l.clear(), i.clear(), a.clear(), s({ games: {} });
|
|
2333
2343
|
},
|
|
2334
|
-
markDisconnected: (e) => s((t) => ({ games: Object.fromEntries(Object.entries(t.games).map(([t, n]) => [t, n.scope === e && n.game !== "tanks_live" && !
|
|
2344
|
+
markDisconnected: (e) => s((t) => ({ games: Object.fromEntries(Object.entries(t.games).map(([t, n]) => [t, n.scope === e && n.game !== "tanks_live" && !Y(n) ? {
|
|
2335
2345
|
...n,
|
|
2336
2346
|
status: "conflict",
|
|
2337
2347
|
error: "Conexión interrumpida. Se intentará resincronizar al reconectar.",
|
|
2338
2348
|
sync: {
|
|
2339
|
-
...
|
|
2349
|
+
...Ir,
|
|
2340
2350
|
...n.sync,
|
|
2341
2351
|
status: "idle",
|
|
2342
2352
|
auto: !1
|
|
@@ -2351,13 +2361,13 @@ function Gr() {
|
|
|
2351
2361
|
...t
|
|
2352
2362
|
} : t, p = f.message ?? f.text;
|
|
2353
2363
|
if (typeof p != "string" || !p.startsWith("LIRA_GAME_V1:")) return !1;
|
|
2354
|
-
let m =
|
|
2364
|
+
let m = Oe(p), h = String(f.room_id ?? ""), g = String(f.user_id ?? "");
|
|
2355
2365
|
if (!m || !o || !l || !g || !h.startsWith("private_")) return !0;
|
|
2356
2366
|
let _ = h.slice(8).split("_");
|
|
2357
2367
|
if (_.length !== 2 || !_.includes(l) || !_.includes(g)) return !0;
|
|
2358
|
-
let v =
|
|
2368
|
+
let v = Mr(o, h, m.game_id), y = c().games[v];
|
|
2359
2369
|
if (y && J(y) !== m.game) return !0;
|
|
2360
|
-
if (
|
|
2370
|
+
if (Lr(m.type)) return y && !y.seen[m.event_id] && c().handleResync(v, m, g, l), !0;
|
|
2361
2371
|
if (!y && m.type !== "game_invite" && m.game === "tanks" && c().restoreTanks(o, m.game_id)) return c().ingest(t, n, r);
|
|
2362
2372
|
if (!y && m.type !== "game_invite") {
|
|
2363
2373
|
let e = Date.now();
|
|
@@ -2391,7 +2401,7 @@ function Gr() {
|
|
|
2391
2401
|
inviteEventId: m.event_id,
|
|
2392
2402
|
lastEventId: m.event_id,
|
|
2393
2403
|
seen: {},
|
|
2394
|
-
sync: { ...
|
|
2404
|
+
sync: { ...Ir }
|
|
2395
2405
|
}, m);
|
|
2396
2406
|
} else y && (b = x.apply(y, m, g, l));
|
|
2397
2407
|
if (!b || b === y) return !0;
|
|
@@ -2407,7 +2417,7 @@ function Gr() {
|
|
|
2407
2417
|
[v]: b
|
|
2408
2418
|
};
|
|
2409
2419
|
if (m.type === "game_invite") {
|
|
2410
|
-
let e = Object.values(t).filter((e) => e.scope === o && e.roomId === h && !
|
|
2420
|
+
let e = Object.values(t).filter((e) => e.scope === o && e.roomId === h && !Y(e)), n = e.sort((e, t) => e.gameId < t.gameId ? -1 : +(e.gameId > t.gameId))[0];
|
|
2411
2421
|
e.forEach((e) => {
|
|
2412
2422
|
e.key !== n?.key && (t[e.key] = {
|
|
2413
2423
|
...e,
|
|
@@ -2416,7 +2426,7 @@ function Gr() {
|
|
|
2416
2426
|
});
|
|
2417
2427
|
});
|
|
2418
2428
|
}
|
|
2419
|
-
return { games:
|
|
2429
|
+
return { games: Nr(t) };
|
|
2420
2430
|
}), b.status === "conflict" && y?.status !== "conflict" && queueMicrotask(() => {
|
|
2421
2431
|
c().requestResync(v, { auto: !0 });
|
|
2422
2432
|
}), c().afterGameChange(v), m.type === "game_invite") {
|
|
@@ -2427,20 +2437,20 @@ function Gr() {
|
|
|
2427
2437
|
},
|
|
2428
2438
|
invite: async ({ roomId: t, opponentId: n, gameType: r = "connect4", firstPlayerId: i, rematchOf: a }) => {
|
|
2429
2439
|
if (!e) throw Error("Chat no disponible");
|
|
2430
|
-
if (!
|
|
2440
|
+
if (!Or.includes(r)) throw Error("Juego no disponible");
|
|
2431
2441
|
let o = e.getScope();
|
|
2432
2442
|
if (!String(e.getUserId() ?? "") || !String(t).startsWith("private_")) throw Error("Abre un chat privado para jugar.");
|
|
2433
|
-
if (Object.values(c().games).some((e) => e.scope === o && e.roomId === String(t) && (!
|
|
2434
|
-
let s =
|
|
2443
|
+
if (Object.values(c().games).some((e) => e.scope === o && e.roomId === String(t) && (!Y(e) || e.pendingEvent))) throw Error("Cierra la partida actual antes de invitar.");
|
|
2444
|
+
let s = m(), u = {
|
|
2435
2445
|
opponent_id: String(n),
|
|
2436
2446
|
rules_version: 1
|
|
2437
2447
|
};
|
|
2438
2448
|
if (r === "tanks") {
|
|
2439
|
-
let e =
|
|
2440
|
-
l.set(`${o}:${s}`, e),
|
|
2449
|
+
let e = $n();
|
|
2450
|
+
l.set(`${o}:${s}`, e), Tr(o, s, { seedA: e }), u.seed_commit = er(e), i != null && (u.first_player_id = String(i)), a && (u.rematch_of = a);
|
|
2441
2451
|
}
|
|
2442
2452
|
r === "tanks_live" && a && (u.rematch_of = a);
|
|
2443
|
-
let d =
|
|
2453
|
+
let d = j("game_invite", {
|
|
2444
2454
|
game_id: s,
|
|
2445
2455
|
data: u,
|
|
2446
2456
|
game: r
|
|
@@ -2454,9 +2464,9 @@ function Gr() {
|
|
|
2454
2464
|
let o = r;
|
|
2455
2465
|
if (n === "game_accept" || n === "game_decline") {
|
|
2456
2466
|
if (i.status !== "invited" || a !== i.guestId) return;
|
|
2457
|
-
o = { invite_event_id: i.inviteEventId }, n === "game_accept" &&
|
|
2467
|
+
o = { invite_event_id: i.inviteEventId }, n === "game_accept" && Ar(i) && (o.seed_b = $n());
|
|
2458
2468
|
} else if (n === "game_move") {
|
|
2459
|
-
if (J(i) !== "connect4" || i.status !== "active" || a !== i.turnId || !
|
|
2469
|
+
if (J(i) !== "connect4" || i.status !== "active" || a !== i.turnId || !Fe(i.board, r.column, a)) return;
|
|
2460
2470
|
o = {
|
|
2461
2471
|
column: r.column,
|
|
2462
2472
|
ply: i.ply + 1,
|
|
@@ -2464,7 +2474,7 @@ function Gr() {
|
|
|
2464
2474
|
};
|
|
2465
2475
|
} else if (n === "game_end") o = { reason: "closed" };
|
|
2466
2476
|
else return;
|
|
2467
|
-
return c().sendEvent(i.roomId,
|
|
2477
|
+
return c().sendEvent(i.roomId, j(n, {
|
|
2468
2478
|
game_id: i.gameId,
|
|
2469
2479
|
data: o,
|
|
2470
2480
|
game: J(i)
|
|
@@ -2472,33 +2482,33 @@ function Gr() {
|
|
|
2472
2482
|
},
|
|
2473
2483
|
bsUpdateLocal: (e, t) => {
|
|
2474
2484
|
let n = c().games[e];
|
|
2475
|
-
if (!
|
|
2485
|
+
if (!kr(n)) return !1;
|
|
2476
2486
|
let r = t(n);
|
|
2477
2487
|
return r !== n && (s((t) => t.games[e] === n ? { games: {
|
|
2478
2488
|
...t.games,
|
|
2479
2489
|
[e]: r
|
|
2480
2490
|
} } : t), c().games[e] === r);
|
|
2481
2491
|
},
|
|
2482
|
-
bsPlaceShip: (e, t) => c().bsUpdateLocal(e, (e) =>
|
|
2483
|
-
bsRemoveShip: (e, t) => c().bsUpdateLocal(e, (e) =>
|
|
2484
|
-
bsRandomFleet: (e) => c().bsUpdateLocal(e, (e) =>
|
|
2492
|
+
bsPlaceShip: (e, t) => c().bsUpdateLocal(e, (e) => ft(e, t)),
|
|
2493
|
+
bsRemoveShip: (e, t) => c().bsUpdateLocal(e, (e) => pt(e, t)),
|
|
2494
|
+
bsRandomFleet: (e) => c().bsUpdateLocal(e, (e) => gt(e)),
|
|
2485
2495
|
bsReady: async (n) => {
|
|
2486
2496
|
let r = c().games[n];
|
|
2487
|
-
if (!
|
|
2497
|
+
if (!kr(r) || r.status !== "placement" || r.myReady) return;
|
|
2488
2498
|
if (r.scope !== e?.getScope?.()) throw Error("Partida no disponible");
|
|
2489
2499
|
if (r.pending || r.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
|
|
2490
|
-
let i =
|
|
2491
|
-
if (!
|
|
2492
|
-
let a =
|
|
2493
|
-
if (!(!s || s.myReady || s.status !== "placement" || s.pending || s.pendingEvent || JSON.stringify(
|
|
2500
|
+
let i = ct(r.myFleet);
|
|
2501
|
+
if (!ut(i)) throw Error("Coloca los cinco barcos antes de continuar.");
|
|
2502
|
+
let a = vt(), o = await bt(i, a), s = c().games[n];
|
|
2503
|
+
if (!(!s || s.myReady || s.status !== "placement" || s.pending || s.pendingEvent || JSON.stringify(ct(s.myFleet)) !== JSON.stringify(i))) return t.set(`${r.scope}:${r.gameId}`, {
|
|
2494
2504
|
fleet: i,
|
|
2495
2505
|
salt: a,
|
|
2496
2506
|
commitment: o
|
|
2497
|
-
}),
|
|
2507
|
+
}), qt(r.scope, r.gameId, {
|
|
2498
2508
|
fleet: i,
|
|
2499
2509
|
salt: a,
|
|
2500
2510
|
commitment: o
|
|
2501
|
-
}), c().sendEvent(r.roomId,
|
|
2511
|
+
}), c().sendEvent(r.roomId, j("bs_commit", {
|
|
2502
2512
|
game_id: r.gameId,
|
|
2503
2513
|
data: { commitment: o },
|
|
2504
2514
|
game: "battleship"
|
|
@@ -2506,9 +2516,9 @@ function Gr() {
|
|
|
2506
2516
|
},
|
|
2507
2517
|
bsFire: async (t, { row: n, col: r } = {}) => {
|
|
2508
2518
|
let i = c().games[t];
|
|
2509
|
-
if (!
|
|
2519
|
+
if (!kr(i) || i.scope !== e?.getScope?.()) throw Error("Partida no disponible");
|
|
2510
2520
|
if (i.pending || i.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
|
|
2511
|
-
if (
|
|
2521
|
+
if (rt(i) && i.targetShots[n]?.[r] === null) return c().sendEvent(i.roomId, j("bs_fire", {
|
|
2512
2522
|
game_id: i.gameId,
|
|
2513
2523
|
data: {
|
|
2514
2524
|
ply: i.ply + 1,
|
|
@@ -2522,14 +2532,14 @@ function Gr() {
|
|
|
2522
2532
|
bsScheduleEffects: (e) => {
|
|
2523
2533
|
r.has(e) || r.set(e, setTimeout(() => {
|
|
2524
2534
|
r.delete(e), c().bsRunEffects(e);
|
|
2525
|
-
},
|
|
2535
|
+
}, jr));
|
|
2526
2536
|
},
|
|
2527
2537
|
bsRunEffects: (t) => {
|
|
2528
2538
|
let r = c().games[t];
|
|
2529
|
-
if (!
|
|
2539
|
+
if (!kr(r) || !e || r.scope !== e.getScope?.()) return;
|
|
2530
2540
|
if (r.opponentReveal && r.verification === "pending" && !i.has(t)) {
|
|
2531
2541
|
let e = r.opponentReveal;
|
|
2532
|
-
i.add(t),
|
|
2542
|
+
i.add(t), Nt(r, e).then((n) => s((r) => {
|
|
2533
2543
|
let i = r.games[t];
|
|
2534
2544
|
return !i || i.opponentReveal !== e || i.verification === n ? r : { games: {
|
|
2535
2545
|
...r.games,
|
|
@@ -2544,14 +2554,14 @@ function Gr() {
|
|
|
2544
2554
|
}
|
|
2545
2555
|
if (r.pending || r.pendingEvent) return;
|
|
2546
2556
|
let a = (e, t) => {
|
|
2547
|
-
c().sendEvent(r.roomId,
|
|
2557
|
+
c().sendEvent(r.roomId, j(e, {
|
|
2548
2558
|
game_id: r.gameId,
|
|
2549
2559
|
data: t,
|
|
2550
2560
|
game: "battleship"
|
|
2551
2561
|
})).catch(() => {});
|
|
2552
2562
|
};
|
|
2553
2563
|
if (r.status === "active" && r.pendingShot && r.pendingShot.by !== r.ownId) {
|
|
2554
|
-
let e =
|
|
2564
|
+
let e = xt(dt(r), r.pendingShot);
|
|
2555
2565
|
e ? a("bs_result", e) : r.error || s((e) => ({ games: {
|
|
2556
2566
|
...e.games,
|
|
2557
2567
|
[t]: {
|
|
@@ -2563,8 +2573,8 @@ function Gr() {
|
|
|
2563
2573
|
}
|
|
2564
2574
|
let o = String(r.winnerId) !== String(r.ownId) || !!r.opponentReveal;
|
|
2565
2575
|
if (r.winnerId && ["won", "closed"].includes(r.status) && !r.myRevealSent && o) {
|
|
2566
|
-
let e =
|
|
2567
|
-
|
|
2576
|
+
let e = ct(r.myFleet), t = r.mySalt ?? n(r.scope, r.gameId)?.salt;
|
|
2577
|
+
ut(e) && t && a("bs_reveal", {
|
|
2568
2578
|
fleet: e,
|
|
2569
2579
|
salt: t
|
|
2570
2580
|
});
|
|
@@ -2576,10 +2586,10 @@ function Gr() {
|
|
|
2576
2586
|
},
|
|
2577
2587
|
tkTurn: async (t, n) => {
|
|
2578
2588
|
let r = c().games[t];
|
|
2579
|
-
if (!
|
|
2589
|
+
if (!Ar(r) || r.scope !== e?.getScope?.()) throw Error("Partida no disponible");
|
|
2580
2590
|
if (r.pending || r.pendingEvent) throw Error("Reintenta el envío pendiente antes de continuar.");
|
|
2581
|
-
let i =
|
|
2582
|
-
if (i) return c().sendEvent(r.roomId,
|
|
2591
|
+
let i = dr(r, n);
|
|
2592
|
+
if (i) return c().sendEvent(r.roomId, j("tk_turn", {
|
|
2583
2593
|
game_id: r.gameId,
|
|
2584
2594
|
data: i,
|
|
2585
2595
|
game: "tanks"
|
|
@@ -2587,7 +2597,7 @@ function Gr() {
|
|
|
2587
2597
|
},
|
|
2588
2598
|
tkSkip: async (t) => {
|
|
2589
2599
|
let n = c().games[t];
|
|
2590
|
-
if (
|
|
2600
|
+
if (Ar(n) && ir(n) && n.scope === e?.getScope?.()) return c().sendEvent(n.roomId, j("tk_skip", {
|
|
2591
2601
|
game_id: n.gameId,
|
|
2592
2602
|
data: {
|
|
2593
2603
|
ply: n.ply + 1,
|
|
@@ -2598,7 +2608,7 @@ function Gr() {
|
|
|
2598
2608
|
},
|
|
2599
2609
|
tkResign: async (t) => {
|
|
2600
2610
|
let n = c().games[t];
|
|
2601
|
-
if (!(!
|
|
2611
|
+
if (!(!Ar(n) || n.status !== "active" || n.pending || n.pendingEvent || n.scope !== e?.getScope?.())) return c().sendEvent(n.roomId, j("tk_resign", {
|
|
2602
2612
|
game_id: n.gameId,
|
|
2603
2613
|
data: {
|
|
2604
2614
|
ply: n.ply + 1,
|
|
@@ -2610,13 +2620,13 @@ function Gr() {
|
|
|
2610
2620
|
tkScheduleEffects: (e) => {
|
|
2611
2621
|
r.has(e) || r.set(e, setTimeout(() => {
|
|
2612
2622
|
r.delete(e), c().tkRunEffects(e);
|
|
2613
|
-
},
|
|
2623
|
+
}, jr));
|
|
2614
2624
|
},
|
|
2615
2625
|
tkRunEffects: (t) => {
|
|
2616
2626
|
let n = c().games[t];
|
|
2617
|
-
if (!
|
|
2627
|
+
if (!Ar(n) || (Tr(n.scope, n.gameId, { snapshot: _r(n) }), !e || n.scope !== e.getScope?.() || n.pending || n.pendingEvent) || n.status !== "seeding" || n.ownId !== n.hostId) return;
|
|
2618
2628
|
let r = u(n.scope, n.gameId);
|
|
2619
|
-
r ? c().sendEvent(n.roomId,
|
|
2629
|
+
r ? c().sendEvent(n.roomId, j("tk_seed", {
|
|
2620
2630
|
game_id: n.gameId,
|
|
2621
2631
|
data: { seed_a: r },
|
|
2622
2632
|
game: "tanks"
|
|
@@ -2630,16 +2640,16 @@ function Gr() {
|
|
|
2630
2640
|
},
|
|
2631
2641
|
restoreTanks: (e, t) => {
|
|
2632
2642
|
let n = !1;
|
|
2633
|
-
return
|
|
2643
|
+
return Dr(e).forEach(({ snapshot: r }) => {
|
|
2634
2644
|
if (!r || t && r.gameId !== t || [
|
|
2635
2645
|
"closed",
|
|
2636
2646
|
"declined",
|
|
2637
2647
|
"won",
|
|
2638
2648
|
"draw"
|
|
2639
2649
|
].includes(r.status)) return;
|
|
2640
|
-
let i =
|
|
2650
|
+
let i = Mr(e, r.roomId, r.gameId);
|
|
2641
2651
|
if (c().games[i]) return;
|
|
2642
|
-
let a =
|
|
2652
|
+
let a = mr(nr({
|
|
2643
2653
|
key: i,
|
|
2644
2654
|
gameId: r.gameId,
|
|
2645
2655
|
game_id: r.gameId,
|
|
@@ -2652,7 +2662,7 @@ function Gr() {
|
|
|
2652
2662
|
inviteEventId: r.inviteEventId,
|
|
2653
2663
|
lastEventId: r.inviteEventId,
|
|
2654
2664
|
seen: {},
|
|
2655
|
-
sync: { ...
|
|
2665
|
+
sync: { ...Ir }
|
|
2656
2666
|
}, {
|
|
2657
2667
|
seed_commit: r.seedCommit,
|
|
2658
2668
|
first_player_id: r.firstPlayerId,
|
|
@@ -2662,11 +2672,11 @@ function Gr() {
|
|
|
2662
2672
|
n = !0;
|
|
2663
2673
|
let o = {
|
|
2664
2674
|
...a,
|
|
2665
|
-
seen:
|
|
2675
|
+
seen: gr({ [r.inviteEventId]: !0 }, a),
|
|
2666
2676
|
status: "conflict",
|
|
2667
2677
|
error: "Partida recuperada en este dispositivo. Sincronizando con el rival…"
|
|
2668
2678
|
};
|
|
2669
|
-
s((e) => ({ games:
|
|
2679
|
+
s((e) => ({ games: Nr({
|
|
2670
2680
|
...e.games,
|
|
2671
2681
|
[i]: o
|
|
2672
2682
|
}) })), queueMicrotask(() => {
|
|
@@ -2678,7 +2688,7 @@ function Gr() {
|
|
|
2678
2688
|
let n = c().games[t];
|
|
2679
2689
|
if (n?.game !== "tanks_live" || n.scope !== e?.getScope?.()) throw Error("Partida no disponible");
|
|
2680
2690
|
let r = e;
|
|
2681
|
-
return
|
|
2691
|
+
return S({
|
|
2682
2692
|
roomId: n.roomId,
|
|
2683
2693
|
send: (n, i) => {
|
|
2684
2694
|
if (e !== r || c().games[t]?.scope !== r.getScope()) throw Error("La sesión cambió");
|
|
@@ -2699,7 +2709,7 @@ function Gr() {
|
|
|
2699
2709
|
},
|
|
2700
2710
|
liveRematch: (t) => {
|
|
2701
2711
|
let n = c().games[t];
|
|
2702
|
-
if (n?.game === "tanks_live" && n.scope === e?.getScope?.() &&
|
|
2712
|
+
if (n?.game === "tanks_live" && n.scope === e?.getScope?.() && Y(n)) return c().invite({
|
|
2703
2713
|
roomId: n.roomId,
|
|
2704
2714
|
opponentId: n.ownId === n.hostId ? n.guestId : n.hostId,
|
|
2705
2715
|
gameType: "tanks_live",
|
|
@@ -2708,7 +2718,7 @@ function Gr() {
|
|
|
2708
2718
|
},
|
|
2709
2719
|
sendEvent: async (t, n) => {
|
|
2710
2720
|
if (!e) throw Error("Chat no disponible");
|
|
2711
|
-
let r = e, i = r.getScope(), a = String(r.getUserId() ?? ""), o =
|
|
2721
|
+
let r = e, i = r.getScope(), a = String(r.getUserId() ?? ""), o = Mr(i, t, n.game_id), l = ke(n);
|
|
2712
2722
|
if (c().ingest({
|
|
2713
2723
|
room_id: t,
|
|
2714
2724
|
user_id: a,
|
|
@@ -2760,7 +2770,7 @@ function Gr() {
|
|
|
2760
2770
|
return;
|
|
2761
2771
|
}
|
|
2762
2772
|
let u = {
|
|
2763
|
-
...
|
|
2773
|
+
...Ir,
|
|
2764
2774
|
...i.sync
|
|
2765
2775
|
};
|
|
2766
2776
|
if (![a.requestType, a.stateType].includes(t.type)) {
|
|
@@ -2848,7 +2858,7 @@ function Gr() {
|
|
|
2848
2858
|
};
|
|
2849
2859
|
let b = Date.now(), x = g.sync.replies.filter((e) => b - e < 3e4), S = null;
|
|
2850
2860
|
if (_ && x.length < 6) try {
|
|
2851
|
-
S =
|
|
2861
|
+
S = Kr(i, a.stateType, {
|
|
2852
2862
|
...a.historyOf(g),
|
|
2853
2863
|
request_event_id: t.event_id
|
|
2854
2864
|
});
|
|
@@ -2883,19 +2893,19 @@ function Gr() {
|
|
|
2883
2893
|
sendResync: async (t, n) => {
|
|
2884
2894
|
let r = c().games[t];
|
|
2885
2895
|
if (!e || !r || r.scope !== e.getScope?.()) throw Error("Chat no disponible");
|
|
2886
|
-
await e.send(r.roomId,
|
|
2896
|
+
await e.send(r.roomId, ke(n));
|
|
2887
2897
|
},
|
|
2888
2898
|
requestResync: async (t, { auto: n = !1 } = {}) => {
|
|
2889
2899
|
let r = c().games[t];
|
|
2890
2900
|
if (!r || r.game === "tanks_live" || !e || ["closed", "declined"].includes(r.status) || r.scope !== e.getScope?.()) return;
|
|
2891
2901
|
let i = {
|
|
2892
|
-
...
|
|
2902
|
+
...Ir,
|
|
2893
2903
|
...r.sync
|
|
2894
2904
|
};
|
|
2895
|
-
if (i.status === "requesting" && Date.now() - i.requestedAt <
|
|
2905
|
+
if (i.status === "requesting" && Date.now() - i.requestedAt < Fr || n && i.auto) return;
|
|
2896
2906
|
let a;
|
|
2897
2907
|
try {
|
|
2898
|
-
a =
|
|
2908
|
+
a = Kr(r, p(r).requestType, p(r).historyOf(r));
|
|
2899
2909
|
} catch {
|
|
2900
2910
|
return;
|
|
2901
2911
|
}
|
|
@@ -2937,7 +2947,7 @@ function Gr() {
|
|
|
2937
2947
|
});
|
|
2938
2948
|
let u = setTimeout(() => {
|
|
2939
2949
|
o.delete(u), l("El rival no respondió a la sincronización. Reintenta cuando esté conectado.");
|
|
2940
|
-
},
|
|
2950
|
+
}, Fr);
|
|
2941
2951
|
o.add(u);
|
|
2942
2952
|
try {
|
|
2943
2953
|
await c().sendResync(t, a);
|
|
@@ -2985,30 +2995,30 @@ function Gr() {
|
|
|
2985
2995
|
}
|
|
2986
2996
|
}));
|
|
2987
2997
|
}
|
|
2988
|
-
var
|
|
2989
|
-
Object.assign(
|
|
2990
|
-
getState:
|
|
2991
|
-
setState:
|
|
2992
|
-
subscribe:
|
|
2998
|
+
var X = qr(), Jr = (e) => l(X, e);
|
|
2999
|
+
Object.assign(Jr, {
|
|
3000
|
+
getState: X.getState,
|
|
3001
|
+
setState: X.setState,
|
|
3002
|
+
subscribe: X.subscribe
|
|
2993
3003
|
});
|
|
2994
3004
|
// src/assets/chatAssets.js
|
|
2995
|
-
var
|
|
2996
|
-
function
|
|
2997
|
-
|
|
3005
|
+
var Yr = "/sounds", Xr = Yr, Zr = (e) => String(e).replace(/\/+$/, "");
|
|
3006
|
+
function Qr(e) {
|
|
3007
|
+
Xr = e == null ? Yr : Zr(e);
|
|
2998
3008
|
}
|
|
2999
|
-
function
|
|
3000
|
-
return
|
|
3009
|
+
function $r() {
|
|
3010
|
+
return Xr;
|
|
3001
3011
|
}
|
|
3002
|
-
function
|
|
3003
|
-
return `${
|
|
3012
|
+
function ei(e) {
|
|
3013
|
+
return `${Xr}/${String(e).replace(/^\/+/, "")}`;
|
|
3004
3014
|
}
|
|
3005
3015
|
// src/audio/useSoundSettings.js
|
|
3006
|
-
function
|
|
3016
|
+
function ti(e) {
|
|
3007
3017
|
return s(e.subscribe, e.getSettings, e.getSettings);
|
|
3008
3018
|
}
|
|
3009
3019
|
// src/games/shared/GameSoundControls.jsx
|
|
3010
|
-
function
|
|
3011
|
-
let { volume: t, muted: n } =
|
|
3020
|
+
function ni({ manager: e }) {
|
|
3021
|
+
let { volume: t, muted: n } = ti(e), r = n || t === 0;
|
|
3012
3022
|
return /* @__PURE__ */ p("div", {
|
|
3013
3023
|
className: "chat-game-sound",
|
|
3014
3024
|
children: [/* @__PURE__ */ f("button", {
|
|
@@ -3031,27 +3041,27 @@ function ti({ manager: e }) {
|
|
|
3031
3041
|
});
|
|
3032
3042
|
}
|
|
3033
3043
|
// src/audio/createSoundManager.js
|
|
3034
|
-
var
|
|
3044
|
+
var ri = [
|
|
3035
3045
|
"pointerdown",
|
|
3036
3046
|
"keydown",
|
|
3037
3047
|
"touchend"
|
|
3038
|
-
],
|
|
3039
|
-
function
|
|
3048
|
+
], ii = 300, ai = 800, oi = (e) => Math.min(1, Math.max(0, Number(e) || 0));
|
|
3049
|
+
function si(e, t) {
|
|
3040
3050
|
try {
|
|
3041
3051
|
let n = JSON.parse(localStorage.getItem(e) ?? "null");
|
|
3042
3052
|
if (n && typeof n == "object") return {
|
|
3043
|
-
volume:
|
|
3053
|
+
volume: oi(n.volume ?? t.volume),
|
|
3044
3054
|
muted: !!n.muted
|
|
3045
3055
|
};
|
|
3046
3056
|
} catch {}
|
|
3047
3057
|
return {
|
|
3048
|
-
volume:
|
|
3058
|
+
volume: oi(t.volume),
|
|
3049
3059
|
muted: !1
|
|
3050
3060
|
};
|
|
3051
3061
|
}
|
|
3052
|
-
var
|
|
3053
|
-
function
|
|
3054
|
-
let o = `lira.sound.${e}`, s = typeof window < "u" ? window.AudioContext || window.webkitAudioContext : null, c = a ? a.getSettings() :
|
|
3062
|
+
var ci = 1.5, li = .6;
|
|
3063
|
+
function ui({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .6, settingsFrom: a = null }) {
|
|
3064
|
+
let o = `lira.sound.${e}`, s = typeof window < "u" ? window.AudioContext || window.webkitAudioContext : null, c = a ? a.getSettings() : si(o, { volume: i }), l = null, u = null, d = !1, f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set(), _ = /* @__PURE__ */ new Set(), v = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), b = !1, x = !1, S = null, ee = (e) => `${String(typeof t == "function" ? t() : t).replace(/\/$/, "")}/${n[e]}`, te = (e) => (f.has(e) || f.set(e, fetch(ee(e)).then((e) => e.ok ? e.arrayBuffer() : null).catch(() => null)), f.get(e)), C = () => {
|
|
3055
3065
|
if (!s) return null;
|
|
3056
3066
|
if (!l) try {
|
|
3057
3067
|
l = new s(), u = l.createGain(), u.gain.value = c.muted ? 0 : c.volume, u.connect(l.destination);
|
|
@@ -3059,27 +3069,27 @@ function li({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .
|
|
|
3059
3069
|
return l = null, null;
|
|
3060
3070
|
}
|
|
3061
3071
|
return l.state === "suspended" && l.resume().catch(() => {}), l;
|
|
3062
|
-
},
|
|
3072
|
+
}, ne = (e) => {
|
|
3063
3073
|
if (m.has(e) || !n[e]) return Promise.resolve(null);
|
|
3064
3074
|
if (!p.has(e)) {
|
|
3065
|
-
let t =
|
|
3075
|
+
let t = C();
|
|
3066
3076
|
if (!t) return Promise.resolve(null);
|
|
3067
|
-
p.set(e,
|
|
3077
|
+
p.set(e, te(e).then((e) => e ? new Promise((n) => {
|
|
3068
3078
|
t.decodeAudioData(e.slice(0), n, () => n(null))?.catch?.(() => n(null));
|
|
3069
3079
|
}) : null).then((t) => (t || m.add(e), t)).catch(() => (m.add(e), null)));
|
|
3070
3080
|
}
|
|
3071
3081
|
return p.get(e);
|
|
3072
|
-
},
|
|
3082
|
+
}, re = (e) => oi(r[e] ?? 1), ie = (e) => {
|
|
3073
3083
|
if (!_.has(e) || v.has(e) || !d) return;
|
|
3074
|
-
let t =
|
|
3084
|
+
let t = C();
|
|
3075
3085
|
if (!t) return;
|
|
3076
3086
|
let n = {};
|
|
3077
|
-
v.set(e, n),
|
|
3087
|
+
v.set(e, n), ne(e).then((r) => {
|
|
3078
3088
|
if (v.get(e) === n) {
|
|
3079
3089
|
if (!r || t.state === "closed") v.delete(e);
|
|
3080
3090
|
else try {
|
|
3081
|
-
let { fadeIn: n =
|
|
3082
|
-
a.gain.setValueAtTime(0, t.currentTime), a.gain.linearRampToValueAtTime(
|
|
3091
|
+
let { fadeIn: n = ci, trim: i = 0 } = y.get(e) ?? {}, a = t.createGain();
|
|
3092
|
+
a.gain.setValueAtTime(0, t.currentTime), a.gain.linearRampToValueAtTime(re(e), t.currentTime + n), a.connect(u);
|
|
3083
3093
|
let o = t.createBufferSource();
|
|
3084
3094
|
o.buffer = r, o.loop = !0, i > 0 && r.duration > i * 4 && (o.loopStart = i, o.loopEnd = r.duration - i), o.connect(a), o.start(0, i > 0 && r.duration > i * 4 ? i : 0), v.set(e, {
|
|
3085
3095
|
source: o,
|
|
@@ -3090,41 +3100,41 @@ function li({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .
|
|
|
3090
3100
|
}
|
|
3091
3101
|
}
|
|
3092
3102
|
});
|
|
3093
|
-
},
|
|
3103
|
+
}, w = (e) => {
|
|
3094
3104
|
let t = v.get(e);
|
|
3095
3105
|
if (v.delete(e), t?.source && l) try {
|
|
3096
|
-
let n = y.get(e)?.fadeOut ??
|
|
3106
|
+
let n = y.get(e)?.fadeOut ?? li, r = l.currentTime;
|
|
3097
3107
|
t.level.gain.cancelScheduledValues(r), t.level.gain.setValueAtTime(t.level.gain.value, r), t.level.gain.linearRampToValueAtTime(0, r + n), t.source.stop(r + n + .05);
|
|
3098
3108
|
} catch {}
|
|
3099
|
-
},
|
|
3100
|
-
d || (d = !0,
|
|
3101
|
-
f.has(e) &&
|
|
3102
|
-
}), _.forEach(
|
|
3109
|
+
}, T = () => {
|
|
3110
|
+
d || (d = !0, E(), C() && Object.keys(n).forEach((e) => {
|
|
3111
|
+
f.has(e) && ne(e);
|
|
3112
|
+
}), _.forEach(ie));
|
|
3103
3113
|
};
|
|
3104
|
-
function
|
|
3105
|
-
x && (x = !1,
|
|
3114
|
+
function E() {
|
|
3115
|
+
x && (x = !1, ri.forEach((e) => window.removeEventListener(e, T, !0)));
|
|
3106
3116
|
}
|
|
3107
|
-
let
|
|
3108
|
-
c = e, u && (u.gain.value = c.muted ? 0 : c.volume),
|
|
3109
|
-
},
|
|
3117
|
+
let ae = (e) => !h.has(e) && (h.add(e), h.size > ii && h.delete(h.values().next().value), !0), oe = () => g.forEach((e) => e()), se = (e) => {
|
|
3118
|
+
c = e, u && (u.gain.value = c.muted ? 0 : c.volume), oe();
|
|
3119
|
+
}, D = (e) => {
|
|
3110
3120
|
let t = {
|
|
3111
|
-
volume:
|
|
3121
|
+
volume: oi(e.volume ?? c.volume),
|
|
3112
3122
|
muted: e.muted ?? c.muted
|
|
3113
3123
|
};
|
|
3114
3124
|
try {
|
|
3115
3125
|
localStorage.setItem(o, JSON.stringify(t));
|
|
3116
3126
|
} catch {}
|
|
3117
|
-
|
|
3118
|
-
},
|
|
3119
|
-
b || (b = !0, a && (c = a.getSettings(), S = a.subscribe(() =>
|
|
3127
|
+
se(t);
|
|
3128
|
+
}, O = () => {
|
|
3129
|
+
b || (b = !0, a && (c = a.getSettings(), S = a.subscribe(() => se(a.getSettings()))), !(typeof window > "u" || d) && (typeof navigator < "u" && navigator.userActivation?.hasBeenActive ? d = !0 : (x = !0, ri.forEach((e) => window.addEventListener(e, T, {
|
|
3120
3130
|
capture: !0,
|
|
3121
3131
|
passive: !0
|
|
3122
3132
|
})))));
|
|
3123
3133
|
};
|
|
3124
3134
|
return {
|
|
3125
|
-
start:
|
|
3135
|
+
start: O,
|
|
3126
3136
|
dispose: () => {
|
|
3127
|
-
|
|
3137
|
+
E(), S && (S(), S = null), b = !1, _.clear(), v.forEach((e) => {
|
|
3128
3138
|
try {
|
|
3129
3139
|
e?.source?.stop();
|
|
3130
3140
|
} catch {}
|
|
@@ -3133,20 +3143,20 @@ function li({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .
|
|
|
3133
3143
|
l = null, u = null, e && e.state !== "closed" && e.close().catch(() => {});
|
|
3134
3144
|
},
|
|
3135
3145
|
preload(e = Object.keys(n)) {
|
|
3136
|
-
|
|
3137
|
-
n[e] && !m.has(e) && (
|
|
3146
|
+
O(), e.forEach((e) => {
|
|
3147
|
+
n[e] && !m.has(e) && (te(e), l && ne(e));
|
|
3138
3148
|
});
|
|
3139
3149
|
},
|
|
3140
3150
|
play(e, { key: t } = {}) {
|
|
3141
|
-
if (
|
|
3142
|
-
let r =
|
|
3151
|
+
if (O(), t != null && !ae(`${e}:${t}`) || !n[e] || m.has(e) || !d || c.muted || c.volume === 0) return !1;
|
|
3152
|
+
let r = C();
|
|
3143
3153
|
if (!r) return !1;
|
|
3144
3154
|
let i = Date.now();
|
|
3145
|
-
return
|
|
3146
|
-
if (!(!t || r.state === "closed" || Date.now() - i >
|
|
3155
|
+
return ne(e).then((t) => {
|
|
3156
|
+
if (!(!t || r.state === "closed" || Date.now() - i > ai)) try {
|
|
3147
3157
|
let n = r.createBufferSource();
|
|
3148
3158
|
n.buffer = t;
|
|
3149
|
-
let i =
|
|
3159
|
+
let i = re(e);
|
|
3150
3160
|
if (i === 1) n.connect(u);
|
|
3151
3161
|
else {
|
|
3152
3162
|
let e = r.createGain();
|
|
@@ -3157,30 +3167,30 @@ function li({ id: e, baseUrl: t, sounds: n, levels: r = {}, defaultVolume: i = .
|
|
|
3157
3167
|
}), !0;
|
|
3158
3168
|
},
|
|
3159
3169
|
markPlayed(e, t) {
|
|
3160
|
-
|
|
3170
|
+
ae(`${e}:${t}`);
|
|
3161
3171
|
},
|
|
3162
3172
|
startLoop(e, t) {
|
|
3163
|
-
|
|
3173
|
+
O(), n[e] && !m.has(e) && (t && y.set(e, t), _.add(e), ie(e));
|
|
3164
3174
|
},
|
|
3165
3175
|
stopLoop(e) {
|
|
3166
|
-
_.delete(e),
|
|
3176
|
+
_.delete(e), w(e);
|
|
3167
3177
|
},
|
|
3168
3178
|
getSettings: () => a && !b ? a.getSettings() : c,
|
|
3169
|
-
setVolume: a ? a.setVolume : (e) =>
|
|
3179
|
+
setVolume: a ? a.setVolume : (e) => D({
|
|
3170
3180
|
volume: e,
|
|
3171
|
-
muted:
|
|
3181
|
+
muted: oi(e) === 0 && c.muted
|
|
3172
3182
|
}),
|
|
3173
|
-
setMuted: a ? a.setMuted : (e) =>
|
|
3174
|
-
toggleMuted: a ? a.toggleMuted : () =>
|
|
3183
|
+
setMuted: a ? a.setMuted : (e) => D({ muted: !!e }),
|
|
3184
|
+
toggleMuted: a ? a.toggleMuted : () => D({ muted: !c.muted }),
|
|
3175
3185
|
subscribe(e) {
|
|
3176
|
-
return
|
|
3186
|
+
return O(), g.add(e), () => g.delete(e);
|
|
3177
3187
|
}
|
|
3178
3188
|
};
|
|
3179
3189
|
}
|
|
3180
3190
|
// src/games/connect4/connect4Sounds.js
|
|
3181
|
-
var Z =
|
|
3191
|
+
var Z = ui({
|
|
3182
3192
|
id: "connect4",
|
|
3183
|
-
baseUrl: () =>
|
|
3193
|
+
baseUrl: () => ei("connect4"),
|
|
3184
3194
|
sounds: {
|
|
3185
3195
|
invite: "invite.ogg",
|
|
3186
3196
|
start: "start.ogg",
|
|
@@ -3191,45 +3201,45 @@ var Z = li({
|
|
|
3191
3201
|
draw: "draw.ogg",
|
|
3192
3202
|
close: "close.ogg"
|
|
3193
3203
|
}
|
|
3194
|
-
}),
|
|
3195
|
-
function
|
|
3196
|
-
e.status === "won" ? Z.play(
|
|
3204
|
+
}), di = 140, Q = /* @__PURE__ */ new Map(), fi = /* @__PURE__ */ new Set(), $ = null, pi = (e, t) => e != null && t != null && String(e) === String(t), mi = () => typeof window < "u" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
3205
|
+
function hi(e, t) {
|
|
3206
|
+
e.status === "won" ? Z.play(pi(e.winnerId, e.ownId) ? "win" : "lose", { key: t }) : e.status === "draw" ? Z.play("draw", { key: t }) : e.status === "active" && pi(e.turnId, e.ownId) && Z.play("turn", { key: t });
|
|
3197
3207
|
}
|
|
3198
|
-
function
|
|
3208
|
+
function gi(e) {
|
|
3199
3209
|
let t = Q.get(e);
|
|
3200
3210
|
if (!t) return;
|
|
3201
3211
|
clearTimeout(t.timer), Q.delete(e), Z.play("drop", { key: e });
|
|
3202
3212
|
let n = setTimeout(() => {
|
|
3203
|
-
|
|
3204
|
-
},
|
|
3205
|
-
|
|
3213
|
+
fi.delete(n), hi(t.game, e);
|
|
3214
|
+
}, di);
|
|
3215
|
+
fi.add(n);
|
|
3206
3216
|
}
|
|
3207
|
-
function
|
|
3217
|
+
function _i(e) {
|
|
3208
3218
|
let t = e.lastMove?.eventId;
|
|
3209
3219
|
if (!t || Q.has(t)) return;
|
|
3210
|
-
let n =
|
|
3220
|
+
let n = mi() ? 0 : 440;
|
|
3211
3221
|
Q.set(t, {
|
|
3212
3222
|
game: e,
|
|
3213
|
-
timer: setTimeout(() =>
|
|
3223
|
+
timer: setTimeout(() => gi(t), n)
|
|
3214
3224
|
});
|
|
3215
3225
|
}
|
|
3216
|
-
function
|
|
3217
|
-
t ? t.status === "invited" && e.status === "active" ? Z.play("start", { key: e.lastEventId }) : e.ply > t.ply ?
|
|
3226
|
+
function vi(e, t) {
|
|
3227
|
+
t ? t.status === "invited" && e.status === "active" ? Z.play("start", { key: e.lastEventId }) : e.ply > t.ply ? _i(e) : (e.status === "closed" && e.closedBy != null || e.status === "declined") && t.status !== e.status && Z.play("close", { key: e.gameId }) : e.status === "invited" && pi(e.guestId, e.ownId) && Z.play("invite", { key: e.inviteEventId });
|
|
3218
3228
|
}
|
|
3219
|
-
var
|
|
3220
|
-
function
|
|
3229
|
+
var yi = () => $ != null;
|
|
3230
|
+
function bi() {
|
|
3221
3231
|
if ($) return $;
|
|
3222
3232
|
Z.start();
|
|
3223
|
-
let e =
|
|
3233
|
+
let e = Jr.subscribe((e, t) => {
|
|
3224
3234
|
e.games !== t.games && Object.entries(e.games).forEach(([e, n]) => {
|
|
3225
3235
|
let r = t.games[e];
|
|
3226
|
-
n.game && n.game !== "connect4" || n !== r && n.ownId != null &&
|
|
3236
|
+
n.game && n.game !== "connect4" || n !== r && n.ownId != null && vi(n, r);
|
|
3227
3237
|
});
|
|
3228
3238
|
}), t = () => {
|
|
3229
|
-
$ === t && ($ = null, e(), Q.forEach(({ timer: e }) => clearTimeout(e)), Q.clear(),
|
|
3239
|
+
$ === t && ($ = null, e(), Q.forEach(({ timer: e }) => clearTimeout(e)), Q.clear(), fi.forEach(clearTimeout), fi.clear());
|
|
3230
3240
|
};
|
|
3231
3241
|
return $ = t, t;
|
|
3232
3242
|
}
|
|
3233
|
-
export {
|
|
3243
|
+
export { x as C, S, L as _, ui as a, ce as b, $r as c, Jr as d, ir as f, R as g, pn as h, bi as i, Qr as l, En as m, yi as n, ni as o, wn as p, gi as r, ei as s, Z as t, X as u, Yt as v, m as w, Ce as x, P as y };
|
|
3234
3244
|
|
|
3235
|
-
//# sourceMappingURL=connect4Sounds-
|
|
3245
|
+
//# sourceMappingURL=connect4Sounds-Cv0q31VW.js.map
|