// ============================================================================= // PACK OPENING SCREEN // ============================================================================= const { useState } = React; function PackScreen({ state, actions }) { const [phase, setPhase] = useState('idle'); // idle | shaking | revealing | summary const [pack, setPack] = useState(null); // array of card ids const [revealedIdx, setRevealedIdx] = useState([]); // bools const openPack = () => { if (state.packsToday <= 0) return; setPhase('shaking'); setTimeout(() => { const newPack = window.GAME_DATA.generatePack(5); setPack(newPack); setRevealedIdx(newPack.map(() => false)); setPhase('revealing'); }, 700); }; const reveal = (i) => { setRevealedIdx(arr => arr.map((v, idx) => idx === i ? true : v)); }; const revealAll = () => { setRevealedIdx(pack.map(() => true)); }; const finishPack = () => { // Persist new cards actions.openedPack(pack); setPhase('idle'); setPack(null); setRevealedIdx([]); }; if (state.packsToday <= 0 && phase === 'idle') { return (
◈ SIN STOCK · DAILY LIMIT
SOBRES AGOTADOS
Has abierto tus 2 sobres diarios.
Vuelve en 24h o reta a un campeón.
); } // IDLE — show the big pack if (phase === 'idle' || phase === 'shaking') { return (
◈ DAILY · SOBRE {3 - state.packsToday}/2
ABRIR SOBRE
5 CARTAS · 1 GARANTIZADA ≥ RARA
TT · v1.0 5 / 5
SLOT LEGENDS
· PACK · 5 ·
{phase==='idle' ? 'TOCA PARA ABRIR' : 'ABRIENDO...'}
); } // REVEALING phase const allRevealed = revealedIdx.every(Boolean); return (
◈ TU SOBRE · {revealedIdx.filter(Boolean).length} / 5 REVELADAS
{allRevealed ? '¡SOBRE COMPLETO!' : 'TOCA CADA CARTA PARA REVELAR'}
{pack.map((cardId, i) => { const card = window.GAME_DATA.getCard(cardId); const isNew = !state.collection[cardId]; const dupCount = pack.slice(0, i).filter(id => id === cardId).length; // If this same card appeared earlier in pack and was new there, this is a duplicate of this pack const newInPackBefore = pack.slice(0, i).some(id => id === cardId && !state.collection[id]); const labelNew = isNew && !newInPackBefore; return (
!revealedIdx[i] && reveal(i)}>
{revealedIdx[i] &&
}
); })}
{!allRevealed && } {allRevealed && }
); } window.PackScreen = PackScreen;