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

@ -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]))} />)}