Web Dev Solutions

Catalin Mititiuc

From 7364c01efe774b4f48a3f6c32a2648dab028b6b4 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Thu, 27 Jun 2024 19:52:12 -0700 Subject: Put grid cells above buildings --- public/assets/css/map.css | 2 +- public/assets/css/radial.css | 78 +++++++++----------------------------------- src/radial.js | 44 +++++++++++++++++++------ 3 files changed, 51 insertions(+), 73 deletions(-) diff --git a/public/assets/css/map.css b/public/assets/css/map.css index c781cf5..38d8f23 100644 --- a/public/assets/css/map.css +++ b/public/assets/css/map.css @@ -15,7 +15,7 @@ text { } use[href="#hex"] { - opacity: 0; + opacity: 0.25; fill: transparent; fill-opacity: 0.5; stroke-width: 0.5px; diff --git a/public/assets/css/radial.css b/public/assets/css/radial.css index 198c7d9..2f03cb2 100644 --- a/public/assets/css/radial.css +++ b/public/assets/css/radial.css @@ -68,78 +68,37 @@ use[href="#hex"] { stroke-linecap: square; } -.elevation-basement { - fill: lightgray; +.building [class*="elevation"] { display: none; } -.elevation-0 use[href="#hex"] { - /* fill: green; */ -} - -.elevation-1, -.elevation-2 { +[data-view-elevation="-1"] .building .elevation-basement { display: inline; } -.elevation-1 use[href="#hex"] { - fill: lightblue; -} - -.elevation-2 use[href="#hex"] { - fill: lightpink; -} - -.building .elevation-1 { - fill: lightblue; -} - -.elevation-roof { - display: none; -} - -.building .elevation-basement use { - fill: lightgray; -} - -.building .elevation-0 use { - fill: white; -} - -.building .elevation-1 use { - fill: lightblue; -} - -.building .elevation-2 use { - fill: lightgreen; -} - -.building .elevation-3 use { - fill: lightpink; -} - -.view-elevation-roof .floor { - fill: darkgray; +[data-view-elevation="0"] .building .elevation-0 { + display: inline; } -.building .elevation-1 { - display: none; +[data-view-elevation="1"] .building .elevation-1 { + display: inline; } -.building > * { - display: none; +[data-view-elevation="2"] .building .elevation-2 { + display: inline; } -[data-view-elevation="-1"] [class^="elevation"] { - display: none; +[data-view-elevation="3"] .building .elevation-3 { + display: inline; } +/* [data-view-elevation="-1"] .building > *, [data-view-elevation="-1"] .building > .structure > * { display: none; -} +} */ -[data-view-elevation="-1"] .building > .elevation-basement, +/* [data-view-elevation="-1"] .building > .elevation-basement, [data-view-elevation="-1"] .building > .elevation-basement ~ .structure, [data-view-elevation="-1"] .building > .elevation-basement ~ .structure [class*="wall"], [data-view-elevation="-1"] .building > .elevation-basement ~ .structure .floor, @@ -147,9 +106,9 @@ use[href="#hex"] { [data-view-elevation="-1"] .building > .elevation-basement ~ .structure .door-edges:not(.exits), [data-view-elevation="-1"] .building > .elevation-basement ~ .structure .furniture { display: inline; -} +} */ -[data-view-elevation="0"] .building .elevation-0, +/* [data-view-elevation="0"] .building .elevation-0, [data-view-elevation="0"] .building .elevation-0 ~ .structure { display: inline; } @@ -219,12 +178,7 @@ use[href="#hex"] { [data-view-elevation="1"] .building .elevation-1 { display: inline; -} - -.building [class*="elevation"] use { - /* fill-opacity: 0.33; */ - stroke: black; -} +} */ #tree .trunk { fill: brown; diff --git a/src/radial.js b/src/radial.js index a2be440..6177a65 100644 --- a/src/radial.js +++ b/src/radial.js @@ -405,6 +405,15 @@ function drawBuildings(buildings, container, { q: pq, r: pr, s: ps }, furniture) let buildingGrid = translateCoords(building.grid, building.position); buildingGrid = translateCoords(buildingGrid, ({ q, r, s }) => ({ q: q + pq, r: r + pr, s: s + ps })); + const buildingTemplate = document.querySelector(`defs #${building.type}`); + const origin = building.position({ q: 0, r: 0, s: 0 }); + const { x, y } = radialToScreenCoords({ q: origin.q + pq, r: origin.r + pr, s: origin.s + ps }); + const transform = origin.transform || ((x, y) => `translate(${x}, ${y})`); + const buildingStructure = document.createElementNS(xmlns, 'g'); + buildingStructure.classList.add('structure'); + buildingStructure.setAttributeNS(null, 'transform', transform(x, y)); + buildingContainer.appendChild(buildingStructure); + building.elevationLevels.forEach(elevationLevel => { const hexContainer = document.createElementNS(xmlns, 'g'); hexContainer.classList.add(`elevation-${elevationLevel === -1 ? 'basement' : elevationLevel}`); @@ -415,24 +424,39 @@ function drawBuildings(buildings, container, { q: pq, r: pr, s: ps }, furniture) acc = new Map([...acc, ...buildingGrid]); }); - const buildingTemplate = document.querySelector(`defs #${building.type}`); - const origin = building.position({ q: 0, r: 0, s: 0 }); - const { x, y } = radialToScreenCoords({ q: origin.q + pq, r: origin.r + pr, s: origin.s + ps }); - const transform = origin.transform || ((x, y) => `translate(${x}, ${y})`); - const buildingStructure = document.createElementNS(xmlns, 'g'); - buildingStructure.classList.add('structure'); - buildingStructure.setAttributeNS(null, 'transform', transform(x, y)); - buildingContainer.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)); + + if (use.classList.contains('floor')) + building.elevationLevels.forEach(el => use.classList.add(`elevation-${el === -1 ? 'basement' : el}`)); + + if (use.classList.contains('outer-wall') || use.classList.contains('inner-wall')) + building.elevationLevels.slice(0, -1).forEach(el => use.classList.add(`elevation-${el === -1 ? 'basement' : el}`)); + + if (use.classList.contains('windows')) + building.elevationLevels.slice(0, -1).filter(el => el >= 0).forEach(el => use.classList.add(`elevation-${el}`)); + + if (use.classList.contains('exits')) use.classList.add(`elevation-0`); + + if ((use.classList.contains('doors') || use.classList.contains('door-edges')) && !use.classList.contains('exits')) + building.elevationLevels.slice(0, -1).forEach(el => use.classList.add(`elevation-${el === -1 ? 'basement' : el}`)); + + if (use.classList.contains('furniture')) + building.elevationLevels.slice(0, -1).forEach(el => use.classList.add(`elevation-${el === -1 ? 'basement' : el}`)); + buildingStructure.appendChild(use); } const furnitureEl = furniture && furniture.querySelector(`.${building.type} .furniture`); - if (furnitureEl) buildingStructure.appendChild(furnitureEl); + + if (furnitureEl) { + for (let child of furnitureEl.children) { + (child.classList.contains('stairs') ? building.elevationLevels : building.elevationLevels.slice(0, -1)).forEach(el => child.classList.add(`elevation-${el === -1 ? 'basement' : el}`)); + } + buildingStructure.appendChild(furnitureEl); + } return acc; }, new Map()); -- cgit v1.2.3