From fcb205ba0b5e958c39100e1eef57317fbf3c20d1 Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Tue, 30 Apr 2024 19:49:34 -0700
Subject: Allow selecting off-board units
---
src/modules/gameboard.js | 7 +++++++
1 file changed, 7 insertions(+)
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) {
--
cgit v1.2.3