sokko-g/website/src/features/cards/CardDetailModal.jsx
Shinuwa d863964a5d Advise players to level with Éclats and keep duplicates for awakenings
Duplicates now matter for awakening tiers, so the upgrade section of a card sheet says so while a tier lies ahead: level up with Éclats and experience, keep duplicates for awakenings. The bulk recycling box reminds that rare, epic and legendary duplicates also awaken cards once the player goes past commons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 10:28:39 +01:00

161 lines
13 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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 (ou l'Éveil devant un palier) 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 { AwakeningPicker } from "./AwakeningPicker.jsx";
import { CardPlan } from "./CardPlan.jsx";
import { frenchList, rarityAdjective } from "./rarityWords.js";
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> : 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>;
}
// É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. 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>
<p className="nebula-form-help">{fillTemplate(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 nextAwakening = progress.awakeningsAhead?.[0];
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">{fillTemplate(content.upgradeHelp, { eclats: formatEclats(eclats) })}</p>
{/* Tant qu'un palier reste à franchir, les doublons valent plus pour l'Éveil que pour un niveau ordinaire. */}
{nextAwakening && <p className="nds-inline-notice" data-variant="info">{fillTemplate(content.nextAwakening, { power: nextAwakening })}</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 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" /></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>;
}