Update deleteClone for cube coords
This commit is contained in:
parent
ade861767b
commit
83457c5218
@ -9,16 +9,9 @@ function traceSelector(counter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCellPosition(cell) {
|
function getCellPosition(cell) {
|
||||||
let pt = new DOMPoint(0, 0),
|
const [x, y] = cell.getAttributeNS(null, 'transform').match(/-?\d+\.?\d*/g);
|
||||||
transform = getComputedStyle(cell).transform.match(/-?\d+\.?\d*/g),
|
|
||||||
mtx = new DOMMatrix(transform);
|
|
||||||
pt = pt.matrixTransform(mtx);
|
|
||||||
|
|
||||||
transform = getComputedStyle(cell.parentElement).transform.match(/-?\d+\.?\d*/g);
|
return { x, y };
|
||||||
mtx = new DOMMatrix(transform);
|
|
||||||
pt = pt.matrixTransform(mtx);
|
|
||||||
|
|
||||||
return pt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClones(svg, counter) {
|
function getClones(svg, counter) {
|
||||||
@ -35,12 +28,9 @@ function addMoveToHistory(selected) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updatePlacement(cell, selected, clone) {
|
function updatePlacement(cell, selected, clone) {
|
||||||
const prevCoords = [
|
const { q, r, s, t } = clone.parentElement.dataset;
|
||||||
clone.parentElement.dataset.x,
|
|
||||||
clone.parentElement.parentElement.dataset.y
|
|
||||||
]
|
|
||||||
|
|
||||||
selected.dataset.previous = prevCoords;
|
selected.dataset.previous = [q, r, s, t];
|
||||||
cell.appendChild(selected);
|
cell.appendChild(selected);
|
||||||
|
|
||||||
Array.from(selected.children).forEach(n => {
|
Array.from(selected.children).forEach(n => {
|
||||||
|
@ -10,8 +10,8 @@ function getCellContents(cell) {
|
|||||||
return cell.querySelectorAll('*:not(use[href="#hex"])');
|
return cell.querySelectorAll('*:not(use[href="#hex"])');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGridIndex({ parentElement: { dataset: { x }, parentElement: { dataset: { y }}}}) {
|
function getGridIndex({ parentElement: { dataset: { q, r, s, t }}}) {
|
||||||
return { x: +x, y: +y };
|
return { q: +q, r: +r, s: +s, t: +t };
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHex(cell) {
|
function getHex(cell) {
|
||||||
@ -56,12 +56,12 @@ function getCellPosition(cell) {
|
|||||||
return { x, y };
|
return { x, y };
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCell(x, y) {
|
function getCell(q, r, s, t) {
|
||||||
return svg.querySelector(`g.grid > g[data-y="${y}"] > g[data-x="${x}"]`);
|
return svg.querySelector(`g[data-q="${q}"][data-r="${r}"][data-s="${s}"][data-t="${t}"]`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCounterAtGridIndex(x, y) {
|
function getCounterAtGridIndex(...coords) {
|
||||||
return getCell(x, y).querySelector('.counter');
|
return getCell(...coords).querySelector('.counter');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelected() {
|
function getSelected() {
|
||||||
@ -155,7 +155,7 @@ function deleteClone(occupant, counter, cell) {
|
|||||||
let current = counter;
|
let current = counter;
|
||||||
trace.setAttributeNS(null, 'points', points);
|
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(','));
|
current = getCounterAtGridIndex(...current.dataset.previous.split(','));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,6 +296,7 @@ export function start(el) {
|
|||||||
// debug //
|
// debug //
|
||||||
const c = soldier.createCounter({ dataset: { allegiance: 'attacker', number: 1, squad: 1 }});
|
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="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);
|
Observable.subscribe('select', select);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user