Let administrators save particles on mythic variations
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:
parent
f77a0ca577
commit
6737a89a1c
21 changed files with 419 additions and 124 deletions
|
|
@ -498,6 +498,12 @@ export function createCardsApiHandler({
|
|||
json(res, 200, service.setMythicTuning(session.player.id, mythicTuning[0], { intensity: body.intensity, level: body.level }));
|
||||
return true;
|
||||
}
|
||||
const mythicFlare = routeMatch(url.pathname, /^\/api\/cards\/admin\/catalog\/mythics\/([^/]+)\/flare$/);
|
||||
if (req.method === "PUT" && mythicFlare) {
|
||||
const body = await readBody(req);
|
||||
json(res, 200, service.setMythicFlare(session.player.id, mythicFlare[0], { id: body.id ?? null, motifId: body.motifId ?? null, paletteId: body.paletteId ?? null, scope: body.scope ?? null, intensity: body.intensity, level: body.level, count: body.count }));
|
||||
return true;
|
||||
}
|
||||
const mythicFinish = routeMatch(url.pathname, /^\/api\/cards\/admin\/catalog\/mythics\/([^/]+)\/finish$/);
|
||||
if (req.method === "PUT" && mythicFinish) {
|
||||
json(res, 200, service.setMythicFinish(session.player.id, mythicFinish[0], (await readBody(req)).finishId));
|
||||
|
|
|
|||
|
|
@ -20,6 +20,70 @@ export const DEFAULT_EFFECT_TUNING = 3;
|
|||
export const isEffectTuning = (value) => Number.isInteger(value) && value >= 1 && value <= EFFECT_TUNING_STEPS;
|
||||
const validTuningScale = (scale) => typeof scale?.label === "string" && scale.label.length > 0 && Array.isArray(scale.levels)
|
||||
&& scale.levels.length === EFFECT_TUNING_STEPS && scale.levels.every((label) => typeof label === "string" && label.length > 0);
|
||||
|
||||
// Particules persistantes d'une variation mythique : une animation du catalogue (`flareEffects`), un motif si elle en
|
||||
// déclare, une palette holographique (celle de la finition par défaut), une zone (`flareScopes`) et les paliers qu'elle
|
||||
// déclare. Les réglages par défaut (palier central, premier motif, palette héritée, zone « art ») ne sont pas publiés.
|
||||
export const DEFAULT_FLARE_SCOPE = "art";
|
||||
export const FLARE_TUNING_KEYS = ["intensity", "level", "count"];
|
||||
const FLARE_TUNING_FIELDS = { intensity: "flareIntensity", level: "flareLevel", count: "flareCount" };
|
||||
|
||||
function validateFlares(catalog) {
|
||||
const scopeIds = requireUnique(catalog.flareScopes || [], "flareScopes");
|
||||
if (catalog.flareScopes?.[0]?.id !== DEFAULT_FLARE_SCOPE || catalog.flareScopes.some((scope) => !scope.label)) throw new TypeError(`Cards catalog flareScopes must start with ${DEFAULT_FLARE_SCOPE} and label every scope.`);
|
||||
requireUnique(catalog.flareEffects || [], "flareEffects");
|
||||
for (const effect of catalog.flareEffects || []) {
|
||||
if (!effect.label) throw new TypeError(`Flare effect ${effect.id} needs a label.`);
|
||||
if (effect.motifs != null) {
|
||||
if (!Array.isArray(effect.motifs) || !effect.motifs.length || effect.motifs.some((motif) => !motif.label)) throw new TypeError(`Flare effect ${effect.id} needs labelled motifs.`);
|
||||
requireUnique(effect.motifs, `flare effect ${effect.id} motifs`);
|
||||
}
|
||||
if (!Array.isArray(effect.tunings) || effect.tunings.some((tuning) => !FLARE_TUNING_KEYS.includes(tuning.key) || !validTuningScale(tuning))
|
||||
|| new Set(effect.tunings.map((tuning) => tuning.key)).size !== effect.tunings.length) {
|
||||
throw new TypeError(`Flare effect ${effect.id} tunings need a known key, a label and ${EFFECT_TUNING_STEPS} level labels.`);
|
||||
}
|
||||
}
|
||||
return scopeIds;
|
||||
}
|
||||
|
||||
// Réglages normalisés d'un flare, ou un code d'erreur : `{ flare }` (null pour « aucune particule ») ou `{ error }`. Un palier
|
||||
// que l'animation ne déclare pas revient au centre ; sans motif, celle qui en déclare prend le premier ; un motif inconnu est
|
||||
// refusé ; une animation sans motifs ignore celui qu'on lui donne.
|
||||
export function normalizeFlare(catalog, input) {
|
||||
if (!input?.id) return { flare: null };
|
||||
const effect = catalog.flareEffects?.find((item) => item.id === input.id);
|
||||
if (!effect) return { error: "FLARE_UNKNOWN" };
|
||||
const motifId = effect.motifs ? input.motifId || effect.motifs[0].id : null;
|
||||
if (effect.motifs && !effect.motifs.some((motif) => motif.id === motifId)) return { error: "FLARE_MOTIF_INVALID" };
|
||||
const paletteId = input.paletteId && input.paletteId !== MATCH_HOLO_PALETTE_ID ? input.paletteId : null;
|
||||
if (paletteId && !catalog.effectPalettes.some((palette) => palette.id === paletteId)) return { error: "FLARE_PALETTE_INVALID" };
|
||||
const scope = input.scope || DEFAULT_FLARE_SCOPE;
|
||||
if (!catalog.flareScopes?.some((item) => item.id === scope)) return { error: "FLARE_SCOPE_INVALID" };
|
||||
const declared = new Set(effect.tunings.map((tuning) => tuning.key));
|
||||
const tunings = {};
|
||||
for (const key of FLARE_TUNING_KEYS) {
|
||||
const value = input[key] ?? DEFAULT_EFFECT_TUNING;
|
||||
if (!isEffectTuning(value)) return { error: "FLARE_TUNING_INVALID" };
|
||||
tunings[key] = declared.has(key) ? value : DEFAULT_EFFECT_TUNING;
|
||||
}
|
||||
return { flare: { id: effect.id, motifId, paletteId, scope, ...tunings } };
|
||||
}
|
||||
|
||||
// Champs publiés sur l'édition pour un flare normalisé (ou des réglages enregistrés qui ne valent plus rien : aucun champ).
|
||||
export function publishedFlare(catalog, stored) {
|
||||
const { flare } = normalizeFlare(catalog, stored);
|
||||
if (!flare) return {};
|
||||
const effect = catalog.flareEffects.find((item) => item.id === flare.id);
|
||||
return {
|
||||
flareId: flare.id,
|
||||
...(flare.motifId && flare.motifId !== effect.motifs[0].id ? { flareMotifId: flare.motifId } : {}),
|
||||
...(flare.paletteId ? { flarePaletteId: flare.paletteId } : {}),
|
||||
...(flare.scope !== DEFAULT_FLARE_SCOPE ? { flareScope: flare.scope } : {}),
|
||||
...Object.fromEntries(FLARE_TUNING_KEYS.filter((key) => flare[key] !== DEFAULT_EFFECT_TUNING).map((key) => [FLARE_TUNING_FIELDS[key], flare[key]]))
|
||||
};
|
||||
}
|
||||
|
||||
const EDITION_FLARE_FIELDS = ["flareId", "flareMotifId", "flarePaletteId", "flareScope", ...Object.values(FLARE_TUNING_FIELDS)];
|
||||
const CARD_IMAGE_PATTERN = /^\/static\/img\/cards\/[a-z0-9-]+\/(?:common|rare|epic|legendary)\/[a-z0-9_]+\.webp$/;
|
||||
const PACK_BACK_IMAGE_PATTERN = /^\/static\/img\/cards\/[a-z0-9-]+\/back\.webp$/;
|
||||
// Étiquettes d'expédition : vocabulaire fermé, par famille (personnage, lieu, thème, objet).
|
||||
|
|
@ -137,6 +201,7 @@ export function validateCardsCatalog(catalog) {
|
|||
if (preset.level != null && !validTuningScale(preset.level)) throw new TypeError(`Holographic effect preset ${preset.id} level needs a label and ${EFFECT_TUNING_STEPS} level labels.`);
|
||||
}
|
||||
if (!validTuningScale(catalog.effectIntensity)) throw new TypeError(`Cards catalog effectIntensity needs a label and ${EFFECT_TUNING_STEPS} level labels.`);
|
||||
validateFlares(catalog);
|
||||
if (catalog.cardFormats?.[0]?.id !== STANDARD_FORMAT || catalog.cardFormats.some((format) => !format.label) || !catalog.cardFormats.some((format) => format.id === FULL_ART_FORMAT)) {
|
||||
throw new TypeError("Cards catalog must declare the standard and full-art formats.");
|
||||
}
|
||||
|
|
@ -252,6 +317,12 @@ export function validateCardsCatalog(catalog) {
|
|||
if (edition.holoIntensity != null && !isEffectTuning(edition.holoIntensity)) throw new TypeError(`Edition ${edition.id} has an unknown holographic intensity.`);
|
||||
if (edition.holoLevel != null && (!preset.level || !isEffectTuning(edition.holoLevel))) throw new TypeError(`Edition ${edition.id} has a level its effect does not declare.`);
|
||||
}
|
||||
// Une édition du catalogue versionné peut déclarer des particules ; elles doivent être valides et sur une finition holo.
|
||||
if (EDITION_FLARE_FIELDS.some((field) => edition[field] != null)) {
|
||||
const holo = catalog.finishes.find((finish) => finish.id === edition.finishIds[0])?.effectPresetId;
|
||||
const { flare, error } = normalizeFlare(catalog, { id: edition.flareId, motifId: edition.flareMotifId ?? catalog.flareEffects?.find((item) => item.id === edition.flareId)?.motifs?.[0].id, paletteId: edition.flarePaletteId, scope: edition.flareScope, intensity: edition.flareIntensity, level: edition.flareLevel, count: edition.flareCount });
|
||||
if (!holo || error || !flare) throw new TypeError(`Edition ${edition.id} has invalid particles.`);
|
||||
}
|
||||
if (destinationCards.some((card) => card.id === edition.cardId) && edition.rarity !== "rare") throw new TypeError(`Destination card edition ${edition.id} must be rare.`);
|
||||
if (edition.promotional && edition.legendaryEditionId) throw new TypeError(`Promotional edition ${edition.id} cannot require a legendary parent.`);
|
||||
if (edition.rarity === "mythic" && !edition.promotional) {
|
||||
|
|
@ -447,7 +518,8 @@ export function buildPublishedCatalog(versionedCatalog, { variations = [], openi
|
|||
legendaryEditionId: parent.id,
|
||||
...(variation.status === "retired" ? { retired: true } : {}),
|
||||
...(isEffectTuning(variation.intensity) && variation.intensity !== DEFAULT_EFFECT_TUNING ? { holoIntensity: variation.intensity } : {}),
|
||||
...(isEffectTuning(variation.level) && variation.level !== DEFAULT_EFFECT_TUNING && effectOf(variation.finishId)?.level ? { holoLevel: variation.level } : {})
|
||||
...(isEffectTuning(variation.level) && variation.level !== DEFAULT_EFFECT_TUNING && effectOf(variation.finishId)?.level ? { holoLevel: variation.level } : {}),
|
||||
...publishedFlare(catalog, variation.flare)
|
||||
};
|
||||
});
|
||||
// Chaque variation suit sa carte légendaire, dans l'ordre des finitions.
|
||||
|
|
|
|||
|
|
@ -493,6 +493,18 @@ export const MIGRATIONS = [
|
|||
`
|
||||
ALTER TABLE mythic_variations ADD COLUMN holo_intensity INTEGER NOT NULL DEFAULT 3 CHECK (holo_intensity BETWEEN 1 AND 5);
|
||||
ALTER TABLE mythic_variations ADD COLUMN holo_level INTEGER NOT NULL DEFAULT 3 CHECK (holo_level BETWEEN 1 AND 5);
|
||||
`,
|
||||
// Particules persistantes d'une variation mythique : animation (`flare_id`, NULL pour aucune), motif, palette (NULL pour celle
|
||||
// de la finition), zone (NULL pour l'illustration) et paliers de 1 à 5. Les identifiants viennent du catalogue versionné et
|
||||
// sont validés par le service ; des réglages que le catalogue ne connaît plus ne sont simplement pas publiés.
|
||||
`
|
||||
ALTER TABLE mythic_variations ADD COLUMN flare_id TEXT;
|
||||
ALTER TABLE mythic_variations ADD COLUMN flare_motif_id TEXT;
|
||||
ALTER TABLE mythic_variations ADD COLUMN flare_palette_id TEXT;
|
||||
ALTER TABLE mythic_variations ADD COLUMN flare_scope TEXT;
|
||||
ALTER TABLE mythic_variations ADD COLUMN flare_intensity INTEGER NOT NULL DEFAULT 3 CHECK (flare_intensity BETWEEN 1 AND 5);
|
||||
ALTER TABLE mythic_variations ADD COLUMN flare_level INTEGER NOT NULL DEFAULT 3 CHECK (flare_level BETWEEN 1 AND 5);
|
||||
ALTER TABLE mythic_variations ADD COLUMN flare_count INTEGER NOT NULL DEFAULT 3 CHECK (flare_count BETWEEN 1 AND 5);
|
||||
`
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import { createHash, randomBytes, randomInt, randomUUID } from "node:crypto";
|
||||
import { normalizeReward } from "./rewards.js";
|
||||
import { MASS_RECYCLE_RARITIES, planRecycling, spareQuantity, validateShopSetting } from "./stardust.js";
|
||||
import { DEFAULT_EFFECT_TUNING, FULL_ART_FORMAT, isEffectTuning, buildPublishedCatalog, collectionDrawableEditions, createCatalogIndex, holographicFinishIds, isMythicEditionIdOf, legendaryParentEdition, MATCH_HOLO_PALETTE_ID, mythicEditionId, publicCatalog, validateRarityWeights } from "./catalog.js";
|
||||
import { DEFAULT_EFFECT_TUNING, DEFAULT_FLARE_SCOPE, FULL_ART_FORMAT, isEffectTuning, normalizeFlare, buildPublishedCatalog, collectionDrawableEditions, createCatalogIndex, holographicFinishIds, isMythicEditionIdOf, legendaryParentEdition, MATCH_HOLO_PALETTE_ID, mythicEditionId, publicCatalog, validateRarityWeights } from "./catalog.js";
|
||||
import { computeStreak, DAILY_REPEAT_WINDOW_DAYS, dailyCandidates, dailyDayKey, dailyZoom, drawDailyPuzzle, guessHint, isDayKey, MAX_DAILY_GUESSES, nextDailyAt, shiftDayKey } from "./daily.js";
|
||||
import { calculateRecharge, pinnedRecharge, drawPack, drawShopPack, MAX_RECHARGE_INTERVAL_MS, MAX_RESERVE_OPENINGS, MIN_RECHARGE_INTERVAL_MS, spendOpening } from "./game-rules.js";
|
||||
import { DEFAULT_DESTINATIONS_PATH, loadExpeditionDestinations } from "./expedition-content.js";
|
||||
|
|
@ -48,6 +48,20 @@ const DAY_MS = 24 * 60 * 60 * 1000;
|
|||
const INACTIVE_ACCOUNT_MS = 730 * DAY_MS;
|
||||
const IDEMPOTENCY_TTL_MS = 30 * DAY_MS;
|
||||
|
||||
// Particules enregistrées d'une variation, telles que la base les garde ; le catalogue les normalise à la publication.
|
||||
function flareOfRow(row) {
|
||||
if (!row.flare_id) return null;
|
||||
return { id: row.flare_id, motifId: row.flare_motif_id, paletteId: row.flare_palette_id, scope: row.flare_scope, intensity: row.flare_intensity, level: row.flare_level, count: row.flare_count };
|
||||
}
|
||||
|
||||
const FLARE_ERROR_MESSAGES = {
|
||||
FLARE_UNKNOWN: "Cette animation de particules n’existe pas.",
|
||||
FLARE_MOTIF_INVALID: "Choisissez un motif proposé par cette animation.",
|
||||
FLARE_PALETTE_INVALID: "Choisissez une palette de particules existante.",
|
||||
FLARE_SCOPE_INVALID: "Choisissez la zone des particules : l’illustration ou toute la carte.",
|
||||
FLARE_TUNING_INVALID: "Choisissez des paliers de particules entre 1 et 5."
|
||||
};
|
||||
|
||||
export class CardsService {
|
||||
// `destinations` : destinations des Expéditions validées ; sans elles, celles du dépôt (services/cards/content).
|
||||
// `alerts` : { available, publicOrigin } pour les alertes Discord des Expéditions (bot configuré, lien des messages).
|
||||
|
|
@ -153,8 +167,8 @@ export class CardsService {
|
|||
const collectionIds = new Set(versioned.collections.map((collection) => collection.id));
|
||||
const shapeIds = new Set(versioned.particleShapes.map((shape) => shape.id));
|
||||
const paletteIds = new Set([...versioned.particlePalettes.map((palette) => palette.id), MATCH_HOLO_PALETTE_ID]);
|
||||
const variations = this.db.prepare("SELECT edition_id, card_id, finish_id, status, holo_intensity, holo_level FROM mythic_variations").all()
|
||||
.map((row) => ({ editionId: row.edition_id, cardId: row.card_id, finishId: row.finish_id, status: row.status, intensity: row.holo_intensity, level: row.holo_level }))
|
||||
const variations = this.db.prepare("SELECT edition_id, card_id, finish_id, status, holo_intensity, holo_level, flare_id, flare_motif_id, flare_palette_id, flare_scope, flare_intensity, flare_level, flare_count FROM mythic_variations").all()
|
||||
.map((row) => ({ editionId: row.edition_id, cardId: row.card_id, finishId: row.finish_id, status: row.status, intensity: row.holo_intensity, level: row.holo_level, flare: flareOfRow(row) }))
|
||||
.filter((row) => holographic.has(row.finishId) && legendaryParentEdition(versioned, row.cardId) && isMythicEditionIdOf(row.editionId, row.cardId));
|
||||
const openingSettings = this.db.prepare("SELECT scope, target_id, particle_shape_id, particle_palette_id FROM mythic_opening_settings ORDER BY scope, target_id").all()
|
||||
.map((row) => ({
|
||||
|
|
@ -325,6 +339,27 @@ export class CardsService {
|
|||
return { catalog: publicCatalog(this.catalog) };
|
||||
}
|
||||
|
||||
// Règle les particules d'une variation, ou les retire (`id` vide). Les réglages sont normalisés : un palier que l'animation
|
||||
// ne déclare pas revient au centre, la palette de la finition et la zone « illustration » sont stockées comme absentes.
|
||||
setMythicFlare(playerId, editionId, input = {}) {
|
||||
this.requireAdmin(playerId);
|
||||
const versioned = this.versionedCatalog;
|
||||
const row = this.db.prepare("SELECT card_id, flare_id, flare_motif_id, flare_palette_id, flare_scope, flare_intensity, flare_level, flare_count FROM mythic_variations WHERE edition_id = ?").get(editionId);
|
||||
if (!row || !versioned.cards.some((item) => item.id === row.card_id)) fail(404, "MYTHIC_NOT_FOUND", "Variation mythique introuvable.");
|
||||
const { flare, error } = normalizeFlare(versioned, input);
|
||||
if (error) fail(400, error, FLARE_ERROR_MESSAGES[error]);
|
||||
const stored = flare ? [flare.id, flare.motifId, flare.paletteId, flare.scope === DEFAULT_FLARE_SCOPE ? null : flare.scope, flare.intensity, flare.level, flare.count] : [null, null, null, null, DEFAULT_EFFECT_TUNING, DEFAULT_EFFECT_TUNING, DEFAULT_EFFECT_TUNING];
|
||||
const current = [row.flare_id, row.flare_motif_id, row.flare_palette_id, row.flare_scope, row.flare_intensity, row.flare_level, row.flare_count];
|
||||
if (stored.every((value, index) => value === current[index])) fail(400, "FLARE_UNCHANGED", "La variation a déjà ces particules.");
|
||||
this.database.transaction(() => {
|
||||
this.db.prepare("UPDATE mythic_variations SET flare_id = ?, flare_motif_id = ?, flare_palette_id = ?, flare_scope = ?, flare_intensity = ?, flare_level = ?, flare_count = ?, updated_at = ?, updated_by = ? WHERE edition_id = ?")
|
||||
.run(...stored, this.now(), playerId, editionId);
|
||||
this.audit(playerId, "catalog_mythic_flare_updated", row.card_id, { editionId, flare });
|
||||
this.reloadCatalog();
|
||||
});
|
||||
return { catalog: publicCatalog(this.catalog) };
|
||||
}
|
||||
|
||||
requireCollection(collectionId) {
|
||||
if (!this.versionedCatalog.collections.some((collection) => collection.id === collectionId)) fail(404, "COLLECTION_NOT_FOUND", "Collection introuvable.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue