Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-04-27 08:18:47 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-04-27 08:18:47 -0700
commitd73b534f681bfd51eb396e70236a752ea2dc9cfd (patch)
treef0b485227db0afdbf36f1ebd2512bf30ade5c80d /src/modules/game/firingArc.js
parentd911ba9bcaa34d37cd12ad583a88c143e3c138ab (diff)
Minor refactor
Diffstat (limited to 'src/modules/game/firingArc.js')
-rw-r--r--src/modules/game/firingArc.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/modules/game/firingArc.js b/src/modules/game/firingArc.js
index 2dd8976..ffb5c27 100644
--- a/src/modules/game/firingArc.js
+++ b/src/modules/game/firingArc.js
@@ -272,7 +272,7 @@ function create(x, y, size, counter, { arcContainer, arcLayer, outlineLayer }) {
export default function (svg) {
function set(size, counter, { x, y }) {
- get(counter).forEach(fa => fa.remove());
+ get(counter).forEach(el => el.remove());
const { grid, containers } = queryContainers(svg),
{ aimLine, firingArc, firingArcOutline } = create(x, y, size, counter, containers);
@@ -287,16 +287,16 @@ export default function (svg) {
}
function placementListener() {
- grid.removeAttribute('style');
aimLine.remove();
- svg.querySelectorAll('.firing-arc.active').forEach(el => el.classList.remove('active'));
+ firingArc.classList.remove('active');
+ grid.removeAttribute('style');
svg.removeEventListener('mousemove', positionListener);
}
function cancelPlacementListener(e) {
e.preventDefault();
- get(counter).forEach(fa => fa.remove());
+ get(counter).forEach(el => el.remove());
grid.removeAttribute('style');
svg.removeEventListener('mousemove', positionListener);
}
@@ -305,16 +305,16 @@ export default function (svg) {
firingArc.addEventListener('click', placementListener, { once: true });
firingArc.addEventListener('contextmenu', cancelPlacementListener, { once: true });
svg.addEventListener('mousemove', positionListener);
- };
+ }
function clear(allegiance) {
const selector = `#firing-arcs [data-allegiance="${allegiance}"]`;
svg.querySelectorAll(selector).forEach(el => el.remove());
- };
+ }
function get({ dataset: { allegiance, number }}) {
return svg.querySelectorAll(`#firing-arcs [data-number="${number}"][data-allegiance="${allegiance}"], #firing-arcs line`);
- };
+ }
function toggleVisibility(allegiance) {
const vis = firingArcVisibility[allegiance],
@@ -322,7 +322,7 @@ export default function (svg) {
clipPaths.forEach(cp => cp.style.display = !vis ? 'none' : '');
firingArcVisibility[allegiance] = !vis;
- };
+ }
function toggleCounterVisibility({ dataset: { number, allegiance }}, vis) {
const cp = svg.querySelector(`#clip-path-${allegiance}-${number}`),
@@ -331,12 +331,10 @@ export default function (svg) {
if (cp) {
cp.style.display = firingArcVisibility[allegiance] ? 'none' : display;
}
- };
+ }
function clipAll() {
- const unclipped = getUnclipped(svg);
-
- unclipped.forEach(el => {
+ getUnclipped(svg).forEach(el => {
const { number, allegiance } = el.dataset,
clipPathId = `clip-path-${allegiance}-${number}`,
isVisible = firingArcVisibility[allegiance];
@@ -347,7 +345,7 @@ export default function (svg) {
el.setAttributeNS(null, 'clip-path', `url(#${clipPathId})`);
});
- };
+ }
return { set, clear, get, toggleVisibility, toggleCounterVisibility, clipAll };
}