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-06-28 11:01:33 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-06-28 11:01:33 -0700 |
commit | ade861767b9961590ba31ca6ba30be1ca8346ea1 (patch) | |
tree | faab247251939a41392b0d2559407188ae4ea481 /src/modules/gameboard.js | |
parent | f270c13fb32666b3fe0c3579f5366dacc8ed1e2f (diff) |
WIP: get sightline working after cube coords update
Diffstat (limited to 'src/modules/gameboard.js')
-rw-r--r-- | src/modules/gameboard.js | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js index afb582b..66b493b 100644 --- a/src/modules/gameboard.js +++ b/src/modules/gameboard.js @@ -51,16 +51,9 @@ function isClone(counter) { } function getCellPosition(cell) { - let pt = new DOMPoint(0, 0), - transform = getComputedStyle(cell).transform.match(/-?\d+\.?\d*/g), - mtx = new DOMMatrix(transform); - pt = pt.matrixTransform(mtx); + const [x, y] = cell.getAttributeNS(null, 'transform').match(/-?\d+\.?\d*/g); - transform = getComputedStyle(cell.parentElement).transform.match(/-?\d+\.?\d*/g); - mtx = new DOMMatrix(transform); - pt = pt.matrixTransform(mtx); - - return pt; + return { x, y }; } function getCell(x, y) { @@ -108,11 +101,14 @@ function updateSightLine(cell) { } function drawSightLine(sourceCell, targetCell) { - const { dataset: { x: sX }, parentElement: { dataset: { y: sY }}} = sourceCell, - { dataset: { x: tX }, parentElement: { dataset: { y: tY }}} = targetCell; - - 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 CURRENT_ELEVATION_LEVEL = 0; + const { q: sq, r: sr, s: ss } = sourceCell.dataset; + const { q: tq, r: tr, s: ts } = targetCell.dataset; + const sourceIndex = { q: +sq, r: +sr, s: +ss }; + const targetIndex = { q: +tq, r: +tr, s: +ts }; + + 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); @@ -297,6 +293,11 @@ export function start(el) { }); }); + // debug // + const c = soldier.createCounter({ dataset: { allegiance: 'attacker', number: 1, squad: 1 }}); + soldier.place(svg, c, svg.querySelector('[data-q="0"][data-r="0"][data-s="0"][data-t="0"]')); + /////////// + Observable.subscribe('select', select); Observable.subscribe('endmove', endMove); console.log('gameboard.js loaded'); |