Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/map.css2
-rw-r--r--public/map1.svg3
-rw-r--r--src/map.js13
-rw-r--r--src/modules/game/soldier.js2
-rw-r--r--src/modules/gameboard.js2
5 files changed, 13 insertions, 9 deletions
diff --git a/public/map.css b/public/map.css
index a53359c..1a57998 100644
--- a/public/map.css
+++ b/public/map.css
@@ -199,7 +199,7 @@ g.selected use {
fill: red;
}
-.board, .gameboard {
+.gameboard {
transform: translate(19px, 31px) scale(4);
}
diff --git a/public/map1.svg b/public/map1.svg
index 99f6e95..efae907 100644
--- a/public/map1.svg
+++ b/public/map1.svg
@@ -45,7 +45,7 @@
<image id="map3" class="map-scans" href="scans/map3.jpg" width="2284" height="1518"/>
</g>
- <g class="board">
+ <g class="gameboard">
<g id="firing-arcs">
<g id="shapes"/>
<g id="lines"/>
@@ -1858,4 +1858,5 @@
</g>
</g>
</g>
+ <script href="map.js"></script>
</svg>
diff --git a/src/map.js b/src/map.js
index 7a04626..06b6ce6 100644
--- a/src/map.js
+++ b/src/map.js
@@ -1,18 +1,21 @@
const svgns = "http://www.w3.org/2000/svg";
+const dataset = document.currentScript.dataset;
const svg = document.querySelector('svg');
-const cellTemplate = svg.querySelector('#hex');
const gb = svg.querySelector('.gameboard');
const bg = svg.querySelector('#background');
const imageMaps = svg.querySelector('#image-maps');
-const grid = gb.querySelector('.grid');
-const dataset = document.currentScript.dataset;
+
if ('cols' in dataset && 'rows' in dataset) {
+ const cellTemplate = svg.querySelector('#hex');
+ const grid = gb.querySelector('.grid');
+
createCells(grid, dataset, cellTemplate.id);
- setElAttrs(bg, calcComputedBboxFor(imageMaps));
- svg.setAttribute('viewBox', formatForViewBox(calcComputedBboxFor(gb)));
}
+setElAttrs(bg, calcComputedBboxFor(imageMaps));
+svg.setAttribute('viewBox', formatForViewBox(calcComputedBboxFor(gb)));
+
function setElAttrs(el, attrs) {
for (key in attrs) {
el.setAttributeNS(null, key, attrs[key]);
diff --git a/src/modules/game/soldier.js b/src/modules/game/soldier.js
index 0d75fc6..922faca 100644
--- a/src/modules/game/soldier.js
+++ b/src/modules/game/soldier.js
@@ -77,7 +77,7 @@ export function place(svg, selected, cell) {
trace.dataset.allegiance = selected.dataset.allegiance;
trace.classList.add('move-trace');
- svg.querySelector('.board').prepend(trace);
+ svg.querySelector('.gameboard').prepend(trace);
} else {
points = `${trace.getAttribute('points')} ${current.x},${current.y}`;
}
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js
index 7623a31..9d054d0 100644
--- a/src/modules/gameboard.js
+++ b/src/modules/gameboard.js
@@ -105,7 +105,7 @@ function drawSightLine(sourceCell, targetCell) {
const hexes = svg.querySelectorAll(selector);
sightLine.setHexes(hexes);
const line = sightLine.create(getCellPosition(sourceCell), getCellPosition(targetCell));
- svg.querySelector('.board').appendChild(line);
+ svg.querySelector('.gameboard').appendChild(line);
distanceCallback && distanceCallback(hexes.length - 1);
}