@caisual/kit 0.8.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 +529 -56
- package/dist/node.js +297 -77
- package/dist/overlay.js +360 -53
- package/dist/runtime.js +248 -47
- package/dist/server.js +2 -0
- package/dist/types/api.d.ts +2 -1
- package/dist/types/contracts/i18n.d.ts +12 -0
- package/dist/types/contracts/immagine.d.ts +27 -0
- package/dist/types/contracts/index.d.ts +5 -0
- package/dist/types/contracts/manifest.d.ts +14 -6
- package/dist/types/contracts/match-result.d.ts +16 -0
- package/dist/types/contracts/overlay.d.ts +16 -2
- package/dist/types/contracts/player.d.ts +1 -0
- package/dist/types/contracts/room-limits.d.ts +13 -0
- package/dist/types/daily.d.ts +14 -0
- package/dist/types/handshake.d.ts +4 -0
- package/dist/types/index.d.ts +24 -2
- package/dist/types/kit.d.ts +2 -0
- package/dist/types/node/index.d.ts +5 -0
- package/dist/types/overlay/host-bridge.d.ts +16 -0
- package/dist/types/overlay/i18n.d.ts +13 -0
- package/dist/types/overlay/index.d.ts +1 -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 +3 -1
- package/dist/types/protocollo.d.ts +13 -0
- package/dist/types/runtime/index.d.ts +6 -1
- package/dist/types/server/index.d.ts +17 -2
- package/dist/types/stanza/nucleo.d.ts +8 -2
- package/dist/types/stanza/tipi.d.ts +13 -0
- package/dist/types/text.d.ts +2 -0
- package/package.json +1 -1
package/dist/kit.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Caisual game kit v0.
|
|
1
|
+
// Caisual game kit v0.12.0
|
|
2
2
|
|
|
3
3
|
// ../contracts/src/slug.ts
|
|
4
4
|
var NOMI_RISERVATI = [
|
|
@@ -43,6 +43,46 @@ function isReservedSlug(value) {
|
|
|
43
43
|
return RISERVATI.has(value);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
// ../contracts/src/i18n.ts
|
|
47
|
+
function normalizeLanguage(value) {
|
|
48
|
+
if (typeof value !== "string" || value.length > 128) return null;
|
|
49
|
+
try {
|
|
50
|
+
return Intl.getCanonicalLocales(value)[0] ?? null;
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function manifestLanguages(manifest) {
|
|
56
|
+
return manifest.languages?.length ? [...manifest.languages] : [manifest.language ?? "en"];
|
|
57
|
+
}
|
|
58
|
+
function languageFallbacks(language, defaultLanguage = "en") {
|
|
59
|
+
const result = [];
|
|
60
|
+
let tag = normalizeLanguage(language);
|
|
61
|
+
while (tag) {
|
|
62
|
+
result.push(tag);
|
|
63
|
+
const parts = tag.split("-");
|
|
64
|
+
parts.pop();
|
|
65
|
+
if (parts.at(-1)?.length === 1) parts.pop();
|
|
66
|
+
tag = parts.join("-");
|
|
67
|
+
}
|
|
68
|
+
result.push(normalizeLanguage(defaultLanguage) ?? defaultLanguage);
|
|
69
|
+
return [...new Set(result)];
|
|
70
|
+
}
|
|
71
|
+
function resolveGameLanguage(preferences, languages2 = []) {
|
|
72
|
+
const declared = languages2.map(normalizeLanguage).filter((tag) => tag !== null);
|
|
73
|
+
const preferred = preferences.map(normalizeLanguage).filter((tag) => tag !== null);
|
|
74
|
+
if (!declared.length) return preferred[0] ?? "en";
|
|
75
|
+
for (const preference of preferred) {
|
|
76
|
+
for (const tag of languageFallbacks(preference, preference)) {
|
|
77
|
+
if (declared.includes(tag)) return tag;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return declared[0];
|
|
81
|
+
}
|
|
82
|
+
function isTextDictionary(value) {
|
|
83
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every((text) => typeof text === "string");
|
|
84
|
+
}
|
|
85
|
+
|
|
46
86
|
// ../contracts/src/manifest.ts
|
|
47
87
|
function risolviModalita(manifest, mode) {
|
|
48
88
|
const scelta = mode === null ? void 0 : manifest.modes.find((voce) => voce.id === mode);
|
|
@@ -62,8 +102,11 @@ var CAMPI = /* @__PURE__ */ new Set([
|
|
|
62
102
|
"name",
|
|
63
103
|
"description",
|
|
64
104
|
"cover",
|
|
105
|
+
"card",
|
|
106
|
+
"icon",
|
|
65
107
|
"screenshots",
|
|
66
108
|
"tags",
|
|
109
|
+
"languages",
|
|
67
110
|
"language",
|
|
68
111
|
"platform",
|
|
69
112
|
"orientation",
|
|
@@ -130,12 +173,32 @@ function stringaDefault(dati, campo, valoreDefault, errori) {
|
|
|
130
173
|
}
|
|
131
174
|
function testoFacoltativo(value, key, max, path, errors) {
|
|
132
175
|
if (value[key] === void 0) return void 0;
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
176
|
+
const check = (text2, field2) => {
|
|
177
|
+
if (typeof text2 !== "string" || text2.trim().length === 0 || text2.trim().length > max || /[\r\n\u0000-\u001f]/.test(text2)) {
|
|
178
|
+
errors.push(`${field2}: must contain 1-${max} characters on one line.`);
|
|
179
|
+
return void 0;
|
|
180
|
+
}
|
|
181
|
+
return text2.trim();
|
|
182
|
+
};
|
|
183
|
+
const text = value[key], field = `${path}.${key}`;
|
|
184
|
+
if (typeof text === "string") return check(text, field);
|
|
185
|
+
const translations = oggetto(text);
|
|
186
|
+
if (!translations || Object.keys(translations).length === 0) {
|
|
187
|
+
errors.push(`${field}: must be a string or a non-empty language-to-text object.`);
|
|
136
188
|
return void 0;
|
|
137
189
|
}
|
|
138
|
-
|
|
190
|
+
const result = {};
|
|
191
|
+
for (const [raw, text2] of Object.entries(translations)) {
|
|
192
|
+
const tag = normalizeLanguage(raw);
|
|
193
|
+
if (!tag) {
|
|
194
|
+
errors.push(`${field}.${raw}: must be a BCP 47 language tag.`);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (Object.hasOwn(result, tag)) errors.push(`${field}.${raw}: duplicate language.`);
|
|
198
|
+
const checked = check(text2, `${field}.${raw}`);
|
|
199
|
+
if (checked !== void 0) result[tag] = checked;
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
139
202
|
}
|
|
140
203
|
function validaManifest(valore) {
|
|
141
204
|
const errori = [];
|
|
@@ -160,12 +223,21 @@ function validaManifest(valore) {
|
|
|
160
223
|
}
|
|
161
224
|
const description = stringaDefault(dati, "description", "", errori);
|
|
162
225
|
if (description.length > 500) errori.push("description: must be at most 500 characters.");
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
+
}
|
|
168
239
|
}
|
|
240
|
+
const { cover, card, icon } = immagini;
|
|
169
241
|
const screenshots = [];
|
|
170
242
|
if (dati.screenshots !== void 0) {
|
|
171
243
|
if (!Array.isArray(dati.screenshots)) errori.push("screenshots: must be an array of relative file paths.");
|
|
@@ -190,10 +262,24 @@ function validaManifest(valore) {
|
|
|
190
262
|
}
|
|
191
263
|
}
|
|
192
264
|
}
|
|
193
|
-
const
|
|
194
|
-
if (!/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(
|
|
265
|
+
const legacyLanguage = stringaDefault(dati, "language", "en", errori);
|
|
266
|
+
if (!/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.test(legacyLanguage)) {
|
|
195
267
|
errori.push("language: must be a BCP 47 language tag such as en, it, or pt-BR.");
|
|
196
268
|
}
|
|
269
|
+
const languages2 = [];
|
|
270
|
+
if (!Array.isArray(dati.languages) || dati.languages.length === 0) {
|
|
271
|
+
errori.push("languages: must be a non-empty array of BCP 47 language tags.");
|
|
272
|
+
} else for (const [index, raw] of dati.languages.entries()) {
|
|
273
|
+
const tag = normalizeLanguage(raw);
|
|
274
|
+
if (!tag) errori.push(`languages[${index}]: must be a BCP 47 language tag.`);
|
|
275
|
+
else if (languages2.includes(tag)) errori.push(`languages[${index}]: duplicate language ${tag}.`);
|
|
276
|
+
else languages2.push(tag);
|
|
277
|
+
}
|
|
278
|
+
if (!languages2.includes("en")) errori.push("languages: English is always required alongside the game's own languages.");
|
|
279
|
+
const language = languages2[0] ?? legacyLanguage;
|
|
280
|
+
if (dati.language !== void 0 && dati.languages !== void 0 && legacyLanguage.toLowerCase() !== language.toLowerCase()) {
|
|
281
|
+
errori.push("language: must match the first entry in languages when both are present.");
|
|
282
|
+
}
|
|
197
283
|
let platform = "both";
|
|
198
284
|
if (dati.platform === void 0) errori.push("platform: is required.");
|
|
199
285
|
else if (typeof dati.platform !== "string" || !PLATFORM.has(dati.platform)) {
|
|
@@ -345,12 +431,14 @@ function validaManifest(valore) {
|
|
|
345
431
|
continue;
|
|
346
432
|
}
|
|
347
433
|
for (const campo of Object.keys(board)) {
|
|
348
|
-
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.`);
|
|
349
435
|
}
|
|
350
436
|
if (board.source !== "client" && board.source !== "server") {
|
|
351
437
|
errori.push(`boards.${id2}.source: must be "client" or "server".`);
|
|
352
438
|
valido = false;
|
|
353
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".`);
|
|
354
442
|
const label = testoFacoltativo(board, "label", 48, `boards.${id2}`, errori);
|
|
355
443
|
let periods = ["all-time"];
|
|
356
444
|
if (board.periods !== void 0) {
|
|
@@ -361,6 +449,7 @@ function validaManifest(valore) {
|
|
|
361
449
|
if (valido) Object.defineProperty(boards, id2, { value: {
|
|
362
450
|
source: board.source,
|
|
363
451
|
periods,
|
|
452
|
+
...board.day === void 0 ? {} : { day: board.day },
|
|
364
453
|
...label === void 0 ? {} : { label }
|
|
365
454
|
}, enumerable: true, configurable: true, writable: true });
|
|
366
455
|
}
|
|
@@ -557,8 +646,11 @@ function validaManifest(valore) {
|
|
|
557
646
|
name,
|
|
558
647
|
description,
|
|
559
648
|
cover,
|
|
649
|
+
card,
|
|
650
|
+
icon,
|
|
560
651
|
screenshots,
|
|
561
652
|
tags,
|
|
653
|
+
languages: languages2,
|
|
562
654
|
language,
|
|
563
655
|
platform,
|
|
564
656
|
orientation,
|
|
@@ -710,25 +802,29 @@ async function probeDevice(globals, timeoutMs = 1500) {
|
|
|
710
802
|
}
|
|
711
803
|
|
|
712
804
|
// ../contracts/src/overlay.ts
|
|
713
|
-
function overlayConfiguration(manifest, coverUrl = null, invite = null) {
|
|
805
|
+
function overlayConfiguration(manifest, coverUrl = null, invite = null, iconUrl = null) {
|
|
714
806
|
const validated = validaManifest(manifest);
|
|
715
807
|
if (!validated.ok) throw new Error("The overlay manifest is invalid.");
|
|
716
|
-
return { manifest: validated.manifest, coverUrl, invite };
|
|
808
|
+
return { manifest: validated.manifest, coverUrl, iconUrl, invite };
|
|
717
809
|
}
|
|
718
810
|
function record(value) {
|
|
719
811
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
720
812
|
}
|
|
721
813
|
function validOverlayHello(value) {
|
|
722
814
|
const hello = record(value), config = record(hello?.configuration);
|
|
723
|
-
return hello?.v === 1 && typeof hello.epoch === "string" && hello.epoch.length > 0 && hello.epoch.length <= 128 && config !== null && (config.coverUrl === null || typeof config.coverUrl === "string") && (config.invite === null || typeof config.invite === "string" && /^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{6}$/.test(config.invite)) && validaManifest(config.manifest).ok;
|
|
815
|
+
return hello?.v === 1 && typeof hello.epoch === "string" && hello.epoch.length > 0 && hello.epoch.length <= 128 && config !== null && (config.coverUrl === null || typeof config.coverUrl === "string") && (config.iconUrl === null || typeof config.iconUrl === "string") && (config.invite === null || typeof config.invite === "string" && /^[ABCDEFGHJKLMNPQRSTUVWXYZ23456789]{6}$/.test(config.invite)) && validaManifest(config.manifest).ok;
|
|
724
816
|
}
|
|
725
817
|
function normalizeOverlayHello(value) {
|
|
726
818
|
if (!validOverlayHello(value)) return null;
|
|
727
|
-
return { v: 1, epoch: value.epoch, configuration: overlayConfiguration(value.configuration.manifest, value.configuration.coverUrl, value.configuration.invite) };
|
|
819
|
+
return { v: 1, epoch: value.epoch, configuration: overlayConfiguration(value.configuration.manifest, value.configuration.coverUrl, value.configuration.invite, value.configuration.iconUrl) };
|
|
820
|
+
}
|
|
821
|
+
function validSafeArea(value) {
|
|
822
|
+
const area = record(value);
|
|
823
|
+
return area !== null && Object.keys(area).length === 4 && ["top", "right", "bottom", "left"].every((key) => typeof area[key] === "number" && Number.isFinite(area[key]) && Number(area[key]) >= 0 && Number(area[key]) <= 1e5);
|
|
728
824
|
}
|
|
729
825
|
function validOverlayView(value) {
|
|
730
826
|
const data = record(value);
|
|
731
|
-
return data !== null && Object.keys(data).every((key) => ["inputBlocked", "reservedRects", "shortcutEnabled"].includes(key)) && (data.shortcutEnabled === void 0 || typeof data.shortcutEnabled === "boolean") && typeof data.inputBlocked === "boolean" && Array.isArray(data.reservedRects) && data.reservedRects.length <= 8 && data.reservedRects.every((value2) => {
|
|
827
|
+
return data !== null && Object.keys(data).every((key) => ["inputBlocked", "reservedRects", "safeArea", "shortcutEnabled"].includes(key)) && (data.safeArea === void 0 || validSafeArea(data.safeArea)) && (data.shortcutEnabled === void 0 || typeof data.shortcutEnabled === "boolean") && typeof data.inputBlocked === "boolean" && Array.isArray(data.reservedRects) && data.reservedRects.length <= 8 && data.reservedRects.every((value2) => {
|
|
732
828
|
const rect = record(value2);
|
|
733
829
|
return rect !== null && Object.keys(rect).length === 4 && ["x", "y", "width", "height"].every((key) => typeof rect[key] === "number" && Number.isFinite(rect[key]) && rect[key] >= 0 && rect[key] <= 1e5);
|
|
734
830
|
});
|
|
@@ -759,6 +855,7 @@ function validOverlayRequest(value) {
|
|
|
759
855
|
return keys("role") && text("role");
|
|
760
856
|
case "room.team":
|
|
761
857
|
return keys("team") && Number.isInteger(args.team) && args.team >= 1 && args.team <= 24;
|
|
858
|
+
case "room.restart":
|
|
762
859
|
case "room.start":
|
|
763
860
|
case "session.cancel":
|
|
764
861
|
case "session.leave":
|
|
@@ -784,6 +881,191 @@ function validBoardDay(value) {
|
|
|
784
881
|
return Number.isFinite(at) && new Date(at).toISOString().slice(0, 10) === value;
|
|
785
882
|
}
|
|
786
883
|
|
|
884
|
+
// ../contracts/src/room-limits.ts
|
|
885
|
+
var MESSAGGI_GIOCO_AL_SECONDO = 20;
|
|
886
|
+
|
|
887
|
+
// ../contracts/src/match-result.ts
|
|
888
|
+
function readMatchResult(value, playerIds) {
|
|
889
|
+
const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
890
|
+
const result = object(value);
|
|
891
|
+
if (!result || !Array.isArray(result.standings)) return null;
|
|
892
|
+
const known = new Set(playerIds), seen = /* @__PURE__ */ new Set();
|
|
893
|
+
const standings = [];
|
|
894
|
+
for (const item of result.standings) {
|
|
895
|
+
const row = object(item);
|
|
896
|
+
if (!row || typeof row.playerId !== "string" || !known.has(row.playerId) || seen.has(row.playerId)) continue;
|
|
897
|
+
seen.add(row.playerId);
|
|
898
|
+
standings.push({
|
|
899
|
+
playerId: row.playerId,
|
|
900
|
+
...typeof row.score === "number" && Number.isFinite(row.score) ? { score: row.score } : {},
|
|
901
|
+
...typeof row.rank === "number" && Number.isSafeInteger(row.rank) && row.rank > 0 ? { rank: row.rank } : {}
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
if (!standings.length) return null;
|
|
905
|
+
return {
|
|
906
|
+
standings,
|
|
907
|
+
...Array.isArray(result.winners) ? { winners: [...new Set(result.winners.filter((id) => typeof id === "string" && seen.has(id)))] } : {},
|
|
908
|
+
...typeof result.draw === "boolean" ? { draw: result.draw } : {},
|
|
909
|
+
...typeof result.unit === "string" ? { unit: result.unit } : {}
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// src/overlay/i18n.ts
|
|
914
|
+
var languages = ["en", "it", "es", "fr", "de", "pt"];
|
|
915
|
+
var words = {
|
|
916
|
+
gameLanguages: ["Game languages", "Lingue del gioco", "Idiomas del juego", "Langues du jeu", "Spielsprachen", "Idiomas do jogo"],
|
|
917
|
+
loading: ["Loading game...", "Caricamento...", "Cargando...", "Chargement...", "Spiel wird geladen...", "Carregando..."],
|
|
918
|
+
loadingSlow: ["This game is taking longer than expected. You can wait a little longer or try again.", "Il gioco ci sta mettendo pi\xF9 del previsto. Puoi aspettare ancora un po\u2019 o riprovare.", "El juego est\xE1 tardando m\xE1s de lo esperado. Puedes esperar un poco m\xE1s o volver a intentarlo.", "Le jeu met plus de temps que pr\xE9vu. Vous pouvez patienter encore un peu ou r\xE9essayer.", "Das Spiel braucht l\xE4nger als erwartet. Du kannst noch etwas warten oder es erneut versuchen.", "O jogo est\xE1 demorando mais do que o esperado. Voc\xEA pode esperar mais um pouco ou tentar novamente."],
|
|
919
|
+
home: ["Play", "Gioca", "Jugar", "Jouer", "Spielen", "Jogar"],
|
|
920
|
+
homeMenu: ["Menu", "Menu", "Men\xFA", "Menu", "Men\xFC", "Menu"],
|
|
921
|
+
mode: ["Mode", "Modalit\xE0", "Modo", "Mode", "Modus", "Modo"],
|
|
922
|
+
play: ["Play", "Gioca", "Jugar", "Jouer", "Spielen", "Jogar"],
|
|
923
|
+
friendsPlay: ["Play with friends", "Gioca con amici", "Jugar con amigos", "Jouer entre amis", "Mit Freunden spielen", "Jogar com amigos"],
|
|
924
|
+
find: ["Find players", "Trova giocatori", "Buscar jugadores", "Trouver des joueurs", "Spieler finden", "Buscar jogadores"],
|
|
925
|
+
join: ["Join with code", "Entra con codice", "Entrar con c\xF3digo", "Rejoindre avec un code", "Mit Code beitreten", "Entrar com c\xF3digo"],
|
|
926
|
+
joinInvite: ["Join this room", "Entra in questa stanza", "Entrar en est\xE1 sala", "Rejoindre cette salle", "Diesem Raum beitreten", "Entrar nest\xE1 sala"],
|
|
927
|
+
watch: ["Watch a room", "Guarda una stanza", "Observar una sala", "Regarder une salle", "Raum ansehen", "Assistir a uma sala"],
|
|
928
|
+
resume: ["Resume", "Riprendi", "Continuar", "Reprendre", "Fortsetzen", "Continuar"],
|
|
929
|
+
room: ["Room", "Stanza", "Sala", "Salle", "Raum", "Sala"],
|
|
930
|
+
code: ["Room code", "Codice stanza", "C\xF3digo de sala", "Code de salle", "Raumcode", "C\xF3digo da sala"],
|
|
931
|
+
copy: ["Copy invite", "Copia invito", "Copiar invitaci\xF3n", "Copier le lien", "Einladung kopieren", "Copiar convite"],
|
|
932
|
+
copied: ["Invite copied", "Invito copiato", "Invitacion copiada", "Lien copi\xE9", "Einladung kopiert", "Convite copiado"],
|
|
933
|
+
copyFailed: ["Copy this link:", "Copia questo link:", "Copia este enlace:", "Copiez ce lien :", "Diesen Link kopieren:", "Copie este link:"],
|
|
934
|
+
joining: ["Joining room...", "Ingresso nella stanza...", "Entrando en la sala...", "Connexion \xE0 la salle...", "Raum wird betreten...", "Entrando na sala..."],
|
|
935
|
+
matching: ["Finding your people...", "Ricerca giocatori...", "Buscando jugadores...", "Recherche de joueurs...", "Spieler werden gesucht...", "Buscando jogadores..."],
|
|
936
|
+
queue: ["{n} / {max} players", "{n} / {max} giocatori", "{n} / {max} jugadores", "{n} / {max} joueurs", "{n} / {max} Spieler", "{n} / {max} jogadores"],
|
|
937
|
+
cancel: ["Cancel", "Annulla", "Cancelar", "Annuler", "Abbrechen", "Cancelar"],
|
|
938
|
+
close: ["Close", "Chiudi", "Cerrar", "Fermer", "Schlie\xDFen", "Fechar"],
|
|
939
|
+
back: ["Back", "Indietro", "Volver", "Retour", "Zur\xFCck", "Voltar"],
|
|
940
|
+
ready: ["Ready", "Pronto", "Listo", "Pr\xEAt", "Bereit", "Pronto"],
|
|
941
|
+
unready: ["Not ready", "Non pronto", "No listo", "Pas pr\xEAt", "Nicht bereit", "N\xE3o pronto"],
|
|
942
|
+
start: ["Start", "Inizia", "Empezar", "Commencer", "Starten", "Come\xE7ar"],
|
|
943
|
+
role: ["Role", "Ruolo", "Rol", "R\xF4le", "Rolle", "Fun\xE7\xE3o"],
|
|
944
|
+
team: ["Team", "Squadra", "Equipo", "\xC9quipe", "Team", "Equipe"],
|
|
945
|
+
host: ["Host", "Host", "Anfitrion", "H\xF4te", "Host", "Anfitri\xE3o"],
|
|
946
|
+
you: ["You", "Tu", "T\xFA", "Vous", "Du", "Voc\xEA"],
|
|
947
|
+
away: ["Away", "Assente", "Ausente", "Absent", "Abwesend", "Ausente"],
|
|
948
|
+
needPlayers: ["Waiting for more players", "In attesa di giocatori", "Esperando m\xE1s jugadores", "En attente de joueurs", "Weitere Spieler fehlen", "Esperando mais jogadores"],
|
|
949
|
+
needReady: ["Everyone needs to be ready", "Tutti devono essere pronti", "Todos deben estar listos", "Tout le monde doit \xEAtre pr\xEAt", "Alle m\xFCssen bereit sein", "Todos precisam estar prontos"],
|
|
950
|
+
needRoles: ["Fill the required roles", "Completa i ruoli richiesti", "Completa los roles", "Compl\xE9tez les r\xF4les", "Ben\xF6tigte Rollen besetzen", "Complete as fun\xE7\xF5es"],
|
|
951
|
+
needTeams: ["Choose the required teams", "Scegli le squadre richieste", "Elige los equipos", "Choisissez les \xE9quipes", "Teams auswahlen", "Escolha as equipes"],
|
|
952
|
+
waitHost: ["Waiting for the host", "In attesa dell'host", "Esperando al anfitrion", "En attente de l\u2019h\xF4te", "Warten auf den Host", "Esperando o anfitri\xE3o"],
|
|
953
|
+
starting: ["Starting in", "Si inizia tra", "Empieza en", "D\xE9but dans", "Start in", "Come\xE7a em"],
|
|
954
|
+
playing: ["Playing", "In partita", "Jugando", "En jeu", "Im Spiel", "Jogando"],
|
|
955
|
+
ended: ["Game finished", "Partita conclusa", "Partida terminada", "Partie termin\xE9e", "Spiel beendet", "Partida encerrada"],
|
|
956
|
+
rematchReady: ["{n}/{max} ready", "{n}/{max} pronti", "{n}/{max} listos", "{n}/{max} pr\xEAts", "{n}/{max} bereit", "{n}/{max} prontos"],
|
|
957
|
+
rematchStart: ["Start rematch", "Avvia rivincita", "Iniciar revancha", "Lancer la revanche", "Revanche starten", "Iniciar revanche"],
|
|
958
|
+
won: ["You won", "Hai vinto", "Has ganado", "Vous avez gagn\xE9", "Du hast gewonnen", "Voc\xEA venceu"],
|
|
959
|
+
lost: ["You lost", "Hai perso", "Has perdido", "Vous avez perdu", "Du hast verloren", "Voc\xEA perdeu"],
|
|
960
|
+
draw: ["Draw", "Pareggio", "Empate", "\xC9galit\xE9", "Unentschieden", "Empate"],
|
|
961
|
+
standings: ["Standings", "Piazzamenti", "Posiciones", "R\xE9sultats", "Platzierungen", "Coloca\xE7\xF5es"],
|
|
962
|
+
points: ["points", "punti", "puntos", "points", "Punkte", "pontos"],
|
|
963
|
+
time: ["time", "tempo", "tiempo", "temps", "Zeit", "tempo"],
|
|
964
|
+
distance: ["distance", "distanza", "distancia", "distance", "Distanz", "dist\xE2ncia"],
|
|
965
|
+
again: ["Play again", "Gioca ancora", "Jugar de nuevo", "Rejouer", "Erneut spielen", "Jogar novamente"],
|
|
966
|
+
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."],
|
|
967
|
+
watching: ["Watching", "In osservazione", "Observando", "Spectateur", "Zuschauen", "Assistindo"],
|
|
968
|
+
delay: ["{n}s delay", "Ritardo {n}s", "Retraso de {n}s", "Retard de {n}s", "{n}s Verz\xF6gerung", "Atraso de {n}s"],
|
|
969
|
+
exit: ["Exit", "Esci", "Salir", "Quitter", "Verlassen", "Sair"],
|
|
970
|
+
leaveNow: ["Leave for now", "Esci per ora", "Salir por ahora", "Quitter pour le moment", "Vor\xFCbergehend verlassen", "Sair por enquanto"],
|
|
971
|
+
leaveRoom: ["Leave room", "Lascia la stanza", "Abandonar sala", "Abandonner la salle", "Raum verlassen", "Deixar a sala"],
|
|
972
|
+
leaveHint: ["Your room stays available for Resume.", "La stanza resta disponibile con Riprendi.", "Podr\xE1s volver a est\xE1 sala.", "Vous pourrez reprendre cette salle.", "Du kannst den Raum fortsetzen.", "Voc\xEA pode voltar a est\xE1 sala."],
|
|
973
|
+
temporaryHint: ["The game continues. Rejoining may only be possible briefly.", "La partita continua. Il rientro pu\xF2 essere disponibile solo per poco.", "La partida continua. Volver puede ser posible solo por poco tiempo.", "La partie continue. Le retour peut \xEAtre limit\xE9.", "Das Spiel l\xE4uft weiter. R\xFCckkehr nur kurz m\xF6glich.", "A partida continua. O retorno pode ser limitado."],
|
|
974
|
+
abandonHint: ["Leave room gives up your place.", "Lascia la stanza libera il tuo posto.", "Abandonar libera tu plaza.", "Abandonner lib\xE8re votre place.", "Raum verlassen gibt deinen Platz frei.", "Deixar a sala libera sua vaga."],
|
|
975
|
+
reconnecting: ["Reconnecting...", "Riconnessione...", "Reconectando...", "Reconnexion...", "Verbindung wird erneuert...", "Reconectando..."],
|
|
976
|
+
replaced: ["Opened in another tab", "Aperta in un\u2019altra scheda", "Abierta en otra pest\xE1na", "Ouverte dans un autre onglet", "In anderem Tab ge\xF6ffnet", "Aberta em outra aba"],
|
|
977
|
+
error: ["Something went wrong. Try again.", "Qualcosa non va. Riprova.", "Algo sali\xF3 mal. Reintenta.", "Une erreur est survenue. R\xE9essayez.", "Etwas ist schiefgelaufen. Erneut versuchen.", "Algo deu errado. Tente novamente."],
|
|
978
|
+
noRoom: ["This room is no longer available.", "Questa stanza non \xE8 pi\xF9 disponibile.", "Esta sala ya no est\xE1 disponible.", "Cette salle n'est plus disponible.", "Dieser Raum ist nicht mehr verf\xFCgbar.", "Esta sala n\xE3o est\xE1 mais disponivel."],
|
|
979
|
+
full: ["This room is full.", "La stanza \xE8 piena.", "La sala est\xE1 llena.", "Cette salle est pleine.", "Dieser Raum ist voll.", "Esta sala est\xE1 cheia."],
|
|
980
|
+
noMatch: ["No match this time. Try again.", "Nessun gruppo trovato. Riprova.", "No hay grupo. Reintenta.", "Aucun groupe trouv\xE9. R\xE9essayez.", "Keine Gruppe gefunden. Erneut versuchen.", "Nenhum grupo encontrado. Tente novamente."],
|
|
981
|
+
invalidCode: ["Enter a six-character room code.", "Inserisci un codice di sei caratteri.", "Escribe un c\xF3digo de seis caracteres.", "Entrez un code de six caracteres.", "Sechsstelligen Raumcode eingeben.", "Digite um c\xF3digo de seis caracteres."],
|
|
982
|
+
refused: ["The room did not accept that change.", "La stanza ha rifiutato la modifica.", "La sala rechaz\xF3 el cambio.", "La salle a refus\xE9 ce changement.", "Der Raum hat die \xC4nderung abgelehnt.", "A sala recusou a altera\xE7\xE3o."],
|
|
983
|
+
unavailable: ["Unavailable right now", "Non disponibile ora", "No disponible ahora", "Indisponible pour le moment", "Derzeit nicht verf\xFCgbar", "Indisponivel agora"],
|
|
984
|
+
offline: ["Connection unavailable. Try again.", "Connessione non disponibile. Riprova.", "Sin conexi\xF3n. Reintenta.", "Connexion indisponible. R\xE9essayez.", "Keine Verbindung. Erneut versuchen.", "Sem conex\xE3o. Tente novamente."],
|
|
985
|
+
saveFailed: ["Keep the room code. Resume could not be saved.", "Conserva il codice. Riprendi non \xE8 stato salvato.", "Guarda el c\xF3digo. No se pudo guardar el regreso.", "Gardez le code. La reprise ne peut pas \xEAtre enregistr\xE9e.", "Raumcode aufbewahren. Fortsetzen nicht gespeichert.", "Guarde o c\xF3digo. O retorno n\xE3o foi salvo."],
|
|
986
|
+
boards: ["Leaderboard", "Classifica", "Clasificaci\xF3n", "Classement", "Bestenliste", "Classifica\xE7\xE3o"],
|
|
987
|
+
board: ["Board", "Classifica", "Tabla", "Classement", "Bestenliste", "Tabela"],
|
|
988
|
+
daily: ["Daily", "Giornaliera", "Diaria", "Du jour", "T\xE4glich", "Di\xE1ria"],
|
|
989
|
+
allTime: ["All time", "Di sempre", "Hist\xF3rica", "Tous les temps", "Gesamt", "Geral"],
|
|
990
|
+
accounts: ["Accounts", "Account", "Cuentas", "Comptes", "Konten", "Contas"],
|
|
991
|
+
guests: ["Guests", "Ospiti", "Invitados", "Invit\xE9s", "G\xE4ste", "Visitantes"],
|
|
992
|
+
category: ["Category", "Categoria", "Categoria", "Cat\xE9gorie", "Kategorie", "Categoria"],
|
|
993
|
+
period: ["Period", "Periodo", "Per\xEDodo", "P\xE9riode", "Zeitraum", "Per\xEDodo"],
|
|
994
|
+
rank: ["Rank", "Posizione", "Puesto", "Rang", "Platz", "Posicao"],
|
|
995
|
+
score: ["Score", "Punteggio", "Puntos", "Score", "Punkte", "Pontos"],
|
|
996
|
+
verified: ["Verified", "Verificato", "Verificado", "V\xE9rifi\xE9", "Verifiziert", "Verificado"],
|
|
997
|
+
own: ["Your best", "Il tuo record", "Tu record", "Votre record", "Dein Rekord", "Seu recorde"],
|
|
998
|
+
empty: ["No scores yet", "Nessun punteggio", "A\xFAn no hay puntos", "Aucun score", "Noch keine Punkte", "Ainda sem pontos"],
|
|
999
|
+
saving: ["Saving score...", "Salvataggio punteggio...", "Guardando puntos...", "Enregistrement du score...", "Punkte werden gespeichert...", "Salvando pontos..."],
|
|
1000
|
+
saved: ["Your best is on the board", "Il tuo record \xE8 in classifica", "Tu record est\xE1 en la tabla", "Votre record est au classement", "Dein Rekord ist eingetragen", "Seu recorde est\xE1 na tabela"],
|
|
1001
|
+
bestAlready: ["Your best is already on the board", "Il tuo record era gi\xE0 in classifica", "Tu record ya estaba en la tabla", "Votre record est d\xE9j\xE0 au classement", "Dein Rekord ist bereits eingetragen", "Seu recorde j\xE1 est\xE1 na tabela"],
|
|
1002
|
+
refresh: ["Refresh", "Aggiorna", "Actualizar", "Actualiser", "Aktualisieren", "Atualizar"],
|
|
1003
|
+
refreshHint: ["Score not visible yet. Refresh to check.", "Punteggio non ancora visibile. Aggiorna per controllare.", "Puntos a\xFAn no visibles. Actualiza.", "Score pas encore visible. Actualisez.", "Punkte noch nicht sichtbar. Aktualisieren.", "Pontos ainda n\xE3o visiveis. Atualize."],
|
|
1004
|
+
friends: ["Friends & party", "Amici e gruppo", "Amigos y grupo", "Amis et groupe", "Freunde & Gruppe", "Amigos e grupo"],
|
|
1005
|
+
localCrew: ["Friends and party are unavailable in local preview.", "Amici e gruppo non disponibili in anteprima locale.", "Amigos y grupo no disponibles en la vista local.", "Amis et groupe indisponibles en aper\xE7u local.", "Freunde und Gruppe in lokaler Vorschau nicht verf\xFCgbar.", "Amigos e grupo indispon\xEDveis na pr\xE9via local."],
|
|
1006
|
+
loginCrew: ["Sign in on Caisual to use friends and party.", "Accedi a Caisual per amici e gruppo.", "Inicia sesion para amigos y grupo.", "Connectez-vous pour utiliser amis et groupe.", "F\xFCr Freunde und Gruppe bei Caisual anmelden.", "Entre no Caisual para amigos e grupo."],
|
|
1007
|
+
online: ["Online", "Online", "En linea", "En ligne", "Online", "Online"],
|
|
1008
|
+
noFriends: ["No friends online", "Nessun amico online", "Sin amigos en linea", "Aucun ami en ligne", "Keine Freunde online", "Nenhum amigo online"],
|
|
1009
|
+
createParty: ["Create party", "Crea gruppo", "Crear grupo", "Cr\xE9er un groupe", "Gruppe erstellen", "Criar grupo"],
|
|
1010
|
+
inviteParty: ["Invite to party", "Invita nel gruppo", "Invitar al grupo", "Inviter au groupe", "In Gruppe einladen", "Convidar para o grupo"],
|
|
1011
|
+
leaveParty: ["Leave party", "Lascia gruppo", "Salir del grupo", "Quitter le groupe", "Gruppe verlassen", "Sair do grupo"],
|
|
1012
|
+
accept: ["Accept", "Accetta", "Aceptar", "Accepter", "Annehmen", "Aceitar"],
|
|
1013
|
+
decline: ["Decline", "Rifiuta", "Rechazar", "Refuser", "Ablehnen", "Recusar"],
|
|
1014
|
+
follow: ["Join them", "Raggiungi", "Unirse", "Rejoindre", "Beitreten", "Juntar-se"],
|
|
1015
|
+
voice: ["Voice", "Voce", "Voz", "Voix", "Sprache", "Voz"],
|
|
1016
|
+
voiceJoin: ["Join voice", "Entra in voce", "Unirse a voz", "Activer la voix", "Sprachchat beitreten", "Entrar na voz"],
|
|
1017
|
+
voiceLeave: ["Leave voice", "Esci dalla voce", "Salir de voz", "Quitter la voix", "Sprachchat verlassen", "Sair da voz"],
|
|
1018
|
+
voiceMute: ["Mute", "Disattiva microfono", "Silenciar", "Couper le micro", "Stummschalten", "Silenciar"],
|
|
1019
|
+
voiceUnmute: ["Unmute", "Attiva microfono", "Activar micr\xF3fono", "Activer le micro", "Mikrofon aktivieren", "Ativar microfone"],
|
|
1020
|
+
voiceOff: ["Voice off", "Voce disattivata", "Voz desactivada", "Voix d\xE9sactiv\xE9e", "Sprachchat aus", "Voz desativada"],
|
|
1021
|
+
voiceJoining: ["Joining voice...", "Connessione voce...", "Conectando voz...", "Connexion vocale...", "Sprachchat verbindet...", "Conectando voz..."],
|
|
1022
|
+
voiceOn: ["Voice connected", "Voce connessa", "Voz conectada", "Voix connect\xE9e", "Sprachchat verbunden", "Voz conectada"],
|
|
1023
|
+
voiceMuted: ["Muted", "Microfono disattivato", "Silenciado", "Micro coup\xE9", "Stumm", "Silenciado"],
|
|
1024
|
+
voiceMic: ["Mic on", "Microfono attivo", "Micr\xF3fono activo", "Micro actif", "Mikrofon an", "Microfone ativo"],
|
|
1025
|
+
voiceListening: ["Listening only", "Solo ascolto", "Solo escucha", "\xC9coute seule", "Nur zuh\xF6ren", "Somente ouvindo"],
|
|
1026
|
+
voiceSpeaking: ["Speaking", "Sta parlando", "Hablando", "Parle", "Spricht", "Falando"],
|
|
1027
|
+
voicePeers: ["Voice participants", "Partecipanti in voce", "Participantes de voz", "Participants vocaux", "Sprachteilnehmer", "Participantes de voz"],
|
|
1028
|
+
voiceEmpty: ["No one else in voice yet.", "Nessun altro in voce per ora.", "A\xFAn no hay nadie m\xE1s en voz.", "Personne d\u2019autre en voix pour le moment.", "Noch niemand im Sprachchat.", "Ningu\xE9m mais na voz ainda."],
|
|
1029
|
+
voiceVolume: ["Volume for {name}", "Volume di {name}", "Volumen de {name}", "Volume de {name}", "Lautst\xE4rke f\xFCr {name}", "Volume de {name}"],
|
|
1030
|
+
voiceUnavailable: ["Join a room with voice to use these controls.", "Entra in una stanza con voce per usare questi controlli.", "Entra en una sala con voz para usar estos controles.", "Rejoignez une salle vocale pour utiliser ces commandes.", "Diese Steuerung braucht einen Raum mit Sprachchat.", "Entre em uma sala com voz para usar estes controles."],
|
|
1031
|
+
voiceWatch: ["Voice is unavailable while watching.", "La voce non e' disponibile in osservazione.", "La voz no est\xE1 disponible al observar.", "La voix est indisponible en observation.", "Beim Zuschauen ist kein Sprachchat verf\xFCgbar.", "A voz n\xE3o est\xE1 dispon\xEDvel ao assistir."],
|
|
1032
|
+
voiceDenied: ["Microphone permission denied. Allow it in your browser, then try again.", "Permesso microfono negato. Consenti l'accesso nel browser e riprova.", "Permiso de micr\xF3fono denegado. Act\xEDvalo en el navegador e int\xE9ntalo de nuevo.", "Acc\xE8s au micro refus\xE9. Autorisez-le dans le navigateur, puis r\xE9essayez.", "Mikrofonzugriff verweigert. Im Browser erlauben und erneut versuchen.", "Permiss\xE3o do microfone negada. Permita no navegador e tente novamente."],
|
|
1033
|
+
voiceUnsupported: ["Voice is not supported in this browser.", "Questo browser non supporta la voce.", "Este navegador no admite voz.", "Ce navigateur ne prend pas en charge la voix.", "Dieser Browser unterst\xFCtzt keinen Sprachchat.", "Este navegador n\xE3o oferece suporte a voz."],
|
|
1034
|
+
voiceFailed: ["Voice could not connect. Try again.", "Connessione voce non riuscita. Riprova.", "No se pudo conectar la voz. Int\xE9ntalo de nuevo.", "Connexion vocale impossible. R\xE9essayez.", "Sprachverbindung fehlgeschlagen. Erneut versuchen.", "N\xE3o foi poss\xEDvel conectar a voz. Tente novamente."],
|
|
1035
|
+
voicePeerGone: ["This participant has left voice.", "Questo partecipante e' uscito dalla voce.", "Este participante sali\xF3 de voz.", "Ce participant a quitt\xE9 la voix.", "Diese Person hat den Sprachchat verlassen.", "Este participante saiu da voz."],
|
|
1036
|
+
shortcut: ["Shift+Tab shortcut", "Scorciatoia Shift+Tab", "Atajo Shift+Tab", "Raccourci Maj+Tab", "Umschalt+Tab-Kurzbefehl", "Atalho Shift+Tab"],
|
|
1037
|
+
menu: ["Caisual menu", "Menu Caisual", "Menu Caisual", "Menu Caisual", "Caisual-Menu", "Menu Caisual"],
|
|
1038
|
+
retry: ["Retry", "Riprova", "Reintentar", "R\xE9essayer", "Erneut versuchen", "Tentar novamente"]
|
|
1039
|
+
};
|
|
1040
|
+
var column = (index) => Object.fromEntries(Object.entries(words).map(([key, row]) => [key, row[index]]));
|
|
1041
|
+
var dictionaries = { en: column(0), it: column(1), es: column(2), fr: column(3), de: column(4), pt: column(5) };
|
|
1042
|
+
function overlayLocale(raw) {
|
|
1043
|
+
const tag = normalizeLanguage(raw);
|
|
1044
|
+
return tag && languages.includes(tag.split("-")[0]) ? tag : "en";
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// src/text.ts
|
|
1048
|
+
function createTextLoader(fetcher, language, pathname = "/") {
|
|
1049
|
+
let pending;
|
|
1050
|
+
const root = pathname.match(/^\/rt\/[^/]+\/[1-9][0-9]*\//)?.[0] ?? "/";
|
|
1051
|
+
return () => pending ?? (pending = (async () => {
|
|
1052
|
+
let dictionary = {};
|
|
1053
|
+
try {
|
|
1054
|
+
const response = await fetcher(`${root}__caisual/text/${encodeURIComponent(language)}.json`);
|
|
1055
|
+
if (response.ok) {
|
|
1056
|
+
const value = await response.json();
|
|
1057
|
+
if (isTextDictionary(value)) dictionary = value;
|
|
1058
|
+
}
|
|
1059
|
+
} catch {
|
|
1060
|
+
}
|
|
1061
|
+
return (key, values = {}) => {
|
|
1062
|
+
if (!Object.hasOwn(dictionary, key)) return key;
|
|
1063
|
+
const text = dictionary[key];
|
|
1064
|
+
return text.replace(/\{([^{}]+)\}/g, (placeholder, name) => Object.hasOwn(values, name) ? String(values[name]) : placeholder);
|
|
1065
|
+
};
|
|
1066
|
+
})());
|
|
1067
|
+
}
|
|
1068
|
+
|
|
787
1069
|
// src/errors.ts
|
|
788
1070
|
function creaErrore(code, message) {
|
|
789
1071
|
return Object.assign(new Error(message), { name: "CaisualError", code });
|
|
@@ -870,7 +1152,7 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
870
1152
|
let pending = null, pendingMode = null;
|
|
871
1153
|
let waiting = null, controller = null;
|
|
872
1154
|
let stops = [], disposed = false, lastState = "";
|
|
873
|
-
let view = { inputBlocked:
|
|
1155
|
+
let view = { inputBlocked: standard, reservedRects: [], safeArea: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
874
1156
|
const listeners = /* @__PURE__ */ new Set();
|
|
875
1157
|
const viewListeners = /* @__PURE__ */ new Set();
|
|
876
1158
|
const stateListeners = /* @__PURE__ */ new Set();
|
|
@@ -900,6 +1182,7 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
900
1182
|
function snapshot() {
|
|
901
1183
|
const attached = current.kind === "room" || current.kind === "watch" ? current.room : null;
|
|
902
1184
|
const configured = attached?.metadata.configuration;
|
|
1185
|
+
const result = attached ? readMatchResult(attached.result, attached.players.map((p) => p.id)) : null;
|
|
903
1186
|
const fallback = manifest && attached && (attached.mode === null || manifest.modes.some((m) => m.id === attached.mode)) ? risolviModalita(manifest, attached.mode) : { players: { min: 1, max: 1 }, lobby: false };
|
|
904
1187
|
return {
|
|
905
1188
|
kind: pending ?? (current.kind === "idle" ? ready ? "home" : "boot" : current.kind),
|
|
@@ -909,12 +1192,14 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
909
1192
|
ready,
|
|
910
1193
|
capabilities: capabilities(),
|
|
911
1194
|
room: attached ? {
|
|
1195
|
+
...attached.metadata.rematch?.keepSetup || attached.metadata.rematch?.autoStart ? { rematch: attached.metadata.rematch } : {},
|
|
912
1196
|
code: attached.code,
|
|
913
1197
|
mode: attached.mode,
|
|
914
1198
|
status: attached.status,
|
|
915
1199
|
host: attached.host,
|
|
916
1200
|
you: current.kind === "room" ? current.room.you : null,
|
|
917
1201
|
players: attached.players.map((p) => ({ id: p.id, name: p.name, guest: p.guest, role: p.role, team: p.team, ready: p.ready, connected: p.connected })),
|
|
1202
|
+
...result ? { result } : {},
|
|
918
1203
|
countdownAt: attached.countdownAt,
|
|
919
1204
|
connection: attached.connection,
|
|
920
1205
|
closedCode: attached.metadata.closedCode,
|
|
@@ -1133,7 +1418,10 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
1133
1418
|
if (!standard) throw creaErrore("overlay_disabled", "This game uses its own room flow.");
|
|
1134
1419
|
if (request.op === "overlay.view") {
|
|
1135
1420
|
if (!validOverlayView(request.args)) throw creaErrore("invalid_request", "The overlay geometry is invalid.");
|
|
1136
|
-
view = structuredClone(request.args);
|
|
1421
|
+
view = { ...structuredClone(request.args), safeArea: { top: 0, right: 0, bottom: 0, left: 0, ...request.args.safeArea } };
|
|
1422
|
+
if (typeof document !== "undefined") for (const [side, value] of Object.entries(view.safeArea)) {
|
|
1423
|
+
document.documentElement.style.setProperty(`--caisual-safe-${side}`, `${value}px`);
|
|
1424
|
+
}
|
|
1137
1425
|
notify(viewListeners, structuredClone(view));
|
|
1138
1426
|
return;
|
|
1139
1427
|
}
|
|
@@ -1205,6 +1493,9 @@ function createSession(base, configuration = null, roomsAvailable = base.connect
|
|
|
1205
1493
|
case "room.start":
|
|
1206
1494
|
active().start();
|
|
1207
1495
|
return;
|
|
1496
|
+
case "room.restart":
|
|
1497
|
+
active().restart();
|
|
1498
|
+
return;
|
|
1208
1499
|
case "session.cancel":
|
|
1209
1500
|
cancel();
|
|
1210
1501
|
return;
|
|
@@ -1444,6 +1735,53 @@ function creaClienteApi(appOrigin, fetcher, biglietto) {
|
|
|
1444
1735
|
|
|
1445
1736
|
// src/daily.ts
|
|
1446
1737
|
var DIVISORE_UINT32 = 4294967296;
|
|
1738
|
+
function prossimaMezzanotteUtc(ora) {
|
|
1739
|
+
return (Math.floor(ora / 864e5) + 1) * 864e5;
|
|
1740
|
+
}
|
|
1741
|
+
function creaDaily(initial, now, refresh) {
|
|
1742
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1743
|
+
let current = { ...initial }, timer, pending = false;
|
|
1744
|
+
function schedule() {
|
|
1745
|
+
if (!listeners.size || timer !== void 0 || pending) return;
|
|
1746
|
+
timer = setTimeout(check, Math.max(0, Math.min(2147483647, current.expiresAt - now())));
|
|
1747
|
+
timer.unref?.();
|
|
1748
|
+
}
|
|
1749
|
+
async function check() {
|
|
1750
|
+
timer = void 0;
|
|
1751
|
+
pending = true;
|
|
1752
|
+
try {
|
|
1753
|
+
const next = await refresh(), changed = next.day !== current.day;
|
|
1754
|
+
current = { ...next };
|
|
1755
|
+
if (changed) for (const listener of [...listeners]) {
|
|
1756
|
+
try {
|
|
1757
|
+
listener({ ...next });
|
|
1758
|
+
} catch {
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
} catch {
|
|
1762
|
+
} finally {
|
|
1763
|
+
pending = false;
|
|
1764
|
+
if (current.expiresAt <= now()) current.expiresAt = now() + 3e4;
|
|
1765
|
+
schedule();
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
return {
|
|
1769
|
+
...initial,
|
|
1770
|
+
random: creaMulberry32(initial.seed),
|
|
1771
|
+
rng: () => creaMulberry32(initial.seed),
|
|
1772
|
+
onChange(listener) {
|
|
1773
|
+
listeners.add(listener);
|
|
1774
|
+
schedule();
|
|
1775
|
+
return () => {
|
|
1776
|
+
listeners.delete(listener);
|
|
1777
|
+
if (!listeners.size && timer !== void 0) {
|
|
1778
|
+
clearTimeout(timer);
|
|
1779
|
+
timer = void 0;
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1447
1785
|
function giornoUtc(ora) {
|
|
1448
1786
|
return new Date(ora).toISOString().slice(0, 10);
|
|
1449
1787
|
}
|
|
@@ -1505,8 +1843,13 @@ function attendiHandshake(finestra, appOrigin, timeoutMs = 3e3) {
|
|
|
1505
1843
|
if (typeof dati?.ticket !== "string" || porta === void 0) return;
|
|
1506
1844
|
porta.start();
|
|
1507
1845
|
const overlay = normalizeOverlayHello(dati.overlay);
|
|
1846
|
+
const tags = (value) => Array.isArray(value) ? value.map(normalizeLanguage).filter((tag) => tag !== null) : void 0;
|
|
1508
1847
|
termina({
|
|
1509
1848
|
...overlay ? { overlay } : {},
|
|
1849
|
+
...normalizeLanguage(dati.language) ? { language: normalizeLanguage(dati.language) } : {},
|
|
1850
|
+
uiLanguage: normalizeLanguage(dati.uiLanguage) ?? void 0,
|
|
1851
|
+
languagePreferences: tags(dati.languagePreferences),
|
|
1852
|
+
gameLanguages: tags(dati.gameLanguages),
|
|
1510
1853
|
ticket: dati.ticket,
|
|
1511
1854
|
live: leggiOrigine(dati.live),
|
|
1512
1855
|
invite: typeof dati.invite === "string" ? dati.invite : null,
|
|
@@ -2473,8 +2816,7 @@ var GRAZIA_RICONNESSIONE = 6e4;
|
|
|
2473
2816
|
var INTERVALLO_PING = 5e3;
|
|
2474
2817
|
var RITARDO_FLUSH = 500;
|
|
2475
2818
|
var ATTESA_ROSTER = 2e3;
|
|
2476
|
-
var CHIUSURE_DEFINITIVE = /* @__PURE__ */ new Set([4003, 4004, 4005, 4006]);
|
|
2477
|
-
var CHIUSURE_DEFINITIVE_SPETTATORE = /* @__PURE__ */ new Set([4008, 4009]);
|
|
2819
|
+
var CHIUSURE_DEFINITIVE = /* @__PURE__ */ new Set([4003, 4004, 4005, 4006, 4008, 4009]);
|
|
2478
2820
|
function record3(value) {
|
|
2479
2821
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
2480
2822
|
}
|
|
@@ -2579,10 +2921,10 @@ function creaApiLive(input) {
|
|
|
2579
2921
|
};
|
|
2580
2922
|
}
|
|
2581
2923
|
var StanzaClient = class {
|
|
2582
|
-
constructor(roomId, codice, url,
|
|
2924
|
+
constructor(roomId, codice, url, dipendenze, api, segnalaStanza, spettatore = false) {
|
|
2583
2925
|
this.roomId = roomId;
|
|
2584
2926
|
this.codice = codice;
|
|
2585
|
-
this.
|
|
2927
|
+
this.dipendenze = dipendenze;
|
|
2586
2928
|
this.api = api;
|
|
2587
2929
|
this.segnalaStanza = segnalaStanza;
|
|
2588
2930
|
this.spettatore = spettatore;
|
|
@@ -2597,6 +2939,13 @@ var StanzaClient = class {
|
|
|
2597
2939
|
this.statoPubblico = null;
|
|
2598
2940
|
this.statoSincronizzato = null;
|
|
2599
2941
|
this.tickCorrente = 0;
|
|
2942
|
+
this.tickRateCorrente = 0;
|
|
2943
|
+
this.latenzaCorrente = null;
|
|
2944
|
+
this.ultimoInput = null;
|
|
2945
|
+
this.inputInviato = null;
|
|
2946
|
+
this.timerInput = null;
|
|
2947
|
+
this.ultimoInvioGioco = -Infinity;
|
|
2948
|
+
this.inviiGioco = [];
|
|
2600
2949
|
this.seedCorrente = 0;
|
|
2601
2950
|
this.statusCorrente = "lobby";
|
|
2602
2951
|
this.giocatoriCorrenti = [];
|
|
@@ -2640,7 +2989,7 @@ var StanzaClient = class {
|
|
|
2640
2989
|
this.rosterRicevuto = true;
|
|
2641
2990
|
this.risolviProntaSePossibile();
|
|
2642
2991
|
}
|
|
2643
|
-
},
|
|
2992
|
+
}, dipendenze, dipendenze.voce);
|
|
2644
2993
|
if (spettatore) this.rosterRicevuto = true;
|
|
2645
2994
|
this.apri(url);
|
|
2646
2995
|
}
|
|
@@ -2686,6 +3035,7 @@ var StanzaClient = class {
|
|
|
2686
3035
|
host: room.host,
|
|
2687
3036
|
mode: room.mode,
|
|
2688
3037
|
countdownAt: room.countdownAt ?? null,
|
|
3038
|
+
rematch: room.rematch ?? null,
|
|
2689
3039
|
configuration: room.configuration ?? null,
|
|
2690
3040
|
connection: "connected",
|
|
2691
3041
|
closedCode: null
|
|
@@ -2699,7 +3049,7 @@ var StanzaClient = class {
|
|
|
2699
3049
|
if (this.roleRequests.size >= 8) return Promise.reject(creaErrore("rate_limited", "Too many role requests."));
|
|
2700
3050
|
const r = ++this.roleId;
|
|
2701
3051
|
return new Promise((resolve, reject) => {
|
|
2702
|
-
const timer = this.
|
|
3052
|
+
const timer = this.dipendenze.setTimeout(() => {
|
|
2703
3053
|
this.roleRequests.delete(r);
|
|
2704
3054
|
reject(creaErrore("timeout", "The role request timed out."));
|
|
2705
3055
|
}, 5e3);
|
|
@@ -2707,7 +3057,7 @@ var StanzaClient = class {
|
|
|
2707
3057
|
try {
|
|
2708
3058
|
this.invia({ t: "request-role", r, role });
|
|
2709
3059
|
} catch (error) {
|
|
2710
|
-
this.
|
|
3060
|
+
this.dipendenze.clearTimeout(timer);
|
|
2711
3061
|
this.roleRequests.delete(r);
|
|
2712
3062
|
reject(error);
|
|
2713
3063
|
}
|
|
@@ -2715,7 +3065,7 @@ var StanzaClient = class {
|
|
|
2715
3065
|
}
|
|
2716
3066
|
clearRoleRequests() {
|
|
2717
3067
|
for (const request of this.roleRequests.values()) {
|
|
2718
|
-
this.
|
|
3068
|
+
this.dipendenze.clearTimeout(request.timer);
|
|
2719
3069
|
request.reject(creaErrore("offline", "The room connection ended."));
|
|
2720
3070
|
}
|
|
2721
3071
|
this.roleRequests.clear();
|
|
@@ -2726,10 +3076,11 @@ var StanzaClient = class {
|
|
|
2726
3076
|
const socket = this.socket;
|
|
2727
3077
|
this.socket = null;
|
|
2728
3078
|
this.voice.termina();
|
|
3079
|
+
this.fermaInput();
|
|
2729
3080
|
this.fermaPing();
|
|
2730
3081
|
this.fermaRiconnessione();
|
|
2731
3082
|
this.clearRoleRequests();
|
|
2732
|
-
if (this.timerRoster !== null) this.
|
|
3083
|
+
if (this.timerRoster !== null) this.dipendenze.clearTimeout(this.timerRoster);
|
|
2733
3084
|
socket?.close(1e3);
|
|
2734
3085
|
this.segnalaStanza(null);
|
|
2735
3086
|
this.metadataChanged({ connection: "disconnected", closedCode: null });
|
|
@@ -2744,6 +3095,12 @@ var StanzaClient = class {
|
|
|
2744
3095
|
get tick() {
|
|
2745
3096
|
return this.tickCorrente;
|
|
2746
3097
|
}
|
|
3098
|
+
get tickRate() {
|
|
3099
|
+
return this.tickRateCorrente;
|
|
3100
|
+
}
|
|
3101
|
+
get latency() {
|
|
3102
|
+
return this.latenzaCorrente;
|
|
3103
|
+
}
|
|
2747
3104
|
get seed() {
|
|
2748
3105
|
return this.seedCorrente;
|
|
2749
3106
|
}
|
|
@@ -2772,7 +3129,7 @@ var StanzaClient = class {
|
|
|
2772
3129
|
return this.promessaPronta;
|
|
2773
3130
|
}
|
|
2774
3131
|
invite() {
|
|
2775
|
-
return { code: this.codice, url: new URL(`/r/${this.codice}`, this.
|
|
3132
|
+
return { code: this.codice, url: new URL(`/r/${this.codice}`, this.dipendenze.appOrigin).href };
|
|
2776
3133
|
}
|
|
2777
3134
|
onState(listener) {
|
|
2778
3135
|
this.ascoltatoriStato.add(listener);
|
|
@@ -2799,9 +3156,63 @@ var StanzaClient = class {
|
|
|
2799
3156
|
};
|
|
2800
3157
|
}
|
|
2801
3158
|
send(message) {
|
|
3159
|
+
if (this.statusCorrente === "finished") return;
|
|
2802
3160
|
const prossimo = this.seq + 1;
|
|
2803
3161
|
this.invia({ t: "msg", seq: prossimo, m: message });
|
|
2804
3162
|
this.seq = prossimo;
|
|
3163
|
+
this.ultimoInvioGioco = this.dipendenze.ora();
|
|
3164
|
+
this.inviiGioco = [...this.inviiGioco.slice(-(MESSAGGI_GIOCO_AL_SECONDO - 1)), this.ultimoInvioGioco];
|
|
3165
|
+
}
|
|
3166
|
+
input(value) {
|
|
3167
|
+
if (this.terminata || this.lasciata || this.statusCorrente === "finished") return;
|
|
3168
|
+
try {
|
|
3169
|
+
const serializzato = JSON.stringify(value);
|
|
3170
|
+
if (serializzato === void 0) throw new TypeError();
|
|
3171
|
+
this.ultimoInput = serializzato;
|
|
3172
|
+
} catch {
|
|
3173
|
+
throw creaErrore("invalid_request", "Room input must be valid JSON.");
|
|
3174
|
+
}
|
|
3175
|
+
this.programmaInput();
|
|
3176
|
+
}
|
|
3177
|
+
pulisciInput() {
|
|
3178
|
+
this.fermaInput();
|
|
3179
|
+
this.ultimoInput = this.inputInviato = null;
|
|
3180
|
+
this.ultimoInvioGioco = -Infinity;
|
|
3181
|
+
this.inviiGioco = [];
|
|
3182
|
+
}
|
|
3183
|
+
fermaInput() {
|
|
3184
|
+
if (this.timerInput !== null) this.dipendenze.clearTimeout(this.timerInput);
|
|
3185
|
+
this.timerInput = null;
|
|
3186
|
+
}
|
|
3187
|
+
programmaInput() {
|
|
3188
|
+
if (this.timerInput !== null || this.ultimoInput === null || this.ultimoInput === this.inputInviato || !this.welcomeRicevuto || this.socket?.readyState !== APERTO || this.terminata || this.lasciata) return;
|
|
3189
|
+
const ora = this.dipendenze.ora();
|
|
3190
|
+
const frequenza = this.tickRateCorrente > 0 ? Math.min(MESSAGGI_GIOCO_AL_SECONDO, this.tickRateCorrente) : MESSAGGI_GIOCO_AL_SECONDO;
|
|
3191
|
+
const periodo = 1e3 / frequenza;
|
|
3192
|
+
this.inviiGioco = this.inviiGioco.filter((at) => ora - at < 1e3);
|
|
3193
|
+
const spazio = this.inviiGioco.length >= MESSAGGI_GIOCO_AL_SECONDO ? this.inviiGioco[0] + 1e3 : ora;
|
|
3194
|
+
const prossimo = Number.isFinite(this.ultimoInvioGioco) ? this.ultimoInvioGioco + periodo : ora + periodo;
|
|
3195
|
+
this.timerInput = this.dipendenze.setTimeout(() => {
|
|
3196
|
+
this.timerInput = null;
|
|
3197
|
+
if (this.ultimoInput === null || this.ultimoInput === this.inputInviato || !this.welcomeRicevuto || this.socket?.readyState !== APERTO || this.terminata || this.lasciata) return;
|
|
3198
|
+
const adesso = this.dipendenze.ora();
|
|
3199
|
+
if (adesso < this.ultimoInvioGioco + periodo || this.inviiGioco.filter((at) => adesso - at < 1e3).length >= MESSAGGI_GIOCO_AL_SECONDO) {
|
|
3200
|
+
this.programmaInput();
|
|
3201
|
+
return;
|
|
3202
|
+
}
|
|
3203
|
+
const valore = this.ultimoInput;
|
|
3204
|
+
try {
|
|
3205
|
+
this.send(JSON.parse(valore));
|
|
3206
|
+
this.inputInviato = valore;
|
|
3207
|
+
} catch {
|
|
3208
|
+
}
|
|
3209
|
+
}, Math.max(0, Math.ceil(Math.max(prossimo, spazio) - ora)));
|
|
3210
|
+
}
|
|
3211
|
+
aggiornaTickRate(value) {
|
|
3212
|
+
if (value === void 0 || !Number.isInteger(value) || value < 0 || value > 60 || value === this.tickRateCorrente) return;
|
|
3213
|
+
this.tickRateCorrente = value;
|
|
3214
|
+
this.fermaInput();
|
|
3215
|
+
this.programmaInput();
|
|
2805
3216
|
}
|
|
2806
3217
|
ready(ready) {
|
|
2807
3218
|
this.invia({ t: "ready", ready });
|
|
@@ -2815,6 +3226,10 @@ var StanzaClient = class {
|
|
|
2815
3226
|
start() {
|
|
2816
3227
|
this.invia({ t: "start" });
|
|
2817
3228
|
}
|
|
3229
|
+
restart() {
|
|
3230
|
+
if (this.statusCorrente !== "finished") throw creaErrore("rematch_unavailable", "This room is not waiting for a rematch.");
|
|
3231
|
+
this.invia({ t: "restart" });
|
|
3232
|
+
}
|
|
2818
3233
|
leave() {
|
|
2819
3234
|
if (this.lasciata) return;
|
|
2820
3235
|
if (!this.spettatore) this.voice.leave();
|
|
@@ -2828,7 +3243,7 @@ var StanzaClient = class {
|
|
|
2828
3243
|
this.termina(1e3);
|
|
2829
3244
|
}
|
|
2830
3245
|
serverTime() {
|
|
2831
|
-
return this.
|
|
3246
|
+
return this.dipendenze.ora() + this.scartoOrario;
|
|
2832
3247
|
}
|
|
2833
3248
|
copiaGiocatori() {
|
|
2834
3249
|
return this.giocatoriCorrenti.map((player) => ({ ...player }));
|
|
@@ -2856,7 +3271,7 @@ var StanzaClient = class {
|
|
|
2856
3271
|
apri(url) {
|
|
2857
3272
|
let socket;
|
|
2858
3273
|
try {
|
|
2859
|
-
socket = this.
|
|
3274
|
+
socket = this.dipendenze.apriSocket(url);
|
|
2860
3275
|
} catch {
|
|
2861
3276
|
this.programmaRiconnessione();
|
|
2862
3277
|
return;
|
|
@@ -2869,22 +3284,22 @@ var StanzaClient = class {
|
|
|
2869
3284
|
if (this.socket === socket && typeof evento.data === "string") this.ricevi(evento.data);
|
|
2870
3285
|
});
|
|
2871
3286
|
socket.addEventListener("close", (evento) => {
|
|
2872
|
-
if (this.socket === socket) this.chiuso(evento.code);
|
|
3287
|
+
if (this.socket === socket) this.chiuso(evento.code, evento.reason);
|
|
2873
3288
|
});
|
|
2874
3289
|
}
|
|
2875
3290
|
avviaPing() {
|
|
2876
|
-
if (this.timerPing !== null) this.
|
|
2877
|
-
this.timerPing = this.
|
|
3291
|
+
if (this.timerPing !== null) this.dipendenze.clearInterval(this.timerPing);
|
|
3292
|
+
this.timerPing = this.dipendenze.setInterval(() => {
|
|
2878
3293
|
if (this.socket?.readyState !== APERTO) return;
|
|
2879
3294
|
try {
|
|
2880
|
-
this.invia({ t: "ping", c: this.
|
|
3295
|
+
this.invia({ t: "ping", c: this.dipendenze.ora() });
|
|
2881
3296
|
} catch {
|
|
2882
3297
|
}
|
|
2883
3298
|
}, INTERVALLO_PING);
|
|
2884
3299
|
}
|
|
2885
3300
|
fermaPing() {
|
|
2886
3301
|
if (this.timerPing === null) return;
|
|
2887
|
-
this.
|
|
3302
|
+
this.dipendenze.clearInterval(this.timerPing);
|
|
2888
3303
|
this.timerPing = null;
|
|
2889
3304
|
}
|
|
2890
3305
|
ricevi(frame) {
|
|
@@ -2915,7 +3330,7 @@ var StanzaClient = class {
|
|
|
2915
3330
|
} else if (dati.t === "role-result") {
|
|
2916
3331
|
const request = this.roleRequests.get(dati.r);
|
|
2917
3332
|
if (request) {
|
|
2918
|
-
this.
|
|
3333
|
+
this.dipendenze.clearTimeout(request.timer);
|
|
2919
3334
|
this.roleRequests.delete(dati.r);
|
|
2920
3335
|
if (dati.ok) request.resolve();
|
|
2921
3336
|
else request.reject(creaErrore(dati.code ?? "role_change_refused", "The role change was not accepted."));
|
|
@@ -2928,13 +3343,16 @@ var StanzaClient = class {
|
|
|
2928
3343
|
riceviWatching(dati) {
|
|
2929
3344
|
const room = dati.room;
|
|
2930
3345
|
if (!this.spettatore || room.id !== this.roomId) return;
|
|
3346
|
+
this.aggiornaTickRate(room.tickRate);
|
|
2931
3347
|
this.seedCorrente = room.seed;
|
|
2932
3348
|
this.hostCorrente = room.host;
|
|
2933
3349
|
this.statusCorrente = room.status;
|
|
3350
|
+
this.resultCorrente = copiaJson(room.result ?? null);
|
|
3351
|
+
if (room.status === "finished") this.pulisciInput();
|
|
2934
3352
|
this.giocatoriCorrenti = dati.players.map((player) => ({ ...player }));
|
|
2935
3353
|
this.delaySpettatore = dati.delayMs;
|
|
2936
3354
|
this.aggiornaStato(dati.state, room.tick, room.serverTime);
|
|
2937
|
-
this.scartoOrario = room.serverTime - this.
|
|
3355
|
+
this.scartoOrario = room.serverTime - this.dipendenze.ora();
|
|
2938
3356
|
this.resyncRichiesto = false;
|
|
2939
3357
|
this.welcomeRicevuto = true;
|
|
2940
3358
|
this.ritardoIndice = 0;
|
|
@@ -2947,22 +3365,26 @@ var StanzaClient = class {
|
|
|
2947
3365
|
room.serverTime
|
|
2948
3366
|
);
|
|
2949
3367
|
this.initialMetadata(room);
|
|
3368
|
+
this.programmaInput();
|
|
2950
3369
|
this.risolviProntaSePossibile();
|
|
2951
3370
|
}
|
|
2952
3371
|
riceviWelcome(dati) {
|
|
2953
3372
|
const room = dati.room;
|
|
2954
3373
|
if (room.id !== this.roomId) return;
|
|
2955
3374
|
this.youCorrente = dati.you;
|
|
3375
|
+
this.aggiornaTickRate(room.tickRate);
|
|
2956
3376
|
this.seedCorrente = room.seed;
|
|
2957
3377
|
this.hostCorrente = room.host;
|
|
2958
3378
|
this.statusCorrente = room.status;
|
|
3379
|
+
this.resultCorrente = copiaJson(room.result ?? null);
|
|
3380
|
+
if (room.status === "finished") this.pulisciInput();
|
|
2959
3381
|
this.giocatoriCorrenti = dati.players.map((player) => ({ ...player }));
|
|
2960
3382
|
this.aggiornaStato(dati.state, room.tick, room.serverTime);
|
|
2961
|
-
this.scartoOrario = room.serverTime - this.
|
|
3383
|
+
this.scartoOrario = room.serverTime - this.dipendenze.ora();
|
|
2962
3384
|
this.resyncRichiesto = false;
|
|
2963
3385
|
this.welcomeRicevuto = true;
|
|
2964
3386
|
if (!this.rosterRicevuto && this.timerRoster === null) {
|
|
2965
|
-
this.timerRoster = this.
|
|
3387
|
+
this.timerRoster = this.dipendenze.setTimeout(() => {
|
|
2966
3388
|
this.timerRoster = null;
|
|
2967
3389
|
this.rosterRicevuto = true;
|
|
2968
3390
|
this.risolviProntaSePossibile();
|
|
@@ -2980,6 +3402,7 @@ var StanzaClient = class {
|
|
|
2980
3402
|
room.serverTime
|
|
2981
3403
|
);
|
|
2982
3404
|
this.initialMetadata(room);
|
|
3405
|
+
this.programmaInput();
|
|
2983
3406
|
this.risolviProntaSePossibile();
|
|
2984
3407
|
}
|
|
2985
3408
|
riceviGiocatori(value, host) {
|
|
@@ -2998,6 +3421,10 @@ var StanzaClient = class {
|
|
|
2998
3421
|
this.statusCorrente = dati.status;
|
|
2999
3422
|
if (dati.host !== void 0) this.hostCorrente = dati.host;
|
|
3000
3423
|
this.resultCorrente = copiaJson(dati.result);
|
|
3424
|
+
if (dati.status === "finished") {
|
|
3425
|
+
this.pulisciInput();
|
|
3426
|
+
this.clearRoleRequests();
|
|
3427
|
+
}
|
|
3001
3428
|
if (dati.status === "ended") {
|
|
3002
3429
|
this.terminata = true;
|
|
3003
3430
|
this.clearRoleRequests();
|
|
@@ -3005,8 +3432,11 @@ var StanzaClient = class {
|
|
|
3005
3432
|
if (!this.spettatore) this.voice.termina();
|
|
3006
3433
|
this.fermaPing();
|
|
3007
3434
|
this.fermaRiconnessione();
|
|
3435
|
+
this.fermaInput();
|
|
3436
|
+
this.ultimoInput = null;
|
|
3008
3437
|
}
|
|
3009
3438
|
this.metadataChanged({
|
|
3439
|
+
rematch: dati.rematch ?? null,
|
|
3010
3440
|
host: this.hostCorrente,
|
|
3011
3441
|
countdownAt: dati.countdownAt ?? (dati.status === "countdown" ? dati.at : null),
|
|
3012
3442
|
...dati.status === "ended" ? { connection: "ended", closedCode: 4004 } : {}
|
|
@@ -3014,6 +3444,7 @@ var StanzaClient = class {
|
|
|
3014
3444
|
this.notifica(this.ascoltatoriStatus, this.statusCorrente, this.resultCorrente, dati.at);
|
|
3015
3445
|
}
|
|
3016
3446
|
riceviDiff(dati) {
|
|
3447
|
+
this.aggiornaTickRate(dati.tickRate);
|
|
3017
3448
|
if (dati.base !== this.tickCorrente) {
|
|
3018
3449
|
this.chiediResync();
|
|
3019
3450
|
return;
|
|
@@ -3028,6 +3459,7 @@ var StanzaClient = class {
|
|
|
3028
3459
|
}
|
|
3029
3460
|
riceviSnapshot(dati) {
|
|
3030
3461
|
if (dati.tick < this.tickCorrente) return;
|
|
3462
|
+
this.aggiornaTickRate(dati.tickRate);
|
|
3031
3463
|
this.resyncRichiesto = false;
|
|
3032
3464
|
this.aggiornaStato(dati.state, dati.tick, dati.serverTime);
|
|
3033
3465
|
}
|
|
@@ -3047,15 +3479,26 @@ var StanzaClient = class {
|
|
|
3047
3479
|
}
|
|
3048
3480
|
}
|
|
3049
3481
|
riceviPong(dati) {
|
|
3050
|
-
|
|
3482
|
+
const ora = this.dipendenze.ora();
|
|
3483
|
+
if (!Number.isFinite(dati.c) || !Number.isFinite(dati.s) || dati.c > ora) return;
|
|
3484
|
+
const rtt = ora - dati.c;
|
|
3485
|
+
this.latenzaCorrente = this.latenzaCorrente === null ? rtt : this.latenzaCorrente * 0.8 + rtt * 0.2;
|
|
3486
|
+
this.scartoOrario = dati.s - (dati.c + ora) / 2;
|
|
3051
3487
|
}
|
|
3052
|
-
chiuso(code) {
|
|
3488
|
+
chiuso(code, reason) {
|
|
3053
3489
|
this.socket = null;
|
|
3054
3490
|
this.welcomeRicevuto = false;
|
|
3491
|
+
this.latenzaCorrente = null;
|
|
3492
|
+
this.fermaInput();
|
|
3493
|
+
this.inputInviato = null;
|
|
3494
|
+
this.ultimoInvioGioco = -Infinity;
|
|
3495
|
+
this.inviiGioco = [];
|
|
3055
3496
|
this.fermaPing();
|
|
3056
3497
|
if (this.lasciata || this.terminata) return;
|
|
3057
|
-
if (CHIUSURE_DEFINITIVE.has(code)
|
|
3058
|
-
|
|
3498
|
+
if (CHIUSURE_DEFINITIVE.has(code)) {
|
|
3499
|
+
const errore = code === 4009 && reason === "message_too_large" ? "message_too_large" : void 0;
|
|
3500
|
+
if (errore) this.notifica(this.errorListeners, { code: errore, message: "The room message is too large." });
|
|
3501
|
+
this.termina(code, errore);
|
|
3059
3502
|
return;
|
|
3060
3503
|
}
|
|
3061
3504
|
this.clearRoleRequests();
|
|
@@ -3073,7 +3516,7 @@ var StanzaClient = class {
|
|
|
3073
3516
|
}
|
|
3074
3517
|
this.ritardoIndice++;
|
|
3075
3518
|
this.tempoRiconnessione += ritardo;
|
|
3076
|
-
this.timerRiconnessione = this.
|
|
3519
|
+
this.timerRiconnessione = this.dipendenze.setTimeout(() => {
|
|
3077
3520
|
this.timerRiconnessione = null;
|
|
3078
3521
|
void this.riconnetti();
|
|
3079
3522
|
}, ritardo);
|
|
@@ -3095,15 +3538,17 @@ var StanzaClient = class {
|
|
|
3095
3538
|
}
|
|
3096
3539
|
fermaRiconnessione() {
|
|
3097
3540
|
if (this.timerRiconnessione === null) return;
|
|
3098
|
-
this.
|
|
3541
|
+
this.dipendenze.clearTimeout(this.timerRiconnessione);
|
|
3099
3542
|
this.timerRiconnessione = null;
|
|
3100
3543
|
}
|
|
3101
|
-
termina(code) {
|
|
3544
|
+
termina(code, errore) {
|
|
3102
3545
|
this.clearRoleRequests();
|
|
3103
3546
|
this.metadataChanged({ connection: code === 1e3 ? "disconnected" : code === 4006 ? "replaced" : "closed", closedCode: typeof code === "number" ? code : null });
|
|
3104
3547
|
const risultato = { closed: code };
|
|
3105
3548
|
const cambiato = this.statusCorrente !== "ended" || JSON.stringify(this.resultCorrente) !== JSON.stringify(risultato);
|
|
3106
3549
|
this.terminata = true;
|
|
3550
|
+
this.fermaInput();
|
|
3551
|
+
this.ultimoInput = null;
|
|
3107
3552
|
this.segnalaStanza(null);
|
|
3108
3553
|
this.statusCorrente = "ended";
|
|
3109
3554
|
this.resultCorrente = risultato;
|
|
@@ -3121,14 +3566,14 @@ var StanzaClient = class {
|
|
|
3121
3566
|
4008: "rate_limited",
|
|
3122
3567
|
4009: "invalid_request"
|
|
3123
3568
|
};
|
|
3124
|
-
const erroreCode = typeof code === "number" ? codici[code] ?? "offline" : "offline";
|
|
3569
|
+
const erroreCode = errore ?? (typeof code === "number" ? codici[code] ?? "offline" : "offline");
|
|
3125
3570
|
this.rifiutaPronta(creaErrore(erroreCode, "The room connection ended."));
|
|
3126
3571
|
}
|
|
3127
3572
|
}
|
|
3128
3573
|
risolviProntaSePossibile() {
|
|
3129
3574
|
if (this.prontaRisolta || !this.welcomeRicevuto || !this.rosterRicevuto) return;
|
|
3130
3575
|
if (this.timerRoster !== null) {
|
|
3131
|
-
this.
|
|
3576
|
+
this.dipendenze.clearTimeout(this.timerRoster);
|
|
3132
3577
|
this.timerRoster = null;
|
|
3133
3578
|
}
|
|
3134
3579
|
this.prontaRisolta = true;
|
|
@@ -3140,7 +3585,7 @@ var StanzaClient = class {
|
|
|
3140
3585
|
richiediFlush() {
|
|
3141
3586
|
this.flushRichiesto = true;
|
|
3142
3587
|
if (this.flushInCorso || this.timerFlush !== null) return;
|
|
3143
|
-
this.timerFlush = this.
|
|
3588
|
+
this.timerFlush = this.dipendenze.setTimeout(() => {
|
|
3144
3589
|
this.timerFlush = null;
|
|
3145
3590
|
void this.eseguiFlush();
|
|
3146
3591
|
}, RITARDO_FLUSH);
|
|
@@ -3231,6 +3676,12 @@ function creaGestoreStanze(input, invited) {
|
|
|
3231
3676
|
get tick() {
|
|
3232
3677
|
return stanza.tick;
|
|
3233
3678
|
},
|
|
3679
|
+
get tickRate() {
|
|
3680
|
+
return stanza.tickRate;
|
|
3681
|
+
},
|
|
3682
|
+
get latency() {
|
|
3683
|
+
return stanza.latency;
|
|
3684
|
+
},
|
|
3234
3685
|
get seed() {
|
|
3235
3686
|
return stanza.seed;
|
|
3236
3687
|
},
|
|
@@ -3454,12 +3905,15 @@ function creaSave(archivio, ora) {
|
|
|
3454
3905
|
};
|
|
3455
3906
|
}
|
|
3456
3907
|
async function creaStandalone(input, invited = null) {
|
|
3457
|
-
const
|
|
3908
|
+
const startedAt = input.ora(), day = giornoUtc(startedAt);
|
|
3458
3909
|
const seed = await calcolaSeed(input.hostname, day, input.subtle);
|
|
3459
3910
|
return {
|
|
3460
3911
|
connected: false,
|
|
3461
3912
|
player: { id: "local", name: "Guest", guest: true },
|
|
3462
|
-
daily: { day, seed,
|
|
3913
|
+
daily: creaDaily({ day, seed, expiresAt: prossimaMezzanotteUtc(startedAt) }, input.ora, async () => {
|
|
3914
|
+
const now = input.ora(), day2 = giornoUtc(now);
|
|
3915
|
+
return { day: day2, seed: await calcolaSeed(input.hostname, day2, input.subtle), expiresAt: prossimaMezzanotteUtc(now) };
|
|
3916
|
+
}),
|
|
3463
3917
|
time: { now: input.ora },
|
|
3464
3918
|
save: creaSave(input.archivio, input.ora),
|
|
3465
3919
|
board: {
|
|
@@ -3499,6 +3953,8 @@ function dipendenzeReali2() {
|
|
|
3499
3953
|
documento: typeof document === "undefined" ? null : document,
|
|
3500
3954
|
fetcher: (input, init) => globalThis.fetch(input, init),
|
|
3501
3955
|
archivio: archivioReale(),
|
|
3956
|
+
language: typeof navigator === "undefined" ? "en" : navigator.language,
|
|
3957
|
+
pathname: typeof location === "undefined" ? "/" : location.pathname,
|
|
3502
3958
|
hostname: typeof location === "undefined" ? "" : location.hostname,
|
|
3503
3959
|
subtle: globalThis.crypto.subtle,
|
|
3504
3960
|
ora: Date.now,
|
|
@@ -3569,7 +4025,14 @@ async function connetti(input) {
|
|
|
3569
4025
|
const base = {
|
|
3570
4026
|
connected: true,
|
|
3571
4027
|
player: me.player,
|
|
3572
|
-
daily:
|
|
4028
|
+
daily: creaDaily(
|
|
4029
|
+
{ day: me.day, seed: me.seed, expiresAt: me.expiresAt ?? prossimaMezzanotteUtc(me.serverTime) },
|
|
4030
|
+
() => input.ora() + scartoOrario,
|
|
4031
|
+
async () => {
|
|
4032
|
+
const next = await api.me();
|
|
4033
|
+
return { day: next.day, seed: next.seed, expiresAt: next.expiresAt ?? prossimaMezzanotteUtc(next.serverTime) };
|
|
4034
|
+
}
|
|
4035
|
+
),
|
|
3573
4036
|
time: { now: () => input.ora() + scartoOrario },
|
|
3574
4037
|
save: {
|
|
3575
4038
|
set: (key, value) => api.saveSet(key, value),
|
|
@@ -3598,10 +4061,20 @@ function installSession(base, handshake, input) {
|
|
|
3598
4061
|
const dispose = attachKitBridge(handshake.porta, handshake.overlay, coordinator);
|
|
3599
4062
|
if (coordinator.session.capabilities.overlay && typeof window !== "undefined" && input?.finestra === window) window.addEventListener("pagehide", dispose, { once: true });
|
|
3600
4063
|
}
|
|
3601
|
-
|
|
4064
|
+
const preferences = handshake?.languagePreferences?.length ? handshake.languagePreferences : [handshake?.language ?? input?.language ?? "en"];
|
|
4065
|
+
const language = resolveGameLanguage(preferences, handshake?.gameLanguages ?? (handshake?.overlay ? manifestLanguages(handshake.overlay.configuration.manifest) : void 0));
|
|
4066
|
+
const uiLanguage = overlayLocale(handshake?.uiLanguage ?? handshake?.language ?? input?.language);
|
|
4067
|
+
return {
|
|
4068
|
+
...base,
|
|
4069
|
+
player: { ...base.player, language, uiLanguage },
|
|
4070
|
+
text: createTextLoader(input?.fetcher ?? globalThis.fetch, language, input?.pathname),
|
|
4071
|
+
room: coordinator.rooms,
|
|
4072
|
+
session: coordinator.session,
|
|
4073
|
+
overlay: coordinator.overlay
|
|
4074
|
+
};
|
|
3602
4075
|
}
|
|
3603
4076
|
async function localConnection(input) {
|
|
3604
|
-
return installSession(await creaStandalone(input));
|
|
4077
|
+
return installSession(await creaStandalone(input), void 0, input);
|
|
3605
4078
|
}
|
|
3606
4079
|
function dispositivoSconosciuto() {
|
|
3607
4080
|
return {
|