Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/map.js')
-rw-r--r--src/map.js13
1 files changed, 8 insertions, 5 deletions
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]);