Rework the daily card page around what the player knows and hints opened in any order
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6993080d81
commit
880f007cce
24 changed files with 812 additions and 415 deletions
|
|
@ -8,9 +8,10 @@ import sharp from "sharp";
|
|||
import { createCardsApiHandler } from "../services/cards/api.js";
|
||||
import { buildPublishedCatalog, prepareVersionedCatalog } from "../services/cards/catalog.js";
|
||||
import { computeStreak, dailyCandidates, dailyCrop, dailyDayKey, dailyZoom, drawDailyPuzzle, MAX_DAILY_GUESSES, nextDailyAt, shiftDayKey } from "../services/cards/daily.js";
|
||||
import { canUseDailyHint, compareClues, DAILY_HINTS, dailyCluesIssues, dailyHintCredits, damagedPage, loadDailyClues, nameShape, prepareDailyClues } from "../services/cards/daily-clues.js";
|
||||
import { answerClues, canUseDailyHint, compareClues, DAILY_HINTS, dailyCluesIssues, dailyHintCredits, loadDailyClues, nameShape, partialDescription, prepareDailyClues } from "../services/cards/daily-clues.js";
|
||||
import { CardsDatabase } from "../services/cards/database.js";
|
||||
import { CardsService } from "../services/cards/service.js";
|
||||
import { dailyKnowledge, dailyVerdict } from "../website/src/features/cards/dailyKnowledge.js";
|
||||
|
||||
const baseCatalog = prepareVersionedCatalog(JSON.parse(await readFile("website/public/data/cards/catalog.json", "utf8")));
|
||||
const ACTIVE_STATES = [{ collectionId: "primordial-nebula", active: true }, { collectionId: "dream-arcade", active: false }];
|
||||
|
|
@ -83,31 +84,58 @@ test("a daily theme comes from the words of the name, the subject only by defaul
|
|||
assert.equal(theme("Encrier Astral"), "Cosmos");
|
||||
assert.equal(theme("Constellation du Loup"), "Lumière");
|
||||
assert.equal(theme("Premier Croissant"), "Lune");
|
||||
const content = { subjects: [{ id: "animal", label: "Animal" }], themes: [{ id: "one", label: "Un", words: ["lune"] }, { id: "two", label: "Deux", words: ["Lune"] }], compoundSubjects: [], cards: {} };
|
||||
const content = { subjects: [{ id: "animal", label: "Animal", phrase: "un animal" }], themes: [{ id: "one", label: "Un", words: ["lune"] }, { id: "two", label: "Deux", words: ["Lune"] }], compoundSubjects: [], cards: {} };
|
||||
assert.throws(() => prepareDailyClues(content), /already belongs to one/);
|
||||
assert.throws(() => prepareDailyClues({ ...content, themes: [], subjects: [{ id: "animal/oiseau", label: "Oiseau" }] }), /has no parent animal/);
|
||||
assert.throws(() => prepareDailyClues({ ...content, themes: [], cards: { card: { subject: "objet" } } }), /unknown subject objet/);
|
||||
const subject = (extra) => prepareDailyClues({ ...content, themes: [], subjects: [{ id: "animal", label: "Animal", ...extra }] });
|
||||
assert.throws(() => subject({ phrase: "animal" }), /needs a phrase/);
|
||||
assert.throws(() => subject({ phrase: "un animal", sentences: { same: "C’est {subject}" } }), /needs sentences/);
|
||||
});
|
||||
|
||||
test("a daily guess shows the common part of the subject and the theme, never the rest of the answer", () => {
|
||||
const answer = cardNamed("Renardeau des Congères");
|
||||
const compare = (name) => compareClues(clues, answer, cardNamed(name));
|
||||
assert.deepEqual(compare("Épée du Socle Ancien"), { subject: { common: [], different: "Objet" }, theme: { label: "Combat", same: false } });
|
||||
const compare = (name) => {
|
||||
const { subject, theme } = compareClues(clues, answer, cardNamed(name));
|
||||
return { subject: { common: subject.common.map((step) => step.label), different: subject.different?.label ?? null }, theme };
|
||||
};
|
||||
assert.deepEqual(compare("Épée du Socle Ancien"), { subject: { common: [], different: "Objet" }, theme: { label: "Combat", span: [0, 4], same: false } });
|
||||
assert.deepEqual(compare("Loutre Pilote du Bateau du Ciel").subject, { common: ["Animal", "Mammifère"], different: "Mustélidé" });
|
||||
assert.deepEqual(compare("Loup des Aurores").subject, { common: ["Animal", "Mammifère", "Canidé"], different: null });
|
||||
// Une espèce sans branche s'arrête à « Mammifère » : rien ne dit que la réponse va plus loin.
|
||||
assert.deepEqual(compare("Phoque des Glaces Lunaires"), { subject: { common: ["Animal", "Mammifère"], different: null }, theme: { label: "Hiver", same: true } });
|
||||
assert.deepEqual(compare("Phoque des Glaces Lunaires"), { subject: { common: ["Animal", "Mammifère"], different: null }, theme: { label: "Hiver", span: [11, 17], same: true } });
|
||||
// Une carte sans indices reste jouable, sans comparaison.
|
||||
assert.deepEqual(compareClues(clues, answer, { id: "new-card", name: "Chose Inconnue" }), { subject: { common: [], different: null }, theme: null });
|
||||
});
|
||||
|
||||
test("the damaged page and the name shape hide words without sending them", () => {
|
||||
test("the partial description and the name shape hide words without sending them", () => {
|
||||
const hedgehog = cardNamed("Hérisson à la Guirlande");
|
||||
assert.equal(shown(damagedPage(hedgehog)), "En voulant aider à décorer le sapin, il s'est emmêlé dans la ▒.");
|
||||
assert.equal(shown(partialDescription(hedgehog)), "En voulant aider à décorer le sapin, il s'est emmêlé dans la ▒.");
|
||||
assert.equal(shown(nameShape("Renardeau des Neiges Astrales")), "▒ des ▒ ▒");
|
||||
assert.equal(shown(nameShape("L'Échange de l'Aube")), "L'▒ de l'▒");
|
||||
assert.ok(nameShape(hedgehog.name).filter((part) => part.hidden).every((part) => Object.keys(part).join() === "hidden"));
|
||||
for (const card of baseCatalog.cards) assert.ok(damagedPage(card).some((part) => part.text) && nameShape(card.name).some((part) => part.hidden), card.id);
|
||||
for (const card of baseCatalog.cards) assert.ok(partialDescription(card).some((part) => part.text) && nameShape(card.name).some((part) => part.hidden), card.id);
|
||||
});
|
||||
|
||||
test("what a player learned adds up, whatever the order of the guesses", async () => {
|
||||
const content = JSON.parse(await readFile("website/public/data/site.json", "utf8")).cards.daily;
|
||||
const answer = cardNamed("Petit Tsuchinoko des Herbes Rouges");
|
||||
const guesses = (...names) => names.map((name) => compareClues(clues, answer, cardNamed(name)));
|
||||
const verdict = (...names) => dailyVerdict(guesses(...names), content).map((part) => part.text).join("");
|
||||
const umbrella = "Parapluie à l'Œil Rieur";
|
||||
// Un essai moins bon n'efface rien : la famille écartée n'apprend plus rien une fois la bonne connue.
|
||||
assert.deepEqual(dailyKnowledge(guesses(umbrella, "Loup des Aurores")), { path: ["Créature fantastique", "Yokai"], ruledOut: [], theme: null, ruledOutThemes: ["Mystère", "Lumière"] });
|
||||
assert.deepEqual(dailyKnowledge(guesses("Loup des Aurores", "Dragon du Néant Étoilé")).ruledOut, ["Dragon"]);
|
||||
assert.equal(dailyKnowledge(guesses("Loup des Aurores"), "Plante").theme, "Plante");
|
||||
assert.equal(dailyKnowledge(guesses("Esprit du Cèdre Creux")).theme, "Plante");
|
||||
assert.equal(verdict(umbrella), "C’est bien un yokai.");
|
||||
assert.equal(verdict("Dragon du Néant Étoilé"), "C’est bien une créature fantastique, mais pas un dragon.");
|
||||
assert.equal(verdict("Loup des Aurores"), "Sa famille n’est pas inspirée d’un animal réel.");
|
||||
assert.equal(verdict(umbrella, "Loup des Aurores"), "Sa famille n’est pas inspirée d’un animal réel : vous le saviez déjà.");
|
||||
assert.equal(verdict("Épée du Socle Ancien", "Dragon du Néant Étoilé", umbrella), "C’est bien un yokai.");
|
||||
const fox = compareClues(clues, cardNamed("Renardeau des Congères"), cardNamed("Manchot des Glaces Étoilées"));
|
||||
assert.equal(dailyVerdict([fox], content).map((part) => part.text).join(""), "Sa famille est bien inspirée d’un animal réel, mais pas d’un oiseau.");
|
||||
assert.deepEqual(dailyVerdict([{ subject: { common: [], different: null }, theme: null }], content), []);
|
||||
});
|
||||
|
||||
test("a wrong daily guess earns one hint of the player's choice", () => {
|
||||
|
|
@ -118,14 +146,11 @@ test("a wrong daily guess earns one hint of the player's choice", () => {
|
|||
assert.equal(canUseDailyHint("album", 1, []), true);
|
||||
assert.equal(canUseDailyHint("album", 2, ["album"]), false);
|
||||
assert.equal(canUseDailyHint("collection", 1, ["album"]), false);
|
||||
assert.equal(canUseDailyHint("theme", 2, []), false);
|
||||
assert.equal(canUseDailyHint("theme", 3, []), true);
|
||||
// Chaque indice est ouvert dès le premier essai raté : le joueur choisit l'ordre.
|
||||
for (const hint of DAILY_HINTS) assert.equal(canUseDailyHint(hint, 1, []), true, hint);
|
||||
// Un thème déjà trouvé par un essai n'est plus un indice.
|
||||
assert.equal(canUseDailyHint("theme", 3, [], ["theme"]), false);
|
||||
assert.equal(canUseDailyHint("rarity", 6, []), false);
|
||||
assert.equal(canUseDailyHint("page", 1, []), false);
|
||||
assert.equal(canUseDailyHint("shape", 3, []), false);
|
||||
assert.equal(canUseDailyHint("shape", 4, ["album"]), true);
|
||||
assert.equal(canUseDailyHint("unknown", 6, []), false);
|
||||
});
|
||||
|
||||
|
|
@ -215,6 +240,9 @@ test("wrong daily guesses unzoom the card until the player runs out of guesses",
|
|||
assert.equal(last.zoom, 1);
|
||||
assert.equal(last.earned, 0);
|
||||
assert.equal(last.answerCardId, service.todayPuzzle(player.id).cardId);
|
||||
// La réponse détaillée n'arrive qu'avec la fin de partie.
|
||||
assert.equal(daily.answerClues, null);
|
||||
assert.deepEqual(last.answerClues, answerClues(clues, service.index.cards.get(last.answerCardId)));
|
||||
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);
|
||||
});
|
||||
|
|
@ -229,8 +257,7 @@ test("a player flips the daily hints in the order of their choice, for free", ()
|
|||
assert.throws(() => flip("album"), (error) => error.code === "DAILY_HINT_LOCKED");
|
||||
assert.throws(() => flip("answer"), (error) => error.code === "DAILY_HINT_INVALID");
|
||||
assert.throws(() => service.useDailyHint(player.id, { day: "demain", hint: "album" }), (error) => error.code === "DAILY_HINT_INVALID");
|
||||
assert.deepEqual(service.guessDaily(player.id, { day, cardId: others[0] }).daily.hintChoices.filter((choice) => choice.available).map((choice) => choice.id), ["album", "collection"]);
|
||||
assert.throws(() => flip("page"), (error) => error.code === "DAILY_HINT_LOCKED");
|
||||
assert.deepEqual(service.guessDaily(player.id, { day, cardId: others[0] }).daily.hintChoices.filter((choice) => choice.available).map((choice) => choice.id).filter((id) => id !== "theme"), ["album", "collection", "shape", "page"]);
|
||||
// La possession est celle du tirage : une carte reçue pendant la partie ne change pas l'indice.
|
||||
const edition = service.catalog.editions.find((item) => item.cardId === answer.id);
|
||||
service.db.prepare("INSERT INTO collection_cards(player_id, edition_id, quantity, acquired_at) VALUES (?, ?, 1, 0)").run(player.id, edition.id);
|
||||
|
|
@ -271,10 +298,10 @@ test("the theme hint names the theme of the answer, unless a guess already found
|
|||
return { service, player, others, choice: daily.hintChoices.find((item) => item.id === "theme"), flip: () => service.useDailyHint(player.id, { day, hint: "theme" }), label: clues.themeLabels.get(theme) };
|
||||
};
|
||||
const unknown = play(false);
|
||||
assert.deepEqual(unknown.choice, { id: "theme", after: 3, known: false, available: true });
|
||||
assert.deepEqual(unknown.choice, { id: "theme", known: false, available: true });
|
||||
assert.deepEqual(unknown.flip().hints, [{ id: "theme", value: unknown.label }]);
|
||||
const found = play(true);
|
||||
assert.deepEqual(found.choice, { id: "theme", after: 3, known: true, available: false });
|
||||
assert.deepEqual(found.choice, { id: "theme", known: true, available: false });
|
||||
assert.throws(found.flip, (error) => error.code === "DAILY_HINT_LOCKED");
|
||||
// Le crédit que le thème aurait pris n'est pas annoncé quand il ne reste rien à retourner.
|
||||
for (const cardId of found.others.slice(2, 4)) found.service.guessDaily(found.player.id, { day, cardId });
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ test("large sass files stay split by stable responsibility", async () => {
|
|||
"website/src/styles/toolboxes/calendar/_date-picker.scss",
|
||||
"website/src/styles/toolboxes/calendar/_event-controls.scss",
|
||||
"website/src/styles/toolboxes/calendar/_form-actions.scss",
|
||||
"website/src/styles/_nebula-daily.scss",
|
||||
"website/src/styles/_nebula-expeditions.scss",
|
||||
"website/src/styles/_nebula-expedition-destinations.scss",
|
||||
"website/src/styles/_nebula-expedition-loadout.scss",
|
||||
|
|
@ -135,7 +136,7 @@ test("Sokko TCG styles load with their route and keep the single-sheet cascade",
|
|||
const main = uses(await readFile(`${root}/main.scss`, "utf8"));
|
||||
const route = uses(await readFile(`${root}/cards-route.scss`, "utf8"));
|
||||
const cardSheets = route.filter((name) => name.startsWith("nebula-"));
|
||||
assert.deepEqual(cardSheets, ["nebula-cards", "nebula-expeditions", "nebula-expedition-destinations", "nebula-expedition-loadout", "nebula-expedition-journey"]);
|
||||
assert.deepEqual(cardSheets, ["nebula-cards", "nebula-daily", "nebula-expeditions", "nebula-expedition-destinations", "nebula-expedition-loadout", "nebula-expedition-journey"]);
|
||||
assert.ok(cardSheets.every((name) => !main.includes(name)), "main.scss must not load the Sokko TCG sheets");
|
||||
// La feuille de route ré-émet, dans le même ordre, toutes les feuilles qui suivaient les cartes dans main.scss.
|
||||
const after = main.slice(main.indexOf("nebula-cards-nav") + 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue