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 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-06 23:46:55 +01:00
parent fd95e4ccff
commit 8c7a6a3e91
5 changed files with 105 additions and 14 deletions

View file

@ -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/<collectionId>/back.webp`; le composant conserve le nom en

View file

@ -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);
});

View file

@ -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",

View file

@ -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",

View file

@ -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 <OpeningStage
key={opening.id}
catalog={catalog}
@ -26,13 +35,17 @@ export function PackPanel({ catalog, state, runMutation, busy, content, reserveC
return runMutation(() => 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 <section key={category} className="nds-panel nebula-pack-category" aria-labelledby={`nebula-pack-category-${category}`}>
<div className="nds-section-heading nebula-pack-category-heading"><div><h3 id={`nebula-pack-category-${category}`}>{label}</h3><p>{description}</p></div><span className="nds-badge" data-variant={category === "event" ? "gold" : "neutral"}>{collections.length}</span></div>
{collections.length ? <div className="nebula-pack-grid">{collections.map((collection) => <button key={collection.id} type="button" className="nebula-pack" disabled={busy || (!hasReserve && !hasPurchased)} aria-label={`${content.open} : ${collection.name}`} onClick={() => runMutation(() => openPack(collection.id, { purchased: !hasReserve }))}>
{collections.length ? <div className="nebula-pack-grid">{collections.map((collection) => <button key={collection.id} type="button" className="nebula-pack" disabled={busy || (!hasReserve && !hasPurchased)} aria-label={`${content.open} : ${collection.name}`} onClick={() => openCollection(collection.id)}>
<span className="nebula-pack-back" data-card-size="md"><CollectionCardBack collection={collection} /></span>
<span className="nebula-pack-note"><span className="nebula-pack-copy" title={collection.description}>{collection.description}</span></span>
</button>)}</div> : <div className="nds-empty-state"><p>{content.empty}</p></div>}
@ -111,11 +124,12 @@ function OpeningOdds({ catalog, opening, collection, content, shopShare }) {
</section>;
}
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 <section className="nebula-opening-stage" aria-labelledby="nebula-opening-title">
<div className="nds-section-heading nebula-section-heading"><div><p className="eyebrow">Paquet attribué</p><h2 id="nebula-opening-title">Révélez vos trois cartes</h2></div>
{!allStarted && <button className="nds-button" data-size="sm" data-variant="secondary" type="button" onClick={() => setRevealed(new Set(opening.cards.map((card) => card.id)))}>Tout révéler</button>}
{allRevealed && <button className="nds-button" data-size="sm" data-variant="secondary" type="button" disabled={busy} onClick={finish}>{content.back}</button>}
{!allStarted && <button ref={revealAllRef} className="nds-button" data-size="sm" data-variant="secondary" type="button" onClick={() => setRevealed(new Set(opening.cards.map((card) => card.id)))}>Tout révéler</button>}
{allRevealed && <div className="nds-toolbar">
<button className="nds-button" data-size="sm" data-variant="secondary" type="button" disabled={busy} onClick={finish}>{content.back}</button>
{onOpenAnother && <button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={busy} onClick={openAnother}>{content.openAnother}</button>}
</div>}
</div>
<div className="nebula-opening-cards">
{opening.cards.map((card) => <NebulaCard key={card.id} catalog={catalog} entry={card} size="lg" faceUp={false} backCollection={collection} newBadge={card.isNewEdition ? content.newBadge : null} revealed={revealed.has(card.id)} onReveal={() => setRevealed((current) => new Set([...current, card.id]))} onRevealComplete={() => setFinishedReveals((current) => new Set([...current, card.id]))} />)}