sokko-g/website/src/features/cards/ExpeditionEquipmentSlots.jsx
Shinuwa ea5f5c9a51 Give the Primordials distinct weaknesses, emblems that build their specialty and constellations that guide their weakness
- Each Primordial has a 45 % specialty and its own 10 % weakness; its emblematic common raises its two strengths with the synergy on its specialty, and its constellation gives Orientation plus its weakness, without penalties.
- Commons declare the stat their synergy raises when stats tie and for power commons, so the bonus no longer falls on Bravoure by field order.
- Expertise is measured against the solo requirement, so it stays within reach when the group raises each place's requirement.
- Missing lore links become playable: the Dragon, Panda and Capybara own their emblems, Turtles and the Reindeer share an identity, and the Bat, the light-current Otters and the Aurora Wolf are recognised at their destinations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 22:23:43 +01:00

157 lines
12 KiB
JavaScript

// Rôle : équipement de la carte choisie pour une expédition. Ses trois emplacements en cartes `md`, nom visible (la commune posée
// avec une corbeille, un « + » pour un emplacement libre, la Puissance qui ouvre un emplacement fermé), et la fenêtre de choix des
// communes : elle reste ouverte, chaque clic pose ou retire une commune, celles déjà posées sur la carte sont en surbrillance.
// L'équipement reste sur la carte d'une expédition à l'autre.
import { useState } from "react";
import { Modal } from "../../components/Modal.jsx";
import { Tooltip } from "../../components/Tooltip.jsx";
import { equipCard } from "./cardsApi.js";
import { fillTemplate } from "./dailyShare.js";
import { editionEntry, powerDetails, powerText, STAT_IDS, tagColor, tagLabel } from "./expeditionFormat.js";
import { MaskIcon, StatValue } from "./ExpeditionLabels.jsx";
import { NebulaCard } from "./NebulaCard.jsx";
// Synergie d'une commune avec la carte : une icône de lien et l'étiquette partagée, dans sa couleur ; « Synergie · … » est dit aux
// lecteurs d'écran.
function SynergyBadge({ catalog, tag, tags, content }) {
return <span className="nds-badge nebula-synergy-badge" data-tag-color={tagColor(tags, tag)} aria-label={fillTemplate(content.equipmentSynergy, { tag: tagLabel(catalog, tag) })}>
<MaskIcon name="link" /><span aria-hidden="true">{tagLabel(catalog, tag)}</span>
</span>;
}
// Tris des communes : synergie avec la carte d'abord, la stat qu'elles apportent, ou les pouvoirs d'abord.
const EQUIPMENT_SORTS = ["synergy", ...STAT_IDS, "power"];
// Sans carte choisie : trois emplacements, inactifs.
const PLACEHOLDER_SLOTS = [0, 1, 2];
// Effet d'une commune, dans un petit encart : ses stats en icônes, signées, leur nom au survol ; ou son pouvoir, comme une ligne de
// stat (icône de fiole et nom en or, effet au survol), pour ne pas ressembler aux pastilles d'étiquette. Posée en synergie,
// le bonus de synergie suit la stat qu'il renforce, dans la couleur de l'étiquette partagée : « +8 (+2) ».
// Infobulle d'un pouvoir : sa description, puis ses effets chiffrés.
export function PowerTooltipContent({ power, values, content }) {
return <span className="nebula-tooltip-lines">
<span>{powerText(power, content)}</span>
{powerDetails(power, values, content).map((line) => <span key={line} className="nebula-power-detail">{line}</span>)}
</span>;
}
export function EquipmentStats({ item, content, color, powerValues }) {
// Une commune de pouvoir n'a pas de stats ; posée en synergie, son bonus va à la stat que le catalogue lui donne, et s'affiche sous le pouvoir.
if (item.power) return <span className="nebula-equipment-stats">
<Tooltip className="nebula-equipment-power" tooltipClassName="nebula-power-tooltip" content={<PowerTooltipContent power={item.power} values={powerValues} content={content} />}
aria-label={[`${content.powers[item.power]} : ${powerText(item.power, content)}`, ...powerDetails(item.power, powerValues, content)].join(" ; ")} tabIndex={-1}>
<MaskIcon name="power" /><span aria-hidden="true">{content.powers[item.power]}</span>
</Tooltip>
{item.synergyStat && item.synergyBonus > 0 && <Tooltip className="nebula-stat-value" content={content.stats[item.synergyStat]} aria-label={`${content.stats[item.synergyStat]} : +${item.synergyBonus}`} tabIndex={-1}>
<MaskIcon name={item.synergyStat} /><span className="nebula-synergy-bonus" data-tag-color={color} aria-hidden="true">{fillTemplate(content.synergyBonus, { value: item.synergyBonus })}</span>
</Tooltip>}
</span>;
return <span className="nebula-equipment-stats">{STAT_IDS.filter((stat) => item.stats?.[stat] || item.synergyStat === stat).map((stat) => <StatValue key={stat} stat={stat} value={item.stats?.[stat] || 0} label={content.stats[stat]} signed>
{item.synergyStat === stat && item.synergyBonus > 0 && <span className="nebula-synergy-bonus" data-tag-color={color}>{fillTemplate(content.synergyBonus, { value: item.synergyBonus })}</span>}
</StatValue>)}</span>;
}
// Les emplacements d'équipement ; sans carte choisie (`progress` absent), trois emplacements inactifs.
// `onEngrave` (avec au moins un Burin) : une commune posée ni gravée ni en synergie propose « Graver », qui ouvre l'atelier de
// gravure sur elle et sur la carte.
export function EquipmentSlots({ catalog, progress, content, busy, runMutation, onOpen, powerValues, onEngrave = null }) {
const remove = (slot) => runMutation(() => equipCard(progress.editionId, slot, null));
if (!progress) return <ul className="nebula-equipment-slots" aria-label={content.equipmentTitle}>{PLACEHOLDER_SLOTS.map((slot) => <li key={slot}>
<span className="nebula-equipment-slot" data-locked><span aria-hidden="true">+</span></span>
</li>)}</ul>;
return <ul className="nebula-equipment-slots" aria-label={content.equipmentTitle}>{progress.slotPowers.map((power, slot) => {
const item = progress.equipment.find((entry) => entry.slot === slot);
const entry = item && editionEntry(catalog, item.editionId);
if (slot >= progress.slots) return <li key={slot}><span className="nebula-equipment-slot" data-locked>{fillTemplate(content.equipmentLocked, { power })}</span></li>;
if (!entry) return <li key={slot}>
<button className="nebula-equipment-slot" type="button" disabled={busy} aria-label={fillTemplate(content.equipmentAdd, { slot: slot + 1 })} onClick={() => onOpen(slot)}><span aria-hidden="true">+</span></button>
</li>;
return <li key={slot}>
<span className="nebula-equipment-card">
<NebulaCard catalog={catalog} entry={entry} size="md" onSelect={() => onOpen(slot)} selectLabel={fillTemplate(content.equipmentReplace, { card: entry.card.name })} />
<button className="nds-icon-button nebula-equipment-remove" type="button" disabled={busy} aria-label={fillTemplate(content.equipmentRemove, { card: entry.card.name })} title={fillTemplate(content.equipmentRemove, { card: entry.card.name })} onClick={() => remove(slot)}>
<MaskIcon name="trash" />
</button>
</span>
<EquipmentStats item={item} content={content} powerValues={powerValues} color={tagColor(progress.tags, item.synergyTag)} />
{item.synergyTag && <SynergyBadge catalog={catalog} tag={item.synergyTag} tags={progress.tags} content={content} />}
{onEngrave && !item.synergyTag && !item.engraved && <button className="nds-button nebula-equipment-engrave" data-size="sm" data-variant="secondary" type="button" disabled={busy}
aria-label={fillTemplate(content.engraveButtonLabel, { card: entry.card.name })} onClick={() => onEngrave(item.editionId)}>
<MaskIcon name="tag" />{content.engraveButton}
</button>}
</li>;
})}</ul>;
}
// Fenêtre de choix des communes, ouverte depuis l'emplacement `slot`. Un clic sur une commune déjà posée sur la carte la retire ; sur
// une autre, il la pose sur l'emplacement ouvert s'il est libre, sinon sur le premier emplacement libre, sinon à la place de
// celle de l'emplacement ouvert. Une carte ne porte qu'un pouvoir : une seconde commune de pouvoir n'est pas posée, un message le
// dit. Un refus du serveur s'affiche aussi dans la fenêtre (le message de la page serait caché derrière).
export function EquipmentPicker({ catalog, state, progress, cardName, slot, content, busy, runMutation, onClose, powerValues }) {
const [sort, setSort] = useState("synergy");
const [error, setError] = useState("");
const nameOf = (cardId) => catalog.cards.find((card) => card.id === cardId)?.name || cardId;
const sharedTag = (item) => item.tags?.find((tag) => progress.tags.includes(tag)) ?? null;
const best = (item) => Math.max(0, ...Object.values(item.stats || {}));
const synergyFirst = (a, b) => Number(Boolean(sharedTag(b))) - Number(Boolean(sharedTag(a))) || best(b) - best(a);
const compare = sort === "synergy" ? synergyFirst
: sort === "power" ? (a, b) => Number(Boolean(b.power)) - Number(Boolean(a.power)) || synergyFirst(a, b)
: (a, b) => (b.stats?.[sort] || 0) - (a.stats?.[sort] || 0) || synergyFirst(a, b);
const placed = new Map(progress.equipment.map((item) => [item.editionId, item.slot]));
// Les communes déjà posées sur la carte en tête, puis dans l'ordre du tri.
const choices = [...(state.equipment || [])].sort((a, b) => Number(placed.has(b.editionId)) - Number(placed.has(a.editionId)) || compare(a, b));
const open = Array.from({ length: progress.slots }, (_, index) => index);
const free = open.filter((index) => !progress.equipment.some((item) => item.slot === index));
const powered = progress.equipment.find((item) => item.power);
const run = (target, editionId) => {
setError("");
return runMutation(async () => {
try {
return await equipCard(progress.editionId, target, editionId);
} catch (mutationError) {
setError(mutationError.message);
return null;
}
});
};
const toggle = (item) => {
if (placed.has(item.editionId)) return run(placed.get(item.editionId), null);
if (item.power && powered) {
setError(fillTemplate(content.equipmentPowerLimit, { power: content.powers[powered.power] }));
return null;
}
const target = free.includes(slot) ? slot : free[0] ?? slot;
return run(target, item.editionId);
};
return <Modal dialogClassName="confirm-modal nds-modal nebula-expedition-picker" labelledBy="nebula-equipment-picker-title" onRequestClose={onClose}>
<h2 id="nebula-equipment-picker-title">{fillTemplate(content.equipmentPickerTitle, { card: cardName })}</h2>
<p className="nebula-form-help" role="status">{fillTemplate(content.equipmentPickerHelp, { used: progress.equipment.length, open: progress.slots })}</p>
{error && <p className="nds-inline-notice" data-variant="warning" role="alert">{error}</p>}
<div className="nebula-expedition-sort" role="group" aria-label={content.sortLabel}>
<span className="nebula-form-help">{content.sortLabel}</span>
{EQUIPMENT_SORTS.map((id) => <button key={id} type="button" className="nds-button" data-size="sm" data-variant={id === sort ? "primary" : "secondary"} aria-pressed={id === sort} onClick={() => setSort(id)}>
{id === "synergy" ? content.sortSynergy : id === "power" ? content.sortPowers : <><MaskIcon name={id} />{content.stats[id]}</>}
</button>)}
</div>
{choices.length ? <ul className="nebula-equipment-choices-grid">{choices.map((item) => {
const choice = editionEntry(catalog, item.editionId);
if (!choice) return null;
const tag = sharedTag(item);
const here = placed.has(item.editionId);
const elsewhere = item.equippedOn && item.equippedOn !== progress.editionId;
return <li key={item.editionId} data-equipped={here || undefined}>
<Tooltip className="nebula-equipment-choice" content={choice.card.name} tabIndex={-1}>
<NebulaCard catalog={catalog} entry={choice} size="sm" selected={here} onSelect={busy ? undefined : () => toggle(item)}
selectLabel={fillTemplate(here ? content.equipmentRemove : content.equipmentPut, { card: choice.card.name })} />
</Tooltip>
<EquipmentStats item={item} content={content} powerValues={powerValues} color={tagColor(progress.tags, tag)} />
{tag && <SynergyBadge catalog={catalog} tag={tag} tags={progress.tags} content={content} />}
{here && <small className="nebula-equipment-here">{content.equipmentHere}</small>}
{elsewhere && <small className="nebula-form-help">{fillTemplate(content.equipmentElsewhere, { card: nameOf(catalog.editions.find((edition) => edition.id === item.equippedOn)?.cardId) })}</small>}
</li>;
})}</ul> : <p className="nebula-form-help">{content.equipmentNone}</p>}
<div className="nds-toolbar nebula-expedition-picker-actions">
<button className="nds-button" data-variant="primary" type="button" onClick={onClose}>{content.pickerDone}</button>
</div>
</Modal>;
}