index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-06-22 10:52:07 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-06-22 10:52:07 -0700 |
commit | aacbf38cd650d3698103bd67bfaf91e3ae01d546 (patch) | |
tree | 99355bce14dc78d05b74694462c503bf3453c71f /src/radial.js | |
parent | 0f4907988aa29211e2b05a3234b0827bd4acc7fd (diff) |
WIP: lay mapsheets out in an array
Diffstat (limited to 'src/radial.js')
-rw-r--r-- | src/radial.js | 87 |
1 files changed, 75 insertions, 12 deletions
diff --git a/src/radial.js b/src/radial.js index 1ab2642..932a95f 100644 --- a/src/radial.js +++ b/src/radial.js @@ -493,18 +493,12 @@ function drawScenario2() { // const scenario2grid = drawScenario2(); const horzMapVect = function(map) { - const direction = 1; - // 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 })); + return vectorAdd(map, { q: 1, r: 0, s: -1 }, 33); } // [-16, 17], [-33, 0, 33], [-49, -16, 17, 50] const vertMapVect = function(map) { - const direction = 1; - // 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 })); + return vectorAdd(map, { q: 1, r: -2, s: 1 }, 13); } // [[7], [[13], [[14], @@ -512,11 +506,80 @@ const vertMapVect = function(map) { // [-13]] [-6] // [-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 })); +} + +function findMult(arr) { + if (arr.length % 2) + 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 = vertMapVect(mapsheet3.grid); -mapsheet3.buildings = mapsheet3.buildings.map(vertMapVect); -mapsheet3 = drawMapsheet(gameboard, mapsheet3); +// 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'); circle.setAttributeNS(null, 'r', 5); |