Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/modules/gameboard.js58
-rw-r--r--src/modules/record_sheet.js10
2 files changed, 32 insertions, 36 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 4b7d87b..8b64617 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -174,8 +174,29 @@ function selectOffBoard() {
Observable.notify('select', this);
}
-export function getUnits() {
- return soldier.getAllCounters(svg);
+function select(data) {
+ if (!data) return;
+
+ const counter = soldier.getCounter(svg, data) || soldier.createCounter(data);
+ const isSelected = counter.classList.contains(soldier.getSelectedClass());
+
+ deselect();
+
+ if (isSelected) return;
+
+ counter.classList.add(soldier.getSelectedClass());
+ firingArc.get(svg, counter).forEach(el => el.removeAttribute('clip-path'));
+ Observable.notify('proneflag', soldier.hasProne(counter));
+ placing.push(counter);
+}
+
+function endMove() {
+ const selected = getSelected();
+
+ if (selected) {
+ soldier.endMove(svg, selected);
+ deselect();
+ }
}
export function start(el) {
@@ -279,29 +300,8 @@ export function start(el) {
console.log('gameboard.js loaded');
}
-export function select(data) {
- if (!data) return;
-
- const counter = soldier.getCounter(svg, data) || soldier.createCounter(data);
- const isSelected = counter.classList.contains(soldier.getSelectedClass());
-
- deselect();
-
- if (isSelected) return;
-
- counter.classList.add(soldier.getSelectedClass());
- firingArc.get(svg, counter).forEach(el => el.removeAttribute('clip-path'));
- Observable.notify('proneflag', soldier.hasProne(counter));
- placing.push(counter);
-}
-
-export function endMove() {
- const selected = getSelected();
-
- if (selected) {
- soldier.endMove(svg, selected);
- deselect();
- }
+export function getUnits() {
+ return soldier.getAllCounters(svg);
}
export function clearFiringArcs(allegiance) {
@@ -309,12 +309,8 @@ export function clearFiringArcs(allegiance) {
}
export function toggleProne() {
- const selected = getSelected(),
- isOnBoard = selected && selected.parentElement.hasAttribute('data-x');
-
- if (selected && isOnBoard) {
- soldier.toggleProne(selected);
- }
+ const selected = getSelected();
+ if (selected) soldier.toggleProne(selected);
}
export function toggleFiringArcVisibility() {
diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js
index b180a8e..f13f5f8 100644
--- a/src/modules/record_sheet.js
+++ b/src/modules/record_sheet.js
@@ -137,11 +137,7 @@ function select(data) {
record.classList.add('selected');
}
-export function getSelected() {
- return document.querySelector('.soldier-record.selected');
-}
-
-export function endMove() {
+function endMove() {
const selected = getSelected();
if (selected) {
@@ -151,6 +147,10 @@ export function endMove() {
deselect();
}
+export function getSelected() {
+ return document.querySelector('.soldier-record.selected');
+}
+
export function start(startLoc, units) {
clear();
const forces = createRecords(units);