Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/game.js')
-rw-r--r--src/modules/game.js27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/modules/game.js b/src/modules/game.js
index 237e346..e40a8a2 100644
--- a/src/modules/game.js
+++ b/src/modules/game.js
@@ -51,7 +51,7 @@ export default class Game {
}
getExistingArcs(al, n) {
- return this.svg.querySelectorAll(`#firing-arcs polygon[data-troop-number="${n}"][data-troop-allegiance="${al}"]`);
+ return this.svg.querySelectorAll(`#firing-arcs polygon[data-number="${n}"][data-allegiance="${al}"]`);
}
getUnclippedFiringArcs() {
@@ -109,7 +109,7 @@ export default class Game {
}
endTurn(allegiance) {
- const selector = `#firing-arcs [data-troop-allegiance="${allegiance}"]`;
+ const selector = `#firing-arcs [data-allegiance="${allegiance}"]`;
this.svg.querySelectorAll(selector).forEach(el => el.remove());
}
@@ -119,7 +119,7 @@ export default class Game {
toggleFiringArcVisibility(allegiance) {
const vis = this.#firingArcVisibility[allegiance],
- clipPaths = this.svg.querySelectorAll(`clipPath[data-troop-allegiance="${allegiance}"]`);
+ clipPaths = this.svg.querySelectorAll(`clipPath[data-allegiance="${allegiance}"]`);
clipPaths.forEach(cp => cp.style.display = !vis ? 'none' : '');
this.#firingArcVisibility[allegiance] = !vis;
@@ -129,9 +129,9 @@ export default class Game {
let unclipped = this.getUnclippedFiringArcs();
unclipped.forEach(el => {
- const { troopNumber, troopAllegiance } = el.dataset,
- clipPathId = `clip-path-${troopAllegiance}-${troopNumber}`,
- isVisible = this.#firingArcVisibility[troopAllegiance];
+ const { number, allegiance } = el.dataset,
+ clipPathId = `clip-path-${allegiance}-${number}`,
+ isVisible = this.#firingArcVisibility[allegiance];
if (isVisible) {
this.svg.querySelector(`#${clipPathId}`).style.display = 'none';
@@ -254,6 +254,21 @@ export default class Game {
}
});
+
+ cell.addEventListener('dblclick', e => {
+ const toPlace = this.placing.pop(),
+ occupant = this.getCellOccupant(cell);
+
+ if (toPlace == occupant) {
+ const { number, allegiance } = toPlace.dataset,
+ selector = `[data-allegiance="${allegiance}"][data-number="${number}"]`;
+
+ this.svg.querySelectorAll(selector).forEach(el => el.remove());
+ }
+
+ this.unSelect();
+ });
+
// Logic for this event:
// If there's a locked sightline, unlock it. Otherwise, if there's an
// active sightline, lock it.