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>
73 lines
4.6 KiB
JavaScript
73 lines
4.6 KiB
JavaScript
/**
|
|
* @file Fin d'une partie de la Carte du jour : résultat, description, réponse détaillée, gains et résultat à
|
|
* partager.
|
|
*/
|
|
|
|
import { useState } from "react";
|
|
import { SubjectChips } from "./DailyFeedback.jsx";
|
|
import { dailyKnowledge } from "./dailyKnowledge.js";
|
|
import { dailyShareText, fillTemplate, formatCountdown, formatStreak } from "../dailyShare.js";
|
|
import { DailyTrack } from "./DailyTrack.jsx";
|
|
import { formatStardust } from "../stardustFormat.js";
|
|
|
|
function wonTitle(count, content) {
|
|
return count === 1 ? content.wonFirstTitle : fillTemplate(content.wonTitle, { count });
|
|
}
|
|
|
|
// Récompense au choix : de la poussière, ou moins de poussière et une étoile dorée pour le prochain recrutement.
|
|
function RewardChoice({ offer, content, busy, onReward }) {
|
|
return <section className="nebula-daily-reward-choice" aria-labelledby="nebula-daily-reward-title">
|
|
<h4 id="nebula-daily-reward-title">{content.rewardTitle}</h4>
|
|
<div>
|
|
<button className="nds-button" data-variant="secondary" type="button" disabled={busy} onClick={() => onReward("stardust")}>{formatStardust(offer.stardust)}</button>
|
|
<button className="nds-button" data-variant="secondary" type="button" disabled={busy || !offer.starAvailable} onClick={() => onReward("star")}>{fillTemplate(content.rewardStar, { reward: formatStardust(offer.starStardust) })}</button>
|
|
</div>
|
|
<p>{fillTemplate(offer.starAvailable ? content.rewardStarHelp : content.rewardStarUnavailable, { count: offer.goldStars, max: offer.maxGoldStars })}</p>
|
|
</section>;
|
|
}
|
|
|
|
export function DailyResult({ catalog, card, daily, content, now, busy = false, notice = "", onReward }) {
|
|
const [copied, setCopied] = useState(false);
|
|
const won = daily.status === "won";
|
|
const collection = catalog.collections.find((item) => item.id === card?.collectionId)?.name;
|
|
const { subject, theme } = daily.answerClues;
|
|
// Après une défaite, ce que les essais et l'indice ont trouvé reste en vert, le reste est en gris.
|
|
const known = dailyKnowledge(daily.guesses, daily.hints.find((hint) => hint.id === "theme")?.value ?? null);
|
|
async function share() {
|
|
const text = dailyShareText(daily, { title: content.shareTitle, url: `${window.location.origin}/#/cards/daily` });
|
|
try {
|
|
await navigator.clipboard.writeText(text);
|
|
setCopied(true);
|
|
} catch {
|
|
setCopied(false);
|
|
}
|
|
}
|
|
return <section className="nds-panel nebula-daily-result" aria-labelledby="nebula-daily-result-title" data-status={daily.status}>
|
|
<div className="nebula-daily-ask-heading">
|
|
<h3 id="nebula-daily-result-title">{won ? wonTitle(daily.guesses.length, content) : content.lostTitle}</h3>
|
|
{daily.hints.length > 0 && <span>{fillTemplate(daily.hints.length > 1 ? content.hintsUsedMany : content.hintsUsedOne, { count: daily.hints.length })}</span>}
|
|
</div>
|
|
<DailyTrack daily={daily} content={content} />
|
|
{/* Seule action attendue du joueur : elle passe avant la réponse. */}
|
|
{daily.rewardOffer && <RewardChoice offer={daily.rewardOffer} content={content} busy={busy} onReward={onReward} />}
|
|
{notice && <p className="nds-inline-notice" data-variant="warning" role="status">{notice}</p>}
|
|
{card?.description && <p className="nebula-daily-description">{card.description}</p>}
|
|
<section className="nebula-daily-know" aria-labelledby="nebula-daily-answer-title">
|
|
<h4 id="nebula-daily-answer-title">{content.answerTitle}</h4>
|
|
<dl>
|
|
{subject.length > 0 && <><dt>{content.columnSubject}</dt><dd><SubjectChips labels={subject.map((step) => step.label)} isFound={(index) => won || index < known.path.length} /></dd></>}
|
|
{theme && <><dt>{content.columnTheme}</dt><dd><span className="nebula-daily-answer-theme"><SubjectChips labels={[theme.label]} isFound={() => won || Boolean(known.theme)} />{card && <span>« {card.name.slice(...theme.span)} »</span>}</span></dd></>}
|
|
{collection && <><dt>{content.hints.collection.title}</dt><dd>{collection}</dd></>}
|
|
</dl>
|
|
</section>
|
|
{won && <ul className="nebula-daily-rewards">
|
|
{daily.earned > 0 && <li>{fillTemplate(content.earned, { reward: formatStardust(daily.earned) })}</li>}
|
|
{daily.earnedStar && <li>{content.earnedStar}</li>}
|
|
{daily.streak > 0 && <li>{fillTemplate(content.streak, { streak: formatStreak(daily.streak) })}</li>}
|
|
</ul>}
|
|
<div className="nebula-daily-result-actions">
|
|
<button className="nds-button" data-variant="primary" type="button" onClick={share}>{copied ? content.shared : content.share}</button>
|
|
<span>{fillTemplate(content.next, { time: formatCountdown(daily.nextAt - now) })}</span>
|
|
</div>
|
|
</section>;
|
|
}
|