Add ARCHITECTURE.md (layers, flows, folder map, glossary), CONTRIBUTING.md (setup and step-by-step recipes) and a README in each main folder, with an index of docs/. Convert the 511 JavaScript headers from "// Rôle :" lines to JSDoc @file blocks, define a three-level header template in website/AGENTS.md and check the header in tests/file-headers.test.mjs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
5.9 KiB
JavaScript
98 lines
5.9 KiB
JavaScript
/**
|
|
* @file Atelier du Plan d'atelier, en fenêtre. Le joueur pose 3 doublons de communes (en cartes illustrées)
|
|
* dans sa sélection, avec leurs doublons libres en pastille sur la carte, puis fabrique : le plan et
|
|
* les doublons ne sont consommés qu'à ce moment, et « Annuler » ferme sans rien utiliser. Une fois
|
|
* fabriquée, la commune de pouvoir obtenue s'affiche à la place du choix, avec sa description, son
|
|
* pouvoir et ses effets chiffrés.
|
|
*/
|
|
|
|
import { useState } from "react";
|
|
import { Modal } from "../../components/Modal.jsx";
|
|
import { fillTemplate } from "./dailyShare.js";
|
|
import { MaskIcon } from "./ExpeditionLabels.jsx";
|
|
import { editionEntry, powerText } from "./expeditionFormat.js";
|
|
import { PowerEffects } from "./ExpeditionOutcome.jsx";
|
|
import { NebulaCard } from "./NebulaCard.jsx";
|
|
|
|
const RECIPE_SIZE = 3;
|
|
|
|
// Commune obtenue : la carte, puis son nom, sa description, son pouvoir, ce qu'il fait et ses effets chiffrés (`powerValues`).
|
|
function CraftedCard({ catalog, entry, content, powerValues }) {
|
|
const power = entry.card.expedition?.equipment?.power;
|
|
return <div className="nebula-atelier-result">
|
|
<NebulaCard catalog={catalog} entry={entry} size="md" />
|
|
<div className="nebula-atelier-result-text">
|
|
<h3>{entry.card.name}</h3>
|
|
{entry.card.description && <p className="nebula-atelier-description">{entry.card.description}</p>}
|
|
{power && <section className="nebula-atelier-power" aria-label={content.atelierPower}>
|
|
<h4><MaskIcon name="power" />{content.powers[power] || power}</h4>
|
|
<p>{powerText(power, content)}</p>
|
|
<PowerEffects power={power} values={powerValues} content={content} />
|
|
</section>}
|
|
</div>
|
|
</div>;
|
|
}
|
|
|
|
export function ExpeditionAtelier({ catalog, state, content, busy, powerValues, onCraft, onClose }) {
|
|
const [chosen, setChosen] = useState([]);
|
|
const [crafted, setCrafted] = useState(null);
|
|
const [error, setError] = useState("");
|
|
// Les communes qui ont le plus de doublons libres d'abord, puis par nom.
|
|
const commons = state.collection.filter((entry) => entry.spare > 0 && entry.edition?.rarity === "common")
|
|
.sort((a, b) => b.spare - a.spare || (editionEntry(catalog, a.editionId)?.card.name || "").localeCompare(editionEntry(catalog, b.editionId)?.card.name || "", "fr"));
|
|
const used = (editionId) => chosen.filter((id) => id === editionId).length;
|
|
const nameOf = (editionId) => editionEntry(catalog, editionId)?.card.name || "";
|
|
const add = (entry) => {
|
|
if (chosen.length < RECIPE_SIZE && used(entry.editionId) < entry.spare) setChosen([...chosen, entry.editionId]);
|
|
};
|
|
const craft = async () => {
|
|
setError("");
|
|
const result = await onCraft(chosen);
|
|
if (result?.crafted) setCrafted(result.crafted);
|
|
else setError(result?.error || "");
|
|
};
|
|
const result = crafted && editionEntry(catalog, crafted);
|
|
|
|
return <Modal dialogClassName="confirm-modal nds-modal nebula-expedition-picker nebula-atelier" labelledBy="nebula-atelier-title" onRequestClose={onClose} canClose={!busy}>
|
|
<h2 id="nebula-atelier-title">{content.atelierTitle}</h2>
|
|
{result ? <>
|
|
<p className="nebula-form-help" role="status">{fillTemplate(content.crafted, { card: result.card.name })}</p>
|
|
<CraftedCard catalog={catalog} entry={result} content={content} powerValues={powerValues} />
|
|
<div className="nds-toolbar nebula-expedition-picker-actions">
|
|
<button className="nds-button" data-variant="primary" type="button" onClick={onClose}>{content.atelierClose}</button>
|
|
</div>
|
|
</> : <>
|
|
<p className="nebula-form-help">{content.atelierHelp}</p>
|
|
{error && <p className="nds-inline-notice" data-variant="warning" role="alert">{error}</p>}
|
|
{/* Sélection : trois places ; une carte posée se retire d'un clic. */}
|
|
<section className="nebula-atelier-selection" aria-labelledby="nebula-atelier-selection-title">
|
|
<h3 id="nebula-atelier-selection-title">{fillTemplate(content.atelierSelection, { count: chosen.length })}</h3>
|
|
<ol>{Array.from({ length: RECIPE_SIZE }, (_, 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.atelierRemove, { card: entry.card.name })} /> : <span aria-hidden="true" />}
|
|
</li>;
|
|
})}</ol>
|
|
</section>
|
|
{commons.length ? <ul className="nebula-equipment-choices-grid" aria-label={content.atelierCommons}>{commons.map((entry) => {
|
|
const card = editionEntry(catalog, entry.editionId);
|
|
if (!card) return null;
|
|
const left = entry.spare - used(entry.editionId);
|
|
const full = chosen.length >= RECIPE_SIZE || 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.atelierAdd, { card: nameOf(entry.editionId) })} />
|
|
</span>
|
|
<strong>{card.card.name}</strong>
|
|
</li>;
|
|
})}</ul> : <p className="nebula-form-help">{content.atelierNoCommons}</p>}
|
|
<div className="nds-toolbar nebula-expedition-picker-actions">
|
|
<button className="nds-button" data-variant="secondary" type="button" disabled={busy} onClick={onClose}>{content.atelierCancel}</button>
|
|
<button className="nds-button" data-variant="primary" type="button" disabled={busy || chosen.length !== RECIPE_SIZE} onClick={craft}>{content.atelierAction}</button>
|
|
</div>
|
|
</>}
|
|
</Modal>;
|
|
}
|