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/gameboard.js')
-rw-r--r-- | src/modules/gameboard.js | 150 |
1 files changed, 87 insertions, 63 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js index fd2aaf1..8c91ee5 100644 --- a/src/modules/gameboard.js +++ b/src/modules/gameboard.js @@ -46,16 +46,16 @@ function isMechTemplate(el) { return el && el.getAttribute('class') === 'mech-template'; } -function isClone(counter) { - const isClone = counter.classList.contains('clone'), - { allegiance: clAl, number: clNum } = counter.dataset; - - return { - of: function ({ dataset: { allegiance, number }}) { - return isClone && clAl == allegiance && clNum == number; - } - }; -} +//function isClone(counter) { +// const isClone = counter.classList.contains('clone'), +// { allegiance: clAl, number: clNum } = counter.dataset; +// +// return { +// of: function ({ dataset: { allegiance, number }}) { +// return isClone && clAl == allegiance && clNum == number; +// } +// }; +//} function getCellPosition(cell) { const [x, y] = cell.getAttributeNS(null, 'transform').match(/-?\d+\.?\d*/g); @@ -127,56 +127,56 @@ function drawSightLine(sourceCell, targetCell) { svg.querySelector('.gameboard').appendChild(line); } -function moveBackOneStepInHistory(counter) { - const trace = soldier.getTrace(svg, counter); - - counter.remove(); - counter = getCounterAtGridIndex(...counter.dataset.previous.split(',')); - counter.classList.remove('clone'); - counter.classList.add(soldier.getSelectedClass()); - - if (!('previous' in counter.dataset)) { - trace.remove(); - } else { - const points = trace.getAttribute('points').split(' '); - points.pop(); - trace.setAttributeNS(null, 'points', points.join(' ')); - } - - return counter; -} - -function clearMoveHistory(clone, counter) { - clone.classList.remove('clone'); - clone.classList.add(soldier.getSelectedClass()); - counter.remove(); - counter = clone; - soldier.removeClones(svg, counter); - soldier.getTrace(svg, counter).remove(); - - return counter; -} - -function deleteClone(occupant, counter, cell) { - const index = getGridIndex(occupant), - trace = soldier.getTrace(svg, counter), - pos = getCellPosition(cell), - points = trace.getAttribute('points').split(' ').filter(p => p != `${pos.x},${pos.y}`).join(' ');; - - let current = counter; - trace.setAttributeNS(null, 'points', points); - - while (current.dataset.previous != `${index.q},${index.r},${index.s},${index.t}`) { - current = getCounterAtGridIndex(...current.dataset.previous.split(',')); - } - - current.dataset.previous = occupant.dataset.previous; - occupant.remove(); -} - -function hasPreviousMoveInHistory(counter) { - return 'previous' in counter.dataset; -} +//function moveBackOneStepInHistory(counter) { +// const trace = soldier.getTrace(svg, counter); +// +// counter.remove(); +// counter = getCounterAtGridIndex(...counter.dataset.previous.split(',')); +// counter.classList.remove('clone'); +// counter.classList.add(soldier.getSelectedClass()); +// +// if (!('previous' in counter.dataset)) { +// trace.remove(); +// } else { +// const points = trace.getAttribute('points').split(' '); +// points.pop(); +// trace.setAttributeNS(null, 'points', points.join(' ')); +// } +// +// return counter; +//} + +//function clearMoveHistory(clone, counter) { +// clone.classList.remove('clone'); +// clone.classList.add(soldier.getSelectedClass()); +// counter.remove(); +// counter = clone; +// soldier.removeClones(svg, counter); +// soldier.getTrace(svg, counter).remove(); +// +// return counter; +//} + +//function deleteClone(occupant, counter, cell) { +// const index = getGridIndex(occupant), +// trace = soldier.getTrace(svg, counter), +// pos = getCellPosition(cell), +// points = trace.getAttribute('points').split(' ').filter(p => p != `${pos.x},${pos.y}`).join(' ');; +// +// let current = counter; +// trace.setAttributeNS(null, 'points', points); +// +// while (current.dataset.previous != `${index.q},${index.r},${index.s},${index.t}`) { +// current = getCounterAtGridIndex(...current.dataset.previous.split(',')); +// } +// +// current.dataset.previous = occupant.dataset.previous; +// occupant.remove(); +//} + +//function hasPreviousMoveInHistory(counter) { +// return 'previous' in counter.dataset; +//} function selectOffBoard() { Observable.notify('select', this, { revealRecord: true }); @@ -229,7 +229,7 @@ function endMove() { const selected = getSelected(); if (selected) { - soldier.endMove(svg, selected); + //soldier.endMove(svg, selected); deselect(); } } @@ -405,9 +405,33 @@ export function start(el) { //cell2.classList.add('hover'); // - //const trooper1 = soldier.createCounter({ dataset: { allegiance: 'attacker', number: 1, squad: 1 }}, 'blazer'); + ['lmg', 'mmg', 'hmg', 'splaser', 'hsplaser', 'mpppc'].forEach((w, i) => { + soldier.place( + svg, + soldier.createCounter({ dataset: { allegiance: 'attacker', number: i + 1, squad: 1 }}, w), + getCell(-3 - i, 9, -6 + i, 0) + ) + }); + + ['srm', 'hsrm', 'law', 'gl', 'autogl', 'lrrifle'].forEach((w, i) => { + soldier.place( + svg, + soldier.createCounter({ dataset: { allegiance: 'attacker', number: i + 1, squad: 2 }}, w), + getCell(-2 - i, 8, -6 + i, 0) + ) + }); + + ['satchelcharge', 'grenade', 'nonlethalhand', 'lethalhand', 'flamer', 'hflamer', 'inferno'].forEach((w, i) => { + soldier.place( + svg, + soldier.createCounter({ dataset: { allegiance: 'attacker', number: i + 1, squad: 3 }}, w), + getCell(-2 - i, 7, -5 + i, 0) + ) + }); + //const weapon = 'mpppc'; + //const trooper1 = soldier.createCounter({ dataset: { allegiance: 'attacker', number: 1, squad: 1 }}, weapon); //soldier.place(svg, trooper1, getCell(-3, 9, -6, 0)); - // + //soldier.place( // svg, // soldier.createCounter({ dataset: { allegiance: 'defender', number: 1, squad: 1 }}, 'blazer'), |