Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-08-02 14:37:20 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-08-02 14:37:20 -0700
commita042537c8eeff2e45bcc5d678e2657f4f542ec93 (patch)
tree6d7a5bc0ad04eb6cce6a1948cd8e8e671399bc87
parentf6ee6e3560022c77724535c2f7abd98c474ced8c (diff)
Fix firing arcs for squads
-rw-r--r--src/modules/game/firing_arc.js25
-rw-r--r--src/modules/game/soldier.js4
-rw-r--r--src/modules/gameboard.js11
-rw-r--r--src/modules/record_sheet.js4
4 files changed, 21 insertions, 23 deletions
diff --git a/src/modules/game/firing_arc.js b/src/modules/game/firing_arc.js
index 7a82c43..5a9e5b2 100644
--- a/src/modules/game/firing_arc.js
+++ b/src/modules/game/firing_arc.js
@@ -190,13 +190,14 @@ function calcPoints(e, aimLine, grid, size) {
return { aimPt, outlinePoints, arcPoints };
}
-function setDataAttrs({ dataset: { allegiance, number }}, el) {
+function setDataAttrs({ dataset: { allegiance, number, squad }}, el) {
el.dataset.allegiance = allegiance;
el.dataset.number = number;
+ el.dataset.squad = squad;
}
-function getClipPathId({ dataset: { allegiance, number }}) {
- return `clip-path-${allegiance}-${number}`;
+function getClipPathId({ dataset: { allegiance, number, squad }}) {
+ return `clip-path-${allegiance}-${squad}-${number}`;
}
function getUnclipped(svg) {
@@ -310,8 +311,11 @@ function clear(svg, allegiance) {
svg.querySelectorAll(selector).forEach(el => el.remove());
}
-function get(svg, { dataset: { allegiance, number }}) {
- return svg.querySelectorAll(`#firing-arcs [data-number="${number}"][data-allegiance="${allegiance}"], #firing-arcs line`);
+function get(svg, { dataset: { allegiance, number, squad }}) {
+ return svg.querySelectorAll(
+ `#firing-arcs [data-number="${number}"][data-allegiance="${allegiance}"][data-squad="${squad}"],
+ #firing-arcs line`
+ );
}
function toggleVisibility(svg, allegiance) {
@@ -322,20 +326,19 @@ function toggleVisibility(svg, allegiance) {
firingArcVisibility[allegiance] = !vis;
}
-function toggleCounterVisibility(svg, { dataset: { number, allegiance }}, vis) {
- const cp = svg.querySelector(`#clip-path-${allegiance}-${number}`),
+function toggleCounterVisibility(svg, counter, vis) {
+ const cp = svg.querySelector(`#${getClipPathId(counter)}`),
display = vis ? 'none' : '';
if (cp) {
- cp.style.display = firingArcVisibility[allegiance] ? 'none' : display;
+ cp.style.display = firingArcVisibility[counter.dataset.allegiance] ? 'none' : display;
}
}
function clipAll(svg) {
getUnclipped(svg).forEach(el => {
- const { number, allegiance } = el.dataset,
- clipPathId = `clip-path-${allegiance}-${number}`,
- isVisible = firingArcVisibility[allegiance];
+ const clipPathId = getClipPathId(el),
+ isVisible = firingArcVisibility[el.dataset.allegiance];
if (isVisible) {
svg.querySelector(`#${clipPathId}`).style.display = 'none';
diff --git a/src/modules/game/soldier.js b/src/modules/game/soldier.js
index a71ceba..8407621 100644
--- a/src/modules/game/soldier.js
+++ b/src/modules/game/soldier.js
@@ -3,8 +3,8 @@ import { extractWeaponFromRecord, isRecord } from '../record_sheet.js';
const selectedClass = 'selected';
-function dataSelector({ dataset: { allegiance, number }}) {
- return `[data-number="${number}"][data-allegiance="${allegiance}"]`;
+function dataSelector({ dataset: { allegiance, number, squad }}) {
+ return `[data-number="${number}"][data-allegiance="${allegiance}"][data-squad="${squad}"]`;
}
function traceSelector(counter) {
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index c486eae..d386855 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -207,14 +207,6 @@ function endMove() {
}
}
-// Work around webkit bug https://bugs.webkit.org/show_bug.cgi?id=233432
-function workaroundForWebKitBug233432(listener) {
- return e => {
- const elUnderCursor = svg.parentNode.elementFromPoint(e.clientX, e.clientY);
- if (!e.target.contains(elUnderCursor)) listener(e);
- };
-}
-
export function start(el) {
svg = el;
const grid = svg.querySelector('.grid');
@@ -318,6 +310,9 @@ export function start(el) {
clearHexDialog.addEventListener('close', e => {
if (clearHexDialog.returnValue === 'confirm') {
[...frontmost.children].forEach(child => {
+ if (child.classList.contains('counter'))
+ firingArc.get(svg, child).forEach(el => el.remove());
+
frontmostStore.delete(child);
child.remove();
});
diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js
index 931177f..684b84e 100644
--- a/src/modules/record_sheet.js
+++ b/src/modules/record_sheet.js
@@ -154,8 +154,8 @@ function createRecords(units) {
return grouped;
}
-function getRecord({ dataset: { allegiance: al, number: n }}) {
- const selector = `.soldier-record[data-number="${n}"][data-allegiance="${al}"]`;
+function getRecord({ dataset: { allegiance: al, number: n, squad: s }}) {
+ const selector = `.soldier-record[data-number="${n}"][data-allegiance="${al}"][data-squad="${s}"]`;
return document.querySelector(selector);
}