Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-08-01 15:36:23 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-08-01 15:40:31 -0700
commit9959b880da96e12eb8f4305c4aae38539fcd4e30 (patch)
tree2f7283b3a78e56cb4e11468d827d393a5fc9fdf7
parent4c6340f67150ad91b8d2e8358734a79613b781e9 (diff)
Get sight line working again
-rw-r--r--src/modules/gameboard.js30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 9ba4f1a..a033a29 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -125,7 +125,7 @@ function updateSightLine(cell) {
}
function drawSightLine(sourceCell, targetCell) {
- calcSightLine(sourceCell, targetCell)
+ calcSightLine(sourceCell, targetCell);
const line = sightLine.create(getCellPosition(sourceCell), getCellPosition(targetCell));
svg.querySelector('.gameboard').appendChild(line);
}
@@ -239,6 +239,8 @@ export function start(el) {
}
frontmostStore.delete(child);
});
+
+ getActiveSightLine(svg) && clearSightLine();
console.log('object', svg.querySelectorAll('.hover'));
});
@@ -319,8 +321,17 @@ export function start(el) {
targetCell.classList.contains('frontmost') ? frontmostStore.get(e.target.closest('.frontmost > *')).classList.add('hover') : targetCell.classList.add('hover');
}
+
}
+ const selected = getSelected();
+
+ if (selected && targetCell && svg.querySelector('.grid').contains(selected) && !getLockedSightLine(svg) && selected.parentElement !== frontmost) {
+ clearSightLine();
+ drawSightLine(selected.parentElement, grid.querySelector('.hover'));
+ } else {
+ getActiveSightLine(svg) && clearSightLine();
+ }
//const counter = targetCell && targetCell.querySelector('.counter');
//console.log('pointerover', 'targetCell', targetCell);
@@ -347,6 +358,7 @@ export function start(el) {
//targetCell && targetCell.classList.add('hover');
+
//if (targetCell && !targetCell.classList.contains('frontmost')) {
// targetCell.classList.add('hover');
// const occupant = targetCell.querySelector('.counter');
@@ -444,14 +456,26 @@ export function start(el) {
grid.addEventListener('contextmenu', e => {
e.preventDefault();
- getSelected() ? sightLine.toggleLock(grid.querySelector('.hover')) : clearHexDialog.showModal();
+ const selected = getSelected();
+
+ if (selected) {
+ if (sightLine.getSightLine()) sightLine.toggleLock(grid.querySelector('.hover'));
+ if (getActiveSightLine(svg)) {
+ clearSightLine();
+ if (selected.parentElement !== frontmost)
+ drawSightLine(selected.parentElement, grid.querySelector('.hover'));
+ }
+ } else {
+ clearHexDialog.showModal();
+ }
});
const startingLocations = svg.querySelector('.start-locations');
startingLocations && getUnits(startingLocations).forEach(unit => unit.addEventListener('click', selectOffBoard));
function clickHandler(e) {
- const targetCell = e.target.closest('[data-q][data-r][data-s][data-t]') || frontmostStore.get(e.target.closest('.frontmost > *'));
+ //const targetCell = e.target.closest('[data-q][data-r][data-s][data-t]') || frontmostStore.get(e.target.closest('.frontmost > *'));
+ const targetCell = grid.querySelector('.hover');
const occupant = frontmost.querySelector('.counter');
let toPlace = placing.pop();