Split dailyShare.js and document the shared exported functions with JSDoc

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>
This commit is contained in:
Shinuwa 2026-12-01 13:32:20 +01:00
parent 166790245f
commit aa8bb1ebaa
71 changed files with 339 additions and 57 deletions

View file

@ -5,7 +5,7 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { BOOST_FACTOR, BOOST_MS, RACE_LENGTH } from "../../../../../services/cards/race-rules.js";
import { fillTemplate } from "../dailyShare.js";
import { fillTemplate } from "../textFormat.js";
import { MaskIcon } from "../expeditions/ExpeditionLabels.jsx";
import { activeHelper, advanceRace, advanceToNextChoice, allRuns, canGiveBoost, createRace, giveBoost, imageOf, nameOf, playerZone, raceOver, racerName } from "./raceRun.js";
import { RaceTrack } from "./RaceTrack.jsx";

View file

@ -6,7 +6,7 @@
import { useMemo, useState } from "react";
import { CurrencyIcon } from "../Currency.jsx";
import { fillTemplate, formatCountdown } from "../dailyShare.js";
import { fillTemplate, formatCountdown } from "../textFormat.js";
import { MaskIcon } from "../expeditions/ExpeditionLabels.jsx";
import { imageOf, nameOf, racerName, raceRanking, raceReview } from "./raceRun.js";
import { formatStardust } from "../stardustFormat.js";

View file

@ -3,7 +3,7 @@
*/
import { MaskIcon } from "../expeditions/ExpeditionLabels.jsx";
import { fillTemplate } from "../dailyShare.js";
import { fillTemplate } from "../textFormat.js";
import { imageOf } from "./raceRun.js";
import { countText } from "./teamFormat.js";

View file

