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-07-16 14:05:08 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-07-16 14:05:11 -0700 |
commit | 3f24534eb775fa26df35a2fbeb909aef3480317f (patch) | |
tree | f5648b8ba8f61194e96f63b6bad9448778ad226d /src/modules/gameboard.js | |
parent | 5ea152f4f6419e77f5d1bf76fb4c15a883376700 (diff) |
WIP: Turn/torso-twist mech template on keypress
Diffstat (limited to 'src/modules/gameboard.js')
-rw-r--r-- | src/modules/gameboard.js | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/src/modules/gameboard.js b/src/modules/gameboard.js index 65c4bb1..d35b2b9 100644 --- a/src/modules/gameboard.js +++ b/src/modules/gameboard.js @@ -38,6 +38,10 @@ function isGrenade(el) { return el && el.getAttribute('href') === '#counter-grenade'; } +function isMechTemplate(el) { + return el && el.getAttribute('class') === 'mech-template'; +} + function isClone(counter) { const isClone = counter.classList.contains('clone'), { allegiance: clAl, number: clNum } = counter.dataset; @@ -203,8 +207,9 @@ export function start(el) { const occupant = getCellOccupant(cell); let toPlace = placing.pop(); - if (isGrenade(toPlace)) { + if (isGrenade(toPlace) || isMechTemplate(toPlace)) { getHex(cell).after(toPlace); + removeEventListener("keydown", handleMechTemplateRotation); } else if (toPlace && !occupant) { soldier.place(svg, toPlace, cell); toPlace.removeEventListener('click', selectOffBoard); @@ -266,6 +271,10 @@ export function start(el) { cell.addEventListener('pointerover', () => { const selected = getSelected(); + if (placing[0]?.getAttributeNS(null, 'class') == 'mech-template') { + cell.appendChild(placing[0]); + } + if (selected && svg.querySelector('.grid').contains(selected) && !getLockedSightLine(svg) && cell !== selected.parentElement) { clearSightLine(); drawSightLine(selected.parentElement, cell); @@ -442,3 +451,46 @@ export function setGrenade() { placing.push(counter); } + +function handleMechTemplateRotation(event) { + const counter = placing[0]; + const upper = placing[0].querySelector('use[href="#mech-template-upper"]'); + + if (event.key === 'a') { + let direction = +counter.style.transform.match(/-?\d+/) || 0; + direction -= 60; + counter.style.transform = `rotate(${direction}deg)`; + } else if (event.key === 'd') { + let direction = +counter.style.transform.match(/-?\d+/) || 0; + direction += 60; + counter.style.transform = `rotate(${direction}deg)`; + } else if (event.key === 'q') { + let facing = +upper.style.transform.match(/-?\d+/) || 0; + facing = facing <= -60 ? -60 : facing - 60; + upper.style.transform = `rotate(${facing}deg)`; + } else if (event.key === 'e') { + let facing = +upper.style.transform.match(/-?\d+/) || 0; + facing = facing >= 60 ? 60 : facing + 60; + upper.style.transform = `rotate(${facing}deg)`; + } +} + +export function setMechTemplate() { + const counter = document.createElementNS(svgns, 'g'); + counter.setAttributeNS(null, 'class', 'mech-template'); + counter.style.pointerEvents = 'none'; + counter.style.transition = 'transform 0.5s'; + + const lower = document.createElementNS(svgns, 'use'); + lower.setAttributeNS(null, 'href', '#mech-template-lower'); + + const upper = document.createElementNS(svgns, 'use'); + upper.setAttributeNS(null, 'href', '#mech-template-upper'); + upper.style.transition = 'transform 0.5s'; + + counter.appendChild(lower); + counter.appendChild(upper); + + addEventListener("keydown", handleMechTemplateRotation); + placing.push(counter); +} |