Web Dev Solutions

Catalin Mititiuc

From d73b534f681bfd51eb396e70236a752ea2dc9cfd Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Sat, 27 Apr 2024 08:18:47 -0700 Subject: Minor refactor --- src/modules/game/firingArc.js | 24 +++++++++++------------- src/modules/game/sightLine.js | 4 ++-- 2 files changed, 13 insertions(+), 15 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 }; } diff --git a/src/modules/game/sightLine.js b/src/modules/game/sightLine.js index 94e91e5..f5f52c0 100644 --- a/src/modules/game/sightLine.js +++ b/src/modules/game/sightLine.js @@ -95,7 +95,7 @@ function create({ x: x1, y: y1 }, { x: x2, y: y2 }) { return sightLine; } -function lock(cell, sightLine, lockTarget) { +function lock(sightLine, cell) { sightLine.classList.remove(activeClassName); cell.classList.add(targetClassName); @@ -138,7 +138,7 @@ export default function (board) { }, toggleLock: function (cell) { - lockTarget = lockTarget ? unlock(sightLine, lockTarget) : lock(cell, sightLine, lockTarget); + lockTarget = lockTarget ? unlock(sightLine, lockTarget) : lock(sightLine, cell); }, get sightLine() { -- cgit v1.2.3