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-08-06 19:51:22 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-08-06 19:51:22 -0700 |
commit | 0783d703c1365f3307cb9e780b81f5ef19387bac (patch) | |
tree | 33759472ca73cc062cedce6430fb7540bc68c040 /src/modules/record_sheet.js | |
parent | c6cdbcf492a1830bcc16259d018980072485e4fb (diff) |
WIP: very rough armor
Diffstat (limited to 'src/modules/record_sheet.js')
-rw-r--r-- | src/modules/record_sheet.js | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js index e5be4bf..34ffe80 100644 --- a/src/modules/record_sheet.js +++ b/src/modules/record_sheet.js @@ -38,11 +38,17 @@ const weapons = { shortRange: '1-44', longRange: '45-108' }, - gl: { + smggl: { name: 'SMG w/Grenade Launcher', damage: '4/2/1 L', shortRange: '1-10', longRange: '11-24' + }, + riflegl: { + name: 'Rifle w/Grenade Launcher', + damage: '4/2/1 L', + shortRange: '1-10', + longRange: '11-24' } } @@ -121,6 +127,48 @@ function createRecord(unit) { spans.forEach(el => div.appendChild(el)); + if (unit.dataset.armor) { + const s = `damage-block:nth-of-type(n + 1):nth-of-type(-n + ${unit.dataset.armor})`; + const armorBlocks = div.shadowRoot.querySelectorAll(s); + + armorBlocks.forEach(el => { + el.classList.add('armor'); + }); + + const ls = 'damage-block:nth-child(1 of .armor):not(:first-child)'; + const rs = 'damage-block:nth-last-child(1 of .armor):not(:last-child)'; + const moveArmorEl = div.shadowRoot.querySelectorAll(`${ls}, ${rs}`); + + function moveArmorHandler(e) { + e.stopPropagation(); + + this.removeEventListener('click', moveArmorHandler); + if (!this.previousElementSibling.classList.contains('armor')) { + this.previousElementSibling.classList.add('armor'); + this.previousElementSibling.addEventListener('click', moveArmorHandler); + let current = this.nextElementSibling; + while (current.nextElementSibling && current.nextElementSibling.classList.contains('armor')) { + current = current.nextElementSibling; + } + current.classList.remove('armor'); + current.removeEventListener('click', moveArmorHandler); + current.previousElementSibling.addEventListener('click', moveArmorHandler); + } else if (!this.nextElementSibling.classList.contains('armor')) { + this.nextElementSibling.classList.add('armor'); + this.nextElementSibling.addEventListener('click', moveArmorHandler); + let current = this.previousElementSibling; + while (current.previousElementSibling && current.previousElementSibling.classList.contains('armor')) { + current = current.previousElementSibling; + } + current.classList.remove('armor'); + current.removeEventListener('click', moveArmorHandler); + current.nextElementSibling.addEventListener('click', moveArmorHandler); + } + } + + moveArmorEl.forEach(el => el.addEventListener('click', moveArmorHandler)); + } + function makeInactiveDivider(parent) { const div = document.createElement('div'); div.classList.add('inactive-divider'); |