index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
-rw-r--r-- | src/modules/game/soldier.js | 6 | ||||
-rw-r--r-- | src/modules/record_sheet.js | 12 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/modules/game/soldier.js b/src/modules/game/soldier.js index fc3d113..7a3ffaa 100644 --- a/src/modules/game/soldier.js +++ b/src/modules/game/soldier.js @@ -1,4 +1,5 @@ import counters from './assets/images/counters.svg'; +import { extractWeaponFromRecord, isRecord } from '../record_sheet.js'; const selectedClass = 'selected'; @@ -58,8 +59,11 @@ function createTrace(previous, current, selected) { export function createCounter(selected, weapon = 'rifle') { const use = document.createElementNS(svgns, 'use'); const g = document.createElementNS(svgns, 'g'); - use.setAttributeNS(null, 'href', `../../${counters}#${weapon}`); + const assignedWeapon = isRecord(selected) ? extractWeaponFromRecord(selected) : weapon; + + use.setAttributeNS(null, 'href', `../../${counters}#${assignedWeapon}`); use.classList.add('primary-weapon'); + g.classList.add('counter'); g.dataset.allegiance = selected.dataset.allegiance; g.dataset.number = selected.dataset.number; diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js index 0f279d5..5f14852 100644 --- a/src/modules/record_sheet.js +++ b/src/modules/record_sheet.js @@ -152,6 +152,18 @@ function endMove() { deselect(); } +export function extractWeaponFromRecord(recordEl) { + return recordEl + .querySelector('[slot="primary-weapon-type"] use') + .getAttributeNS(null, 'href') + .split('#') + .pop(); +} + +export function isRecord(el) { + return el.classList && el.classList.contains('soldier-record'); +} + export function getSelected() { return document.querySelector('.soldier-record.selected'); } |