Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-04-30 21:10:11 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-04-30 21:22:00 -0700
commita3bf726e40fe4ed529bdefa83c977af4b72791a9 (patch)
treeab42c7cc50545a670ffd6b8804a769ec0b086b3f /src
parent1eda0dafd539b6a259fe1ad4609419c8f04c49c7 (diff)
Allow placing a counter that doesn't already exist
Diffstat (limited to 'src')
-rw-r--r--src/modules/game/soldier.js12
-rw-r--r--src/modules/gameboard.js14
-rw-r--r--src/modules/record_sheet.js13
3 files changed, 30 insertions, 9 deletions
diff --git a/src/modules/game/soldier.js b/src/modules/game/soldier.js
index 8e2725d..1555c19 100644
--- a/src/modules/game/soldier.js
+++ b/src/modules/game/soldier.js
@@ -63,6 +63,18 @@ function createTrace(previous, current, selected) {
return trace;
}
+export function createCounter(selected) {
+ const use = document.createElementNS(svgns, 'use');
+ const g = document.createElementNS(svgns, 'g');
+ use.setAttributeNS(null, 'href', `#t-${selected.dataset.number}`);
+ g.classList.add('counter');
+ g.dataset.allegiance = selected.dataset.allegiance;
+ g.dataset.number = selected.dataset.number;
+ g.appendChild(use);
+
+ return g;
+}
+
export function handleTrace(svg, selected, clone, current) {
let trace = getTrace(svg, selected);
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 3482ce7..2df5b36 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -234,6 +234,7 @@ export function start(el) {
selector = `[data-allegiance="${allegiance}"][data-number="${number}"]`;
svg.querySelectorAll(selector).forEach(el => el.remove());
+ selectCallback();
}
});
@@ -272,15 +273,18 @@ export function start(el) {
}
export function select(selected) {
- const counter = soldier.getCounter(svg, selected);
+ unSelect();
+ let counter = soldier.getCounter(svg, selected);
if (counter) {
- unSelect();
- placing.push(counter);
- counter.classList.add(soldier.getSelectedClass());
firingArc.get(svg, counter).forEach(el => el.removeAttribute('clip-path'));
- selectCallback && selectCallback({ prone: soldier.hasProne(counter), ...counter.dataset });
+ } else {
+ counter = soldier.createCounter(selected);
}
+
+ placing.push(counter);
+ counter.classList.add(soldier.getSelectedClass());
+ selectCallback && selectCallback({ prone: soldier.hasProne(counter), ...counter.dataset });
}
export function unSelect() {
diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js
index 736ffb2..6909249 100644
--- a/src/modules/record_sheet.js
+++ b/src/modules/record_sheet.js
@@ -94,12 +94,17 @@ export function getSelected() {
}
export function select(data) {
- const selector =
- `#record-sheet .soldier-record[data-number="${data.number}"][data-allegiance="${data.allegiance}"]`
-
unSelect();
+
+ if (!data) {
+ return;
+ }
+
+ const { allegiance: al, number: n } = data,
+ selector = `.soldier-record[data-number="${n}"][data-allegiance="${al}"]`;
+
document.querySelector(selector).classList.add('selected');
- document.getElementById('toggle-prone-counter').checked = data.prone;
+ document.querySelector('#toggle-prone-counter').checked = data.prone;
}
export function endMove() {