Let administrators save particles on mythic variations
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 22m41s
Validate and deploy Sokko G / deploy (push) Successful in 14s

Lightning, twinkles and fireflies move from a visual lab prototype to real
settings. The catalog declares the animations, their motifs, sliders and zones;
migration 24 stores each variation's particles; the service validates and
normalizes them behind a dedicated admin route and records the change in the
history. Published editions carry the particle fields, so every card of the
variation shows them in collections, card sheets and openings. The Particles
tab of the variation editor now saves with the same Enregistrer button as the
finish and tunings, including when a variation is created.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-22 16:44:32 +01:00
parent f77a0ca577
commit 6737a89a1c
21 changed files with 419 additions and 124 deletions

View file

@ -4,11 +4,11 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import { flareEditionFields, MATCH_HOLO_FLARE_PALETTE, NO_FLARE, resolveFlare } from "../website/src/features/cards/holoFlares.js";
import { flareEditionFields, flareOfEdition, MATCH_HOLO_FLARE_PALETTE, NO_FLARE, resolveFlare, sameFlare } from "../website/src/features/cards/holoFlares.js";
import { boltGeometry, boltPath, TARGET_ZONE } from "../website/src/features/cards/holoLightning.js";
import { motifAngle } from "../website/src/features/cards/flareSprites.js";
import { fireflyFade, fireflyHeading } from "../website/src/features/cards/holoFireflies.js";
import { TWINKLE_MOTIFS, twinkleState } from "../website/src/features/cards/holoTwinkle.js";
import { FIREFLY_COUNTS, fireflyFade, fireflyHeading } from "../website/src/features/cards/holoFireflies.js";
import { TWINKLE_COUNTS, twinkleState } from "../website/src/features/cards/holoTwinkle.js";
const catalog = JSON.parse(await readFile(new URL("../website/public/data/cards/catalog.json", import.meta.url), "utf8"));
const seeded = (seed = 7) => () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };
@ -53,10 +53,10 @@ test("on the whole card, bolts start from the card edges and still aim at the il
});
test("flare settings travel on the edition without their default values", () => {
assert.deepEqual(flareEditionFields(NO_FLARE), {});
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "lightning" }), { flareId: "lightning" });
assert.deepEqual(flareEditionFields({ id: "lightning", paletteId: "cosmic", intensity: 5, level: 1, scope: "card" }), { flareId: "lightning", flarePaletteId: "cosmic", flareIntensity: 5, flareLevel: 1, flareScope: "card" });
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "lightning", scope: "art" }), { flareId: "lightning" });
assert.deepEqual(flareEditionFields(NO_FLARE, catalog), {});
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "lightning" }, catalog), { flareId: "lightning" });
assert.deepEqual(flareEditionFields({ id: "lightning", paletteId: "cosmic", intensity: 5, level: 1, scope: "card" }, catalog), { flareId: "lightning", flarePaletteId: "cosmic", flareIntensity: 5, flareLevel: 1, flareScope: "card" });
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "lightning", scope: "art" }, catalog), { flareId: "lightning" });
assert.equal(MATCH_HOLO_FLARE_PALETTE, NO_FLARE.paletteId);
});
@ -82,13 +82,13 @@ test("a twinkle grows past its size, flashes at its peak, then shrinks away", ()
});
test("twinkle settings carry their motif, count and speed, defaults omitted", () => {
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "twinkle" }), { flareId: "twinkle" });
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "twinkle", motifId: "heart", count: 5, level: 1 }), { flareId: "twinkle", flareMotifId: "heart", flareLevel: 1, flareCount: 5 });
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "twinkle" }, catalog), { flareId: "twinkle" });
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "twinkle", motifId: "heart", count: 5, level: 1 }, catalog), { flareId: "twinkle", flareMotifId: "heart", flareLevel: 1, flareCount: 5 });
// Les éclairs n'ont ni motif ni nombre : ces réglages ne voyagent pas avec eux.
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "lightning", motifId: "heart", count: 5 }), { flareId: "lightning" });
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "lightning", motifId: "heart", count: 5 }, catalog), { flareId: "lightning" });
const twinkle = resolveFlare({ flareId: "twinkle", flareMotifId: "snowflake", flareCount: 4 }, catalog, visual);
assert.deepEqual([twinkle.motifId, twinkle.count, twinkle.level], ["snowflake", 4, 3]);
assert.equal(resolveFlare({ flareId: "twinkle", flareMotifId: "comet" }, catalog, visual).motifId, TWINKLE_MOTIFS[0].id);
assert.equal(resolveFlare({ flareId: "twinkle", flareMotifId: "comet" }, catalog, visual).motifId, "four-point-star");
assert.equal(resolveFlare({ flareId: "lightning" }, catalog, visual).motifId, null);
});
@ -102,8 +102,8 @@ test("a firefly fades in, glows, fades out, and wanders around its heading", ()
});
test("fireflies carry their own motif list, count and speed", () => {
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "fireflies" }), { flareId: "fireflies" });
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "fireflies", motifId: "heart", count: 2 }), { flareId: "fireflies", flareMotifId: "heart", flareCount: 2 });
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "fireflies" }, catalog), { flareId: "fireflies" });
assert.deepEqual(flareEditionFields({ ...NO_FLARE, id: "fireflies", motifId: "heart", count: 2 }, catalog), { flareId: "fireflies", flareMotifId: "heart", flareCount: 2 });
// Le reflet n'existe que pour les scintillements : les lucioles reprennent leur motif par défaut.
assert.equal(resolveFlare({ flareId: "fireflies", flareMotifId: "glint" }, catalog, visual).motifId, "firefly");
});
@ -115,3 +115,25 @@ test("a bubble never turns and a heart stays upright, other motifs take any angl
assert.equal(motifAngle("snowflake", angle), angle);
}
});
test("the catalog animations match their render engines", () => {
const effect = (id) => catalog.flareEffects.find((item) => item.id === id);
assert.deepEqual(catalog.flareEffects.map((item) => item.id), ["lightning", "twinkle", "fireflies"]);
// Les libellés du curseur « Nombre » annoncent les nombres que les moteurs visent réellement.
assert.deepEqual(effect("twinkle").tunings.find((tuning) => tuning.key === "count").levels, TWINKLE_COUNTS.map((count) => `≈ ${count}`));
assert.deepEqual(effect("fireflies").tunings.find((tuning) => tuning.key === "count").levels, FIREFLY_COUNTS.map((count) => `≈ ${count}`));
const drawable = new Set(["four-point-star", "glint", "star", "diamond", "heart", "snowflake", "bubble", "firefly"]);
assert.ok(catalog.flareEffects.flatMap((item) => item.motifs || []).every((motif) => drawable.has(motif.id)));
assert.deepEqual(catalog.flareScopes.map((scope) => scope.id), ["art", "card"]);
});
test("a published edition reads back as editable settings, compared by what they publish", () => {
assert.deepEqual(flareOfEdition({ id: "x" }, catalog), NO_FLARE);
const flare = flareOfEdition({ flareId: "twinkle", flareMotifId: "heart", flareScope: "card", flareCount: 5 }, catalog);
assert.deepEqual(flare, { id: "twinkle", motifId: "heart", paletteId: MATCH_HOLO_FLARE_PALETTE, scope: "card", intensity: 3, level: 3, count: 5 });
assert.deepEqual(flareEditionFields(flare, catalog), { flareId: "twinkle", flareMotifId: "heart", flareScope: "card", flareCount: 5 });
// Le premier motif et le motif vide publient la même chose ; un palier que l'animation n'a pas ne compte pas.
assert.ok(sameFlare({ ...NO_FLARE, id: "twinkle", motifId: "" }, { ...NO_FLARE, id: "twinkle", motifId: "four-point-star" }, catalog));
assert.ok(sameFlare({ ...NO_FLARE, id: "lightning", count: 5 }, { ...NO_FLARE, id: "lightning" }, catalog));
assert.ok(!sameFlare({ ...NO_FLARE, id: "lightning" }, NO_FLARE, catalog));
});

