Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/game/soldier.js2
-rw-r--r--src/modules/gameboard.js13
-rw-r--r--src/modules/observable.js2
-rw-r--r--src/modules/record_sheet.js4
4 files changed, 10 insertions, 11 deletions
diff --git a/src/modules/game/soldier.js b/src/modules/game/soldier.js
index fb0a559..ae1d708 100644
--- a/src/modules/game/soldier.js
+++ b/src/modules/game/soldier.js
@@ -129,7 +129,7 @@ export function endMove(svg, counter) {
}
export function hasProne(counter) {
- return !!counter.querySelector('[href="#counter-prone"]');
+ return !!counter.querySelector('[href="#counter-prone"]:not(.removed)');
}
export function toggleProne(counter) {
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 8f03603..48a32bb 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -3,8 +3,7 @@ import * as sightLine from './game/sight_line.js';
import * as soldier from './game/soldier.js';
import { Observable } from "./observable";
-let svg, distanceCallback, proneFlagCallback,
- selected,
+let svg, distanceCallback, selected,
placing = [];
function getCellContents(cell) {
@@ -78,6 +77,7 @@ function getSelected() {
function deselect() {
const selected = getSelected();
placing = [];
+ Observable.notify('proneflag', false);
if (selected) {
selected.classList.remove(soldier.getSelectedClass());
@@ -182,10 +182,6 @@ export function setDistanceCallback(callback) {
distanceCallback = callback;
}
-export function setProneFlagCallback(callback) {
- proneFlagCallback = callback;
-}
-
export function start(el) {
svg = el;
@@ -231,6 +227,9 @@ export function start(el) {
console.log('removing cell contents');
getCellContents(cell).forEach(el => el.remove());
}
+
+ const selected = getSelected();
+ Observable.notify('proneflag', selected && soldier.hasProne(selected));
});
cell.addEventListener('dblclick', e => {
@@ -280,6 +279,7 @@ export function start(el) {
});
Observable.subscribe('select', select);
+ Observable.subscribe('endmove', endMove);
console.log('gameboard.js loaded');
}
@@ -295,6 +295,7 @@ export function select(data) {
counter.classList.add(soldier.getSelectedClass());
firingArc.get(svg, counter).forEach(el => el.removeAttribute('clip-path'));
+ Observable.notify('proneflag', soldier.hasProne(counter));
placing.push(counter);
}
diff --git a/src/modules/observable.js b/src/modules/observable.js
index e4f6797..c9bea9b 100644
--- a/src/modules/observable.js
+++ b/src/modules/observable.js
@@ -2,7 +2,7 @@ const observers = {};
export const Observable = Object.freeze({
notify: (event, data) => {
- observers[event].forEach((observer) => observer(data))
+ (observers[event] || []).forEach((observer) => observer(data))
},
subscribe: (event, func) => {
diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js
index 7b0a80f..b180a8e 100644
--- a/src/modules/record_sheet.js
+++ b/src/modules/record_sheet.js
@@ -118,8 +118,6 @@ function deselect() {
if (selected) {
selected.classList.remove('selected');
}
-
- document.getElementById('toggle-prone-counter').checked = false;
}
function clear() {
@@ -137,7 +135,6 @@ function select(data) {
if (isSelected || !data) return;
record.classList.add('selected');
- document.querySelector('#toggle-prone-counter').checked = data.prone;
}
export function getSelected() {
@@ -170,5 +167,6 @@ export function start(startLoc, units) {
}
Observable.subscribe('select', select);
+ Observable.subscribe('endmove', endMove);
addEventListeners();
}