File size: 1,020 Bytes
883d13a
89c1c4c
 
 
 
 
 
 
 
 
 
883d13a
 
 
 
89c1c4c
00ee4d1
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

document.addEventListener('DOMContentLoaded', () => {
    const dicePool = document.querySelector('dice-pool');
    const diceGrid = document.querySelector('dice-grid');
    const castBtn = document.getElementById('castBtn');

    // Initialize dice pool with some dice
    dicePool.dice = ['A', 'B', 'C', 'D', 'E'];
    
    // Helper function to get random dice from pool
    function getRandomDice(dicePool, count) {
        // Make copy of current dice array
        const currentDice = [...(dicePool.dice || [])];
        const shuffled = [...currentDice].sort(() => 0.5 - Math.random());
        return shuffled.slice(0, Math.min(count, currentDice.length));
    }

    // Ensure button exists before adding listener
    if (castBtn) {
        castBtn.addEventListener('click', () => {
            // Get random 5 dice from the pool
            const selectedDice = getRandomDice(dicePool, 5);
            
            // Place dice on the grid
            diceGrid.placeDice(selectedDice);
        });
    }
});