Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-06-28 15:10:28 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-06-28 15:10:28 -0700
commit83457c5218047584d2d9e8210060b64b10739de0 (patch)
tree151f83ed97176a83da3aff5cb2b1111512b44991 /src/modules/gameboard.js
parentade861767b9961590ba31ca6ba30be1ca8346ea1 (diff)
Update deleteClone for cube coords
Diffstat (limited to 'src/modules/gameboard.js')
-rw-r--r--src/modules/gameboard.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 66b493b..81d71a3 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -10,8 +10,8 @@ function getCellContents(cell) {
return cell.querySelectorAll('*:not(use[href="#hex"])');
}
-function getGridIndex({ parentElement: { dataset: { x }, parentElement: { dataset: { y }}}}) {
- return { x: +x, y: +y };
+function getGridIndex({ parentElement: { dataset: { q, r, s, t }}}) {
+ return { q: +q, r: +r, s: +s, t: +t };
}
function getHex(cell) {
@@ -56,12 +56,12 @@ function getCellPosition(cell) {
return { x, y };
}
-function getCell(x, y) {
- return svg.querySelector(`g.grid > g[data-y="${y}"] > g[data-x="${x}"]`);
+function getCell(q, r, s, t) {
+ return svg.querySelector(`g[data-q="${q}"][data-r="${r}"][data-s="${s}"][data-t="${t}"]`);
}
-function getCounterAtGridIndex(x, y) {
- return getCell(x, y).querySelector('.counter');
+function getCounterAtGridIndex(...coords) {
+ return getCell(...coords).querySelector('.counter');
}
function getSelected() {
@@ -155,7 +155,7 @@ function deleteClone(occupant, counter, cell) {
let current = counter;
trace.setAttributeNS(null, 'points', points);
- while (current.dataset.previous != `${index.x},${index.y}`) {
+ while (current.dataset.previous != `${index.q},${index.r},${index.s},${index.t}`) {
current = getCounterAtGridIndex(...current.dataset.previous.split(','));
}
@@ -296,6 +296,7 @@ export function start(el) {
// debug //
const c = soldier.createCounter({ dataset: { allegiance: 'attacker', number: 1, squad: 1 }});
soldier.place(svg, c, svg.querySelector('[data-q="0"][data-r="0"][data-s="0"][data-t="0"]'));
+ // soldier.place(svg, c, svg.querySelector('[data-q="-2"][data-r="-3"][data-s="5"][data-t="0"]'));
///////////
Observable.subscribe('select', select);