diff --git a/.beads/interactions.jsonl b/.beads/interactions.jsonl index 654d353..9f2ab97 100644 --- a/.beads/interactions.jsonl +++ b/.beads/interactions.jsonl @@ -449,3 +449,5 @@ {"id":"int-0d747b5002f3c0ea920420c0a0a2a252","kind":"field_change","created_at":"2026-11-21T16:17:50.491271549Z","actor":"Shinuwa","issue_id":"sokko-g-lzov","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Sokko TCG and Expeditions styles load with the cards route (cards-route.scss, imported by CardsPage) and re-emit the three late sheets so the cascade is unchanged (verified byte for byte against the previous build). Common CSS 94 243 → 69 413 o gzip, budget lowered to 75 000; cold home 1 557 424 o."}} {"id":"int-dee60321fbd2d9574fb5bac63bf0be2d","kind":"field_change","created_at":"2026-11-21T16:49:09.73375071Z","actor":"Shinuwa","issue_id":"sokko-g-t8ig","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Finition modifiable depuis l'admin (crayon), id conservé ; tests unitaires, API et e2e ajoutés"}} {"id":"int-2bbd2c76193c4fb098ea70a32ad248c6","kind":"field_change","created_at":"2026-11-21T17:30:59.206437281Z","actor":"Shinuwa","issue_id":"sokko-g-4bnb","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Prototype Parallaxe prismatique disponible dans l’Atelier visuel, comparaison avec l’Écrin actuel ajoutée, prompts et setup de couches documentés, check:full validé."}} +{"id":"int-2b918586f7e3fb55443858e1948ac365","kind":"field_change","created_at":"2026-11-21T21:31:58.383758099Z","actor":"Shinuwa","issue_id":"sokko-g-qp2y","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Glace brisée ajoutée au catalogue comme quatrième effet holographique (finitions générées, palier de taille des éclats), validée par l'utilisateur le 2026-11-21."}} +{"id":"int-44cf17594a942cc45489c59af8598230","kind":"field_change","created_at":"2026-11-21T21:32:10.26683769Z","actor":"Shinuwa","issue_id":"sokko-g-i9j6","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Paliers de 1 à 5 réglés au curseur (intensité de la palette, palier propre à l'effet), enregistrés par variation mythique, réglables dès la création d'une variation et essayables dans l'Atelier."}} diff --git a/DESIGN_SYSTEM.md b/DESIGN_SYSTEM.md index 97ccb8c..4ace4fc 100644 --- a/DESIGN_SYSTEM.md +++ b/DESIGN_SYSTEM.md @@ -1328,7 +1328,8 @@ L'Atelier visuel regroupe deux bancs d'essai distincts. La section « Effets holographiques mythiques », en premier, affiche une carte `lg` (300 x 420 px) de « La Pioche Mythique » par effet holographique, y compris ceux qu'aucune édition n'utilise encore, avec le menu de palette de sept couleurs et un menu « Particules au -survol » désactivé, réservé au réglage à venir. La section « Effets d'ouverture » suit avec +survol » désactivé, réservé au réglage à venir, ainsi que les curseurs des paliers +(intensité de la palette et palier propre à l'effet). La section « Effets d'ouverture » suit avec une carte face cachée par rareté, la Mythique en tête : seule sur sa ligne, limitée à 760 px et centrée, aperçu à gauche et menus de forme puis de palette de particules empilés (dont « Comme la palette holo »), puis Rare, Épique et Légendaire partagent une ligne de trois colonnes à @@ -1443,6 +1444,29 @@ rythmes différents ; la silhouette du héros se frange enfin de deux couleurs opposées de la palette, décalées en sens inverse. Sans plaque de décor, le composite la remplace ; sans héros détouré, l'illustration reste un seul plan immobile qui garde le prisme. Le mouvement réduit fige les calques. +Le preset **Glace brisée** (`shattered-ice`) couvre la carte d'une mosaïque d'éclats +en quatre groupes de facettes : chaque groupe ne s'allume que lorsque l'inclinaison +approche de sa propre orientation, si bien que les éclats scintillent par groupes, +dans les couleurs de la palette, au lieu d'une bande qui glisse ; les fissures +accrochent une lumière blanche. En format standard, elle couvre le cadre et le +texte et passe sous l'illustration, qui reste intacte ; en pleine illustration, +elle passe devant, plus discrète. Ses masques, raccordables, sont générés par +`scripts/generate-shattered-ice-textures.mjs` ; l'effet ne demande aucun fichier +par carte. +Chaque variation mythique règle deux **paliers**, de 1 à 5 avec un curseur +`nds-range` dont le libellé affiche le cran ; le niveau 3 reproduit le rendu de +référence et n'ajoute aucun attribut. L'**intensité de la palette** (`effectIntensity`, +de Très douce à Très intense), commune à tous les effets, multiplie l'opacité de +leurs calques de couleur (`data-holo-intensity`, `--holo-intensity` de 0,5 à 1,5) ; +le **palier propre à l'effet**, quand le catalogue lui en déclare un +(`effectPresets[].level`), règle la vitesse du Prisme spectral (9 à 3 s), +l'amplitude de la Parallaxe prismatique (`--parallax-reach` de 0,025 à 0,065) ou +la taille des éclats de la Glace brisée (×0,6 à ×1,5), via `data-holo-level`. Le +Reflet diffractif n'a que l'intensité. Dans l'éditeur mythique, les curseurs se +règlent dès la création d'une variation, puis sur chaque variation enregistrée : +l'aperçu suit le curseur aussitôt et l'enregistrement part quand le réglage se +pose, visible par les joueurs qui la possèdent. L'Atelier visuel propose les +mêmes curseurs en aperçu. Le gradient surdimensionné se déplace uniquement de `0 %` à `100 %`, sans répétition visible. Les couleurs de la palette sont répétées et espacées automatiquement, sans paliers explicites, afin de conserver des bandes régulières diff --git a/e2e/nebula-cards.spec.js b/e2e/nebula-cards.spec.js index f44a6b1..53cb7e7 100644 --- a/e2e/nebula-cards.spec.js +++ b/e2e/nebula-cards.spec.js @@ -698,6 +698,21 @@ test("administrator navigates sections, manages mythic content and previews visu await solarVariation.getByRole("button", { name: "Valider la nouvelle finition de Prisme spectral — Solaire" }).click(); await page.getByRole("dialog", { name: "Changer la finition de Prisme spectral — Solaire ?" }).getByRole("button", { name: "Changer la finition" }).click(); await expect(dragonVariations.locator("strong")).toHaveText(["Aurore", "Cosmique"]); + // Les paliers d'une variation, de 1 à 5 : l'aperçu suit le curseur, l'enregistrement suit quand le réglage se pose. + const tunedVariation = mythicEditorPanel.getByRole("group", { name: "Prisme spectral — Aurore" }); + const tunedCard = tunedVariation.locator('.nebula-card[data-card-size="sm"]'); + await tunedVariation.getByRole("slider", { name: "Intensité" }).fill("5"); + await expect(tunedCard).toHaveAttribute("data-holo-intensity", "5"); + await tunedVariation.getByRole("slider", { name: "Vitesse" }).fill("1"); + await expect(tunedCard).toHaveAttribute("data-holo-level", "1"); + const tunedEdition = async () => (await page.evaluate(() => globalThis.fetch("/api/cards/config").then((response) => response.json()))).catalog.editions.find((edition) => edition.id === "starvoid-dragon-spectral-prism-aurora"); + await expect.poll(async () => { const edition = await tunedEdition(); return [edition.holoIntensity, edition.holoLevel]; }).toEqual([5, 1]); + // Retour aux paliers centraux : la variation retrouve son rendu de référence, sans attribut. + await tunedVariation.getByRole("slider", { name: "Intensité" }).fill("3"); + await tunedVariation.getByRole("slider", { name: "Vitesse" }).fill("3"); + await expect.poll(async () => { const edition = await tunedEdition(); return [edition.holoIntensity, edition.holoLevel]; }).toEqual([undefined, undefined]); + await expect(tunedCard).not.toHaveAttribute("data-holo-level"); + await expect(tunedCard).not.toHaveAttribute("data-holo-intensity"); await mythicEditorPanel.getByRole("button", { name: "Fermer" }).click(); await expect(mythicEditorPanel).toHaveCount(0); await expect(dragonTileButton).toHaveAttribute("aria-pressed", "false"); @@ -814,6 +829,10 @@ test("administrator navigates sections, manages mythic content and previews visu await expect(editorSurface).toHaveAttribute("data-particle-shape", "snowflakes"); await expect(editorSurface).toHaveAttribute("data-particle-palette", "match-holo"); await expect(editorSurface).toHaveCSS("--opening-aura", "#ff0000"); + // Les paliers se règlent dès la création : ils s'enregistrent avec la nouvelle variation. + const draftVariation = editor.locator(".nebula-admin-mythic-variation[data-new]"); + await draftVariation.getByRole("slider", { name: "Intensité" }).fill("4"); + await expect(draftVariation.locator('.nebula-card[data-card-size="sm"]')).toHaveAttribute("data-holo-intensity", "4"); await editor.getByRole("button", { name: "Valider la nouvelle variation" }).click(); await expect(editor.locator(".nebula-admin-mythic-variation[data-new]")).toHaveCount(0); await expect(editor.locator(".nebula-admin-mythic-variation")).toHaveCount(2); @@ -824,7 +843,7 @@ test("administrator navigates sections, manages mythic content and previews visu await noOverflow(); const config = await page.evaluate(() => globalThis.fetch("/api/cards/config").then((response) => response.json())); - expect(config.catalog.editions.some((edition) => edition.id === "mythic-card-pull-spectral-prism-rainbow")).toBe(true); + expect(config.catalog.editions.find((edition) => edition.id === "mythic-card-pull-spectral-prism-rainbow")?.holoIntensity).toBe(4); expect(config.catalog.mythicOpeningSettings).toEqual(expect.arrayContaining([ { scope: "card", targetId: "mythic-card-pull", particleShapeId: null, particlePaletteId: "match-holo" }, { scope: "collection", targetId: "astral-genesis", particleShapeId: "snowflakes", particlePaletteId: null } @@ -869,7 +888,12 @@ test("administrator navigates sections, manages mythic content and previews visu expect(Math.abs((mythicBox.x - gridBox.x) - (gridBox.x + gridBox.width - mythicBox.x - mythicBox.width))).toBeLessThanOrEqual(1); const effectStyles = page.locator(".nebula-admin-effect-grid .nebula-admin-style-card"); - await expect(effectStyles.locator("h4")).toHaveText(["Prisme spectral", "Reflet diffractif", "Parallaxe prismatique"]); + await expect(effectStyles.locator("h4")).toHaveText(["Prisme spectral", "Reflet diffractif", "Parallaxe prismatique", "Glace brisée"]); + const iceCard = effectStyles.filter({ has: page.getByRole("heading", { name: /Glace brisée/ }) }).locator('.nebula-card[data-holo-effect="shattered-ice"]'); + await expect(iceCard.locator(".nebula-card-holo-shards > i")).toHaveCount(4); + await expect(iceCard.locator('.nebula-card-holo-shards > [data-facet="0"]')).toHaveCSS("mask-image", /shattered-ice-facet-0\.webp/); + // En format standard, la glace passe sous l'illustration, qui reste intacte. + expect(await iceCard.evaluate((element) => { const view = element.ownerDocument.defaultView; return Number(view.getComputedStyle(element.querySelector(".nebula-card-art")).zIndex) > Number(view.getComputedStyle(element.querySelector(".nebula-card-holo-shards")).zIndex); })).toBe(true); // La Parallaxe prismatique pose le héros détouré de la carte sur son décor sans lui, puis les décale selon leur profondeur. const parallaxStyle = effectStyles.filter({ has: page.getByRole("heading", { name: "Parallaxe prismatique", exact: true }) }); const parallaxCard = parallaxStyle.locator('.nebula-card[data-holo-effect="prismatic-backdrop"]'); @@ -891,6 +915,18 @@ test("administrator navigates sections, manages mythic content and previews visu await expect(parallaxCard.locator('[data-depth-layer="backdrop"] img[src$="/mythic_card_pull__full__backdrop.webp"]')).toBeVisible(); await expect(parallaxCard.locator('[data-depth-layer="subject"] img[src$="/mythic_card_pull__full__cutout.webp"]')).toBeVisible(); await chooseOption(parallaxStyle, "Format", "Standard"); + // Les paliers, de 1 à 5, s'essaient sur l'aperçu : intensité de la palette pour tous les effets, amplitude pour la parallaxe. + const parallaxIntensity = parallaxStyle.getByRole("slider", { name: "Intensité" }); + await expect(parallaxIntensity).toHaveValue("3"); + await expect(parallaxCard).not.toHaveAttribute("data-holo-intensity"); + await parallaxIntensity.fill("5"); + await expect(parallaxCard).toHaveAttribute("data-holo-intensity", "5"); + await expect(parallaxStyle.locator(".nebula-admin-tuning-range").first()).toContainText("Très intense"); + await parallaxStyle.getByRole("slider", { name: "Amplitude" }).fill("1"); + await expect(parallaxCard).toHaveAttribute("data-holo-level", "1"); + // Le Reflet diffractif n'a que l'intensité ; la Glace brisée règle la taille de ses éclats. + await expect(effectStyles.filter({ has: page.getByRole("heading", { name: "Reflet diffractif", exact: true }) }).getByRole("slider")).toHaveCount(1); + await expect(effectStyles.filter({ has: page.getByRole("heading", { name: "Glace brisée", exact: true }) }).getByRole("slider", { name: "Taille des éclats" })).toBeVisible(); const spectralStyle = effectStyles.filter({ has: page.getByRole("heading", { name: "Prisme spectral", exact: true }) }); // Les aperçus holographiques gardent le vrai format `lg`, 300 x 420 px. const holoPreviewBox = await spectralStyle.locator(".nebula-admin-style-preview > .nebula-card").boundingBox(); diff --git a/scripts/generate-shattered-ice-textures.mjs b/scripts/generate-shattered-ice-textures.mjs new file mode 100644 index 0000000..503308d --- /dev/null +++ b/scripts/generate-shattered-ice-textures.mjs @@ -0,0 +1,78 @@ +// Rôle : génère les masques de l'effet holographique « Glace brisée » : une mosaïque d'éclats raccordable sur ses bords, +// répartie en quatre groupes de facettes (un masque par groupe), plus le masque des fissures qui les séparent. +// Usage : node scripts/generate-shattered-ice-textures.mjs +import { mkdir } from "node:fs/promises"; +import sharp from "sharp"; + +const SIZE = 512; +const GRID = 7; // 7 x 7 germes décalés : environ 49 éclats de tailles voisines par tuile. +const GROUPS = 4; +const OUT = "website/public/static/img/cards/effects"; + +// Générateur pseudo-aléatoire déterministe : la même commande redonne exactement les mêmes textures. +let seed = 20261121; +const random = () => { + seed = (seed * 1664525 + 1013904223) >>> 0; + return seed / 2 ** 32; +}; + +const cells = []; +for (let row = 0; row < GRID; row++) { + for (let column = 0; column < GRID; column++) { + const angle = random() * Math.PI * 2; + cells.push({ + x: ((column + 0.15 + random() * 0.7) / GRID) * SIZE, + y: ((row + 0.15 + random() * 0.7) / GRID) * SIZE, + group: Math.floor(random() * GROUPS), + // Chaque éclat reçoit un dégradé interne propre : il paraît incliné, comme un vrai fragment de glace. + shadeX: Math.cos(angle), + shadeY: Math.sin(angle), + shadeMin: 0.45 + random() * 0.3 + }); + } +} + +// Distance sur un tore : la tuile se raccorde à elle-même dans les deux directions. +const wrapped = (delta) => { + const value = Math.abs(delta) % SIZE; + return Math.min(value, SIZE - value); +}; + +const facets = Array.from({ length: GROUPS }, () => Buffer.alloc(SIZE * SIZE * 2)); +const cracks = Buffer.alloc(SIZE * SIZE * 2); +for (let y = 0; y < SIZE; y++) { + for (let x = 0; x < SIZE; x++) { + let first = Infinity; + let second = Infinity; + let owner = null; + for (const cell of cells) { + const distance = Math.hypot(wrapped(x - cell.x), wrapped(y - cell.y)); + if (distance < first) { + second = first; + first = distance; + owner = cell; + } else if (distance < second) { + second = distance; + } + } + // Près de la médiatrice entre deux germes, l'écart entre les deux distances s'annule : c'est la fissure. + const crack = Math.max(0, Math.min(1, 1 - (second - first - 1.2) / 1.6)); + const offset = (y * SIZE + x) * 2; + cracks[offset] = 255; + cracks[offset + 1] = Math.round(crack * 255); + const dx = (x - owner.x) / (SIZE / GRID); + const dy = (y - owner.y) / (SIZE / GRID); + const shade = owner.shadeMin + (1 - owner.shadeMin) * Math.max(0, Math.min(1, 0.5 + (dx * owner.shadeX + dy * owner.shadeY))); + const facet = facets[owner.group]; + facet[offset] = 255; + facet[offset + 1] = Math.round((1 - crack) * shade * 255); + } +} + +await mkdir(OUT, { recursive: true }); +const write = (buffer, name) => sharp(buffer, { raw: { width: SIZE, height: SIZE, channels: 2 } }).webp({ lossless: true }).toFile(`${OUT}/${name}`); +await Promise.all([ + ...facets.map((buffer, index) => write(buffer, `shattered-ice-facet-${index}.webp`)), + write(cracks, "shattered-ice-cracks.webp") +]); +console.log(`${GROUPS} masques de facettes et un masque de fissures écrits dans ${OUT}.`); diff --git a/services/cards/api.js b/services/cards/api.js index f250550..27285f9 100644 --- a/services/cards/api.js +++ b/services/cards/api.js @@ -492,6 +492,12 @@ export function createCardsApiHandler({ json(res, 200, service.setCardMythicConfig(session.player.id, cardMythic[0], { finishIds: body.finishIds, opening: { particleShapeId: body.opening?.particleShapeId ?? null, particlePaletteId: body.opening?.particlePaletteId ?? null } })); return true; } + const mythicTuning = routeMatch(url.pathname, /^\/api\/cards\/admin\/catalog\/mythics\/([^/]+)\/tuning$/); + if (req.method === "PUT" && mythicTuning) { + const body = await readBody(req); + json(res, 200, service.setMythicTuning(session.player.id, mythicTuning[0], { intensity: body.intensity, level: body.level })); + return true; + } const mythicFinish = routeMatch(url.pathname, /^\/api\/cards\/admin\/catalog\/mythics\/([^/]+)\/finish$/); if (req.method === "PUT" && mythicFinish) { json(res, 200, service.setMythicFinish(session.player.id, mythicFinish[0], (await readBody(req)).finishId)); diff --git a/services/cards/catalog.js b/services/cards/catalog.js index 0fb12ca..0be47a1 100644 --- a/services/cards/catalog.js +++ b/services/cards/catalog.js @@ -13,6 +13,13 @@ const STANDARD_FORMAT = "standard"; export const FULL_ART_FORMAT = "full-art"; // Palette d'ouverture spéciale : reprend les couleurs de la palette holographique de la variation. export const MATCH_HOLO_PALETTE_ID = "match-holo"; +// Paliers d'une variation mythique, de 1 à 5 : l'intensité de la palette, commune à tous les effets, et le palier propre à +// l'effet (vitesse, amplitude…) quand il en déclare un. Le palier central, 3, est la valeur par défaut et le rendu de référence. +export const EFFECT_TUNING_STEPS = 5; +export const DEFAULT_EFFECT_TUNING = 3; +export const isEffectTuning = (value) => Number.isInteger(value) && value >= 1 && value <= EFFECT_TUNING_STEPS; +const validTuningScale = (scale) => typeof scale?.label === "string" && scale.label.length > 0 && Array.isArray(scale.levels) + && scale.levels.length === EFFECT_TUNING_STEPS && scale.levels.every((label) => typeof label === "string" && label.length > 0); const CARD_IMAGE_PATTERN = /^\/static\/img\/cards\/[a-z0-9-]+\/(?:common|rare|epic|legendary)\/[a-z0-9_]+\.webp$/; const PACK_BACK_IMAGE_PATTERN = /^\/static\/img\/cards\/[a-z0-9-]+\/back\.webp$/; // Étiquettes d'expédition : vocabulaire fermé, par famille (personnage, lieu, thème, objet). @@ -127,7 +134,9 @@ export function validateCardsCatalog(catalog) { for (const preset of catalog.effectPresets) { if (!preset.label || preset.kind !== "holographic") throw new TypeError(`Invalid holographic effect preset ${preset.id}.`); + if (preset.level != null && !validTuningScale(preset.level)) throw new TypeError(`Holographic effect preset ${preset.id} level needs a label and ${EFFECT_TUNING_STEPS} level labels.`); } + if (!validTuningScale(catalog.effectIntensity)) throw new TypeError(`Cards catalog effectIntensity needs a label and ${EFFECT_TUNING_STEPS} level labels.`); if (catalog.cardFormats?.[0]?.id !== STANDARD_FORMAT || catalog.cardFormats.some((format) => !format.label) || !catalog.cardFormats.some((format) => format.id === FULL_ART_FORMAT)) { throw new TypeError("Cards catalog must declare the standard and full-art formats."); } @@ -237,6 +246,12 @@ export function validateCardsCatalog(catalog) { if (!RARITY_IDS.has(edition.rarity)) throw new TypeError(`Unknown rarity for edition ${edition.id}.`); if (!Array.isArray(edition.finishIds) || edition.finishIds.some((id) => !finishIds.has(id))) throw new TypeError(`Unknown finish for edition ${edition.id}.`); if (edition.retired != null && typeof edition.retired !== "boolean") throw new TypeError(`Edition ${edition.id} retired flag must be a boolean.`); + if (edition.holoIntensity != null || edition.holoLevel != null) { + const preset = catalog.effectPresets.find((item) => item.id === catalog.finishes.find((finish) => finish.id === edition.finishIds[0])?.effectPresetId); + if (!preset) throw new TypeError(`Edition ${edition.id} can only be tuned with a holographic finish.`); + if (edition.holoIntensity != null && !isEffectTuning(edition.holoIntensity)) throw new TypeError(`Edition ${edition.id} has an unknown holographic intensity.`); + if (edition.holoLevel != null && (!preset.level || !isEffectTuning(edition.holoLevel))) throw new TypeError(`Edition ${edition.id} has a level its effect does not declare.`); + } if (destinationCards.some((card) => card.id === edition.cardId) && edition.rarity !== "rare") throw new TypeError(`Destination card edition ${edition.id} must be rare.`); if (edition.promotional && edition.legendaryEditionId) throw new TypeError(`Promotional edition ${edition.id} cannot require a legendary parent.`); if (edition.rarity === "mythic" && !edition.promotional) { @@ -394,7 +409,8 @@ export function isMythicEditionIdOf(editionId, cardId) { } // Construit le catalogue publié : catalogue versionné + variations mythiques et réglages d'ouverture enregistrés en base. -// `variations` : [{ editionId, cardId, finishId, status: "active" | "retired" }] +// `variations` : [{ editionId, cardId, finishId, status: "active" | "retired", intensity?, level? }] ; un palier central ou absent +// n'est pas publié, et le palier d'effet seulement si l'effet de la finition en déclare un. // `openingSettings` : [{ scope: "collection" | "card", targetId, particleShapeId | null, particlePaletteId | null }] // `collectionStates` : [{ collectionId, active }] ; une collection sans état est inactive. // `dropRates` : [{ collectionId, rarityWeights }] ; publiés sur chaque collection dans `dropWeights`. @@ -410,6 +426,7 @@ export function buildPublishedCatalog(versionedCatalog, { variations = [], openi if (!collection.dropWeights) throw new TypeError(`Active collection ${collection.id} needs drop rates.`); } const holographic = holographicFinishIds(catalog); + const effectOf = (finishId) => catalog.effectPresets.find((preset) => preset.id === catalog.finishes.find((finish) => finish.id === finishId)?.effectPresetId); const knownIds = new Set(catalog.editions.map((edition) => edition.id)); const cardFinishes = new Set(); const mythics = variations.map((variation) => { @@ -428,7 +445,9 @@ export function buildPublishedCatalog(versionedCatalog, { variations = [], openi finishIds: [variation.finishId], promotional: false, legendaryEditionId: parent.id, - ...(variation.status === "retired" ? { retired: true } : {}) + ...(variation.status === "retired" ? { retired: true } : {}), + ...(isEffectTuning(variation.intensity) && variation.intensity !== DEFAULT_EFFECT_TUNING ? { holoIntensity: variation.intensity } : {}), + ...(isEffectTuning(variation.level) && variation.level !== DEFAULT_EFFECT_TUNING && effectOf(variation.finishId)?.level ? { holoLevel: variation.level } : {}) }; }); // Chaque variation suit sa carte légendaire, dans l'ordre des finitions. diff --git a/services/cards/database.js b/services/cards/database.js index f526166..13d0b9a 100644 --- a/services/cards/database.js +++ b/services/cards/database.js @@ -487,6 +487,12 @@ export const MIGRATIONS = [ // l'identifiant ne garantit donc plus qu'une carte a une seule variation par finition, cet index le fait. ` CREATE UNIQUE INDEX mythic_variations_card_finish_idx ON mythic_variations(card_id, finish_id); + `, + // Paliers d'une variation mythique, de 1 à 5 : intensité de la palette et palier propre à l'effet (vitesse, amplitude…). Le + // palier central, 3, ne change rien au rendu : les variations existantes gardent exactement leur apparence. + ` + ALTER TABLE mythic_variations ADD COLUMN holo_intensity INTEGER NOT NULL DEFAULT 3 CHECK (holo_intensity BETWEEN 1 AND 5); + ALTER TABLE mythic_variations ADD COLUMN holo_level INTEGER NOT NULL DEFAULT 3 CHECK (holo_level BETWEEN 1 AND 5); ` ]; diff --git a/services/cards/service.js b/services/cards/service.js index b79fe44..440b45e 100644 --- a/services/cards/service.js +++ b/services/cards/service.js @@ -2,7 +2,7 @@ import { createHash, randomBytes, randomInt, randomUUID } from "node:crypto"; import { normalizeReward } from "./rewards.js"; import { MASS_RECYCLE_RARITIES, planRecycling, spareQuantity, validateShopSetting } from "./stardust.js"; -import { FULL_ART_FORMAT, buildPublishedCatalog, collectionDrawableEditions, createCatalogIndex, holographicFinishIds, isMythicEditionIdOf, legendaryParentEdition, MATCH_HOLO_PALETTE_ID, mythicEditionId, publicCatalog, validateRarityWeights } from "./catalog.js"; +import { DEFAULT_EFFECT_TUNING, FULL_ART_FORMAT, isEffectTuning, buildPublishedCatalog, collectionDrawableEditions, createCatalogIndex, holographicFinishIds, isMythicEditionIdOf, legendaryParentEdition, MATCH_HOLO_PALETTE_ID, mythicEditionId, publicCatalog, validateRarityWeights } from "./catalog.js"; import { computeStreak, DAILY_REPEAT_WINDOW_DAYS, dailyCandidates, dailyDayKey, dailyZoom, drawDailyPuzzle, guessHint, isDayKey, MAX_DAILY_GUESSES, nextDailyAt, shiftDayKey } from "./daily.js"; import { calculateRecharge, pinnedRecharge, drawPack, drawShopPack, MAX_RECHARGE_INTERVAL_MS, MAX_RESERVE_OPENINGS, MIN_RECHARGE_INTERVAL_MS, spendOpening } from "./game-rules.js"; import { DEFAULT_DESTINATIONS_PATH, loadExpeditionDestinations } from "./expedition-content.js"; @@ -153,8 +153,8 @@ export class CardsService { const collectionIds = new Set(versioned.collections.map((collection) => collection.id)); const shapeIds = new Set(versioned.particleShapes.map((shape) => shape.id)); const paletteIds = new Set([...versioned.particlePalettes.map((palette) => palette.id), MATCH_HOLO_PALETTE_ID]); - const variations = this.db.prepare("SELECT edition_id, card_id, finish_id, status FROM mythic_variations").all() - .map((row) => ({ editionId: row.edition_id, cardId: row.card_id, finishId: row.finish_id, status: row.status })) + const variations = this.db.prepare("SELECT edition_id, card_id, finish_id, status, holo_intensity, holo_level FROM mythic_variations").all() + .map((row) => ({ editionId: row.edition_id, cardId: row.card_id, finishId: row.finish_id, status: row.status, intensity: row.holo_intensity, level: row.holo_level })) .filter((row) => holographic.has(row.finishId) && legendaryParentEdition(versioned, row.cardId) && isMythicEditionIdOf(row.editionId, row.cardId)); const openingSettings = this.db.prepare("SELECT scope, target_id, particle_shape_id, particle_palette_id FROM mythic_opening_settings ORDER BY scope, target_id").all() .map((row) => ({ @@ -305,6 +305,26 @@ export class CardsService { return { catalog: publicCatalog(this.catalog) }; } + // Règle les paliers d'une variation : intensité de la palette et palier propre à son effet, s'il en déclare un. Les joueurs qui + // la possèdent voient aussitôt le nouveau réglage, sans autre changement. + setMythicTuning(playerId, editionId, { intensity, level } = {}) { + this.requireAdmin(playerId); + const versioned = this.versionedCatalog; + const row = this.db.prepare("SELECT card_id, finish_id, holo_intensity, holo_level FROM mythic_variations WHERE edition_id = ?").get(editionId); + if (!row || !versioned.cards.some((item) => item.id === row.card_id)) fail(404, "MYTHIC_NOT_FOUND", "Variation mythique introuvable."); + const preset = versioned.effectPresets.find((item) => item.id === versioned.finishes.find((finish) => finish.id === row.finish_id)?.effectPresetId); + if (!isEffectTuning(intensity)) fail(400, "INTENSITY_INVALID", "Choisissez une intensité de palette entre 1 et 5."); + if (!isEffectTuning(level)) fail(400, "LEVEL_INVALID", "Choisissez un palier d’effet entre 1 et 5."); + if (!preset?.level && level !== DEFAULT_EFFECT_TUNING) fail(400, "LEVEL_UNAVAILABLE", "Cet effet n’a pas de palier réglable."); + if (row.holo_intensity === intensity && row.holo_level === level) fail(400, "TUNING_UNCHANGED", "La variation a déjà ces réglages."); + this.database.transaction(() => { + this.db.prepare("UPDATE mythic_variations SET holo_intensity = ?, holo_level = ?, updated_at = ?, updated_by = ? WHERE edition_id = ?").run(intensity, level, this.now(), playerId, editionId); + this.audit(playerId, "catalog_mythic_tuning_changed", row.card_id, { editionId, intensity, level }); + this.reloadCatalog(); + }); + return { catalog: publicCatalog(this.catalog) }; + } + requireCollection(collectionId) { if (!this.versionedCatalog.collections.some((collection) => collection.id === collectionId)) fail(404, "COLLECTION_NOT_FOUND", "Collection introuvable."); } diff --git a/tests/nebula-cards.test.mjs b/tests/nebula-cards.test.mjs index a0b81fb..021f9c8 100644 --- a/tests/nebula-cards.test.mjs +++ b/tests/nebula-cards.test.mjs @@ -260,7 +260,7 @@ test("finishes are generated: standard plus one per holographic effect and seven assert.equal("finishes" in rawCatalog, false); const preset = catalog.effectPresets.find((effect) => effect.id === "spectral-prism"); assert.equal(preset.kind, "holographic"); - assert.deepEqual(catalog.finishes.map((finish) => finish.id), ["standard", ...["", "full-art-"].flatMap((format) => ["spectral-prism", "diffraction-sheen", "prismatic-backdrop"].flatMap((effect) => ["rainbow", "solar", "dusk", "crimson", "nature", "aurora", "winter", "cosmic", "darkness"].map((palette) => `${format}${effect}-${palette}`)))]); + assert.deepEqual(catalog.finishes.map((finish) => finish.id), ["standard", ...["", "full-art-"].flatMap((format) => ["spectral-prism", "diffraction-sheen", "prismatic-backdrop", "shattered-ice"].flatMap((effect) => ["rainbow", "solar", "dusk", "crimson", "nature", "aurora", "winter", "cosmic", "darkness"].map((palette) => `${format}${effect}-${palette}`)))]); assert.deepEqual(catalog.finishes[0], { id: "standard", label: "Standard", effectPresetId: null, paletteId: null, formatId: "standard" }); assert.ok(catalog.finishes.every((finish) => !("particlePresetId" in finish))); assert.ok(catalog.effectPalettes.every((palette) => palette.colors.length === 7 && new Set(palette.colors).size === 7)); @@ -273,7 +273,7 @@ test("finishes are generated: standard plus one per holographic effect and seven withNewEffect.effectPresets.push({ id: "effect-x", kind: "holographic", label: "Effet X" }); withNewEffect.effectPalettes.push({ id: "ember", label: "Braise", colors: ["#7f1d1d", "#b91c1c", "#ef4444", "#f97316", "#fb923c", "#fdba74", "#fff7ed"], highlight: "#ffffff" }); const generated = prepareVersionedCatalog(withNewEffect).finishes; - assert.equal(generated.length, 1 + 2 * 4 * 10); + assert.equal(generated.length, 1 + 2 * 5 * 10); assert.deepEqual(generated.find((finish) => finish.id === "effect-x-ember"), { id: "effect-x-ember", label: "Effet X — Braise", effectPresetId: "effect-x", paletteId: "ember", formatId: "standard" }); const invalidPalette = structuredClone(rawCatalog); @@ -1205,6 +1205,65 @@ test("changing a mythic finish keeps its id, the players' copies and their exped database.close(); }); +test("a mythic variation tunes its palette intensity and its effect level, kept across finish changes", () => { + const now = 1_800_000_000_000; + const database = new CardsDatabase(":memory:"); + const service = new CardsService({ database, catalog: baseCatalog, now: () => now, random: () => 0 }); + const admin = service.upsertPlayer({ discordId: "tuning-admin", displayName: "Admin", isAdmin: true }); + const player = service.upsertPlayer({ discordId: "tuning-player", displayName: "Player" }); + service.setCardMythicConfig(admin.id, "mythic-card-pull", { finishIds: ["prismatic-backdrop-solar", "diffraction-sheen-solar"] }); + const parallax = "mythic-card-pull-prismatic-backdrop-solar"; + const diffraction = "mythic-card-pull-diffraction-sheen-solar"; + const editionOf = (catalog, id) => catalog.editions.find((edition) => edition.id === id); + // Une variation neuve garde le palier central, 3 : rien n'est publié, le rendu de référence s'applique. + assert.deepEqual([editionOf(service.catalog, parallax).holoIntensity, editionOf(service.catalog, parallax).holoLevel], [undefined, undefined]); + + assert.throws(() => service.setMythicTuning(player.id, parallax, { intensity: 5, level: 5 }), /administrateur/); + assert.throws(() => service.setMythicTuning(admin.id, "unknown-mythic", { intensity: 5, level: 5 }), /introuvable/); + assert.throws(() => service.setMythicTuning(admin.id, parallax, { intensity: 6, level: 5 }), /intensité/); + assert.throws(() => service.setMythicTuning(admin.id, parallax, { intensity: "5", level: 5 }), /intensité/); + assert.throws(() => service.setMythicTuning(admin.id, parallax, { intensity: 5, level: 0 }), /palier/); + // Le Reflet diffractif ne déclare pas de palier propre : seule son intensité se règle. + assert.throws(() => service.setMythicTuning(admin.id, diffraction, { intensity: 5, level: 1 }), /pas de palier/); + assert.throws(() => service.setMythicTuning(admin.id, parallax, { intensity: 3, level: 3 }), /déjà ces réglages/); + + const tuned = editionOf(service.setMythicTuning(admin.id, parallax, { intensity: 1, level: 5 }).catalog, parallax); + assert.deepEqual([tuned.holoIntensity, tuned.holoLevel], [1, 5]); + assert.equal(editionOf(service.setMythicTuning(admin.id, diffraction, { intensity: 4, level: 3 }).catalog, diffraction).holoIntensity, 4); + const audit = database.db.prepare("SELECT entity_id, details_json FROM audit_log WHERE event_type = 'catalog_mythic_tuning_changed' ORDER BY rowid").get(); + assert.deepEqual([audit.entity_id, JSON.parse(audit.details_json)], ["mythic-card-pull", { editionId: parallax, intensity: 1, level: 5 }]); + + // Vers un effet sans palier propre, l'intensité reste et le palier n'est plus publié ; il revient avec un effet qui en a un. + service.setMythicFinish(admin.id, parallax, "diffraction-sheen-cosmic"); + assert.deepEqual([editionOf(service.catalog, parallax).holoIntensity, editionOf(service.catalog, parallax).holoLevel], [1, undefined]); + service.setMythicFinish(admin.id, parallax, "shattered-ice-cosmic"); + assert.equal(editionOf(service.catalog, parallax).holoLevel, 5); + // Les réglages survivent au redémarrage ; la base refuse un palier hors de 1 à 5. + const reloaded = new CardsService({ database, catalog: baseCatalog, now: () => now }); + assert.deepEqual([editionOf(reloaded.catalog, parallax).holoIntensity, editionOf(reloaded.catalog, parallax).holoLevel], [1, 5]); + assert.throws(() => database.db.prepare("UPDATE mythic_variations SET holo_level = 6 WHERE edition_id = ?").run(parallax), /CHECK/); + database.close(); +}); + +test("holographic effect levels and intensities are declared by the catalog and checked on editions", () => { + assert.deepEqual(rawCatalog.effectIntensity.levels, ["Très douce", "Douce", "Normale", "Intense", "Très intense"]); + assert.deepEqual(rawCatalog.effectPresets.filter((preset) => preset.level).map((preset) => preset.id), ["spectral-prism", "prismatic-backdrop", "shattered-ice"]); + const withoutIntensity = structuredClone(rawCatalog); + delete withoutIntensity.effectIntensity; + assert.throws(() => prepareVersionedCatalog(withoutIntensity), /effectIntensity/); + const brokenLevel = structuredClone(rawCatalog); + brokenLevel.effectPresets.find((preset) => preset.id === "prismatic-backdrop").level.levels.pop(); + assert.throws(() => prepareVersionedCatalog(brokenLevel), /level needs a label/); + const variation = (extra) => ({ editionId: "mythic-card-pull-x", cardId: "mythic-card-pull", finishId: "diffraction-sheen-solar", status: "active", ...extra }); + // Un palier d'effet n'est publié que si l'effet de la finition en déclare un. + const published = buildPublishedCatalog(baseCatalog, { variations: [variation({ intensity: 5, level: 1 })] }); + const edition = published.editions.find((item) => item.id === "mythic-card-pull-x"); + assert.deepEqual([edition.holoIntensity, edition.holoLevel], [5, undefined]); + const tunedEdition = structuredClone(published); + tunedEdition.editions.find((item) => item.id === "mythic-card-pull-x").holoLevel = 1; + assert.throws(() => validateCardsCatalog(tunedEdition), /level its effect does not declare/); +}); + test("pack availability and drop rates live in the database and apply immediately", () => { assert.equal("dropTables" in rawCatalog, false); assert.ok(rawCatalog.collections.every((collection) => !("active" in collection) && !("dropWeights" in collection))); diff --git a/website/public/data/cards/catalog.json b/website/public/data/cards/catalog.json index c844114..d3f237d 100644 --- a/website/public/data/cards/catalog.json +++ b/website/public/data/cards/catalog.json @@ -41,7 +41,8 @@ { "id": "spectral-prism", "kind": "holographic", - "label": "Prisme spectral" + "label": "Prisme spectral", + "level": { "label": "Vitesse", "levels": ["Très lente", "Lente", "Normale", "Rapide", "Très rapide"] } }, { "id": "diffraction-sheen", @@ -51,9 +52,17 @@ { "id": "prismatic-backdrop", "kind": "holographic", - "label": "Parallaxe prismatique" + "label": "Parallaxe prismatique", + "level": { "label": "Amplitude", "levels": ["Très douce", "Douce", "Moyenne", "Forte", "Très forte"] } + }, + { + "id": "shattered-ice", + "kind": "holographic", + "label": "Glace brisée", + "level": { "label": "Taille des éclats", "levels": ["Très fins", "Fins", "Moyens", "Gros", "Très gros"] } } ], + "effectIntensity": { "label": "Intensité", "levels": ["Très douce", "Douce", "Normale", "Intense", "Très intense"] }, "cardFormats": [ { "id": "standard", diff --git a/website/public/static/img/cards/effects/shattered-ice-cracks.webp b/website/public/static/img/cards/effects/shattered-ice-cracks.webp new file mode 100644 index 0000000..f0a41c6 Binary files /dev/null and b/website/public/static/img/cards/effects/shattered-ice-cracks.webp differ diff --git a/website/public/static/img/cards/effects/shattered-ice-facet-0.webp b/website/public/static/img/cards/effects/shattered-ice-facet-0.webp new file mode 100644 index 0000000..f05ad4f Binary files /dev/null and b/website/public/static/img/cards/effects/shattered-ice-facet-0.webp differ diff --git a/website/public/static/img/cards/effects/shattered-ice-facet-1.webp b/website/public/static/img/cards/effects/shattered-ice-facet-1.webp new file mode 100644 index 0000000..438d507 Binary files /dev/null and b/website/public/static/img/cards/effects/shattered-ice-facet-1.webp differ diff --git a/website/public/static/img/cards/effects/shattered-ice-facet-2.webp b/website/public/static/img/cards/effects/shattered-ice-facet-2.webp new file mode 100644 index 0000000..0322e9e Binary files /dev/null and b/website/public/static/img/cards/effects/shattered-ice-facet-2.webp differ diff --git a/website/public/static/img/cards/effects/shattered-ice-facet-3.webp b/website/public/static/img/cards/effects/shattered-ice-facet-3.webp new file mode 100644 index 0000000..20614e0 Binary files /dev/null and b/website/public/static/img/cards/effects/shattered-ice-facet-3.webp differ diff --git a/website/src/features/cards/NebulaCard.jsx b/website/src/features/cards/NebulaCard.jsx index 694c189..3230b1e 100644 --- a/website/src/features/cards/NebulaCard.jsx +++ b/website/src/features/cards/NebulaCard.jsx @@ -6,6 +6,9 @@ import { MATCH_HOLO_PALETTE_ID, MATCH_HOLO_PALETTE_LABEL, resolveMythicOpeningSt const STANDARD_CARD_LAYOUT = "standard"; // Effets holographiques qui découpent l'illustration en calques de parallaxe (décor, puis héros détouré). const PARALLAX_EFFECTS = new Set(["prismatic-backdrop"]); +// Effets holographiques à facettes : chaque groupe d'éclats de la mosaïque capte la lumière sous un angle qui lui est propre. +const SHARD_EFFECTS = new Set(["shattered-ice"]); +const SHARD_FACETS = [0, 1, 2, 3]; function useCardTilt() { const cardRef = useRef(null); @@ -249,6 +252,9 @@ function CardFace({ entry, quantity, visual, size }) { {visual.effectPreset && <>