index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
-rw-r--r-- | public/radial.html | 192 | ||||
-rw-r--r-- | src/radial.js | 54 |
2 files changed, 63 insertions, 183 deletions
diff --git a/public/radial.html b/public/radial.html index 16907fb..1fe2bd6 100644 --- a/public/radial.html +++ b/public/radial.html @@ -260,7 +260,7 @@ <body> <!-- <svg viewBox="-150 -130 300 260" xmlns="http://www.w3.org/2000/svg"> --> <!-- <svg viewBox="-300 -250 600 500" xmlns="http://www.w3.org/2000/svg"> --> - <svg viewBox="-900 -600 1800 1200" xmlns="http://www.w3.org/2000/svg"> + <svg viewBox="-900 -600 1800 1200" xmlns="http://www.w3.org/2000/svg"> <defs> <polygon id="hex" points="0,10 8.66,5 8.66,-5 0,-10 -8.66,-5 -8.66,5" /> <line id="ast-line" stroke="#000000" stroke-width="0.3" x1="-1.2" y1="0" x2="1.2" y2="0" /> @@ -278,8 +278,7 @@ </pattern> <g id="building1" class="building"> - <path id="building1-floor" class="floor" - d="M -38.969999,-67.499999 H 38.969999 V 67.499999 h -77.939998 z" /> + <path id="building1-floor" class="floor" d="M -38.969999,-67.499999 H 38.969999 V 67.499999 h -77.939998 z" /> <path id="building1-outer-wall" class="outer-wall" d="m 38.969998,-7.500001 h -12.99 v 12.5 m -21.6499995,32.5 H 38.969998 m -34.6399995,30 v -60 h -8.66 v -45 m -8.6600005,105 v -45 h -25.979997 m 0,-89.999998 H 38.969999 V 67.499999 h -77.939998 z" /> <path id="building1-inner-wall" class="inner-wall" @@ -298,182 +297,35 @@ </g> <g id="building3" class="building"> - <rect id="building3-floor" class="floor" x="-32.25" y="-44" width="64.5" height="88" /> - <path id="building3-outer-wall" class="outer-wall" d=" - M -32.25 -44 h 64.5 v 88 h -64 z - m 37.5 0 v 18 - m -37.5 0 h 64.5 - m -36.5 0 v 10.5 - m 0 21 V 44 - m 24.5 -34.5 h 12 - " /> - <path id="building3-inner-wall" class="inner-wall" d=" - M -32.25 -44 h 64.5 v 88 h -64 z - m 37.5 0 v 18 - m -37.5 0 h 64.5 - m -36.5 0 v 10.5 - m 0 21 V 44 - m 24.5 -34.5 h 12 - " /> - <path id="building3-windows" class="windows" d=" - M -13.75 -44 h 10.5 - M 32.25 -10 v 10 - M 23 44 h -10.5 - M -32.25 29 v -10.5 - m 0 -21 v -10 - " /> - <path id="building3-door-edges" class="door-edges" d=" - M 12 -44 h 10.5 - m -45 18 h 10.5 - m 24.5 0 h 10.5 - M -22 44 h 10.5 - " /> - <path id="building3-doors" class="doors" d=" - M 15 -44 h 5 - m -40 18 h 5.5 - m 29 0 h 5.5 - M -19.5 44 h 5.5 - " /> + <path id="building3-floor" class="floor" d="m -30.310003,52.5 v -89.999997 h 60.62001 V 52.5 Z" /> + <path id="building3-outer-wall" class="outer-wall" + d="m 21.650012,0 h 8.659995 m -34.640005,-37.5 v 45 m 0,30 v -15 m 8.66,30.000001 V 37.500003 m -34.64,0 h 60.620005 m -60.620005,15 v -90 h 60.620005 v 90 z" /> + <path id="building3-inner-wall" class="inner-wall" + d="m 21.650012,0 h 8.659995 m -34.640005,-37.5 v 45 m 0,30 v -15 m 8.66,30.000001 V 37.500003 m -34.64,0 h 60.620005 m -60.620005,15 v -90 h 60.620005 v 90 z" /> </g> <g id="building4" class="building"> - <rect id="building4-floor" class="floor" x="-35.25" y="-62.25" width="70.5" height="124.5"/> - <path id="building4-outer-wall" class="outer-wall" d=" - M -35.25 -62.25 h 70.5 v 124.5 h -70.5 z - m 35.5 0 v 50 h -35.5 - m 35.5 -14 h 35 - m -17 0 v 30 - m 17 0 h -34.5 v 58 - m 34.5 -22.25 h -34 - m -16 1.5 h -20 - "/> - <path id="building4-inner-wall" class="inner-wall" d=" - M -35.25 -62.25 h 70.5 v 124.5 h -70.5 z - m 35.5 0 v 50 h -35.5 - m 35.5 -14 h 35 - m -17 0 v 30 - m 17 0 h -34.5 v 58 - m 34.5 -22.25 h -34 - m -16 1.5 h -20 - "/> - <path id="building4-windows" class="windows" d=" - M 35.25 -44 v 10.5 - m 0 51 v 10 - m -14.5 34.75 h -15.5 - m -40.5 -50 v -10 - m 0 -18 v -10 - "/> - <path id="building4-door-edges" class="door-edges" d=" - M -27 -62.25 h 10 - m 20 36 h 10 - m -31 14 h 10 - m 26.25 -1.5 v 10 - m -15.25 7.5 h 10 - m -12.25 40 v 10 - m -31 8.5 h 16 - "/> - <path id="building4-doors" class="doors" d=" - M -24.5 -62.25 h 5 - m 25 36 h 5 - m -26 14 h 5 - m 28.75 1 v 5 - m -13 10 h 5.5 - m -10 42.25 v 5.5 - m -28.5 10.75 h 11 - "/> + <rect id="building4-floor" class="floor" width="69.279999" height="120" x="-30.309992" y="-52.499996" /> + <path id="building4-outer-wall" class="outer-wall" + d="m -30.31,52.5 h 17.32 m 34.64001,-45 0,-30 m 17.32,75 H 4.33 m 34.64001,-45 h -34.64 l 0,60 m 34.64,-90 H 4.33 m 0,-30 L 4.33,-7.4999998 H -30.31 M -30.31,-52.5 h 69.28 v 120 h -69.28 z" /> + <path id="building4-inner-wall" class="inner-wall" + d="m -30.31,52.5 h 17.32 m 34.64001,-45 0,-30 m 17.32,75 H 4.33 m 34.64001,-45 h -34.64 l 0,60 m 34.64,-90 H 4.33 m 0,-30 L 4.33,-7.4999998 H -30.31 M -30.31,-52.5 h 69.28 v 120 h -69.28 z" /> </g> <g id="building5" class="building"> - <rect id="building5-floor" class="floor" x="-75" y="-32.75" width="150" height="65.5"/> - <path id="building5-outer-wall" class="outer-wall" d=" - M -75 -32.75 h 150 v 65.5 h -150 z - m 0 13 h 8 m 13 0 h 7 - m 0 -13 v 26.5 - m 43 -26.5 v 26.5 - m 38 -26.5 v 26.5 - m 23.5 -26.5 v 65.5 - m -132.5 -39 h 7 m 14 0 h 111 - m 15 1.5 h 3 - m -105.25 -1.5 v 7.5 - m 0 17.5 v 13.5 - m 36.5 0 v -13.5 - m 4.5 -19 v -6 - "/> - <path id="building5-inner-wall" class="inner-wall" d=" - M -75 -32.75 h 150 v 65.5 h -150 z - m 0 13 h 8 m 13 0 h 7 - m 0 -13 v 26.5 - m 43 -26.5 v 26.5 - m 38 -26.5 v 26.5 - m 23.5 -26.5 v 65.5 - m -132.5 -39 h 7 m 14 0 h 111 - m 15 1.5 h 3 - m -105.25 -1.5 v 7.5 - m 0 17.5 v 13.5 - m 36.5 0 v -13.5 - m 4.5 -19 v -6 - "/> - <path id="building5-windows" class="windows" d=" - M -21 -32.75 h 10 - m 33 0 h 10 - m 6.5 0 h 10 - m 9 51 v 10 - m -31 4.5 h -16 - m -19.5 0 h -16 - M -75 2 v 10 - m 0 7 v 10 - "/> - <path id="building5-door-edges" class="door-edges" d=" - M -75 -17.75 v 9.5 - m 150 -22 v 10 - m -17.5 21 v 10 - m -2 -17 h -9 - m -38 0 h -10 - m -10.5 0 h -10 - "/> - <path id="building5-doors" class="doors" d=" - M -75 -15.75 v 5.5 - m 150 -18 v 6 - m -17.5 25 v 6 - m -4 -15 h -5 - m -43 0 h -4.5 - m -15.5 0 h -5 - "/> + <rect id="building5-floor" class="floor" width="147.22" height="60" x="-82.269997" y="-37.5" /> + <path id="building5-outer-wall" class="outer-wall" + d="M -56.289999,-7.5 H -64.95 m 8.660001,-15 H -64.95 m -12.989999,15 h -4.329999 m 4.329999,-15 h -4.33 m 47.63,32.5 V 22.5 M 0,10 v 12.5 m 21.650001,-60 v 30 m -34.64,0 v -30 m -43.3,0 v 30 h 103.92 m 0,-30 v 60 m -129.899999,-60 H 64.950001 v 60 h -147.22 z" /> + <path id="building5-inner-wall" class="inner-wall" + d="M -56.289999,-7.5 H -64.95 m 8.660001,-15 H -64.95 m -12.989999,15 h -4.329999 m 4.329999,-15 h -4.33 m 47.63,32.5 V 22.5 M 0,10 v 12.5 m 21.650001,-60 v 30 m -34.64,0 v -30 m -43.3,0 v 30 h 103.92 m 0,-30 v 60 m -129.899999,-60 H 64.950001 v 60 h -147.22 z" /> </g> <g id="building6" class="building"> - <rect id="building6-floor" class="floor" x="-23" y="-58.75" width="46" height="117.5" /> - <path id="building6-outer-wall" class="outer-wall" d=" - M -23 -58.75 h 46 v 117.5 h -46 z - m 19.5 0 v 44 h 26.5 - M -23 26.25 h 46 - m -18.5 0 v -16 - " /> - <path id="building6-inner-wall" class="inner-wall" d=" - M -23 -58.75 h 46 v 117.5 h -46 z - m 19.5 0 v 44 h 26.5 - M -23 26.25 h 46 - m -18.5 0 v -16 - " /> - <path id="building6-windows" class="windows" d=" - M 3.5 -58.75 h 10 - m 9.5 56 v 10.5 - m 0 20.5 v 10.5 - M -23 -31 v 10.5 - m 0 18 v 10.5 - " /> - <path id="building6-door-edges" class="door-edges" d=" - M -23 -46.5 v 10 - m 23.5 21.75 h 16.5 - m -30.75 41 h 10 - m -10 32.5 h 10 - " /> - <path id="building6-door-doors" class="doors" d=" - M -23 -44 v 5 - m 26 24.25 h 11.5 - m -26 41 h 5.5 - m -5 32.5 h 5 - " /> + <rect id="building6-floor" class="floor" width="43.299999" height="120" x="-12.990005" y="-67.5" /> + <path id="building6-outer-wall" class="outer-wall" + d="m 12.99,7.5 v 15 m 17.32,0 h -43.3 m 17.32,-90 v 45 h 25.98 m -43.30001,-45 H 30.31 v 120 h -43.30001 z" /> + <path id="building6-inner-wall" class="inner-wall" + d="m 12.99,7.5 v 15 m 17.32,0 h -43.3 m 17.32,-90 v 45 h 25.98 m -43.30001,-45 H 30.31 v 120 h -43.30001 z" /> </g> <g id="building7" class="building"> diff --git a/src/radial.js b/src/radial.js index 5a8ae5a..9978b14 100644 --- a/src/radial.js +++ b/src/radial.js @@ -77,7 +77,7 @@ function radialToScreenCoords({ q, r, s }) { x = Math.abs(q) + Math.abs(s); x = (q > s ? -1 : 1) * x * horzSpacing; - y = r * vertSpacing; + const y = r * vertSpacing; return { x, y }; } @@ -408,7 +408,7 @@ let mapsheet30 = { { type: 'building4', grid: new Map(buildingHexes.bld4), - position: ({ q, r, s }) => ({ q: q - 9, r: r - 6, s: s + 15 }) + position: reflectR({ q: -10, r: -5, s: 15 }) }, { type: 'building5', @@ -418,7 +418,7 @@ let mapsheet30 = { { type: 'building6', grid: new Map(buildingHexes.bld6), - position: reflectR({ q: 1, r: 6, s: -7 }) + position: reflectR({ q: 0, r: 6, s: -6 }) }, { type: 'building7', @@ -431,10 +431,10 @@ let mapsheet30 = { function reflectR(coords) { return function ({ q, r, s }) { return { - q: -s + coords.q, + q: -q + coords.q, r: -r + coords.r, - s: -q + coords.s, - transform: "scale(1 -1)" + s: -s + coords.s, + transform: "rotate(180)" }; }; } @@ -487,11 +487,20 @@ function drawMapsheet(gameboard, { id, grid, buildings }, { q: pq, r: pr, s: ps const buildingTemplate = document.querySelector(`defs #${building.type}`); const origin = building.position({ q: 0, r: 0, s: 0 }); + const { x: rx, y: ry } = radialToScreenCoords(origin); const { x, y } = radialToScreenCoords({ q: origin.q + pq, r: origin.r + pr, s: origin.s + ps }); + console.log(x, y); + const buildingStructure = document.createElementNS(xmlns, 'g'); buildingStructure.classList.add('structure'); - buildingStructure.setAttributeNS(null, 'transform', `translate(${x}, ${y}) ${origin.transform ? origin.transform : ''}`); + + if (origin.transform) { + buildingStructure.setAttributeNS(null, 'transform', `rotate(180 ${x}, ${y}) translate(${x}, ${y})`); + } else { + buildingStructure.setAttributeNS(null, 'transform', `translate(${x}, ${y})`); + } + buildingContainer.appendChild(buildingStructure); for (let child of buildingTemplate.children) { @@ -568,15 +577,34 @@ function findScalar(arr) { // mapsheet10 = drawMapsheet(gameboard, mapsheet10, { q: -1, r: 0, s: 1 }); -// const sheets = [[mapsheet10]]; +let sheets = []; -// drawHexes(gameboard, buildingHexes.bld7, true); +// sheets = [[mapsheet30]]; + +// drawHexes(gameboard, buildingHexes.bld4, true); +// drawHexes(gameboard, translateCoords(buildingHexes.bld4, reflectR({ q: -9, r: -6, s: 15 })), true); +// drawHexes(gameboard, translateCoords(buildingHexes.bld4, reflectR({ q: 0, r: 0, s: 0 })), true); + +const buildingTemplate = document.querySelector(`defs #building4`); +const { x, y } = radialToScreenCoords({ q: 0, r: 0, s: 0 }); + +const buildingStructure = document.createElementNS(xmlns, 'g'); +buildingStructure.classList.add('structure'); +buildingStructure.classList.add('building'); +buildingStructure.setAttributeNS(null, 'transform', `translate(${x}, ${y}) rotate(180)`); +// gameboard.appendChild(buildingStructure); + +for (let child of buildingTemplate.children) { + const use = document.createElementNS(xmlns, 'use'); + use.setAttributeNS(null, 'href', `#${child.id}`); + child.classList.forEach(className => use.classList.add(className)); + buildingStructure.appendChild(use); +} -// drawHexes(addGroup(gameboard, 'part-1'), bld8, true); -const sheets = [[mapsheet20], [mapsheet30]]; -// const sheets = [[mapsheet2], [mapsheet10], [mapsheet3]]; -// const sheets = [[mapsheet4]]; +sheets = [[mapsheet20], [mapsheet30]]; +// const sheets = [[mapsheet20], [mapsheet10], [mapsheet30]]; +// const sheets = [[mapsheet30]]; // const sheets = [ // [mapsheet2, mapsheet1], |