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:
parent
9f70bea523
commit
f77a0ca577
15 changed files with 1779 additions and 16 deletions
|
|
@ -1,6 +1,10 @@
|
|||
// Rôle : affiche les cartes Sokko TCG et pilote leur tilt, leurs finitions et leurs animations de révélation.
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { CollectionCardBack } from "./CollectionCardBack.jsx";
|
||||
import { resolveFlare } from "./holoFlares.js";
|
||||
import { createFireflies } from "./holoFireflies.js";
|
||||
import { createLightning } from "./holoLightning.js";
|
||||
import { createTwinkle } from "./holoTwinkle.js";
|
||||
import { MATCH_HOLO_PALETTE_ID, MATCH_HOLO_PALETTE_LABEL, resolveMythicOpeningStyle, resolveOpeningEffect } from "./openingEffects.js";
|
||||
|
||||
const STANDARD_CARD_LAYOUT = "standard";
|
||||
|
|
@ -210,7 +214,66 @@ function particlePosition(index, count, intense, color) {
|
|||
};
|
||||
}
|
||||
|
||||
function CardFace({ entry, quantity, visual, size }) {
|
||||
// Moteur de chaque animation de particules persistantes ; tous partagent la même interface.
|
||||
const FLARE_ENGINES = { lightning: createLightning, twinkle: createTwinkle, fireflies: createFireflies };
|
||||
|
||||
// Particules d'une variation mythique : un canvas dans l'illustration ou sur toute la face, animé seulement quand la carte
|
||||
// est affichée en grand ou survolée, visible et dans un onglet actif. Sous mouvement réduit, une image fixe. Sur toute la
|
||||
// face, les éclairs visent toujours l'illustration, dont la boîte est mesurée dans le canvas.
|
||||
function HoloFlareCanvas({ flare, behindSubject, size }) {
|
||||
const canvasRef = useRef(null);
|
||||
const colorsKey = flare.colors.join(",");
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
const card = canvas?.closest(".nebula-card");
|
||||
if (!canvas || !card) return undefined;
|
||||
const engine = FLARE_ENGINES[flare.effect.id](canvas, { colors: colorsKey.split(","), core: flare.core, intensity: flare.intensity, level: flare.level, count: flare.count, motifId: flare.motifId, behindSubject });
|
||||
const resize = () => {
|
||||
const art = flare.scope === "card" ? canvas.parentElement?.querySelector(".nebula-card-art") : null;
|
||||
const focus = art ? { x: art.offsetLeft, y: art.offsetTop, width: art.offsetWidth, height: art.offsetHeight } : null;
|
||||
engine.resize(canvas.offsetWidth, canvas.offsetHeight, Math.min(2, window.devicePixelRatio || 1), focus);
|
||||
};
|
||||
const resizeObserver = new ResizeObserver(resize);
|
||||
resizeObserver.observe(canvas);
|
||||
resize();
|
||||
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
||||
engine.renderStatic();
|
||||
return () => { resizeObserver.disconnect(); engine.destroy(); };
|
||||
}
|
||||
let hovered = false;
|
||||
let visible = true;
|
||||
const update = () => engine.setActive(visible && !document.hidden && (size === "lg" || hovered));
|
||||
const enter = () => { hovered = true; update(); };
|
||||
const leave = () => { hovered = false; engine.setPointer(null); update(); };
|
||||
const move = (event) => {
|
||||
const bounds = canvas.getBoundingClientRect();
|
||||
engine.setPointer({ x: (event.clientX - bounds.left) / bounds.width, y: (event.clientY - bounds.top) / bounds.height });
|
||||
};
|
||||
const intersection = new IntersectionObserver(([entry]) => { visible = entry.isIntersecting; update(); });
|
||||
intersection.observe(canvas);
|
||||
card.addEventListener("pointerenter", enter);
|
||||
card.addEventListener("pointerleave", leave);
|
||||
card.addEventListener("pointermove", move);
|
||||
card.addEventListener("focus", enter);
|
||||
card.addEventListener("blur", leave);
|
||||
document.addEventListener("visibilitychange", update);
|
||||
update();
|
||||
return () => {
|
||||
resizeObserver.disconnect();
|
||||
intersection.disconnect();
|
||||
card.removeEventListener("pointerenter", enter);
|
||||
card.removeEventListener("pointerleave", leave);
|
||||
card.removeEventListener("pointermove", move);
|
||||
card.removeEventListener("focus", enter);
|
||||
card.removeEventListener("blur", leave);
|
||||
document.removeEventListener("visibilitychange", update);
|
||||
engine.destroy();
|
||||
};
|
||||
}, [colorsKey, flare.effect.id, flare.core, flare.intensity, flare.level, flare.count, flare.motifId, flare.scope, behindSubject, size]);
|
||||
return <canvas ref={canvasRef} className="nebula-card-flare" data-flare={flare.effect.id} data-flare-scope={flare.scope} data-behind-subject={behindSubject || undefined} aria-hidden="true" />;
|
||||
}
|
||||
|
||||
function CardFace({ entry, quantity, visual, size, flare = null }) {
|
||||
const { card, edition } = entry;
|
||||
const finishIds = edition.finishIds || [];
|
||||
const showName = size !== "sm";
|
||||
|
|
@ -220,6 +283,12 @@ function CardFace({ entry, quantity, visual, size }) {
|
|||
const image = (fullArt && card.fullImage) || card.image;
|
||||
const parallax = PARALLAX_EFFECTS.has(visual.effectPreset?.id) ? resolveParallaxLayers(card, fullArt, image) : null;
|
||||
const loading = size === "lg" ? "eager" : "lazy";
|
||||
// Dans l'illustration, derrière un héros détouré, les éclairs passent entre le décor et lui ; scintillements et lucioles,
|
||||
// eux, restent devant pour être vus. Sur toute la carte, les particules couvrent la face sous le texte, devant le héros.
|
||||
const cardScope = flare?.scope === "card";
|
||||
const behindSubject = Boolean(flare?.effect.id === "lightning" && !cardScope && parallax && parallax.layers.length > 1);
|
||||
const flareCanvas = flare && <HoloFlareCanvas flare={flare} behindSubject={behindSubject} size={size} />;
|
||||
const artFlare = cardScope ? null : flareCanvas;
|
||||
return <div
|
||||
className="nebula-card-face"
|
||||
data-card-layout={visual.layout}
|
||||
|
|
@ -230,17 +299,18 @@ function CardFace({ entry, quantity, visual, size }) {
|
|||
>
|
||||
<div className={`nebula-card-art ${image ? "has-image" : ""}`} data-parallax-setup={parallax?.setup} aria-hidden="true">
|
||||
{/* Chaque calque porte sa profondeur ; son image sert aussi de masque au reflet prismatique qui ne touche que lui. */}
|
||||
{parallax ? parallax.layers.map((layer, index) => <span
|
||||
{parallax ? parallax.layers.flatMap((layer, index) => [layer.role === "subject" && behindSubject && artFlare ? <span key="flare" className="nebula-card-flare-plane">{artFlare}</span> : null, <span
|
||||
key={layer.id}
|
||||
className="nebula-card-depth-layer"
|
||||
data-depth-layer={layer.id}
|
||||
data-depth-role={layer.role}
|
||||
style={{ "--layer-depth": layer.depth, "--layer-depth-abs": Math.abs(layer.depth), "--layer-index": index, "--layer-image": `url("${layer.src}")`, zIndex: index }}
|
||||
style={{ "--layer-depth": layer.depth, "--layer-depth-abs": Math.abs(layer.depth), "--layer-index": index, "--layer-image": `url("${layer.src}")`, zIndex: index * 2 }}
|
||||
>
|
||||
<img src={layer.src} alt="" loading={loading} decoding="async" />
|
||||
{layer.role === "backdrop" && <span className="nebula-card-depth-tint" />}
|
||||
<span className="nebula-card-depth-foil" />
|
||||
</span>) : image ? <img src={image} alt="" loading={loading} decoding="async" /> : <span className="nebula-card-placeholder-mark" />}
|
||||
</span>]) : image ? <img src={image} alt="" loading={loading} decoding="async" /> : <span className="nebula-card-placeholder-mark" />}
|
||||
{!behindSubject && artFlare}
|
||||
</div>
|
||||
{showName && <h3><span>{card.name}</span></h3>}
|
||||
{showDetails && <div className="nebula-card-copy">
|
||||
|
|
@ -256,6 +326,7 @@ function CardFace({ entry, quantity, visual, size }) {
|
|||
{SHARD_FACETS.map((facet) => <i key={facet} data-facet={facet} />)}
|
||||
</span>}
|
||||
</>}
|
||||
{cardScope && flareCanvas}
|
||||
<span className="nebula-card-glare" aria-hidden="true" />
|
||||
</div>;
|
||||
}
|
||||
|
|
@ -265,6 +336,7 @@ export function NebulaCard({ catalog, entry, quantity = 0, size = "lg", faceUp =
|
|||
const rarity = entry.edition?.rarity || "common";
|
||||
const finish = entry.edition?.finishIds?.join(" ") || "standard";
|
||||
const visual = destinationVisual(entry.card, resolveFinishVisual(entry.edition, catalog));
|
||||
const flare = resolveFlare(entry.edition, catalog, visual);
|
||||
const openingVisual = resolveOpeningVisual(rarity, entry.card.id, entry.card.collectionId, catalog, visual);
|
||||
// Les particules n'existent que pendant l'ouverture : une carte face visible n'en déclare aucune.
|
||||
const displayedParticlePreset = faceUp ? null : openingVisual.particlePreset;
|
||||
|
|
@ -284,6 +356,7 @@ export function NebulaCard({ catalog, entry, quantity = 0, size = "lg", faceUp =
|
|||
// Paliers de la variation (intensité de la palette, palier propre à l'effet) : le palier central n'a pas d'attribut.
|
||||
"data-holo-intensity": visual.effectPreset ? entry.edition?.holoIntensity : undefined,
|
||||
"data-holo-level": visual.effectPreset?.level ? entry.edition?.holoLevel : undefined,
|
||||
"data-flare": flare?.effect.id,
|
||||
"data-particle-preset": displayedParticlePreset?.id,
|
||||
"data-particle-shape": displayedParticleShape?.id,
|
||||
"data-particle-palette": displayedParticlePalette?.id,
|
||||
|
|
@ -390,7 +463,7 @@ export function NebulaCard({ catalog, entry, quantity = 0, size = "lg", faceUp =
|
|||
data-has-image={backCollection?.back?.image ? "true" : undefined}
|
||||
style={backCollection?.back?.image ? { "--card-back-image": `url("${backCollection.back.image}")` } : undefined}
|
||||
><CollectionCardBack collection={backCollection} /></span>
|
||||
<CardFace entry={entry} quantity={quantity} visual={visual} size={cardSize} />
|
||||
<CardFace entry={entry} quantity={quantity} visual={visual} size={cardSize} flare={revealPhase === "revealed" ? flare : null} />
|
||||
</span>
|
||||
{newBadge && revealPhase === "revealed" && <span className="nds-badge nebula-card-new-badge" aria-hidden="true">{newBadge}</span>}
|
||||
</span>
|
||||
|
|
@ -398,7 +471,7 @@ export function NebulaCard({ catalog, entry, quantity = 0, size = "lg", faceUp =
|
|||
{particlesVisible && <span className="nebula-card-particles" aria-hidden="true">{rarity === "mythic" && <><span className="nebula-card-particle-ring-glow" data-glow="outer"><span><span /></span></span><span className="nebula-card-particle-ring-glow" data-glow="inner"><span><span /></span></span></>}{Array.from({ length: openingVisual.particlePreset.count }, (_, index) => <i key={index} style={particlePosition(index, openingVisual.particlePreset.count, rarity === "legendary" || rarity === "mythic", openingVisual.particlePalette?.colors[index % openingVisual.particlePalette.colors.length])} />)}</span>}
|
||||
</button>;
|
||||
}
|
||||
const content = <div className="nebula-card-tilt-surface"><CardFace entry={entry} quantity={quantity} visual={visual} size={cardSize} /></div>;
|
||||
const content = <div className="nebula-card-tilt-surface"><CardFace entry={entry} quantity={quantity} visual={visual} size={cardSize} flare={flare} /></div>;
|
||||
return onSelect
|
||||
? <button ref={cardRef} className="nebula-card nebula-card-select" data-card-size={cardSize} data-card-layout={visual.layout} data-card-kind={entry.card.kind} data-rarity={rarity} data-finish={finish} {...visualAttributes} type="button" onClick={onSelect} aria-label={selectLabel || `Voir ${entry.card.name}`} aria-pressed={selected}>{content}</button>
|
||||
: <article ref={cardRef} className="nebula-card" data-card-size={cardSize} data-card-layout={visual.layout} data-card-kind={entry.card.kind} data-rarity={rarity} data-finish={finish} {...visualAttributes}>{content}</article>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue