Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/game.js')
-rw-r--r--src/modules/game.js21
1 files changed, 20 insertions, 1 deletions
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);
+ }
}