Simplify loading scenarios

This commit is contained in:
2025-06-16 22:41:30 -07:00
parent 33c43c3914
commit e4c1aaaf4f
2 changed files with 17 additions and 21 deletions

View File

@@ -24,25 +24,22 @@ const mapPlaceholder = document.querySelector('.map-placeholder'),
});
localStorage.setItem('content-visibility', this.checked);
}).bind(contentVisToggleEl),
mapResourceObserver = new MutationObserver(function () {
const current = document.querySelector('object');
const resource = current.getAttribute('data');
const next = document.createElement('object');
next.setAttribute('type', 'image/svg+xml');
next.style.opacity = 0;
next.addEventListener('load', load);
mapPlaceholder.after(next);
mapPlaceholder.style.opacity = 1;
next.data = resource;
this.disconnect();
current.remove();
this.observe(next, { attributeFilter: ['data'] });
});
}).bind(contentVisToggleEl);
let mapResourceEl = document.querySelector('object');
function loadScenario(data) {
const current = document.querySelector('object');
const next = document.createElement('object');
next.setAttribute('type', 'image/svg+xml');
next.style.opacity = 0;
next.addEventListener('load', load);
mapPlaceholder.after(next);
mapPlaceholder.style.opacity = 1;
next.data = data;
current.remove();
}
function updateTurnCounter() {
const turnCounter = document.getElementById('turn-count');
@@ -161,11 +158,10 @@ mapSelectDialog
.selectCurrentOptionOnPageLoad()
.showOnClick()
.updateValueOnSelection()
.changeMapOnConfirm();
.changeMapOnConfirm(loadScenario);
mapResourceEl.addEventListener('load', load);
mapResourceEl.data = map;
mapResourceObserver.observe(mapResourceEl, { attributeFilter: ['data'] });
mapResourceEl = null;
document.querySelector('#download-save').addEventListener('click', e => {
@@ -187,5 +183,5 @@ document.querySelector('#upload-save').addEventListener('click', () => {
document.querySelector('input[type="file"]').addEventListener('change', e => {
const [file] = fileInputEl.files;
document.querySelector('object').data = URL.createObjectURL(file);
loadScenario(URL.createObjectURL(file))
});