Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/game.js15
-rw-r--r--src/modules/game/counter.js3
-rw-r--r--src/modules/game/firingArc.js3
-rw-r--r--src/modules/game/sightLine.js3
-rw-r--r--src/modules/recordSheet.js32
5 files changed, 40 insertions, 16 deletions
diff --git a/src/modules/game.js b/src/modules/game.js
index 5bc1fe3..e66f126 100644
--- a/src/modules/game.js
+++ b/src/modules/game.js
@@ -2,8 +2,6 @@ import * as firingArc from './game/firingArc.js';
import * as sightLine from './game/sightLine.js';
import * as counterMod from './game/counter.js';
-const svgns = "http://www.w3.org/2000/svg";
-
function getCellContents(cell) {
return cell.querySelectorAll('*:not(use[href="#hex"])');
}
@@ -111,9 +109,7 @@ function drawSightLine(sourceCell, targetCell) {
distanceCallback && distanceCallback(hexes.length - 1);
}
-let svg, distanceCallback, proneFlagCallback, selectCallback;
-
-let board,
+let svg, distanceCallback, proneFlagCallback, selectCallback,
placing = [];
export function setDistanceCallback(callback) {
@@ -130,7 +126,6 @@ export function setSelectCallback(callback) {
export function start(el) {
svg = el;
- board = svg.querySelector('.board');
getCells(svg).forEach(cell => {
cell.addEventListener('click', e => {
@@ -332,16 +327,16 @@ export function toggleProne() {
}
}
-export function toggleFiringArcVisibility(allegiance) {
- firingArc.toggleVisibility(svg, allegiance);
+export function toggleFiringArcVisibility() {
+ firingArc.toggleVisibility(svg, this.dataset.allegiance);
}
-export function setFiringArc(size) {
+export function setFiringArc() {
const counter = getSelected(),
isOnBoard = counter => counter && counter.parentElement.hasAttribute('data-x');
if (isOnBoard(counter)) {
- firingArc.set(svg, size, counter, getCellPosition(counter.parentElement));
+ firingArc.set(svg, this.dataset.size, counter, getCellPosition(counter.parentElement));
}
}
diff --git a/src/modules/game/counter.js b/src/modules/game/counter.js
index ff9b0f4..0d75fc6 100644
--- a/src/modules/game/counter.js
+++ b/src/modules/game/counter.js
@@ -1,5 +1,4 @@
-const svgns = "http://www.w3.org/2000/svg",
- selectedClass = 'selected';
+const selectedClass = 'selected';
function dataSelector({ dataset: { allegiance, number }}) {
return `[data-number="${number}"][data-allegiance="${allegiance}"]`;
diff --git a/src/modules/game/firingArc.js b/src/modules/game/firingArc.js
index db122a0..817bc44 100644
--- a/src/modules/game/firingArc.js
+++ b/src/modules/game/firingArc.js
@@ -4,8 +4,7 @@
// cancels out, leaving us with a unitless ratio of sqrt(3) / (3 / 2), or
// 2 * sqrt(3) / 3.
-const svgns = "http://www.w3.org/2000/svg",
- horzToVertDistRatio = 2 * Math.sqrt(3) / 3,
+const horzToVertDistRatio = 2 * Math.sqrt(3) / 3,
arcSize = {
'small': Math.atan(horzToVertDistRatio / 6),
diff --git a/src/modules/game/sightLine.js b/src/modules/game/sightLine.js
index 2da99d4..6b94514 100644
--- a/src/modules/game/sightLine.js
+++ b/src/modules/game/sightLine.js
@@ -1,5 +1,4 @@
-const svgns = "http://www.w3.org/2000/svg",
- targetClassName = 'sight-line-target',
+const targetClassName = 'sight-line-target',
activeClassName = 'active';
function evenr_to_axial(x, y) {
diff --git a/src/modules/recordSheet.js b/src/modules/recordSheet.js
new file mode 100644
index 0000000..99af18f
--- /dev/null
+++ b/src/modules/recordSheet.js
@@ -0,0 +1,32 @@
+export function unSelect() {
+ const selected = getSelected();
+
+ if (selected) {
+ selected.classList.remove('selected');
+ }
+
+ document.getElementById('toggle-prone-counter').checked = false;
+}
+
+export function getSelected() {
+ return document.querySelector('.soldier-record.selected');
+}
+
+export function select(data) {
+ const selector =
+ `#record-sheet .soldier-record[data-number="${data.number}"][data-allegiance="${data.allegiance}"]`
+
+ unSelect();
+ document.querySelector(selector).classList.add('selected');
+ document.getElementById('toggle-prone-counter').checked = data.prone;
+}
+
+export function endMove() {
+ const selected = getSelected();
+
+ if (selected) {
+ selected.classList.toggle('movement-ended');
+ }
+
+ unSelect();
+}