Add the Broken Mirror puzzle to the Guild

A daily puzzle: a card illustration cut into pieces, rebuilt by swapping
two pieces of the same row or column within a limited number of swaps.
The normal picture is a square card in 4 x 4, drawn for each player, with
placed pieces outlined in green; the hard one is a 5 x 7 portrait shared
by everyone each day, with a result to copy. The limit is the computer's
best result (beam search) plus a margin, and every swap left adds
stardust. Two companions of the daily team can each give one help, by
specialty; a double specialty picks one when used.

The server keeps the piece positions, sends the picture already shuffled
and checks every swap. Uniform illustrations are left out, from measures
written by scripts/mirror-illustrations.mjs. The Guild gets its quest and
a Codex tile, the administration a tab (opening, rewards, margins, the
day's summary), and migration 30 its tables. New collections must plan at
least one double-specialty character, counted by
scripts/team-specialties.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-28 13:38:46 +01:00
parent 5210503922
commit 9cf48ea0d0
36 changed files with 3124 additions and 20 deletions

View file

@ -1,10 +1,11 @@
// Rôle : règle les quêtes de la Guilde des Veilleurs, une par onglet (Carte du jour, Équipe du jour, Course des courants, Expéditions),
// Rôle : règle les quêtes de la Guilde des Veilleurs, une par onglet (Carte du jour, Équipe du jour, Course des courants, Miroir brisé, 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 { MirrorSettings } from "./MirrorSettings.jsx";
import { RaceSettings } from "./RaceSettings.jsx";
import { TeamSettings } from "./TeamSettings.jsx";
@ -32,9 +33,9 @@ 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: "team", label: "Équipe du jour" }, { id: "race", label: "Course des courants" }, { id: "expeditions", label: "Expéditions" }];
const GUILD_TABS = [{ id: "daily", label: "Carte du jour" }, { id: "team", label: "Équipe du jour" }, { id: "race", label: "Course des courants" }, { id: "mirror", label: "Miroir brisé" }, { id: "expeditions", label: "Expéditions" }];
export function AdminGuild({ dashboard, busy, runMutation, refreshDashboard, tab = "" }) {
export function AdminGuild({ dashboard, catalog, busy, runMutation, refreshDashboard, tab = "" }) {
const setting = dashboard?.shopSetting;
const save = shopSettingSaver(setting, runMutation, refreshDashboard);
const activeTab = GUILD_TABS.some((item) => item.id === tab) ? tab : GUILD_TABS[0].id;
@ -45,6 +46,7 @@ export function AdminGuild({ dashboard, busy, runMutation, refreshDashboard, tab
{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 === "race" && dashboard.teamSettings && <RaceSettings dashboard={dashboard} busy={busy} runMutation={runMutation} refreshDashboard={refreshDashboard} />}
{activeTab === "mirror" && dashboard.mirrorSettings && <MirrorSettings dashboard={dashboard} catalog={catalog} 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>}

View file

@ -0,0 +1,82 @@
// Rôle : règle le Miroir brisé depuis Administration › Guilde : ouverture, suivi du jour (illustration du Difficile, parties,
// poussière versée), gains et marges d'échanges. Ses règles de jeu restent dans mirror-rules.js.
import { useState } from "react";
import { ConfirmModal } from "../../../components/ToolboxModals.jsx";
import { updateMirrorSettings } from "../cardsApi.js";
import { ApplyBar, SettingsGroup } from "./SettingFields.jsx";
import { useSettingsDraft, writePath } from "./settingsDraft.js";
const MODE_LABELS = { normal: "Normal", hard: "Difficile" };
const number = (value) => value.toLocaleString("fr-FR");
const MIRROR_SETTING_GROUPS = [
{
id: "mirror-rewards", title: "Gains", help: "En poussière d’étoiles, pour une image reconstituée : la base, plus une part par échange restant. Une partie perdue ne rapporte rien. Repères : la Carte du jour rapporte 20 en production, la Course 20 à 5.",
fields: [
{ path: "rewards.normal.base", label: "Normal, base", min: 0, max: 100_000 },
{ path: "rewards.normal.perSwap", label: "Normal, par échange restant", min: 0, max: 100_000 },
{ path: "rewards.hard.base", label: "Difficile, base", min: 0, max: 100_000 },
{ path: "rewards.hard.perSwap", label: "Difficile, par échange restant", min: 0, max: 100_000 }
]
},
{
id: "mirror-margins", title: "Marges d’échanges", help: "Échanges permis au-delà du meilleur résultat trouvé par l’ordinateur. En Normal, avec 3, un joueur attentif réussit environ 9 fois sur 10 (simulation). Une partie commencée garde sa limite.",
fields: [
{ path: "margins.normal", label: "Normal", min: 0, max: 30 },
{ path: "margins.hard", label: "Difficile", min: 0, max: 30 }
]
}
];
const FIELDS = MIRROR_SETTING_GROUPS.flatMap((group) => group.fields);
const LABELS = new Map([...FIELDS.map((field) => [field.path, `${field.path.startsWith("margins.") ? "Marge, " : "Gain, "}${field.label.toLowerCase()}`]), ["enabled", "Miroir brisé ouvert aux joueurs"]]);
const labelOf = (path) => LABELS.get(path) || path;
const formatValue = (value) => (typeof value === "boolean" ? (value ? "oui" : "non") : String(value));
// Ouverture (appliquée tout de suite) et suivi du jour.
function MirrorStatus({ settings, today, catalog, busy, onToggle }) {
const [confirming, setConfirming] = useState(false);
const open = settings.enabled;
const hardCard = today.hard ? catalog?.cards.find((card) => card.id === today.hard.cardId) : null;
return <section className="nds-panel nebula-admin-shop nebula-admin-expedition-status" data-open={open} aria-labelledby="nebula-admin-mirror-status-title">
<div className="nebula-admin-expedition-status-head">
<div>
<h3 id="nebula-admin-mirror-status-title">Miroir brisé <span className="nds-badge" data-variant={open ? "success" : "neutral"}>{open ? "Ouvert aux joueurs" : "Fermé aux joueurs"}</span></h3>
<p className="nebula-admin-guild-today">Aujourd’hui : <strong>{number(today.stardust)}</strong> de poussière versée.</p>
</div>
<button className="nds-button" data-size="sm" data-variant={open ? "secondary" : "primary"} type="button" disabled={busy} onClick={() => setConfirming(true)}>{open ? "Fermer le Miroir" : "Ouvrir le Miroir"}</button>
</div>
<dl className="nebula-admin-race-figures">
{Object.entries(today.games).map(([mode, games]) => <div key={mode}><dt>{MODE_LABELS[mode]}</dt><dd>{games.started ? `${number(games.started)} partie${games.started > 1 ? "s" : ""} · ${number(games.won)} gagnée${games.won > 1 ? "s" : ""} · ${number(games.lost)} perdue${games.lost > 1 ? "s" : ""}` : "Aucune partie."}</dd></div>)}
<div><dt>Difficile du jour</dt><dd>{today.hard ? `${hardCard?.name || today.hard.cardId} · ordinateur : ${today.hard.par} échanges` : "Tiré à la première partie du jour."}</dd></div>
</dl>
{confirming && <ConfirmModal
title={open ? "Fermer le Miroir brisé ?" : "Ouvrir le Miroir brisé ?"}
message={open ? "Plus aucune nouvelle partie. Une partie déjà commencée peut se terminer." : "La tuile du Miroir brisé apparaît au tableau de la Guilde."}
confirmLabel={open ? "Fermer" : "Ouvrir"}
onClose={async (confirmed) => {
setConfirming(false);
if (confirmed) await onToggle(!open);
}}
/>}
</section>;
}
export function MirrorSettings({ dashboard, catalog, busy, runMutation, refreshDashboard }) {
const { settings, defaults, today } = dashboard.mirrorSettings;
const draft = useSettingsDraft(settings, FIELDS);
const save = async (apply) => {
const next = structuredClone(settings);
apply(next);
const saved = await runMutation(() => updateMirrorSettings(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();
};
return <div className="nebula-admin-expeditions">
<MirrorStatus settings={settings} today={today} catalog={catalog} busy={busy} onToggle={(enabled) => save((next) => { next.enabled = enabled; })} />
{MIRROR_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 prochaines parties. Une partie commencée garde sa limite et ses gains." labelOf={labelOf} formatValue={formatValue} />
</div>;
}