sokko-g/website/src/features/cards/ExpeditionLoadout.jsx
Shinuwa 98ffe6562c Add a loot legend, a foldable Watcher's bag and a mythic halo, and move card sheet and power texts to site.json
- 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>
2026-11-18 15:44:44 +01:00

116 lines
9.4 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 : étape « Votre carte » de la préparation d'une expédition. Un cadre réunit l'emplacement de la carte envoyée (en `lg`, un
// « + » tant qu'aucune n'est choisie), ses stats pour l'expédition et ses trois emplacements d'équipement (en `md`). Un clic sur
// l'emplacement de la carte ouvre la liste des cartes jouables (tris, étiquettes utiles à la destination) ; un clic sur un
// emplacement d'équipement ouvre le choix des communes, « Graver » sous une commune sa gravure (avec un Burin) ; « Améliorer la
// carte » ouvre sa fiche (niveau, plan de progression).
import { useMemo, useState } from "react";
import { Modal } from "../../components/Modal.jsx";
import { Tooltip } from "../../components/Tooltip.jsx";
import { fillTemplate } from "./dailyShare.js";
import { ExpeditionCardTile } from "./ExpeditionCardTile.jsx";
import { EquipmentPicker, EquipmentSlots, PowerTooltipContent } from "./ExpeditionEquipmentSlots.jsx";
import { CardSheet, EngraveModal } from "./ExpeditionImprove.jsx";
import { editionEntry, formatDecimal, helpScore, powerDetails, powerText, STAT_IDS, tagColor, tagLabel } from "./expeditionFormat.js";
import { MaskIcon } from "./ExpeditionLabels.jsx";
import { NebulaCard } from "./NebulaCard.jsx";
// Tris des cartes jouables : utiles à la destination (condition, dangers, Affinité), Puissance ou une stat.
const SORTS = ["useful", "power", ...STAT_IDS];
// Total d'une stat de la carte pour l'expédition, et au survol son détail : la valeur de la carte et l'apport de chaque commune
// (synergie comprise).
function StatTotal({ card, stat, content }) {
const sign = (value) => `${value > 0 ? "+" : "−"}${formatDecimal(Math.abs(value))}`;
const base = card.baseStats?.[stat] ?? card.stats[stat];
const lines = [
fillTemplate(content.statBase, { value: formatDecimal(base) }),
...(card.equipment || []).map((item) => {
const value = (item.stats?.[stat] || 0) + (item.synergyStat === stat ? item.synergyBonus || 0 : 0);
return value ? fillTemplate(content.bonusFrom, { card: item.name, value: sign(value) }) : null;
}).filter(Boolean)
];
return <Tooltip className="nebula-loadout-stat-total" content={<span className="nebula-tooltip-lines">{lines.map((line) => <span key={line}>{line}</span>)}</span>}
aria-label={`${content.stats[stat]} : ${formatDecimal(card.stats[stat])}. ${lines.join(" ; ")}`} tabIndex={0}>
<strong aria-hidden="true">{formatDecimal(card.stats[stat])}</strong>
</Tooltip>;
}
// Liste des cartes jouables, dans une fenêtre : un clic choisit la carte et la ferme.
function CardPicker({ catalog, view, destination, selectedId, content, onChoose, onClose }) {
const mainStat = destination?.stats[0];
// Tri par défaut : la stat principale de la destination.
const [sort, setSort] = useState(null);
const sortKey = sort || mainStat;
// La carte déjà choisie en tête, puis les cartes libres avant celles en expédition, dans l'ordre du tri.
const cards = useMemo(() => [...view.cards].sort((a, b) => Number(b.editionId === selectedId) - Number(a.editionId === selectedId) || Number(a.busy) - Number(b.busy)
|| (sortKey === "useful" ? helpScore(b, destination) - helpScore(a, destination) || (b.stats[mainStat] ?? 0) - (a.stats[mainStat] ?? 0)
: sortKey === "power" ? b.power - a.power : (b.stats[sortKey] ?? 0) - (a.stats[sortKey] ?? 0) || b.power - a.power)), [view.cards, sortKey, destination, mainStat, selectedId]);
return <Modal dialogClassName="confirm-modal nds-modal nebula-expedition-picker" labelledBy="nebula-card-picker-title" onRequestClose={onClose}>
<h2 id="nebula-card-picker-title">{content.cardPickerTitle}</h2>
<p className="nebula-form-help">{fillTemplate(content.cardPickerHelp, { destination: destination?.name || "" })}</p>
<div className="nebula-expedition-sort" role="group" aria-label={content.sortLabel}>
<span className="nebula-form-help">{content.sortLabel}</span>
{SORTS.map((id) => <button key={id} type="button" className="nds-button" data-size="sm" data-variant={id === sortKey ? "primary" : "secondary"} aria-pressed={id === sortKey} onClick={() => setSort(id)}>
{id === "useful" ? content.sortUseful : id === "power" ? content.sortPower : <><MaskIcon name={id} />{content.stats[id]}</>}
</button>)}
</div>
{cards.length ? <ul className="nebula-expedition-cards" aria-label={content.cardsLabel}>{cards.map((item) => <ExpeditionCardTile key={item.editionId} catalog={catalog} card={item}
destination={destination} content={content} selected={item.editionId === selectedId} sortKey={sortKey} onSelect={() => { onChoose(item.editionId); onClose(); }} />)}</ul>
: <p className="nds-inline-notice" data-variant="info">{content.noCards}</p>}
<div className="nds-toolbar nebula-expedition-picker-actions">
<button className="nds-button" data-variant="secondary" type="button" onClick={onClose}>{content.cancel}</button>
</div>
</Modal>;
}
export function ExpeditionLoadout({ catalog, state, view, destination, card, onChooseCard, content, busy, runMutation }) {
// Fenêtre ouverte : « card » (choix de la carte) ou le numéro de l'emplacement d'équipement.
const [picker, setPicker] = useState(null);
// Exigences de la destination choisie pour une carte seule : elles ne donnent que la couleur des totaux.
const requirements = destination?.requirements || [];
const entry = card && editionEntry(catalog, card.editionId);
const progress = card && state.cardProgress?.find((item) => item.editionId === card.editionId);
return <div className="nebula-expedition-loadout">
<div className="nebula-loadout-card">
{entry ? <NebulaCard catalog={catalog} entry={entry} size="lg" onSelect={() => setPicker("card")} selectLabel={fillTemplate(content.changeCard, { card: entry.card.name })} />
: <button className="nebula-loadout-empty" type="button" onClick={() => setPicker("card")}><span aria-hidden="true">+</span><strong>{content.chooseCardSlot}</strong></button>}
{card?.tags?.length > 0 && <ul className="nebula-loadout-tags" aria-label={content.tagsTitle}>{card.tags.map((tag) => <li key={tag} className="nebula-tag-chip" data-tag-color={tagColor(card.tags, tag)}>{tagLabel(catalog, tag)}</li>)}</ul>}
{/* La fiche de la carte, sans quitter les Expéditions : niveau, plan de progression, équipement et gravure. */}
{entry && <button className="nds-button nebula-loadout-improve" data-size="sm" data-variant="secondary" type="button" onClick={() => setPicker("sheet")}>
<MaskIcon name="power" />{content.improveCard}
</button>}
</div>
<div className="nebula-loadout-body">
{card ? <h4>{entry?.card.name}</h4> : <p className="nebula-form-help">{content.loadoutEmpty}</p>}
<div className="nebula-loadout-columns">
<section className="nebula-loadout-equipment" aria-label={content.equipmentTitle}>
<h5>{content.equipmentTitle}</h5>
<EquipmentSlots catalog={catalog} progress={progress} content={content} busy={busy} runMutation={runMutation} onOpen={setPicker} powerValues={view.powers}
onEngrave={(state.items?.engraving ?? 0) > 0 ? (equipmentId) => setPicker({ engrave: equipmentId }) : null} />
</section>
{card && <section className="nebula-loadout-stats" aria-label={content.chosenStats}>
<h5>{content.chosenStatsTitle}</h5>
<ul className="nebula-expedition-chosen-stats">{STAT_IDS.map((stat) => {
const requirement = requirements.find((item) => item.stat === stat);
const met = requirement ? card.stats[stat] >= requirement.value : null;
return <li key={stat} data-met={met == null ? undefined : String(met)}>
<span className="nebula-loadout-stat-name"><MaskIcon name={stat} />{content.stats[stat]}</span>
<StatTotal card={card} stat={stat} content={content} />
</li>;
})}</ul>
{card.powers?.length > 0 && <ul className="nebula-expedition-chosen-powers" aria-label={content.chosenPowers}>{card.powers.map((power) => <li key={power}>
<Tooltip className="nebula-equipment-power" tooltipClassName="nebula-power-tooltip" content={<PowerTooltipContent power={power} values={view.powers} content={content} />}
aria-label={[`${content.powers[power]} : ${powerText(power, content)}`, ...powerDetails(power, view.powers, content)].join(" ; ")} tabIndex={0}>
<MaskIcon name="power" /><span aria-hidden="true">{content.powers[power]}</span>
</Tooltip> {powerText(power, content)}
</li>)}</ul>}
</section>}
</div>
</div>
{picker?.engrave && progress && <EngraveModal catalog={catalog} state={state} view={view} equipmentId={picker.engrave} characterId={progress.editionId} content={content} busy={busy} runMutation={runMutation} onClose={() => setPicker(null)} />}
{picker === "sheet" && card && <CardSheet catalog={catalog} state={state} editionId={card.editionId} content={content.cardSheet} busy={busy} runMutation={runMutation} onClose={() => setPicker(null)} />}
{picker === "card" && <CardPicker catalog={catalog} view={view} destination={destination} selectedId={card?.editionId} content={content} onChoose={onChooseCard} onClose={() => setPicker(null)} />}
{typeof picker === "number" && progress && <EquipmentPicker catalog={catalog} state={state} progress={progress} cardName={entry?.card.name || ""} slot={picker} content={content}
busy={busy} runMutation={runMutation} onClose={() => setPicker(null)} powerValues={view.powers} />}
</div>;
}