- The expeditions page rereads its view on its own: every 10 seconds while a group is shown, every 20 seconds otherwise, on tab return and at the next recruitment deadline; late responses no longer overwrite a newer action. A failed load offers "Réessayer" and a failed refresh keeps the last view. - The periodic alert pass first departs groups whose recruitment ended, so their return is announced even if nobody visits the site. - Queued alerts are checked again at sending time: a player who opted out or alerts switched off by the administration drop the message for good. - The engraving confirmation sticks to the bottom of its window, the workshop lists commons by spare count, the guild expeditions card shows the Great Void, and stale help texts and comments are fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
92 lines
5.9 KiB
JavaScript
92 lines
5.9 KiB
JavaScript
// Rôle : 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, POWER_TEXT, powerDetails } from "./expeditionFormat.js";
|
|
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>{POWER_TEXT[power]}</p>
|
|
{powerDetails(power, powerValues).length > 0 && <ul>{powerDetails(power, powerValues).map((line) => <li key={line}>{line}</li>)}</ul>}
|
|
</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>;
|
|
}
|