The destination panel now lists the themes that grant Affinité, with the score it adds and whether the chosen card carries one. A theme that is also the condition shows once, in the condition line, since a single card then meets both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
267 lines
21 KiB
JavaScript
267 lines
21 KiB
JavaScript
// Rôle : prépare une expédition en trois étapes : la destination du jour (butin et exigences, colorées selon la carte choisie), la
|
||
// carte envoyée et son équipement (ExpeditionLoadout), puis la durée et le départ, seul tout de suite ou ouvert au groupe.
|
||
import { useEffect, useMemo, useState } from "react";
|
||
import { Tooltip } from "../../components/Tooltip.jsx";
|
||
import { previewExpedition } from "./cardsApi.js";
|
||
import { fillTemplate } from "./dailyShare.js";
|
||
import { conditionText, coverEntry, dangerText, editionEntry, formatDecimal, formatEclats, ITEM_ART, synergyBadges, tagLabel } from "./expeditionFormat.js";
|
||
import { MainStatMark, MaskIcon } from "./ExpeditionLabels.jsx";
|
||
import { ExpeditionLoadout } from "./ExpeditionLoadout.jsx";
|
||
import { BonusBadges, ExpectedLootTile, PowerName, TierTile } from "./ExpeditionOutcome.jsx";
|
||
|
||
const PREVIEW_DELAY_MS = 250;
|
||
const LOOT_KINDS = ["eclats", "stardust", "cards", "items"];
|
||
|
||
// Effet de la spécialité sur le butin, regroupé par sens : une flèche verte (le ou les butins favorisés) ou rouge (les autres)
|
||
// suivie des icônes des butins concernés ; le pourcentage s'affiche dans l'infobulle de la flèche.
|
||
// Toutes en contour monochrome (les monnaies ont leur version « outline ») pour que les icônes du butin restent homogènes.
|
||
// Au survol, l'icône dit de quel butin il s'agit. Elle est dans le bouton de la destination : pas d'arrêt au clavier en plus, le
|
||
// libellé complet est porté par la ligne (aria-label).
|
||
function LootIcon({ kind, label }) {
|
||
return <Tooltip className="nebula-loot-icon" content={label} tabIndex={-1}><MaskIcon name={kind} /></Tooltip>;
|
||
}
|
||
|
||
const ARROW_PATHS = { up: "M5 1 9 5.4H6.4V9H3.6V5.4H1Z", down: "M5 9 1 4.6H3.6V1H6.4V4.6H9Z" };
|
||
// Flèche avec, au survol, le montant du bonus ou du malus (Tooltip du NDS) ; sans `label`, pas d'infobulle.
|
||
function TrendArrow({ trend, label = null }) {
|
||
return <Tooltip className="nebula-loot-arrow-anchor" content={label} tabIndex={-1}>
|
||
<svg className="nebula-loot-arrow" viewBox="0 0 10 10" aria-hidden="true"><path d={ARROW_PATHS[trend]} /></svg>
|
||
</Tooltip>;
|
||
}
|
||
|
||
function LootEffects({ specialty, settings, content }) {
|
||
if (!specialty || !settings) return null;
|
||
// Spécialité simple (une récompense favorisée) ou double (deux), chacune avec ses pourcentages.
|
||
const pct = specialty.length === 2 ? { boostPct: settings.pairBoostPct, otherPct: settings.pairOtherPct } : settings;
|
||
const rows = [
|
||
{ trend: "up", delta: pct.boostPct - 100, kinds: LOOT_KINDS.filter((kind) => specialty.includes(kind)) },
|
||
{ trend: "down", delta: pct.otherPct - 100, kinds: LOOT_KINDS.filter((kind) => !specialty.includes(kind)) }
|
||
].filter((row) => row.delta && row.kinds.length);
|
||
return <span className="nebula-loot-effects" role="list" aria-label={content.lootTitle}>{rows.map(({ trend, delta, kinds }) => {
|
||
const value = `${delta > 0 ? "+" : "−"}${Math.abs(delta)} %`;
|
||
const label = fillTemplate(content.lootEffect, { loot: kinds.map((kind) => content.loot[kind]).join(", "), value });
|
||
return <span key={trend} role="listitem" className="nebula-loot-effect" data-trend={trend} aria-label={label}>
|
||
<TrendArrow trend={trend} label={value} />
|
||
<span className="nebula-loot-icons" aria-hidden="true">{kinds.map((kind) => <LootIcon key={kind} kind={kind} label={content.loot[kind]} />)}</span>
|
||
</span>;
|
||
})}</span>;
|
||
}
|
||
|
||
// Légende du butin des destinations, une fois en tête de l'étape : chaque icône avec son nom, et le sens des flèches.
|
||
function LootLegend({ content }) {
|
||
return <p className="nebula-loot-legend" aria-label={content.lootLegendLabel}>
|
||
<span className="nebula-loot-legend-kinds">{LOOT_KINDS.map((kind) => <span key={kind}><MaskIcon name={kind} />{content.loot[kind]}</span>)}</span>
|
||
<span className="nebula-loot-legend-trends">
|
||
<span data-trend="up"><svg className="nebula-loot-arrow" viewBox="0 0 10 10" aria-hidden="true"><path d={ARROW_PATHS.up} /></svg>{content.lootLegendUp}</span>
|
||
<span data-trend="down"><svg className="nebula-loot-arrow" viewBox="0 0 10 10" aria-hidden="true"><path d={ARROW_PATHS.down} /></svg>{content.lootLegendDown}</span>
|
||
</span>
|
||
</p>;
|
||
}
|
||
|
||
// Illustration d'une destination : son paysage dans la forme du coup de pinceau, sinon l'image de sa carte de couverture.
|
||
// Toujours un bandeau de même forme, pour que les cartes voisines restent alignées.
|
||
function DestinationCover({ catalog, destination }) {
|
||
const cover = !destination.image && destination.coverCardId && coverEntry(catalog, destination.coverCardId);
|
||
const image = destination.image || cover?.card.image;
|
||
return <span className="nebula-destination-scene" data-cover={cover ? "" : undefined}>{image && <img src={image} alt="" loading="lazy" />}</span>;
|
||
}
|
||
|
||
// Badge des étoiles d'une destination, lu « Difficulté : 2 étoiles ».
|
||
function StarsBadge({ stars, content }) {
|
||
return <span className="nds-badge nebula-expedition-stars" data-variant="gold" role="img" aria-label={fillTemplate(content.starsLabel, { stars: `${stars} étoile${stars > 1 ? "s" : ""}` })}>{"★".repeat(stars)}</span>;
|
||
}
|
||
|
||
// Condition et dangers d'une destination, dans sa carte : une ligne chacun (la phrase complète au survol). Avec une carte choisie,
|
||
// un pouce vert levé pour une condition remplie ou un danger paré, un pouce rouge baissé sinon (l'état est dit en texte aux
|
||
// lecteurs d'écran).
|
||
function DestinationHazards({ catalog, destination, card, content }) {
|
||
const condition = destination.condition;
|
||
const conditionLabel = condition && (condition.type === "collection"
|
||
? catalog.collections.find((item) => item.id === condition.collectionId)?.name || condition.collectionId
|
||
: tagLabel(catalog, condition.tag));
|
||
const conditionMet = card && condition && (condition.type === "collection" ? card.collectionId === condition.collectionId : card.tags?.includes(condition.tag));
|
||
// Condition, Affinité (les thèmes de la destination) et dangers : nom et état sur la première ligne, ce qui la remplit, l'obtient
|
||
// ou le pare dessous, sur toute la largeur.
|
||
const row = ({ key, text, detail, title, ok, okText, koText }) => <span key={key} role="listitem" className="nebula-destination-hazard" data-met={card ? String(Boolean(ok)) : undefined}
|
||
title={title} aria-label={`${title}${card ? ` ${ok ? okText : koText}` : ""}`}>
|
||
<strong aria-hidden="true">{text}</strong>
|
||
{card && <span className="nebula-destination-hazard-state" data-ok={ok ? "true" : "false"} aria-hidden="true" title={ok ? okText : koText}><MaskIcon name="thumb" /></span>}
|
||
<small aria-hidden="true">{detail}</small>
|
||
</span>;
|
||
// Un thème qui est aussi la condition ne s'affiche qu'une fois : la condition dit qu'elle donne l'Affinité, la ligne Affinité ne
|
||
// garde que les autres thèmes (tous en 1 et 2 ★, sans condition).
|
||
const themes = destination.themeTags || [];
|
||
const conditionTheme = condition?.type === "tag" && themes.includes(condition.tag);
|
||
const otherThemes = themes.filter((tag) => !(conditionTheme && tag === condition.tag));
|
||
const conditionDetail = conditionTheme ? `${content.conditionDetail} ${fillTemplate(content.conditionAffinity, { value: destination.affinityPct ?? "" })}` : content.conditionDetail;
|
||
return <span className="nebula-destination-hazards" role="list" aria-label={content.hazardsTitle}>
|
||
{condition && row({ key: "condition", text: fillTemplate(content.conditionShort, { name: conditionLabel }), detail: conditionDetail,
|
||
title: conditionText(condition, catalog, content), ok: conditionMet, okText: content.conditionOk, koText: content.conditionKo })}
|
||
{otherThemes.length > 0 && (() => {
|
||
const tags = otherThemes.map((tag) => tagLabel(catalog, tag)).join(content.or);
|
||
const values = { tags, value: destination.affinityPct ?? "" };
|
||
return row({ key: "affinity", text: fillTemplate(content.affinityShort, values), detail: fillTemplate(content.affinityDetail, values),
|
||
title: fillTemplate(content.affinityText, values), ok: card?.tags?.some((tag) => otherThemes.includes(tag)), okText: content.affinityOk, koText: content.affinityKo });
|
||
})()}
|
||
{destination.dangers.map((danger) => row({ key: danger.id, text: fillTemplate(content.dangerShort, { label: danger.label }),
|
||
detail: fillTemplate(content.dangerDetail, { stat: content.stats[danger.stat], tags: danger.unlessTags.map((tag) => tagLabel(catalog, tag)).join(content.or) }),
|
||
title: dangerText(danger, catalog, content), ok: card?.tags?.some((tag) => danger.unlessTags.includes(tag)), okText: content.dangerOk, koText: content.dangerKo }))}
|
||
</span>;
|
||
}
|
||
|
||
// Aperçu d'un départ seul, en petits encarts comme une expédition ouverte : résultat prévu (palier, score, effet sur le butin), butin
|
||
// attendu, pouvoirs et bonus au score ; puis les avertissements (trajet, durée, étoiles). Les exigences sont dans la carte de la
|
||
// destination. Avec le Coup de folie, pas de résultat prévu, seulement la fourchette des exigences réelles.
|
||
function Preview({ catalog, preview, content, hours, tierLootPct }) {
|
||
const bonuses = synergyBadges(preview, catalog, content);
|
||
return <div className="nebula-expedition-preview" aria-live="polite">
|
||
<dl className="nebula-group-outcome" aria-label={content.previewTitle}>
|
||
{preview.hiddenRequirements
|
||
? <div><dt>{content.groupOutcomeTier}</dt><dd><p className="nebula-group-tier-loot">{fillTemplate(content.hiddenRequirements, preview.requirementRange || { min: "?", max: "?" })}</p></dd></div>
|
||
: <TierTile tier={preview.tier} scorePct={preview.scorePct} lootPct={tierLootPct?.[preview.tier]} content={content} />}
|
||
<ExpectedLootTile expected={preview.expected} content={content} />
|
||
{(preview.powers || []).length > 0 && <div><dt>{content.groupOutcomePowers}</dt><dd className="nebula-group-powers">{preview.powers.map((power) => <PowerName key={power} power={power} content={content} stats={power === "attunement" ? (preview.attunement || []).map((item) => item.stat) : []} />)}</dd></div>}
|
||
{bonuses.length > 0 && <div><dt>{content.groupOutcomeBonuses}</dt><dd><BonusBadges badges={bonuses} /></dd></div>}
|
||
</dl>
|
||
{!preview.hiddenRequirements && preview.limitedByStars && <p className="nds-inline-notice" data-variant="warning">{fillTemplate(content.limitedByStarsHelp, { stars: preview.limitedByStars })}</p>}
|
||
{!preview.hiddenRequirements && preview.durationFactor < 1 && <p className="nds-inline-notice" data-variant="warning">{content.durationMalus}</p>}
|
||
{/* Seulement si un pouvoir allonge ou raccourcit le trajet ; `hours` est la durée pour laquelle cet aperçu a été calculé. */}
|
||
{preview.travelHours != null && preview.travelHours !== hours && <p className="nebula-form-help">{fillTemplate(content.travelTime, { hours: formatDecimal(preview.travelHours) })}</p>}
|
||
</div>;
|
||
}
|
||
|
||
// Exigences d'une destination pour une carte seule, dans sa carte : une ligne par stat exigée (icône, nom complet, valeur). La stat
|
||
// principale, qui compte double dans le score, porte une étoile. Avec une carte choisie, chaque ligne montre sa valeur face à l'exigence, en vert si elle
|
||
// l'atteint, en rouge sinon. Avec le Coup de folie, les exigences réelles varient : les valeurs affichées sont des estimations (« ≈ »).
|
||
function DestinationRequirements({ requirements, card, content }) {
|
||
const shown = (value) => (card?.powers?.includes("madCompass") ? fillTemplate(content.requirementsUncertain, { value }) : value);
|
||
return <span className="nebula-destination-requirements" role="list" aria-label={content.requirementsFactTitle}>
|
||
{requirements.map(({ stat, value, main }) => {
|
||
const team = card?.stats[stat];
|
||
const met = card ? team >= value : null;
|
||
const label = [
|
||
fillTemplate(content.requirementValue, { stat: content.stats[stat], value }),
|
||
main ? content.mainStatHelp : "",
|
||
card ? fillTemplate(met ? content.requirementMet : content.requirementUnmet, { team: formatDecimal(team) }) : ""
|
||
].filter(Boolean).join(" ");
|
||
return <span key={stat} role="listitem" className="nebula-destination-requirement" data-main={main || undefined} data-met={met == null ? undefined : String(met)} aria-label={label}>
|
||
<span className="nebula-destination-requirement-stat" aria-hidden="true">
|
||
<MaskIcon name={stat} />{content.stats[stat]}
|
||
{main && <MainStatMark content={content} />}
|
||
</span>
|
||
<strong aria-hidden="true">{card ? fillTemplate(content.teamVersus, { team: formatDecimal(team), value: shown(value) }) : value}</strong>
|
||
</span>;
|
||
})}
|
||
</span>;
|
||
}
|
||
|
||
// Une destination du jour, en deux rangées alignées avec celles de la carte voisine : en-tête (paysage réduit à gauche ; nom, étoiles,
|
||
// description et butin à droite), puis ses exigences (stats, condition et dangers).
|
||
function DestinationOption({ catalog, item, selected, card, view, content, onSelect }) {
|
||
const collection = item.rewardCollectionId && (catalog.collections.find((entry) => entry.id === item.rewardCollectionId)?.name || item.rewardCollectionId);
|
||
return <button type="button" className="nebula-expedition-destination" aria-pressed={selected} onClick={onSelect}>
|
||
<span className="nebula-expedition-destination-head">
|
||
<DestinationCover catalog={catalog} destination={item} />
|
||
<span className="nebula-expedition-destination-copy">
|
||
<strong className="nebula-expedition-destination-name">{item.name}<StarsBadge stars={item.star} content={content} />{item.bonusSlot && <span className="nds-badge" data-variant="gold">{content.bonusSlots[item.bonusSlot]}</span>}</strong>
|
||
<span className="nebula-expedition-destination-description">{item.description}</span>
|
||
<span className="nebula-destination-loot">
|
||
<span className="nebula-destination-fact-title">{content.lootTitle}</span>
|
||
<LootEffects specialty={item.specialty} settings={view.specialty} content={content} />
|
||
{collection && <span className="nebula-loot-effect" data-trend="up" data-kind="collection" aria-label={fillTemplate(content.rewardCollection, { collection })}>
|
||
<TrendArrow trend="up" /><span aria-hidden="true"><LootIcon kind="cards" label={fillTemplate(content.rewardCollection, { collection })} />{collection}</span>
|
||
</span>}
|
||
{!item.specialty && !collection && <span className="nebula-destination-neutral">{content.lootNeutral}</span>}
|
||
</span>
|
||
</span>
|
||
</span>
|
||
<span className="nebula-destination-fact">
|
||
<span className="nebula-destination-fact-title">{content.requirementsFactTitle}</span>
|
||
<DestinationRequirements requirements={item.requirements} card={card} content={content} />
|
||
{(item.condition || item.dangers.length > 0 || (item.themeTags || []).length > 0) && <DestinationHazards catalog={catalog} destination={item} card={card} content={content} />}
|
||
</span>
|
||
</button>;
|
||
}
|
||
|
||
export function ExpeditionPlanner({ catalog, state, view, content, busy, onStart, onReroll, runMutation }) {
|
||
// Destinations de la plus facile à la plus difficile.
|
||
const destinations = useMemo(() => [...view.destinations].sort((a, b) => (a.level ?? 0) - (b.level ?? 0)), [view.destinations]);
|
||
const [destinationId, setDestinationId] = useState(destinations[0]?.id || "");
|
||
const [hours, setHours] = useState(view.durations[0]);
|
||
const [editionId, setEditionId] = useState(null);
|
||
const [preview, setPreview] = useState({ key: "", value: null, error: "" });
|
||
const destination = destinations.find((item) => item.id === destinationId) || destinations[0];
|
||
const card = view.cards.find((item) => item.editionId === editionId && !item.busy) || null;
|
||
const complete = Boolean(destination && card);
|
||
const body = useMemo(() => ({ day: view.day, destinationId: destination?.id, durationHours: hours, editionId: card?.editionId ?? null }), [view.day, destination?.id, hours, card?.editionId]);
|
||
// L'équipement change les stats : l'aperçu se recalcule avec elles.
|
||
const bodyKey = JSON.stringify({ ...body, stats: card?.stats, powers: card?.powers });
|
||
|
||
// Aperçu demandé au serveur dès que la carte est choisie, après une courte pause pour ne pas l'interroger à chaque clic.
|
||
useEffect(() => {
|
||
if (!complete) return undefined;
|
||
let active = true;
|
||
const timer = setTimeout(() => {
|
||
const { stats: _stats, powers: _powers, ...request } = JSON.parse(bodyKey);
|
||
previewExpedition(request)
|
||
.then((result) => { if (active) setPreview({ key: bodyKey, value: result.preview, error: "" }); })
|
||
.catch((error) => { if (active) setPreview({ key: bodyKey, value: null, error: error.message }); });
|
||
}, PREVIEW_DELAY_MS);
|
||
return () => { active = false; clearTimeout(timer); };
|
||
}, [bodyKey, complete]);
|
||
|
||
if (!destination) return <div className="nds-empty-state"><p>{content.noDestination}</p></div>;
|
||
|
||
// Pendant qu'un nouvel aperçu se calcule (durée, carte ou équipement changés), le précédent reste affiché, atténué : la page ne
|
||
// saute pas. Une erreur ne vaut que pour la demande en cours.
|
||
const stale = preview.key !== bodyKey;
|
||
const shownPreview = complete ? { value: preview.value, error: stale ? "" : preview.error } : null;
|
||
const start = async (departNow) => { if (await onStart({ ...body, departNow })) setEditionId(null); };
|
||
return <div className="nebula-expedition-planner">
|
||
<section className="nds-panel nebula-expedition-step" aria-labelledby="nebula-expedition-destinations-title">
|
||
{/* La Rose des vents se joue ici, à côté des destinations qu'elle remplace, tant que le joueur en a. */}
|
||
<div className="nebula-expedition-step-heading">
|
||
<h3 id="nebula-expedition-destinations-title">{content.destinationsTitle}</h3>
|
||
{view.enabled && view.items?.windRose > 0 && <button className="nds-button nebula-wind-rose-button" data-size="sm" data-variant="secondary" type="button" disabled={busy} onClick={onReroll}>
|
||
<img src={ITEM_ART.windRose} alt="" />{fillTemplate(content.useWindRose, { count: view.items.windRose })}
|
||
</button>}
|
||
</div>
|
||
{view.unlocked && view.unlocked.count < view.unlocked.total && <p className="nebula-form-help">{fillTemplate(content.unlockedDestinations, view.unlocked)}</p>}
|
||
<LootLegend content={content} />
|
||
<p className="nebula-form-help">{card ? fillTemplate(content.requirementsHelpCard, { card: editionEntry(catalog, card.editionId)?.card.name || "" }) : content.requirementsHelp}</p>
|
||
<div className="nebula-expedition-destinations">{destinations.map((item) => <DestinationOption key={item.id} catalog={catalog} item={item} selected={item.id === destination.id} card={card}
|
||
view={view} content={content} onSelect={() => setDestinationId(item.id)} />)}</div>
|
||
</section>
|
||
|
||
<section className="nds-panel nebula-expedition-step" aria-labelledby="nebula-expedition-team-title">
|
||
<h3 id="nebula-expedition-team-title">{content.teamTitle}</h3>
|
||
<p className="nebula-form-help">{content.teamHelp}</p>
|
||
<ExpeditionLoadout catalog={catalog} state={state} view={view} destination={destination} card={card} onChooseCard={setEditionId} content={content} busy={busy} runMutation={runMutation} />
|
||
</section>
|
||
|
||
<section className="nds-panel nebula-expedition-step" aria-labelledby="nebula-expedition-settings-title">
|
||
<h3 id="nebula-expedition-settings-title">{content.difficultyTitle}</h3>
|
||
<div className="nebula-expedition-choices">
|
||
{/* En local, une durée de test en plus (`view.testDuration`), aux règles de la plus courte. */}
|
||
<div role="group" aria-label={content.durationLabel} className="nds-toolbar">{[...view.durations, ...(view.testDuration ? [view.testDuration] : [])].map((value) => <button key={value} type="button" className="nds-button" data-size="sm" data-variant={value === hours ? "primary" : "secondary"} aria-pressed={value === hours} onClick={() => setHours(value)}>{value === view.testDuration ? content.testDuration : fillTemplate(content.hours, { hours: value })}</button>)}</div>
|
||
</div>
|
||
{!complete && <p className="nebula-form-help">{content.previewEmpty}</p>}
|
||
{shownPreview?.error && <p className="nds-inline-notice" data-variant="warning" role="status">{shownPreview.error}</p>}
|
||
{shownPreview?.value && <div className="nebula-preview-frame" data-stale={stale || undefined} aria-busy={stale}>
|
||
<Preview catalog={catalog} preview={shownPreview.value} content={content} hours={JSON.parse(preview.key).durationHours} tierLootPct={view.tierLootPct} />
|
||
</div>}
|
||
<div className="nebula-depart-choices">
|
||
<div className="nebula-depart-choice">
|
||
<h4>{content.departSoloTitle}</h4>
|
||
<p>{content.departSoloHelp}</p>
|
||
<button className="nds-button" data-variant="primary" type="button" disabled={busy || !complete} onClick={() => start(true)}>{content.departSolo}</button>
|
||
</div>
|
||
<div className="nebula-depart-choice">
|
||
<h4>{content.openGroupTitle}</h4>
|
||
<p>{fillTemplate(content.openGroupHelp, { loot: formatEclats(view.group.lootPct[0] / 100), max: formatEclats(view.group.lootPct.at(-1) / 100), hours: view.group.recruitHours })}</p>
|
||
<button className="nds-button" data-variant="secondary" type="button" disabled={busy || !complete} onClick={() => start(false)}>{content.openGroup}</button>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</div>;
|
||
}
|