Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-07-10 17:35:18 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-07-10 17:35:18 -0700
commitb3f902f012e04facad489c613b5c577a1788b570 (patch)
treea0dd26414256b88cd800424cc8cee91a918cb34b /src/index.js
parent4cf7aaab807f36721416eedfe5f9fab3f0c55e20 (diff)
Build scenarios from scenario files
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js46
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() {