index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/modules/scenario.js')
-rw-r--r-- | src/modules/scenario.js | 15 |
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'); } |