index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-04-27 12:34:07 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-04-27 12:34:07 -0700 |
commit | b88945ced695e8478076c5f53a198fd405f7db96 (patch) | |
tree | b219c59c60111272c7aee4e672588e5de06be017 /src/modules/game | |
parent | 25c74d9a8eafe35abd92fa3bdb6b3146614e7fa1 (diff) |
Remove 'reveal pattern' from counter module
Diffstat (limited to 'src/modules/game')
-rw-r--r-- | src/modules/game/counter.js | 159 |
1 files changed, 74 insertions, 85 deletions
diff --git a/src/modules/game/counter.js b/src/modules/game/counter.js index 21406c8..ff9b0f4 100644 --- a/src/modules/game/counter.js +++ b/src/modules/game/counter.js @@ -30,116 +30,105 @@ function getCounterAndClones(svg, counter) { return svg.querySelectorAll(`.counter${dataSelector(counter)}`); } -export default function (svg, board) { - function getCounter(selected) { - return svg.querySelector(`.counter${dataSelector(selected)}:not(.clone)`); - } - - function getTrace(counter) { - return svg.querySelector(traceSelector(counter)); - } +export function getCounter(svg, selected) { + return svg.querySelector(`.counter${dataSelector(selected)}:not(.clone)`); +} - function place(selected, cell) { - let points, - counterNodeList = getCounterAndClones(svg, selected); +export function getTrace(svg, counter) { + return svg.querySelector(traceSelector(counter)); +} - if (counterNodeList.length > 0 && selected.parentElement.hasAttribute('data-x')) { - let trace = svg.querySelector(traceSelector(selected)); +export function place(svg, selected, cell) { + let points, + counterNodeList = getCounterAndClones(svg, selected); - let prevCoords = [ - selected.parentElement.dataset.x, - selected.parentElement.parentElement.dataset.y - ] + if (counterNodeList.length > 0 && selected.parentElement.hasAttribute('data-x')) { + let trace = svg.querySelector(traceSelector(selected)); - let clone = selected.cloneNode(true); - clone.classList.remove(selectedClass); - clone.classList.add('clone'); + let prevCoords = [ + selected.parentElement.dataset.x, + selected.parentElement.parentElement.dataset.y + ] - selected.dataset.previous = prevCoords; - selected.parentElement.appendChild(clone); - cell.appendChild(selected); + let clone = selected.cloneNode(true); + clone.classList.remove(selectedClass); + clone.classList.add('clone'); - selected.childNodes.forEach(n => { - if (n.classList.contains('removed')) { - n.remove(); - } else if ('preexisting' in n.dataset) { - delete n.dataset.preexisting; - } - }); + selected.dataset.previous = prevCoords; + selected.parentElement.appendChild(clone); + cell.appendChild(selected); - let previous = getCellPosition(clone.parentElement), - current = getCellPosition(selected.parentElement); + selected.childNodes.forEach(n => { + if (n.classList.contains('removed')) { + n.remove(); + } else if ('preexisting' in n.dataset) { + delete n.dataset.preexisting; + } + }); - if (!trace) { - trace = document.createElementNS(svgns, 'polyline'); + let previous = getCellPosition(clone.parentElement), + current = getCellPosition(selected.parentElement); - points = `${previous.x},${previous.y} ${current.x},${current.y}`; + if (!trace) { + trace = document.createElementNS(svgns, 'polyline'); - trace.dataset.number = selected.dataset.number; - trace.dataset.allegiance = selected.dataset.allegiance; - trace.classList.add('move-trace'); + points = `${previous.x},${previous.y} ${current.x},${current.y}`; - board.prepend(trace); - } else { - points = `${trace.getAttribute('points')} ${current.x},${current.y}`; - } + trace.dataset.number = selected.dataset.number; + trace.dataset.allegiance = selected.dataset.allegiance; + trace.classList.add('move-trace'); - trace.setAttributeNS(null, 'points', points); + svg.querySelector('.board').prepend(trace); } else { - selected.removeAttribute('data-x'); - cell.appendChild(selected); + points = `${trace.getAttribute('points')} ${current.x},${current.y}`; } - } - function removeClones(counter) { - getClones(svg, counter).forEach(c => c.remove()); + trace.setAttributeNS(null, 'points', points); + } else { + selected.removeAttribute('data-x'); + cell.appendChild(selected); } +} - function endMove(counter) { - const trace = svg.querySelector(traceSelector(counter)), - proneCounter = counter.querySelector('[href="#counter-prone"]'); +export function removeClones(svg, counter) { + getClones(svg, counter).forEach(c => c.remove()); +} - if (trace) { - trace.remove(); - } +export function endMove(svg, counter) { + const trace = svg.querySelector(traceSelector(counter)), + proneCounter = counter.querySelector('[href="#counter-prone"]'); - delete counter.dataset.previous; + if (trace) { + trace.remove(); + } - if (proneCounter) { - proneCounter.dataset.preexisting = ''; - } + delete counter.dataset.previous; - removeClones(counter); + if (proneCounter) { + proneCounter.dataset.preexisting = ''; } - function hasProne(counter) { - return !!counter.querySelector('[href="#counter-prone"]'); - } + removeClones(counter); +} - function toggleProne(counter) { - let proneCounter = counter.querySelector('[href="#counter-prone"]'); +export function hasProne(counter) { + return !!counter.querySelector('[href="#counter-prone"]'); +} - if (!proneCounter) { - proneCounter = document.createElementNS(svgns, 'use'); - proneCounter.setAttributeNS(null, 'href', '#counter-prone'); - counter.appendChild(proneCounter); - } else if ('preexisting' in proneCounter.dataset) { - proneCounter.classList.toggle('removed'); - } else { - proneCounter.remove(); - } +export function toggleProne(counter) { + let proneCounter = counter.querySelector('[href="#counter-prone"]'); + + if (!proneCounter) { + proneCounter = document.createElementNS(svgns, 'use'); + proneCounter.setAttributeNS(null, 'href', '#counter-prone'); + counter.appendChild(proneCounter); + } else if ('preexisting' in proneCounter.dataset) { + proneCounter.classList.toggle('removed'); + } else { + proneCounter.remove(); } +} - return { - get selectedClass() { - return selectedClass; - }, - endMove, - getCounter, - hasProne, - toggleProne, - place, - getTrace, - removeClones - }; +export function getSelectedClass() { + return selectedClass; } |