sokko-g/website/src/features/cards/AwakeningPicker.jsx
Shinuwa 048d9a0c91 Let closed-collection cards awaken with duplicates from any collection
A closed collection no longer sells packs, so its legendaries could
barely awaken. Its cards now accept substitute duplicates of their
rarity from any collection, at the same 6/2/1 count. The Watchers'
Logbooks never count as closed. The awakening sheet and picker say so,
and a daily tip and the balance guide explain the rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 12:29:43 +01:00

61 lines
4.6 KiB
JavaScript

// Rôle : choix des doublons d'un Éveil de substitution, en fenêtre, comme l'atelier : le joueur pose dans sa sélection autant de
// doublons de la collection et de la rareté de la carte qu'il en faut (cartes illustrées, doublons libres en pastille), puis éveille.
// Collection fermée (`awakening.anyCollection`) : les doublons viennent de toute collection, chacun avec le nom de la sienne.
// Rien n'est consommé avant « Éveiller » ; « Annuler » ferme sans rien utiliser.
import { useState } from "react";
import { Modal } from "../../components/Modal.jsx";
import { fillTemplate } from "./dailyShare.js";
import { editionEntry } from "./expeditionFormat.js";
import { NebulaCard } from "./NebulaCard.jsx";
// `awakening` : vue du serveur (needed, candidates) ; `rarityWords(count)` : les raretés acceptées accordées (« rares »,
// « légendaire ou mythique ») ; `onAwaken(editionIds)` renvoie le résultat de la mutation, null en cas d'échec.
export function AwakeningPicker({ catalog, cardName, awakening, rarityWords, collectionName, content, busy, onAwaken, onClose }) {
const [chosen, setChosen] = useState([]);
const { needed, candidates, anyCollection } = awakening;
const plural = needed > 1 ? "s" : "";
const used = (editionId) => chosen.filter((id) => id === editionId).length;
const nameOf = (editionId) => editionEntry(catalog, editionId)?.card.name || "";
const collectionOf = (card) => catalog.collections.find((item) => item.id === card.collectionId)?.name ?? "";
const add = (entry) => {
if (chosen.length < needed && used(entry.editionId) < entry.spare) setChosen([...chosen, entry.editionId]);
};
const awaken = async () => {
if (await onAwaken(chosen)) onClose();
};
return <Modal dialogClassName="confirm-modal nds-modal nebula-expedition-picker nebula-atelier nebula-awakening-picker" labelledBy="nebula-awakening-picker-title" onRequestClose={onClose} canClose={!busy}>
<h2 id="nebula-awakening-picker-title">{fillTemplate(content.awakenPickerTitle, { card: cardName, power: awakening.power })}</h2>
<p className="nebula-form-help">{fillTemplate(anyCollection ? content.awakenPickerHelpAny : content.awakenPickerHelp, { count: needed, s: plural, rarity: rarityWords(needed), collection: collectionName })}</p>
{/* Sélection : une place par doublon demandé ; une carte posée se retire d'un clic. */}
<section className="nebula-atelier-selection" aria-labelledby="nebula-awakening-selection-title">
<h3 id="nebula-awakening-selection-title">{fillTemplate(content.awakenSelection, { count: chosen.length, needed })}</h3>
<ol>{Array.from({ length: needed }, (_, index) => {
const editionId = chosen[index];
const entry = editionId && editionEntry(catalog, editionId);
return <li key={index} data-empty={!entry || undefined}>
{entry ? <NebulaCard catalog={catalog} entry={entry} size="sm" onSelect={busy ? undefined : () => setChosen(chosen.filter((_, position) => position !== index))}
selectLabel={fillTemplate(content.awakenRemove, { card: entry.card.name })} /> : <span aria-hidden="true" />}
</li>;
})}</ol>
</section>
{candidates.length ? <ul className="nebula-equipment-choices-grid" aria-label={content.awakenCandidates}>{candidates.map((entry) => {
const card = editionEntry(catalog, entry.editionId);
if (!card) return null;
const left = entry.spare - used(entry.editionId);
const full = chosen.length >= needed || left <= 0;
return <li key={entry.editionId} data-equipped={used(entry.editionId) > 0 || undefined} data-unavailable={(full && !used(entry.editionId)) || undefined}>
<span className="nebula-equipment-choice">
<NebulaCard catalog={catalog} entry={card} size="sm" quantity={left} disabled={busy || full} onSelect={() => add(entry)}
selectLabel={fillTemplate(content.awakenAdd, { card: nameOf(entry.editionId) })} />
</span>
<strong>{card.card.name}</strong>
{anyCollection && <small>{collectionOf(card.card)}</small>}
</li>;
})}</ul> : <p className="nebula-form-help">{fillTemplate(anyCollection ? content.awakenNoCandidatesAny : content.awakenNoCandidates, { rarity: rarityWords(1), collection: collectionName })}</p>}
<div className="nds-toolbar nebula-expedition-picker-actions">
<button className="nds-button" data-variant="secondary" type="button" disabled={busy} onClick={onClose}>{content.awakenCancel}</button>
<button className="nds-button" data-variant="primary" type="button" disabled={busy || chosen.length !== needed} onClick={awaken}>{content.awakenConfirm}</button>
</div>
</Modal>;
}