Allow selecting off-board units

This commit is contained in:
Catalin Constantin Mititiuc 2025-06-16 22:41:29 -07:00
parent 0af0271076
commit 484100727f

View File

@ -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) {