WIP: add fullscreen and download save abilities

This commit is contained in:
2025-06-16 22:41:30 -07:00
parent 2c18004cde
commit 73cbf3e6dd
6 changed files with 70 additions and 9 deletions

View File

@@ -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);
});