sokko-g/website/src/features/cards/rendering/holoFlares.js
Shinuwa 166790245f Turn the comments that describe functions into JSDoc so the editor shows them on hover
The 669 // comments sitting right above a function, method or hook become
/** */ blocks, unchanged in wording; eslint directives stay right above the
line they target. website/AGENTS.md now asks for JSDoc on function comments
and // inside function bodies. ExpeditionPlanner.jsx grew past 300 lines and
gets its full header, as the header test requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 11:51:47 +01:00

72 lines
3.9 KiB
JavaScript

/**
* @file 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
};
}