From b3f902f012e04facad489c613b5c577a1788b570 Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Wed, 10 Jul 2024 17:35:18 -0700
Subject: Build scenarios from scenario files
---
src/modules/scenario.js | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
(limited to 'src/modules')
diff --git a/src/modules/scenario.js b/src/modules/scenario.js
index bde8cf3..c15f500 100644
--- a/src/modules/scenario.js
+++ b/src/modules/scenario.js
@@ -1,3 +1,6 @@
+import counters from './assets/images/counters.svg';
+import mapsheets from './assets/images/mapsheets.svg';
+
async function loadScript(scenario, svg, script) {
return new Promise((resolve, reject) => {
const scriptEl = document.createElementNS("http://www.w3.org/2000/svg", 'script');
@@ -54,6 +57,8 @@ export async function build(svg, request) {
const startLocs = scenario.querySelector('.start-locations');
const externalResourceEls = Array.from(scenario.querySelectorAll('use[href*=".svg"'));
+ scenario.querySelectorAll('defs > *').forEach(el => defs.append(svg.ownerDocument.importNode(el, true)));
+
const refs = externalResourceEls.reduce((acc, el) => {
const href = el.getAttributeNS(null, 'href');
const [filename] = href.match(/.+\.svg/);
@@ -65,8 +70,16 @@ export async function build(svg, request) {
return acc;
}, {});
+ console.log('refs', refs);
+ console.log(counters.split('/').pop().split('-').shift());
+
+ const hashedFilenames = {
+ 'counters.svg': counters,
+ 'mapsheets.svg': mapsheets
+ }
+
await Promise.all(
- Object.keys(refs).map(filename => requestResource(`assets/images/${filename}`))
+ Object.keys(refs).map(filename => requestResource(hashedFilenames[filename]))
).then(result => {
Object.keys(refs).forEach((filename, index) => {
const external = result[index];
@@ -85,11 +98,14 @@ export async function build(svg, request) {
});
});
- scenario.querySelectorAll('use.mapsheet').forEach(el =>
- gb.querySelector('#background').after(svg.ownerDocument.importNode(el, true))
- );
+ // scenario.querySelectorAll('use.mapsheet').forEach(el =>
+ // gb.querySelector('#background').after(svg.ownerDocument.importNode(el, true))
+ //);
+
+ // startLocs.querySelectorAll('.counter').forEach(el => console.log(el));
+ //console.log(startLocs);
- if (startLocs) grid.before(svg.ownerDocument.importNode(startLocs, true));
+ //if (startLocs) grid.before(svg.ownerDocument.importNode(startLocs, true));
const scenarioGrid = scenario.querySelector('.grid');
@@ -97,7 +113,7 @@ export async function build(svg, request) {
grid.replaceWith(svg.ownerDocument.importNode(scenarioGrid, true));
}
- defs.replaceWith(scenario.querySelector('defs'));
+ //defs.replaceWith(scenario.querySelector('defs'));
await loadScript(scenario, svg, 'radial')
return loadScript(scenario, svg, 'map');
--
cgit v1.2.3