v1.5.15 - svg save data cleansing

This commit is contained in:
Azgaar 2021-02-11 01:09:41 +03:00
parent 6987474c2e
commit 002160ed21
8 changed files with 164 additions and 135 deletions

View file

@ -205,6 +205,7 @@ function editEmblem(type, id, el) {
reader.onload = function(readerEvent) {
const result = readerEvent.target.result;
const defs = document.getElementById("defs-emblems");
const coa = document.getElementById(id); // old emblem
if (type === "image") {
const svg = `<svg id="${id}" xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200"><image x="0" y="0" width="200" height="200" href="${result}"/></svg>`;
@ -217,9 +218,7 @@ function editEmblem(type, id, el) {
newEmblem.setAttribute("height", 200);
}
const coa = document.getElementById(id);
if (coa) coa.remove(); // remove old emblem
el.coa = "custom";
emblemShapeSelector.disabled = true;
};
@ -282,7 +281,6 @@ function editEmblem(type, id, el) {
function getSVG(svg, coa, size) {
const clone = svg.cloneNode(true); // clone svg
const d = clone.getElementsByTagName("defs")[0];
clone.setAttribute("width", size);
clone.setAttribute("height", size);

View file

@ -1304,15 +1304,15 @@ function drawEmblems() {
}
const burgNodes = nodes.filter(node => node.type === "burg");
const burgString = burgNodes.map(d => `<use data-i="${d.i}" x="${d.x - d.size / 2}" y="${d.y - d.size / 2}" width="1em" height="1em"/>`).join("");
const burgString = burgNodes.map(d => `<use data-i="${d.i}" x="${rn(d.x - d.size / 2)}" y="${rn(d.y - d.size / 2)}" width="1em" height="1em"/>`).join("");
emblems.select("#burgEmblems").attr("font-size", sizeBurgs).html(burgString);
const provinceNodes = nodes.filter(node => node.type === "province");
const provinceString = provinceNodes.map(d => `<use data-i="${d.i}" x="${d.x - d.size / 2}" y="${d.y - d.size / 2}" width="1em" height="1em"/>`).join("");
const provinceString = provinceNodes.map(d => `<use data-i="${d.i}" x="${rn(d.x - d.size / 2)}" y="${rn(d.y - d.size / 2)}" width="1em" height="1em"/>`).join("");
emblems.select("#provinceEmblems").attr("font-size", sizeProvinces).html(provinceString);
const stateNodes = nodes.filter(node => node.type === "state");
const stateString = stateNodes.map(d => `<use data-i="${d.i}" x="${d.x - d.size / 2}" y="${d.y - d.size / 2}" width="1em" height="1em"/>`).join("");
const stateString = stateNodes.map(d => `<use data-i="${d.i}" x="${rn(d.x - d.size / 2)}" y="${rn(d.y - d.size / 2)}" width="1em" height="1em"/>`).join("");
emblems.select("#stateEmblems").attr("font-size", sizeStates).html(stateString);
invokeActiveZooming();

View file

@ -664,14 +664,9 @@ function fetchTextureURL(url) {
img.src = url;
}
function armiesStyle() {
return `#armies text {stroke: none; fill: #fff; text-shadow: 0 0 4px #000; dominant-baseline: central; text-anchor: middle; font-family: Helvetica; fill-opacity: 1;}#armies text.regimentIcon {font-size: .8em;}`;
}
// apply default or custom style settings on load
function applyStyleOnLoad() {
addDefaulsStyles(); // add FMG system styles to localStorage
svg.select("defs").append("style").text(armiesStyle()); // add armies style
const preset = localStorage.getItem("presetStyle");
const style = preset ? localStorage.getItem(preset) : null;