From 6811f68b3688cdbb5845f15bd3da42fa6ccc580b Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Tue, 30 Apr 2024 14:58:19 -0700
Subject: Fix end movement bug
---
src/modules/game/soldier.js | 25 +++++++------------------
src/modules/gameboard.js | 4 ----
2 files changed, 7 insertions(+), 22 deletions(-)
(limited to 'src')
diff --git a/src/modules/game/soldier.js b/src/modules/game/soldier.js
index c4e9753..db5fd3d 100644
--- a/src/modules/game/soldier.js
+++ b/src/modules/game/soldier.js
@@ -25,10 +25,6 @@ function getClones(svg, counter) {
return svg.querySelectorAll(`.counter.clone${dataSelector(counter)}`);
}
-function getCounterAndClones(svg, counter) {
- return svg.querySelectorAll(`.counter${dataSelector(counter)}`);
-}
-
export function getAllCounters(container) {
return container.querySelectorAll('g.counter[data-allegiance][data-number]');
}
@@ -42,10 +38,7 @@ export function getTrace(svg, counter) {
}
export function place(svg, selected, cell) {
- let points,
- counterNodeList = getCounterAndClones(svg, selected);
-
- if (counterNodeList.length > 0 && svg.querySelector('.grid').contains(selected)) {
+ if (svg.querySelector('.grid').contains(selected)) {
let trace = svg.querySelector(traceSelector(selected));
let prevCoords = [
@@ -70,7 +63,8 @@ export function place(svg, selected, cell) {
});
let previous = getCellPosition(clone.parentElement),
- current = getCellPosition(selected.parentElement);
+ current = getCellPosition(selected.parentElement),
+ points;
if (!trace) {
trace = document.createElementNS(svgns, 'polyline');
@@ -98,20 +92,15 @@ export function removeClones(svg, counter) {
}
export function endMove(svg, counter) {
- const trace = svg.querySelector(traceSelector(counter)),
- proneCounter = counter.querySelector('[href="#counter-prone"]');
-
- if (trace) {
- trace.remove();
- }
-
- delete counter.dataset.previous;
+ const proneCounter = counter.querySelector('[href="#counter-prone"]');
if (proneCounter) {
proneCounter.dataset.preexisting = '';
}
- removeClones(counter);
+ svg.querySelector(traceSelector(counter))?.remove();
+ delete counter.dataset.previous;
+ removeClones(svg, counter);
}
export function hasProne(counter) {
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 678f828..3c932d9 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -30,10 +30,6 @@ function getLockedSightLine(svg) {
return svg.querySelector('line.sight-line:not(.active)');
}
-function getSightLine() {
- return sightLine.getSightLine();
-}
-
function getActiveSightLine(svg) {
return svg.querySelector('line.sight-line.active');
}
--
cgit v1.2.3