Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-06-28 15:18:34 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-06-28 15:18:34 -0700
commit80985eb58aead3441e65f36ac6d5b264bfb5ee0a (patch)
treedbc8367e074d9a8b4b06b6467574526b42f0fbf7
parent83457c5218047584d2d9e8210060b64b10739de0 (diff)
Update updateSightLine for cube coords
-rw-r--r--src/modules/gameboard.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 81d71a3..1cdec7b 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -87,11 +87,14 @@ function clearSightLine() {
}
function updateSightLine(cell) {
- const { dataset: { x: sX }, parentElement: { dataset: { y: sY }}} = cell,
- { dataset: { x: tX }, parentElement: { dataset: { y: tY }}} = sightLine.getLockTarget();
+ const CURRENT_ELEVATION_LEVEL = 0;
+ const { q: sq, r: sr, s: ss } = cell.dataset;
+ const { q: tq, r: tr, s: ts } = sightLine.getLockTarget().dataset;
+ const sourceIndex = { q: +sq, r: +sr, s: +ss };
+ const targetIndex = { q: +tq, r: +tr, s: +ts };
- const selector = sightLine.calcIndexes(+sX, +sY, +tX, +tY)
- .map(([x, y]) => `g.grid g[data-y="${y}"] g[data-x="${x}"] use[href="#hex"]`)
+ const selector = sightLine.calcIndexes(sourceIndex, targetIndex)
+ .map(({ q, r, s }) => `g[data-q="${q}"][data-r="${r}"][data-s="${s}"][data-t="${CURRENT_ELEVATION_LEVEL}"] use[href="#hex"]`)
.join(', ');
const hexes = svg.querySelectorAll(selector);