WIP: lay mapsheets out in an array

This commit is contained in:
Catalin Constantin Mititiuc 2025-06-16 22:41:31 -07:00
parent d914d9ec7d
commit b0d9675793

View File

@ -493,18 +493,12 @@ function drawScenario2() {
// const scenario2grid = drawScenario2(); // const scenario2grid = drawScenario2();
const horzMapVect = function(map) { const horzMapVect = function(map) {
const direction = 1; return vectorAdd(map, { q: 1, r: 0, s: -1 }, 33);
// right, { q: -1, r: 0, s: 1 }, 33
// left, { q: 1, r: 0, s: -1 }, 33
return translateCoords(map, ({ q, r, s }) => ({ q: q - 33 * direction, r, s: s + 33 * direction }));
} }
// [-16, 17], [-33, 0, 33], [-49, -16, 17, 50] // [-16, 17], [-33, 0, 33], [-49, -16, 17, 50]
const vertMapVect = function(map) { const vertMapVect = function(map) {
const direction = 1; return vectorAdd(map, { q: 1, r: -2, s: 1 }, 13);
// up, { q: 1, r: -2, s: 1 }, 13
// down, { q: -1, r: 2, s: -1 }, 13
return translateCoords(map, ({ q, r, s }) => ({ q: q - 13 * direction, r: r + 26 * direction, s: s - 13 * direction }));
} }
// [[7], [[13], [[14], // [[7], [[13], [[14],
@ -512,11 +506,80 @@ const vertMapVect = function(map) {
// [-13]] [-6] // [-13]] [-6]
// [-12]] // [-12]]
mapsheet2 = drawMapsheet(gameboard, mapsheet2); function vectorAdd(map, { q: dq, r: dr, s: ds }, scalar) {
return translateCoords(map, ({ q, r, s }) => ({ q: q - dq * scalar, r: r + dr * scalar, s: s - ds * scalar }));
}
mapsheet3.grid = vertMapVect(mapsheet3.grid); function findMult(arr) {
mapsheet3.buildings = mapsheet3.buildings.map(vertMapVect); if (arr.length % 2)
mapsheet3 = drawMapsheet(gameboard, mapsheet3); return arr.map((v, index) => {
const row = v.length % 2 ? v.map((rv, rindex) => [Math.floor(rindex - v.length / 2) + 1, rv]) : v.map((rv, rindex) => [Math.floor(rindex - v.length / 2), rv]).map(([rm, rv]) => [rm > -1 ? rm + 1 : rm, rv]);
return [Math.floor(index - arr.length / 2) + 1, row];
});
else
return arr.map((v, index) => {
const row = v.length % 2 ? v.map((rv, rindex) => [Math.floor(rindex - v.length / 2) + 1, rv]) : v.map((rv, rindex) => [Math.floor(rindex - v.length / 2), rv]).map(([rm, rv]) => [rm > -1 ? rm + 1 : rm, rv]);
return [Math.floor(index - arr.length / 2), row];
}).map(([m, v]) => [m > -1 ? m + 1 : m, v]);
}
function findScalar(arr) {
let pos;
let neg;
if (arr.length % 2) {
pos = 13;
neg = 13;
} else {
pos = 7;
neg = 6;
}
return arr.map(([mult, v]) => {
let hpos, hneg;
if (v.length % 2) {
hpos = 33;
hneg = 33;
} else {
hpos = 16;
hneg = 17;
}
const row = v.map(([hmult, hv]) => [hmult < 0 ? hmult * hneg : hmult * hpos, hv]);
return [mult < 0 ? mult * neg : mult * pos, row];
});
}
// const mults = findMult([['a', 'b', 'c'], ['c', 'd', 'e'], ['e', 'f', 'g']]);
// const mults = findMult([['a', 'b'], ['c', 'd', 'e'], ['c', 'd', 'e'], ['c', 'd', 'e']]);
// console.log(findScalar(mults));
const sheets = [[mapsheet2, mapsheet3]];
// const sheets = [[mapsheet2], [mapsheet1], [mapsheet3]];
findScalar(findMult(sheets)).forEach(([vscalar, row]) => {
const vertMapVect = function(map) {
return vectorAdd(map, { q: 1, r: -2, s: 1 }, vscalar);
}
row.forEach(([hscalar, ms]) => {
const horzMapVect = function(map) {
return vectorAdd(map, { q: 1, r: 0, s: -1 }, hscalar);
}
ms.grid = horzMapVect(vertMapVect(ms.grid));
ms.buildings = ms.buildings.map(buildings => horzMapVect(vertMapVect(buildings)));
ms = drawMapsheet(gameboard, ms);
})
});
// mapsheet1 = drawMapsheet(gameboard, mapsheet1);
// mapsheet3.grid = horzMapVect(vertMapVect(mapsheet3.grid));
// mapsheet3.buildings = mapsheet3.buildings.map(buildings => horzMapVect(vertMapVect(buildings)));
// mapsheet3 = drawMapsheet(gameboard, mapsheet3);
const circle = document.createElementNS(xmlns, 'circle'); const circle = document.createElementNS(xmlns, 'circle');
circle.setAttributeNS(null, 'r', 5); circle.setAttributeNS(null, 'r', 5);