mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-03-31 12:37:24 +02:00
fix: use global isExternalIcon to allow local custom icons in regiments & prevent unscaled svg crashing v1.109 loads
This commit is contained in:
parent
743d45c318
commit
6d000f7b06
3 changed files with 13 additions and 9 deletions
|
|
@ -732,10 +732,14 @@ async function parseLoadedData(data, mapVersion) {
|
||||||
// V1.109 changed how use tags scale, causing massive icons if not redrawn.
|
// V1.109 changed how use tags scale, causing massive icons if not redrawn.
|
||||||
if (compareVersions(mapVersion, VERSION).isNewer) {
|
if (compareVersions(mapVersion, VERSION).isNewer) {
|
||||||
// Prevent huge sizes from newer unsupported SVGs
|
// Prevent huge sizes from newer unsupported SVGs
|
||||||
const forceDefault = (el, attr, def) => { if (!el.attr(attr) || isNaN(el.attr(attr)) || +el.attr(attr) > 10) el.attr(attr, def); };
|
const forceDefault = (el, attr, def) => {
|
||||||
|
if (el && el.node() && (!el.attr(attr) || isNaN(el.attr(attr)) || +el.attr(attr) > 10)) {
|
||||||
|
el.attr(attr, def);
|
||||||
|
}
|
||||||
|
};
|
||||||
forceDefault(armies, "box-size", 3);
|
forceDefault(armies, "box-size", 3);
|
||||||
forceDefault(icons.select("#burgIcons > #cities"), "size", 1);
|
forceDefault(burgIcons.select("#cities"), "size", 1);
|
||||||
forceDefault(icons.select("#burgIcons > #towns"), "size", 0.5);
|
forceDefault(burgIcons.select("#towns"), "size", 0.5);
|
||||||
forceDefault(anchors.select("#cities"), "size", 2);
|
forceDefault(anchors.select("#cities"), "size", 2);
|
||||||
forceDefault(anchors.select("#towns"), "size", 1);
|
forceDefault(anchors.select("#towns"), "size", 1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ function drawMarker(marker, rescale = 1) {
|
||||||
const viewX = rn(x - zoomSize / 2, 1);
|
const viewX = rn(x - zoomSize / 2, 1);
|
||||||
const viewY = rn(y - zoomSize, 1);
|
const viewY = rn(y - zoomSize, 1);
|
||||||
|
|
||||||
const isExternal = icon.startsWith("http") || icon.startsWith("data:image") || icon.includes(".svg") || icon.includes("/");
|
const isExternal = typeof icon === "string" && (icon.startsWith("http") || icon.startsWith("data:image") || icon.includes(".svg") || icon.includes("/"));
|
||||||
|
|
||||||
return /* html */ `
|
return /* html */ `
|
||||||
<svg id="${id}" viewbox="0 0 30 30" width="${zoomSize}" height="${zoomSize}" x="${viewX}" y="${viewY}">
|
<svg id="${id}" viewbox="0 0 30 30" width="${zoomSize}" height="${zoomSize}" x="${viewX}" y="${viewY}">
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const isExternalIcon = (icon) => icon && (icon.startsWith("http") || icon.startsWith("data:image") || icon.includes(".svg") || icon.includes("/"));
|
window.isExternalIcon = (icon) => typeof icon === "string" && (icon.startsWith("http") || icon.startsWith("data:image") || icon.includes(".svg") || icon.includes("/"));
|
||||||
|
|
||||||
function drawMilitary() {
|
function drawMilitary() {
|
||||||
TIME && console.time("drawMilitary");
|
TIME && console.time("drawMilitary");
|
||||||
|
|
@ -58,14 +58,14 @@ const drawRegiments = function (regiments, s) {
|
||||||
.attr("text-rendering", "optimizeSpeed")
|
.attr("text-rendering", "optimizeSpeed")
|
||||||
.attr("x", d => x(d) - size)
|
.attr("x", d => x(d) - size)
|
||||||
.attr("y", d => d.y)
|
.attr("y", d => d.y)
|
||||||
.text(d => (isExternalIcon(d.icon) ? "" : d.icon));
|
.text(d => (window.isExternalIcon(d.icon) ? "" : d.icon));
|
||||||
g.append("image")
|
g.append("image")
|
||||||
.attr("class", "regimentImage")
|
.attr("class", "regimentImage")
|
||||||
.attr("x", d => x(d) - h)
|
.attr("x", d => x(d) - h)
|
||||||
.attr("y", d => y(d))
|
.attr("y", d => y(d))
|
||||||
.attr("height", h)
|
.attr("height", h)
|
||||||
.attr("width", h)
|
.attr("width", h)
|
||||||
.attr("href", d => (isExternalIcon(d.icon) ? d.icon : ""));
|
.attr("href", d => (window.isExternalIcon(d.icon) ? d.icon : ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawRegiment = function (reg, stateId) {
|
const drawRegiment = function (reg, stateId) {
|
||||||
|
|
@ -111,14 +111,14 @@ const drawRegiment = function (reg, stateId) {
|
||||||
.attr("text-rendering", "optimizeSpeed")
|
.attr("text-rendering", "optimizeSpeed")
|
||||||
.attr("x", x1 - size)
|
.attr("x", x1 - size)
|
||||||
.attr("y", reg.y)
|
.attr("y", reg.y)
|
||||||
.text(isExternalIcon(reg.icon) ? "" : reg.icon);
|
.text(window.isExternalIcon(reg.icon) ? "" : reg.icon);
|
||||||
g.append("image")
|
g.append("image")
|
||||||
.attr("class", "regimentImage")
|
.attr("class", "regimentImage")
|
||||||
.attr("x", x1 - h)
|
.attr("x", x1 - h)
|
||||||
.attr("y", y1)
|
.attr("y", y1)
|
||||||
.attr("height", h)
|
.attr("height", h)
|
||||||
.attr("width", h)
|
.attr("width", h)
|
||||||
.attr("href", isExternalIcon(reg.icon) ? reg.icon : "");
|
.attr("href", window.isExternalIcon(reg.icon) ? reg.icon : "");
|
||||||
};
|
};
|
||||||
|
|
||||||
// move one regiment to another
|
// move one regiment to another
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue