index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
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'); |