#/mobile/cards shows the game without the site shell: a title, a footer with the account and a discreet "Version complète" link, and a tab bar fixed at the bottom. Phones opening #/cards are sent to the same section in mobile mode unless the player chose the full version. Account, History and Administration point to the computer. The panels are the computer ones, adapted under .nebula-mobile (and body.nebula-mobile-body for dialogs) for a 393×852 reference phone: small cards with names under them when opening packs, a revealed card shown large on tap, tap-to-pick team recruitment with a single Recruit button and large stars, row lists for explorers and commons in the expedition pickers, a race track and circuit that read at phone size, and full-width actions throughout. Firefox no longer shows a mirrored back on a flipped card. Phone Playwright journeys check that every section fits the screen with no button wrapping, then open a pack, run an expedition and recruit a team by touch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
149 lines
11 KiB
JavaScript
149 lines
11 KiB
JavaScript
/**
|
||
* @file É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 "../textFormat.js";
|
||
import { useCardsMobile } from "../useCardsHref.js";
|
||
import { ExpeditionCardTile } from "./ExpeditionCardTile.jsx";
|
||
import { EquipmentPicker, EquipmentSlots } from "./ExpeditionEquipmentSlots.jsx";
|
||
import { CardSheet, EngraveModal } from "./ExpeditionImprove.jsx";
|
||
import { editionEntry, formatDecimal, helpScore, powerText, STAT_IDS, tagColor, tagLabel } from "./expeditionFormat.js";
|
||
import { MainStatMark, MaskIcon } from "./ExpeditionLabels.jsx";
|
||
import { PowerName } from "./ExpeditionOutcome.jsx";
|
||
import { NebulaCard } from "../rendering/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>;
|
||
}
|
||
|
||
/**
|
||
* Exigences d'un groupe, une pastille par stat : l'apport de l'équipe face à l'exigence, en vert si elle est atteinte ; avec `missing`
|
||
* (avant le choix de la carte), ce qui manque au groupe. Sans prévision (Coup de folie), l'exigence seule.
|
||
*/
|
||
function GroupNeeds({ needs, content }) {
|
||
return <section className="nebula-group-needs" aria-label={needs.title} aria-busy={needs.stale || undefined} data-stale={needs.stale || undefined}>
|
||
<span className="nebula-group-needs-title">{needs.title}</span>
|
||
<ul>{needs.rows.map(({ stat, main, value, team }) => {
|
||
const met = team == null ? null : team >= value;
|
||
return <li key={stat} data-met={met == null ? undefined : String(met)}>
|
||
<span className="nebula-loadout-stat-name"><MaskIcon name={stat} />{content.stats[stat]}{main && <MainStatMark content={content} />}</span>
|
||
<strong>{team == null ? value : fillTemplate(content.teamVersus, { team: formatDecimal(team), value })}</strong>
|
||
{needs.missing && met === false && <small>{fillTemplate(content.needsMissing, { value: formatDecimal(Math.ceil((value - team) * 10) / 10) })}</small>}
|
||
</li>;
|
||
})}</ul>
|
||
</section>;
|
||
}
|
||
|
||
/** Liste des cartes jouables, dans une fenêtre : un clic choisit la carte et la ferme. */
|
||
function CardPicker({ catalog, view, destination, selectedId, needs, 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>
|
||
{needs && <GroupNeeds needs={needs} content={content} />}
|
||
<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>;
|
||
}
|
||
|
||
/**
|
||
* `needs` et `pickerNeeds` : pour un groupe, ses exigences rappelées au-dessus des équipements et dans le choix de la carte.
|
||
* `actions` : boutons du cadre (valider, annuler…), en bas à droite.
|
||
*/
|
||
export function ExpeditionLoadout({ catalog, state, view, destination, card, onChooseCard, content, busy, runMutation, needs = null, pickerNeeds = null, actions = null }) {
|
||
// Fenêtre ouverte : « card » (choix de la carte) ou le numéro de l'emplacement d'équipement.
|
||
const [picker, setPicker] = useState(null);
|
||
// Sur téléphone, la carte choisie est en petit format (illustration seule) : son nom est juste dessous, et les textes
|
||
// d'une grande carte réduite à cette largeur seraient illisibles.
|
||
const mobile = useCardsMobile();
|
||
// 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={mobile ? "sm" : "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>}
|
||
{needs && <GroupNeeds needs={needs} content={content} />}
|
||
<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}>
|
||
<PowerName power={power} values={view.powers} content={content} /> {powerText(power, content)}
|
||
</li>)}</ul>}
|
||
</section>}
|
||
</div>
|
||
</div>
|
||
{actions && <div className="nds-toolbar nebula-loadout-actions">{actions}</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} needs={pickerNeeds} 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>;
|
||
}
|