Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/modules/gameboard.js31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 135b5e9..5cf0c51 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -222,8 +222,6 @@ export function start(el) {
const startingLocations = svg.querySelector('.start-locations');
startingLocations && getUnits(startingLocations).forEach(unit => unit.addEventListener('click', selectOffBoard));
- svg.addEventListener('pointerout', e => console.log('pointerout svg'));
-
getCells(svg).forEach(cell => {
cell.addEventListener('click', e => {
const occupant = getCellOccupant(cell);
@@ -333,14 +331,23 @@ export function start(el) {
}
});
- cell.addEventListener('pointerout', () => {
- console.log('pointerout cell', cell);
- getActiveSightLine(svg) && clearSightLine();
+ cell.addEventListener('pointerout', e => {
+ // If pointerout was not triggered by hovering over an element on that
+ // game hex
+ if (!e.relatedTarget || top.collection.get(e.relatedTarget)?.parent !== cell) {
+ [...top.container.children].forEach(child => {
+ top.collection.get(child).parent.append(child);
+ top.collection.delete(child);
+ });
- const occupant = getCellOccupant(cell);
+ cell.classList.remove('hover');
+ getActiveSightLine(svg) && clearSightLine();
- if (occupant) {
- firingArc.toggleCounterVisibility(svg, occupant, false);
+ const occupant = getCellOccupant(cell);
+
+ if (occupant) {
+ firingArc.toggleCounterVisibility(svg, occupant, false);
+ }
}
});
});
@@ -353,14 +360,14 @@ export function start(el) {
// debug //
// Add a trooper counter
- const attacker = { dataset: { allegiance: 'attacker', number: 1, squad: 1 }};
+ //const attacker = { dataset: { allegiance: 'attacker', number: 1, squad: 1 }};
// const defender = { dataset: { allegiance: 'defender', number: 1, squad: 2 }};
- const cell = getCell(0, 0, 0, 0);
- const trooper = soldier.createCounter(attacker, 'blazer');
+ //const cell = getCell(0, 0, 0, 0);
+ //const trooper = soldier.createCounter(attacker, 'blazer');
//const trooperSack = document.createElementNS(svgns, 'g');
//trooperSack.classList.add('cell-contents');
//trooperSack.append(trooper);
- soldier.place(svg, trooper, cell);
+ //soldier.place(svg, trooper, cell);
// Add some counters in an unoccupied cell
//const countersCell = getCell(-1, 1, 0, 0);