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

@ -11,6 +11,7 @@ const EVENT_LABELS = {
catalog_card_mythic_updated: "Variations mythiques modifiées",
catalog_mythic_finish_changed: "Finition mythique changée",
catalog_mythic_tuning_changed: "Réglages mythiques changés",
catalog_mythic_flare_updated: "Particules mythiques changées",
catalog_collection_opening_updated: "Effets d’ouverture modifiés",
collection_opened: "Collection ouverte aux joueurs",
collection_closed: "Collection fermée aux joueurs",
@ -59,6 +60,22 @@ function mythicTuningDetail(entry, catalog) {
return [`${card} · ${finish?.label || entry.details.editionId}`, catalog.effectIntensity && step(catalog.effectIntensity, entry.details.intensity), level && step(level, entry.details.level)].filter(Boolean).join(" · ");
}
// Particules d'une variation : animation, motif et paliers déclarés, ou leur retrait.
function mythicFlareDetail(entry, catalog) {
const card = catalog.cards.find((item) => item.id === entry.entityId)?.name || entry.entityId;
const edition = catalog.editions.find((item) => item.id === entry.details.editionId);
const finish = catalog.finishes.find((item) => item.id === edition?.finishIds[0]);
const flare = entry.details.flare;
const effect = catalog.flareEffects?.find((item) => item.id === flare?.id);
const settings = !flare ? ["particules retirées"] : [
effect?.label || flare.id,
effect?.motifs?.find((item) => item.id === flare.motifId)?.label,
flare.scope === "card" ? "toute la carte" : null,
...(effect?.tunings || []).map((scale) => `${scale.label.toLowerCase()} ${(scale.levels[flare[scale.key] - 1] || flare[scale.key]).toLowerCase()}`)
];
return [`${card} · ${finish?.label || entry.details.editionId}`, ...settings].filter(Boolean).join(" · ");
}
function eventDetail(entry, catalog) {
const { details, campaignName } = entry;
switch (entry.type) {
@ -71,6 +88,7 @@ function eventDetail(entry, catalog) {
case "catalog_card_mythic_updated": return mythicDetail(entry, catalog);
case "catalog_mythic_finish_changed": return mythicFinishDetail(entry, catalog);
case "catalog_mythic_tuning_changed": return mythicTuningDetail(entry, catalog);
case "catalog_mythic_flare_updated": return mythicFlareDetail(entry, catalog);
case "catalog_collection_opening_updated":
case "collection_opened":
case "collection_closed": return collectionName(entry, catalog);

View file

@ -71,7 +71,7 @@ function HolographicBench({ catalog, effects: allEffects, previewCard }) {
const formatId = fittingFormat(catalog, previewCard, preset.id, value.formatId);
const finish = catalog.finishes.find((item) => item.effectPresetId === preset.id && item.paletteId === value.paletteId && item.formatId === formatId)
|| catalog.finishes.find((item) => item.effectPresetId === preset.id);
return { id: `admin-effect-preview-${preset.id}`, cardId: previewCard.id, rarity: "mythic", finishIds: [finish?.id], promotional: false, ...tuningEditionFields(preset, value), ...flareEditionFields(value.flare) };
return { id: `admin-effect-preview-${preset.id}`, cardId: previewCard.id, rarity: "mythic", finishIds: [finish?.id], promotional: false, ...tuningEditionFields(preset, value), ...flareEditionFields(value.flare, catalog) };
};
return <div className="nds-card nebula-admin-lab-bench">

View file

@ -1,10 +1,12 @@
// Rôle : configure l'ouverture mythique d'une carte légendaire et ses variations. L'ouverture s'enregistre à chaque
// changement ; une variation se règle dans le panneau à onglets partagé avec l'Atelier visuel et s'enregistre avec son bouton.
// changement ; une variation (finition, paliers, particules) se règle dans le panneau à onglets partagé avec l'Atelier visuel
// et s'enregistre avec son bouton.
// Changer la finition d'une variation garde son identifiant : les joueurs gardent leurs exemplaires et voient la nouvelle finition.
import { Tooltip } from "../../../components/Tooltip.jsx";
import { useState } from "react";
import { ConfirmModal } from "../../../components/ToolboxModals.jsx";
import { updateCardMythic, updateMythicFinish, updateMythicTuning } from "../cardsApi.js";
import { updateCardMythic, updateMythicFinish, updateMythicFlare, updateMythicTuning } from "../cardsApi.js";
import { flareEditionFields, flareMotifOf, flareOfEdition, NO_FLARE, sameFlare } from "../holoFlares.js";
import { NebulaCard } from "../NebulaCard.jsx";
import { resolveMythicOpeningStyle, withCardOpeningSetting } from "../openingEffects.js";
import { openingSettingFor, withoutOpeningSetting } from "./catalogSettings.js";
@ -42,17 +44,22 @@ export function MythicEditor({ catalog, lookup, card, dashboard, mutateCatalog,
const levelOf = (value) => (effectOf(value.effectPresetId)?.level ? value.level : DEFAULT_TUNING);
const savedValue = (edition) => {
const finish = finishOf(edition);
return { formatId: finish.formatId, effectPresetId: finish.effectPresetId, paletteId: finish.paletteId, intensity: edition.holoIntensity ?? DEFAULT_TUNING, level: edition.holoLevel ?? DEFAULT_TUNING };
return { formatId: finish.formatId, effectPresetId: finish.effectPresetId, paletteId: finish.paletteId, intensity: edition.holoIntensity ?? DEFAULT_TUNING, level: edition.holoLevel ?? DEFAULT_TUNING, flare: flareOfEdition(edition, catalog) };
};
const valueOf = (edition) => edits[edition.id] || savedValue(edition);
const changesOf = (edition) => {
const value = valueOf(edition);
const finish = finishOfValue(value);
const finishChanged = Boolean(finish && finish.id !== edition.finishIds[0]);
const tuningChanged = value.intensity !== (edition.holoIntensity ?? DEFAULT_TUNING) || levelOf(value) !== (edition.holoLevel ?? DEFAULT_TUNING);
const flareChanged = !sameFlare(value.flare, flareOfEdition(edition, catalog), catalog);
return {
value,
finish,
finishChanged: Boolean(finish && finish.id !== edition.finishIds[0]),
tuningChanged: value.intensity !== (edition.holoIntensity ?? DEFAULT_TUNING) || levelOf(value) !== (edition.holoLevel ?? DEFAULT_TUNING),
finishChanged,
tuningChanged,
flareChanged,
dirty: finishChanged || tuningChanged || flareChanged,
// Une finition déjà portée par une autre variation de la carte, même retirée, ne peut pas être reprise.
duplicated: Boolean(finish && mythics.some((other) => other.id !== edition.id && other.finishIds[0] === finish.id))
};
@ -60,8 +67,8 @@ export function MythicEditor({ catalog, lookup, card, dashboard, mutateCatalog,
// Aperçu d'une variation avec ses réglages en cours.
const withValue = (edition, value) => {
const finish = finishOfValue(value);
const { holoIntensity: _intensity, holoLevel: _level, ...base } = edition;
return { ...base, finishIds: finish ? [finish.id] : edition.finishIds, ...(finish ? tuningEditionFields(effectOf(value.effectPresetId), value) : {}) };
const { holoIntensity: _intensity, holoLevel: _level, flareId: _flare, flareMotifId: _motif, flarePaletteId: _palette, flareScope: _scope, flareIntensity: _flareIntensity, flareLevel: _flareLevel, flareCount: _count, ...base } = edition;
return { ...base, finishIds: finish ? [finish.id] : edition.finishIds, ...(finish ? tuningEditionFields(effectOf(value.effectPresetId), value) : {}), ...flareEditionFields(value.flare, catalog) };
};
const draftFinish = draft ? finishOfValue(draft) : null;
const draftDuplicated = Boolean(draftFinish && savedFinishIds.includes(draftFinish.id));
@ -74,6 +81,8 @@ export function MythicEditor({ catalog, lookup, card, dashboard, mutateCatalog,
const select = (key) => { setPreviewKey(key); restart(); };
const save = (finishIds, nextOpening = opening) => mutateCatalog(() => updateCardMythic(card.id, { finishIds, opening: nextOpening }));
const forget = (editionId) => setEdits(({ [editionId]: _done, ...others }) => others);
// Réglages envoyés au service ; une animation vide retire les particules.
const flarePayload = (flare) => ({ id: flare.id || null, motifId: flareMotifOf(catalog.flareEffects?.find((item) => item.id === flare.id), flare.motifId), paletteId: flare.paletteId, scope: flare.scope, intensity: flare.intensity, level: flare.level, count: flare.count });
async function createDraft() {
const tuning = { intensity: draft.intensity, level: levelOf(draft) };
@ -84,15 +93,18 @@ export function MythicEditor({ catalog, lookup, card, dashboard, mutateCatalog,
const created = result.catalog.editions.find((edition) => edition.cardId === card.id && edition.rarity === "mythic" && !edition.retired && edition.finishIds[0] === draftFinish.id);
// Les paliers choisis à la création s'enregistrent sur la variation qui vient d'être créée.
if (created && (tuning.intensity !== DEFAULT_TUNING || tuning.level !== DEFAULT_TUNING)) await mutateCatalog(() => updateMythicTuning(created.id, tuning));
// Ses particules aussi.
if (created && draft.flare?.id) await mutateCatalog(() => updateMythicFlare(created.id, flarePayload(draft.flare)));
select(created?.id || null);
}
}
// Enregistre la finition puis les paliers ; les réglages en cours ne sont oubliés que si tout est passé.
// Enregistre la finition, puis les paliers, puis les particules ; les réglages en cours ne sont oubliés que si tout est passé.
async function applyChanges(edition) {
const { value, finish, finishChanged, tuningChanged } = changesOf(edition);
const { value, finish, finishChanged, tuningChanged, flareChanged } = changesOf(edition);
if (finishChanged && !(await mutateCatalog(() => updateMythicFinish(edition.id, finish.id)))?.catalog) return;
if (tuningChanged && !(await mutateCatalog(() => updateMythicTuning(edition.id, { intensity: value.intensity, level: levelOf(value) })))?.catalog) return;
if (flareChanged && !(await mutateCatalog(() => updateMythicFlare(edition.id, flarePayload(value.flare))))?.catalog) return;
forget(edition.id);
select(edition.id);
}
@ -112,18 +124,18 @@ export function MythicEditor({ catalog, lookup, card, dashboard, mutateCatalog,
}
function addDraft() {
setDraft({ effectPresetId: unusedFinish.effectPresetId, paletteId: unusedFinish.paletteId, formatId: unusedFinish.formatId, intensity: DEFAULT_TUNING, level: DEFAULT_TUNING });
setDraft({ effectPresetId: unusedFinish.effectPresetId, paletteId: unusedFinish.paletteId, formatId: unusedFinish.formatId, intensity: DEFAULT_TUNING, level: DEFAULT_TUNING, flare: NO_FLARE });
select(DRAFT_KEY);
}
const draftEdition = draft && { id: `admin-preview-${card.id}-${draftFinish?.id || "draft"}`, cardId: card.id, rarity: "mythic", finishIds: draftFinish ? [draftFinish.id] : [], promotional: false, ...(draftFinish ? tuningEditionFields(effectOf(draft.effectPresetId), draft) : {}) };
const draftEdition = draft && { id: `admin-preview-${card.id}-${draftFinish?.id || "draft"}`, cardId: card.id, rarity: "mythic", finishIds: draftFinish ? [draftFinish.id] : [], promotional: false, ...(draftFinish ? tuningEditionFields(effectOf(draft.effectPresetId), draft) : {}), ...flareEditionFields(draft.flare, catalog) };
const selectedMythic = previewKey === DRAFT_KEY ? null : activeMythics.find((edition) => edition.id === previewKey) || (draft ? null : activeMythics[0]);
const previewEdition = (selectedMythic && withValue(selectedMythic, valueOf(selectedMythic))) || draftEdition
|| { id: `admin-preview-${card.id}`, cardId: card.id, rarity: "mythic", finishIds: [lookup.holographicFinishes[0]?.id], promotional: false };
const previewLabel = lookup.finishes.get(previewEdition.finishIds[0])?.label;
const previewCatalog = withCardOpeningSetting(catalog, card.id, opening);
const selected = selectedMythic && changesOf(selectedMythic);
const selectedDirty = Boolean(selected && (selected.finishChanged || selected.tuningChanged));
const selectedDirty = Boolean(selected?.dirty);
return <section className="nebula-admin-mythic-editor" aria-label={`Version mythique de ${card.name}`}>
<section className="nebula-admin-card-opening-block" aria-labelledby={`nebula-admin-card-opening-${card.id}`}>
@ -148,7 +160,7 @@ export function MythicEditor({ catalog, lookup, card, dashboard, mutateCatalog,
{activeMythics.map((edition) => {
const finish = finishOf(edition);
const changes = changesOf(edition);
const dirty = changes.finishChanged || changes.tuningChanged;
const dirty = changes.dirty;
const isSelected = selectedMythic?.id === edition.id;
return <article key={edition.id} className="nebula-admin-mythic-variation" role="group" aria-label={finish.label} data-selected={isSelected || undefined} data-modified={dirty || undefined}>
<NebulaCard catalog={catalog} entry={{ card, edition: withValue(edition, changes.value) }} size="sm" onSelect={() => select(edition.id)} selected={isSelected} selectLabel={`Régler ${finish.label}`} />

View file

@ -3,7 +3,7 @@
import { useState } from "react";
import { SelectDropdown } from "../../../components/SelectDropdown.jsx";
import { Tabs } from "../../../components/Tabs.jsx";
import { DEFAULT_FLARE_SCOPE, DEFAULT_FLARE_TUNING, FLARE_EFFECTS, FLARE_SCOPES, MATCH_HOLO_FLARE_LABEL, MATCH_HOLO_FLARE_PALETTE } from "../holoFlares.js";
import { DEFAULT_FLARE_SCOPE, DEFAULT_FLARE_TUNING, flareMotifOf, MATCH_HOLO_FLARE_LABEL, MATCH_HOLO_FLARE_PALETTE } from "../holoFlares.js";
import { EffectTuningFields, TuningRange } from "./EffectTuningFields.jsx";
import { variationSummary } from "./effectTuning.js";
import { effectMissingHint, fittingFormat, formatMissingHint } from "./finishAvailability.js";
@ -33,7 +33,8 @@ export function VariationCustomizer({ catalog, card, value, showEffect = true, d
return { value: item.id, label: item.label, disabled: Boolean(hint), hint };
}).toSorted(enabledFirst);
const flare = value.flare;
const flareEffect = FLARE_EFFECTS.find((item) => item.id === flare?.id);
const flareEffects = catalog.flareEffects || [];
const flareEffect = flareEffects.find((item) => item.id === flare?.id);
const changeFlare = (next) => onChange({ ...value, flare: { ...flare, ...next } });
const changeEffect = (effectPresetId) => onChange({ ...value, effectPresetId, formatId: fittingFormat(catalog, card, effectPresetId, value.formatId) });
return <div className="nebula-admin-customizer">
@ -48,10 +49,10 @@ export function VariationCustomizer({ catalog, card, value, showEffect = true, d
<EffectTuningFields catalog={catalog} effect={effect} value={value} disabled={disabled} onChange={(tuning) => onChange({ ...value, ...tuning })} />
</> : flare ? <>
<div className="nebula-admin-customizer-choices">
<SelectDropdown className="nebula-admin-inline-field" label="Animation" size="sm" value={flare.id} disabled={disabled} options={[{ value: "", label: "Aucune" }, ...FLARE_EFFECTS.map((item) => ({ value: item.id, label: item.label }))]} onChange={(id) => changeFlare({ id })} />
{flareEffect?.motifs && <SelectDropdown className="nebula-admin-inline-field" label="Motif" size="sm" value={flareEffect.motifs.some((item) => item.id === flare.motifId) ? flare.motifId : flareEffect.motifs[0].id} disabled={disabled} options={flareEffect.motifs.map((item) => ({ value: item.id, label: item.label }))} onChange={(motifId) => changeFlare({ motifId })} />}
<SelectDropdown className="nebula-admin-inline-field" label="Animation" size="sm" value={flare.id} disabled={disabled} options={[{ value: "", label: "Aucune" }, ...flareEffects.map((item) => ({ value: item.id, label: item.label }))]} onChange={(id) => changeFlare({ id })} />
{flareEffect?.motifs && <SelectDropdown className="nebula-admin-inline-field" label="Motif" size="sm" value={flareMotifOf(flareEffect, flare.motifId)} disabled={disabled} options={flareEffect.motifs.map((item) => ({ value: item.id, label: item.label }))} onChange={(motifId) => changeFlare({ motifId })} />}
{flareEffect && <SwatchDropdown className="nebula-admin-inline-field" label="Palette" accessibleLabel="Palette des particules" value={flare.paletteId} options={[{ id: MATCH_HOLO_FLARE_PALETTE, label: MATCH_HOLO_FLARE_LABEL }, ...catalog.effectPalettes]} disabled={disabled} onChange={(paletteId) => changeFlare({ paletteId })} />}
{flareEffect && <SelectDropdown className="nebula-admin-inline-field" label="Zone" size="sm" value={flare.scope || DEFAULT_FLARE_SCOPE} disabled={disabled} options={FLARE_SCOPES.map((item) => ({ value: item.id, label: item.label }))} onChange={(scope) => changeFlare({ scope })} />}
{flareEffect && <SelectDropdown className="nebula-admin-inline-field" label="Zone" size="sm" value={flare.scope || DEFAULT_FLARE_SCOPE} disabled={disabled} options={(catalog.flareScopes || []).map((item) => ({ value: item.id, label: item.label }))} onChange={(scope) => changeFlare({ scope })} />}
</div>
{flareEffect && <div className="nebula-admin-tuning">
{flareEffect.tunings.map((scale) => <TuningRange key={scale.key} scale={scale} value={flare[scale.key] || DEFAULT_FLARE_TUNING} disabled={disabled} onChange={(next) => changeFlare({ [scale.key]: next })} />)}

View file

@ -1,7 +1,5 @@
// Rôle : valeurs communes des paliers d'une variation mythique (intensité de la palette, palier propre à l'effet), de 1 à 5,
// et résumé d'une ligne de ses réglages.
import { FLARE_EFFECTS } from "../holoFlares.js";
export const DEFAULT_TUNING = 3;
// Un palier central n'est pas transmis : la carte garde son rendu de référence, sans attribut.
@ -26,6 +24,6 @@ export function variationSummary(catalog, card, value) {
card.fullImage && format?.label,
`${catalog.effectIntensity.label} ${lower(intensity)}`,
effect?.level && `${effect.level.label} ${lower(effect.level.levels[(value.level ?? DEFAULT_TUNING) - 1])}`,
`Particules : ${lower(FLARE_EFFECTS.find((item) => item.id === value.flare?.id)?.label) || "aucune"}`
`Particules : ${lower(catalog.flareEffects?.find((item) => item.id === value.flare?.id)?.label) || "aucune"}`
].filter(Boolean).join(" · ");
}

View file

@ -151,6 +151,10 @@ export function updateMythicTuning(editionId, { intensity, level }) {
return request(`/admin/catalog/mythics/${encodeURIComponent(editionId)}/tuning`, { method: "PUT", body: JSON.stringify({ intensity, level }) });
}
export function updateMythicFlare(editionId, { id, motifId, paletteId, scope, intensity, level, count }) {
return request(`/admin/catalog/mythics/${encodeURIComponent(editionId)}/flare`, { method: "PUT", body: JSON.stringify({ id, motifId, paletteId, scope, intensity, level, count }) });
}
export function updateCollectionMythicOpening(collectionId, { particleShapeId, particlePaletteId }) {
return request(`/admin/catalog/collections/${encodeURIComponent(collectionId)}/mythic-opening`, { method: "PUT", body: JSON.stringify({ particleShapeId, particlePaletteId }) });
}

View file

@ -6,14 +6,7 @@ import { motifAngle, motifSprite, SPRITE_SIZE } from "./flareSprites.js";
const TAU = Math.PI * 2;
export const FIREFLY_MOTIFS = [
{ id: "firefly", label: "Luciole" },
{ id: "four-point-star", label: "Étoile à quatre branches" },
{ id: "star", label: "Étoile" },
{ id: "heart", label: "Cœur" },
{ id: "snowflake", label: "Flocon" },
{ id: "bubble", label: "Bulle" }
];
// Les motifs proposés (identifiants et libellés) sont déclarés par le catalogue (`flareEffects`).
// Paliers 1 à 5 : nombre moyen de lucioles (illustration d'une carte `lg`), vitesse de vol en fraction de la largeur par
// seconde (et durée de vie qui raccourcit avec elle), intensité (taille et éclat).

View file

@ -1,80 +1,61 @@
// 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";
// 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";
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);
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 ; 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);
// 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 = motifOf(effect, flare.motifId);
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 } : {}),
...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 } : {})
...(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(edition?.flareId);
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 = FLARE_SCOPES.some((item) => item.id === edition.flareScope) ? edition.flareScope : DEFAULT_FLARE_SCOPE;
const scope = catalog.flareScopes?.some((item) => item.id === edition.flareScope) ? edition.flareScope : DEFAULT_FLARE_SCOPE;
return {
effect,
motifId: motifOf(effect, edition.flareMotifId),
motifId: flareMotifOf(effect, edition.flareMotifId),
colors: palette.colors,
core: palette.highlight,
intensity: edition.flareIntensity || DEFAULT_FLARE_TUNING,

View file

@ -6,15 +6,7 @@ import { motifAngle, motifSprite, SPRITE_SIZE, streakSprite } from "./flareSprit
const TAU = Math.PI * 2;
export const TWINKLE_MOTIFS = [
{ id: "four-point-star", label: "Étoile à quatre branches" },
{ id: "glint", label: "Reflet" },
{ id: "star", label: "Étoile" },
{ id: "diamond", label: "Losange" },
{ id: "heart", label: "Cœur" },
{ id: "snowflake", label: "Flocon" },
{ id: "bubble", label: "Bulle" }
];
// Les motifs proposés (identifiants et libellés) sont déclarés par le catalogue (`flareEffects`).
// Paliers 1 à 5 : nombre moyen de motifs visibles (pour une illustration de carte `lg`), durée de vie d'un motif, intensité
// (taille et éclat).