Group Sokko TCG's interface files by Guild quest and card rendering
The 48 files of the Daily Card, Expeditions, Daily Team and race, Broken Mirror and card rendering move to daily/, expeditions/, team/, mirror/ and rendering/ under website/src/features/cards, with every relative import rewritten. The root keeps the page, server calls, cache and the player sections outside the Guild. The cards README, the quest recipe and the current docs follow the new paths; dated audits and plans keep theirs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
863050437f
commit
88c7bf8317
74 changed files with 165 additions and 161 deletions
|
|
@ -1,312 +0,0 @@
|
|||
/**
|
||||
* @file Page du Miroir brisé : trois cartes illustrées pour les miroirs Facile, Normal et Difficile du jour
|
||||
* (chacun ouvert après le précédent), puis la partie (plateau, mouvements restants, coups de main de
|
||||
* l'Équipe du jour) et son résultat, à partager pour le Difficile.
|
||||
*
|
||||
* Contexte : la page a sa propre vue (`GET /api/cards/mirror`) et demande l'image mélangée de chaque partie à
|
||||
* part ; les actions passent par `runMutation`.
|
||||
* Utilisé par : CardsPage.jsx (section `mirror`).
|
||||
* Dépend de : MirrorBoard.jsx, mirrorFormat.js, cardsApi.js.
|
||||
* Attention : l'image servie a une version (le nombre de coups joués quand elle a été rendue) ; les URL d'objets
|
||||
* créées pour les images sont libérées au démontage.
|
||||
* @see docs/miroir-brise.md
|
||||
*/
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { applyMirrorHelp, loadMirror, loadMirrorImage, resetMirror, startMirror, swapMirror } from "./cardsApi.js";
|
||||
import { fillTemplate, formatCountdown } from "./dailyShare.js";
|
||||
import { Tooltip } from "../../components/Tooltip.jsx";
|
||||
import { MirrorBoard } from "./MirrorBoard.jsx";
|
||||
import { mirrorShareText } from "./mirrorFormat.js";
|
||||
import { formatStardustFull } from "./stardustFormat.js";
|
||||
import { MaskIcon } from "./ExpeditionLabels.jsx";
|
||||
|
||||
// Les trois miroirs du jour, dans l'ordre : chacun s'ouvre une fois le précédent terminé.
|
||||
const MODES = ["easy", "normal", "hard"];
|
||||
const MODE_ART = { easy: "/static/img/cards/guild/mirror-easy.webp", normal: "/static/img/cards/guild/mirror-normal.webp", hard: "/static/img/cards/guild/mirror-hard.webp" };
|
||||
const identity = (count) => Array.from({ length: count }, (_, index) => index);
|
||||
|
||||
// Les deux miroirs du jour, côte à côte : illustration, nombre de morceaux, état de la partie et bouton. Le Difficile reste
|
||||
// verrouillé tant que le Normal n'est pas terminé.
|
||||
function MirrorModes({ mirror, content, busy, onOpen }) {
|
||||
return <div className="nebula-mirror-home"><div className="nebula-mirror-modes">{MODES.map((mode) => {
|
||||
const game = mirror.games[mode];
|
||||
const lock = !game ? mirror.locks[mode] : null;
|
||||
const reward = mirror.rewards[mode];
|
||||
const status = !game ? "none" : game.status;
|
||||
const done = status === "won" || status === "lost";
|
||||
return <article key={mode} className="nds-card nebula-mirror-mode" data-mode={mode} data-locked={lock || undefined} data-done={done || undefined} aria-labelledby={`nebula-mirror-mode-${mode}`}>
|
||||
<button type="button" className="nds-card-cover nebula-mirror-mode-cover" tabIndex={-1} aria-hidden="true" disabled={busy || Boolean(lock) || (!game && !mirror.enabled)} onClick={() => onOpen(mode)}><img src={MODE_ART[mode]} alt="" /></button>
|
||||
<div className="nds-card-body nebula-mirror-mode-body">
|
||||
<p className="eyebrow">{content.modes[mode].pieces}</p>
|
||||
<h3 id={`nebula-mirror-mode-${mode}`}>{content.modes[mode].label}</h3>
|
||||
<p>{content.modes[mode].text}</p>
|
||||
<p className="nebula-mirror-reward">{fillTemplate(content.rewardLine, { base: formatStardustFull(reward.base), perSwap: reward.perSwap })}</p>
|
||||
<p className="nebula-mirror-mode-status">{lock ? content.locked[lock] : fillTemplate(content.cardStatus[status], { reward: formatStardustFull(game?.reward ?? 0) })}</p>
|
||||
<div className="nds-card-actions"><button className="nds-button" data-size="sm" data-variant={done ? "secondary" : "primary"} type="button" disabled={busy || Boolean(lock) || (!game && !mirror.enabled)} onClick={() => onOpen(mode)}>
|
||||
{!game ? content.cardActions.play : done ? content.cardActions.result : content.cardActions.resume}
|
||||
</button></div>
|
||||
</div>
|
||||
</article>;
|
||||
})}</div><MirrorReminders content={content} /></div>;
|
||||
}
|
||||
|
||||
// L'essentiel des règles, en petites boîtes à côté des deux cartes : une idée par boîte.
|
||||
function MirrorReminders({ content }) {
|
||||
return <aside className="nebula-mirror-reminders" aria-label={content.reminders.label}>
|
||||
{content.reminders.items.map((item) => <section key={item.title} className="nds-panel nebula-mirror-reminder">
|
||||
<h3>{item.title}</h3>
|
||||
<p>{item.text}</p>
|
||||
</section>)}
|
||||
</aside>;
|
||||
}
|
||||
|
||||
// Coups de main : les compagnons de l'Équipe du jour en vignettes. Un clic sur une vignette donne son coup de main, quand le joueur
|
||||
// veut ; deux par partie, chez les compagnons de son choix. Une double spécialité a deux boutons, au choix.
|
||||
function MirrorHelpers({ catalog, mirror, game, content, teamContent, busy, aiming, onHelp }) {
|
||||
if (!mirror.team.length) return <section className="nds-panel nebula-mirror-helpers"><h3>{content.helpersTitle}</h3><p className="nebula-mirror-note">{content.helpersNone}</p><a className="nds-button" data-size="sm" data-variant="secondary" href="#/cards/team">{content.toTeam}</a></section>;
|
||||
const playing = game.status === "playing";
|
||||
const left = game.helpsLeft;
|
||||
return <section className="nds-panel nebula-mirror-helpers" aria-labelledby="nebula-mirror-helpers-title">
|
||||
<div className="nebula-mirror-helpers-head">
|
||||
<h3 id="nebula-mirror-helpers-title">{content.helpersTitle}</h3>
|
||||
<span className="nds-badge" data-variant={left ? "gold" : "neutral"}>{left ? fillTemplate(left > 1 ? content.helpsLeft.many : content.helpsLeft.one, { count: left }) : content.helpsLeft.none}</span>
|
||||
</div>
|
||||
<ul className="nebula-mirror-helper-grid">{mirror.team.map((helper) => {
|
||||
const card = catalog.cards.find((item) => item.id === helper.cardId);
|
||||
const used = game.used[helper.cardId];
|
||||
const available = playing && !used && left > 0;
|
||||
const targeted = aiming?.cardId === helper.cardId;
|
||||
return <li key={helper.cardId} className="nebula-mirror-helper" data-used={Boolean(used) || undefined} data-off={(!available && !used) || undefined} data-aiming={targeted || undefined}
|
||||
style={{ "--specialty-start": `var(--color-stat-${helper.helps[0]})`, "--specialty-end": `var(--color-stat-${helper.helps.at(-1)})` }}>
|
||||
<div className="nebula-mirror-helper-art">
|
||||
<img src={card?.image} alt="" />
|
||||
{used && <span className="nebula-mirror-helper-used">{content.helpUsed}</span>}
|
||||
</div>
|
||||
<p className="nebula-mirror-helper-name">{card?.name || teamContent.unknownCard}</p>
|
||||
<div className="nebula-mirror-helper-actions">{helper.helps.map((help) => <Tooltip as="button" key={help} type="button" className="nebula-mirror-help" style={{ "--specialty": `var(--color-stat-${help})` }}
|
||||
content={content.helps[help].text} disabled={busy || !available || (help === "endurance" && game.swaps === 0)} aria-pressed={used === help || (targeted && aiming.help === help)} onClick={() => onHelp(helper.cardId, help)}>
|
||||
<MaskIcon name={help} /><span>{content.helps[help].name}</span>
|
||||
</Tooltip>)}</div>
|
||||
</li>;
|
||||
})}</ul>
|
||||
</section>;
|
||||
}
|
||||
|
||||
function MirrorResult({ catalog, mirror, game, content, nextAt }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [now] = useState(() => Date.now());
|
||||
const card = catalog.cards.find((item) => item.id === game.cardId);
|
||||
const won = game.status === "won";
|
||||
async function share() {
|
||||
const text = mirrorShareText(mirror, game, { title: content.shareText, modes: content.modes, url: `${window.location.origin}/#/cards/mirror` });
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
setCopied(true);
|
||||
} catch {
|
||||
setCopied(false);
|
||||
}
|
||||
}
|
||||
return <section className="nds-panel nebula-mirror-result" data-won={won || undefined} aria-labelledby={`nebula-mirror-result-${game.mode}`}>
|
||||
<h3 id={`nebula-mirror-result-${game.mode}`} tabIndex={-1}>{won ? content.wonTitle : content.lostTitle}</h3>
|
||||
{won ? <p className="nebula-mirror-earned">+{formatStardustFull(game.reward)}</p> : <p>{fillTemplate(content.lostText, { placed: game.placedCount, total: game.cols * game.rows })}</p>}
|
||||
<p>{fillTemplate(content.resultSwaps, { swaps: game.swaps, par: game.par })}{won && game.swaps < game.par && <> {content.resultBetter}</>}</p>
|
||||
{card && <p className="nebula-mirror-note">{fillTemplate(content.revealed, { card: card.name })}</p>}
|
||||
{game.mode === "hard" && <div className="nds-card-actions"><button className="nds-button" data-variant="primary" type="button" onClick={share}>{copied ? content.shared : content.share}</button></div>}
|
||||
{game.mode === "hard" && <p className="nebula-mirror-note">{fillTemplate(content.next, { time: formatCountdown(nextAt - now) })}</p>}
|
||||
</section>;
|
||||
}
|
||||
|
||||
export function MirrorPanel({ catalog, runMutation, busy, content, teamContent }) {
|
||||
const [mirror, setMirror] = useState(null);
|
||||
const [loadError, setLoadError] = useState("");
|
||||
const [reloadKey, setReloadKey] = useState(0);
|
||||
const [notice, setNotice] = useState("");
|
||||
const [mode, setMode] = useState(null);
|
||||
// Par mode : l'image servie, sa version (coups joués quand elle a été rendue) et la place de ses morceaux depuis.
|
||||
const [boards, setBoards] = useState({});
|
||||
// Copie à jour des plateaux, lue au retour du serveur et à l'arrivée d'une image.
|
||||
const boardsRef = useRef({});
|
||||
const [models, setModels] = useState({});
|
||||
const [peeking, setPeeking] = useState(false);
|
||||
// Orientation en cours : le prochain clic sur le plateau désigne le morceau dont on veut la place.
|
||||
const [aiming, setAiming] = useState(null);
|
||||
// Morceau choisi sur le plateau : « Montrer la place » le vise directement.
|
||||
const [selected, setSelected] = useState(null);
|
||||
const [toast, setToast] = useState("");
|
||||
const urls = useRef([]);
|
||||
// Images en cours de chargement, pour ne pas demander deux fois la même.
|
||||
const pending = useRef(new Set());
|
||||
|
||||
const commitBoards = useCallback((next) => {
|
||||
boardsRef.current = next;
|
||||
setBoards(next);
|
||||
}, []);
|
||||
|
||||
const fetchImage = useCallback(async (gameMode, version, count) => {
|
||||
const key = `${gameMode}:${version}`;
|
||||
if (pending.current.has(key)) return;
|
||||
pending.current.add(key);
|
||||
try {
|
||||
const src = await loadMirrorImage(gameMode, { version });
|
||||
urls.current.push(src);
|
||||
commitBoards({ ...boardsRef.current, [gameMode]: { src, version, applied: version, tiles: identity(count) } });
|
||||
} catch (error) {
|
||||
setNotice(error.message);
|
||||
} finally {
|
||||
pending.current.delete(key);
|
||||
}
|
||||
}, [commitBoards]);
|
||||
|
||||
// Suit la partie à chaque réponse du serveur : un coup de plus (échange, coup de main) se rejoue sur l'image affichée ; tout
|
||||
// autre écart (premier affichage, page restée ouverte) recharge l'image. Le plateau attend pendant ce temps.
|
||||
const applyView = useCallback((next) => {
|
||||
let boardsNext = boardsRef.current;
|
||||
for (const gameMode of MODES) {
|
||||
const current = next.games[gameMode];
|
||||
if (!current) continue;
|
||||
const board = boardsNext[gameMode];
|
||||
if (board && current.moves === board.applied) continue;
|
||||
if (board?.src && current.moves === board.applied + 1) {
|
||||
const tiles = [...board.tiles];
|
||||
if (current.lastMove) {
|
||||
const [x, y] = current.lastMove;
|
||||
[tiles[x], tiles[y]] = [tiles[y], tiles[x]];
|
||||
}
|
||||
boardsNext = { ...boardsNext, [gameMode]: { ...board, tiles, applied: current.moves } };
|
||||
} else fetchImage(gameMode, current.moves, current.cols * current.rows);
|
||||
}
|
||||
if (boardsNext !== boardsRef.current) commitBoards(boardsNext);
|
||||
setMirror(next);
|
||||
}, [commitBoards, fetchImage]);
|
||||
|
||||
useEffect(() => () => urls.current.forEach((url) => URL.revokeObjectURL(url)), []);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
loadMirror()
|
||||
.then((result) => { if (active) { applyView(result.mirror); setLoadError(""); } })
|
||||
.catch((error) => { if (active) setLoadError(error.message); });
|
||||
return () => { active = false; };
|
||||
}, [reloadKey, applyView]);
|
||||
|
||||
// Sans miroir choisi, la page montre les deux cartes ; un miroir choisi montre sa partie, et son résultat une fois finie.
|
||||
const activeMode = mode;
|
||||
const game = (activeMode && mirror?.games[activeMode]) || null;
|
||||
|
||||
if (loadError) return <section className="nds-empty-state" role="alert"><h2>{content.title}</h2><p>{loadError}</p><button className="nds-button" data-variant="secondary" type="button" onClick={() => setReloadKey((key) => key + 1)}>{teamContent.retry}</button></section>;
|
||||
if (!mirror) return <section className="nds-empty-state" aria-busy="true"><h2>{content.title}</h2></section>;
|
||||
|
||||
// Les refus propres au Miroir restent dans ce panneau ; runMutation garde le reste (erreurs réseau).
|
||||
async function act(action) {
|
||||
setNotice("");
|
||||
const result = await runMutation(async () => {
|
||||
try {
|
||||
return await action();
|
||||
} catch (error) {
|
||||
if (/^MIRROR_/.test(String(error.code || ""))) return { mirrorError: error };
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
if (result?.mirrorError) {
|
||||
setNotice(result.mirrorError.message);
|
||||
setReloadKey((key) => key + 1);
|
||||
return null;
|
||||
}
|
||||
if (result?.mirror) applyView(result.mirror);
|
||||
return result?.mirror || null;
|
||||
}
|
||||
|
||||
function flash(text) {
|
||||
setToast(text);
|
||||
window.setTimeout(() => setToast((value) => (value === text ? "" : value)), 1800);
|
||||
}
|
||||
|
||||
async function swap(from, to) {
|
||||
const before = game;
|
||||
const next = await act(() => swapMirror(mirror.day, activeMode, from, to, game.moves));
|
||||
const after = next?.games[activeMode];
|
||||
if (!after || after.moves === before.moves) return;
|
||||
if (after.status === "playing" && activeMode !== "hard" && after.placed.length - before.placed.length >= 2) flash(content.twoPlaced);
|
||||
}
|
||||
|
||||
// Le modèle se charge à la première demande ; le serveur ne l'envoie que tant qu'il est visible.
|
||||
async function peek(on) {
|
||||
setPeeking(on);
|
||||
if (!on || models[activeMode]) return;
|
||||
try {
|
||||
const src = await loadMirrorImage(activeMode, { model: true });
|
||||
urls.current.push(src);
|
||||
setModels((current) => ({ ...current, [activeMode]: src }));
|
||||
} catch (error) {
|
||||
setPeeking(false);
|
||||
setNotice(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Coup de main : l'Orientation attend d'abord le morceau visé.
|
||||
async function help(cardId, helpId, cell = null) {
|
||||
// Orientation : sur le morceau déjà choisi, sinon le prochain clic sur le plateau le désigne ; un second clic l'annule sans la dépenser.
|
||||
if (helpId === "orientation" && cell === null) {
|
||||
if (selected === null) { setAiming((current) => (current?.cardId === cardId ? null : { cardId, help: helpId })); return; }
|
||||
cell = selected;
|
||||
}
|
||||
setAiming(null);
|
||||
// La sélection reste pour le Mouvement libre (il suffit de cliquer la case voulue), pas pour les autres coups de main.
|
||||
if (helpId !== "bravoure") setSelected(null);
|
||||
await act(() => applyMirrorHelp(mirror.day, activeMode, cardId, helpId, game.moves, cell));
|
||||
}
|
||||
|
||||
// Ouvre un miroir : sa partie si elle existe, sinon elle commence.
|
||||
async function open(gameMode) {
|
||||
setPeeking(false);
|
||||
setAiming(null);
|
||||
setSelected(null);
|
||||
if (!mirror.games[gameMode] && !await act(() => startMirror(mirror.day, gameMode))) return;
|
||||
setMode(gameMode);
|
||||
}
|
||||
|
||||
const board = boards[activeMode];
|
||||
const left = game?.left ?? 0;
|
||||
const nextMode = activeMode ? MODES[MODES.indexOf(activeMode) + 1] : null;
|
||||
return <section className="nebula-mirror" aria-labelledby="nebula-mirror-title">
|
||||
<div className="nds-section-heading nebula-section-heading">
|
||||
<div><p className="eyebrow">{content.eyebrow}</p><h2 id="nebula-mirror-title">{content.title}</h2></div>
|
||||
<div className="nebula-team-heading-actions">
|
||||
{game && <button className="nds-button" data-size="sm" data-variant="secondary" type="button" onClick={() => { setMode(null); setPeeking(false); setAiming(null); setSelected(null); }}>{content.chooseOther}</button>}
|
||||
{mirror.devReset && <button className="nds-button" data-size="sm" data-variant="secondary" type="button" disabled={busy} onClick={async () => { commitBoards({}); setMode(null); await act(() => resetMirror()); }}>{content.devReset}</button>}
|
||||
<a className="nds-button" data-size="sm" data-variant="secondary" href="#/cards/guild">{content.back}</a>
|
||||
</div>
|
||||
</div>
|
||||
{notice && <p className="nds-inline-notice" data-variant="warning" role="status">{notice}</p>}
|
||||
{!mirror.enabled && MODES.every((id) => !mirror.games[id])
|
||||
? <div className="nds-empty-state"><p>{content.closed}</p></div>
|
||||
: <>
|
||||
{!game && <MirrorModes mirror={mirror} content={content} busy={busy} onOpen={open} />}
|
||||
{game && <div className="nebula-mirror-layout">
|
||||
<div className="nebula-mirror-stage">
|
||||
<MirrorBoard game={game} src={board?.src} modelSrc={peeking ? models[activeMode] : null} tiles={board?.tiles || identity(game.cols * game.rows)} peeking={peeking} disabled={busy || !board?.src || board.applied !== game.moves} content={content} onSwap={swap}
|
||||
selected={selected} onSelect={setSelected} aiming={Boolean(aiming)} onAim={(cell) => help(aiming.cardId, aiming.help, cell)} />
|
||||
{toast && <p className="nebula-mirror-toast" role="status">{toast}</p>}
|
||||
{game.status === "playing" && game.modelOpen && <Tooltip as="button" className="nds-button nebula-mirror-peek" content={content.peekUntilFirst} data-size="sm" data-variant="secondary" type="button" onMouseEnter={() => peek(true)} onMouseLeave={() => peek(false)} onFocus={() => peek(true)} onBlur={() => peek(false)}>{content.peek}</Tooltip>}
|
||||
</div>
|
||||
<div className="nebula-mirror-side">
|
||||
{game.status === "playing"
|
||||
? <section className="nds-panel nebula-mirror-counter" aria-live="polite">
|
||||
<p className="nebula-mirror-left" data-low={left <= 2 || undefined}><strong>{left}</strong><span>{left > 1 ? content.left.many : content.left.one}</span></p>
|
||||
{/* Une consigne en cours (viser, mouvement libre) reste affichée en demi-écran ; le rappel du mode, non. */}
|
||||
<p className="nebula-mirror-note" data-active={Boolean(aiming) || undefined}>{aiming ? content.aimHint : game.hint ? content.hintShown : content.modes[activeMode].hint}</p>
|
||||
{game.treasure && <p className="nebula-mirror-reward">{content.treasureOn}</p>}
|
||||
<p className="nebula-mirror-reward">{fillTemplate(content.rewardLine, { base: formatStardustFull(game.rewards.base), perSwap: game.rewards.perSwap })}</p>
|
||||
<details className="nebula-mirror-howto"><summary>{content.howTo}</summary><ol className="nebula-mirror-rules">{content.rules.map((rule) => <li key={rule}>{rule}</li>)}</ol></details>
|
||||
</section>
|
||||
: <MirrorResult catalog={catalog} mirror={mirror} game={game} content={content} nextAt={mirror.nextAt} />}
|
||||
{/* Partie finie : le miroir suivant, s'il est ouvert et pas encore commencé. */}
|
||||
{game.status !== "playing" && nextMode && !mirror.games[nextMode] && !mirror.locks[nextMode] && <div className="nds-card-actions"><button className="nds-button" data-variant="primary" type="button" disabled={busy} onClick={() => open(nextMode)}>{content.toNext[nextMode]}</button></div>}
|
||||
{(game.status === "playing" || Object.keys(game.used).length > 0) && <MirrorHelpers catalog={catalog} mirror={mirror} game={game} content={content} teamContent={teamContent} busy={busy}
|
||||
aiming={aiming} onHelp={(cardId, helpId) => help(cardId, helpId)} />}
|
||||
</div>
|
||||
</div>}
|
||||
</>}
|
||||
</section>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue