Let administrators set the opening reserve size
The reserve was fixed at 5 by CHECK constraints on players and recharge_settings. Migration 21 rebuilds both tables with foreign keys off and checks them before committing; the reserve now goes from 1 to 50 and is set next to the recharge delay. A raised reserve restarts the recharge of full players at once, a reduced one keeps their extra openings, and the player counter shows the configured maximum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fd47514d81
commit
d2ef3b098c
13 changed files with 216 additions and 35 deletions
|
|
@ -18,11 +18,13 @@ export function OpeningReserve({ recharge, content, children, compact = false })
|
|||
return () => window.clearInterval(interval);
|
||||
}, [recharge.nextOpeningAt]);
|
||||
|
||||
// La réserve maximale est réglée par l'administration ; un joueur peut la dépasser si elle a été réduite depuis.
|
||||
const maxOpenings = recharge.maxOpenings ?? 5;
|
||||
return <section className={`nds-panel nebula-opening-reserve ${compact ? "is-compact" : ""}`} aria-label={content.available}>
|
||||
<div className="nebula-opening-reserve-value"><strong>{recharge.openingsBalance}</strong><span>/ 5</span></div>
|
||||
<div className="nebula-opening-reserve-value"><strong>{recharge.openingsBalance}</strong><span>/ {maxOpenings}</span></div>
|
||||
<div className="nebula-opening-reserve-copy">
|
||||
<h2>{content.available}</h2>
|
||||
<div className="nds-progress" role="progressbar" aria-valuemin="0" aria-valuemax="5" aria-valuenow={recharge.openingsBalance}><span style={{ width: `${recharge.openingsBalance / 5 * 100}%` }} /></div>
|
||||
<div className="nds-progress" role="progressbar" aria-valuemin="0" aria-valuemax={maxOpenings} aria-valuenow={Math.min(recharge.openingsBalance, maxOpenings)}><span style={{ width: `${Math.min(1, recharge.openingsBalance / maxOpenings) * 100}%` }} /></div>
|
||||
{/* Sous le menu, le libellé court garde le compte à rebours sur la même ligne. */}
|
||||
<p>{recharge.nextOpeningAt ? <>{compact ? content.nextShort : content.next} <strong>{formatRemaining(recharge.nextOpeningAt, now)}</strong></> : content.full}</p>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -44,7 +44,11 @@ function mythicDetail(entry, catalog) {
|
|||
function eventDetail(entry, catalog) {
|
||||
const { details, campaignName } = entry;
|
||||
switch (entry.type) {
|
||||
case "recharge_updated": return `${formatDuration(details.previousIntervalMs)} → ${formatDuration(details.intervalMs)}`;
|
||||
case "recharge_updated": return [
|
||||
details.previousIntervalMs !== details.intervalMs && `${formatDuration(details.previousIntervalMs)} → ${formatDuration(details.intervalMs)}`,
|
||||
// Les entrées d'avant la réserve réglable n'ont que le délai.
|
||||
details.maxOpenings != null && details.previousMaxOpenings !== details.maxOpenings && `réserve ${details.previousMaxOpenings} → ${details.maxOpenings}`
|
||||
].filter(Boolean).join(" · ");
|
||||
case "shop_updated": return shopChanges(details, catalog).filter(Boolean).join(" · ");
|
||||
case "catalog_card_mythic_updated": return mythicDetail(entry, catalog);
|
||||
case "catalog_collection_opening_updated":
|
||||
|
|
|
|||
|
|
@ -60,15 +60,29 @@ export function DropRatesEditor({ catalog, collection, busy, mutateCatalog }) {
|
|||
}
|
||||
|
||||
const MAX_RECHARGE_MINUTES = 7 * 24 * 60;
|
||||
// Même borne que le serveur (MAX_RESERVE_OPENINGS).
|
||||
const MAX_RESERVE_OPENINGS = 50;
|
||||
|
||||
function reserveMessage(setting, intervalMs, reserve) {
|
||||
const changes = [];
|
||||
if (intervalMs !== setting.intervalMs) changes.push("Le nouveau délai s’applique immédiatement à tous les joueurs, y compris au temps déjà écoulé depuis leur dernière recharge.");
|
||||
if (reserve > setting.maxOpenings) changes.push(`Les joueurs dont la réserve était pleine recommencent à recharger jusqu’à ${reserve}.`);
|
||||
if (reserve < setting.maxOpenings) changes.push(`Les joueurs qui ont plus de ${reserve} ouvertures les gardent ; leur réserve ne se recharge qu’une fois redescendue sous ${reserve}.`);
|
||||
return changes.join(" ");
|
||||
}
|
||||
|
||||
export function RechargeSetting({ setting, busy, runMutation, refreshDashboard }) {
|
||||
const [minutes, setMinutes] = useState(() => (setting ? String(setting.intervalMs / 60_000) : ""));
|
||||
const [reserveDraft, setReserveDraft] = useState(() => (setting ? String(setting.maxOpenings) : ""));
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
if (!setting) return <aside className="nds-panel nebula-admin-recharge" aria-busy="true"><p className="nebula-admin-empty">Chargement de la recharge…</p></aside>;
|
||||
const parsed = /^\d+$/.test(minutes) ? Number(minutes) : NaN;
|
||||
const valid = Number.isInteger(parsed) && parsed >= 1 && parsed <= MAX_RECHARGE_MINUTES;
|
||||
const reserve = /^\d+$/.test(reserveDraft) ? Number(reserveDraft) : NaN;
|
||||
const intervalValid = Number.isInteger(parsed) && parsed >= 1 && parsed <= MAX_RECHARGE_MINUTES;
|
||||
const reserveValid = Number.isInteger(reserve) && reserve >= 1 && reserve <= MAX_RESERVE_OPENINGS;
|
||||
const valid = intervalValid && reserveValid;
|
||||
const intervalMs = parsed * 60_000;
|
||||
const changed = valid && intervalMs !== setting.intervalMs;
|
||||
const changed = valid && (intervalMs !== setting.intervalMs || reserve !== setting.maxOpenings);
|
||||
const perDay = valid ? 1440 / parsed : 0;
|
||||
|
||||
return <aside className="nds-panel nebula-admin-recharge" aria-labelledby="nebula-admin-recharge-title">
|
||||
|
|
@ -76,19 +90,22 @@ export function RechargeSetting({ setting, busy, runMutation, refreshDashboard }
|
|||
<h4 id="nebula-admin-recharge-title">Recharge des ouvertures</h4>
|
||||
<span className="nebula-admin-recharge-current">{formatRechargeInterval(setting.intervalMs)} · réserve de {setting.maxOpenings}</span>
|
||||
</div>
|
||||
<p className="nebula-form-help">Commune à tous les paquets. Un nouveau délai s’applique immédiatement, y compris au temps déjà écoulé depuis la dernière recharge.</p>
|
||||
<p className="nebula-form-help">Commune à tous les paquets. Un nouveau délai s’applique immédiatement, y compris au temps déjà écoulé depuis la dernière recharge. Réduire la réserve ne retire aucune ouverture aux joueurs.</p>
|
||||
<div className="nebula-admin-recharge-form">
|
||||
<label><span>Délai en minutes</span><input className="nds-input" type="number" inputMode="numeric" min="1" max={MAX_RECHARGE_MINUTES} step="1" value={minutes} disabled={busy} onChange={(event) => setMinutes(event.target.value)} /></label>
|
||||
<label><span>Réserve maximale</span><input className="nds-input" type="number" inputMode="numeric" min="1" max={MAX_RESERVE_OPENINGS} step="1" value={reserveDraft} disabled={busy} onChange={(event) => setReserveDraft(event.target.value)} /></label>
|
||||
<button className="nds-button" data-variant="primary" type="button" disabled={busy || !changed} onClick={() => setConfirming(true)}>Appliquer</button>
|
||||
</div>
|
||||
<p className="nebula-admin-recharge-preview" role="status">{valid ? `${formatDuration(intervalMs)} · ${perDay.toLocaleString("fr-FR", { maximumFractionDigits: 1 })} ouverture${perDay >= 2 ? "s" : ""} par jour · réserve vide remplie en ${formatDuration(intervalMs * setting.maxOpenings)}` : `Entre 1 et ${MAX_RECHARGE_MINUTES.toLocaleString("fr-FR")} minutes (7 jours).`}</p>
|
||||
<p className="nebula-admin-recharge-preview" role="status">{valid
|
||||
? `${formatDuration(intervalMs)} · ${perDay.toLocaleString("fr-FR", { maximumFractionDigits: 1 })} ouverture${perDay >= 2 ? "s" : ""} par jour · réserve vide remplie en ${formatDuration(intervalMs * reserve)}`
|
||||
: [!intervalValid && `Délai : entre 1 et ${MAX_RECHARGE_MINUTES.toLocaleString("fr-FR")} minutes (7 jours).`, !reserveValid && `Réserve : entre 1 et ${MAX_RESERVE_OPENINGS} ouvertures.`].filter(Boolean).join(" ")}</p>
|
||||
{confirming && <ConfirmModal
|
||||
title={`Passer à ${formatRechargeInterval(intervalMs)} ?`}
|
||||
message="Le nouveau délai s’applique immédiatement à tous les joueurs, y compris au temps déjà écoulé depuis leur dernière recharge."
|
||||
confirmLabel="Appliquer le délai"
|
||||
title={`Passer à ${[intervalMs !== setting.intervalMs && formatRechargeInterval(intervalMs), reserve !== setting.maxOpenings && `une réserve de ${reserve}`].filter(Boolean).join(" et ")} ?`}
|
||||
message={reserveMessage(setting, intervalMs, reserve)}
|
||||
confirmLabel="Appliquer la recharge"
|
||||
onClose={async (confirmed) => {
|
||||
setConfirming(false);
|
||||
if (confirmed && (await runMutation(() => updateRechargeSetting(intervalMs)))) await refreshDashboard();
|
||||
if (confirmed && (await runMutation(() => updateRechargeSetting({ intervalMs, maxOpenings: reserve })))) await refreshDashboard();
|
||||
}}
|
||||
/>}
|
||||
</aside>;
|
||||
|
|
|
|||
|
|
@ -155,8 +155,8 @@ export function setDropRates(collectionId, rarityWeights) {
|
|||
return request(`/admin/collections/${encodeURIComponent(collectionId)}/drop-rates`, { method: "PUT", body: JSON.stringify({ rarityWeights }) });
|
||||
}
|
||||
|
||||
export function updateRechargeSetting(intervalMs) {
|
||||
return request("/admin/recharge", { method: "PUT", body: JSON.stringify({ intervalMs }) });
|
||||
export function updateRechargeSetting({ intervalMs, maxOpenings }) {
|
||||
return request("/admin/recharge", { method: "PUT", body: JSON.stringify({ intervalMs, maxOpenings }) });
|
||||
}
|
||||
|
||||
export function loadCampaignDetail(campaignId) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue