The 669 // comments sitting right above a function, method or hook become /** */ blocks, unchanged in wording; eslint directives stay right above the line they target. website/AGENTS.md now asks for JSDoc on function comments and // inside function bodies. ExpeditionPlanner.jsx grew past 300 lines and gets its full header, as the header test requires. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
217 lines
17 KiB
JavaScript
217 lines
17 KiB
JavaScript
/**
|
||
* @file Affiche la fiche détaillée d'une carte possédée : à gauche la carte en grand (et, sur
|
||
* « Amélioration », les Éclats et les doublons disponibles), à droite son nom et, pour une carte des
|
||
* Expéditions, deux onglets. « La carte » (par défaut depuis la collection) : son lore, ses
|
||
* informations (exemplaires, collection, finitions) et les actions (favori, recyclage d'un doublon,
|
||
* don, échange). « Amélioration » (par défaut depuis les Expéditions, `initialTab`) : un récapitulatif
|
||
* (Puissance, niveau et expérience, les quatre stats et celles que donnerait la répartition en cours de
|
||
* choix), l'amélioration (ou l'Éveil devant un palier) et la répartition des statistiques. L'équipement
|
||
* se règle depuis les Expéditions.
|
||
*
|
||
* Une commune montre ce qu'elle apporte en équipement : ses stats ou son pouvoir, et sa synergie.
|
||
*
|
||
* `focus` (« plan ») ouvre « Amélioration » et fait défiler la fiche jusqu'à cette section, depuis un objet
|
||
* du Sac.
|
||
*/
|
||
|
||
import { useEffect, useRef, useState } from "react";
|
||
import { Modal } from "../../components/Modal.jsx";
|
||
import { Tabs } from "../../components/Tabs.jsx";
|
||
import { recycleDuplicates, setFavorite, upgradeCard } from "./cardsApi.js";
|
||
import { AwakeningPicker } from "./expeditions/AwakeningPicker.jsx";
|
||
import { CardPlan } from "./expeditions/CardPlan.jsx";
|
||
import { frenchList, rarityAdjective } from "./rarityWords.js";
|
||
import { CurrencyAmount, CurrencyIcon } from "./Currency.jsx";
|
||
import { readCollection } from "./collectionState.js";
|
||
import { fillTemplate } from "./dailyShare.js";
|
||
import { MaskIcon, StatValue } from "./expeditions/ExpeditionLabels.jsx";
|
||
import { PowerEffects } from "./expeditions/ExpeditionOutcome.jsx";
|
||
import { NebulaCard } from "./rendering/NebulaCard.jsx";
|
||
import { formatEclats, powerText, tagLabel } from "./expeditions/expeditionFormat.js";
|
||
import { formatStardust } from "./stardustFormat.js";
|
||
|
||
const STAT_IDS = ["bravoure", "endurance", "fortune", "orientation"];
|
||
const FOCUS_SELECTORS = { plan: ".nebula-card-plan" };
|
||
const TAB_IDS = ["card", "improve"];
|
||
|
||
/**
|
||
* Récapitulatif d'une carte des Expéditions : Puissance, niveau et expérience, puis ses quatre stats (équipement compris ; la part
|
||
* de l'équipement en petit dessous). `preview` : stats sans équipement de la répartition en cours de choix, montrées « 15 → 18 ».
|
||
*/
|
||
function CardSummary({ progress, preview, content }) {
|
||
const atCap = progress.nextCost == null;
|
||
return <section className="nebula-card-summary" aria-label={content.summaryLabel}>
|
||
<div className="nebula-card-summary-head">
|
||
<div className="nebula-card-summary-power"><span>{content.power}</span><strong>{progress.power}</strong></div>
|
||
<div className="nebula-card-summary-level">
|
||
<span>{content.level} <strong>{progress.level}</strong> / {progress.maxLevel}</span>
|
||
{atCap ? <small>{content.atCap}</small> : progress.awakening ? <small>{fillTemplate(content.awakeningWait, { power: progress.awakening.power })}</small> : <>
|
||
<div className="nds-progress" data-size="sm" role="progressbar" aria-label={content.experience} aria-valuemin={0} aria-valuemax={100} aria-valuenow={progress.fieldXp}><span style={{ width: `${progress.fieldXp}%` }} /></div>
|
||
<small>{fillTemplate(content.experienceValue, { value: progress.fieldXp })}</small>
|
||
</>}
|
||
</div>
|
||
</div>
|
||
<ul className="nebula-card-summary-stats" aria-label={content.statsLabel}>{STAT_IDS.map((stat) => {
|
||
const base = progress.baseStats?.[stat] ?? progress.stats[stat];
|
||
const gear = progress.stats[stat] - base;
|
||
const next = preview ? progress.stats[stat] + preview[stat] - base : progress.stats[stat];
|
||
return <li key={stat} data-trend={next > progress.stats[stat] ? "up" : next < progress.stats[stat] ? "down" : undefined}>
|
||
<span><MaskIcon name={stat} />{content.stats[stat]}</span>
|
||
<strong>{next !== progress.stats[stat] ? <>{progress.stats[stat]} <span aria-hidden="true">→</span><span className="sr-only">{content.becomes}</span>{next}</> : progress.stats[stat]}</strong>
|
||
{gear !== 0 && <small data-sign={gear > 0 ? "up" : "down"}>{fillTemplate(content.gear, { value: `${gear > 0 ? "+" : "−"}${Math.abs(gear)}` })}</small>}
|
||
</li>;
|
||
})}</ul>
|
||
</section>;
|
||
}
|
||
|
||
/** Sous la carte, dans l'onglet « Amélioration » : les Éclats du joueur et les doublons libres de la carte, en grand. */
|
||
function CardResources({ eclats, spare, content }) {
|
||
return <ul className="nebula-card-resources" aria-label={content.resourcesLabel}>
|
||
<li data-kind="eclats" data-empty={eclats === 0 || undefined}><span><CurrencyIcon kind="eclats" />{content.resourceEclats}</span><strong>{formatEclats(eclats)}</strong></li>
|
||
<li data-kind="duplicates" data-empty={spare === 0 || undefined}><span><MaskIcon name="cards" />{content.resourceDuplicates}</span><strong>{spare}</strong></li>
|
||
</ul>;
|
||
}
|
||
|
||
/**
|
||
* Éveil d'une carte arrêtée devant un palier : un doublon d'elle-même (pour une mythique, sa version légendaire), ou des doublons de
|
||
* sa collection et de sa rareté, choisis dans une fenêtre comme à l'atelier (de toute collection si les ouvertures ne
|
||
* donnent pas la sienne : fermée, des Expéditions ou de la Boutique). L'Éveil ne coûte pas d'Éclats.
|
||
*/
|
||
function CardAwakening({ catalog, progress, busy, runMutation, content }) {
|
||
const [choosing, setChoosing] = useState(false);
|
||
const { awakening } = progress;
|
||
const own = catalog.editions.find((edition) => edition.id === progress.editionId);
|
||
const card = catalog.cards.find((item) => item.id === own?.cardId);
|
||
// « rare », « légendaires ou mythiques » : les raretés acceptées, accordées avec le nombre de doublons.
|
||
const acceptedIds = own?.rarity === "mythic" ? ["legendary", "mythic"] : [own?.rarity];
|
||
const accepted = (count) => frenchList(acceptedIds.map((id) => rarityAdjective(catalog, id, count)), "disjunction");
|
||
const collectionName = catalog.collections.find((item) => item.id === card?.collectionId)?.name ?? "";
|
||
const exactIsOther = awakening.exact && awakening.exact !== progress.editionId;
|
||
const plural = awakening.needed > 1 ? "s" : "";
|
||
return <section className="nebula-card-upgrade nebula-card-awakening" aria-labelledby="nebula-card-awakening-title">
|
||
<h3 id="nebula-card-awakening-title">{fillTemplate(content.awakeningTitle, { power: awakening.power })}</h3>
|
||
<p className="nebula-form-help">{content.awakeningText}</p>
|
||
<div className="nds-toolbar">
|
||
<button className="nds-button" data-variant="primary" type="button" disabled={busy || !awakening.exact} onClick={() => runMutation(() => upgradeCard(progress.editionId, "duplicate"))}>{exactIsOther ? content.awakenLegendary : content.awakenExact}</button>
|
||
<button className="nds-button" data-variant="secondary" type="button" disabled={busy} onClick={() => setChoosing(true)}>{fillTemplate(content.awakenChoose, { count: awakening.needed, s: plural, rarity: accepted(awakening.needed) })}</button>
|
||
</div>
|
||
{awakening.anyCollection && <p className="nds-inline-notice" data-variant="info">{fillTemplate(content.awakenAnyCollection, { collection: collectionName, rarity: accepted(2) })}</p>}
|
||
<p className="nebula-form-help">{fillTemplate(awakening.anyCollection ? content.awakenPoolCountAny : content.awakenPoolCount, { available: Math.min(awakening.available, awakening.needed), count: awakening.needed, rarity: accepted(2), collection: collectionName })}</p>
|
||
{choosing && <AwakeningPicker catalog={catalog} cardName={card?.name ?? ""} awakening={awakening} rarityWords={accepted} collectionName={collectionName} content={content} busy={busy}
|
||
onAwaken={(editionIds) => runMutation(() => upgradeCard(progress.editionId, "awaken", editionIds))} onClose={() => setChoosing(false)} />}
|
||
</section>;
|
||
}
|
||
|
||
/**
|
||
* Amélioration d'une carte rare ou mieux : Éclats, ou doublon de la même édition (l'Éveil devant un palier) ; puis la répartition
|
||
* de ses statistiques.
|
||
*/
|
||
function CardProgress({ catalog, state, progress, eclats, locked, busy, runMutation, onPreview, content }) {
|
||
const atCap = progress.nextCost == null;
|
||
const awakeningsAhead = progress.awakeningsAhead ?? [];
|
||
return <>
|
||
{!atCap && progress.awakening && <CardAwakening catalog={catalog} progress={progress} busy={busy} runMutation={runMutation} content={content} />}
|
||
{!atCap && !progress.awakening && <section className="nebula-card-upgrade" aria-labelledby="nebula-card-upgrade-title">
|
||
<h3 id="nebula-card-upgrade-title">{content.upgradeTitle}</h3>
|
||
<div className="nds-toolbar">
|
||
<button className="nds-button" data-variant="primary" type="button" disabled={busy || eclats < progress.nextCost} onClick={() => runMutation(() => upgradeCard(progress.editionId, "eclats"))}>{content.upgradeEclats}<CurrencyAmount kind="eclats">{fillTemplate(content.eclatsAmount, { value: formatEclats(progress.nextCost) })}</CurrencyAmount></button>
|
||
{progress.spare > 0 && <button className="nds-button" data-variant="secondary" type="button" disabled={busy} onClick={() => runMutation(() => upgradeCard(progress.editionId, "duplicate"))}>{content.upgradeDuplicate}</button>}
|
||
</div>
|
||
<p className="nebula-form-help">{content.upgradeHelp}</p>
|
||
{/* Tant qu'un palier reste à franchir, les doublons valent plus pour l'Éveil que pour un niveau ordinaire : un par Éveil restant. */}
|
||
{awakeningsAhead.length > 0 && <p className="nds-inline-notice" data-variant="info">{fillTemplate(awakeningsAhead.length > 1 ? content.nextAwakening : content.lastAwakening, { power: awakeningsAhead[0], count: awakeningsAhead.length })}</p>}
|
||
</section>}
|
||
<CardPlan key={`${progress.plan.id}-${progress.plan.points}-${JSON.stringify(progress.plan.allocation)}`} progress={progress} oblivions={state.items?.oblivion ?? 0} locked={locked} busy={busy} runMutation={runMutation} onPreview={onPreview} content={content.plan} statNames={content.stats} />
|
||
</>;
|
||
}
|
||
|
||
/**
|
||
* Ce qu'une commune apporte quand elle équipe une carte : ses stats signées, ou son pouvoir (description, gains et contreparties),
|
||
* puis sa synergie et ses étiquettes (celle que le joueur a gravée comprise). `values` : `equipmentValues` de l'état du joueur.
|
||
*/
|
||
function CardEquipment({ catalog, card, tags, values, content }) {
|
||
const { stats = {}, power, synergyStat } = card.expedition.equipment;
|
||
const texts = content.expeditions;
|
||
const best = synergyStat ?? STAT_IDS.reduce((top, stat) => ((stats[stat] || 0) > (stats[top] || 0) ? stat : top), STAT_IDS[0]);
|
||
return <section className="nebula-card-equipment" data-power={power ? "" : undefined} aria-labelledby="nebula-card-equipment-title">
|
||
<h3 id="nebula-card-equipment-title">{content.equipmentTitle}</h3>
|
||
{power ? <div className="nebula-card-equipment-power">
|
||
<h4><MaskIcon name="power" /><span className="sr-only">{content.equipmentPower} : </span>{texts.powers[power]}</h4>
|
||
<p>{powerText(power, texts)}</p>
|
||
<PowerEffects power={power} values={values} content={texts} />
|
||
</div> : <ul className="nebula-card-equipment-stats">{STAT_IDS.filter((stat) => stats[stat]).map((stat) => <li key={stat}>
|
||
<StatValue stat={stat} value={stats[stat]} label={content.stats[stat]} signed /> {content.stats[stat]}
|
||
</li>)}</ul>}
|
||
<p className="nebula-form-help">{fillTemplate(content.equipmentSynergy, { value: values.synergyBonus, stat: content.stats[best] })}</p>
|
||
<p className="nebula-form-help">{fillTemplate(content.equipmentTags, { tags: tags.map((tag) => tagLabel(catalog, tag)).join(", ") })}</p>
|
||
</section>;
|
||
}
|
||
|
||
/** `content` : textes cards.cardSheet (et, pour une commune, ceux des Expéditions dans `expeditions`). */
|
||
export function CardDetailModal({ catalog, state, entry, content, runMutation, busy, onClose, onStartTransfer = null, focus = null, initialTab = "card" }) {
|
||
const dialogRef = useRef(null);
|
||
useEffect(() => {
|
||
if (!focus) return undefined;
|
||
const frame = requestAnimationFrame(() => dialogRef.current?.querySelector(FOCUS_SELECTORS[focus])?.scrollIntoView({ block: "start", behavior: "smooth" }));
|
||
return () => cancelAnimationFrame(frame);
|
||
}, [focus]);
|
||
const owned = readCollection(state).entries.get(entry.edition.id);
|
||
const quantity = owned?.quantity || 0;
|
||
const spare = owned?.spare || 0;
|
||
const value = state.shop.stardustValues[entry.edition.rarity] ?? 0;
|
||
const favorites = new Set(state.favorites);
|
||
const expedition = state.expeditions?.busyEditions?.find((item) => item.editionId === entry.edition.id);
|
||
const progress = state.cardProgress?.find((item) => item.editionId === entry.edition.id);
|
||
// Ce qu'une commune apporte en équipement, seulement si les Expéditions sont ouvertes.
|
||
const equipment = state.expeditions?.enabled && content.expeditions && state.equipmentValues && entry.card.expedition?.equipment;
|
||
const engravedTags = state.equipment?.find((item) => item.editionId === entry.edition.id)?.tags;
|
||
// Aperçu de la répartition en cours de choix, lié à la répartition enregistrée : il disparaît dès qu'elle change.
|
||
const planKey = progress && `${progress.plan.id}-${progress.plan.points}-${JSON.stringify(progress.plan.allocation)}`;
|
||
const [preview, setPreview] = useState({ key: null, stats: null });
|
||
const previewStats = preview.key === planKey ? preview.stats : null;
|
||
const [tab, setTab] = useState(focus ? "improve" : initialTab);
|
||
// Sans progression (commune, destination), seulement la carte.
|
||
const activeTab = progress ? tab : "card";
|
||
const tabs = TAB_IDS.map((id) => ({ id, label: content.tabs[id] }));
|
||
|
||
const info = <>
|
||
{entry.card.description && <p className="nebula-card-detail-lore">{entry.card.description}</p>}
|
||
{equipment && <CardEquipment catalog={catalog} card={entry.card} tags={engravedTags ?? entry.card.expedition.tags} values={state.equipmentValues} content={content} />}
|
||
<dl><div><dt>{content.owned}</dt><dd>{quantity}</dd></div><div><dt>{content.collection}</dt><dd>{catalog.collections.find((item) => item.id === entry.card.collectionId)?.name}</dd></div><div><dt>{content.finishes}</dt><dd>{entry.edition.finishIds.map((id) => catalog.finishes.find((item) => item.id === id)?.label).join(" · ")}</dd></div></dl>
|
||
<div className="nds-toolbar nebula-card-detail-actions">
|
||
<button className="nds-button" data-variant={favorites.has(entry.edition.id) ? "primary" : "secondary"} type="button" disabled={busy} aria-pressed={favorites.has(entry.edition.id)} onClick={() => runMutation(() => setFavorite(entry.edition.id, !favorites.has(entry.edition.id)))}>{favorites.has(entry.edition.id) ? content.favoriteRemove : content.favoriteAdd}</button>
|
||
{spare > 0 && <button className="nds-button" data-variant="secondary" type="button" disabled={busy} onClick={() => runMutation(() => recycleDuplicates(entry.edition.id))}>{fillTemplate(content.recycle, { value: formatStardust(value) })}</button>}
|
||
{spare > 0 && onStartTransfer && <>
|
||
<button className="nds-button" data-variant="secondary" type="button" onClick={() => onStartTransfer("gift", entry.edition.id)}>{content.give}</button>
|
||
<button className="nds-button" data-variant="secondary" type="button" onClick={() => onStartTransfer("trade", entry.edition.id)}>{content.trade}</button>
|
||
</>}
|
||
</div>
|
||
{quantity > 1 && !spare && <p className="nebula-form-help">{content.reserved}</p>}
|
||
</>;
|
||
const improve = progress && <>
|
||
<CardSummary progress={progress} preview={previewStats} content={content} />
|
||
<CardProgress catalog={catalog} state={state} progress={progress} eclats={state.wallet.eclats ?? 0} locked={Boolean(expedition)} busy={busy} runMutation={runMutation}
|
||
onPreview={(stats) => setPreview({ key: planKey, stats })} content={content} />
|
||
</>;
|
||
|
||
return <Modal dialogClassName="confirm-modal nds-modal nebula-card-detail" labelledBy="nebula-card-detail-title" onRequestClose={onClose} dialogRef={dialogRef}>
|
||
<div className="nebula-card-detail-layout">
|
||
<div className="nebula-card-detail-side">
|
||
<NebulaCard catalog={catalog} entry={entry} size="lg" />
|
||
{activeTab === "improve" && progress.nextCost != null && <CardResources eclats={state.wallet.eclats ?? 0} spare={progress.spare} content={content} />}
|
||
</div>
|
||
<div className="nebula-card-detail-main">
|
||
<header><p className="eyebrow">{catalog.rarities.find((item) => item.id === entry.edition.rarity)?.label}</p><h2 id="nebula-card-detail-title">{entry.card.name}</h2></header>
|
||
{expedition && <p className="nds-inline-notice" data-variant="info">{fillTemplate(content.busyUntil, { date: new Date(expedition.returnsAt).toLocaleString("fr-FR", { weekday: "long", hour: "2-digit", minute: "2-digit" }) })}</p>}
|
||
{/* Une carte des Expéditions a deux onglets : la carte et son lore, puis son amélioration. */}
|
||
{progress && <Tabs className="nebula-card-detail-tabs" tabs={tabs} activeTab={activeTab} onChange={setTab} />}
|
||
<div className="nebula-card-detail-panel" role={progress ? "tabpanel" : undefined} aria-label={progress ? content.tabs[activeTab] : undefined}>
|
||
{activeTab === "improve" ? improve : info}
|
||
</div>
|
||
<div className="nds-toolbar nebula-card-detail-close">
|
||
<button className="nds-button" data-variant="secondary" type="button" onClick={onClose}>{content.close}</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</Modal>;
|
||
}
|