Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-04-30 19:49:34 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-04-30 19:49:34 -0700
commitfcb205ba0b5e958c39100e1eef57317fbf3c20d1 (patch)
treea7a8ac02173007fc907587c17c099ccf53716f07 /src/modules
parent9304d937fc4dd793dbfba13be30b0073d1f76597 (diff)
Allow selecting off-board units
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/gameboard.js7
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) {