index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2024-07-10 19:29:38 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-07-10 19:29:38 -0700 |
commit | 17118633340b1979e94f30d0c85b885d5237ba14 (patch) | |
tree | 11b87ffb5b7e872088d9a67c84889aabc7c930c5 /src/index.js | |
parent | b3f902f012e04facad489c613b5c577a1788b570 (diff) |
Clone template instead of modifying original
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/index.js b/src/index.js index e6efe5f..84f8dd4 100644 --- a/src/index.js +++ b/src/index.js @@ -35,6 +35,12 @@ const mapPlaceholder = document.querySelector('.map-placeholder'), 6: 'six' }, + attrNames = { + 'primary-weapon': 'weapon', + 'troop-number': 'number', + 'squad-number': 'squad' + }, + toggleContentVis = (function () { document.querySelector('#content').style.minWidth = this.checked ? '' : 0; @@ -55,19 +61,12 @@ async function buildScenario(req) { gameboard.stop(); recordSheet.stop(); - // const svg = scenarioTemplate.querySelector('svg').cloneNode(true); - - const svg = document.querySelector('object').contentDocument.querySelector('svg'); + const map = document.querySelector('object').contentDocument.querySelector('svg'); + const template = scenarioTemplate.querySelector('svg').cloneNode(true); + map.replaceWith(template); - await build(svg, req); + await build(template, req); const scenario = await req; - - const attrNames = { - 'primary-weapon': 'weapon', - 'troop-number': 'number', - 'squad-number': 'squad' - }; - const scenarioUnits = scenario.querySelectorAll('svg g.counter'); scenarioUnits.forEach(cntr => { @@ -81,8 +80,8 @@ async function buildScenario(req) { mapResourceEl.style.opacity = 1; mapPlaceholder.style.opacity = 0; - panzoom.start(svg); - gameboard.start(svg); + panzoom.start(template); + gameboard.start(template); // recordSheet.start(svg.querySelector('.start-locations'), gameboard.getUnits()); recordSheet.start(null, scenarioUnits); |