- The destinations step opens with a legend of the four loots and what the green and red arrows mean. - The Watcher's bag folds into a strip of item art and counts; the choice is kept by the browser. - Mythic cards wear a slowly turning prismatic ring across the expedition screens; it is visual only. - The card sheet and the stats distribution read their texts from cards.cardSheet, and power descriptions and their figures from cards.expeditions.powerText and powerDetails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
10 KiB
JavaScript
128 lines
10 KiB
JavaScript
// Rôle : affiche la fiche détaillée d'une carte possédée : à gauche la carte en grand, à 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 et la répartition des statistiques. L'équipement se règle depuis les Expéditions.
|
||
// `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 { CardPlan } from "./CardPlan.jsx";
|
||
import { CurrencyAmount } from "./Currency.jsx";
|
||
import { readCollection } from "./collectionState.js";
|
||
import { fillTemplate } from "./dailyShare.js";
|
||
import { MaskIcon } from "./ExpeditionLabels.jsx";
|
||
import { NebulaCard } from "./NebulaCard.jsx";
|
||
import { formatEclats } from "./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> : <>
|
||
<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>;
|
||
}
|
||
|
||
// Amélioration d'une carte rare ou mieux : Éclats, ou doublon de la même édition ; puis la répartition de ses statistiques.
|
||
function CardProgress({ state, progress, eclats, locked, busy, runMutation, onPreview, content }) {
|
||
const atCap = progress.nextCost == null;
|
||
return <>
|
||
{!atCap && <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">{fillTemplate(content.upgradeHelp, { eclats: formatEclats(eclats) })}</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} />
|
||
</>;
|
||
}
|
||
|
||
// `content` : textes cards.cardSheet.
|
||
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);
|
||
// 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>}
|
||
<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 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" /></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>;
|
||
}
|