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/index.js')
-rw-r--r-- | src/index.js | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/index.js b/src/index.js index 98a3c1b..e6efe5f 100644 --- a/src/index.js +++ b/src/index.js @@ -19,12 +19,12 @@ const mapPlaceholder = document.querySelector('.map-placeholder'), proneToggle = document.getElementById('toggle-prone-counter'), contentVisToggleEl = document.querySelector('#edge-inputs input[type="checkbox"].visible'), // fileName = localStorage.getItem('map') || 'scenario-side_show', - fileName = localStorage.getItem('map') || 'radial', + fileName = localStorage.getItem('map') || 'scenario-side_show', map = scenarios[fileName]?.hashed || `assets/images/${fileName}.svg`, + scenarioRequest = requestResource(map), fileInputEl = document.querySelector('input[type="file"]'), dice = document.querySelectorAll('.die'), mapResourceEl = document.querySelector('object'), - scenarioRequest = requestResource(map), d6 = { 1: 'one', @@ -55,10 +55,28 @@ async function buildScenario(req) { gameboard.stop(); recordSheet.stop(); - const svg = scenarioTemplate.querySelector('svg').cloneNode(true); - document.querySelector('object').contentDocument.querySelector('svg').replaceWith(svg); + // const svg = scenarioTemplate.querySelector('svg').cloneNode(true); + + const svg = document.querySelector('object').contentDocument.querySelector('svg'); await build(svg, 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 => { + cntr.querySelectorAll('use').forEach(use => { + const [attr] = use.classList; + const val = use.getAttributeNS(null, 'href').split('#').pop().split('-').pop(); + cntr.setAttributeNS(null, `data-${attrNames[attr]}`, val); + }); + }); mapResourceEl.style.opacity = 1; mapPlaceholder.style.opacity = 0; @@ -67,25 +85,7 @@ async function buildScenario(req) { gameboard.start(svg); // recordSheet.start(svg.querySelector('.start-locations'), gameboard.getUnits()); - const units = [ - { dataset: { allegiance: 'attacker', number: 1, squad: 1, weapon: 'blazer' }}, - { dataset: { allegiance: 'attacker', number: 2, squad: 1, weapon: 'rifle' }}, - { dataset: { allegiance: 'attacker', number: 3, squad: 1, weapon: 'rifle' }}, - { dataset: { allegiance: 'attacker', number: 4, squad: 1, weapon: 'smg' }}, - { dataset: { allegiance: 'attacker', number: 5, squad: 1, weapon: 'smg' }}, - { dataset: { allegiance: 'attacker', number: 6, squad: 1, weapon: 'smg' }}, - { dataset: { allegiance: 'attacker', number: 7, squad: 1, weapon: 'smg' }}, - - { dataset: { allegiance: 'defender', number: 1, squad: 1, weapon: 'blazer' }}, - { dataset: { allegiance: 'defender', number: 2, squad: 1, weapon: 'rifle' }}, - { dataset: { allegiance: 'defender', number: 3, squad: 1, weapon: 'rifle' }}, - { dataset: { allegiance: 'defender', number: 4, squad: 1, weapon: 'smg' }}, - { dataset: { allegiance: 'defender', number: 5, squad: 1, weapon: 'smg' }}, - { dataset: { allegiance: 'defender', number: 6, squad: 1, weapon: 'smg' }}, - { dataset: { allegiance: 'defender', number: 7, squad: 1, weapon: 'smg' }}, - ] - - recordSheet.start(null, units); + recordSheet.start(null, scenarioUnits); } function updateTurnCounter() { |