Web Dev Solutions

Catalin Mititiuc

From 4dc47d6f045c01479d1298b933fd3e129d3d8279 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Mon, 22 Apr 2024 14:28:29 -0700 Subject: Add grenade counter --- src/modules/game.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/modules') 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); + } } -- cgit v1.2.3