- Every catalog card carries expedition tags and every collection a stat profile, validated at load; twelve destinations live server-side so hidden ones stay secret. - Pure rules compute card power, per-slot requirements, roles, dangers, the long-trip malus, the score (one more star never raises it) and loot proportional to the chosen duration. - A simulator script and a balance test guard the design thresholds; agent docs and a new-card skill explain how to tag new cards. - Migration 8 adds Éclats d'étoile, expedition settings stored as one validated JSON, daily destinations, expeditions, members and slots, and rebuilds gift_packs so a pack can come from an expedition. - Players launch a solo expedition from the Guild, see an exact preview, and claim their loot when it returns; the card sheet shows cards away on an expedition. - Administration › Guilde tunes every value with server-side bounds, toggles destinations and cancels running expeditions; expeditions stay closed until an administrator opens them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
10 KiB
JavaScript
128 lines
10 KiB
JavaScript
// Rôle : règle les Expéditions depuis Administration › Guilde : un panneau par groupe de réglages, les destinations, et le suivi du jour.
|
||
import { useState } from "react";
|
||
import { ConfirmModal } from "../../../components/ToolboxModals.jsx";
|
||
import { cancelExpedition, updateExpeditionSettings } from "../cardsApi.js";
|
||
import { DATE_FORMATTER } from "./adminFormat.js";
|
||
import { ApplyActions } from "./adminSettingForm.jsx";
|
||
import { inRange, parse } from "./adminSettings.js";
|
||
import { EXPEDITION_SETTING_GROUPS } from "./expeditionSettingFields.js";
|
||
|
||
const readPath = (source, path) => path.split(".").reduce((value, key) => value?.[key], source);
|
||
|
||
function writePath(target, path, value) {
|
||
const keys = path.split(".");
|
||
keys.slice(0, -1).reduce((node, key) => node[key], target)[keys.at(-1)] = value;
|
||
}
|
||
|
||
const toDraft = (value) => (typeof value === "boolean" ? value : Array.isArray(value) ? value.map(String) : String(value));
|
||
const fromDraft = (value) => (typeof value === "boolean" ? value : Array.isArray(value) ? value.map(parse) : parse(value));
|
||
const validValue = (field, value) => (field.kind === "bool" ? typeof value === "boolean" : (Array.isArray(value) ? value : [value]).every((item) => inRange(item, field.min, field.max)));
|
||
|
||
// Un panneau : brouillon de ses réglages, vérifiés avec les bornes du serveur ; les contraintes entre réglages sont vérifiées par le serveur.
|
||
function SettingsGroup({ group, settings, schema, busy, save }) {
|
||
const fields = group.fields.map((field) => ({ ...field, ...schema.find((item) => item.path === field.path) }));
|
||
const initial = () => Object.fromEntries(fields.map((field) => [field.path, toDraft(readPath(settings, field.path))]));
|
||
const [draft, setDraft] = useState(initial);
|
||
const values = Object.fromEntries(fields.map((field) => [field.path, fromDraft(draft[field.path])]));
|
||
const invalid = fields.filter((field) => !validValue(field, values[field.path]));
|
||
const changed = !invalid.length && fields.some((field) => JSON.stringify(values[field.path]) !== JSON.stringify(readPath(settings, field.path)));
|
||
const set = (path, value) => setDraft((current) => ({ ...current, [path]: value }));
|
||
return <section className="nds-panel nebula-admin-shop nebula-admin-expedition-group" aria-labelledby={`nebula-admin-expedition-${group.id}`}>
|
||
<div className="nds-section-heading nebula-admin-panel-heading"><h3 id={`nebula-admin-expedition-${group.id}`}>{group.title}</h3></div>
|
||
<p className="nebula-form-help">{group.help}</p>
|
||
<div className="nebula-admin-expedition-fields">{fields.map((field) => {
|
||
const value = draft[field.path];
|
||
if (field.kind === "bool") return <div key={field.path} className="nebula-admin-expedition-field">
|
||
<span>{field.label}</span>
|
||
<button className="nds-button" data-size="sm" data-variant={value ? "primary" : "secondary"} type="button" aria-pressed={value} aria-label={field.label} disabled={busy} onClick={() => set(field.path, !value)}>{value ? "Oui" : "Non"}</button>
|
||
</div>;
|
||
if (Array.isArray(value)) return <fieldset key={field.path} className="nebula-admin-expedition-field">
|
||
<legend>{field.label}</legend>
|
||
<div className="nebula-admin-expedition-items">{value.map((item, index) => <label key={index}><span>{field.items?.[index] ?? index + 1}</span>
|
||
<input className="nds-input" type="number" inputMode="numeric" min={field.min} max={field.max} step="1" value={item} disabled={busy} onChange={(event) => set(field.path, value.map((current, position) => (position === index ? event.target.value : current)))} />
|
||
</label>)}</div>
|
||
</fieldset>;
|
||
return <label key={field.path} className="nebula-admin-expedition-field"><span>{field.label}</span>
|
||
<input className="nds-input" type="number" inputMode="numeric" min={field.min} max={field.max} step="1" value={value} disabled={busy} onChange={(event) => set(field.path, event.target.value)} />
|
||
</label>;
|
||
})}</div>
|
||
{invalid.length > 0 && <p className="nebula-form-help" role="alert">{invalid.map((field) => `${field.label} : entier de ${field.min.toLocaleString("fr-FR")} à ${field.max.toLocaleString("fr-FR")}`).join(" · ")}</p>}
|
||
<ApplyActions
|
||
busy={busy}
|
||
changed={changed}
|
||
onCancel={() => setDraft(initial())}
|
||
onApply={() => save((next) => fields.forEach((field) => writePath(next, field.path, values[field.path])))}
|
||
confirmTitle={`Appliquer les réglages « ${group.title} » ?`}
|
||
confirmMessage="Les nouveaux réglages s’appliquent aux prochains départs. Les expéditions en route gardent ceux de leur départ."
|
||
/>
|
||
</section>;
|
||
}
|
||
|
||
// Destinations : proposées ou non, et poids dans le tirage du jour. Leurs textes vivent dans le fichier du serveur.
|
||
function DestinationSettings({ settings, destinations, busy, save }) {
|
||
const initial = () => Object.fromEntries(destinations.map((destination) => [destination.id, { active: settings.destinations[destination.id].active, weight: String(settings.destinations[destination.id].weight) }]));
|
||
const [draft, setDraft] = useState(initial);
|
||
const invalid = destinations.filter((destination) => !inRange(parse(draft[destination.id].weight), 0, 100));
|
||
const changed = !invalid.length && destinations.some((destination) => draft[destination.id].active !== settings.destinations[destination.id].active || parse(draft[destination.id].weight) !== settings.destinations[destination.id].weight);
|
||
const set = (id, changes) => setDraft((current) => ({ ...current, [id]: { ...current[id], ...changes } }));
|
||
return <section className="nds-panel nebula-admin-shop nebula-admin-expedition-group" aria-labelledby="nebula-admin-expedition-destinations">
|
||
<div className="nds-section-heading nebula-admin-panel-heading"><h3 id="nebula-admin-expedition-destinations">Destinations</h3></div>
|
||
<p className="nebula-form-help">Une destination retirée n’est plus tirée ; le poids règle sa fréquence parmi les destinations proposées. Les destinations cachées ne sont jamais tirées.</p>
|
||
<ul className="nebula-admin-expedition-destinations">{destinations.map((destination) => <li key={destination.id} className="nds-list-row">
|
||
<strong>{destination.name}{destination.hidden && <span className="nds-badge" data-variant="neutral">Cachée</span>}</strong>
|
||
<button className="nds-button" data-size="sm" data-variant={draft[destination.id].active ? "primary" : "secondary"} type="button" aria-pressed={draft[destination.id].active} aria-label={`${destination.name} proposée`} disabled={busy} onClick={() => set(destination.id, { active: !draft[destination.id].active })}>{draft[destination.id].active ? "Proposée" : "Retirée"}</button>
|
||
<label><span>Poids</span><input className="nds-input" type="number" inputMode="numeric" min="0" max="100" step="1" value={draft[destination.id].weight} disabled={busy} aria-label={`Poids de ${destination.name}`} onChange={(event) => set(destination.id, { weight: event.target.value })} /></label>
|
||
</li>)}</ul>
|
||
{invalid.length > 0 && <p className="nebula-form-help" role="alert">Poids : entier de 0 à 100.</p>}
|
||
<ApplyActions
|
||
busy={busy}
|
||
changed={changed}
|
||
onCancel={() => setDraft(initial())}
|
||
onApply={() => save((next) => destinations.forEach((destination) => { next.destinations[destination.id] = { active: draft[destination.id].active, weight: parse(draft[destination.id].weight) }; }))}
|
||
confirmTitle="Appliquer les destinations ?"
|
||
confirmMessage="Le changement vaut pour les prochains tirages : les destinations déjà proposées aujourd’hui restent jusqu’à minuit."
|
||
/>
|
||
</section>;
|
||
}
|
||
|
||
function ExpeditionsToday({ today, destinations, busy, onCancel }) {
|
||
const [cancelling, setCancelling] = useState(null);
|
||
const name = (id) => destinations.find((destination) => destination.id === id)?.name || id;
|
||
return <section className="nds-panel nebula-admin-shop nebula-admin-expedition-group" aria-labelledby="nebula-admin-expedition-today">
|
||
<div className="nds-section-heading nebula-admin-panel-heading"><h3 id="nebula-admin-expedition-today">Aujourd’hui</h3></div>
|
||
<p className="nebula-admin-guild-today"><strong>{today.launches}</strong> départ{today.launches > 1 ? "s" : ""} · <strong>{today.running}</strong> en route · <strong>{today.returnedUnclaimed}</strong> butin{today.returnedUnclaimed > 1 ? "s" : ""} à récupérer.</p>
|
||
{today.runningList.length > 0 && <ul className="nebula-admin-expedition-destinations">{today.runningList.map((expedition) => <li key={expedition.id} className="nds-list-row">
|
||
<strong>{name(expedition.destinationId)} · {"★".repeat(expedition.stars)}</strong>
|
||
<span>{expedition.creatorName} · retour le {DATE_FORMATTER.format(expedition.returnsAt)}</span>
|
||
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" disabled={busy} onClick={() => setCancelling(expedition)}>Annuler</button>
|
||
</li>)}</ul>}
|
||
{cancelling && <ConfirmModal
|
||
title="Annuler cette expédition ?"
|
||
message={`L’expédition vers ${name(cancelling.destinationId)} de ${cancelling.creatorName} s’arrête : les cartes sont libérées, sans butin.`}
|
||
confirmLabel="Annuler l’expédition"
|
||
onClose={async (confirmed) => {
|
||
const target = cancelling;
|
||
setCancelling(null);
|
||
if (confirmed) await onCancel(target.id);
|
||
}}
|
||
/>}
|
||
</section>;
|
||
}
|
||
|
||
export function ExpeditionSettings({ dashboard, busy, runMutation, refreshDashboard }) {
|
||
const { settings, schema, destinations, updatedAt } = dashboard.expeditionSettings;
|
||
const save = async (apply) => {
|
||
const next = structuredClone(settings);
|
||
apply(next);
|
||
if (await runMutation(() => updateExpeditionSettings(next))) await refreshDashboard();
|
||
};
|
||
const cancel = async (id) => {
|
||
if (await runMutation(() => cancelExpedition(id))) await refreshDashboard();
|
||
};
|
||
return <div className="nebula-admin-expeditions" aria-labelledby="nebula-admin-expeditions-title">
|
||
<h2 id="nebula-admin-expeditions-title">Expéditions</h2>
|
||
<ExpeditionsToday today={dashboard.expeditionsToday} destinations={destinations} busy={busy} onCancel={cancel} />
|
||
{EXPEDITION_SETTING_GROUPS.map((group) => <SettingsGroup key={`${group.id}-${updatedAt}`} group={group} settings={settings} schema={schema} busy={busy} save={save} />)}
|
||
<DestinationSettings key={`destinations-${updatedAt}`} settings={settings} destinations={destinations} busy={busy} save={save} />
|
||
</div>;
|
||
}
|