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-09 16:25:27 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-08-09 16:25:27 -0700 |
commit | 518693844d391b5c0753555b6fafe5810c1c9afb (patch) | |
tree | 9d464bd0b647980723de9e073d4471895ebaf7de | |
parent | b14c070373dadc8a16afec7a0797a53c9515ccc2 (diff) |
Fix squad reveal/select bug
-rw-r--r-- | src/modules/record_sheet.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js index fb0b037..81add27 100644 --- a/src/modules/record_sheet.js +++ b/src/modules/record_sheet.js @@ -293,14 +293,6 @@ function getRecord({ dataset: { allegiance: al, number: n, squad: s }}) { return document.querySelector(selector); } -function deselect() { - const selected = getSelected(); - - if (selected) { - selected.classList.remove('selected'); - } -} - function clear() { document.querySelectorAll('#record-sheet > *').forEach(el => { //el.querySelectorAll('.squad-number').forEach(sn => sn.remove()); @@ -338,13 +330,13 @@ function reveal(record) { // transformation. ScrollTo seems to create enough delay. toSquad.style.display = 'block'; records.scrollTo(0, 0); + if (toSquad[`${direction}ElementSibling`] && toSquad !== target) { showSquad(toSquad, target, direction); } else { toSquad.style.transform = 'translateX(0)'; toSquad.addEventListener('transitionend', e => { - record.classList.add('selected'); record.scrollIntoView({ behavior: 'smooth' }); }, { once: true }); } @@ -359,6 +351,12 @@ function reveal(record) { record.scrollIntoView({ behavior: 'smooth' }); } +function deselect() { + const selected = getSelected(); + + if (selected) selected.classList.remove('selected'); +} + function select(data, opts) { const record = data && getRecord(data); const isSelected = record?.classList.contains('selected'); @@ -367,8 +365,8 @@ function select(data, opts) { if (isSelected || !data) return; - if (opts?.revealRecord) reveal(record); record.classList.add('selected'); + if (opts?.revealRecord) reveal(record); } function endMove() { @@ -379,9 +377,11 @@ function endMove() { const index = [...list].findIndex(s => s === selected); const next = list.length > 1 ? list[(index + 1) % list.length] : null; selected.classList.toggle('movement-ended'); - deselect(); - if (next) Observable.notify('select', next, { revealCounter: true, revealRecord: true }); + if (next) + Observable.notify('select', next, { revealCounter: true, revealRecord: true }); + else + deselect(); } } |