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')
-rw-r--r-- | src/index.js | 2 | ||||
-rw-r--r-- | src/modules/game.js | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/index.js b/src/index.js index 617e953..63925b1 100644 --- a/src/index.js +++ b/src/index.js @@ -206,6 +206,8 @@ window.addEventListener('load', () => { el.addEventListener('click', () => game.setFiringArc(el.dataset.size)) ); + document.querySelector('.set-grenade').addEventListener('click', () => game.setGrenade()); + recordSheetVisibility.addEventListener('input', e => { let divs = document.querySelectorAll('#content div'); diff --git a/src/modules/game.js b/src/modules/game.js index c94685e..a7bb05e 100644 --- a/src/modules/game.js +++ b/src/modules/game.js @@ -131,6 +131,7 @@ function linedraw(x1, y1, x2, y2) { export default class Game { info; + placing = []; #firingArcVisibility = { davion: false, @@ -392,13 +393,20 @@ export default class Game { point = this.getHex(cell); point.addEventListener('click', e => { + const toPlace = this.placing.pop(); + // TODO let existingOccupant = this.svg.querySelector(`.counter[data-x="${point.dataset.x}"][data-y="${point.dataset.y}"]`); + if (toPlace && toPlace.getAttribute('href') === '#counter-grenade') { + point.parentElement.appendChild(toPlace); + return; + } + if (this.getSelected() && !existingOccupant) { let sl = this.svg.querySelector('.sight-line'); - + this.placing.push(toPlace); this.Counter.place(point); if (sl) { @@ -618,6 +626,7 @@ export default class Game { let counter = container.getCounter(allegiance, number); if (counter) { + container.placing.push(counter); counter.classList.add(selectedClass); let existingArcs = container.getExistingArcs(allegiance, number); existingArcs.forEach(el => el.removeAttribute('clip-path')); @@ -627,6 +636,7 @@ export default class Game { this.unSelect = function () { let selected = container.getSelected(); + container.place = []; if (selected) { let { troopNumber, troopAllegiance } = selected.dataset; @@ -965,4 +975,13 @@ export default class Game { firingArc.addEventListener('contextmenu', cancelFiringArcPlacement); } } + + setGrenade() { + const svgns = "http://www.w3.org/2000/svg"; + + let counter = document.createElementNS(svgns, 'use'); + counter.setAttributeNS(null, 'href', '#counter-grenade'); + counter.addEventListener('click', () => counter.remove()); + this.placing.push(counter); + } } |