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-05-29 18:02:18 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-05-29 18:02:18 -0700 |
commit | 187faec2dfb7959c536d6847a61be912cff9275e (patch) | |
tree | 2875104e6f5c33912dd6cfffb0c36d2982d702ad /src | |
parent | fdf9e0145ee14d4db7004c56d0e5b15cb3461e2d (diff) |
Try to simplify trooper counter
Diffstat (limited to 'src')
-rw-r--r-- | src/import_external_resources.js | 15 | ||||
-rw-r--r-- | src/import_mapsheets.js | 8 | ||||
-rw-r--r-- | src/modules/record_sheet.js | 5 |
3 files changed, 18 insertions, 10 deletions
diff --git a/src/import_external_resources.js b/src/import_external_resources.js new file mode 100644 index 0000000..aba29d2 --- /dev/null +++ b/src/import_external_resources.js @@ -0,0 +1,15 @@ +import mapsheets from './assets/images/mapsheets.svg'; +import counters from './assets/images/counters.svg'; + +const files = { + 'mapsheets.svg': mapsheets, + 'counters.svg': counters +} + +document.querySelectorAll('use[data-href*=".svg"').forEach(el => { + const [filename] = el.dataset.href.match(/.+\.svg/g) + , href = el.dataset.href.replace(filename, files[filename].split('/').pop()) + ; + + el.setAttributeNS(null, 'href', href); +}); diff --git a/src/import_mapsheets.js b/src/import_mapsheets.js deleted file mode 100644 index 2e1b0fc..0000000 --- a/src/import_mapsheets.js +++ /dev/null @@ -1,8 +0,0 @@ -import mapsheets from './assets/images/mapsheets.svg'; - -const useEls = document.querySelectorAll('svg use[data-href*="mapsheets.svg"'); - -useEls.forEach(el => { - const href = el.dataset.href.replace('mapsheets.svg', mapsheets.split('/').pop()); - el.setAttributeNS(null, 'href', href); -}); diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js index 2865309..33a21fe 100644 --- a/src/modules/record_sheet.js +++ b/src/modules/record_sheet.js @@ -81,12 +81,13 @@ function createWeaponIcon(type) { function createRecord(unit) { const { dataset: { allegiance, number, squad }} = unit, primaryWeapon = unit.querySelector('.primary-weapon'), - pw = primaryWeapon?.getAttribute('href').replace('#', '') || 'rifle', + pw = primaryWeapon.getAttributeNS(null, 'href').split('#').pop() || 'rifle', div = document.createElement('div', { is: 'soldier-record-block' }), spans = Array(6).fill('span').map(t => document.createElement(t)), [tn, sn, pwt, pwd, pwrs, pwrl] = spans; - div.setAttribute('class', 'soldier-record'); + div.classList.add('soldier-record'); + if (unit.classList.contains('selected')) div.classList.add('selected'); div.dataset.number = number; div.dataset.allegiance = allegiance; |