index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
-rw-r--r-- | src/modules/gameboard.js | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js index d4592fc..3482ce7 100644 --- a/src/modules/gameboard.js +++ b/src/modules/gameboard.js @@ -158,6 +158,10 @@ function hasPreviousMoveInHistory(counter) { return 'previous' in counter.dataset; } +function selectOffBoard() { + this.classList.contains(soldier.getSelectedClass()) ? unSelect() : select(this); +} + export function getUnits() { return soldier.getAllCounters(svg); } @@ -177,6 +181,8 @@ export function setSelectCallback(callback) { export function start(el) { svg = el; + getUnits(svg).forEach(unit => unit.addEventListener('click', selectOffBoard)); + getCells(svg).forEach(cell => { cell.addEventListener('click', e => { const occupant = getCellOccupant(cell); @@ -186,6 +192,7 @@ export function start(el) { getHex(cell).after(toPlace); } else if (toPlace && !occupant) { soldier.place(svg, toPlace, cell); + toPlace.removeEventListener('click', selectOffBoard); placing.push(toPlace); getLockedSightLine(svg) ? updateSightLine(cell) : clearSightLine(); } else if (toPlace && occupant) { |