diff --git a/DESIGN_SYSTEM.md b/DESIGN_SYSTEM.md index 97ff006..4b212aa 100644 --- a/DESIGN_SYSTEM.md +++ b/DESIGN_SYSTEM.md @@ -583,6 +583,7 @@ Sidebar : - icones SVG pour Accueil, Toolboxes et Jeux ; - navigation active en violet soft ; - le logo controller garde le gradient de l'ancien badge et une rotation au hover. +- quand la réserve d'ouvertures Sokko TCG est pleine, l'icône Sokko TCG porte en haut à droite une pastille or `nav-icon-count` avec le solde, détourée de la couleur de la sidebar ; le nom accessible et l'infobulle compacte le précisent. L'icône étant un masque, la pastille est posée à côté dans `nav-icon-slot`. Hors de la page de jeu, la route légère `GET /api/cards/reserve` la tient à jour (chargement, retour sur l'onglet, échéance de recharge) ; sur la page, chaque état serveur reçu la remplace aussitôt. - `sidebar[data-variant="compact"]` réduit la navigation à 72 px jusqu'à `1024px`, ainsi que lorsqu'un panneau toolbox latéral est ouvert en fenêtre large : la manette conserve sa rotation au hover, les trois entrées principales et les trois raccourcis secondaires utilisent `Tooltip`, puis l’encart inférieur contient uniquement les actions globales exporter/importer empilées avec leurs propres infobulles. Le nom de marque affiche `Sokko` en blanc et `G` en dore. Au hover, `Sokko` anime vers le dore de droite a gauche puis revient au hover out. @@ -1195,7 +1196,9 @@ seulement si la largeur manque), puis un `nds-panel` compact « Probabilités » (les taux et la garantie du paquet offert s'il y en a). « Retour » ramène à la liste une fois toutes les cartes révélées ; à côté, un bouton primaire rouvre directement la même collection tant qu'il reste une ouverture, sauf après un paquet offert ou de la -boutique, qui n'en consomment pas. +boutique, qui n'en consomment pas. Sous le titre, une ligne discrète « Ouvertures +restantes » sépare la recharge auto des ouvertures achetées à l'unité, puisque le menu +latéral et sa réserve sont masqués pendant l'ouverture. Chaque collection fournit un dos illustré WebP au ratio 5:7 sous `static/img/cards//back.webp`; le composant conserve le nom en diff --git a/e2e/nebula-cards.spec.js b/e2e/nebula-cards.spec.js index b0433d7..79645eb 100644 --- a/e2e/nebula-cards.spec.js +++ b/e2e/nebula-cards.spec.js @@ -1613,6 +1613,11 @@ test("a player chains packs of the same collection while openings remain", async await page.getByRole("button", { name: "Ouvrir ce paquet : Genèse Astrale", exact: true }).click(); await expect(revealAll).toBeVisible(); await expect(openAnother).toHaveCount(0); + // L'étape rappelle ce qu'il reste à ouvrir, en séparant la recharge automatique des ouvertures achetées. + const balances = await page.evaluate(async () => (await globalThis.fetch("/api/cards/state")).json().then((state) => [state.recharge.openingsBalance, state.wallet.purchasedOpenings])); + const remaining = page.getByRole("definition"); + await expect(page.getByRole("term")).toHaveText(["Recharge auto", "À l’unité"]); + await expect(remaining).toHaveText(balances.map(String)); await revealAll.click(); await expect(openAnother).toBeEnabled(); await expect.poll(pendingCollection).toBeNull(); @@ -1634,6 +1639,7 @@ test("a player chains packs of the same collection while openings remain", async const openRequest = page.waitForRequest((request) => request.method() === "POST" && request.url().endsWith("/api/cards/openings")); await revealAll.click(); await expect(openAnother).toBeEnabled(); + await expect(remaining).toHaveText(["0", "1"]); await openAnother.click(); expect((await openRequest).postDataJSON()).toEqual({ collectionId: "astral-genesis", purchased: true }); await expect(page.getByRole("alert")).toContainText("aucune ouverture achetée"); @@ -1650,3 +1656,35 @@ test("a player chains packs of the same collection while openings remain", async await expect(back).toBeEnabled(); await expect(openAnother).toHaveCount(0); }); + +test("the Sokko TCG menu entry shows a count while the opening reserve is full", async ({ page }) => { + const cardsLink = page.getByRole("navigation", { name: "Navigation principale" }).getByRole("link", { name: /^Sokko TCG/ }); + const count = cardsLink.locator(".nav-icon-count"); + // Visiteur sans compte : aucune pastille. + await page.goto("/#/toolboxes"); + await expect(cardsLink).toHaveAccessibleName("Sokko TCG"); + await expect(count).toHaveCount(0); + + await page.goto("/#/cards"); + await page.getByRole("button", { name: "Version développement", exact: true }).click(); + await expect(page.getByRole("heading", { name: "Sokko TCG", exact: true })).toBeVisible(); + // Le compte de développement garde une réserve juste sous le maximum : la route est simulée pleine. + await page.route("**/api/cards/reserve", (route) => route.fulfill({ json: { recharge: { openingsBalance: 5, rechargeAnchor: null, nextOpeningAt: null } } })); + await page.goto("/#/toolboxes"); + await page.reload(); + await expect(count).toHaveText("5"); + await expect(cardsLink).toHaveAccessibleName("Sokko TCG (réserve d’ouvertures pleine)"); + const [icon, badge] = await Promise.all([cardsLink.locator(".nav-icon").boundingBox(), count.boundingBox()]); + expect(badge.x).toBeGreaterThan(icon.x + icon.width / 2); + expect(badge.y).toBeLessThan(icon.y + icon.height / 2); + // En sidebar compacte, la pastille reste sur l'icône seule. + await page.setViewportSize({ width: 900, height: 800 }); + await expect(count).toBeVisible(); + await page.setViewportSize({ width: 1280, height: 720 }); + + // Sur la page de jeu, l'état réel (réserve non pleine) remplace aussitôt la valeur relue par le menu. + await page.getByRole("navigation", { name: "Navigation principale" }).getByRole("link", { name: /^Sokko TCG/ }).click(); + await expect(page.locator(".nebula-opening-reserve")).toBeVisible(); + await expect(count).toHaveCount(0); + await expect(cardsLink).toHaveAccessibleName("Sokko TCG"); +}); diff --git a/services/cards/api.js b/services/cards/api.js index fa297ec..5afa662 100644 --- a/services/cards/api.js +++ b/services/cards/api.js @@ -278,6 +278,12 @@ export function createCardsApiHandler({ return true; } + // Lue par le menu sur toutes les pages : un visiteur sans compte reçoit une réserve vide plutôt qu'une erreur. + if (req.method === "GET" && url.pathname === "/api/cards/reserve") { + json(res, 200, { recharge: session ? service.getReserve(session.player.id) : null }); + return true; + } + if (!session) throw Object.assign(new Error("Connectez-vous pour accéder à votre collection."), { status: 401, code: "AUTH_REQUIRED" }); if (req.method !== "GET") { const origin = req.headers.origin; diff --git a/services/cards/service.js b/services/cards/service.js index b0552ca..b1445a2 100644 --- a/services/cards/service.js +++ b/services/cards/service.js @@ -329,6 +329,11 @@ export class CardsService { return recharge; } + // Réserve rechargeable seule, pour la pastille du menu : bien plus légère que l'état complet. + getReserve(playerId) { + return this.database.transaction(() => this.refreshRecharge(playerId)); + } + // Carte affichable à partir d'une édition (catalogue publié). cardEntry(editionId, extra = {}) { const edition = this.index.editions.get(editionId); diff --git a/tests/helpers/data-validation.mjs b/tests/helpers/data-validation.mjs index d04163a..bfb1650 100644 --- a/tests/helpers/data-validation.mjs +++ b/tests/helpers/data-validation.mjs @@ -88,6 +88,7 @@ export function validateSiteContent(site) { "navigation.toolboxes", "navigation.games", "navigation.cards", + "navigation.cardsReserveFull", "navigation.library", "navigation.about", "sidebar.badge", @@ -218,6 +219,9 @@ export function validateSiteContent(site) { "cards.packs.probabilities", "cards.packs.back", "cards.packs.openAnother", + "cards.packs.remainingLabel", + "cards.packs.remainingReserve", + "cards.packs.remainingPurchased", "cards.packs.newBadge", "cards.packs.shopShare", "cards.shop.packDescription", diff --git a/tests/nebula-cards-api.test.mjs b/tests/nebula-cards-api.test.mjs index 9f5cb96..0ea965a 100644 --- a/tests/nebula-cards-api.test.mjs +++ b/tests/nebula-cards-api.test.mjs @@ -359,3 +359,20 @@ test("cookies carry the __Host- prefix over HTTPS and only the prefixed session assert.equal((await call(handler, { path: "/api/cards/session", headers: { cookie: `sokkog_cards_session=${token}` } })).json.authenticated, false); assert.equal((await call(handler, { path: "/api/cards/session", headers: { cookie: `__Host-sokkog_cards_session=${token}` } })).json.authenticated, true); }); + +test("the reserve route answers visitors without an account and returns the player's recharge", async (t) => { + const handler = createCardsApiHandler({ projectRoot: resolve("."), enabled: true, devAuth: true, databasePath: ":memory:", env: { NODE_ENV: "test" }, random: () => 0 }); + t.after(() => handler.close()); + + const anonymous = await call(handler, { path: "/api/cards/reserve" }); + assert.equal(anonymous.status, 200); + assert.deepEqual(anonymous.json, { recharge: null }); + + const login = await call(handler, { method: "POST", path: "/api/cards/auth/dev", body: {} }); + const cookie = login.headers["set-cookie"].split(";")[0]; + const reserve = await call(handler, { path: "/api/cards/reserve", headers: { cookie } }); + const state = await call(handler, { path: "/api/cards/state", headers: { cookie } }); + assert.equal(reserve.status, 200); + assert.equal(reserve.json.recharge.openingsBalance, state.json.recharge.openingsBalance); + assert.equal(reserve.json.recharge.nextOpeningAt, state.json.recharge.nextOpeningAt); +}); diff --git a/website/public/data/site.json b/website/public/data/site.json index fa12f26..9d93ef8 100644 --- a/website/public/data/site.json +++ b/website/public/data/site.json @@ -8,6 +8,7 @@ "toolboxes": "Toolboxes", "games": "Jeux", "cards": "Sokko TCG", + "cardsReserveFull": "réserve d’ouvertures pleine", "library": "Librairie", "about": "C'est quoi Sokko G ?" }, @@ -201,6 +202,9 @@ "probabilities": "Probabilités", "back": "Retour", "openAnother": "Ouvrir un autre paquet de la même collection", + "remainingLabel": "Ouvertures restantes", + "remainingReserve": "Recharge auto", + "remainingPurchased": "À l’unité", "newBadge": "New", "shopShare": "des légendaires et mythiques tirées viennent de", "purchasedLabel": "Ouvertures achetées", diff --git a/website/src/components/Shell.jsx b/website/src/components/Shell.jsx index 478789b..0da0c10 100644 --- a/website/src/components/Shell.jsx +++ b/website/src/components/Shell.jsx @@ -1,5 +1,6 @@ // Rôle : structure le layout global avec sidebar, topbar, navigation et contenu. import { useEffect, useRef } from "react"; +import { useFullCardsReserve } from "../features/cards/cardsReserve.js"; import { Icon } from "./Icon.jsx"; import { ImportButton } from "./ImportButton.jsx"; import { Tooltip } from "./Tooltip.jsx"; @@ -41,6 +42,9 @@ export function Shell({ route, content, games, drawerGameId = "", drawerVisible } }, [compactGameLayout, compactToolboxVisible]); + const fullCardsReserve = useFullCardsReserve(cardsEnabled); + const cardsLabel = fullCardsReserve ? `${content.navigation.cards} (${content.navigation.cardsReserveFull})` : content.navigation.cards; + return (