Give each player their own daily card and send only the visible crop of its illustration
- Each player draws their own daily card and zoom point on their first visit, so a shared answer no longer helps; the migration keeps past games with their day's shared card. - The server crops the illustration with sharp to the part visible at the current zoom; the full image only arrives once the game is over. - The admin overview shows the day's winners and players instead of a single card. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
41325a3a32
commit
fc43444995
17 changed files with 839 additions and 118 deletions
|
|
@ -385,3 +385,4 @@
|
|||
{"id":"int-90df2fcebecd14255c48d5e8d81a4a72","kind":"field_change","created_at":"2026-11-18T14:34:44.803671161Z","actor":"Shinuwa","issue_id":"sokko-g-nz26","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Closed"}}
|
||||
{"id":"int-b698fa576eae0abf4d9fc1e419f3c017","kind":"field_change","created_at":"2026-11-18T14:36:20.893548004Z","actor":"Shinuwa","issue_id":"sokko-g-a5ai","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Closed"}}
|
||||
{"id":"int-da51bff9acf776eb69455d4eff19cec2","kind":"field_change","created_at":"2026-11-18T14:43:12.194977093Z","actor":"Shinuwa","issue_id":"sokko-g-ai7g","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Closed"}}
|
||||
{"id":"int-f575237a44ede80d416712eefda7a85d","kind":"field_change","created_at":"2026-11-18T15:42:16.458576079Z","actor":"Shinuwa","issue_id":"sokko-g-xmqn","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Closed"}}
|
||||
|
|
|
|||
|
|
@ -1484,7 +1484,7 @@ les pages Guilde et Carte du jour (`daily`, sans entrée propre), le menu désig
|
|||
bouton de retour, l'Accueil étant dans le menu ; la Carte du jour garde dans son en-tête un retour (`nds-button` `sm`
|
||||
secondaire) vers la Guilde.
|
||||
La Carte du jour place côte à côte l'illustration carrée (360 px au plus),
|
||||
zoomée par `transform: scale()` dans un cadre qui masque le reste, avec une rangée de six
|
||||
recadrée par le serveur sur la zone visible au zoom courant (chaque nouveau morceau apparaît en fondu), avec une rangée de six
|
||||
pastilles d'essais (gris : raté, `warning` : bonne collection, `success` : trouvée), et
|
||||
une colonne de jeu. Celle-ci contient le formulaire `nds-panel` avec `CategoryAutocompleteInput`
|
||||
(le panneau laisse dépasser les suggestions), puis les essais en `nds-list-row` avec un badge
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ L'interface cible les fenêtres d'ordinateur en plein écran ou en demi-écran.
|
|||
- Sokko TCG : recharge serveur, paquets de trois cartes, album, historique,
|
||||
échanges/dons protégés, distributions promotionnelles administrées, notice de
|
||||
confidentialité et suppression de compte en libre-service.
|
||||
- Guilde des Veilleurs de Sokko TCG, qui confie des quêtes, dont la Carte du jour : un défi quotidien commun à tous les joueurs, qui consiste à
|
||||
- Guilde des Veilleurs de Sokko TCG, qui confie des quêtes, dont la Carte du jour : un défi quotidien, avec une carte propre à chaque joueur, qui consiste à
|
||||
retrouver une illustration zoomée en 6 essais, avec des indices de collection et
|
||||
de rareté, une récompense en poussière d'étoiles et un résultat à partager.
|
||||
- Expéditions de Sokko TCG, seconde quête de la Guilde : des cartes rares ou mieux partent, seules ou
|
||||
|
|
|
|||
|
|
@ -92,22 +92,29 @@ Poussière d'étoiles et boutique :
|
|||
- `shop_settings.daily_reward` (migration 7) : poussière créditée par une victoire à la
|
||||
Carte du jour (entier de 0 à 100 000, 10 au départ), réglée dans Administration › Guilde (enregistrée avec les réglages de la boutique).
|
||||
|
||||
Carte du jour (migration 7, règles pures dans `services/cards/daily.js`) :
|
||||
Carte du jour (migrations 7 et 18, règles pures dans `services/cards/daily.js`) :
|
||||
|
||||
- Le jour change à minuit, heure de Paris (clé `AAAA-MM-JJ`). Tous les joueurs ont la même
|
||||
carte, tirée au premier appel du jour parmi les cartes des collections actives, hors cartes
|
||||
tirées les 60 derniers jours tant qu'il en reste d'autres.
|
||||
- `daily_puzzles(day, card_id, focus_x, focus_y, created_at)` : la carte du jour et le point
|
||||
zoomé (20 à 80 % de l'image). Le numéro du défi est le rang du jour dans cette table.
|
||||
- `daily_attempts(player_id, day, guesses_json, status, reward, updated_at)` : la partie d'un
|
||||
joueur. `guesses_json` liste les cartes proposées dans l'ordre ; `status` vaut `playing`,
|
||||
`won` ou `lost` (6 essais au plus) ; `reward` est la poussière créditée par la victoire.
|
||||
- Le jour change à minuit, heure de Paris (clé `AAAA-MM-JJ`). Chaque joueur a sa propre carte
|
||||
(migration 18 ; une carte commune incitait à se passer la réponse), tirée à sa première visite
|
||||
de la Carte du jour parmi les cartes illustrées des collections actives, hors cartes qu'il a eues
|
||||
les 60 derniers jours tant qu'il en reste d'autres. Le résumé du tableau de bord ne tire rien.
|
||||
- `daily_days(day, created_at)` : les jours de la Carte du jour ; le numéro du défi est le rang
|
||||
du jour dans cette table.
|
||||
- `daily_attempts(player_id, day, card_id, focus_x, focus_y, guesses_json, status, reward,
|
||||
created_at, updated_at)` : la partie d'un joueur, créée au tirage de sa carte. `focus_x` et
|
||||
`focus_y` situent le point zoomé (20 à 80 % de l'image) ; `guesses_json` liste les cartes
|
||||
proposées dans l'ordre ; `status` vaut `playing`, `won` ou `lost` (6 essais au plus) ;
|
||||
`reward` est la poussière créditée par la victoire. La migration 18 a gardé les parties
|
||||
passées avec la carte commune de leur jour.
|
||||
- `GET /api/cards/daily` : partie du jour, indices de chaque essai (bonne collection, rareté de
|
||||
la réponse égale, plus haute ou plus basse), zoom, série de victoires et collections dont les
|
||||
cartes peuvent être proposées. `answerCardId` n'est renvoyé qu'une fois la partie terminée.
|
||||
- `GET /api/cards/daily/image` : l'illustration du jour, sous cette adresse fixe
|
||||
cartes peuvent être proposées. `answerCardId` n'est renvoyé qu'une fois la partie terminée, et
|
||||
le point zoomé jamais.
|
||||
- `GET /api/cards/daily/image` : l'illustration du joueur, sous cette adresse fixe
|
||||
(`Cache-Control: private, no-store`) pour ne pas révéler la carte par son nom de fichier.
|
||||
Le zoom est appliqué par le navigateur : la récompense fixe rend la triche sans intérêt.
|
||||
Pendant la partie, le serveur (`sharp`, `services/cards/daily-image.js`) n'envoie que la zone
|
||||
visible au zoom courant, agrandie à 720 px de large ; l'illustration entière n'arrive qu'en fin de
|
||||
partie. Un petit cache mémoire garde les 64 derniers morceaux.
|
||||
- `POST /api/cards/daily/guesses` (`{ day, cardId }`) : `DAILY_EXPIRED` si le jour annoncé n'est
|
||||
plus le jour en cours, `DAILY_FINISHED`, `DAILY_GUESS_REPEATED` ou `DAILY_GUESS_INVALID`
|
||||
sinon. Une victoire crédite `daily_reward` et inscrit `daily_won` (numéro, carte, essais,
|
||||
|
|
@ -358,7 +365,7 @@ Le tableau de bord administrateur lit un agrégat calculé depuis ces tables.
|
|||
d'ouvertures après recharge serveur, cartes possédées par rareté (somme des quantités),
|
||||
transferts terminés (`transfersCount`) et poussière d'étoiles.
|
||||
- `shopSetting`, et le nombre de joueurs possédant chaque édition (`editionOwners`).
|
||||
- `daily` : carte du jour, numéro, joueurs et gagnants du jour.
|
||||
- `daily` : numéro de la Carte du jour, joueurs (ceux qui ont proposé au moins une carte) et gagnants du jour.
|
||||
- `recordedEditions` : éditions possédées ou citées par une ouverture ou un transfert.
|
||||
|
||||
Cet agrégat ne renvoie pas l'identifiant Discord au navigateur.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { DatabaseSync } from "node:sqlite";
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
// Sélecteurs à choix unique du design system (`SelectDropdown`).
|
||||
|
|
@ -1783,21 +1784,28 @@ test("a player finds the daily card with hints and copies the result", async ({
|
|||
await expect(sections.getByRole("link", { name: /^Guilde/ })).toHaveAttribute("aria-current", "page");
|
||||
await expect(page.getByRole("link", { name: "Retour à la Guilde", exact: true })).toHaveAttribute("href", "#/cards/guild");
|
||||
|
||||
// L'illustration arrive en blob, sans adresse qui nommerait la carte, et commence très zoomée.
|
||||
// L'illustration arrive en blob, sans adresse qui nommerait la carte : seulement la zone visible, recadrée et agrandie par
|
||||
// le serveur (720 px de large), sans agrandissement CSS à défaire.
|
||||
const image = page.getByRole("img", { name: "Illustration de la Carte du jour, agrandie" });
|
||||
await expect(image).toHaveAttribute("src", /^blob:/);
|
||||
await expect.poll(() => image.evaluate((element) => element.naturalWidth)).toBeGreaterThan(0);
|
||||
await expect(image).toHaveCSS("transform", "matrix(6, 0, 0, 6, 0, 0)");
|
||||
await expect.poll(() => image.evaluate((element) => element.naturalWidth)).toBe(720);
|
||||
await expect(image).toHaveCSS("transform", "none");
|
||||
const firstCrop = await image.getAttribute("src");
|
||||
|
||||
const { answer, wrong, sameCollection } = await page.evaluate(async () => {
|
||||
const [dashboard, config, daily] = await Promise.all(["/api/cards/admin/dashboard", "/api/cards/config", "/api/cards/daily"].map(async (path) => (await globalThis.fetch(path)).json()));
|
||||
// Chaque joueur a sa propre carte, que l'API ne donne qu'en fin de partie : le parcours la lit dans la base du serveur E2E.
|
||||
const { path: databasePath } = JSON.parse(await readFile(join(tmpdir(), "sokkog-cards-e2e-db.json"), "utf8"));
|
||||
const database = new DatabaseSync(databasePath, { readOnly: true });
|
||||
const { card_id: answerId } = database.prepare("SELECT attempt.card_id FROM daily_attempts AS attempt JOIN players ON players.id = attempt.player_id WHERE players.discord_id = 'dev-admin' ORDER BY attempt.day DESC LIMIT 1").get();
|
||||
database.close();
|
||||
const { answer, wrong, sameCollection } = await page.evaluate(async (answerCardId) => {
|
||||
const [config, daily] = await Promise.all(["/api/cards/config", "/api/cards/daily"].map(async (path) => (await globalThis.fetch(path)).json()));
|
||||
const cards = config.catalog.cards;
|
||||
const answerCard = cards.find((card) => card.id === dashboard.daily.cardId);
|
||||
const answerCard = cards.find((card) => card.id === answerCardId);
|
||||
// Une carte de la même collection si elle en a d'autres (la collection de la boutique n'en compte qu'une).
|
||||
const others = cards.filter((card) => card.id !== answerCard.id && daily.collectionIds.includes(card.collectionId));
|
||||
const wrongCard = others.find((card) => card.collectionId === answerCard.collectionId) || others[0];
|
||||
return { answer: answerCard.name, wrong: wrongCard.name, sameCollection: wrongCard.collectionId === answerCard.collectionId };
|
||||
});
|
||||
}, answerId);
|
||||
|
||||
const input = page.getByRole("combobox", { name: /^Votre proposition/ });
|
||||
// La recherche ignore les accents et la casse.
|
||||
|
|
@ -1810,7 +1818,9 @@ test("a player finds the daily card with hints and copies the result", async ({
|
|||
await expect(guesses).toHaveCount(1);
|
||||
await expect(guesses.first()).toContainText(wrong);
|
||||
await expect(guesses.first()).toContainText(sameCollection ? "Même collection" : "Pas dans");
|
||||
await expect(image).toHaveCSS("transform", "matrix(4.2, 0, 0, 4.2, 0, 0)");
|
||||
// Un essai raté fait venir un morceau plus large de l'illustration.
|
||||
await expect(image).not.toHaveAttribute("src", firstCrop);
|
||||
await expect.poll(() => image.evaluate((element) => element.naturalWidth)).toBe(720);
|
||||
await expect(page.locator(`.nebula-daily-steps li[data-result="${sameCollection ? "close" : "miss"}"]`)).toHaveCount(1);
|
||||
|
||||
await input.fill(answer);
|
||||
|
|
@ -1820,7 +1830,8 @@ test("a player finds the daily card with hints and copies the result", async ({
|
|||
await expect(result).toContainText("+10 poussières gagnées");
|
||||
await expect(result.locator(".nebula-daily-answer strong")).toHaveText(answer);
|
||||
await expect(result.locator(".nebula-card")).toBeVisible();
|
||||
await expect(image).toHaveCSS("transform", "matrix(1, 0, 0, 1, 0, 0)");
|
||||
// La partie finie, l'illustration entière arrive à sa taille d'origine, à la place des morceaux de 720 px.
|
||||
await expect.poll(() => image.evaluate((element) => element.naturalWidth)).not.toBe(720);
|
||||
await expect(page.getByRole("combobox", { name: /^Votre proposition/ })).toHaveCount(0);
|
||||
|
||||
await result.getByRole("button", { name: "Copier le résultat", exact: true }).click();
|
||||
|
|
|
|||
587
package-lock.json
generated
587
package-lock.json
generated
|
|
@ -11,6 +11,7 @@
|
|||
"@vitejs/plugin-react": "^6.0.3",
|
||||
"react": "^19.2.7",
|
||||
"react-dom": "^19.2.7",
|
||||
"sharp": "0.34.5",
|
||||
"vite": "^8.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
@ -291,6 +292,16 @@
|
|||
"keyv": "^5.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/runtime": {
|
||||
"version": "1.11.3",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz",
|
||||
"integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint-community/eslint-utils": {
|
||||
"version": "4.10.1",
|
||||
"resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.10.1.tgz",
|
||||
|
|
@ -485,6 +496,519 @@
|
|||
"url": "https://github.com/sponsors/nzakas"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/colour": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz",
|
||||
"integrity": "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-darwin-arm64": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.34.5.tgz",
|
||||
"integrity": "sha512-imtQ3WMJXbMY4fxb/Ndp6HBTNVtWCUI0WdobyheGf5+ad6xX8VIDO8u2xE4qc/fr08CKG/7dDseFtn6M6g/r3w==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-darwin-arm64": "1.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-darwin-x64": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.34.5.tgz",
|
||||
"integrity": "sha512-YNEFAF/4KQ/PeW0N+r+aVVsoIY0/qxxikF2SWdp+NRkmMB7y9LBZAVqQ4yhGCm/H3H270OSykqmQMKLBhBJDEw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-darwin-x64": "1.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-libvips-darwin-arm64": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.2.4.tgz",
|
||||
"integrity": "sha512-zqjjo7RatFfFoP0MkQ51jfuFZBnVE2pRiaydKJ1G/rHZvnsrHAOcQALIi9sA5co5xenQdTugCvtb1cuf78Vf4g==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-libvips-darwin-x64": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.2.4.tgz",
|
||||
"integrity": "sha512-1IOd5xfVhlGwX+zXv2N93k0yMONvUlANylbJw1eTah8K/Jtpi15KC+WSiaX/nBmbm2HxRM1gZ0nSdjSsrZbGKg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-libvips-linux-arm": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.2.4.tgz",
|
||||
"integrity": "sha512-bFI7xcKFELdiNCVov8e44Ia4u2byA+l3XtsAj+Q8tfCwO6BQ8iDojYdvoPMqsKDkuoOo+X6HZA0s0q11ANMQ8A==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-libvips-linux-arm64": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.2.4.tgz",
|
||||
"integrity": "sha512-excjX8DfsIcJ10x1Kzr4RcWe1edC9PquDRRPx3YVCvQv+U5p7Yin2s32ftzikXojb1PIFc/9Mt28/y+iRklkrw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-libvips-linux-ppc64": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-ppc64/-/sharp-libvips-linux-ppc64-1.2.4.tgz",
|
||||
"integrity": "sha512-FMuvGijLDYG6lW+b/UvyilUWu5Ayu+3r2d1S8notiGCIyYU/76eig1UfMmkZ7vwgOrzKzlQbFSuQfgm7GYUPpA==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-libvips-linux-riscv64": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-riscv64/-/sharp-libvips-linux-riscv64-1.2.4.tgz",
|
||||
"integrity": "sha512-oVDbcR4zUC0ce82teubSm+x6ETixtKZBh/qbREIOcI3cULzDyb18Sr/Wcyx7NRQeQzOiHTNbZFF1UwPS2scyGA==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-libvips-linux-s390x": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.2.4.tgz",
|
||||
"integrity": "sha512-qmp9VrzgPgMoGZyPvrQHqk02uyjA0/QrTO26Tqk6l4ZV0MPWIW6LTkqOIov+J1yEu7MbFQaDpwdwJKhbJvuRxQ==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-libvips-linux-x64": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.2.4.tgz",
|
||||
"integrity": "sha512-tJxiiLsmHc9Ax1bz3oaOYBURTXGIRDODBqhveVHonrHJ9/+k89qbLl0bcJns+e4t4rvaNBxaEZsFtSfAdquPrw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-libvips-linuxmusl-arm64": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.2.4.tgz",
|
||||
"integrity": "sha512-FVQHuwx1IIuNow9QAbYUzJ+En8KcVm9Lk5+uGUQJHaZmMECZmOlix9HnH7n1TRkXMS0pGxIJokIVB9SuqZGGXw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-libvips-linuxmusl-x64": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.2.4.tgz",
|
||||
"integrity": "sha512-+LpyBk7L44ZIXwz/VYfglaX/okxezESc6UxDSoyo2Ks6Jxc4Y7sGjpgU9s4PMgqgjj1gZCylTieNamqA1MF7Dg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-linux-arm": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.34.5.tgz",
|
||||
"integrity": "sha512-9dLqsvwtg1uuXBGZKsxem9595+ujv0sJ6Vi8wcTANSFpwV/GONat5eCkzQo/1O6zRIkh0m/8+5BjrRr7jDUSZw==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-arm": "1.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-linux-arm64": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.34.5.tgz",
|
||||
"integrity": "sha512-bKQzaJRY/bkPOXyKx5EVup7qkaojECG6NLYswgktOZjaXecSAeCWiZwwiFf3/Y+O1HrauiE3FVsGxFg8c24rZg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-arm64": "1.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-linux-ppc64": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-linux-ppc64/-/sharp-linux-ppc64-0.34.5.tgz",
|
||||
"integrity": "sha512-7zznwNaqW6YtsfrGGDA6BRkISKAAE1Jo0QdpNYXNMHu2+0dTrPflTLNkpc8l7MUP5M16ZJcUvysVWWrMefZquA==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-ppc64": "1.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-linux-riscv64": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-linux-riscv64/-/sharp-linux-riscv64-0.34.5.tgz",
|
||||
"integrity": "sha512-51gJuLPTKa7piYPaVs8GmByo7/U7/7TZOq+cnXJIHZKavIRHAP77e3N2HEl3dgiqdD/w0yUfiJnII77PuDDFdw==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-riscv64": "1.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-linux-s390x": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.34.5.tgz",
|
||||
"integrity": "sha512-nQtCk0PdKfho3eC5MrbQoigJ2gd1CgddUMkabUj+rBevs8tZ2cULOx46E7oyX+04WGfABgIwmMC0VqieTiR4jg==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-s390x": "1.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-linux-x64": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.34.5.tgz",
|
||||
"integrity": "sha512-MEzd8HPKxVxVenwAa+JRPwEC7QFjoPWuS5NZnBt6B3pu7EG2Ge0id1oLHZpPJdn3OQK+BQDiw9zStiHBTJQQQQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linux-x64": "1.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-linuxmusl-arm64": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.34.5.tgz",
|
||||
"integrity": "sha512-fprJR6GtRsMt6Kyfq44IsChVZeGN97gTD331weR1ex1c1rypDEABN6Tm2xa1wE6lYb5DdEnk03NZPqA7Id21yg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linuxmusl-arm64": "1.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-linuxmusl-x64": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.34.5.tgz",
|
||||
"integrity": "sha512-Jg8wNT1MUzIvhBFxViqrEhWDGzqymo3sV7z7ZsaWbZNDLXRJZoRGrjulp60YYtV4wfY8VIKcWidjojlLcWrd8Q==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-libvips-linuxmusl-x64": "1.2.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-wasm32": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.34.5.tgz",
|
||||
"integrity": "sha512-OdWTEiVkY2PHwqkbBI8frFxQQFekHaSSkUIJkwzclWZe64O1X4UlUjqqqLaPbUpMOQk6FBu/HtlGXNblIs0huw==",
|
||||
"cpu": [
|
||||
"wasm32"
|
||||
],
|
||||
"license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/runtime": "^1.7.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-win32-arm64": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-win32-arm64/-/sharp-win32-arm64-0.34.5.tgz",
|
||||
"integrity": "sha512-WQ3AgWCWYSb2yt+IG8mnC6Jdk9Whs7O0gxphblsLvdhSpSTtmu69ZG1Gkb6NuvxsNACwiPV6cNSZNzt0KPsw7g==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "Apache-2.0 AND LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-win32-ia32": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.34.5.tgz",
|
||||
"integrity": "sha512-FV9m/7NmeCmSHDD5j4+4pNI8Cp3aW+JvLoXcTUo0IqyjSfAZJ8dIUmijx1qaJsIiU+Hosw6xM5KijAWRJCSgNg==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"license": "Apache-2.0 AND LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@img/sharp-win32-x64": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.34.5.tgz",
|
||||
"integrity": "sha512-+29YMsqY2/9eFEiW93eqWnuLcWcufowXewwSNIT6UwZdUUCrM3oFjMWH/Z6/TMmb4hlFenmfAVbpWeup2jryCw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "Apache-2.0 AND LGPL-3.0-or-later",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
}
|
||||
},
|
||||
"node_modules/@jridgewell/gen-mapping": {
|
||||
"version": "0.3.13",
|
||||
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
|
||||
|
|
@ -2578,6 +3102,62 @@
|
|||
"semver": "bin/semver.js"
|
||||
}
|
||||
},
|
||||
"node_modules/sharp": {
|
||||
"version": "0.34.5",
|
||||
"resolved": "https://registry.npmjs.org/sharp/-/sharp-0.34.5.tgz",
|
||||
"integrity": "sha512-Ou9I5Ft9WNcCbXrU9cMgPBcCK8LiwLqcbywW3t4oDV37n1pzpuNLsYiAV8eODnjbtQlSDwZ2cUEeQz4E54Hltg==",
|
||||
"hasInstallScript": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@img/colour": "^1.0.0",
|
||||
"detect-libc": "^2.1.2",
|
||||
"semver": "^7.7.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/libvips"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@img/sharp-darwin-arm64": "0.34.5",
|
||||
"@img/sharp-darwin-x64": "0.34.5",
|
||||
"@img/sharp-libvips-darwin-arm64": "1.2.4",
|
||||
"@img/sharp-libvips-darwin-x64": "1.2.4",
|
||||
"@img/sharp-libvips-linux-arm": "1.2.4",
|
||||
"@img/sharp-libvips-linux-arm64": "1.2.4",
|
||||
"@img/sharp-libvips-linux-ppc64": "1.2.4",
|
||||
"@img/sharp-libvips-linux-riscv64": "1.2.4",
|
||||
"@img/sharp-libvips-linux-s390x": "1.2.4",
|
||||
"@img/sharp-libvips-linux-x64": "1.2.4",
|
||||
"@img/sharp-libvips-linuxmusl-arm64": "1.2.4",
|
||||
"@img/sharp-libvips-linuxmusl-x64": "1.2.4",
|
||||
"@img/sharp-linux-arm": "0.34.5",
|
||||
"@img/sharp-linux-arm64": "0.34.5",
|
||||
"@img/sharp-linux-ppc64": "0.34.5",
|
||||
"@img/sharp-linux-riscv64": "0.34.5",
|
||||
"@img/sharp-linux-s390x": "0.34.5",
|
||||
"@img/sharp-linux-x64": "0.34.5",
|
||||
"@img/sharp-linuxmusl-arm64": "0.34.5",
|
||||
"@img/sharp-linuxmusl-x64": "0.34.5",
|
||||
"@img/sharp-wasm32": "0.34.5",
|
||||
"@img/sharp-win32-arm64": "0.34.5",
|
||||
"@img/sharp-win32-ia32": "0.34.5",
|
||||
"@img/sharp-win32-x64": "0.34.5"
|
||||
}
|
||||
},
|
||||
"node_modules/sharp/node_modules/semver": {
|
||||
"version": "7.8.6",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.6.tgz",
|
||||
"integrity": "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==",
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/shebang-command": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||
|
|
@ -2626,6 +3206,13 @@
|
|||
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.9.1",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
|
||||
"integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
|
||||
"license": "0BSD",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/type-check": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
"@vitejs/plugin-react": "^6.0.3",
|
||||
"react": "^19.2.7",
|
||||
"react-dom": "^19.2.7",
|
||||
"sharp": "0.34.5",
|
||||
"vite": "^8.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ for (const editionId of ["aurora-wolf-standard", "aurora-wolf-standard", "aurora
|
|||
for (const card of seedService.catalog.cards.filter((item) => item.kind === "destination")) seedService.addCard(partner.id, seedService.catalog.editions.find((edition) => edition.cardId === card.id).id);
|
||||
seedDatabase.db.prepare("UPDATE players SET stardust = 500 WHERE id = ?").run(partner.id);
|
||||
writeFileSync(join(tmpdir(), "sokkog-cards-e2e-partner.json"), JSON.stringify({ token: seedService.createSession(partner.id).token }));
|
||||
// Chaque joueur a sa propre Carte du jour, jamais exposée par l'API avant la fin de la partie : le parcours la lit en base.
|
||||
writeFileSync(join(tmpdir(), "sokkog-cards-e2e-db.json"), JSON.stringify({ path: process.env.CARDS_DB_PATH }));
|
||||
// Une base neuve n'a aucune variation mythique : les parcours de jeu et d'administration en ont besoin.
|
||||
const insertVariation = seedDatabase.db.prepare("INSERT INTO mythic_variations(edition_id, card_id, finish_id, status, updated_at, updated_by) VALUES (?, ?, ?, 'active', 0, NULL)");
|
||||
for (const cardId of ["starvoid-dragon", "crimson-moon-kitsune", "milky-way-panda", "constellation-magpie", "solar-dawn-capybara", "aurora-wolf"]) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
// Rôle : expose l'API HTTP, l'authentification Discord et les protections de session Sokko TCG.
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { CardsDatabase } from "./database.js";
|
||||
import { loadCardsCatalog, publicCatalog } from "./catalog.js";
|
||||
import { createDailyImageRenderer } from "./daily-image.js";
|
||||
import { DEFAULT_DESTINATIONS_PATH, loadExpeditionDestinations } from "./expedition-content.js";
|
||||
import { createDiscordAlertSender, dispatchAlerts } from "./discord-alerts.js";
|
||||
import { CardsService, DEV_DISCORD_ID } from "./service.js";
|
||||
|
|
@ -140,6 +140,7 @@ export function createCardsApiHandler({
|
|||
const destinations = loadExpeditionDestinations(destinationsPath, catalog);
|
||||
service = new CardsService({ database, catalog, now, random, devPerks, destinations, alerts: { available: Boolean(alertSender), publicOrigin: env.CARDS_PUBLIC_ORIGIN || null } });
|
||||
}
|
||||
const renderDailyImage = createDailyImageRenderer(join(projectRoot, "website", "public"));
|
||||
const secureCookies = env.NODE_ENV === "production" || String(env.CARDS_PUBLIC_ORIGIN || "").startsWith("https://");
|
||||
const adminIds = new Set(String(env.CARDS_ADMIN_DISCORD_IDS || "").split(",").map((item) => item.trim()).filter(Boolean));
|
||||
service?.syncAdmins(adminIds, { keepDevAdmin: devAuth });
|
||||
|
|
@ -308,9 +309,10 @@ export function createCardsApiHandler({
|
|||
json(res, 200, service.getDaily(session.player.id));
|
||||
return true;
|
||||
}
|
||||
// L'illustration du jour passe par cette adresse fixe : ni son nom de fichier ni une redirection ne révèlent la carte.
|
||||
// L'illustration du jour passe par cette adresse fixe : ni son nom de fichier ni une redirection ne révèlent la carte,
|
||||
// et seule la zone visible au zoom courant est envoyée tant que la partie dure.
|
||||
if (req.method === "GET" && url.pathname === "/api/cards/daily/image") {
|
||||
const image = await readFile(join(projectRoot, "website", "public", service.dailyImage()));
|
||||
const image = await renderDailyImage(service.dailyImage(session.player.id));
|
||||
res.writeHead(200, { "Content-Type": "image/webp", "Content-Length": image.length, "Cache-Control": "private, no-store", "X-Content-Type-Options": "nosniff" });
|
||||
res.end(image);
|
||||
return true;
|
||||
|
|
|
|||
38
services/cards/daily-image.js
Normal file
38
services/cards/daily-image.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// Rôle : prépare l'illustration de la Carte du jour envoyée au joueur : seulement la zone visible au zoom courant, agrandie,
|
||||
// pour que ni « Ouvrir l'image » ni les outils du navigateur ne montrent la carte entière avant la fin de la partie.
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import sharp from "sharp";
|
||||
import { dailyCrop } from "./daily.js";
|
||||
|
||||
// Taille du morceau envoyé : le cadre de jeu fait 360 px au plus, doublés pour les écrans denses.
|
||||
const OUTPUT_SIZE = 720;
|
||||
// Quelques joueurs par jour partagent rarement une carte et un point de zoom : un petit cache évite surtout de recalculer
|
||||
// un morceau quand la page se recharge.
|
||||
const CACHE_LIMIT = 64;
|
||||
|
||||
export function createDailyImageRenderer(publicRoot) {
|
||||
const cache = new Map();
|
||||
return function render({ image, focus, zoom }) {
|
||||
const path = join(publicRoot, image);
|
||||
// Partie terminée : l'illustration entière, telle quelle.
|
||||
if (!(zoom > 1)) return readFile(path);
|
||||
const key = `${image}|${focus.x}|${focus.y}|${zoom}`;
|
||||
const cached = cache.get(key);
|
||||
if (cached) {
|
||||
cache.delete(key);
|
||||
cache.set(key, cached);
|
||||
return cached;
|
||||
}
|
||||
const rendered = (async () => {
|
||||
const source = sharp(path);
|
||||
const { width, height } = await source.metadata();
|
||||
return source.extract(dailyCrop(width, height, focus, zoom)).resize({ width: OUTPUT_SIZE }).webp({ quality: 86 }).toBuffer();
|
||||
})();
|
||||
cache.set(key, rendered);
|
||||
if (cache.size > CACHE_LIMIT) cache.delete(cache.keys().next().value);
|
||||
// Un échec ne reste pas en cache : le prochain appel réessaie.
|
||||
rendered.catch(() => cache.delete(key));
|
||||
return rendered;
|
||||
};
|
||||
}
|
||||
|
|
@ -66,6 +66,16 @@ export function drawDailyPuzzle(catalog, recentCardIds = [], random = (max) => r
|
|||
return { cardId: card.id, focusX: FOCUS_MIN + random(span), focusY: FOCUS_MIN + random(span) };
|
||||
}
|
||||
|
||||
// Zone de l'illustration visible au zoom `zoom` autour du point `focus` (en %), comme un agrandissement CSS de même origine :
|
||||
// le serveur n'envoie que ce morceau. Un zoom de 1 ou moins rend l'illustration entière.
|
||||
export function dailyCrop(width, height, focus, zoom) {
|
||||
if (!(zoom > 1)) return { left: 0, top: 0, width, height };
|
||||
const cropWidth = Math.max(1, Math.round(width / zoom));
|
||||
const cropHeight = Math.max(1, Math.round(height / zoom));
|
||||
const offset = (size, crop, percent) => Math.min(size - crop, Math.max(0, Math.round((size - crop) * percent / 100)));
|
||||
return { left: offset(width, cropWidth, focus.x), top: offset(height, cropHeight, focus.y), width: cropWidth, height: cropHeight };
|
||||
}
|
||||
|
||||
// Indice d'un essai : bonne collection ou non, et rareté de la réponse par rapport à celle de l'essai.
|
||||
export function guessHint(catalog, answerId, guessId) {
|
||||
const cards = new Map(catalog.cards.map((card) => [card.id, card]));
|
||||
|
|
|
|||
|
|
@ -406,6 +406,33 @@ const MIGRATIONS = [
|
|||
// Le Grimoire (paires et Résonances découvertes) est retiré : il n'avait aucun effet sur le jeu.
|
||||
`
|
||||
DROP TABLE IF EXISTS grimoire_entries;
|
||||
`,
|
||||
// Carte du jour personnelle : une carte commune incitait à se passer la réponse. Chaque joueur tire sa carte et son point
|
||||
// de zoom à sa première visite du jour, gardés avec sa partie. daily_days numérote les jours ; les parties passées gardent
|
||||
// la carte commune de leur jour.
|
||||
`
|
||||
CREATE TABLE daily_days (day TEXT PRIMARY KEY, created_at INTEGER NOT NULL) STRICT;
|
||||
INSERT INTO daily_days(day, created_at) SELECT day, created_at FROM daily_puzzles;
|
||||
CREATE TABLE daily_attempts_next (
|
||||
player_id TEXT NOT NULL REFERENCES players(id) ON DELETE CASCADE,
|
||||
day TEXT NOT NULL REFERENCES daily_days(day),
|
||||
card_id TEXT NOT NULL,
|
||||
focus_x INTEGER NOT NULL CHECK (focus_x BETWEEN 0 AND 100),
|
||||
focus_y INTEGER NOT NULL CHECK (focus_y BETWEEN 0 AND 100),
|
||||
guesses_json TEXT NOT NULL,
|
||||
status TEXT NOT NULL CHECK (status IN ('playing', 'won', 'lost')),
|
||||
reward INTEGER NOT NULL DEFAULT 0 CHECK (reward >= 0),
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
PRIMARY KEY (player_id, day)
|
||||
) STRICT;
|
||||
INSERT INTO daily_attempts_next(player_id, day, card_id, focus_x, focus_y, guesses_json, status, reward, created_at, updated_at)
|
||||
SELECT attempt.player_id, attempt.day, puzzle.card_id, puzzle.focus_x, puzzle.focus_y, attempt.guesses_json, attempt.status, attempt.reward, attempt.updated_at, attempt.updated_at
|
||||
FROM daily_attempts AS attempt JOIN daily_puzzles AS puzzle ON puzzle.day = attempt.day;
|
||||
DROP TABLE daily_attempts;
|
||||
DROP TABLE daily_puzzles;
|
||||
ALTER TABLE daily_attempts_next RENAME TO daily_attempts;
|
||||
CREATE INDEX daily_attempts_day_idx ON daily_attempts(day, status);
|
||||
`
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|||
import { normalizeReward } from "./rewards.js";
|
||||
import { planRecycling, spareQuantity, validateShopSetting } from "./stardust.js";
|
||||
import { FULL_ART_FORMAT, buildPublishedCatalog, collectionDrawableEditions, createCatalogIndex, holographicFinishIds, legendaryParentEdition, MATCH_HOLO_PALETTE_ID, mythicEditionId, publicCatalog, validateRarityWeights } from "./catalog.js";
|
||||
import { computeStreak, DAILY_REPEAT_WINDOW_DAYS, dailyDayKey, dailyZoom, drawDailyPuzzle, guessHint, isDayKey, MAX_DAILY_GUESSES, nextDailyAt, shiftDayKey } from "./daily.js";
|
||||
import { computeStreak, DAILY_REPEAT_WINDOW_DAYS, dailyCandidates, dailyDayKey, dailyZoom, drawDailyPuzzle, guessHint, isDayKey, MAX_DAILY_GUESSES, nextDailyAt, shiftDayKey } from "./daily.js";
|
||||
import { calculateRecharge, pinnedRecharge, drawPack, drawShopPack, MAX_RECHARGE_INTERVAL_MS, MIN_RECHARGE_INTERVAL_MS, spendOpening } from "./game-rules.js";
|
||||
import { DEFAULT_DESTINATIONS_PATH, loadExpeditionDestinations } from "./expedition-content.js";
|
||||
import { ExpeditionService } from "./expedition-service.js";
|
||||
|
|
@ -721,25 +721,36 @@ export class CardsService {
|
|||
});
|
||||
}
|
||||
|
||||
// Carte du jour : une carte commune à tous les joueurs, tirée au premier appel du jour de Paris puis gardée en base.
|
||||
// À appeler dans une transaction : deux premiers appels simultanés ne tirent qu'une carte.
|
||||
ensureDailyPuzzle(day) {
|
||||
const stored = () => this.db.prepare("SELECT day, card_id, focus_x, focus_y FROM daily_puzzles WHERE day = ?").get(day);
|
||||
if (!stored()) {
|
||||
const recent = this.db.prepare("SELECT card_id FROM daily_puzzles WHERE day >= ?").all(shiftDayKey(day, -DAILY_REPEAT_WINDOW_DAYS)).map((row) => row.card_id);
|
||||
const drawn = drawDailyPuzzle(this.catalog, recent, this.random);
|
||||
if (!drawn) fail(409, "DAILY_UNAVAILABLE", "Aucune carte ne peut être tirée aujourd’hui.");
|
||||
this.db.prepare("INSERT INTO daily_puzzles(day, card_id, focus_x, focus_y, created_at) VALUES (?, ?, ?, ?, ?)").run(day, drawn.cardId, drawn.focusX, drawn.focusY, this.now());
|
||||
}
|
||||
const row = stored();
|
||||
// Une carte retirée du catalogue après son tirage ne peut plus être affichée.
|
||||
if (!this.index.cards.has(row.card_id)) fail(503, "DAILY_UNAVAILABLE", "La Carte du jour est indisponible.");
|
||||
const number = this.db.prepare("SELECT COUNT(*) AS count FROM daily_puzzles WHERE day <= ?").get(day).count;
|
||||
return { day: row.day, cardId: row.card_id, focus: { x: row.focus_x, y: row.focus_y }, number };
|
||||
// Carte du jour : chaque joueur a sa propre carte, tirée à sa première visite du jour de Paris puis gardée avec sa partie ;
|
||||
// une carte commune incitait à se passer la réponse. daily_days numérote les jours où quelqu'un a joué.
|
||||
// À appeler dans une transaction : deux premières visites simultanées ne tirent qu'une carte.
|
||||
ensureDailyDay(day) {
|
||||
this.db.prepare("INSERT OR IGNORE INTO daily_days(day, created_at) VALUES (?, ?)").run(day, this.now());
|
||||
return this.db.prepare("SELECT COUNT(*) AS count FROM daily_days WHERE day <= ?").get(day).count;
|
||||
}
|
||||
|
||||
todayPuzzle() {
|
||||
return this.database.transaction(() => this.ensureDailyPuzzle(dailyDayKey(this.now())));
|
||||
dailyAttemptRow(playerId, day) {
|
||||
return this.db.prepare("SELECT card_id, focus_x, focus_y, guesses_json, status, reward FROM daily_attempts WHERE player_id = ? AND day = ?").get(playerId, day);
|
||||
}
|
||||
|
||||
// Partie du joueur pour ce jour, tirée s'il n'en a pas encore : pas de carte qu'il a déjà eue ces 60 derniers jours.
|
||||
ensureDailyPuzzle(playerId, day) {
|
||||
const number = this.ensureDailyDay(day);
|
||||
if (!this.dailyAttemptRow(playerId, day)) {
|
||||
const recent = this.db.prepare("SELECT card_id FROM daily_attempts WHERE player_id = ? AND day >= ?").all(playerId, shiftDayKey(day, -DAILY_REPEAT_WINDOW_DAYS)).map((row) => row.card_id);
|
||||
const drawn = drawDailyPuzzle(this.catalog, recent, this.random);
|
||||
if (!drawn) fail(409, "DAILY_UNAVAILABLE", "Aucune carte ne peut être tirée aujourd’hui.");
|
||||
this.db.prepare("INSERT INTO daily_attempts(player_id, day, card_id, focus_x, focus_y, guesses_json, status, reward, created_at, updated_at) VALUES (?, ?, ?, ?, ?, '[]', 'playing', 0, ?, ?)")
|
||||
.run(playerId, day, drawn.cardId, drawn.focusX, drawn.focusY, this.now(), this.now());
|
||||
}
|
||||
const row = this.dailyAttemptRow(playerId, day);
|
||||
// Une carte retirée du catalogue après son tirage ne peut plus être affichée.
|
||||
if (!this.index.cards.has(row.card_id)) fail(503, "DAILY_UNAVAILABLE", "La Carte du jour est indisponible.");
|
||||
return { day, number, cardId: row.card_id, focus: { x: row.focus_x, y: row.focus_y }, guesses: JSON.parse(row.guesses_json), status: row.status, earned: row.reward };
|
||||
}
|
||||
|
||||
todayPuzzle(playerId) {
|
||||
return this.database.transaction(() => this.ensureDailyPuzzle(playerId, dailyDayKey(this.now())));
|
||||
}
|
||||
|
||||
// Collections dont le joueur peut proposer les cartes : celles qu'il voit (ouvertes ou dont il possède une carte) et
|
||||
|
|
@ -751,30 +762,28 @@ export class CardsService {
|
|||
return [...ids];
|
||||
}
|
||||
|
||||
dailyAttempt(playerId, day) {
|
||||
const row = this.db.prepare("SELECT guesses_json, status, reward FROM daily_attempts WHERE player_id = ? AND day = ?").get(playerId, day);
|
||||
return { guesses: row ? JSON.parse(row.guesses_json) : [], status: row?.status || "playing", earned: row?.reward ?? 0 };
|
||||
}
|
||||
|
||||
dailyStreak(playerId, day) {
|
||||
return computeStreak(this.db.prepare("SELECT day FROM daily_attempts WHERE player_id = ? AND status = 'won'").all(playerId).map((row) => row.day), day);
|
||||
}
|
||||
|
||||
// La réponse n'est envoyée qu'une fois la partie terminée.
|
||||
// Zoom de la partie : il se relâche à chaque essai raté et vaut 1 une fois la partie terminée.
|
||||
dailyPuzzleZoom(puzzle) {
|
||||
return dailyZoom(puzzle.guesses.length - (puzzle.status === "won" ? 1 : 0), puzzle.status !== "playing");
|
||||
}
|
||||
|
||||
// La réponse n'est envoyée qu'une fois la partie terminée, et l'illustration n'arrive que recadrée (voir dailyImage).
|
||||
dailyView(playerId, puzzle) {
|
||||
const { guesses, status, earned } = this.dailyAttempt(playerId, puzzle.day);
|
||||
const finished = status !== "playing";
|
||||
const finished = puzzle.status !== "playing";
|
||||
return {
|
||||
day: puzzle.day,
|
||||
number: puzzle.number,
|
||||
maxGuesses: MAX_DAILY_GUESSES,
|
||||
focus: puzzle.focus,
|
||||
zoom: dailyZoom(guesses.length - (status === "won" ? 1 : 0), finished),
|
||||
status,
|
||||
guesses: guesses.map((cardId) => guessHint(this.catalog, puzzle.cardId, cardId)),
|
||||
zoom: this.dailyPuzzleZoom(puzzle),
|
||||
status: puzzle.status,
|
||||
guesses: puzzle.guesses.map((cardId) => guessHint(this.catalog, puzzle.cardId, cardId)),
|
||||
collectionIds: this.dailyCollectionIds(playerId, puzzle.cardId),
|
||||
reward: this.shopSetting.dailyReward,
|
||||
earned,
|
||||
earned: puzzle.earned,
|
||||
streak: this.dailyStreak(playerId, puzzle.day),
|
||||
nextAt: nextDailyAt(this.now()),
|
||||
answerCardId: finished ? puzzle.cardId : null
|
||||
|
|
@ -782,19 +791,17 @@ export class CardsService {
|
|||
}
|
||||
|
||||
getDaily(playerId) {
|
||||
return this.dailyView(playerId, this.todayPuzzle());
|
||||
return this.dailyView(playerId, this.todayPuzzle(playerId));
|
||||
}
|
||||
|
||||
// Résumé pour le tableau de bord du joueur ; l'état reste lisible si aucune carte ne peut être tirée.
|
||||
// Résumé pour le tableau de bord du joueur, sans tirer sa carte : il n'en a une qu'en ouvrant la Carte du jour.
|
||||
dailySummary(playerId) {
|
||||
try {
|
||||
const puzzle = this.todayPuzzle();
|
||||
const { guesses, status } = this.dailyAttempt(playerId, puzzle.day);
|
||||
return { day: puzzle.day, number: puzzle.number, status, guessCount: guesses.length, maxGuesses: MAX_DAILY_GUESSES, streak: this.dailyStreak(playerId, puzzle.day) };
|
||||
} catch (error) {
|
||||
if (error.code === "DAILY_UNAVAILABLE") return null;
|
||||
throw error;
|
||||
}
|
||||
const day = dailyDayKey(this.now());
|
||||
if (!dailyCandidates(this.catalog).length) return null;
|
||||
const number = this.database.transaction(() => this.ensureDailyDay(day));
|
||||
const row = this.dailyAttemptRow(playerId, day);
|
||||
const guesses = row ? JSON.parse(row.guesses_json) : [];
|
||||
return { day, number, status: row?.status || "playing", guessCount: guesses.length, maxGuesses: MAX_DAILY_GUESSES, streak: this.dailyStreak(playerId, day) };
|
||||
}
|
||||
|
||||
// Un essai vaut pour le jour annoncé par le client : après minuit, il doit recharger la nouvelle partie.
|
||||
|
|
@ -803,43 +810,39 @@ export class CardsService {
|
|||
const daily = this.database.transaction(() => {
|
||||
const today = dailyDayKey(this.now());
|
||||
if (day !== today) fail(409, "DAILY_EXPIRED", "Une nouvelle Carte du jour est arrivée : rechargez la partie.");
|
||||
const puzzle = this.ensureDailyPuzzle(today);
|
||||
const attempt = this.dailyAttempt(playerId, today);
|
||||
if (attempt.status !== "playing") fail(409, "DAILY_FINISHED", "Vous avez déjà terminé la Carte du jour.");
|
||||
const puzzle = this.ensureDailyPuzzle(playerId, today);
|
||||
if (puzzle.status !== "playing") fail(409, "DAILY_FINISHED", "Vous avez déjà terminé la Carte du jour.");
|
||||
const card = this.index.cards.get(cardId);
|
||||
if (!card || !this.dailyCollectionIds(playerId, puzzle.cardId).includes(card.collectionId)) fail(400, "DAILY_GUESS_INVALID", "Choisissez une carte de la liste.");
|
||||
if (attempt.guesses.includes(cardId)) fail(409, "DAILY_GUESS_REPEATED", "Vous avez déjà proposé cette carte.");
|
||||
const guesses = [...attempt.guesses, cardId];
|
||||
if (puzzle.guesses.includes(cardId)) fail(409, "DAILY_GUESS_REPEATED", "Vous avez déjà proposé cette carte.");
|
||||
const guesses = [...puzzle.guesses, cardId];
|
||||
const won = cardId === puzzle.cardId;
|
||||
const status = won ? "won" : guesses.length >= MAX_DAILY_GUESSES ? "lost" : "playing";
|
||||
const reward = won ? this.shopSetting.dailyReward : 0;
|
||||
this.db.prepare(`INSERT INTO daily_attempts(player_id, day, guesses_json, status, reward, updated_at) VALUES (?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(player_id, day) DO UPDATE SET guesses_json = excluded.guesses_json, status = excluded.status, reward = excluded.reward, updated_at = excluded.updated_at`)
|
||||
.run(playerId, today, JSON.stringify(guesses), status, reward, this.now());
|
||||
this.db.prepare("UPDATE daily_attempts SET guesses_json = ?, status = ?, reward = ?, updated_at = ? WHERE player_id = ? AND day = ?")
|
||||
.run(JSON.stringify(guesses), status, reward, this.now(), playerId, today);
|
||||
if (won) {
|
||||
if (reward) this.db.prepare("UPDATE players SET stardust = stardust + ? WHERE id = ?").run(reward, playerId);
|
||||
this.audit(playerId, "daily_won", today, { number: puzzle.number, cardId, guesses: guesses.length, stardust: reward });
|
||||
}
|
||||
return this.dailyView(playerId, puzzle);
|
||||
return this.dailyView(playerId, { ...puzzle, guesses, status, earned: reward });
|
||||
});
|
||||
// L'état complet suit chaque essai : résumé de la quête du jour et, après une victoire, solde et historique.
|
||||
return { daily, state: this.getState(playerId) };
|
||||
}
|
||||
|
||||
// Illustration de la carte du jour, servie par l'API sous une adresse qui ne révèle pas la carte.
|
||||
dailyImage() {
|
||||
return this.index.cards.get(this.todayPuzzle().cardId).image;
|
||||
// Ce que l'API doit envoyer de l'illustration du joueur : le fichier, le point de zoom et le zoom courant.
|
||||
dailyImage(playerId) {
|
||||
const puzzle = this.todayPuzzle(playerId);
|
||||
return { image: this.index.cards.get(puzzle.cardId).image, focus: puzzle.focus, zoom: this.dailyPuzzleZoom(puzzle) };
|
||||
}
|
||||
|
||||
// Joueurs : ceux qui ont proposé au moins une carte aujourd'hui (ouvrir la page tire une carte sans jouer).
|
||||
dailyAdminSummary() {
|
||||
try {
|
||||
const puzzle = this.todayPuzzle();
|
||||
const counts = this.db.prepare("SELECT COUNT(*) AS players, COALESCE(SUM(status = 'won'), 0) AS winners FROM daily_attempts WHERE day = ?").get(puzzle.day);
|
||||
return { day: puzzle.day, number: puzzle.number, cardId: puzzle.cardId, players: counts.players, winners: counts.winners };
|
||||
} catch (error) {
|
||||
if (error.code === "DAILY_UNAVAILABLE") return null;
|
||||
throw error;
|
||||
}
|
||||
const day = dailyDayKey(this.now());
|
||||
const number = this.database.transaction(() => this.ensureDailyDay(day));
|
||||
const counts = this.db.prepare("SELECT COALESCE(SUM(guesses_json <> '[]'), 0) AS players, COALESCE(SUM(status = 'won'), 0) AS winners FROM daily_attempts WHERE day = ?").get(day);
|
||||
return { day, number, players: counts.players, winners: counts.winners };
|
||||
}
|
||||
|
||||
completeOpening(playerId, openingId) {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@ import { readFile } from "node:fs/promises";
|
|||
import { resolve } from "node:path";
|
||||
import { Readable } from "node:stream";
|
||||
import { test } from "node:test";
|
||||
import sharp from "sharp";
|
||||
import { createCardsApiHandler } from "../services/cards/api.js";
|
||||
import { buildPublishedCatalog, prepareVersionedCatalog } from "../services/cards/catalog.js";
|
||||
import { computeStreak, dailyCandidates, dailyDayKey, dailyZoom, drawDailyPuzzle, guessHint, MAX_DAILY_GUESSES, nextDailyAt, shiftDayKey } from "../services/cards/daily.js";
|
||||
import { computeStreak, dailyCandidates, dailyCrop, dailyDayKey, dailyZoom, drawDailyPuzzle, guessHint, MAX_DAILY_GUESSES, nextDailyAt, shiftDayKey } from "../services/cards/daily.js";
|
||||
import { CardsDatabase } from "../services/cards/database.js";
|
||||
import { CardsService } from "../services/cards/service.js";
|
||||
|
||||
|
|
@ -69,21 +70,31 @@ test("a daily guess tells the collection and how the answer rarity compares", ()
|
|||
assert.equal(dailyZoom(2, true), 1);
|
||||
});
|
||||
|
||||
function dailyService(start = Date.parse("2026-11-13T09:00:00Z")) {
|
||||
function dailyService(start = Date.parse("2026-11-13T09:00:00Z"), random = () => 0) {
|
||||
const clock = { now: start };
|
||||
const database = new CardsDatabase(":memory:");
|
||||
const service = new CardsService({ database, catalog: baseCatalog, now: () => clock.now, random: () => 0 });
|
||||
const service = new CardsService({ database, catalog: baseCatalog, now: () => clock.now, random });
|
||||
const admin = service.upsertPlayer({ discordId: "daily-admin", displayName: "Admin", isAdmin: true });
|
||||
const player = service.upsertPlayer({ discordId: "daily-player", displayName: "Player" });
|
||||
const wrongCards = () => {
|
||||
const answer = service.todayPuzzle().cardId;
|
||||
const answer = service.todayPuzzle(player.id).cardId;
|
||||
return service.catalog.cards.filter((item) => item.collectionId === "primordial-nebula" && item.id !== answer).map((item) => item.id);
|
||||
};
|
||||
return { clock, database, service, admin, player, wrongCards };
|
||||
}
|
||||
|
||||
test("every player gets the same daily card and the answer stays hidden while playing", () => {
|
||||
test("the daily crop keeps the visible part of the illustration around the focus point", () => {
|
||||
assert.deepEqual(dailyCrop(800, 800, { x: 20, y: 20 }, 6), { left: 133, top: 133, width: 133, height: 133 });
|
||||
assert.deepEqual(dailyCrop(800, 800, { x: 100, y: 0 }, 4.2), { left: 610, top: 0, width: 190, height: 190 });
|
||||
assert.deepEqual(dailyCrop(640, 640, { x: 50, y: 80 }, 1.15), { left: 42, top: 66, width: 557, height: 557 });
|
||||
assert.deepEqual(dailyCrop(800, 800, { x: 20, y: 20 }, 1), { left: 0, top: 0, width: 800, height: 800 });
|
||||
});
|
||||
|
||||
test("each player draws a daily card on the first visit and the answer stays hidden while playing", () => {
|
||||
const { service, admin, player, database } = dailyService();
|
||||
// Le tableau de bord résume la quête sans tirer de carte : seul le passage par la Carte du jour en tire une.
|
||||
assert.equal(service.getState(player.id).daily.status, "playing");
|
||||
assert.equal(database.db.prepare("SELECT COUNT(*) AS count FROM daily_attempts").get().count, 0);
|
||||
const daily = service.getDaily(player.id);
|
||||
assert.equal(daily.day, "2026-11-13");
|
||||
assert.equal(daily.number, 1);
|
||||
|
|
@ -92,16 +103,31 @@ test("every player gets the same daily card and the answer stays hidden while pl
|
|||
assert.equal(daily.maxGuesses, MAX_DAILY_GUESSES);
|
||||
assert.equal(daily.reward, 10);
|
||||
assert.equal(daily.answerCardId, null);
|
||||
assert.ok(!JSON.stringify(daily).includes(service.todayPuzzle().cardId));
|
||||
assert.deepEqual(daily.focus, { x: 20, y: 20 });
|
||||
assert.ok(!JSON.stringify(daily).includes(service.todayPuzzle(player.id).cardId));
|
||||
// Le point de zoom reste au serveur, qui n'envoie que la zone visible de l'illustration.
|
||||
assert.equal(daily.focus, undefined);
|
||||
assert.deepEqual(service.dailyImage(player.id).focus, { x: 20, y: 20 });
|
||||
assert.equal(daily.nextAt, Date.parse("2026-11-13T23:00:00Z"));
|
||||
assert.ok(daily.collectionIds.includes("primordial-nebula"));
|
||||
assert.ok(!daily.collectionIds.includes("dream-arcade"));
|
||||
assert.equal(service.getDaily(admin.id).day, daily.day);
|
||||
assert.equal(database.db.prepare("SELECT COUNT(*) AS count FROM daily_puzzles").get().count, 1);
|
||||
assert.equal(database.db.prepare("SELECT COUNT(*) AS count FROM daily_days").get().count, 1);
|
||||
assert.equal(database.db.prepare("SELECT COUNT(*) AS count FROM daily_attempts").get().count, 2);
|
||||
// Ouvrir la page tire une carte sans jouer : l'administration ne compte que les joueurs qui ont proposé une carte.
|
||||
assert.deepEqual(service.getAdminDashboard(admin.id).daily, { day: "2026-11-13", number: 1, players: 0, winners: 0 });
|
||||
assert.equal(service.getState(player.id).daily.status, "playing");
|
||||
});
|
||||
|
||||
test("players get different daily cards, so a shared answer does not help", () => {
|
||||
let draw = 0;
|
||||
const { service, admin, player } = dailyService(undefined, (max) => (draw++ * 7) % max);
|
||||
const mine = service.todayPuzzle(player.id).cardId;
|
||||
const theirs = service.todayPuzzle(admin.id).cardId;
|
||||
assert.notEqual(mine, theirs);
|
||||
assert.equal(service.todayPuzzle(player.id).cardId, mine);
|
||||
assert.equal(service.guessDaily(player.id, { day: "2026-11-13", cardId: theirs }).daily.status, "playing");
|
||||
});
|
||||
|
||||
test("wrong daily guesses unzoom the card until the player runs out of guesses", () => {
|
||||
const { service, player, wrongCards } = dailyService();
|
||||
const [first, ...others] = wrongCards();
|
||||
|
|
@ -121,7 +147,7 @@ test("wrong daily guesses unzoom the card until the player runs out of guesses",
|
|||
assert.equal(last.status, "lost");
|
||||
assert.equal(last.zoom, 1);
|
||||
assert.equal(last.earned, 0);
|
||||
assert.equal(last.answerCardId, service.todayPuzzle().cardId);
|
||||
assert.equal(last.answerCardId, service.todayPuzzle(player.id).cardId);
|
||||
assert.throws(() => service.guessDaily(player.id, { day: "2026-11-13", cardId: others.at(-1) }), (error) => error.code === "DAILY_FINISHED");
|
||||
assert.equal(service.getState(player.id).wallet.stardust, 0);
|
||||
});
|
||||
|
|
@ -129,7 +155,7 @@ test("wrong daily guesses unzoom the card until the player runs out of guesses",
|
|||
test("finding the daily card credits the reward once and records it in the player history", () => {
|
||||
const { service, admin, player, wrongCards } = dailyService();
|
||||
service.updateShopSetting(admin.id, { ...service.shopSetting, dailyReward: 25 });
|
||||
const answer = service.todayPuzzle().cardId;
|
||||
const answer = service.todayPuzzle(player.id).cardId;
|
||||
service.guessDaily(player.id, { day: "2026-11-13", cardId: wrongCards()[0] });
|
||||
const { daily, state } = service.guessDaily(player.id, { day: "2026-11-13", cardId: answer });
|
||||
assert.equal(daily.status, "won");
|
||||
|
|
@ -141,7 +167,7 @@ test("finding the daily card credits the reward once and records it in the playe
|
|||
assert.deepEqual(state.history.find((entry) => entry.type === "daily_won"), { type: "daily_won", entityId: "2026-11-13", details: { number: 1, cardId: answer, guesses: 2, stardust: 25 }, createdAt: Date.parse("2026-11-13T09:00:00Z") });
|
||||
assert.throws(() => service.guessDaily(player.id, { day: "2026-11-13", cardId: answer }), (error) => error.code === "DAILY_FINISHED");
|
||||
assert.equal(service.getState(player.id).wallet.stardust, 25);
|
||||
assert.deepEqual(service.getAdminDashboard(admin.id).daily, { day: "2026-11-13", number: 1, cardId: answer, players: 1, winners: 1 });
|
||||
assert.deepEqual(service.getAdminDashboard(admin.id).daily, { day: "2026-11-13", number: 1, players: 1, winners: 1 });
|
||||
// La récompense de la Carte du jour n'est pas une action d'administration.
|
||||
assert.ok(!service.getAdminHistory(admin.id).entries.some((entry) => entry.type === "daily_won"));
|
||||
assert.throws(() => service.updateShopSetting(admin.id, { ...service.shopSetting, dailyReward: -1 }), /Carte du jour/);
|
||||
|
|
@ -149,7 +175,7 @@ test("finding the daily card credits the reward once and records it in the playe
|
|||
|
||||
test("a new daily card arrives at midnight in Paris and the streak continues", () => {
|
||||
const { clock, service, player } = dailyService();
|
||||
const firstAnswer = service.todayPuzzle().cardId;
|
||||
const firstAnswer = service.todayPuzzle(player.id).cardId;
|
||||
service.guessDaily(player.id, { day: "2026-11-13", cardId: firstAnswer });
|
||||
clock.now = Date.parse("2026-11-13T23:00:00Z");
|
||||
assert.throws(() => service.guessDaily(player.id, { day: "2026-11-13", cardId: firstAnswer }), (error) => error.code === "DAILY_EXPIRED");
|
||||
|
|
@ -158,14 +184,14 @@ test("a new daily card arrives at midnight in Paris and the streak continues", (
|
|||
assert.equal(daily.number, 2);
|
||||
assert.equal(daily.status, "playing");
|
||||
assert.equal(daily.streak, 1);
|
||||
const secondAnswer = service.todayPuzzle().cardId;
|
||||
const secondAnswer = service.todayPuzzle(player.id).cardId;
|
||||
assert.notEqual(secondAnswer, firstAnswer);
|
||||
assert.equal(service.guessDaily(player.id, { day: "2026-11-14", cardId: secondAnswer }).daily.streak, 2);
|
||||
});
|
||||
|
||||
test("deleting an account erases its daily games", () => {
|
||||
const { service, player, database } = dailyService();
|
||||
service.guessDaily(player.id, { day: "2026-11-13", cardId: service.todayPuzzle().cardId });
|
||||
service.guessDaily(player.id, { day: "2026-11-13", cardId: service.todayPuzzle(player.id).cardId });
|
||||
service.deleteAccount(player.id);
|
||||
assert.equal(database.db.prepare("SELECT COUNT(*) AS count FROM daily_attempts WHERE player_id = ?").get(player.id).count, 0);
|
||||
});
|
||||
|
|
@ -195,7 +221,7 @@ async function call(handler, options) {
|
|||
return response;
|
||||
}
|
||||
|
||||
test("the daily API requires a session, protects guesses and serves the image without revealing the card", async (t) => {
|
||||
test("the daily API requires a session, protects guesses and serves only the visible part of the image while playing", async (t) => {
|
||||
const handler = createCardsApiHandler({ projectRoot: resolve("."), enabled: true, devAuth: true, databasePath: ":memory:", env: { NODE_ENV: "test" }, random: () => 0 });
|
||||
t.after(() => handler.close());
|
||||
for (const path of ["/api/cards/daily", "/api/cards/daily/image"]) assert.equal((await call(handler, { path })).status, 401);
|
||||
|
|
@ -214,9 +240,13 @@ test("the daily API requires a session, protects guesses and serves the image wi
|
|||
assert.equal(image.headers["cache-control"], "private, no-store");
|
||||
assert.equal(image.headers["content-disposition"], undefined);
|
||||
assert.equal(image.raw.subarray(8, 12).toString("ascii"), "WEBP");
|
||||
const answer = handler.service.todayPuzzle().cardId;
|
||||
const player = handler.service.db.prepare("SELECT id FROM players WHERE discord_id = 'dev-admin'").get();
|
||||
const answer = handler.service.todayPuzzle(player.id).cardId;
|
||||
assert.ok(!JSON.stringify(image.headers).includes(answer));
|
||||
assert.deepEqual(image.raw, await readFile(resolve("website/public", `.${handler.service.index.cards.get(answer).image}`)));
|
||||
// Pendant la partie, un morceau recadré de 720 px, jamais le fichier de l'illustration.
|
||||
const original = await readFile(resolve("website/public", `.${handler.service.index.cards.get(answer).image}`));
|
||||
assert.notDeepEqual(image.raw, original);
|
||||
assert.equal((await sharp(image.raw).metadata()).width, 720);
|
||||
|
||||
const unprotected = await call(handler, { method: "POST", path: "/api/cards/daily/guesses", headers: { cookie }, body: { day: daily.json.day, cardId: answer } });
|
||||
assert.equal(unprotected.status, 403);
|
||||
|
|
@ -224,6 +254,8 @@ test("the daily API requires a session, protects guesses and serves the image wi
|
|||
assert.equal(won.status, 200);
|
||||
assert.equal(won.json.daily.status, "won");
|
||||
assert.ok(won.json.state.history.some((entry) => entry.type === "daily_won"));
|
||||
// La partie finie, l'illustration entière.
|
||||
assert.deepEqual((await call(handler, { path: "/api/cards/daily/image", headers: { cookie } })).raw, original);
|
||||
const again = await call(handler, { method: "POST", path: "/api/cards/daily/guesses", headers: { cookie, "x-csrf-token": csrf }, body: { day: daily.json.day, cardId: answer } });
|
||||
assert.equal(again.status, 409);
|
||||
assert.equal(again.json.error.code, "DAILY_FINISHED");
|
||||
|
|
|
|||
|
|
@ -83,7 +83,9 @@ export function DailyPanel({ catalog, state, runMutation, busy, content }) {
|
|||
return () => { active = false; };
|
||||
}, [content.unavailable, reloadKey]);
|
||||
|
||||
// Une seule illustration par jour : elle reste en mémoire pendant la partie, le zoom ne fait que changer d'échelle.
|
||||
// Le serveur n'envoie que la zone visible au zoom courant : chaque essai raté recharge un morceau plus large, et
|
||||
// l'illustration entière n'arrive qu'en fin de partie. Le morceau précédent reste affiché pendant le chargement.
|
||||
const zoom = daily?.zoom ?? 0;
|
||||
useEffect(() => {
|
||||
if (!day) return undefined;
|
||||
let active = true;
|
||||
|
|
@ -99,7 +101,7 @@ export function DailyPanel({ catalog, state, runMutation, busy, content }) {
|
|||
active = false;
|
||||
if (url) URL.revokeObjectURL(url);
|
||||
};
|
||||
}, [day]);
|
||||
}, [day, zoom]);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => setNow(Date.now()), COUNTDOWN_TICK_MS);
|
||||
|
|
@ -159,7 +161,7 @@ export function DailyPanel({ catalog, state, runMutation, busy, content }) {
|
|||
<div className="nebula-daily-layout">
|
||||
<div className="nds-panel nebula-daily-stage">
|
||||
<div className="nebula-daily-frame" data-finished={finished || undefined}>
|
||||
{imageUrl ? <img src={imageUrl} alt={content.imageAlt} draggable="false" style={{ transform: `scale(${daily.zoom})`, transformOrigin: `${daily.focus.x}% ${daily.focus.y}%` }} /> : <span className="nebula-daily-frame-status" role={imageFailed ? "alert" : "status"}>{imageFailed ? content.imageError : content.imageLoading}</span>}
|
||||
{imageUrl ? <img key={imageUrl} src={imageUrl} alt={content.imageAlt} draggable="false" /> : <span className="nebula-daily-frame-status" role={imageFailed ? "alert" : "status"}>{imageFailed ? content.imageError : content.imageLoading}</span>}
|
||||
</div>
|
||||
<ol className="nebula-daily-steps" aria-label={fillTemplate(content.attempts, { count: Math.min(daily.guesses.length + (finished ? 0 : 1), daily.maxGuesses), max: daily.maxGuesses })}>
|
||||
{Array.from({ length: daily.maxGuesses }, (_, index) => {
|
||||
|
|
|
|||
|
|
@ -27,13 +27,12 @@ function buildAlerts({ catalog, lookup, dashboard, now }) {
|
|||
return alerts;
|
||||
}
|
||||
|
||||
// La réponse reste repliée : un administrateur qui joue aussi ne la voit qu'en la demandant.
|
||||
function DailyStat({ catalog, daily }) {
|
||||
const name = catalog.cards.find((card) => card.id === daily.cardId)?.name || daily.cardId;
|
||||
// Chaque joueur a sa propre carte : la vue d'ensemble ne montre que la participation du jour.
|
||||
function DailyStat({ daily }) {
|
||||
return <DashboardStat
|
||||
label={`Carte du jour n° ${daily.number}`}
|
||||
value={<>{daily.winners.toLocaleString("fr-FR")}<small> / {daily.players.toLocaleString("fr-FR")}</small></>}
|
||||
detail={<>gagnants sur les joueurs du jour · <details className="nebula-admin-daily-answer"><summary>Voir la carte</summary><span>{name}</span></details></>}
|
||||
detail="gagnants sur les joueurs du jour"
|
||||
/>;
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +54,7 @@ export function AdminOverview(props) {
|
|||
<DashboardStat label="Joueurs" value={stats?.totalPlayers ?? "—"} detail={stats && `${plural(stats.activePlayers7d, "actif", "actifs")} sur 7 jours`} />
|
||||
<DashboardStat label="Collections actives" value={activeCollections} detail={`sur ${plural(catalog.collections.length, "collection")} au total`} />
|
||||
<DashboardStat label="Cartes différentes" value={editions.length.toLocaleString("fr-FR")} detail={`dont ${plural(mythics, "variante mythique", "variantes mythiques")}`} />
|
||||
{dashboard?.daily && <DailyStat catalog={catalog} daily={dashboard.daily} />}
|
||||
{dashboard?.daily && <DailyStat daily={dashboard.daily} />}
|
||||
</div>
|
||||
<AdminPlayers {...props} />
|
||||
</>;
|
||||
|
|
|
|||
|
|
@ -158,7 +158,10 @@
|
|||
}
|
||||
.nds-panel.nebula-daily-stage { display: grid; gap: var(--space-3); padding: var(--space-3); }
|
||||
.nebula-daily-frame { display: grid; place-items: center; overflow: hidden; aspect-ratio: 1; border-radius: var(--radius-lg); background: var(--color-bg-deep); }
|
||||
.nebula-daily-frame img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 700ms ease; user-select: none; -webkit-user-drag: none; }
|
||||
/* Chaque morceau envoyé par le serveur (zone visible au zoom courant) apparaît en fondu à la place du précédent. */
|
||||
.nebula-daily-frame img { display: block; width: 100%; height: 100%; object-fit: cover; user-select: none; -webkit-user-drag: none; animation: nebula-daily-image-in 450ms ease; }
|
||||
@keyframes nebula-daily-image-in { from { opacity: 0; transform: scale(1.04); } }
|
||||
@media (prefers-reduced-motion: reduce) { .nebula-daily-frame img { animation: none; } }
|
||||
.nebula-daily-frame-status { padding: var(--space-4); color: var(--color-text-muted); font-size: var(--font-size-sm); text-align: center; }
|
||||
.nebula-daily-steps { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
|
||||
.nebula-daily-steps li { height: 8px; border-radius: var(--radius-pill); background: var(--color-bg-hover); }
|
||||
|
|
@ -1149,7 +1152,3 @@ button.nebula-privacy-toggle:hover:not(:disabled) { color: var(--color-text-prim
|
|||
.nebula-privacy-notice p { margin: 0; }
|
||||
.nebula-privacy-notice h4 { margin: 0 0 var(--space-1); }
|
||||
.nebula-privacy-contact a { overflow-wrap: anywhere; }
|
||||
.nebula-admin-daily-answer { display: inline; }
|
||||
.nebula-admin-daily-answer summary { display: inline; color: var(--color-text-secondary); cursor: pointer; text-decoration: underline dotted; }
|
||||
.nebula-admin-daily-answer[open] summary { margin-right: var(--space-1); }
|
||||
.nebula-admin-daily-answer span { color: var(--color-text-primary); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue