Add the daily team administration, recruitment retouches, the Watchers' balm and a new Guild layout
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7ed63fff49
commit
b179a40a04
36 changed files with 799 additions and 298 deletions
|
|
@ -1,9 +1,10 @@
|
|||
// Rôle : règle les quêtes de la Guilde des Veilleurs, une par onglet (Carte du jour, Expéditions), chacun avec son adresse.
|
||||
// Rôle : règle les quêtes de la Guilde des Veilleurs, une par onglet (Carte du jour, Équipe du jour, Expéditions), chacun avec son adresse.
|
||||
import { useState } from "react";
|
||||
import { Tabs } from "../../../components/Tabs.jsx";
|
||||
import { ApplyActions } from "./adminSettingForm.jsx";
|
||||
import { inRange, MAX_VALUE, parse, shopSettingSaver } from "./adminSettings.js";
|
||||
import { ExpeditionSettings } from "./ExpeditionSettings.jsx";
|
||||
import { TeamSettings } from "./TeamSettings.jsx";
|
||||
|
||||
// Carte du jour : la partie du jour (joueurs et gagnants), puis la récompense d'une victoire.
|
||||
function DailyQuestSettings({ setting, daily, busy, save }) {
|
||||
|
|
@ -29,7 +30,7 @@ function DailyQuestSettings({ setting, daily, busy, save }) {
|
|||
}
|
||||
|
||||
// Onglets de la Guilde : l'adresse #/cards/admin/guild/<onglet> garde l'onglet ouvert ; sans onglet, la Carte du jour.
|
||||
const GUILD_TABS = [{ id: "daily", label: "Carte du jour" }, { id: "expeditions", label: "Expéditions" }];
|
||||
const GUILD_TABS = [{ id: "daily", label: "Carte du jour" }, { id: "team", label: "Équipe du jour" }, { id: "expeditions", label: "Expéditions" }];
|
||||
|
||||
export function AdminGuild({ dashboard, busy, runMutation, refreshDashboard, tab = "" }) {
|
||||
const setting = dashboard?.shopSetting;
|
||||
|
|
@ -40,6 +41,7 @@ export function AdminGuild({ dashboard, busy, runMutation, refreshDashboard, tab
|
|||
{setting
|
||||
? <>
|
||||
{activeTab === "daily" && <DailyQuestSettings key={setting.dailyReward} setting={setting} daily={dashboard.daily} busy={busy} save={save} />}
|
||||
{activeTab === "team" && dashboard.teamSettings && <TeamSettings dashboard={dashboard} busy={busy} runMutation={runMutation} refreshDashboard={refreshDashboard} />}
|
||||
{activeTab === "expeditions" && dashboard.expeditionSettings && <ExpeditionSettings dashboard={dashboard} busy={busy} runMutation={runMutation} refreshDashboard={refreshDashboard} />}
|
||||
</>
|
||||
: <div className="nds-empty-state" aria-busy="true"><p>Chargement des quêtes…</p></div>}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import { loadAdminHistory } from "../cardsApi.js";
|
|||
import { summarizeReward } from "../rewardText.js";
|
||||
import { DATE_FORMATTER, formatDuration } from "./adminFormat.js";
|
||||
import { expeditionSettingLabel, formatSettingValue } from "./expeditionSettingFields.js";
|
||||
import { readPath } from "./settingsDraft.js";
|
||||
import { formatTeamSetting, TEAM_SETTING_PATHS, teamSettingLabel } from "./teamSettingFields.js";
|
||||
|
||||
const EVENT_LABELS = {
|
||||
recharge_updated: "Recharge modifiée",
|
||||
|
|
@ -21,7 +23,8 @@ const EVENT_LABELS = {
|
|||
campaign_extended: "Campagne prolongée",
|
||||
account_deleted: "Compte joueur supprimé",
|
||||
expedition_settings_updated: "Expéditions modifiées",
|
||||
expedition_cancelled: "Expédition annulée"
|
||||
expedition_cancelled: "Expédition annulée",
|
||||
team_settings_updated: "Équipe du jour modifiée"
|
||||
};
|
||||
|
||||
const collectionName = (entry, catalog) => catalog.collections.find((item) => item.id === entry.entityId)?.name || entry.entityId;
|
||||
|
|
@ -97,6 +100,7 @@ function eventDetail(entry, catalog) {
|
|||
case "campaign_extended": return `${campaignName || entry.entityId} · ${details.expiresAt == null ? "sans expiration" : `jusqu’au ${DATE_FORMATTER.format(details.expiresAt)}`}`;
|
||||
case "campaign_revoked": return campaignName || entry.entityId;
|
||||
case "expedition_settings_updated": return (details.changes || []).map((item) => change(expeditionSettingLabel(item.path), formatSettingValue(item.previous), formatSettingValue(item.next))).filter(Boolean).join(" · ");
|
||||
case "team_settings_updated": return TEAM_SETTING_PATHS.map((path) => change(teamSettingLabel(path), formatTeamSetting(readPath(details.previous, path)), formatTeamSetting(readPath(details.next, path)))).filter(Boolean).join(" · ");
|
||||
case "expedition_cancelled": return details.destinationId;
|
||||
default: return "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,25 +5,12 @@ import { Tabs } from "../../../components/Tabs.jsx";
|
|||
import { ConfirmModal } from "../../../components/ToolboxModals.jsx";
|
||||
import { cancelExpedition, updateExpeditionSettings } from "../cardsApi.js";
|
||||
import { DATE_FORMATTER } from "./adminFormat.js";
|
||||
import { inRange, parse } from "./adminSettings.js";
|
||||
import { EXPEDITION_OPEN_PATH, EXPEDITION_SETTING_GROUPS, EXPEDITION_SETTING_THEMES, expeditionSettingLabel, formatSettingValue } from "./expeditionSettingFields.js";
|
||||
import { ApplyBar, DefaultHint, NumberInput, SettingsGroup } from "./SettingFields.jsx";
|
||||
import { readPath, same, toDraft, useSettingsDraft, writePath } from "./settingsDraft.js";
|
||||
|
||||
const DESTINATION_WEIGHT = { min: 0, max: 100 };
|
||||
|
||||
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 same = (left, right) => JSON.stringify(left) === JSON.stringify(right);
|
||||
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)));
|
||||
const withUnit = (value, unit) => (unit ? `${value} ${unit}` : String(value));
|
||||
const formatDefault = (value, unit) => (typeof value === "boolean" ? (value ? "oui" : "non") : Array.isArray(value) ? value.map((item) => withUnit(item, unit)).join(" / ") : withUnit(value, unit));
|
||||
|
||||
// Tous les réglages modifiables ici : ceux des groupes rangés dans un onglet (bornes du schéma) et ceux de chaque destination.
|
||||
// L'ouverture (bandeau d'état) et le prix d'un Éclat (Boutique) se règlent ailleurs.
|
||||
function editableFields(schema, destinations) {
|
||||
|
|
@ -38,70 +25,6 @@ function editableFields(schema, destinations) {
|
|||
|
||||
const PANEL_THEME = new Map(EXPEDITION_SETTING_THEMES.flatMap((theme) => theme.panels.map((panel) => [panel, theme.id])));
|
||||
|
||||
// Brouillon commun à tous les onglets : seules les valeurs touchées y figurent, le reste se lit dans les réglages enregistrés.
|
||||
function useSettingsDraft(settings, fields) {
|
||||
const [draft, setDraft] = useState({});
|
||||
const value = (path) => (path in draft ? fromDraft(draft[path]) : readPath(settings, path));
|
||||
const raw = (path) => (path in draft ? draft[path] : toDraft(readPath(settings, path)));
|
||||
const touched = fields.filter((field) => field.path in draft);
|
||||
const invalid = touched.filter((field) => !validValue(field, value(field.path)));
|
||||
const changes = touched.filter((field) => validValue(field, value(field.path)) && !same(value(field.path), readPath(settings, field.path)));
|
||||
const set = (path, next) => setDraft((current) => ({ ...current, [path]: next }));
|
||||
const reset = () => setDraft({});
|
||||
return { value, raw, invalid, changes, set, reset };
|
||||
}
|
||||
|
||||
function DefaultHint({ field, value, defaults, busy, onReset }) {
|
||||
const fallback = readPath(defaults, field.path);
|
||||
if (fallback === undefined || same(value, fallback)) return null;
|
||||
return <button className="nebula-admin-setting-default" type="button" disabled={busy} title="Rétablir la valeur par défaut" onClick={onReset}>
|
||||
Défaut : {formatDefault(fallback, field.unit)} <span aria-hidden="true">↺</span>
|
||||
</button>;
|
||||
}
|
||||
|
||||
function NumberInput({ field, value, label, busy, onChange }) {
|
||||
return <span className="nebula-admin-setting-input" data-unit={field.unit || undefined}>
|
||||
<input className="nds-input" type="number" inputMode="numeric" min={field.min} max={field.max} step="1" value={value} disabled={busy} aria-label={label} aria-invalid={!inRange(parse(value), field.min, field.max) || undefined} onChange={(event) => onChange(event.target.value)} />
|
||||
{field.unit && <span aria-hidden="true">{field.unit}</span>}
|
||||
</span>;
|
||||
}
|
||||
|
||||
// Un réglage : interrupteur, nombre ou suite de nombres, avec son état (modifié, invalide) et la valeur par défaut s'il s'en écarte.
|
||||
function SettingField({ field, draft, settings, defaults, busy }) {
|
||||
const value = draft.value(field.path);
|
||||
const raw = draft.raw(field.path);
|
||||
const changed = !same(value, readPath(settings, field.path));
|
||||
const invalid = !validValue(field, value);
|
||||
const label = field.unit ? `${field.label} (${field.unit})` : field.label;
|
||||
const state = { "data-changed": changed || undefined, "data-invalid": invalid || undefined };
|
||||
const hint = <DefaultHint field={field} value={value} defaults={defaults} busy={busy} onReset={() => draft.set(field.path, toDraft(readPath(defaults, field.path)))} />;
|
||||
const error = invalid && <small role="alert">Entier de {field.min.toLocaleString("fr-FR")} à {field.max.toLocaleString("fr-FR")}</small>;
|
||||
if (field.kind === "bool") return <div className="nebula-admin-expedition-field" {...state}>
|
||||
<span className="nebula-admin-setting-label">{field.label}</span>
|
||||
<button className="nds-button" data-size="sm" data-variant={raw ? "primary" : "secondary"} type="button" aria-pressed={raw} aria-label={field.label} disabled={busy} onClick={() => draft.set(field.path, !raw)}>{raw ? "Oui" : "Non"}</button>
|
||||
{hint}
|
||||
</div>;
|
||||
if (Array.isArray(raw)) return <fieldset className="nebula-admin-expedition-field" {...state}>
|
||||
<legend>{field.label}</legend>
|
||||
<div className="nebula-admin-expedition-items">{raw.map((item, index) => <label key={index}><span>{field.items?.[index] ?? index + 1}</span>
|
||||
<NumberInput field={field} value={item} label={`${label} · ${field.items?.[index] ?? index + 1}`} busy={busy} onChange={(next) => draft.set(field.path, raw.map((current, position) => (position === index ? next : current)))} />
|
||||
</label>)}</div>
|
||||
{error}{hint}
|
||||
</fieldset>;
|
||||
return <label className="nebula-admin-expedition-field" {...state}><span className="nebula-admin-setting-label">{field.label}</span>
|
||||
<NumberInput field={field} value={raw} label={label} busy={busy} onChange={(next) => draft.set(field.path, next)} />
|
||||
{error}{hint}
|
||||
</label>;
|
||||
}
|
||||
|
||||
function SettingsGroup({ group, fields, ...props }) {
|
||||
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) => <SettingField key={field.path} field={field} {...props} />)}</div>
|
||||
</section>;
|
||||
}
|
||||
|
||||
// Destinations : proposées ou non, et poids dans le tirage du jour. Leurs textes vivent dans le fichier du serveur.
|
||||
function DestinationSettings({ destinations, draft, settings, defaults, busy }) {
|
||||
return <section className="nds-panel nebula-admin-shop nebula-admin-expedition-group" aria-labelledby="nebula-admin-expedition-destinations">
|
||||
|
|
@ -164,34 +87,6 @@ function ExpeditionsStatus({ enabled, today, destinations, busy, onToggle, onCan
|
|||
</section>;
|
||||
}
|
||||
|
||||
// Barre commune : nombre de réglages modifiés ou invalides, puis confirmation avec la liste des changements.
|
||||
function ApplyBar({ draft, settings, destinations, busy, onApply }) {
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const { changes, invalid } = draft;
|
||||
if (!changes.length && !invalid.length) return null;
|
||||
const count = (total, word) => `${total} réglage${total > 1 ? "s" : ""} ${word}${total > 1 ? "s" : ""}`;
|
||||
return <div className="nds-panel nebula-admin-apply-bar" role="region" aria-label="Modifications en attente">
|
||||
<p role="status">{[changes.length && count(changes.length, "modifié"), invalid.length && count(invalid.length, "invalide")].filter(Boolean).join(" · ")}</p>
|
||||
<div className="nds-toolbar">
|
||||
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" disabled={busy} aria-label="Annuler les modifications" onClick={draft.reset}>Annuler</button>
|
||||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={busy || !changes.length || invalid.length > 0} onClick={() => setConfirming(true)}>Appliquer</button>
|
||||
</div>
|
||||
{confirming && <ConfirmModal
|
||||
title={`Appliquer ${count(changes.length, "modifié")} ?`}
|
||||
message="Les nouveaux réglages s’appliquent aux prochains départs. Les expéditions en route gardent ceux de leur départ."
|
||||
confirmLabel="Appliquer"
|
||||
onClose={async (confirmed) => {
|
||||
setConfirming(false);
|
||||
if (confirmed) await onApply();
|
||||
}}
|
||||
>
|
||||
<ul className="nebula-admin-apply-changes">{changes.map((field) => <li key={field.path}>
|
||||
<span>{expeditionSettingLabel(field.path, destinations)}</span> : {formatSettingValue(readPath(settings, field.path))} → <strong>{formatSettingValue(draft.value(field.path))}</strong>
|
||||
</li>)}</ul>
|
||||
</ConfirmModal>}
|
||||
</div>;
|
||||
}
|
||||
|
||||
export function ExpeditionSettings({ dashboard, busy, runMutation, refreshDashboard }) {
|
||||
const { settings, defaults, schema, destinations } = dashboard.expeditionSettings;
|
||||
const [themeId, setThemeId] = useState(EXPEDITION_SETTING_THEMES[0].id);
|
||||
|
|
@ -227,6 +122,6 @@ export function ExpeditionSettings({ dashboard, busy, runMutation, refreshDashbo
|
|||
{theme.panels.map((panel) => (panel === "destinations"
|
||||
? <DestinationSettings key={panel} destinations={destinations} {...props} />
|
||||
: <SettingsGroup key={panel} group={EXPEDITION_SETTING_GROUPS.find((group) => group.id === panel)} fields={fields.filter((field) => field.panel === panel)} {...props} />))}
|
||||
<ApplyBar draft={draft} settings={settings} destinations={destinations} busy={busy} onApply={apply} />
|
||||
<ApplyBar draft={draft} settings={settings} busy={busy} onApply={apply} message="Les nouveaux réglages s’appliquent aux prochains départs. Les expéditions en route gardent ceux de leur départ." labelOf={(path) => expeditionSettingLabel(path, destinations)} formatValue={formatSettingValue} />
|
||||
</div>;
|
||||
}
|
||||
|
|
|
|||
85
website/src/features/cards/admin/SettingFields.jsx
Normal file
85
website/src/features/cards/admin/SettingFields.jsx
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
// Rôle : champs et barre d'application des formulaires de réglages de l'administration (Expéditions, Équipe du jour).
|
||||
import { useState } from "react";
|
||||
import { ConfirmModal } from "../../../components/ToolboxModals.jsx";
|
||||
import { inRange, parse } from "./adminSettings.js";
|
||||
import { formatDefault, readPath, same, toDraft, validValue } from "./settingsDraft.js";
|
||||
|
||||
export function DefaultHint({ field, value, defaults, busy, onReset }) {
|
||||
const fallback = readPath(defaults, field.path);
|
||||
if (fallback === undefined || same(value, fallback)) return null;
|
||||
return <button className="nebula-admin-setting-default" type="button" disabled={busy} title="Rétablir la valeur par défaut" onClick={onReset}>
|
||||
Défaut : {formatDefault(fallback, field.unit)} <span aria-hidden="true">↺</span>
|
||||
</button>;
|
||||
}
|
||||
|
||||
export function NumberInput({ field, value, label, busy, onChange }) {
|
||||
return <span className="nebula-admin-setting-input" data-unit={field.unit || undefined}>
|
||||
<input className="nds-input" type="number" inputMode="numeric" min={field.min} max={field.max} step="1" value={value} disabled={busy} aria-label={label} aria-invalid={!inRange(parse(value), field.min, field.max) || undefined} onChange={(event) => onChange(event.target.value)} />
|
||||
{field.unit && <span aria-hidden="true">{field.unit}</span>}
|
||||
</span>;
|
||||
}
|
||||
|
||||
// Un réglage : interrupteur, nombre ou suite de nombres, avec son état (modifié, invalide) et la valeur par défaut s'il s'en écarte.
|
||||
function SettingField({ field, draft, settings, defaults, busy }) {
|
||||
const value = draft.value(field.path);
|
||||
const raw = draft.raw(field.path);
|
||||
const changed = !same(value, readPath(settings, field.path));
|
||||
const invalid = !validValue(field, value);
|
||||
const label = field.unit ? `${field.label} (${field.unit})` : field.label;
|
||||
const state = { "data-changed": changed || undefined, "data-invalid": invalid || undefined };
|
||||
const hint = <DefaultHint field={field} value={value} defaults={defaults} busy={busy} onReset={() => draft.set(field.path, toDraft(readPath(defaults, field.path)))} />;
|
||||
const error = invalid && <small role="alert">Entier de {field.min.toLocaleString("fr-FR")} à {field.max.toLocaleString("fr-FR")}</small>;
|
||||
if (field.kind === "bool") return <div className="nebula-admin-expedition-field" {...state}>
|
||||
<span className="nebula-admin-setting-label">{field.label}</span>
|
||||
<button className="nds-button" data-size="sm" data-variant={raw ? "primary" : "secondary"} type="button" aria-pressed={raw} aria-label={field.label} disabled={busy} onClick={() => draft.set(field.path, !raw)}>{raw ? "Oui" : "Non"}</button>
|
||||
{hint}
|
||||
</div>;
|
||||
if (Array.isArray(raw)) return <fieldset className="nebula-admin-expedition-field" {...state}>
|
||||
<legend>{field.label}</legend>
|
||||
<div className="nebula-admin-expedition-items">{raw.map((item, index) => <label key={index}><span>{field.items?.[index] ?? index + 1}</span>
|
||||
<NumberInput field={field} value={item} label={`${label} · ${field.items?.[index] ?? index + 1}`} busy={busy} onChange={(next) => draft.set(field.path, raw.map((current, position) => (position === index ? next : current)))} />
|
||||
</label>)}</div>
|
||||
{error}{hint}
|
||||
</fieldset>;
|
||||
return <label className="nebula-admin-expedition-field" {...state}><span className="nebula-admin-setting-label">{field.label}</span>
|
||||
<NumberInput field={field} value={raw} label={label} busy={busy} onChange={(next) => draft.set(field.path, next)} />
|
||||
{error}{hint}
|
||||
</label>;
|
||||
}
|
||||
|
||||
export function SettingsGroup({ group, fields, ...props }) {
|
||||
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) => <SettingField key={field.path} field={field} {...props} />)}</div>
|
||||
</section>;
|
||||
}
|
||||
|
||||
// Barre commune : nombre de réglages modifiés ou invalides, puis confirmation avec la liste des changements.
|
||||
// `labelOf` et `formatValue` nomment un réglage et sa valeur ; `blocked` : ce qui empêche d'appliquer des valeurs valides une à une.
|
||||
export function ApplyBar({ draft, settings, busy, message, labelOf, formatValue, blocked = "", onApply }) {
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const { changes, invalid } = draft;
|
||||
if (!changes.length && !invalid.length) return null;
|
||||
const count = (total, word) => `${total} réglage${total > 1 ? "s" : ""} ${word}${total > 1 ? "s" : ""}`;
|
||||
return <div className="nds-panel nebula-admin-apply-bar" role="region" aria-label="Modifications en attente">
|
||||
<p role="status">{[changes.length && count(changes.length, "modifié"), invalid.length && count(invalid.length, "invalide"), blocked].filter(Boolean).join(" · ")}</p>
|
||||
<div className="nds-toolbar">
|
||||
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" disabled={busy} aria-label="Annuler les modifications" onClick={draft.reset}>Annuler</button>
|
||||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={busy || !changes.length || invalid.length > 0 || Boolean(blocked)} onClick={() => setConfirming(true)}>Appliquer</button>
|
||||
</div>
|
||||
{confirming && <ConfirmModal
|
||||
title={`Appliquer ${count(changes.length, "modifié")} ?`}
|
||||
message={message}
|
||||
confirmLabel="Appliquer"
|
||||
onClose={async (confirmed) => {
|
||||
setConfirming(false);
|
||||
if (confirmed) await onApply();
|
||||
}}
|
||||
>
|
||||
<ul className="nebula-admin-apply-changes">{changes.map((field) => <li key={field.path}>
|
||||
<span>{labelOf(field.path)}</span> : {formatValue(readPath(settings, field.path))} → <strong>{formatValue(draft.value(field.path))}</strong>
|
||||
</li>)}</ul>
|
||||
</ConfirmModal>}
|
||||
</div>;
|
||||
}
|
||||
60
website/src/features/cards/admin/TeamSettings.jsx
Normal file
60
website/src/features/cards/admin/TeamSettings.jsx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// Rôle : règle l'Équipe du jour depuis Administration › Guilde : ouverture et suivi du jour, étoiles, Puissance et récompenses.
|
||||
import { useState } from "react";
|
||||
import { ConfirmModal } from "../../../components/ToolboxModals.jsx";
|
||||
import { updateTeamSettings } from "../cardsApi.js";
|
||||
import { ApplyBar, SettingsGroup } from "./SettingFields.jsx";
|
||||
import { readPath, useSettingsDraft, writePath } from "./settingsDraft.js";
|
||||
import { formatTeamSetting, TEAM_SETTING_GROUPS, teamSettingLabel, teamSettingsConflict } from "./teamSettingFields.js";
|
||||
|
||||
const FIELDS = TEAM_SETTING_GROUPS.flatMap((group) => group.fields);
|
||||
const plural = (count, word) => `${word}${count > 1 ? "s" : ""}`;
|
||||
|
||||
// Ouverture, appliquée tout de suite sans toucher au brouillon, et activité du jour.
|
||||
function TeamStatus({ enabled, today, busy, onToggle }) {
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
return <section className="nds-panel nebula-admin-shop nebula-admin-expedition-status" data-open={enabled} aria-labelledby="nebula-admin-team-status-title">
|
||||
<div className="nebula-admin-expedition-status-head">
|
||||
<div>
|
||||
<h3 id="nebula-admin-team-status-title">Équipe du jour <span className="nds-badge" data-variant={enabled ? "success" : "neutral"}>{enabled ? "Ouverte aux joueurs" : "Fermée aux joueurs"}</span></h3>
|
||||
<p className="nebula-admin-guild-today">Aujourd’hui : <strong>{today.teams}</strong> {plural(today.teams, "équipe")} utilisable{today.teams > 1 ? "s" : ""} · <strong>{today.races}</strong> {plural(today.races, "course")} · <strong>{today.stars}</strong> {plural(today.stars, "étoile")} {plural(today.stars, "dorée")} {plural(today.stars, "choisie")}.</p>
|
||||
</div>
|
||||
<button className="nds-button" data-size="sm" data-variant={enabled ? "secondary" : "primary"} type="button" disabled={busy} onClick={() => setConfirming(true)}>{enabled ? "Fermer l’Équipe du jour" : "Ouvrir l’Équipe du jour"}</button>
|
||||
</div>
|
||||
{confirming && <ConfirmModal
|
||||
title={enabled ? "Fermer l’Équipe du jour ?" : "Ouvrir l’Équipe du jour ?"}
|
||||
message={enabled
|
||||
? "Plus aucun recrutement ni départ de course. Un recrutement ou une course déjà commencés se terminent, et la Carte du jour redonne sa poussière aussitôt."
|
||||
: "Les tuiles de l’Équipe du jour et de la Course apparaissent dans la Guilde, et la Carte du jour propose une étoile dorée."}
|
||||
confirmLabel={enabled ? "Fermer" : "Ouvrir"}
|
||||
onClose={async (confirmed) => {
|
||||
setConfirming(false);
|
||||
if (confirmed) await onToggle(!enabled);
|
||||
}}
|
||||
/>}
|
||||
</section>;
|
||||
}
|
||||
|
||||
export function TeamSettings({ dashboard, busy, runMutation, refreshDashboard }) {
|
||||
const { settings, defaults, today } = dashboard.teamSettings;
|
||||
const draft = useSettingsDraft(settings, FIELDS);
|
||||
const save = async (apply) => {
|
||||
const next = structuredClone(settings);
|
||||
apply(next);
|
||||
const saved = await runMutation(() => updateTeamSettings(next));
|
||||
if (saved) await refreshDashboard();
|
||||
return saved;
|
||||
};
|
||||
const apply = async () => {
|
||||
if (await save((next) => draft.changes.forEach((field) => writePath(next, field.path, draft.value(field.path))))) draft.reset();
|
||||
};
|
||||
const value = (path) => draft.value(path) ?? readPath(settings, path);
|
||||
const starStardust = value("starStardust");
|
||||
const dailyReward = dashboard.shopSetting.dailyReward;
|
||||
return <div className="nebula-admin-expeditions">
|
||||
<TeamStatus enabled={settings.enabled} today={today} busy={busy} onToggle={(enabled) => save((next) => { next.enabled = enabled; })} />
|
||||
{starStardust >= dailyReward && <p className="nds-inline-notice" data-variant="warning" role="status">L’étoile dorée vient avec {starStardust.toLocaleString("fr-FR")} de poussière, autant ou plus que la Carte du jour sans étoile ({dailyReward.toLocaleString("fr-FR")}) : les joueurs n’auraient aucune raison de choisir la poussière seule.</p>}
|
||||
{TEAM_SETTING_GROUPS.map((group) => <SettingsGroup key={group.id} group={group} fields={group.fields} draft={draft} settings={settings} defaults={defaults} busy={busy} />)}
|
||||
<ApplyBar draft={draft} settings={settings} busy={busy} onApply={apply} message="Les nouveaux réglages valent pour les prochains recrutements, courses et victoires à la Carte du jour." labelOf={teamSettingLabel} formatValue={formatTeamSetting}
|
||||
blocked={teamSettingsConflict({ powers: value("recruitment.powers"), fallPower: value("recruitment.fallPower") })} />
|
||||
</div>;
|
||||
}
|
||||
|
|
@ -161,6 +161,7 @@ export const EXPEDITION_SETTING_GROUPS = [
|
|||
{ path: "items.weights.guideStar", label: "Poids : étoile guide (destination bonus)" },
|
||||
{ path: "items.weights.skyChart", label: "Poids : carte céleste (destination bonus au butin plus riche)" },
|
||||
{ path: "items.weights.windRose", label: "Poids : rose des vents (nouvelles destinations du jour)" },
|
||||
{ path: "items.weights.balm", label: "Poids : baume des Veilleurs (soigne un compagnon, si l’Équipe du jour est ouverte)" },
|
||||
{ path: "items.weights.oblivion", label: "Poids : parchemin d’oubli (changer le plan d’une carte)" }
|
||||
]
|
||||
},
|
||||
|
|
|
|||
30
website/src/features/cards/admin/settingsDraft.js
Normal file
30
website/src/features/cards/admin/settingsDraft.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// Rôle : brouillon des formulaires de réglages de l'administration (Expéditions, Équipe du jour) : lecture, saisie, validation.
|
||||
import { useState } from "react";
|
||||
import { inRange, parse } from "./adminSettings.js";
|
||||
|
||||
export const readPath = (source, path) => path.split(".").reduce((value, key) => value?.[key], source);
|
||||
|
||||
export function writePath(target, path, value) {
|
||||
const keys = path.split(".");
|
||||
keys.slice(0, -1).reduce((node, key) => node[key], target)[keys.at(-1)] = value;
|
||||
}
|
||||
|
||||
export const same = (left, right) => JSON.stringify(left) === JSON.stringify(right);
|
||||
export const toDraft = (value) => (typeof value === "boolean" ? value : Array.isArray(value) ? value.map(String) : String(value));
|
||||
export const fromDraft = (value) => (typeof value === "boolean" ? value : Array.isArray(value) ? value.map(parse) : parse(value));
|
||||
export const validValue = (field, value) => (field.kind === "bool" ? typeof value === "boolean" : (Array.isArray(value) ? value : [value]).every((item) => inRange(item, field.min, field.max)));
|
||||
const withUnit = (value, unit) => (unit ? `${value} ${unit}` : String(value));
|
||||
export const formatDefault = (value, unit) => (typeof value === "boolean" ? (value ? "oui" : "non") : Array.isArray(value) ? value.map((item) => withUnit(item, unit)).join(" / ") : withUnit(value, unit));
|
||||
|
||||
// Brouillon commun : seules les valeurs touchées y figurent, le reste se lit dans les réglages enregistrés.
|
||||
export function useSettingsDraft(settings, fields) {
|
||||
const [draft, setDraft] = useState({});
|
||||
const value = (path) => (path in draft ? fromDraft(draft[path]) : readPath(settings, path));
|
||||
const raw = (path) => (path in draft ? draft[path] : toDraft(readPath(settings, path)));
|
||||
const touched = fields.filter((field) => field.path in draft);
|
||||
const invalid = touched.filter((field) => !validValue(field, value(field.path)));
|
||||
const changes = touched.filter((field) => validValue(field, value(field.path)) && !same(value(field.path), readPath(settings, field.path)));
|
||||
const set = (path, next) => setDraft((current) => ({ ...current, [path]: next }));
|
||||
const reset = () => setDraft({});
|
||||
return { value, raw, invalid, changes, set, reset };
|
||||
}
|
||||
42
website/src/features/cards/admin/teamSettingFields.js
Normal file
42
website/src/features/cards/admin/teamSettingFields.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// Rôle : décrit les réglages de l'Équipe du jour dans l'administration : libellés, bornes et règles entre plusieurs valeurs.
|
||||
|
||||
export const TEAM_SETTING_GROUPS = [
|
||||
{
|
||||
id: "team-stars", title: "Recrutement", help: "Étoiles cachées au début d’un recrutement. Les étoiles dorées en réserve s’y ajoutent. Nouvelles propositions : fois où un joueur peut redemander trois personnages. Un recrutement commencé garde les réglages de son début.",
|
||||
fields: [
|
||||
{ path: "recruitment.goldStars", label: "Étoiles dorées", min: 1, max: 30 },
|
||||
{ path: "recruitment.blackStars", label: "Étoiles noires", min: 0, max: 15 },
|
||||
{ path: "recruitment.dustStars", label: "Étoiles de poussière", min: 0, max: 10 },
|
||||
{ path: "recruitment.dustValue", label: "Poussière par étoile", min: 0, max: 1_000 },
|
||||
{ path: "recruitment.rerolls", label: "Nouvelles propositions", min: 0, max: 10 }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: "team-powers", title: "Puissance des compagnons", help: "Puissance à l’arrivée, puis après chaque étoile dorée. La Puissance après une étoile noire doit rester sous celle du départ : sinon, le premier essai ne coûte rien.",
|
||||
fields: [
|
||||
{ path: "recruitment.powers", label: "Paliers", min: 1, max: 100, items: ["Départ", "1 dorée", "2 dorées", "3 dorées"] },
|
||||
{ path: "recruitment.fallPower", label: "Après une étoile noire", min: 1, max: 100 }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: "team-rewards", title: "Récompenses", help: "En poussière d’étoiles. Les récompenses d’une course sont celles de son départ.",
|
||||
fields: [
|
||||
{ path: "raceRewards", label: "Course, selon la place", min: 0, max: 100_000, items: ["1re", "2e", "3e", "4e"] },
|
||||
{ path: "starStardust", label: "Avec une étoile dorée (Carte du jour)", min: 0, max: 100_000 }
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
const FIELDS = TEAM_SETTING_GROUPS.flatMap((group) => group.fields);
|
||||
const LABELS = new Map([...FIELDS.map((field) => [field.path, field.label]), ["enabled", "Ouverte aux joueurs"]]);
|
||||
|
||||
export const teamSettingLabel = (path) => LABELS.get(path) || path;
|
||||
export const formatTeamSetting = (value) => (typeof value === "boolean" ? (value ? "oui" : "non") : Array.isArray(value) ? value.join(" / ") : String(value));
|
||||
export const TEAM_SETTING_PATHS = ["enabled", ...FIELDS.map((field) => field.path)];
|
||||
|
||||
// Règles entre valeurs, que le serveur vérifie aussi.
|
||||
export function teamSettingsConflict({ powers, fallPower }) {
|
||||
if (powers.some((power, index) => index > 0 && power <= powers[index - 1])) return "Chaque palier doit dépasser le précédent.";
|
||||
if (fallPower >= powers[0]) return "La Puissance après une étoile noire doit être inférieure à celle du départ.";
|
||||
return "";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue