Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-06-27 12:48:06 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-06-27 12:48:06 -0700
commitc148f4a4f329decec4602a48a8a71a62b429bfb4 (patch)
tree5dc552f1bfe34a4369999753b9217d88a10c61e2 /src/modules/scenario.js
parent9c0645b481224bcc777cac58eb2c7ea1592e58e1 (diff)
WIP: render radial coord hexes/maps
Diffstat (limited to 'src/modules/scenario.js')
-rw-r--r--src/modules/scenario.js15
1 files changed, 9 insertions, 6 deletions
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');
}