@ -5,7 +5,7 @@
import { STAT_IDS } from "../expeditions/expeditionFormat.js";
import { MaskIcon } from "../expeditions/ExpeditionLabels.jsx";
import { fillTemplate } from "../dailyShare.js";
import { fillTemplate } from "../textFormat.js";
import { bandOf, BALANCED, mainStats, specialtyStyle } from "./teamFormat.js";
export function SpecialtyBand({ companion, content, statLabels }) {

View file

@ -5,7 +5,7 @@
import { useEffect, useRef, useState } from "react";
import { chooseTeamCharacter, healTeamCompanion, keepTeamCompanion, loadTeam, recruitTeam, rerollTeamOffer, resetTeam, revealTeamStar } from "../cardsApi.js";
import { fillTemplate } from "../dailyShare.js";
import { fillTemplate } from "../textFormat.js";
import { ITEM_ART } from "../expeditions/expeditionFormat.js";
import { TeamRecruitment } from "./TeamRecruitment.jsx";
import { TeamSky } from "./TeamSky.jsx";

View file

@ -4,7 +4,7 @@
import { useEffect, useRef } from "react";
import { CurrencyIcon } from "../Currency.jsx";
import { fillTemplate } from "../dailyShare.js";
import { fillTemplate } from "../textFormat.js";
import { ITEM_ART } from "../expeditions/expeditionFormat.js";
import { TeamCompanion } from "./TeamCompanion.jsx";
import { TeamSky } from "./TeamSky.jsx";

View file

@ -3,7 +3,7 @@
*/
import { CurrencyIcon } from "../Currency.jsx";
import { fillTemplate } from "../dailyShare.js";
import { fillTemplate } from "../textFormat.js";
/** Le ciel tient sur deux rangées. */
function Star({ star, index, content, canReveal, onReveal }) {

View file

@ -5,7 +5,7 @@
*/
import { CurrencyIcon } from "../Currency.jsx";
import { fillTemplate } from "../dailyShare.js";
import { fillTemplate } from "../textFormat.js";
const TABLE_ART = "/static/img/cards/guild/tavern.webp";

View file

@ -16,6 +16,7 @@ export function createRace(race) {
};
}
/** Avance la course d'un pas, sur place : coureur du joueur, puis chaque adversaire avec ses élans prévus arrivés à échéance. */
export function stepRace(race) {
race.player.run = stepRun(race.player.run, race.player.runner, race.zones);
for (const opponent of race.opponents) {
@ -24,11 +25,16 @@ export function stepRace(race) {
}
}
/** États de tous les coureurs, celui du joueur en premier. */
export const allRuns = (race) => [race.player.run, ...race.opponents.map((opponent) => opponent.run)];
/** Vrai quand tous les coureurs ont franchi l'arrivée. */
export const raceOver = (race) => allRuns(race).every((run) => run.finishedAt !== null);
/** Zone où se trouve le coureur du joueur. */
export const playerZone = (race) => zoneAt(race.player.run.position);
/** Vrai si le joueur peut donner l'élan de cet équipier maintenant (voir `canBoost` des règles). */
export const canGiveBoost = (race, helper) => canBoost(race.player.run, race.player.helpers, helper);
/** Donne l'élan de l'équipier au coureur du joueur, sur place, et renvoie la liste des élans donnés (à envoyer au serveur). */
export function giveBoost(race, helper) {
race.player.run = applyBoost(race.player.run, race.player.helpers, race.zones, helper);
return race.player.run.boosts;
@ -68,6 +74,10 @@ export function raceRanking(race) {
// coureur nettement plus rapide dans l'équipe, s'il n'a pas couru.
const CLEARLY_FASTER_MS = 300;
/**
* Bilan d'une course finie : temps sans élan, temps du joueur, meilleur temps possible et la place qu'il aurait donnée,
* zone et stat de chaque élan donné comparées à la meilleure stat de l'équipier, et l'équipier qui aurait couru nettement plus vite.
*/
export function raceReview(race) {
const runner = race.runner.stats;
const helpers = race.helpers.map((helper) => helper.stats);
@ -109,5 +119,7 @@ export function racerName(entry, content) {
return entry.name || (entry.watchers ? content.watchers : content.deletedPlayer);
}
/** Illustration d'une carte, ou chaîne vide. */
export const imageOf = (catalog, cardId) => catalog.cards.find((card) => card.id === cardId)?.image || "";
/** Nom d'une carte, ou le libellé « carte inconnue » du contenu. */
export const nameOf = (catalog, cardId, content) => catalog.cards.find((card) => card.id === cardId)?.name || content.unknownCard;

View file

@ -3,11 +3,12 @@
* textes au pluriel).
*/
import { fillTemplate } from "../dailyShare.js";
import { fillTemplate } from "../textFormat.js";
import { STAT_IDS } from "../expeditions/expeditionFormat.js";
// Spécialités affichées sur le bandeau : celles données par le serveur, ou l'équilibre.
export const BALANCED = "balanced";
/** Spécialités affichées sur le bandeau d'un équipier, ou `BALANCED` s'il n'en a pas. */
export const bandOf = (companion) => (companion.specialties.length ? companion.specialties : [BALANCED]);
/** Stats montrées en grand : les spécialités, sinon la plus haute. */
@ -16,8 +17,10 @@ export function mainStats({ specialties, stats }) {
return [STAT_IDS.reduce((best, stat) => (stats[stat] > stats[best] ? stat : best), STAT_IDS[0])];
}
/** Meilleure valeur de l'équipe pour chaque stat. */
export const teamBest = (companions) => Object.fromEntries(STAT_IDS.map((stat) => [stat, Math.max(0, ...companions.map((companion) => companion.stats[stat]))]));
/** Puissance moyenne de l'équipe, arrondie. */
export const averagePower = (companions) => Math.round(companions.reduce((sum, companion) => sum + companion.power, 0) / companions.length);
/** Un candidat « manque à l'équipe » s'il a une spécialité que personne n'a encore. */
@ -29,6 +32,7 @@ export function isMissing(companion, team) {
/** Texte au singulier ou au pluriel : `{ one, many }`, avec `{count}`. */
export const countText = (texts, count, values = {}) => fillTemplate(count > 1 ? texts.many : texts.one, { count, ...values });
/** Part d'étoiles noires parmi les étoiles encore cachées, en pourcentage. */
export const riskPct = ({ gold, black, dust }) => {
const total = gold + black + dust;
return total ? Math.round((black / total) * 100) : 0;