Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/scenario.js')
-rw-r--r--src/modules/scenario.js28
1 files changed, 22 insertions, 6 deletions
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');