index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-07-26 16:17:23 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-07-26 16:17:23 -0700 |
commit | 54ad14b3f97eed8ae1d2b0664d17dc74f1578bd5 (patch) | |
tree | e1d3162dac099d51552d4ed7f01e5ccc93b199ae | |
parent | d3975d3fc519f21b670178a6e52c65edb75360a5 (diff) |
Clear hover on pointerout?
-rw-r--r-- | src/modules/gameboard.js | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js index 135b5e9..5cf0c51 100644 --- a/src/modules/gameboard.js +++ b/src/modules/gameboard.js @@ -222,8 +222,6 @@ export function start(el) { const startingLocations = svg.querySelector('.start-locations'); startingLocations && getUnits(startingLocations).forEach(unit => unit.addEventListener('click', selectOffBoard)); - svg.addEventListener('pointerout', e => console.log('pointerout svg')); - getCells(svg).forEach(cell => { cell.addEventListener('click', e => { const occupant = getCellOccupant(cell); @@ -333,14 +331,23 @@ export function start(el) { } }); - cell.addEventListener('pointerout', () => { - console.log('pointerout cell', cell); - getActiveSightLine(svg) && clearSightLine(); + cell.addEventListener('pointerout', e => { + // If pointerout was not triggered by hovering over an element on that + // game hex + if (!e.relatedTarget || top.collection.get(e.relatedTarget)?.parent !== cell) { + [...top.container.children].forEach(child => { + top.collection.get(child).parent.append(child); + top.collection.delete(child); + }); - const occupant = getCellOccupant(cell); + cell.classList.remove('hover'); + getActiveSightLine(svg) && clearSightLine(); - if (occupant) { - firingArc.toggleCounterVisibility(svg, occupant, false); + const occupant = getCellOccupant(cell); + + if (occupant) { + firingArc.toggleCounterVisibility(svg, occupant, false); + } } }); }); @@ -353,14 +360,14 @@ export function start(el) { // debug // // Add a trooper counter - const attacker = { dataset: { allegiance: 'attacker', number: 1, squad: 1 }}; + //const attacker = { dataset: { allegiance: 'attacker', number: 1, squad: 1 }}; // const defender = { dataset: { allegiance: 'defender', number: 1, squad: 2 }}; - const cell = getCell(0, 0, 0, 0); - const trooper = soldier.createCounter(attacker, 'blazer'); + //const cell = getCell(0, 0, 0, 0); + //const trooper = soldier.createCounter(attacker, 'blazer'); //const trooperSack = document.createElementNS(svgns, 'g'); //trooperSack.classList.add('cell-contents'); //trooperSack.append(trooper); - soldier.place(svg, trooper, cell); + //soldier.place(svg, trooper, cell); // Add some counters in an unoccupied cell //const countersCell = getCell(-1, 1, 0, 0); |