Web Dev Solutions

Catalin Mititiuc

From 4c6340f67150ad91b8d2e8358734a79613b781e9 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Thu, 1 Aug 2024 14:46:10 -0700 Subject: Wire clear-hex dialog back up --- src/modules/gameboard.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src/modules/gameboard.js') diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js index 25d17e2..9ba4f1a 100644 --- a/src/modules/gameboard.js +++ b/src/modules/gameboard.js @@ -226,6 +226,7 @@ export function start(el) { // For when the pointer leaves the window document.querySelector('object').addEventListener('pointerout', e => { + if (clearHexDialog.open) return; console.log('object pointerout'); console.log('Left map... CLEARING HOVERS'); svg.querySelectorAll('.hover').forEach(el => el.classList.remove('hover')); @@ -410,19 +411,15 @@ export function start(el) { grid.addEventListener('click', clickHandler); const clearHexDialog = document.querySelector('#clear-hex'); - //clearHexDialog.addEventListener('close', e => { - // if (clearHexDialog.returnValue === 'confirm') { - // [...top.container.children].forEach(child => { - // top.collection.delete(child); - // child.remove(); - // }); - // } - //}); - //clearHexDialog.querySelector('button[value="confirm"]').addEventListener('click', function(e) { - // e.preventDefault(); - // clearHexDialog.close(this.value); - //}); + clearHexDialog.addEventListener('close', e => { + if (clearHexDialog.returnValue === 'confirm') { + [...frontmost.children].forEach(child => { + frontmostStore.delete(child); + child.remove(); + }); + } + }); //gridTop.addEventListener('pointerleave', workaroundForWebKitBug233432(e => { // console.log('pointerleave top', performance.now(), top.cell); @@ -443,11 +440,12 @@ export function start(el) { //})); //topHex.addEventListener('click', clickHandler); - // - //topHex.addEventListener('contextmenu', e => { - // e.preventDefault(); - // getSelected() ? sightLine.toggleLock(top.cell) : clearHexDialog.showModal(); - //}); + + grid.addEventListener('contextmenu', e => { + e.preventDefault(); + + getSelected() ? sightLine.toggleLock(grid.querySelector('.hover')) : clearHexDialog.showModal(); + }); const startingLocations = svg.querySelector('.start-locations'); startingLocations && getUnits(startingLocations).forEach(unit => unit.addEventListener('click', selectOffBoard)); -- cgit v1.2.3