Let players pick the duplicates that awaken a card, shown as cards
The awakening with duplicates of the collection used to take them automatically, without showing them. It now opens a picker like the Atelier: the needed slots at the top, the usable duplicates below as illustrated cards with their free copies, and nothing is used before "Éveiller". The server lists the candidates and checks the chosen copies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
055f8cf17b
commit
0533a8f766
10 changed files with 142 additions and 45 deletions
57
website/src/features/cards/AwakeningPicker.jsx
Normal file
57
website/src/features/cards/AwakeningPicker.jsx
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// 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.
|
||||
// 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) ; `onAwaken(editionIds)` renvoie le résultat de la mutation, null en cas d'échec.
|
||||
export function AwakeningPicker({ catalog, cardName, awakening, rarityLabel, collectionName, content, busy, onAwaken, onClose }) {
|
||||
const [chosen, setChosen] = useState([]);
|
||||
const { needed, candidates } = awakening;
|
||||
const plural = needed > 1 ? "s" : "";
|
||||
const used = (editionId) => chosen.filter((id) => id === editionId).length;
|
||||
const nameOf = (editionId) => editionEntry(catalog, editionId)?.card.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(content.awakenPickerHelp, { count: needed, s: plural, rarity: rarityLabel, 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>
|
||||
</li>;
|
||||
})}</ul> : <p className="nebula-form-help">{fillTemplate(content.awakenNoCandidates, { rarity: rarityLabel, 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>;
|
||||
}
|
||||
|
|
@ -6,9 +6,9 @@
|
|||
// `focus` (« plan ») ouvre « Amélioration » et fait défiler la fiche jusqu'à cette section, depuis un objet du Sac.
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Modal } from "../../components/Modal.jsx";
|
||||
import { ConfirmModal } from "../../components/ToolboxModals.jsx";
|
||||
import { Tabs } from "../../components/Tabs.jsx";
|
||||
import { recycleDuplicates, setFavorite, upgradeCard } from "./cardsApi.js";
|
||||
import { AwakeningPicker } from "./AwakeningPicker.jsx";
|
||||
import { CardPlan } from "./CardPlan.jsx";
|
||||
import { CurrencyAmount } from "./Currency.jsx";
|
||||
import { readCollection } from "./collectionState.js";
|
||||
|
|
@ -51,33 +51,27 @@ function CardSummary({ progress, preview, content }) {
|
|||
}
|
||||
|
||||
// Éveil d'une carte arrêtée devant un palier : un doublon d'elle-même (pour une mythique, sa version légendaire), ou des doublons de
|
||||
// sa collection et de sa rareté, montrés avant d'être consommés. L'Éveil ne coûte pas d'Éclats.
|
||||
// sa collection et de sa rareté, choisis dans une fenêtre comme à l'atelier. L'Éveil ne coûte pas d'Éclats.
|
||||
function CardAwakening({ catalog, progress, busy, runMutation, content }) {
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const [choosing, setChoosing] = useState(false);
|
||||
const { awakening } = progress;
|
||||
const editionOf = (id) => catalog.editions.find((edition) => edition.id === id);
|
||||
const cardName = (id) => catalog.cards.find((card) => card.id === editionOf(id)?.cardId)?.name ?? id;
|
||||
const own = editionOf(progress.editionId);
|
||||
const own = catalog.editions.find((edition) => edition.id === progress.editionId);
|
||||
const card = catalog.cards.find((item) => item.id === own?.cardId);
|
||||
const rarityLabel = (id) => catalog.rarities.find((item) => item.id === id)?.label ?? id;
|
||||
const accepted = own?.rarity === "mythic" ? `${rarityLabel("legendary")} ou ${rarityLabel("mythic")}` : rarityLabel(own?.rarity);
|
||||
const collectionName = catalog.collections.find((item) => item.id === catalog.cards.find((card) => card.id === own?.cardId)?.collectionId)?.name ?? "";
|
||||
const collectionName = catalog.collections.find((item) => item.id === card?.collectionId)?.name ?? "";
|
||||
const exactIsOther = awakening.exact && awakening.exact !== progress.editionId;
|
||||
const plural = awakening.needed > 1 ? "s" : "";
|
||||
const used = awakening.picks.map((item) => `${cardName(item.editionId)}${item.count > 1 ? ` ×${item.count}` : ""}`).join(", ");
|
||||
return <section className="nebula-card-upgrade nebula-card-awakening" aria-labelledby="nebula-card-awakening-title">
|
||||
<h3 id="nebula-card-awakening-title">{fillTemplate(content.awakeningTitle, { power: awakening.power })}</h3>
|
||||
<p className="nebula-form-help">{content.awakeningText}</p>
|
||||
<div className="nds-toolbar">
|
||||
<button className="nds-button" data-variant="primary" type="button" disabled={busy || !awakening.exact} onClick={() => runMutation(() => upgradeCard(progress.editionId, "duplicate"))}>{exactIsOther ? content.awakenLegendary : content.awakenExact}</button>
|
||||
<button className="nds-button" data-variant="secondary" type="button" disabled={busy || !awakening.picks.length} onClick={() => setConfirming(true)}>{fillTemplate(content.awakenPool, { count: awakening.needed, s: plural, rarity: accepted })}</button>
|
||||
<button className="nds-button" data-variant="secondary" type="button" disabled={busy} onClick={() => setChoosing(true)}>{fillTemplate(content.awakenChoose, { count: awakening.needed, s: plural })}</button>
|
||||
</div>
|
||||
<p className="nebula-form-help">{fillTemplate(content.awakenPoolCount, { available: Math.min(awakening.available, awakening.needed), count: awakening.needed, s: plural, rarity: accepted, collection: collectionName })}</p>
|
||||
{confirming && <ConfirmModal
|
||||
title={content.awakenConfirmTitle}
|
||||
message={fillTemplate(content.awakenConfirmText, { cards: used })}
|
||||
confirmLabel={content.awakenConfirm}
|
||||
onClose={(confirmed) => { setConfirming(false); if (confirmed) void runMutation(() => upgradeCard(progress.editionId, "awaken")); }}
|
||||
/>}
|
||||
{choosing && <AwakeningPicker catalog={catalog} cardName={card?.name ?? ""} awakening={awakening} rarityLabel={accepted} collectionName={collectionName} content={content} busy={busy}
|
||||
onAwaken={(editionIds) => runMutation(() => upgradeCard(progress.editionId, "awaken", editionIds))} onClose={() => setChoosing(false)} />}
|
||||
</section>;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -219,9 +219,10 @@ export function departExpedition(expeditionId) {
|
|||
return request(`/expeditions/${encodeURIComponent(expeditionId)}/depart`, { method: "POST" });
|
||||
}
|
||||
|
||||
// Améliore une carte d'un niveau : `method` vaut « eclats » ou « duplicate » (un doublon de la même édition).
|
||||
export function upgradeCard(editionId, method) {
|
||||
return request("/progress/upgrade", { method: "POST", body: JSON.stringify({ editionId, method }) });
|
||||
// Améliore une carte d'un niveau : `method` vaut « eclats », « duplicate » (un doublon de la même carte) ou « awaken » (Éveil avec
|
||||
// les doublons de sa collection choisis dans `editionIds`, une entrée par exemplaire).
|
||||
export function upgradeCard(editionId, method, editionIds = null) {
|
||||
return request("/progress/upgrade", { method: "POST", body: JSON.stringify({ editionId, method, ...(editionIds ? { editionIds } : {}) }) });
|
||||
}
|
||||
|
||||
// Plan de progression d'une carte : « collection », une vocation (leader, guardian, seeker, navigator) ou « free » avec ses points placés.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue