From 8c7a6a3e91673d583db3f2ffc6747ee656ada753 Mon Sep 17 00:00:00 2001 From: Shinuwa Date: Fri, 6 Nov 2026 23:46:55 +0100 Subject: [PATCH] Offer to open another pack of the same collection after a reveal Players had to go back to the pack list between two openings. Once the cards are revealed, a button now reopens the same collection while an opening remains, using the reserve first and then purchased openings. Gift and shop packs do not offer it, since they spend no opening themselves. Co-Authored-By: Claude Opus 5.5 --- DESIGN_SYSTEM.md | 4 +- e2e/nebula-cards.spec.js | 62 ++++++++++++++++++++++++ tests/helpers/data-validation.mjs | 1 + website/public/data/site.json | 1 + website/src/features/cards/PackPanel.jsx | 51 ++++++++++++++----- 5 files changed, 105 insertions(+), 14 deletions(-) diff --git a/DESIGN_SYSTEM.md b/DESIGN_SYSTEM.md index 67aedf6..97ff006 100644 --- a/DESIGN_SYSTEM.md +++ b/DESIGN_SYSTEM.md @@ -1193,7 +1193,9 @@ désactivées quand il ne reste ni l'une ni l'autre. L'étape d'ouverture garde masque le menu et affiche les trois cartes au format `lg` (300 x 420 px, réduites 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. +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. 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 3a383d6..b0433d7 100644 --- a/e2e/nebula-cards.spec.js +++ b/e2e/nebula-cards.spec.js @@ -1364,6 +1364,9 @@ test("administrator navigates sections, manages mythic content and previews visu await expect(page.locator(".nebula-opening-odds")).toContainText("au moins 1 carte légendaire ou mieux garantie"); await page.getByRole("button", { name: "Tout révéler" }).click(); await expect(page.locator(".nebula-opening-cards .nebula-card[data-rarity=\"legendary\"], .nebula-opening-cards .nebula-card[data-rarity=\"mythic\"]").first()).toBeAttached(); + // Le paquet offert n'a consommé aucune ouverture : il ne propose pas d'en dépenser une pour continuer. + await expect(page.getByRole("button", { name: "Retour", exact: true })).toBeVisible({ timeout: 30_000 }); + await expect(page.getByRole("button", { name: "Ouvrir un autre paquet de la même collection", exact: true })).toHaveCount(0); }); test("administration stays within a phone screen", async ({ page }) => { @@ -1474,6 +1477,9 @@ test("players give cards and answer trade proposals from two accounts", async ({ await expect(partner.locator(".nebula-card-back img").first()).toHaveAttribute("src", "/static/img/cards/stardust/back.webp"); await expect(partner.locator(".nebula-opening-odds")).toContainText("50 % des légendaires et mythiques tirées viennent de Poussières d'étoiles"); await partner.getByRole("button", { name: "Tout révéler" }).click(); + await expect(partner.getByRole("button", { name: "Retour", exact: true })).toBeVisible({ timeout: 30_000 }); + // Ce paquet se paie en poussière : il ne propose pas de continuer sur une ouverture. + await expect(partner.getByRole("button", { name: "Ouvrir un autre paquet de la même collection", exact: true })).toHaveCount(0); await partner.getByRole("button", { name: "Retour", exact: true }).click({ timeout: 30_000 }); await partner.goto("/#/cards/shop"); await expect(partner.locator(".nebula-shop-wallet")).toContainText("440"); @@ -1588,3 +1594,59 @@ test("the shop pack rates count the cards it draws from the other collections", await expect(commonRow.locator("td").nth(2)).not.toHaveText("0"); await expect(commonRow.locator("td").nth(3)).toHaveText("—"); }); + +test("a player chains packs of the same collection while openings remain", async ({ page }) => { + test.setTimeout(60_000); + const openAnother = page.getByRole("button", { name: "Ouvrir un autre paquet de la même collection", exact: true }); + const revealAll = page.getByRole("button", { name: "Tout révéler" }); + const back = page.getByRole("button", { name: "Retour", exact: true }); + const pendingCollection = () => page.evaluate(async () => (await globalThis.fetch("/api/cards/state")).json().then((state) => state.pendingOpening?.collectionId ?? null)); + // Fait croire au client que le solde a changé à la fin de l'ouverture : le compte de développement a une réserve figée. + const stubBalance = (openingsBalance, purchasedOpenings) => page.route("**/api/cards/openings/*/complete", async (route) => { + const response = await route.fetch(); + const state = await response.json(); + await route.fulfill({ response, json: { ...state, recharge: { ...state.recharge, openingsBalance }, wallet: { ...state.wallet, purchasedOpenings } } }); + }); + + await page.goto("/#/cards/packs"); + await page.getByRole("button", { name: "Version développement", exact: true }).click(); + await page.getByRole("button", { name: "Ouvrir ce paquet : Genèse Astrale", exact: true }).click(); + await expect(revealAll).toBeVisible(); + await expect(openAnother).toHaveCount(0); + await revealAll.click(); + await expect(openAnother).toBeEnabled(); + await expect.poll(pendingCollection).toBeNull(); + // Le libellé long tient à la largeur minimale, à côté de « Retour ». + await page.setViewportSize({ width: 768, height: 900 }); + await expect(openAnother).toBeVisible(); + expect(await page.evaluate(() => globalThis.document.documentElement.scrollWidth <= globalThis.document.documentElement.clientWidth)).toBe(true); + await page.setViewportSize({ width: 1280, height: 720 }); + + // Le nouveau paquet vient de la même collection, et le clavier reprend sur « Tout révéler ». + await openAnother.click(); + await expect(page.getByRole("button", { name: "Révéler la carte" })).toHaveCount(3); + await expect(page.locator('.nebula-card-back img[src="/static/img/cards/astral-genesis/back.webp"]')).toHaveCount(3); + await expect.poll(pendingCollection).toBe("astral-genesis"); + await expect(revealAll).toBeFocused(); + + // Réserve vide mais ouverture achetée : l'enchaînement utilise l'achetée ; le refus du serveur laisse les cartes et l'action en place. + await stubBalance(0, 1); + const openRequest = page.waitForRequest((request) => request.method() === "POST" && request.url().endsWith("/api/cards/openings")); + await revealAll.click(); + await expect(openAnother).toBeEnabled(); + await openAnother.click(); + expect((await openRequest).postDataJSON()).toEqual({ collectionId: "astral-genesis", purchased: true }); + await expect(page.getByRole("alert")).toContainText("aucune ouverture achetée"); + await expect(page.locator('.nebula-opening-cards .nebula-card[data-card-size="lg"]')).toHaveCount(3); + await expect(openAnother).toBeEnabled(); + + // Plus aucune ouverture : seul le retour reste proposé. + await page.unroute("**/api/cards/openings/*/complete"); + await back.click(); + await page.reload(); + await page.getByRole("button", { name: "Ouvrir ce paquet : Genèse Astrale", exact: true }).click(); + await stubBalance(0, 0); + await revealAll.click(); + await expect(back).toBeEnabled(); + await expect(openAnother).toHaveCount(0); +}); diff --git a/tests/helpers/data-validation.mjs b/tests/helpers/data-validation.mjs index c9a45bd..d04163a 100644 --- a/tests/helpers/data-validation.mjs +++ b/tests/helpers/data-validation.mjs @@ -217,6 +217,7 @@ export function validateSiteContent(site) { "cards.packs.open", "cards.packs.probabilities", "cards.packs.back", + "cards.packs.openAnother", "cards.packs.newBadge", "cards.packs.shopShare", "cards.shop.packDescription", diff --git a/website/public/data/site.json b/website/public/data/site.json index dcb45fb..fa12f26 100644 --- a/website/public/data/site.json +++ b/website/public/data/site.json @@ -200,6 +200,7 @@ "open": "Ouvrir ce paquet", "probabilities": "Probabilités", "back": "Retour", + "openAnother": "Ouvrir un autre paquet de la même collection", "newBadge": "New", "shopShare": "des légendaires et mythiques tirées viennent de", "purchasedLabel": "Ouvertures achetées", diff --git a/website/src/features/cards/PackPanel.jsx b/website/src/features/cards/PackPanel.jsx index 95ec306..4cc672a 100644 --- a/website/src/features/cards/PackPanel.jsx +++ b/website/src/features/cards/PackPanel.jsx @@ -12,8 +12,17 @@ export function PackPanel({ catalog, state, runMutation, busy, content, reserveC const activeCollections = catalog.collections.filter((collection) => collection.active); const [completedOpening, setCompletedOpening] = useState(null); const opening = state.pendingOpening || completedOpening; + // L'enchaînement remplace l'étape : le focus clavier passe à la suivante au lieu de retomber en haut de page. + const focusNextStageRef = useRef(false); + // Une tuile n'a qu'une action : la réserve rechargeable d'abord, puis les ouvertures achetées. + const hasReserve = state.recharge.openingsBalance > 0; + const hasPurchased = state.wallet.purchasedOpenings > 0; + const openCollection = (collectionId) => runMutation(() => openPack(collectionId, { purchased: !hasReserve })); if (opening) { + // Un paquet offert ou de la boutique ne consomme aucune ouverture : l'enchaîner en dépenserait une sans le même tirage. + const canOpenAnother = !opening.options && (hasReserve || hasPurchased) + && activeCollections.some((collection) => collection.id === opening.collectionId && collection.packCategory !== "shop"); return completeOpening(opening.id)); }} onDismiss={() => setCompletedOpening(null)} + focusOnMountRef={focusNextStageRef} + onOpenAnother={canOpenAnother ? async () => { + focusNextStageRef.current = true; + const result = await openCollection(opening.collectionId); + if (result) setCompletedOpening(null); + else focusNextStageRef.current = false; + } : null} />; } const giftPacks = state.giftPacks || []; - // Une tuile n'a qu'une action : la réserve rechargeable d'abord, puis les ouvertures achetées. - const hasReserve = state.recharge.openingsBalance > 0; - const hasPurchased = state.wallet.purchasedOpenings > 0; const categories = [ ["permanent", content.permanent, content.permanentDescription], ["event", content.event, content.eventDescription] @@ -70,7 +83,7 @@ export function PackPanel({ catalog, state, runMutation, busy, content, reserveC const collections = activeCollections.filter((collection) => collection.packCategory === category); return

{label}

{description}

{collections.length}
- {collections.length ?
{collections.map((collection) => )}
:

{content.empty}

} @@ -111,11 +124,12 @@ function OpeningOdds({ catalog, opening, collection, content, shopShare }) {
; } -function OpeningStage({ catalog, opening, onComplete, onDismiss, busy, content, shopShare }) { +function OpeningStage({ catalog, opening, onComplete, onDismiss, onOpenAnother, focusOnMountRef, busy, content, shopShare }) { const [revealed, setRevealed] = useState(new Set()); const [finishedReveals, setFinishedReveals] = useState(new Set()); const [completed, setCompleted] = useState(false); const completionRequestedRef = useRef(false); + const revealAllRef = useRef(null); const allStarted = revealed.size === opening.cards.length; const allRevealed = finishedReveals.size === opening.cards.length; const collection = catalog.collections.find((item) => item.id === opening.collectionId); @@ -128,19 +142,30 @@ function OpeningStage({ catalog, opening, onComplete, onDismiss, busy, content, }); }, [allRevealed, onComplete]); + useEffect(() => { + if (!focusOnMountRef.current) return; + focusOnMountRef.current = false; + revealAllRef.current?.focus(); + }, [focusOnMountRef]); + + // L'enregistrement automatique a pu échouer : le retenter avant de quitter cette ouverture. + const ensureCompleted = async () => completed || Boolean(await onComplete()); + async function finish() { - if (completed) { - onDismiss(); - return; - } - const result = await onComplete(); - if (result) onDismiss(); + if (await ensureCompleted()) onDismiss(); + } + + async function openAnother() { + if (await ensureCompleted()) await onOpenAnother(); } return

Paquet attribué

Révélez vos trois cartes

- {!allStarted && } - {allRevealed && } + {!allStarted && } + {allRevealed &&
+ + {onOpenAnother && } +
}
{opening.cards.map((card) => setRevealed((current) => new Set([...current, card.id]))} onRevealComplete={() => setFinishedReveals((current) => new Set([...current, card.id]))} />)}