From c148f4a4f329decec4602a48a8a71a62b429bfb4 Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Thu, 27 Jun 2024 12:48:06 -0700
Subject: WIP: render radial coord hexes/maps
---
src/modules/scenario.js | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
(limited to 'src/modules/scenario.js')
diff --git a/src/modules/scenario.js b/src/modules/scenario.js
index 2483bc2..8b466cb 100644
--- a/src/modules/scenario.js
+++ b/src/modules/scenario.js
@@ -1,4 +1,4 @@
-async function loadScript(scenario, svg) {
+async function loadScript(scenario, svg, script) {
return new Promise((resolve, reject) => {
const scriptEl = document.createElementNS("http://www.w3.org/2000/svg", 'script');
@@ -11,14 +11,15 @@ async function loadScript(scenario, svg) {
reject(Error('Script failed to load.'));
};
- const dataset = scenario.querySelector('script').dataset;
+ const dataset = scenario.querySelector('script')?.dataset || {};
if ('cols' in dataset && 'rows' in dataset) {
scriptEl.dataset.rows = dataset.rows;
scriptEl.dataset.cols = dataset.cols;
}
- scriptEl.setAttributeNS(null, 'href', '../../map.js');
+ // scriptEl.setAttributeNS(null, 'href', '../../map.js');
+ scriptEl.setAttributeNS(null, 'href', `../../${script}.js`);
svg.append(scriptEl);
});
}
@@ -46,6 +47,7 @@ export async function requestResource(url) {
}
export async function build(svg, request) {
+ const defs = svg.querySelector('defs');
const gb = svg.querySelector('.gameboard');
const grid = svg.querySelector('.grid');
@@ -67,8 +69,6 @@ export async function build(svg, request) {
await Promise.all(
Object.keys(refs).map(filename => requestResource(`assets/images/${filename}`))
).then(result => {
- const defs = svg.querySelector('defs');
-
Object.keys(refs).forEach((filename, index) => {
const external = result[index];
@@ -98,5 +98,8 @@ export async function build(svg, request) {
grid.replaceWith(svg.ownerDocument.importNode(scenarioGrid, true));
}
- return loadScript(scenario, svg);
+ defs.replaceWith(scenario.querySelector('defs'));
+
+ await loadScript(scenario, svg, 'radial')
+ return loadScript(scenario, svg, 'map');
}
--
cgit v1.2.3