Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCatalin Mititiuc <webdevcat@proton.me>2024-07-02 15:52:38 -0700
committerCatalin Mititiuc <webdevcat@proton.me>2024-07-02 15:52:38 -0700
commit3c0e59f68ee061abc98dafa07301bd54005e94dc (patch)
tree8b8cd84b9ec75b728949cc32948b3a062ea8f309 /src
parent71724cc97967a876224d1a4b711843b17256cb0d (diff)
Create counters with assigned weapons
Diffstat (limited to 'src')
-rw-r--r--src/modules/game/soldier.js6
-rw-r--r--src/modules/record_sheet.js12
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');
}