Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/game.js')
-rw-r--r--src/modules/game.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/modules/game.js b/src/modules/game.js
index ff9937b..657aa9d 100644
--- a/src/modules/game.js
+++ b/src/modules/game.js
@@ -23,11 +23,19 @@ export default class Game {
}
getCells() {
- return this.svg.querySelectorAll('g[data-x]');
+ return this.svg.querySelectorAll('g[data-y] > g[data-x]');
}
getCell(x, y) {
- return this.svg.querySelector(`g[data-y="${y}"] g[data-x="${x}"]`);
+ return this.svg.querySelector(`g[data-y="${y}"] > g[data-x="${x}"]`);
+ }
+
+ getCellOccupant(cell) {
+ return cell.querySelector('.counter');
+ }
+
+ getCellContents(cell) {
+ return cell.querySelectorAll('*:not(use[href="#hex"])');
}
getHex(cell) {
@@ -35,7 +43,7 @@ export default class Game {
}
getSelected() {
- return this.svg.querySelector(`use[data-allegiance][data-number].selected`);
+ return this.svg.querySelector(`.counter.selected[data-allegiance][data-number]`);
}
getSightLine() {
@@ -55,7 +63,7 @@ export default class Game {
}
getCounterAtGridIndex(x, y) {
- return this.getCell(x, y).querySelector('use[href*="#t-"');
+ return this.getCell(x, y).querySelector('.counter');
}
getBoard() {
@@ -152,8 +160,8 @@ export default class Game {
const state = {
placing: this.placing,
hex: cell.querySelector('use[href="#hex"]'),
- occupant: cell.querySelector('use[href*="#t-"'),
- contents: cell.querySelectorAll('*:not(use[href="#hex"])')
+ occupant: this.getCellOccupant(cell),
+ contents: this.getCellContents(cell)
};
let toPlace = this.placing.pop();
@@ -285,7 +293,7 @@ export default class Game {
}
}
- let occupant = cell.querySelector('use[href*="#t-"');
+ let occupant = this.getCellOccupant(cell);
if (occupant) {
const { number, allegiance } = occupant.dataset;
@@ -304,7 +312,7 @@ export default class Game {
this.sightLine.clear();
}
- let occupant = cell.querySelector('use[href*="#t-"');
+ let occupant = this.getCellOccupant(cell);
if (occupant) {
let { number, allegiance } = occupant.dataset,