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-07 11:03:14 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-08-07 11:03:14 -0700 |
commit | 39c939ebaf2683b4167ab65eb9cfdc202f90a35e (patch) | |
tree | 8ef4520b499ead1fcda3c8b180ffd28586ed95bd | |
parent | 0ff2d23093beeee00fc0d0ebec50c943c1cc8873 (diff) |
Extract reveal record logic into a function
-rw-r--r-- | src/modules/record_sheet.js | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/modules/record_sheet.js b/src/modules/record_sheet.js index 841a693..8caf395 100644 --- a/src/modules/record_sheet.js +++ b/src/modules/record_sheet.js @@ -252,14 +252,7 @@ function clear() { //document.querySelector('#defender-record .name').textContent = 'defender'; } -function select(data) { - const record = data && getRecord(data); - const isSelected = record?.classList.contains('selected'); - - deselect(); - - if (isSelected || !data) return; - +function reveal(record) { const currentSquadView = document.querySelector(`#record-sheet #${record.dataset.allegiance}-record .records-header .squad-number text`); const records = document.querySelector(`#record-sheet #${record.dataset.allegiance}-record .records`); const target = records.querySelector(`.squad-${record.dataset.squad}`); @@ -302,10 +295,20 @@ function select(data) { if (currentSquad !== target) showSquad(currentSquad, target, direction); - else { - record.classList.add('selected'); + else record.scrollIntoView({ behavior: 'smooth' }); - } +} + +function select(data) { + const record = data && getRecord(data); + const isSelected = record?.classList.contains('selected'); + + deselect(); + + if (isSelected || !data) return; + + reveal(record); + record.classList.add('selected'); } function endMove() { |