@caisual/kit 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kit.js +127 -16
- package/dist/node.js +77 -18
- package/dist/overlay.js +109 -30
- package/dist/runtime.js +79 -18
- package/dist/types/api.d.ts +1 -0
- package/dist/types/contracts/immagine.d.ts +27 -0
- package/dist/types/contracts/index.d.ts +2 -0
- package/dist/types/contracts/manifest.d.ts +4 -1
- package/dist/types/contracts/match-result.d.ts +16 -0
- package/dist/types/contracts/overlay.d.ts +7 -1
- package/dist/types/daily.d.ts +14 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/node/index.d.ts +4 -0
- package/dist/types/overlay/i18n.d.ts +7 -0
- package/dist/types/overlay/styles.d.ts +1 -1
- package/dist/types/overlay/ui-model.d.ts +4 -0
- package/dist/types/overlay/ui.d.ts +2 -0
- package/dist/types/protocollo.d.ts +8 -0
- package/dist/types/runtime/index.d.ts +4 -0
- package/dist/types/server/index.d.ts +12 -1
- package/dist/types/stanza/nucleo.d.ts +3 -0
- package/dist/types/stanza/tipi.d.ts +11 -0
- package/package.json +1 -1
package/dist/overlay.js
CHANGED
|
@@ -102,6 +102,8 @@ var CAMPI = /* @__PURE__ */ new Set([
|
|
|
102
102
|
"name",
|
|
103
103
|
"description",
|
|
104
104
|
"cover",
|
|
105
|
+
"card",
|
|
106
|
+
"icon",
|
|
105
107
|
"screenshots",
|
|
106
108
|
"tags",
|
|
107
109
|
"languages",
|
|
@@ -221,12 +223,21 @@ function validaManifest(valore) {
|
|
|
221
223
|
}
|
|
222
224
|
const description = stringaDefault(dati, "description", "", errori);
|
|
223
225
|
if (description.length > 500) errori.push("description: must be at most 500 characters.");
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
const immagini = { cover: "", card: "", icon: "" };
|
|
227
|
+
const usati = /* @__PURE__ */ new Set();
|
|
228
|
+
for (const campo of ["cover", "card", "icon"]) {
|
|
229
|
+
const path = dati[campo];
|
|
230
|
+
if (path === void 0 || path === null) errori.push(`${campo}: is required.`);
|
|
231
|
+
else if (typeof path !== "string" || !percorsoRelativo(path)) errori.push(`${campo}: must be a relative file path inside client/ without query, fragment, or parent segments.`);
|
|
232
|
+
else {
|
|
233
|
+
if (!/\.(png|jpe?g|webp)$/i.test(path)) errori.push(`${campo}: must be a PNG, JPEG or WebP file.`);
|
|
234
|
+
const canonical = decodeURIComponent(path);
|
|
235
|
+
if (usati.has(canonical)) errori.push(`${campo}: each image must use a different file; cover, card and icon cannot share a path.`);
|
|
236
|
+
usati.add(canonical);
|
|
237
|
+
immagini[campo] = path;
|
|
238
|
+
}
|
|
229
239
|
}
|
|
240
|
+
const { cover, card, icon } = immagini;
|
|
230
241
|
const screenshots = [];
|
|
231
242
|
if (dati.screenshots !== void 0) {
|
|
232
243
|
if (!Array.isArray(dati.screenshots)) errori.push("screenshots: must be an array of relative file paths.");
|
|
@@ -256,8 +267,7 @@ function validaManifest(valore) {
|
|
|
256
267
|
errori.push("language: must be a BCP 47 language tag such as en, it, or pt-BR.");
|
|
257
268
|
}
|
|
258
269
|
const languages2 = [];
|
|
259
|
-
if (dati.languages ===
|
|
260
|
-
else if (!Array.isArray(dati.languages) || dati.languages.length === 0) {
|
|
270
|
+
if (!Array.isArray(dati.languages) || dati.languages.length === 0) {
|
|
261
271
|
errori.push("languages: must be a non-empty array of BCP 47 language tags.");
|
|
262
272
|
} else for (const [index, raw] of dati.languages.entries()) {
|
|
263
273
|
const tag = normalizeLanguage(raw);
|
|
@@ -265,6 +275,7 @@ function validaManifest(valore) {
|
|
|
265
275
|
else if (languages2.includes(tag)) errori.push(`languages[${index}]: duplicate language ${tag}.`);
|
|
266
276
|
else languages2.push(tag);
|
|
267
277
|
}
|
|
278
|
+
if (!languages2.includes("en")) errori.push("languages: English is always required alongside the game's own languages.");
|
|
268
279
|
const language = languages2[0] ?? legacyLanguage;
|
|
269
280
|
if (dati.language !== void 0 && dati.languages !== void 0 && legacyLanguage.toLowerCase() !== language.toLowerCase()) {
|
|
270
281
|
errori.push("language: must match the first entry in languages when both are present.");
|
|
@@ -420,12 +431,14 @@ function validaManifest(valore) {
|
|
|
420
431
|
continue;
|
|
421
432
|
}
|
|
422
433
|
for (const campo of Object.keys(board)) {
|
|
423
|
-
if (!["source", "label", "periods"].includes(campo)) errori.push(`boards.${id2}.${campo}: unknown field.`);
|
|
434
|
+
if (!["source", "label", "periods", "day"].includes(campo)) errori.push(`boards.${id2}.${campo}: unknown field.`);
|
|
424
435
|
}
|
|
425
436
|
if (board.source !== "client" && board.source !== "server") {
|
|
426
437
|
errori.push(`boards.${id2}.source: must be "client" or "server".`);
|
|
427
438
|
valido = false;
|
|
428
439
|
}
|
|
440
|
+
if (board.day !== void 0 && board.day !== "submit" && board.day !== "start") errori.push(`boards.${id2}.day: must be "submit" or "start".`);
|
|
441
|
+
if (board.day === "start" && board.source !== "server") errori.push(`boards.${id2}.day: start requires source "server".`);
|
|
429
442
|
const label = testoFacoltativo(board, "label", 48, `boards.${id2}`, errori);
|
|
430
443
|
let periods = ["all-time"];
|
|
431
444
|
if (board.periods !== void 0) {
|
|
@@ -436,6 +449,7 @@ function validaManifest(valore) {
|
|
|
436
449
|
if (valido) Object.defineProperty(boards, id2, { value: {
|
|
437
450
|
source: board.source,
|
|
438
451
|
periods,
|
|
452
|
+
...board.day === void 0 ? {} : { day: board.day },
|
|
439
453
|
...label === void 0 ? {} : { label }
|
|
440
454
|
}, enumerable: true, configurable: true, writable: true });
|
|
441
455
|
}
|
|
@@ -632,6 +646,8 @@ function validaManifest(valore) {
|
|
|
632
646
|
name,
|
|
633
647
|
description,
|
|
634
648
|
cover,
|
|
649
|
+
card,
|
|
650
|
+
icon,
|
|
635
651
|
screenshots,
|
|
636
652
|
tags,
|
|
637
653
|
languages: languages2,
|
|
@@ -657,10 +673,10 @@ function validaManifest(valore) {
|
|
|
657
673
|
|
|
658
674
|
// ../contracts/src/overlay.ts
|
|
659
675
|
var OVERLAY_PANELS = ["home", "room", "invite", "friends", "voice", "boards"];
|
|
660
|
-
function overlayConfiguration(manifest, coverUrl = null, invite = null) {
|
|
676
|
+
function overlayConfiguration(manifest, coverUrl = null, invite = null, iconUrl = null) {
|
|
661
677
|
const validated = validaManifest(manifest);
|
|
662
678
|
if (!validated.ok) throw new Error("The overlay manifest is invalid.");
|
|
663
|
-
return { manifest: validated.manifest, coverUrl, invite };
|
|
679
|
+
return { manifest: validated.manifest, coverUrl, iconUrl, invite };
|
|
664
680
|
}
|
|
665
681
|
function record(value) {
|
|
666
682
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
@@ -740,8 +756,9 @@ function validOverlaySessionState(value) {
|
|
|
740
756
|
if (data.waiting !== null && (!exact(waiting, ["players", "min", "max"]) || !Object.values(waiting).every((v) => Number.isInteger(v) && Number(v) >= 0 && Number(v) <= 24))) return false;
|
|
741
757
|
if (data.resume !== null && (!exact(resume, ["version", "code", "mode", "updatedAt"]) || resume.version !== 1 || !text(resume.code) || !nullable(resume.mode) || !finite(resume.updatedAt))) return false;
|
|
742
758
|
if (data.room === null) return true;
|
|
743
|
-
if (!exact(room, ["code", "mode", "status", "host", "you", "players", "countdownAt", "connection", "closedCode", "limits", "lobby", "persistent", "delayMs", "requestRole"]) || !room) return false;
|
|
744
|
-
const limits = record(room.limits);
|
|
759
|
+
if (!exact(room, ["code", "mode", "status", "host", "you", "players", "countdownAt", "connection", "closedCode", "limits", "lobby", "persistent", "delayMs", "requestRole", ..."result" in (room ?? {}) ? ["result"] : [], ..."rematch" in (room ?? {}) ? ["rematch"] : []]) || !room) return false;
|
|
760
|
+
const limits = record(room.limits), rematch = record(room.rematch);
|
|
761
|
+
if (room.rematch !== void 0 && room.rematch !== null && (!exact(rematch, ["keepSetup", "autoStart"]) || typeof rematch.keepSetup !== "boolean" || typeof rematch.autoStart !== "boolean")) return false;
|
|
745
762
|
return text(room.code) && nullable(room.mode) && nullable(room.host) && nullable(room.you) && ["lobby", "countdown", "playing", "finished", "ended"].includes(String(room.status)) && ["connecting", "connected", "reconnecting", "disconnected", "ended", "closed", "replaced"].includes(String(room.connection)) && ["countdownAt", "closedCode", "delayMs"].every((key) => room[key] === null || finite(room[key])) && ["lobby", "persistent", "requestRole"].every((key) => typeof room[key] === "boolean") && exact(limits, ["min", "max"]) && Object.values(limits).every((v) => Number.isInteger(v) && Number(v) >= 1 && Number(v) <= 24) && Array.isArray(room.players) && room.players.length <= 24 && room.players.every((value2) => {
|
|
746
763
|
const player = record(value2);
|
|
747
764
|
return exact(player, ["id", "name", "guest", "role", "team", "ready", "connected"]) && player !== null && text(player.id) && text(player.name) && nullable(player.role) && (player.team === null || Number.isInteger(player.team) && Number(player.team) >= 1 && Number(player.team) <= 24) && ["guest", "ready", "connected"].every((key) => typeof player[key] === "boolean");
|
|
@@ -759,6 +776,32 @@ function validOverlayVoice(value) {
|
|
|
759
776
|
});
|
|
760
777
|
}
|
|
761
778
|
|
|
779
|
+
// ../contracts/src/match-result.ts
|
|
780
|
+
function readMatchResult(value, playerIds) {
|
|
781
|
+
const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
782
|
+
const result = object(value);
|
|
783
|
+
if (!result || !Array.isArray(result.standings)) return null;
|
|
784
|
+
const known = new Set(playerIds), seen = /* @__PURE__ */ new Set();
|
|
785
|
+
const standings = [];
|
|
786
|
+
for (const item of result.standings) {
|
|
787
|
+
const row = object(item);
|
|
788
|
+
if (!row || typeof row.playerId !== "string" || !known.has(row.playerId) || seen.has(row.playerId)) continue;
|
|
789
|
+
seen.add(row.playerId);
|
|
790
|
+
standings.push({
|
|
791
|
+
playerId: row.playerId,
|
|
792
|
+
...typeof row.score === "number" && Number.isFinite(row.score) ? { score: row.score } : {},
|
|
793
|
+
...typeof row.rank === "number" && Number.isSafeInteger(row.rank) && row.rank > 0 ? { rank: row.rank } : {}
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
if (!standings.length) return null;
|
|
797
|
+
return {
|
|
798
|
+
standings,
|
|
799
|
+
...Array.isArray(result.winners) ? { winners: [...new Set(result.winners.filter((id) => typeof id === "string" && seen.has(id)))] } : {},
|
|
800
|
+
...typeof result.draw === "boolean" ? { draw: result.draw } : {},
|
|
801
|
+
...typeof result.unit === "string" ? { unit: result.unit } : {}
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
|
|
762
805
|
// src/errors.ts
|
|
763
806
|
function creaErrore(code, message) {
|
|
764
807
|
return Object.assign(new Error(message), { name: "CaisualError", code });
|
|
@@ -1158,6 +1201,13 @@ var words = {
|
|
|
1158
1201
|
ended: ["Game finished", "Partita conclusa", "Partida terminada", "Partie termin\xE9e", "Spiel beendet", "Partida encerrada"],
|
|
1159
1202
|
rematchReady: ["{n}/{max} ready", "{n}/{max} pronti", "{n}/{max} listos", "{n}/{max} pr\xEAts", "{n}/{max} bereit", "{n}/{max} prontos"],
|
|
1160
1203
|
rematchStart: ["Start rematch", "Avvia rivincita", "Iniciar revancha", "Lancer la revanche", "Revanche starten", "Iniciar revanche"],
|
|
1204
|
+
won: ["You won", "Hai vinto", "Has ganado", "Vous avez gagn\xE9", "Du hast gewonnen", "Voc\xEA venceu"],
|
|
1205
|
+
lost: ["You lost", "Hai perso", "Has perdido", "Vous avez perdu", "Du hast verloren", "Voc\xEA perdeu"],
|
|
1206
|
+
draw: ["Draw", "Pareggio", "Empate", "\xC9galit\xE9", "Unentschieden", "Empate"],
|
|
1207
|
+
standings: ["Standings", "Piazzamenti", "Posiciones", "R\xE9sultats", "Platzierungen", "Coloca\xE7\xF5es"],
|
|
1208
|
+
points: ["points", "punti", "puntos", "points", "Punkte", "pontos"],
|
|
1209
|
+
time: ["time", "tempo", "tiempo", "temps", "Zeit", "tempo"],
|
|
1210
|
+
distance: ["distance", "distanza", "distancia", "distance", "Distanz", "dist\xE2ncia"],
|
|
1161
1211
|
again: ["Play again", "Gioca ancora", "Jugar de nuevo", "Rejouer", "Erneut spielen", "Jogar novamente"],
|
|
1162
1212
|
newRoom: ["New room. Share the new invite.", "Nuova stanza. Condividi il nuovo invito.", "Nueva sala. Comparte la invitaci\xF3n.", "Nouvelle salle. Partagez le lien.", "Neuer Raum. Neue Einladung teilen.", "Nova sala. Compartilhe o convite."],
|
|
1163
1213
|
watching: ["Watching", "In osservazione", "Observando", "Spectateur", "Zuschauen", "Assistindo"],
|
|
@@ -1312,7 +1362,9 @@ function reduceUi(model, action) {
|
|
|
1312
1362
|
function visiblePanel(model) {
|
|
1313
1363
|
const current = phase(model.session);
|
|
1314
1364
|
if (current === "boot" || current === "attaching" || current === "matching" || current === "error") return current;
|
|
1365
|
+
if (model.session?.room?.limits.max === 1 && ["room", "invite"].includes(model.panel ?? "")) return "home";
|
|
1315
1366
|
if (model.panel !== "auto") return model.panel;
|
|
1367
|
+
if (model.session?.room?.limits.max === 1 && current === "lobby") return null;
|
|
1316
1368
|
return current === "home" ? "home" : current === "lobby" ? "room" : current === "countdown" ? "countdown" : null;
|
|
1317
1369
|
}
|
|
1318
1370
|
function primaryAction(manifest, mode) {
|
|
@@ -1336,28 +1388,39 @@ function startReason(manifest, session) {
|
|
|
1336
1388
|
function canPlayAgain(session) {
|
|
1337
1389
|
if (phase(session) !== "ended") return false;
|
|
1338
1390
|
if (session?.kind === "local") return true;
|
|
1339
|
-
if (session?.room?.status === "finished") return session.kind === "room" && session.room.connection === "connected" && session.room.players.some((p) => p.id === session.room.you && p.connected && p.role !== "spectator" && !p.ready);
|
|
1340
|
-
return session?.kind === "room" && (!session.room?.lobby || session.room.host === session.room.you);
|
|
1391
|
+
if (session?.room?.status === "finished") return session.kind === "room" && session.room.connection === "connected" && (session.room.limits.max === 1 || session.room.players.some((p) => p.id === session.room.you && p.connected && p.role !== "spectator" && !p.ready));
|
|
1392
|
+
return session?.kind === "room" && (session.room?.limits.max === 1 || !session.room?.lobby || session.room.host === session.room.you);
|
|
1341
1393
|
}
|
|
1342
1394
|
function normalizeInvite(code) {
|
|
1343
1395
|
const value = code.toUpperCase().replace(/[\s-]/g, "");
|
|
1344
1396
|
return /^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{6}$/.test(value) ? value : null;
|
|
1345
1397
|
}
|
|
1398
|
+
function matchPresentation(session) {
|
|
1399
|
+
const room = session?.room;
|
|
1400
|
+
if (!room || !["finished", "ended"].includes(room.status)) return null;
|
|
1401
|
+
const result = readMatchResult(room.result, room.players.map((p) => p.id));
|
|
1402
|
+
if (!result) return null;
|
|
1403
|
+
const own = session?.kind === "room" && room.players.some((p) => p.id === room.you && p.role !== "spectator") && result.standings.some((p) => p.playerId === room.you);
|
|
1404
|
+
const first = result.standings[0];
|
|
1405
|
+
const winners = result.winners ?? result.standings.filter((p, i) => i === 0 || first.rank !== void 0 && p.rank === first.rank).map((p) => p.playerId);
|
|
1406
|
+
return { result, outcome: !own ? "ended" : result.draw ? "draw" : winners.includes(room.you) ? "won" : "lost" };
|
|
1407
|
+
}
|
|
1346
1408
|
|
|
1347
1409
|
// src/overlay/styles.ts
|
|
1348
1410
|
var styles = `
|
|
1411
|
+
.game-icon{width:28px;height:28px;aspect-ratio:1;object-fit:contain;border-radius:7px;flex:none;vertical-align:middle}.game-icon-title{width:56px;height:56px;margin-bottom:12px}
|
|
1349
1412
|
.safe-area-probe{position:fixed;visibility:hidden;pointer-events:none;padding:env(safe-area-inset-top,0px) env(safe-area-inset-right,0px) env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px)}
|
|
1350
1413
|
:host{all:initial;position:fixed;inset:0;z-index:10000;pointer-events:none;font:15px/1.45 system-ui,sans-serif;color:#f4f4f1;color-scheme:dark;--accent:#a8efc5}
|
|
1351
|
-
[data-layout],[data-surface],.sr{pointer-events:none}*{box-sizing:border-box}button,input,select{font:inherit}button,a,input,select{touch-action:manipulation}button,select,input{border:1px solid #ffffff30;background:#25292b;color:inherit;border-radius:12px;min-height:44px;padding:10px 14px}button{cursor:pointer}button:disabled{opacity:.45;cursor:default}button:hover:not(:disabled){background:#343b3a}button:focus-visible,a:focus-visible,input:focus-visible,select:focus-visible{outline:3px solid var(--accent);outline-offset:3px}a{color:var(--accent)}.primary{background:var(--accent);color:var(--accent-ink,#11221b);border-color:transparent;font-weight:700}.primary:hover:not(:disabled){filter:brightness(1.1);background:var(--accent)}.quiet{background:transparent}label{display:grid;gap:6px;text-align:left}select,input{width:100%;min-width:0}h1,h2,p{margin:0}h1{font-size:clamp(26px,5vw,42px);line-height:1.1;letter-spacing:-.035em}h2{font-size:20px}small,.muted{color:#bdc5c1}.stack{display:grid;gap:16px}.row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.row>*{flex:0 1 auto}.row .grow,.grow{flex:1}.split{display:grid;grid-template-columns:1fr 1fr;gap:10px}.pill{position:absolute;top:max(10px,env(safe-area-inset-top));right:max(10px,env(safe-area-inset-right));display:flex;height:44px;border:1px solid #ffffff35;border-radius:24px;background:#171e20eF;box-shadow:0 4px 20px #0004;pointer-events:auto;overflow:hidden}.pill button{border:0;border-radius:0;padding:8px 13px;background:transparent}.pill button:focus-visible{outline-offset:-4px}.pill small{margin-left:8px}.backdrop{position:absolute;inset:0;background:#0b151ce8;backdrop-filter:blur(10px);pointer-events:auto;display:grid;place-items:center;padding:max(16px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));overflow:auto}.backdrop.home{background-color:#142127;background-size:
|
|
1414
|
+
[data-layout],[data-surface],.sr{pointer-events:none}*{box-sizing:border-box}button,input,select{font:inherit}button,a,input,select{touch-action:manipulation}button,select,input{border:1px solid #ffffff30;background:#25292b;color:inherit;border-radius:12px;min-height:44px;padding:10px 14px}button{cursor:pointer}button:disabled{opacity:.45;cursor:default}button:hover:not(:disabled){background:#343b3a}button:focus-visible,a:focus-visible,input:focus-visible,select:focus-visible{outline:3px solid var(--accent);outline-offset:3px}a{color:var(--accent)}.primary{background:var(--accent);color:var(--accent-ink,#11221b);border-color:transparent;font-weight:700}.primary:hover:not(:disabled){filter:brightness(1.1);background:var(--accent)}.quiet{background:transparent}label{display:grid;gap:6px;text-align:left}select,input{width:100%;min-width:0}h1,h2,p{margin:0}h1{font-size:clamp(26px,5vw,42px);line-height:1.1;letter-spacing:-.035em}h2{font-size:20px}small,.muted{color:#bdc5c1}.stack{display:grid;gap:16px}.row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.row>*{flex:0 1 auto}.row .grow,.grow{flex:1}.split{display:grid;grid-template-columns:1fr 1fr;gap:10px}.pill{position:absolute;top:max(10px,env(safe-area-inset-top));right:max(10px,env(safe-area-inset-right));display:flex;height:44px;border:1px solid #ffffff35;border-radius:24px;background:#171e20eF;box-shadow:0 4px 20px #0004;pointer-events:auto;overflow:hidden}.pill button{border:0;border-radius:0;padding:8px 13px;background:transparent}.pill button:focus-visible{outline-offset:-4px}.pill small{margin-left:8px}.backdrop{position:absolute;inset:0;background:#0b151ce8;backdrop-filter:blur(10px);pointer-events:auto;display:grid;place-items:center;padding:max(16px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));overflow:auto}.backdrop.home{background-color:#142127;background-size:contain;background-repeat:no-repeat;background-position:center}.dialog{position:relative;width:min(100%,540px);max-height:100%;overflow:auto;overscroll-behavior:contain;background:#141b1df5;border:1px solid #ffffff25;border-radius:22px;padding:24px;box-shadow:0 20px 80px #0005}.dialog.wide{width:min(100%,700px)}.top{display:flex;align-items:center;gap:12px;margin-bottom:18px}.top h2{flex:1}.tabs{display:flex;gap:6px;flex-wrap:wrap;border-bottom:1px solid #ffffff25;padding-bottom:12px}.tabs button{min-height:36px;padding:6px 10px}.tabs [aria-current=true]{border-color:var(--accent)}.roster{list-style:none;padding:0;margin:0;display:grid;gap:8px;max-height:32dvh;overflow:auto}.roster li{display:flex;align-items:center;gap:8px;padding:10px;background:#ffffff08;border-radius:10px}.roster .name{flex:1;overflow-wrap:anywhere}.badge{border:1px solid #ffffff30;border-radius:6px;padding:2px 6px;font-size:12px}.code{font-size:24px;letter-spacing:.13em;font-variant-numeric:tabular-nums}.notice,.error{border-radius:10px;padding:10px;background:#a8efc514;overflow-wrap:anywhere}.error{background:#ff8b7720;color:#ffd2c9}.countdown{font-size:88px;line-height:1;text-align:center;font-variant-numeric:tabular-nums}.ended{position:absolute;bottom:max(12px,env(safe-area-inset-bottom));left:50%;transform:translateX(-50%);max-width:calc(100% - 24px);width:max-content;background:#171e20f5;pointer-events:auto;border:1px solid #ffffff30;border-radius:16px;padding:10px;display:flex;align-items:center;justify-content:center;gap:8px;flex-wrap:wrap}.ended [data-rematch-players]{max-width:100%;max-height:3.2em;overflow:auto;overflow-wrap:anywhere}.standings{list-style:none;margin:0;padding:0;flex-basis:100%;max-height:20dvh;overflow:auto;font-size:13px}.standings li{display:flex;justify-content:space-between;gap:16px;overflow-wrap:anywhere}.ended{max-height:calc(100dvh - 80px);overflow:auto}.ended strong{padding:0 8px}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.table-wrap{overflow:auto;max-height:38dvh}table{width:100%;border-collapse:collapse;text-align:left}th,td{padding:9px 6px;border-bottom:1px solid #ffffff20}td:nth-child(3){text-align:right}td small{display:block}.self{background:#ffffff0a}.checkbox{display:flex;align-items:center;gap:8px;font-size:13px}.checkbox input{width:18px;min-height:18px}.full{width:100%}
|
|
1352
1415
|
[hidden]{display:none!important}.voice-peers{list-style:none;margin:0;padding:0;display:grid;gap:10px}.voice-peers li{border:1px solid #ffffff25;border-radius:12px;padding:12px;display:grid;gap:8px}.voice-peers [data-speaking=true]{border-color:var(--accent)}.voice-peers input{width:100%;accent-color:var(--accent);padding:0}.voice-peers label{font-size:13px}.pill .voice-toggle{width:44px;padding:8px}.voice-toggle[data-voice-state=on][data-muted=false]{color:var(--accent)}
|
|
1353
1416
|
.boot{position:absolute;inset:0;z-index:2;isolation:isolate;display:grid;place-items:center;overflow:auto;overscroll-behavior:contain;padding:max(100px,env(safe-area-inset-top)) max(24px,env(safe-area-inset-right)) max(48px,env(safe-area-inset-bottom)) max(24px,env(safe-area-inset-left));background:#0b151c;opacity:1;transition:opacity .4s ease;pointer-events:auto;outline:none}
|
|
1354
1417
|
.boot::before,.boot::after{content:"";position:fixed;inset:0;pointer-events:none;z-index:-1}.boot::before{background:radial-gradient(ellipse at 50% 38%,color-mix(in srgb,var(--accent),transparent 80%),transparent 65%)}.boot::after{background:radial-gradient(ellipse at 50% 38%,#0b151c20,#0b151cd9 85%),linear-gradient(#0b151c66,#0b151cbf)}
|
|
1355
|
-
.boot-cover{position:fixed;inset:0;z-index:-2;width:100%;height:100%;object-fit:
|
|
1418
|
+
.boot-cover{position:fixed;inset:0;z-index:-2;width:100%;height:100%;aspect-ratio:3 / 2;object-fit:contain;filter:blur(20px);opacity:.65;pointer-events:none}
|
|
1356
1419
|
.boot-brand{position:absolute;top:max(28px,env(safe-area-inset-top));left:max(32px,env(safe-area-inset-left));display:flex;align-items:center;gap:10px;font-size:14px;font-weight:650;letter-spacing:.02em;color:#f4f4f1b3}.boot-brand span{display:grid;place-items:center;width:36px;height:36px;border:1px solid #ffffff25;border-radius:12px;background:#171e20af;box-shadow:0 4px 20px #0004;color:var(--boot-accent);font-size:20px;font-weight:800}
|
|
1357
1420
|
.boot-content{width:min(100%,900px);text-align:center;display:grid;justify-items:center;gap:24px}.boot h1{max-width:16ch;font-size:clamp(44px,8vw,108px);font-weight:800;line-height:1.04;letter-spacing:-.05em;overflow-wrap:anywhere;text-wrap:balance;color:var(--boot-accent);text-shadow:0 20px 80px #0005}
|
|
1358
1421
|
.boot-progress{width:112px;height:3px;border-radius:12px;background:#ffffff20;overflow:hidden;margin-top:12px}.boot-progress span{display:block;width:44%;height:100%;border-radius:inherit;background:var(--boot-accent);animation:boot-progress 1.8s ease-in-out infinite}.boot-status{max-width:42ch;min-height:3em;font-size:14px;line-height:1.5;color:#d3dad6;text-wrap:balance}.boot-recovery{min-height:44px}.boot-recovery .row{justify-content:center}.boot-leaving{opacity:0;pointer-events:none}
|
|
1359
1422
|
@keyframes boot-progress{0%{transform:translateX(-110%)}100%{transform:translateX(340%)}}
|
|
1360
|
-
@media(max-width:480px){.dialog{padding:18px;border-radius:18px}.split{grid-template-columns:1fr 1fr;gap:8px}.tabs{gap:4px}.tabs button{font-size:13px;padding:6px 8px}.pill button:focus-visible{outline-offset:-4px}.pill small{display:none}.ended{gap:6px}.ended strong{font-size:13px}.ended button{padding:8px 10px;font-size:13px}.roster{max-height:28dvh}}
|
|
1423
|
+
@media(max-width:480px){.dialog{padding:18px;border-radius:18px}.split{grid-template-columns:1fr 1fr;gap:8px}.tabs{gap:4px}.tabs button{font-size:13px;padding:6px 8px}.pill button:focus-visible{outline-offset:-4px}.pill small{display:none}.ended{gap:6px}.standings{list-style:none;margin:0;padding:0;flex-basis:100%;max-height:20dvh;overflow:auto;font-size:13px}.standings li{display:flex;justify-content:space-between;gap:16px;overflow-wrap:anywhere}.ended{max-height:calc(100dvh - 80px);overflow:auto}.ended strong{font-size:13px}.ended button{padding:8px 10px;font-size:13px}.roster{max-height:28dvh}}
|
|
1361
1424
|
@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto}.boot{transition:none}.boot-progress span{animation:none;transform:translateX(65%)}}
|
|
1362
1425
|
`;
|
|
1363
1426
|
|
|
@@ -1556,7 +1619,9 @@ function mountOverlay(input) {
|
|
|
1556
1619
|
if (live.textContent !== text) live.textContent = text;
|
|
1557
1620
|
};
|
|
1558
1621
|
const controls = () => [...root.querySelectorAll('button:not(:disabled),a[href],input:not(:disabled),select:not(:disabled),[tabindex="0"]')].filter((el) => !el.closest("[hidden]"));
|
|
1559
|
-
const
|
|
1622
|
+
const soloMode = (mode) => (mode === null || manifest.modes.some((item) => item.id === mode)) && risolviModalita(manifest, mode).players.max === 1;
|
|
1623
|
+
const solo = () => model.session?.room?.limits.max === 1;
|
|
1624
|
+
const roomCode = () => solo() ? null : model.session?.room?.code ?? null;
|
|
1560
1625
|
const setPanel = (panel) => {
|
|
1561
1626
|
if (panel === "boards" && boards && !boards.state.query) {
|
|
1562
1627
|
const id = Object.keys(manifest.boards)[0];
|
|
@@ -1632,13 +1697,14 @@ function mountOverlay(input) {
|
|
|
1632
1697
|
}
|
|
1633
1698
|
}
|
|
1634
1699
|
function invitation() {
|
|
1700
|
+
if (solo()) return "";
|
|
1635
1701
|
const code = roomCode();
|
|
1636
1702
|
if (!code) return `<p>${t("noRoom")}</p>`;
|
|
1637
1703
|
return `<div class="row"><div class="grow"><small>${t("code")}</small><div class="code" data-room-code>${escape(code)}</div></div>${button("copy", "copy")}</div>${copyFallback ? `<label>${t("copyFailed")}<input data-control="invite-link" readonly value="${escape(copyFallback)}"></label>` : ""}`;
|
|
1638
1704
|
}
|
|
1639
1705
|
function navigation(panel) {
|
|
1640
1706
|
const items = [];
|
|
1641
|
-
if (model.session?.room) items.push(["room", "room"], ["invite", "copy"]);
|
|
1707
|
+
if (model.session?.room && !solo()) items.push(["room", "room"], ["invite", "copy"]);
|
|
1642
1708
|
items.push(["friends", "friends"]);
|
|
1643
1709
|
if (Object.keys(manifest.boards).length) items.push(["boards", "boards"]);
|
|
1644
1710
|
if (voiceEligible(manifest, model.session)) items.push(["voice", "voice"]);
|
|
@@ -1646,15 +1712,15 @@ function mountOverlay(input) {
|
|
|
1646
1712
|
}
|
|
1647
1713
|
function home() {
|
|
1648
1714
|
const selected = selectedMode(), action = primaryAction(manifest, model.mode), session = model.session;
|
|
1649
|
-
const hasRooms = manifest.modes.some((mode) => mode.execution === "room");
|
|
1650
|
-
return `<h1>${escape(manifest.name)}</h1><p class="muted" data-game-languages>${t("gameLanguages")}: ${escape(manifestLanguages(manifest).join(" \xB7 "))}</p><label>${t("mode")}<select data-control="mode"${disabled()}>${manifest.modes.map((mode) => `<option value="${escape(mode.id)}"${mode.id === model.mode ? " selected" : ""}>${escape(risolviPresentazione(manifest, mode.id, input.language).label)}</option>`).join("")}</select></label>
|
|
1715
|
+
const hasRooms = manifest.modes.some((mode) => mode.execution === "room" && risolviModalita(manifest, mode.id).players.max > 1);
|
|
1716
|
+
return `${input.configuration.iconUrl ? `<img class="game-icon game-icon-title" src="${escape(input.configuration.iconUrl)}" alt="" />` : ""}<h1>${escape(manifest.name)}</h1><p class="muted" data-game-languages>${t("gameLanguages")}: ${escape(manifestLanguages(manifest).join(" \xB7 "))}</p><label>${t("mode")}<select data-control="mode"${disabled()}>${manifest.modes.map((mode) => `<option value="${escape(mode.id)}"${mode.id === model.mode ? " selected" : ""}>${escape(risolviPresentazione(manifest, mode.id, input.language).label)}</option>`).join("")}</select></label>
|
|
1651
1717
|
${selected?.instructions ? `<p class="muted">${escape(resolveText(selected.instructions, input.language, manifestLanguages(manifest)[0]))}</p>` : ""}
|
|
1652
1718
|
${input.configuration.invite && phase(session) === "home" ? button("join-invite", "joinInvite", ' class="primary"', !session?.ready) : ""}
|
|
1653
1719
|
${action ? button("play", action.friends ? "friendsPlay" : "play", ' class="primary"', !session?.ready) : ""}
|
|
1654
1720
|
${selected?.matchmaking ? button("match", "find", "", !selected.matchmaking.defaults || !session?.ready) : ""}
|
|
1655
|
-
${session?.resume ? button("resume", "resume", "", !session.ready) + `<small>${escape(session.resume.code)}</small>` : ""}
|
|
1656
|
-
${hasRooms ? `<div class="split">${button("panel:join", "join", "", !session?.ready)}${manifest.spectators ? button("panel:watch", "watch", "", !session?.ready) : ""}</div>` : ""}
|
|
1657
|
-
${navigation("home")}<label class="checkbox"><input type="checkbox" data-control="shortcut"${model.shortcutEnabled ? " checked" : ""}>${t("shortcut")}</label>`;
|
|
1721
|
+
${session?.resume ? button("resume", "resume", "", !session.ready) + `<small>${escape(solo() || soloMode(session.resume.mode) ? "" : session.resume.code)}</small>` : ""}
|
|
1722
|
+
${hasRooms && !solo() ? `<div class="split">${button("panel:join", "join", "", !session?.ready)}${manifest.spectators ? button("panel:watch", "watch", "", !session?.ready) : ""}</div>` : ""}
|
|
1723
|
+
${solo() ? button("panel:exit", "exit", ' class="quiet"') : ""}${navigation("home")}<label class="checkbox"><input type="checkbox" data-control="shortcut"${model.shortcutEnabled ? " checked" : ""}>${t("shortcut")}</label>`;
|
|
1658
1724
|
}
|
|
1659
1725
|
function room() {
|
|
1660
1726
|
const session = model.session, room2 = session?.room;
|
|
@@ -1673,10 +1739,10 @@ function mountOverlay(input) {
|
|
|
1673
1739
|
const provider = input.crew, state = provider?.getSnapshot();
|
|
1674
1740
|
if (!provider || provider.unavailable || !state?.you) return `<p>${t(provider?.unavailable === "local" ? "localCrew" : "loginCrew")}</p>`;
|
|
1675
1741
|
const online = state.friends.filter((friend) => friend.online), party = state.party;
|
|
1676
|
-
const person = (p) => `<li
|
|
1742
|
+
const person = (p) => `<li>${p.game ? `<img class="game-icon" src="${escape(p.game.iconUrl)}" alt="" />` : ""}<span class="name">${escape(p.name)}<small>${p.game ? ` \xB7 ${escape(p.game.name)}` : ""}</small></span>${p.room && p.game ? button("follow", "follow", ` data-code="${escape(p.room.code)}" data-game="${escape(p.game.slug)}"`) : ""}${party?.leader === state.you.id && !party.members.some((member) => member.id === p.id) ? button("party-invite", "inviteParty", ` data-player="${escape(p.id)}"`) : ""}</li>`;
|
|
1677
1743
|
return `${!state.connected ? `<p>${t("reconnecting")}</p>` : ""}${party ? `<ul class="roster">${party.members.map(person).join("")}</ul>${button("party-leave", "leaveParty")}` : button("party-create", "createParty")}
|
|
1678
1744
|
${state.invites.map((invite) => `<div class="row"><span class="grow">${escape(invite.from.name)}</span>${button("party-accept", "accept", ` data-party="${escape(invite.party)}"`)}${button("party-decline", "decline", ` data-party="${escape(invite.party)}"`)}</div>`).join("")}
|
|
1679
|
-
${state.follow ? `<div class="row"><span class="grow"
|
|
1745
|
+
${state.follow ? `<div class="row"><span class="grow"><img class="game-icon" src="${escape(state.follow.game.iconUrl)}" alt="" /> ${escape(state.follow.from.name)} \xB7 ${escape(state.follow.game.name)}</span>${button("follow", "follow", ` data-code="${escape(state.follow.code)}" data-game="${escape(state.follow.game.slug)}"`)}</div>` : ""}
|
|
1680
1746
|
<h2>${t("online")}</h2>${online.length ? `<ul class="roster">${online.map(person).join("")}</ul>` : `<p class="muted">${t("noFriends")}</p>`}`;
|
|
1681
1747
|
}
|
|
1682
1748
|
function leaderboard() {
|
|
@@ -1760,15 +1826,27 @@ function mountOverlay(input) {
|
|
|
1760
1826
|
function resize() {
|
|
1761
1827
|
if (!geometryFrame) geometryFrame = win.requestAnimationFrame(geometry);
|
|
1762
1828
|
}
|
|
1829
|
+
function resultBar() {
|
|
1830
|
+
const presentation = matchPresentation(model.session);
|
|
1831
|
+
if (!presentation) return `<strong>${t("ended")}</strong>`;
|
|
1832
|
+
const room2 = model.session.room, { result } = presentation;
|
|
1833
|
+
const unit = result.unit && ["points", "time", "distance"].includes(result.unit) ? t(result.unit) : result.unit;
|
|
1834
|
+
const rows = result.standings.map((p, i) => {
|
|
1835
|
+
const name = room2.players.find((player) => player.id === p.playerId).name;
|
|
1836
|
+
const score = p.score === void 0 ? "" : `<span>${escape(String(p.score))}${unit ? ` ${escape(unit)}` : ""}</span>`;
|
|
1837
|
+
return `<li><span>${p.rank ?? i + 1}. ${escape(name)}</span>${score}</li>`;
|
|
1838
|
+
}).join("");
|
|
1839
|
+
return `<strong data-outcome>${t(presentation.outcome)}</strong><ol class="standings" aria-label="${t("standings")}">${rows}</ol>`;
|
|
1840
|
+
}
|
|
1763
1841
|
function rematchBar() {
|
|
1764
1842
|
const session = model.session, room2 = session?.room;
|
|
1765
|
-
if (!room2 || room2.status !== "finished") return "";
|
|
1843
|
+
if (!room2 || room2.status !== "finished" || solo()) return "";
|
|
1766
1844
|
const active = room2.players.filter((p) => p.connected && p.role !== "spectator");
|
|
1767
1845
|
const ready = active.filter((p) => p.ready), host2 = session.kind === "room" && room2.host === room2.you;
|
|
1768
1846
|
const canStart = room2.connection === "connected" && active.length >= room2.limits.min && ready.length === active.length;
|
|
1769
1847
|
return `<small role="status" data-rematch-ready>${t("rematchReady", { n: ready.length, max: active.length })}</small>
|
|
1770
1848
|
${ready.length ? `<small data-rematch-players>${ready.map((p) => escape(p.name)).join(", ")}</small>` : ""}
|
|
1771
|
-
${host2 ? button("restart", "rematchStart", ' class="primary"', !canStart) : `<small>${t("waitHost")}</small>`}`;
|
|
1849
|
+
${room2.rematch?.autoStart ? "" : host2 ? button("restart", "rematchStart", ' class="primary"', !canStart) : `<small>${t("waitHost")}</small>`}`;
|
|
1772
1850
|
}
|
|
1773
1851
|
function render() {
|
|
1774
1852
|
if (disposed) return;
|
|
@@ -1779,9 +1857,9 @@ function mountOverlay(input) {
|
|
|
1779
1857
|
const previousScroll = root.querySelector(".dialog")?.scrollTop ?? 0;
|
|
1780
1858
|
const selection = focused?.tagName === "INPUT" ? { start: focused.selectionStart, end: focused.selectionEnd } : null;
|
|
1781
1859
|
const crewState = input.crew?.getSnapshot(), invitations = (crewState?.invites.length ?? 0) + (crewState?.follow ? 1 : 0);
|
|
1782
|
-
const label = current === "watching" ? t("watching") : room2?.connection === "reconnecting" ? t("reconnecting") : room2?.code ?? "Caisual";
|
|
1860
|
+
const label = current === "watching" ? t("watching") : room2?.connection === "reconnecting" ? t("reconnecting") : solo() ? "Caisual" : room2?.code ?? "Caisual";
|
|
1783
1861
|
surface.innerHTML = current === "boot" ? "" : `<div class="pill" data-reserve><button type="button" data-action="menu" aria-label="${t("menu")}" aria-expanded="${!!panel}">C<span aria-hidden="true"><small>${escape(label)}</small></span></button>${voiceEligible(manifest, model.session) && model.session?.kind === "room" ? `<button type="button" class="voice-toggle" data-voice-toggle data-action="panel:voice"></button>` : ""}${invitations ? `<button type="button" data-action="panel:friends" aria-label="${t("friends")} (${invitations})">${invitations}</button>` : ""}</div>
|
|
1784
|
-
${current === "ended" && !panel ? `<div class="ended" data-reserve role="region" aria-label="${t("ended")}"
|
|
1862
|
+
${current === "ended" && !panel ? `<div class="ended" data-reserve role="region" aria-label="${t("ended")}">${resultBar()}${boards?.state.saving ? `<small role="status" data-saving>${t(boards.state.saving)}</small>` : ""}${canPlayAgain(model.session) ? button("again", "again", ' class="primary"') : model.session?.kind === "room" && room2?.status !== "finished" && !solo() ? `<small>${t("waitHost")}</small>` : ""}${rematchBar()}${Object.keys(manifest.boards).length ? button("panel:boards", "boards") : ""}${button("panel:home", "homeMenu")}</div>` : ""}
|
|
1785
1863
|
${panel ? `<div class="backdrop${panel === "home" ? " home" : ""}"><section class="dialog${panel === "boards" || panel === "friends" ? " wide" : ""}" role="dialog" aria-modal="true" aria-labelledby="panel-title" tabindex="-1"><div class="top"><h2 id="panel-title">${title(panel)}</h2><button type="button" data-action="close" aria-label="${t("close")}">\xD7</button></div><div class="stack">${content(panel)}${model.error ? `<p class="error" role="alert" data-error>${t(errorText(model.error))}</p>` : ""}${model.session?.resumeError ? `<p class="error" role="alert">${t("saveFailed")}</p>` : ""}${model.notice ? `<p class="notice" role="status">${escape(model.notice)}</p>` : ""}</div></section></div>` : ""}`;
|
|
1786
1864
|
for (const element of surface.querySelectorAll(".pill,.backdrop,.ended")) element.style.pointerEvents = "auto";
|
|
1787
1865
|
const backdrop = root.querySelector(".backdrop.home");
|
|
@@ -1871,6 +1949,7 @@ function mountOverlay(input) {
|
|
|
1871
1949
|
if (!canPlayAgain(model.session)) break;
|
|
1872
1950
|
if (model.session?.kind === "local") void perform("local.start", { mode: model.session.mode ?? model.mode });
|
|
1873
1951
|
else if (model.session?.room?.status === "finished") void perform("room.restart", {});
|
|
1952
|
+
else if (solo()) void perform("room.create", { mode: model.session?.room?.mode ?? null });
|
|
1874
1953
|
else void perform("room.create", { mode: model.session?.room?.mode ?? null }, async () => {
|
|
1875
1954
|
setPanel("invite");
|
|
1876
1955
|
dispatch({ type: "notice", notice: t("newRoom") });
|
package/dist/runtime.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// src/daily.ts
|
|
2
|
+
function prossimaMezzanotteUtc(ora) {
|
|
3
|
+
return (Math.floor(ora / 864e5) + 1) * 864e5;
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
// ../contracts/src/slug.ts
|
|
2
7
|
var NOMI_RISERVATI = [
|
|
3
8
|
"www",
|
|
@@ -321,6 +326,7 @@ var GRAZIA_MS = 6e4;
|
|
|
321
326
|
var STANZA_VUOTA_MS = 5 * 6e4;
|
|
322
327
|
var ATTESA_RIVINCITA_MS = 2 * 6e4;
|
|
323
328
|
var COUNTDOWN_MS = 3e3;
|
|
329
|
+
var GRAZIA_GIORNALIERA_MS = 10 * 6e4;
|
|
324
330
|
var RIPOSO_TICK_MS = 3e4;
|
|
325
331
|
var INATTIVITA_MS = 10 * 6e4;
|
|
326
332
|
var SCADENZA_PERSISTENTE_MS = 30 * 24 * 60 * 6e4;
|
|
@@ -383,10 +389,13 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
383
389
|
const nucleo = this;
|
|
384
390
|
const daily = {
|
|
385
391
|
get day() {
|
|
386
|
-
return nucleo.
|
|
392
|
+
return nucleo.richiediDati().daily.day;
|
|
387
393
|
},
|
|
388
394
|
get seed() {
|
|
389
|
-
return
|
|
395
|
+
return nucleo.richiediDati().daily.seed;
|
|
396
|
+
},
|
|
397
|
+
get expiresAt() {
|
|
398
|
+
return nucleo.richiediDati().daily.expiresAt;
|
|
390
399
|
}
|
|
391
400
|
};
|
|
392
401
|
this.room = {
|
|
@@ -441,7 +450,7 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
441
450
|
nucleo.impostaSquadraDalServer(idGiocatore(player), team);
|
|
442
451
|
},
|
|
443
452
|
end(result, options) {
|
|
444
|
-
nucleo.richiediFine(result, options?.rematch
|
|
453
|
+
nucleo.richiediFine(result, options?.rematch ?? false);
|
|
445
454
|
},
|
|
446
455
|
save(key, value) {
|
|
447
456
|
return nucleo.salva(key, value);
|
|
@@ -471,7 +480,11 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
471
480
|
},
|
|
472
481
|
board: {
|
|
473
482
|
submit(player, board, score, options = {}) {
|
|
474
|
-
|
|
483
|
+
if (typeof board === "number") {
|
|
484
|
+
const active = nucleo.richiediDati().giocatori.filter((p) => p.role !== "spectator");
|
|
485
|
+
if (nucleo.configurazione.players.max !== 1 || active.length !== 1) throw erroreConCodice("board_player_required", "Specify the player when submitting a multiplayer score.");
|
|
486
|
+
nucleo.accodaPunteggio(active[0].id, player, board, typeof score === "object" ? score : {});
|
|
487
|
+
} else nucleo.accodaPunteggio(idGiocatore(player), board, score, options);
|
|
475
488
|
}
|
|
476
489
|
},
|
|
477
490
|
daily,
|
|
@@ -502,7 +515,8 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
502
515
|
if (salvato !== void 0) {
|
|
503
516
|
nucleo.dati = salvato;
|
|
504
517
|
nucleo.tickRateSincronizzato = salvato.tickRate;
|
|
505
|
-
const daAggiornare = salvato.ultimoInputAt === void 0 || salvato.ultimoCambioStatoAt === void 0;
|
|
518
|
+
const daAggiornare = salvato.ultimoInputAt === void 0 || salvato.ultimoCambioStatoAt === void 0 || salvato.daily === void 0;
|
|
519
|
+
salvato.daily ??= nucleo.contestoGiornaliero();
|
|
506
520
|
salvato.ultimoInputAt ??= adattatore.ora();
|
|
507
521
|
salvato.ultimoCambioStatoAt ??= salvato.ultimoInputAt;
|
|
508
522
|
nucleo.ultimoStatoOsservato = JSON.stringify(salvato.state);
|
|
@@ -534,6 +548,7 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
534
548
|
const ora = this.adattatore.ora();
|
|
535
549
|
this.dati = {
|
|
536
550
|
versione: 1,
|
|
551
|
+
daily: this.contestoGiornaliero(ora),
|
|
537
552
|
id,
|
|
538
553
|
mode,
|
|
539
554
|
status: "lobby",
|
|
@@ -576,7 +591,8 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
576
591
|
return true;
|
|
577
592
|
}
|
|
578
593
|
get configurazione() {
|
|
579
|
-
|
|
594
|
+
const mode = risolviModalita(this.manifest, this.dati?.mode ?? null);
|
|
595
|
+
return mode.players.max === 1 ? { ...mode, lobby: false } : mode;
|
|
580
596
|
}
|
|
581
597
|
info(playerId) {
|
|
582
598
|
if (this.dati === null) return null;
|
|
@@ -899,7 +915,7 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
899
915
|
else await this.rimuoviGiocatore(player, "timeout");
|
|
900
916
|
}
|
|
901
917
|
if (this.dati.status === "countdown" && this.dati.countdownAt !== null && this.dati.countdownAt <= ora) {
|
|
902
|
-
const errore = this.erroreMinimi();
|
|
918
|
+
const errore = this.erroreMinimi(this.dati.countdownRivincita);
|
|
903
919
|
if (errore !== null) {
|
|
904
920
|
this.dati.status = "lobby";
|
|
905
921
|
this.dati.countdownAt = null;
|
|
@@ -1067,13 +1083,13 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1067
1083
|
if (player === void 0) throw erroreConCodice("player_not_found", "Player not found.");
|
|
1068
1084
|
return player;
|
|
1069
1085
|
}
|
|
1070
|
-
erroreMinimi() {
|
|
1086
|
+
erroreMinimi(saltaPronti = false) {
|
|
1071
1087
|
const connessi = this.richiediDati().giocatori.filter((player) => player.connected);
|
|
1072
1088
|
const attivi = connessi.filter((player) => player.role !== "spectator");
|
|
1073
1089
|
if (attivi.length < this.configurazione.players.min) {
|
|
1074
1090
|
return { code: "not_enough_players", message: "The room does not have enough players." };
|
|
1075
1091
|
}
|
|
1076
|
-
if (connessi.some((player) => !player.ready)) {
|
|
1092
|
+
if (!saltaPronti && connessi.some((player) => !player.ready)) {
|
|
1077
1093
|
return { code: "players_not_ready", message: "Every connected player must be ready." };
|
|
1078
1094
|
}
|
|
1079
1095
|
for (const role of this.manifest.roles) {
|
|
@@ -1095,31 +1111,48 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1095
1111
|
this.inviaErrore(player, "rematch_unavailable", "This room is not waiting for a rematch.");
|
|
1096
1112
|
return;
|
|
1097
1113
|
}
|
|
1114
|
+
if (this.configurazione.players.max === 1) {
|
|
1115
|
+
await this.avviaRivincita();
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1098
1118
|
if (player.role !== "spectator" && !player.ready) {
|
|
1099
1119
|
player.ready = true;
|
|
1100
1120
|
this.inviaGiocatori();
|
|
1101
|
-
await this.
|
|
1121
|
+
if (dati.rivincita?.autoStart && this.prontiRivincita()) await this.avviaRivincita();
|
|
1122
|
+
else await this.persistiEProgramma();
|
|
1102
1123
|
return;
|
|
1103
1124
|
}
|
|
1104
1125
|
if (dati.hostId !== player.id) return;
|
|
1105
|
-
|
|
1106
|
-
if (attivi.length < this.configurazione.players.min || attivi.some((item) => !item.ready)) {
|
|
1126
|
+
if (!this.prontiRivincita(dati.rivincita?.autoStart === true)) {
|
|
1107
1127
|
this.inviaErrore(player, "players_not_ready", "Enough connected players must be ready for the rematch.");
|
|
1108
1128
|
return;
|
|
1109
1129
|
}
|
|
1110
|
-
|
|
1130
|
+
await this.avviaRivincita();
|
|
1131
|
+
}
|
|
1132
|
+
prontiRivincita(anticipata = false) {
|
|
1133
|
+
const attivi = this.richiediDati().giocatori.filter((item) => item.connected && item.role !== "spectator");
|
|
1134
|
+
return attivi.filter((item) => item.ready).length >= this.configurazione.players.min && (anticipata || attivi.every((item) => item.ready));
|
|
1135
|
+
}
|
|
1136
|
+
async avviaRivincita() {
|
|
1137
|
+
const dati = this.richiediDati(), solo = this.configurazione.players.max === 1;
|
|
1138
|
+
const keepSetup = dati.rivincita?.keepSetup === true && !solo;
|
|
1139
|
+
dati.status = solo ? "playing" : keepSetup ? "countdown" : this.configurazione.lobby ? "lobby" : "playing";
|
|
1140
|
+
dati.countdownRivincita = keepSetup;
|
|
1141
|
+
dati.countdownAt = keepSetup ? this.adattatore.ora() + COUNTDOWN_MS : null;
|
|
1111
1142
|
dati.rivincitaFinoA = null;
|
|
1143
|
+
dati.rivincita = null;
|
|
1112
1144
|
dati.result = null;
|
|
1113
1145
|
dati.resultAt = null;
|
|
1114
1146
|
dati.ultimoInputAt = this.adattatore.ora();
|
|
1115
|
-
for (const item of dati.giocatori) item.ready = false;
|
|
1147
|
+
for (const item of dati.giocatori) item.ready = keepSetup && (dati.prontiPrecedenti?.includes(item.id) ?? false);
|
|
1148
|
+
dati.prontiPrecedenti = [];
|
|
1116
1149
|
await this.chiama(this.definizione.onRestart, this.room);
|
|
1117
1150
|
await this.applicaAzioni();
|
|
1118
1151
|
if (dati.status === "playing") {
|
|
1119
1152
|
await this.chiama(this.definizione.onStart, this.room);
|
|
1120
1153
|
}
|
|
1121
1154
|
await this.concludiEvento();
|
|
1122
|
-
if (dati.status === "lobby" || dati.status === "playing") {
|
|
1155
|
+
if (dati.status === "lobby" || dati.status === "playing" || dati.status === "countdown") {
|
|
1123
1156
|
this.inviaSnapshotTutti();
|
|
1124
1157
|
this.inviaGiocatori();
|
|
1125
1158
|
this.inviaStatus(this.adattatore.ora());
|
|
@@ -1138,13 +1171,14 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1138
1171
|
return;
|
|
1139
1172
|
}
|
|
1140
1173
|
dati.status = "countdown";
|
|
1174
|
+
dati.countdownRivincita = false;
|
|
1141
1175
|
dati.countdownAt = this.adattatore.ora() + COUNTDOWN_MS;
|
|
1142
1176
|
this.inviaStatus(dati.countdownAt);
|
|
1143
1177
|
await this.persistiEProgramma();
|
|
1144
1178
|
}
|
|
1145
1179
|
verificaCountdown() {
|
|
1146
1180
|
const dati = this.richiediDati();
|
|
1147
|
-
if (dati.status !== "countdown" || this.erroreMinimi() === null) return;
|
|
1181
|
+
if (dati.status !== "countdown" || this.erroreMinimi(dati.countdownRivincita) === null) return;
|
|
1148
1182
|
dati.status = "lobby";
|
|
1149
1183
|
dati.countdownAt = null;
|
|
1150
1184
|
this.inviaStatus(this.adattatore.ora());
|
|
@@ -1213,7 +1247,11 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1213
1247
|
giornata(ora = this.adattatore.ora()) {
|
|
1214
1248
|
return this.adattatore.giorno?.(ora) ?? giornoUtc(ora);
|
|
1215
1249
|
}
|
|
1216
|
-
|
|
1250
|
+
contestoGiornaliero(ora = this.adattatore.ora()) {
|
|
1251
|
+
const day = this.giornata(ora);
|
|
1252
|
+
return { day, seed: seedGiornata(this.manifest.id, day), expiresAt: prossimaMezzanotteUtc(ora) };
|
|
1253
|
+
}
|
|
1254
|
+
accodaPunteggio(playerId, board, score, options) {
|
|
1217
1255
|
if (!this.richiediDati().giocatori.some((player2) => player2.id === playerId)) {
|
|
1218
1256
|
throw new Error("Player not found.");
|
|
1219
1257
|
}
|
|
@@ -1224,7 +1262,19 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1224
1262
|
throw new TypeError("Score must be a non-negative safe integer.");
|
|
1225
1263
|
}
|
|
1226
1264
|
const submittedAt = this.adattatore.ora();
|
|
1227
|
-
const
|
|
1265
|
+
const daily = options.daily === true || options.day !== void 0;
|
|
1266
|
+
let day = daily ? this.giornata(submittedAt) : null;
|
|
1267
|
+
const start = this.manifest.boards?.[board]?.day === "start";
|
|
1268
|
+
if (options.day !== void 0 && (!start || options.daily === false)) {
|
|
1269
|
+
throw erroreConCodice("board_day_policy", "An explicit day requires a start-day board and a daily score.");
|
|
1270
|
+
}
|
|
1271
|
+
if (daily && start) {
|
|
1272
|
+
const run = this.richiediDati().daily;
|
|
1273
|
+
if (options.day === void 0) throw erroreConCodice("board_day_required", "Submit the daily score with room.daily.day.");
|
|
1274
|
+
if (options.day !== run.day) throw erroreConCodice("board_day_mismatch", "The score day must match room.daily.day.");
|
|
1275
|
+
if (submittedAt > run.expiresAt + GRAZIA_GIORNALIERA_MS) throw erroreConCodice("board_day_expired", "The starting day grace period has expired.");
|
|
1276
|
+
day = run.day;
|
|
1277
|
+
}
|
|
1228
1278
|
this.richiediDati().punteggi.push({
|
|
1229
1279
|
playerId,
|
|
1230
1280
|
board,
|
|
@@ -1412,6 +1462,7 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1412
1462
|
seed: seedStanza(dati.id),
|
|
1413
1463
|
status: dati.status,
|
|
1414
1464
|
result: dati.result,
|
|
1465
|
+
rematch: dati.status === "finished" ? dati.rivincita ?? null : null,
|
|
1415
1466
|
mode: dati.mode,
|
|
1416
1467
|
tick: dati.tick,
|
|
1417
1468
|
tickRate: dati.tickRate,
|
|
@@ -1433,6 +1484,7 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1433
1484
|
const dati = this.richiediDati();
|
|
1434
1485
|
this.broadcast({
|
|
1435
1486
|
t: "status",
|
|
1487
|
+
rematch: dati.status === "finished" ? dati.rivincita ?? null : null,
|
|
1436
1488
|
status: dati.status,
|
|
1437
1489
|
host: dati.hostId,
|
|
1438
1490
|
countdownAt: dati.countdownAt,
|
|
@@ -1505,6 +1557,10 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1505
1557
|
async concludiEvento() {
|
|
1506
1558
|
await this.applicaAzioni();
|
|
1507
1559
|
if (this.dati === null || this.dati.status === "ended") return;
|
|
1560
|
+
if (this.dati.status === "finished" && this.dati.rivincita?.autoStart && this.prontiRivincita()) {
|
|
1561
|
+
await this.avviaRivincita();
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1508
1564
|
this.inviaGuadagniCambiati();
|
|
1509
1565
|
const stato = await this.verificaStato();
|
|
1510
1566
|
if (stato === null || this.stanzaTerminata()) return;
|
|
@@ -1600,6 +1656,11 @@ var NucleoStanza = class _NucleoStanza {
|
|
|
1600
1656
|
if (dati.status === "ended") return;
|
|
1601
1657
|
const giaFinita = dati.status === "finished";
|
|
1602
1658
|
dati.status = rematch ? "finished" : "ended";
|
|
1659
|
+
dati.rivincita = rematch ? {
|
|
1660
|
+
keepSetup: typeof rematch === "object" && rematch.keepSetup === true,
|
|
1661
|
+
autoStart: typeof rematch === "object" && rematch.autoStart === true
|
|
1662
|
+
} : null;
|
|
1663
|
+
dati.prontiPrecedenti = rematch ? dati.giocatori.filter((p) => p.ready).map((p) => p.id) : [];
|
|
1603
1664
|
dati.rivincitaFinoA = rematch ? this.adattatore.ora() + ATTESA_RIVINCITA_MS : null;
|
|
1604
1665
|
dati.timer = [];
|
|
1605
1666
|
if (rematch) for (const player of dati.giocatori) player.ready = false;
|
package/dist/types/api.d.ts
CHANGED