index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/modules/game/soldier.js')
-rw-r--r-- | src/modules/game/soldier.js | 145 |
1 files changed, 73 insertions, 72 deletions
diff --git a/src/modules/game/soldier.js b/src/modules/game/soldier.js index 8407621..efca3ef 100644 --- a/src/modules/game/soldier.js +++ b/src/modules/game/soldier.js @@ -7,9 +7,9 @@ function dataSelector({ dataset: { allegiance, number, squad }}) { return `[data-number="${number}"][data-allegiance="${allegiance}"][data-squad="${squad}"]`; } -function traceSelector(counter) { - return `polyline.move-trace${dataSelector(counter)}`; -} +//function traceSelector(counter) { +// return `polyline.move-trace${dataSelector(counter)}`; +//} function getCellPosition(cell) { const [x, y] = cell.getAttributeNS(null, 'transform').match(/-?\d+\.?\d*/g); @@ -17,44 +17,44 @@ function getCellPosition(cell) { return { x, y }; } -function getClones(svg, counter) { - return svg.querySelectorAll(`.counter.clone${dataSelector(counter)}`); -} - -function addMoveToHistory(selected) { - const clone = selected.cloneNode(true); - clone.classList.remove(selectedClass); - clone.classList.add('clone'); - selected.parentElement.appendChild(clone); - - return clone; -} - -function updatePlacement(cell, selected, clone) { - const { q, r, s, t } = clone.parentElement.dataset; - - selected.dataset.previous = [q, r, s, t]; - placeIn(cell, selected); - - Array.from(selected.children).forEach(n => { - if (n.classList.contains('removed')) { - n.remove(); - } else if ('preexisting' in n.dataset) { - delete n.dataset.preexisting; - } - }); -} - -function createTrace(previous, current, selected) { - const trace = document.createElementNS(svgns, 'polyline'); - - trace.dataset.number = selected.dataset.number; - trace.dataset.allegiance = selected.dataset.allegiance; - trace.classList.add('move-trace'); - trace.setAttributeNS(null, 'points', `${previous.x},${previous.y} ${current.x},${current.y}`); - - return trace; -} +//function getClones(svg, counter) { +// return svg.querySelectorAll(`.counter.clone${dataSelector(counter)}`); +//} + +//function addMoveToHistory(selected) { +// const clone = selected.cloneNode(true); +// clone.classList.remove(selectedClass); +// clone.classList.add('clone'); +// selected.parentElement.appendChild(clone); +// +// return clone; +//} + +//function updatePlacement(cell, selected, clone) { +// const { q, r, s, t } = clone.parentElement.dataset; +// +// selected.dataset.previous = [q, r, s, t]; +// placeIn(cell, selected); +// +// Array.from(selected.children).forEach(n => { +// if (n.classList.contains('removed')) { +// n.remove(); +// } else if ('preexisting' in n.dataset) { +// delete n.dataset.preexisting; +// } +// }); +//} + +//function createTrace(previous, current, selected) { +// const trace = document.createElementNS(svgns, 'polyline'); +// +// trace.dataset.number = selected.dataset.number; +// trace.dataset.allegiance = selected.dataset.allegiance; +// trace.classList.add('move-trace'); +// trace.setAttributeNS(null, 'points', `${previous.x},${previous.y} ${current.x},${current.y}`); +// +// return trace; +//} function placeIn(location, target) { location.querySelector('use[href="#hex"]').after(target); @@ -87,29 +87,30 @@ export function createCounter(selected, weapon = 'rifle') { return g; } -export function handleTrace(svg, selected, clone, current) { - let trace = getTrace(svg, selected); - - if (!trace) { - trace = createTrace(getCellPosition(clone.parentElement), current, selected); - svg.querySelector('.grid').before(trace); - } else { - const points = `${trace.getAttribute('points')} ${current.x},${current.y}`; - trace.setAttributeNS(null, 'points', points); - } -} +//export function handleTrace(svg, selected, clone, current) { +// let trace = getTrace(svg, selected); +// +// if (!trace) { +// trace = createTrace(getCellPosition(clone.parentElement), current, selected); +// svg.querySelector('.grid').before(trace); +// } else { +// const points = `${trace.getAttribute('points')} ${current.x},${current.y}`; +// trace.setAttributeNS(null, 'points', points); +// } +//} export function getAllCounters(container) { return container.querySelectorAll('g.counter[data-allegiance][data-number]'); } export function getCounter(svg, selected) { - return svg.querySelector(`.counter${dataSelector(selected)}:not(.clone)`); + //return svg.querySelector(`.counter${dataSelector(selected)}:not(.clone)`); + return svg.querySelector(`.counter${dataSelector(selected)}`); } -export function getTrace(svg, counter) { - return svg.querySelector(traceSelector(counter)); -} +//export function getTrace(svg, counter) { +// return svg.querySelector(traceSelector(counter)); +//} export function place(svg, selected, cell) { //console.log(selected.parentElement); @@ -134,23 +135,23 @@ export function place(svg, selected, cell) { //} } -export function removeClones(svg, counter) { - getClones(svg, counter).forEach(c => c.remove()); -} +//export function removeClones(svg, counter) { +// getClones(svg, counter).forEach(c => c.remove()); +//} -export function endMove(svg, counter) { - Array.from(counter.children).forEach(n => { - if (n.classList.contains('removed')) { - n.remove(); - } else { - n.dataset.preexisting = ''; - } - }); - - svg.querySelector(traceSelector(counter))?.remove(); - delete counter.dataset.previous; - removeClones(svg, counter); -} +//export function endMove(svg, counter) { + //Array.from(counter.children).forEach(n => { + // if (n.classList.contains('removed')) { + // n.remove(); + // } else { + // n.dataset.preexisting = ''; + // } + //}); + + //svg.querySelector(traceSelector(counter))?.remove(); + //delete counter.dataset.previous; + //removeClones(svg, counter); +//} export function getSelectedClass() { return selectedClass; |