Prototype lightning, twinkle and firefly particles in the visual lab

The Particles tab of the visual lab now previews three persistent particle
animations for mythic cards, drawn on a canvas inside the illustration or over
the whole card. Lightning bolts grow from the edges towards a random point near
the hero and pass behind a cut-out hero with the prismatic parallax. Twinkles
pop chosen motifs in and out with a light cross at their peak. Fireflies drift
on winding paths, pulse and move away from the pointer. Each animation offers a
palette, a zone and its own sliders, runs only on a large or hovered card, and
stays still under reduced motion. Nothing is saved on the variations yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-22 16:07:22 +01:00
parent 9f70bea523
commit f77a0ca577
15 changed files with 1779 additions and 16 deletions

View file

@ -0,0 +1,85 @@
// Rôle : particules persistantes d'une variation mythique (distinctes des particules d'ouverture) : les animations
// disponibles, leurs réglages, et la résolution des réglages d'une édition (animation, motif, palette, zone, paliers).
// Prototype de l'Atelier visuel : les animations entreront au catalogue quand elles seront enregistrées sur les variations.
import { FIREFLY_COUNTS, FIREFLY_MOTIFS } from "./holoFireflies.js";
import { TWINKLE_COUNTS, TWINKLE_MOTIFS } from "./holoTwinkle.js";
export const DEFAULT_FLARE_TUNING = 3;
export const MATCH_HOLO_FLARE_PALETTE = "match-holo";
export const MATCH_HOLO_FLARE_LABEL = "Comme le holo";
const INTENSITY = { key: "intensity", label: "Intensité", levels: ["Très douce", "Douce", "Normale", "Intense", "Très intense"] };
// Chaque animation déclare ses curseurs (paliers de 1 à 5, le 3 au centre) et, le cas échéant, ses motifs.
export const FLARE_EFFECTS = [
{
id: "lightning",
label: "Éclairs",
tunings: [INTENSITY, { key: "level", label: "Fréquence", levels: ["Très rare", "Rare", "Normale", "Fréquente", "Déchaînée"] }]
},
{
id: "twinkle",
label: "Scintillements",
motifs: TWINKLE_MOTIFS,
tunings: [
{ key: "count", label: "Nombre", levels: TWINKLE_COUNTS.map((count) => `≈ ${count}`) },
{ key: "level", label: "Vitesse", levels: ["Très lente", "Lente", "Normale", "Rapide", "Très rapide"] },
INTENSITY
]
},
{
id: "fireflies",
label: "Lucioles",
motifs: FIREFLY_MOTIFS,
tunings: [
{ key: "count", label: "Nombre", levels: FIREFLY_COUNTS.map((count) => `≈ ${count}`) },
{ key: "level", label: "Vitesse", levels: ["Très lente", "Lente", "Normale", "Rapide", "Très rapide"] },
INTENSITY
]
}
];
// Zone des particules : l'illustration seule (par défaut) ou toute la carte, utile aux cartes à illustration carrée.
export const DEFAULT_FLARE_SCOPE = "art";
export const FLARE_SCOPES = [{ id: "art", label: "Illustration" }, { id: "card", label: "Toute la carte" }];
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 = (id) => FLARE_EFFECTS.find((item) => item.id === id);
// Motif retenu : celui choisi s'il appartient à l'animation, sinon le premier de sa liste.
const motifOf = (effect, motifId) => (effect?.motifs ? (effect.motifs.some((item) => item.id === motifId) ? motifId : effect.motifs[0].id) : null);
// Champs portés par l'édition ; 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) {
const effect = effectOf(flare?.id);
if (!effect) return {};
const motifId = motifOf(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 } : {}),
...Object.fromEntries(effect.tunings.filter(({ key }) => flare[key] && flare[key] !== DEFAULT_FLARE_TUNING).map(({ key }) => [TUNING_FIELDS[key], flare[key]])),
...(flare.scope && flare.scope !== DEFAULT_FLARE_SCOPE ? { flareScope: flare.scope } : {})
};
}
// 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(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 = FLARE_SCOPES.some((item) => item.id === edition.flareScope) ? edition.flareScope : DEFAULT_FLARE_SCOPE;
return {
effect,
motifId: motifOf(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
};
}