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 | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js index 5a804a3..47533dd 100644 --- a/src/modules/gameboard.js +++ b/src/modules/gameboard.js @@ -2,6 +2,10 @@ import * as firingArc from './game/firing_arc.js'; import * as sightLine from './game/sight_line.js'; import * as soldier from './game/soldier.js'; +let svg, distanceCallback, proneFlagCallback, selectCallback, + selected, + placing = []; + function getCellContents(cell) { return cell.querySelectorAll('*:not(use[href="#hex"])'); } @@ -26,8 +30,8 @@ function getLockedSightLine(svg) { return svg.querySelector('line.sight-line:not(.active)'); } -export function getSightLine(svg) { - return svg.querySelector('line.sight-line'); +function getSightLine() { + return sightLine.getSightLine(); } function getActiveSightLine(svg) { @@ -109,8 +113,9 @@ function drawSightLine(sourceCell, targetCell) { distanceCallback && distanceCallback(hexes.length - 1); } -let svg, distanceCallback, proneFlagCallback, selectCallback, - placing = []; +export function getUnits() { + return soldier.getAllCounters(svg); +} export function setDistanceCallback(callback) { distanceCallback = callback; @@ -143,13 +148,7 @@ export function start(el) { } else if (toPlace && !state.occupant) { soldier.place(svg, toPlace, cell); placing.push(toPlace); - const lockedSl = getLockedSightLine(svg); - - if (!lockedSl) { - clearSightLine(); - } else { - updateSightLine(cell); - } + getLockedSightLine(svg) ? updateSightLine(cell) : clearSightLine(); } else if (toPlace && state.occupant) { if (toPlace === state.occupant) { if ('previous' in toPlace.dataset) { @@ -187,13 +186,7 @@ export function start(el) { toPlace = state.occupant; soldier.removeClones(svg, toPlace); soldier.getTrace(svg, toPlace).remove(); - const lockedSl = getLockedSightLine(svg); - - if (!lockedSl) { - clearSightLine(); - } else { - updateSightLine(cell); - } + getLockedSightLine(svg) ? updateSightLine(cell) : clearSightLine(); } else { const index = getGridIndex(state.occupant), trace = soldier.getTrace(svg, toPlace), @@ -242,10 +235,15 @@ export function start(el) { }); cell.addEventListener('pointerover', () => { + // should we draw a sight line? + // conditions: + // we have a soldier selected + // that soldier's counter is on the board + // the sight line is not locked let selected = getSelected(); if (selected) { - let sl = getSightLine(svg), + let sl = getSightLine(), isOnBoard = selected.parentElement.hasAttribute('data-x'), sourceCell = selected.parentElement; |