sokko-g/website/src/features/cards/DailyHints.jsx
Shinuwa 880f007cce
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 23m0s
Validate and deploy Sokko G / deploy (push) Successful in 15s
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>
2026-11-25 14:01:43 +01:00

56 lines
3.6 KiB
JavaScript

// Rôle : indices facultatifs de la Carte du jour : cinq cadres de taille fixe, un à dévoiler par essai raté, dans l'ordre choisi par le joueur.
import { DailyIcon } from "./DailyIcon.jsx";
import { fillTemplate } from "./dailyShare.js";
// Texte dont certains mots manquent : le serveur ne les envoie pas.
function MaskedText({ parts, content }) {
return parts.map((part, index) => (part.hidden
? <span key={index} className="nebula-daily-gap"><span className="sr-only">{content.hintHiddenWord}</span></span>
: <span key={index}>{part.text}</span>));
}
function HintValue({ catalog, hint, content }) {
if (hint.id === "album") return <strong>{hint.value ? content.hintAlbumYes : content.hintAlbumNo}</strong>;
if (hint.id === "theme") return <strong>{hint.value}</strong>;
if (hint.id === "collection") return <strong>{catalog.collections.find((item) => item.id === hint.value)?.name}</strong>;
if (hint.id === "page") return <em><MaskedText parts={hint.value} content={content} /></em>;
return <strong><MaskedText parts={hint.value} content={content} /></strong>;
}
function helpText(daily, content) {
if (daily.hintCredits > 1) return content.hintsMany;
if (daily.hintCredits === 1) return content.hintsOne;
if (!daily.guesses.length) return content.hintsRule;
return daily.guesses.length === daily.maxGuesses - 1 || daily.hintChoices.every((choice) => choice.known || daily.hints.some((hint) => hint.id === choice.id)) ? content.hintsSpent : content.hintsNext;
}
// Réserve d'indices : une loupe par indice à dévoiler.
function HintPurse({ credits, content }) {
return <span className="nebula-daily-purse" data-on={credits > 0 || undefined} role="status">
{Array.from({ length: Math.max(1, credits) }, (_, index) => <DailyIcon key={index} name="lens" />)}
{credits ? fillTemplate(credits > 1 ? content.hintCreditsMany : content.hintCreditsOne, { count: credits }) : content.hintCreditsNone}
</span>;
}
export function DailyHints({ catalog, daily, busy, content, onUse }) {
const opened = new Map(daily.hints.map((hint) => [hint.id, hint]));
const guessedTheme = daily.guesses.find((guess) => guess.theme?.same)?.theme.label;
return <section className="nebula-daily-hints" aria-labelledby="nebula-daily-hints-title">
<div className="nebula-daily-heading">
<h3 id="nebula-daily-hints-title">{content.hintsTitle}</h3>
<p>{helpText(daily, content)}</p>
<HintPurse credits={daily.hintCredits} content={content} />
</div>
<ul>{daily.hintChoices.map(({ id, known, available }) => {
const { title, text } = content.hints[id];
// Un thème trouvé par un essai s'affiche ouvert, sans coûter d'indice.
const found = known && id === "theme" && guessedTheme ? { id, value: guessedTheme } : null;
const hint = opened.get(id) || found;
const icon = <span className="nebula-daily-disc"><DailyIcon name={id} /></span>;
if (hint) return <li key={id} className="nebula-daily-hint" data-hint={id} data-state="open"><div>{icon}<span><small>{opened.has(id) ? title : fillTemplate(content.hintKnown, { title })}</small><HintValue catalog={catalog} hint={hint} content={content} /></span></div></li>;
return <li key={id} className="nebula-daily-hint" data-hint={id} data-state={available ? "ready" : "locked"}>
<button type="button" disabled={busy || !available} title={available ? content.hintOpen : undefined} onClick={() => onUse(id)}>{icon}<span><strong>{title}</strong><small>{text}</small></span><span className="nebula-daily-lens"><DailyIcon name="lens" /></span></button>
</li>;
})}</ul>
</section>;
}