dailyShare.js held fillTemplate and formatCountdown, used across the whole TCG, under a Daily Card name. They now live in textFormat.js at the root, and the Daily Card helpers in daily/dailyFormat.js. 173 exported functions that other files call now explain what they return and how they treat missing values: the server game rules, the toolbox storage chain, the shared hooks and utilities, and the TCG display helpers. website/AGENTS.md asks the same of new shared functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1.7 KiB
JavaScript
29 lines
1.7 KiB
JavaScript
/**
|
|
* @file Encart « Astuce du jour » de l'Accueil : une astuce simple sur une mécanique peu visible du jeu, la
|
|
* même pour tous ce jour-là, puis les suivantes à la demande. Les chiffres viennent des réglages en
|
|
* cours (`state.tipValues`) ; les astuces des Expéditions ne s'affichent que si elles sont ouvertes.
|
|
*/
|
|
|
|
import { useState } from "react";
|
|
import { fillTemplate } from "./textFormat.js";
|
|
import { availableTips, TIP_SECTION_VARIANTS, tipOfDay } from "./dailyTips.js";
|
|
|
|
/** `content` : textes cards.tips ; `day` : jour de la Carte du jour (heure de Paris), sinon la date du navigateur. */
|
|
export function DailyTip({ content, values, day }) {
|
|
const tips = availableTips(content.items, values);
|
|
const [offset, setOffset] = useState(0);
|
|
if (!tips.length) return null;
|
|
const tip = tips[(tipOfDay(day, tips.length) + offset) % tips.length];
|
|
// La partie du jeu en badge (une couleur par partie), puis le sujet : l'astuce, son badge et son sujet changent ensemble.
|
|
return <section className="nds-panel nebula-home-tip" aria-label={content.label}>
|
|
<div className="nebula-home-tip-copy" aria-live="polite">
|
|
<p className="eyebrow">{content.eyebrow}</p>
|
|
<div className="nebula-home-tip-heading">
|
|
<span className="nds-badge" data-variant={TIP_SECTION_VARIANTS[tip.section] ?? undefined}>{content.sections[tip.section]}</span>
|
|
{tip.topic && <h3>{tip.topic}</h3>}
|
|
</div>
|
|
<p className="nebula-home-tip-text">{fillTemplate(tip.text, values ?? {})}</p>
|
|
</div>
|
|
{tips.length > 1 && <button className="nds-button" data-size="sm" data-variant="secondary" type="button" onClick={() => setOffset(offset + 1)}>{content.next}</button>}
|
|
</section>;
|
|
}
|