sokko-g/website/src/features/cards/holoFlares.js
Shinuwa 6737a89a1c
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 22m41s
Validate and deploy Sokko G / deploy (push) Successful in 14s
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>
2026-11-22 16:44:32 +01:00

66 lines
3.8 KiB
JavaScript

// Rôle : particules persistantes d'une variation mythique (distinctes des particules d'ouverture) côté navigateur : réglages
// d'une édition (animation, motif, palette, zone, paliers) d'après les animations déclarées par le catalogue (`flareEffects`,
// `flareScopes`), champs d'édition pour un aperçu et comparaison de deux réglages. Les moteurs de rendu sont à part.
export const DEFAULT_FLARE_TUNING = 3;
export const DEFAULT_FLARE_SCOPE = "art";
export const MATCH_HOLO_FLARE_PALETTE = "match-holo";
export const MATCH_HOLO_FLARE_LABEL = "Comme le holo";
export const NO_FLARE = { id: "", motifId: "", paletteId: MATCH_HOLO_FLARE_PALETTE, intensity: DEFAULT_FLARE_TUNING, level: DEFAULT_FLARE_TUNING, count: DEFAULT_FLARE_TUNING, scope: DEFAULT_FLARE_SCOPE };
const TUNING_FIELDS = { intensity: "flareIntensity", level: "flareLevel", count: "flareCount" };
const effectOf = (catalog, id) => catalog?.flareEffects?.find((item) => item.id === id);
// Motif retenu : celui choisi s'il appartient à l'animation, sinon le premier de sa liste ; aucun si elle n'a pas de motifs.
export const flareMotifOf = (effect, motifId) => (effect?.motifs ? (effect.motifs.some((item) => item.id === motifId) ? motifId : effect.motifs[0].id) : null);
// Champs portés par l'édition, comme le serveur les publie : les paliers centraux, le motif par défaut, la palette héritée et
// la zone par défaut ne sont pas transmis, ni les réglages que l'animation n'a pas.
export function flareEditionFields(flare, catalog) {
const effect = effectOf(catalog, flare?.id);
if (!effect) return {};
const motifId = flareMotifOf(effect, flare.motifId);
return {
flareId: effect.id,
...(motifId && motifId !== effect.motifs[0].id ? { flareMotifId: motifId } : {}),
...(flare.paletteId && flare.paletteId !== MATCH_HOLO_FLARE_PALETTE ? { flarePaletteId: flare.paletteId } : {}),
...(flare.scope && flare.scope !== DEFAULT_FLARE_SCOPE ? { flareScope: flare.scope } : {}),
...Object.fromEntries(effect.tunings.filter(({ key }) => flare[key] && flare[key] !== DEFAULT_FLARE_TUNING).map(({ key }) => [TUNING_FIELDS[key], flare[key]]))
};
}
// Réglages éditables d'une édition publiée (ou NO_FLARE), pour l'éditeur des variations.
export function flareOfEdition(edition, catalog) {
const effect = effectOf(catalog, edition?.flareId);
if (!effect) return NO_FLARE;
return {
id: effect.id,
motifId: flareMotifOf(effect, edition.flareMotifId) || "",
paletteId: edition.flarePaletteId || MATCH_HOLO_FLARE_PALETTE,
scope: edition.flareScope || DEFAULT_FLARE_SCOPE,
intensity: edition.flareIntensity || DEFAULT_FLARE_TUNING,
level: edition.flareLevel || DEFAULT_FLARE_TUNING,
count: edition.flareCount || DEFAULT_FLARE_TUNING
};
}
// Deux réglages se valent s'ils publient les mêmes champs.
export const sameFlare = (left, right, catalog) => JSON.stringify(flareEditionFields(left, catalog)) === JSON.stringify(flareEditionFields(right, catalog));
// Réglages affichés pour une édition, ou null : sans palette explicite, les particules prennent celle du holo.
export function resolveFlare(edition, catalog, finishVisual) {
const effect = effectOf(catalog, edition?.flareId);
if (!effect || !finishVisual?.effectPreset) return null;
const palette = edition.flarePaletteId ? catalog?.effectPalettes?.find((item) => item.id === edition.flarePaletteId) : finishVisual.palette;
if (!palette) return null;
const scope = catalog.flareScopes?.some((item) => item.id === edition.flareScope) ? edition.flareScope : DEFAULT_FLARE_SCOPE;
return {
effect,
motifId: flareMotifOf(effect, edition.flareMotifId),
colors: palette.colors,
core: palette.highlight,
intensity: edition.flareIntensity || DEFAULT_FLARE_TUNING,
level: edition.flareLevel || DEFAULT_FLARE_TUNING,
count: edition.flareCount || DEFAULT_FLARE_TUNING,
scope
};
}