Allow selecting off-board units

This commit is contained in:
Catalin Constantin Mititiuc 2024-04-30 19:49:34 -07:00
parent 9304d937fc
commit fcb205ba0b

View File

@ -158,6 +158,10 @@ function hasPreviousMoveInHistory(counter) {
return 'previous' in counter.dataset; return 'previous' in counter.dataset;
} }
function selectOffBoard() {
this.classList.contains(soldier.getSelectedClass()) ? unSelect() : select(this);
}
export function getUnits() { export function getUnits() {
return soldier.getAllCounters(svg); return soldier.getAllCounters(svg);
} }
@ -177,6 +181,8 @@ export function setSelectCallback(callback) {
export function start(el) { export function start(el) {
svg = el; svg = el;
getUnits(svg).forEach(unit => unit.addEventListener('click', selectOffBoard));
getCells(svg).forEach(cell => { getCells(svg).forEach(cell => {
cell.addEventListener('click', e => { cell.addEventListener('click', e => {
const occupant = getCellOccupant(cell); const occupant = getCellOccupant(cell);
@ -186,6 +192,7 @@ export function start(el) {
getHex(cell).after(toPlace); getHex(cell).after(toPlace);
} else if (toPlace && !occupant) { } else if (toPlace && !occupant) {
soldier.place(svg, toPlace, cell); soldier.place(svg, toPlace, cell);
toPlace.removeEventListener('click', selectOffBoard);
placing.push(toPlace); placing.push(toPlace);
getLockedSightLine(svg) ? updateSightLine(cell) : clearSightLine(); getLockedSightLine(svg) ? updateSightLine(cell) : clearSightLine();
} else if (toPlace && occupant) { } else if (toPlace && occupant) {