diff --git a/modules/save-and-load.js b/modules/save-and-load.js index 57fb3c93..42640d8c 100644 --- a/modules/save-and-load.js +++ b/modules/save-and-load.js @@ -102,19 +102,19 @@ function GFontToDataURI(url) { let s = document.createElement('style'); s.innerHTML = text; document.head.appendChild(s); - let styleSheet = Array.prototype.filter.call( - document.styleSheets, - sS => sS.ownerNode === s)[0]; - let FontRule = rule => { - let src = rule.style.getPropertyValue('src'); - let url = src.split('url(')[1].split(')')[0]; - return {rule: rule, src: src, url: url.substring(url.length - 1, 1)}; - }; - let fontRules = [], fontProms = []; + const styleSheet = Array.prototype.filter.call(document.styleSheets, sS => sS.ownerNode === s)[0]; - for (let r of styleSheet.cssRules) { + const FontRule = rule => { + const src = rule.style.getPropertyValue('src'); + const url = src ? src.split('url(')[1].split(')')[0] : ""; + return {rule, src, url: url.substring(url.length - 1, 1)}; + } + const fontProms = []; + + for (const r of styleSheet.cssRules) { let fR = FontRule(r); - fontRules.push(fR); + if (!fR.url) continue; + fontProms.push( fetch(fR.url) // fetch the actual font-file (.woff) .then(resp => resp.blob()) @@ -125,9 +125,7 @@ function GFontToDataURI(url) { f.readAsDataURL(blob); }) }) - .then(dataURL => { - return fR.rule.cssText.replace(fR.url, dataURL); - }) + .then(dataURL => fR.rule.cssText.replace(fR.url, dataURL)) ) } document.head.removeChild(s); // clean up diff --git a/modules/ui/burgs-editor.js b/modules/ui/burgs-editor.js index dd624c84..17824974 100644 --- a/modules/ui/burgs-editor.js +++ b/modules/ui/burgs-editor.js @@ -31,14 +31,18 @@ function editBurgs() { const stateFilter = document.getElementById("burgsFilterState"); const selectedState = stateFilter.value || 1; stateFilter.options.length = 0; // remove all options - stateFilter.options.add(new Option("all", -1, false, selectedState == -1)); - pack.states.filter(s => !s.removed).forEach(s => stateFilter.options.add(new Option(s.name, s.i, false, s.i == selectedState))); + stateFilter.options.add(new Option(`all`, -1, false, selectedState == -1)); + stateFilter.options.add(new Option(pack.states[0].name, 0, false, !selectedState)); + const statesSorted = pack.states.filter(s => s.i && !s.removed).sort((a, b) => (a.name > b.name) ? 1 : -1); + statesSorted.forEach(s => stateFilter.options.add(new Option(s.name, s.i, false, s.i == selectedState))); const cultureFilter = document.getElementById("burgsFilterCulture"); const selectedCulture = cultureFilter.value || -1; cultureFilter.options.length = 0; // remove all options - cultureFilter.options.add(new Option("all", -1, false, selectedCulture == -1)); - pack.cultures.filter(c => !c.removed).forEach(c => cultureFilter.options.add(new Option(c.name, c.i, false, c.i == selectedCulture))); + cultureFilter.options.add(new Option(`all`, -1, false, selectedCulture == -1)); + cultureFilter.options.add(new Option(pack.cultures[0].name, 0, false, !selectedCulture)); + const culturesSorted = pack.cultures.filter(c => c.i && !c.removed).sort((a, b) => (a.name > b.name) ? 1 : -1); + culturesSorted.forEach(c => cultureFilter.options.add(new Option(c.name, c.i, false, c.i == selectedCulture))); } // add line for each state @@ -154,12 +158,13 @@ function editBurgs() { function toggleCapitalStatus() { const burg = +this.parentNode.parentNode.dataset.id, state = pack.burgs[burg].state; - if (pack.burgs[burg].capital) {tip("To change capital please assign capital status to another burg", false, "error"); return;} - if (!state) {tip("Neutral lands cannot have a capital", false, "error"); return;} + if (pack.burgs[burg].capital) {tip("To change capital please assign a capital status to another burg", false, "error"); return;} + if (!state) {tip("Neutral lands do not have a capital", false, "error"); return;} const old = pack.states[state].capital; // change statuses pack.states[state].capital = burg; + pack.states[state].center = pack.burgs[burg].cell; pack.burgs[burg].capital = true; pack.burgs[old].capital = false; moveBurgToGroup(burg, "cities");