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-05-04 10:25:22 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2024-05-04 10:25:22 -0700 |
commit | f021368a6697c6b064aa8da208cdf60265f4bfe0 (patch) | |
tree | 57a4f8aa011d893004accc1a5043c5e154780d8f /src/index.js | |
parent | 3049acbe1599e6665fd6ee48496048493349bf97 (diff) |
WIP: add fullscreen and download save abilities
Diffstat (limited to 'src/index.js')
-rw-r--r-- | src/index.js | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/index.js b/src/index.js index 1f8f2c1..91809c3 100644 --- a/src/index.js +++ b/src/index.js @@ -10,7 +10,8 @@ const mapPlaceholder = document.querySelector('.map-placeholder'), proneToggle = document.getElementById('toggle-prone-counter'), contentVisToggleEl = document.querySelector('#content input[type="checkbox"].visible'), object = document.querySelector('object'), - fileName = `assets/images/${localStorage.getItem('map') || 'map1'}.svg`, + fileName = localStorage.getItem('map') || (env === 'test' ? 'test_map' : 'map1'), + map = `assets/images/${fileName}.svg`, toggleContentVis = (function () { document.querySelectorAll('#content div').forEach(div => { @@ -118,6 +119,14 @@ document.querySelectorAll('.end-move').forEach(el => el.addEventListener('click' gameboard.endMove(); })); +document.querySelector('#fullscreen').addEventListener('click', e => { + if (!document.fullscreenElement) { + document.documentElement.requestFullscreen(); + } else if (document.exitFullscreen) { + document.exitFullscreen(); + } +}); + contentVisToggleEl.checked = (localStorage.getItem('content-visibility') !== 'false'); toggleContentVis(); @@ -129,8 +138,18 @@ mapSelectDialog .changeMapOnConfirm(); object.addEventListener('load', load); +object.data = map; objectDataObserver.observe(object, { attributeFilter: ['data'] }); -if (object.getAttribute('data') !== fileName) { - object.data = fileName; -} +document.querySelector('#download-save').addEventListener('click', e => { + const data = object.contentDocument.documentElement.outerHTML; + const element = document.createElement('a'); + + element.setAttribute('download', 'save.svg'); + element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(data)); + element.style.display = 'none'; + + document.body.appendChild(element); + element.click(); + document.body.removeChild(element); +}); |