From ddd32d47c5210eeda6209c6caa36a426a668cc21 Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Thu, 2 May 2024 16:58:00 -0700
Subject: Generate weapon data dynamically from counters
---
src/modules/record_sheet.js | 36 ++++++++++++++++++++++++++++++------
1 file changed, 30 insertions(+), 6 deletions(-)
(limited to 'src/modules/record_sheet.js')
diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js
index 6909249..4d8aada 100644
--- a/src/modules/record_sheet.js
+++ b/src/modules/record_sheet.js
@@ -1,3 +1,24 @@
+const weapons = {
+ rifle: {
+ name: 'Rifle',
+ damage: '4L',
+ shortRange: '1-27',
+ longRange: '28-75'
+ },
+ smg: {
+ name: 'SMG',
+ damage: '3L',
+ shortRange: '1-15',
+ longRange: '16-25'
+ },
+ blazer: {
+ name: 'Blazer',
+ damage: '4L',
+ shortRange: '1-17',
+ longRange: '18-105'
+ }
+}
+
function createIcon(number) {
const svgns = 'http://www.w3.org/2000/svg';
const [icon, circle, text] = ['svg', 'circle', 'text'].map(t => document.createElementNS(svgns, t));
@@ -17,8 +38,11 @@ function createIcon(number) {
return icon;
}
-function createRecord({ dataset: { allegiance, number }}) {
- const div = document.createElement('div', { is: 'soldier-record-block' }),
+function createRecord(unit) {
+ const { dataset: { allegiance, number }} = unit,
+ primaryWeapon = unit.querySelector('.primary-weapon'),
+ pw = primaryWeapon.getAttribute('href').replace('#', ''),
+ div = document.createElement('div', { is: 'soldier-record-block' }),
spans = Array(5).fill('span').map(t => document.createElement(t)),
[tn, pwt, pwd, pwrs, pwrl] = spans;
@@ -30,16 +54,16 @@ function createRecord({ dataset: { allegiance, number }}) {
tn.appendChild(createIcon(number));
pwt.setAttribute('slot', 'primary-weapon-type');
- pwt.textContent = 'Rifle';
+ pwt.textContent = weapons[pw].name;
pwd.setAttribute('slot', 'primary-weapon-damage');
- pwd.textContent = '4L';
+ pwd.textContent = weapons[pw].damage;
pwrs.setAttribute('slot', 'primary-weapon-range-short');
- pwrs.textContent = '1-27';
+ pwrs.textContent = weapons[pw].shortRange;
pwrl.setAttribute('slot', 'primary-weapon-range-long');
- pwrl.textContent = '28-75';
+ pwrl.textContent = weapons[pw].longRange;
spans.forEach(el => div.appendChild(el));
--
cgit v1.2.3