Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/modules/gameboard.js3
-rw-r--r--src/radial.js28
2 files changed, 26 insertions, 5 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index d9919ec..afb582b 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -23,7 +23,8 @@ function getCellOccupant(cell) {
}
function getCells(svg) {
- return svg.querySelectorAll('g.grid > g[data-y] > g[data-x]');
+ // return svg.querySelectorAll('g.grid > g[data-y] > g[data-x]');
+ return svg.querySelectorAll('[data-q][data-r][data-s][data-t]');
}
function getLockedSightLine(svg) {
diff --git a/src/radial.js b/src/radial.js
index 6177a65..2c261bf 100644
--- a/src/radial.js
+++ b/src/radial.js
@@ -88,6 +88,10 @@ function drawHexes(el, list, renderText = false) {
const { x, y } = radialToScreenCoords({ q, r, s });
const cell = document.createElementNS(xmlns, 'g');
+ cell.dataset.q = q;
+ cell.dataset.r = r;
+ cell.dataset.s = s;
+ cell.dataset.t = t;
cell.setAttributeNS(null, 'transform', `translate(${x}, ${y})`);
const use = document.createElementNS(xmlns, 'use');
@@ -469,7 +473,6 @@ function drawMapsheet(gameboard, mapsheet, position) {
const gridContainer = document.createElementNS(xmlns, 'g');
gridContainer.classList.add('elevation-0');
- container.appendChild(gridContainer);
const buildingHexes = drawBuildings(mapsheet.buildings, container, position, document.querySelector(`defs .${mapsheet.id}`));
@@ -492,6 +495,8 @@ function drawMapsheet(gameboard, mapsheet, position) {
gridContainer.appendChild(use);
});
+ container.appendChild(gridContainer);
+
return new Map([...grid, ...buildingHexes]);
// return { id, grid, buildings };
}
@@ -505,7 +510,7 @@ const vertMapVect = function(coords) {
}
function vectorAdd({ q, r, s }, { q: dq, r: dr, s: ds }, scalar) {
- return ({ q: q - dq * scalar, r: r + dr * scalar, s: s - ds * scalar });
+ return ({ q: q + dq * scalar, r: r + dr * scalar, s: s + ds * scalar });
}
function findMult(arr) {
@@ -553,9 +558,11 @@ let sheets = [];
// sheets = [[mapsheet1]];
// sheets = [[mapsheet2]];
-// sheets = [[mapsheet2], [mapsheet3]];
+// sheets = [[mapsheet2, mapsheet3]];
// sheets = [[mapsheet2], [mapsheet1], [mapsheet3]];
+// drawMapsheet(grid, mapsheet2, vectorAdd({ q: 0, r: 0, s: 0 }, { q: 1, r: -2, s: 1 }, 6));
+
sheets = [
[mapsheet2, mapsheet1],
[mapsheet3, mapsheet4]
@@ -571,6 +578,10 @@ sheets = [
// const map1building2furniture = document.querySelector('defs .mapsheet2 .building2 .furniture');
// document.querySelector('.gameboard .building2 .structure').appendChild(map1building2furniture);
+// console.log(mapsheet2);
+
+let finalGrid = new Map();
+
findScalar(findMult(sheets)).forEach(([vscalar, row]) => {
const vertMapVect = function(coords) {
return vectorAdd(coords, { q: 1, r: -2, s: 1 }, vscalar);
@@ -578,13 +589,22 @@ findScalar(findMult(sheets)).forEach(([vscalar, row]) => {
row.forEach(([hscalar, ms]) => {
const horzMapVect = function(coords) {
- return vectorAdd(coords, { q: 1, r: 0, s: -1 }, hscalar);
+ return vectorAdd(coords, { q: -1, r: 0, s: 1 }, hscalar);
}
ms = drawMapsheet(grid, ms, horzMapVect(vertMapVect({ q: 0, r: 0, s: 0 })));
+ // console.log(ms);
+ finalGrid = new Map([...finalGrid, ...ms]);
})
});
+const origin = document.querySelector('[transform="translate(0, 0)"]');
+// console.log(origin);
+
+// console.log([...finalGrid.entries()].find(([k, v]) => v === origin));
+
+console.log(finalGrid.get('0,0,0,0'));
+
const circle = document.createElementNS(xmlns, 'circle');
circle.setAttributeNS(null, 'r', 5);
circle.setAttributeNS(null, 'fill', 'green');