View file

@ -195,6 +195,18 @@ test("cards API authenticates dev sessions and protects mutations", async (t) =>
assert.deepEqual(changedFinish.json.catalog.editions.find((edition) => edition.id === "mythic-card-pull-spectral-prism-solar").finishIds, ["spectral-prism-aurora"]);
const restoredFinish = await call(handler, { method: "PUT", path: finishPath, headers: { cookie: sessionCookie, "x-csrf-token": csrfToken }, body: { finishId: "spectral-prism-solar" } });
assert.equal(restoredFinish.status, 200);
// Particules d'une variation : réservées aux administrateurs, validées, publiées dans la configuration des joueurs.
const flarePath = "/api/cards/admin/catalog/mythics/mythic-card-pull-spectral-prism-solar/flare";
const regularFlare = await call(handler, { method: "PUT", path: flarePath, headers: { cookie: `sokkog_cards_session=${regularSession.token}`, "x-csrf-token": regularSession.csrfToken }, body: { id: "lightning" } });
assert.equal(regularFlare.status, 403);
const unknownFlare = await call(handler, { method: "PUT", path: flarePath, headers: { cookie: sessionCookie, "x-csrf-token": csrfToken }, body: { id: "comet" } });
assert.deepEqual([unknownFlare.status, unknownFlare.json.error.code], [400, "FLARE_UNKNOWN"]);
const savedFlare = await call(handler, { method: "PUT", path: flarePath, headers: { cookie: sessionCookie, "x-csrf-token": csrfToken }, body: { id: "fireflies", motifId: "bubble", paletteId: "match-holo", scope: "art", intensity: 3, level: 2, count: 3 } });
assert.equal(savedFlare.status, 200);
const publishedFlare = (await call(handler, { path: "/api/cards/config" })).json.catalog.editions.find((edition) => edition.id === "mythic-card-pull-spectral-prism-solar");
assert.deepEqual([publishedFlare.flareId, publishedFlare.flareMotifId, publishedFlare.flareLevel], ["fireflies", "bubble", 2]);
const clearedFlare = await call(handler, { method: "PUT", path: flarePath, headers: { cookie: sessionCookie, "x-csrf-token": csrfToken }, body: { id: null } });
assert.equal(clearedFlare.json.catalog.editions.find((edition) => edition.id === "mythic-card-pull-spectral-prism-solar").flareId, undefined);
const collectionOpening = await call(handler, { method: "PUT", path: "/api/cards/admin/catalog/collections/astral-genesis/mythic-opening", headers: { cookie: sessionCookie, "x-csrf-token": csrfToken }, body: { particleShapeId: null, particlePaletteId: "match-holo" } });
assert.equal(collectionOpening.status, 200);
const refreshedConfig = await call(handler, { path: "/api/cards/config" });

View file

@ -1245,6 +1245,66 @@ test("a mythic variation tunes its palette intensity and its effect level, kept
database.close();
});
test("a mythic variation saves its particles, normalized, audited and kept across restarts and finish changes", () => {
const now = 1_800_000_000_000;
const database = new CardsDatabase(":memory:");
const service = new CardsService({ database, catalog: baseCatalog, now: () => now, random: () => 0 });
const admin = service.upsertPlayer({ discordId: "flare-admin", displayName: "Admin", isAdmin: true });
const player = service.upsertPlayer({ discordId: "flare-player", displayName: "Player" });
service.setCardMythicConfig(admin.id, "mythic-card-pull", { finishIds: ["prismatic-backdrop-solar"] });
const mythic = "mythic-card-pull-prismatic-backdrop-solar";
const editionOf = (catalog) => catalog.editions.find((edition) => edition.id === mythic);
const flareFields = (edition) => Object.fromEntries(Object.entries(edition).filter(([key]) => key.startsWith("flare")));
// Une variation neuve n'a pas de particules.
assert.deepEqual(flareFields(editionOf(service.catalog)), {});
assert.throws(() => service.setMythicFlare(player.id, mythic, { id: "lightning" }), /administrateur/);
assert.throws(() => service.setMythicFlare(admin.id, "unknown-mythic", { id: "lightning" }), /introuvable/);
assert.throws(() => service.setMythicFlare(admin.id, mythic, { id: "comet" }), /n’existe pas/);
assert.throws(() => service.setMythicFlare(admin.id, mythic, { id: "twinkle", motifId: "firefly" }), /motif/);
assert.throws(() => service.setMythicFlare(admin.id, mythic, { id: "lightning", paletteId: "neon" }), /palette/);
assert.throws(() => service.setMythicFlare(admin.id, mythic, { id: "lightning", scope: "sky" }), /zone/);
assert.throws(() => service.setMythicFlare(admin.id, mythic, { id: "lightning", level: 6 }), /paliers/);
assert.throws(() => service.setMythicFlare(admin.id, mythic, { id: null }), /déjà ces particules/);
// Sans motif, une animation qui en déclare prend le premier : rien à publier de plus que l'animation.
assert.deepEqual(flareFields(editionOf(service.setMythicFlare(admin.id, mythic, { id: "twinkle" }).catalog)), { flareId: "twinkle" });
// Réglages par défaut : seule l'animation est publiée ; un nombre que les éclairs ne déclarent pas revient au centre.
assert.deepEqual(flareFields(editionOf(service.setMythicFlare(admin.id, mythic, { id: "lightning", paletteId: "match-holo", scope: "art", count: 5 }).catalog)), { flareId: "lightning" });
assert.throws(() => service.setMythicFlare(admin.id, mythic, { id: "lightning" }), /déjà ces particules/);
const twinkle = { id: "twinkle", motifId: "heart", paletteId: "cosmic", scope: "card", intensity: 2, level: 4, count: 5 };
assert.deepEqual(flareFields(editionOf(service.setMythicFlare(admin.id, mythic, twinkle).catalog)), { flareId: "twinkle", flareMotifId: "heart", flarePaletteId: "cosmic", flareScope: "card", flareIntensity: 2, flareLevel: 4, flareCount: 5 });
const audit = database.db.prepare("SELECT entity_id, details_json FROM audit_log WHERE event_type = 'catalog_mythic_flare_updated' ORDER BY rowid DESC").get();
assert.deepEqual([audit.entity_id, JSON.parse(audit.details_json)], ["mythic-card-pull", { editionId: mythic, flare: twinkle }]);
// Les particules suivent la variation quand sa finition change, et survivent au redémarrage.
service.setMythicFinish(admin.id, mythic, "spectral-prism-aurora");
assert.equal(editionOf(service.catalog).flareId, "twinkle");
const reloaded = new CardsService({ database, catalog: baseCatalog, now: () => now });
assert.equal(editionOf(reloaded.catalog).flareMotifId, "heart");
// Une animation que le catalogue ne connaît plus n'est simplement pas publiée.
database.db.prepare("UPDATE mythic_variations SET flare_id = 'retired-flare' WHERE edition_id = ?").run(mythic);
assert.deepEqual(flareFields(editionOf(new CardsService({ database, catalog: baseCatalog, now: () => now }).catalog)), {});
database.db.prepare("UPDATE mythic_variations SET flare_id = 'twinkle' WHERE edition_id = ?").run(mythic);
assert.throws(() => database.db.prepare("UPDATE mythic_variations SET flare_count = 0 WHERE edition_id = ?").run(mythic), /CHECK/);
// Une animation vide retire les particules.
const cleared = reloaded.setMythicFlare(admin.id, mythic, { id: "" });
assert.deepEqual(flareFields(editionOf(cleared.catalog)), {});
assert.deepEqual(JSON.parse(database.db.prepare("SELECT details_json FROM audit_log WHERE event_type = 'catalog_mythic_flare_updated' ORDER BY rowid DESC").get().details_json), { editionId: mythic, flare: null });
database.close();
});
test("particle animations are declared by the catalog and checked on editions", () => {
const broken = (change) => { const catalog = structuredClone(rawCatalog); change(catalog); return () => prepareVersionedCatalog(catalog); };
assert.throws(broken((catalog) => { catalog.flareScopes.reverse(); }), /flareScopes must start with art/);
assert.throws(broken((catalog) => { catalog.flareEffects[1].motifs.push({ id: "heart", label: "Cœur bis" }); }), /Duplicate|unique|motifs/i);
assert.throws(broken((catalog) => { catalog.flareEffects[0].tunings.push({ key: "speed", label: "Vitesse", levels: ["1", "2", "3", "4", "5"] }); }), /tunings need a known key/);
assert.throws(broken((catalog) => { catalog.flareEffects[0].tunings[1].levels.pop(); }), /tunings need a known key/);
assert.throws(broken((catalog) => { catalog.editions.find((edition) => edition.rarity === "common").flareId = "lightning"; }), /invalid particles/);
assert.doesNotThrow(() => prepareVersionedCatalog(structuredClone(rawCatalog)));
});
test("holographic effect levels and intensities are declared by the catalog and checked on editions", () => {
assert.deepEqual(rawCatalog.effectIntensity.levels, ["Très douce", "Douce", "Normale", "Intense", "Très intense"]);
assert.deepEqual(rawCatalog.effectPresets.filter((preset) => preset.level).map((preset) => preset.id), ["spectral-prism", "prismatic-backdrop", "shattered-ice"]);