Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-08-01 14:46:10 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-08-01 14:46:10 -0700
commit4c6340f67150ad91b8d2e8358734a79613b781e9 (patch)
tree596641e6b6cbbca932c67a8f59fa8fa97ca8c886
parent28e0188ecdc5c2dcfb37469ea089717868650e6a (diff)
Wire clear-hex dialog back up
-rw-r--r--public/index.html1
-rw-r--r--src/modules/gameboard.js32
2 files changed, 16 insertions, 17 deletions
diff --git a/public/index.html b/public/index.html
index 870c79e..51c4fcf 100644
--- a/public/index.html
+++ b/public/index.html
@@ -373,6 +373,7 @@
<button
style="display: block; margin-left: auto;"
value="confirm"
+ formmethod="dialog"
>Confirm</button>
</div>
</form>
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));