mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-04-17 12:46:06 +02:00
allow auto-downgrade for newer map versions and expand external icon detection to include SVGs and paths.
This commit is contained in:
parent
647b0d4513
commit
743d45c318
3 changed files with 42 additions and 24 deletions
|
|
@ -88,8 +88,7 @@ function loadMapFromURL(maplink, random) {
|
||||||
|
|
||||||
function showUploadErrorMessage(error, URL, random) {
|
function showUploadErrorMessage(error, URL, random) {
|
||||||
ERROR && console.error(error);
|
ERROR && console.error(error);
|
||||||
alertMessage.innerHTML = /* html */ `Cannot load map from the ${link(URL, "link provided")}. ${
|
alertMessage.innerHTML = /* html */ `Cannot load map from the ${link(URL, "link provided")}. ${random ? `A new random map is generated. ` : ""
|
||||||
random ? `A new random map is generated. ` : ""
|
|
||||||
} Please ensure the
|
} Please ensure the
|
||||||
linked file is reachable and CORS is allowed on server side`;
|
linked file is reachable and CORS is allowed on server side`;
|
||||||
$("#alert").dialog({
|
$("#alert").dialog({
|
||||||
|
|
@ -194,8 +193,9 @@ function showUploadMessage(type, mapData, mapVersion) {
|
||||||
message = `The map version you are trying to load (${mapVersion}) is too old and cannot be updated to the current version.<br>Please keep using an ${archive}`;
|
message = `The map version you are trying to load (${mapVersion}) is too old and cannot be updated to the current version.<br>Please keep using an ${archive}`;
|
||||||
title = "Ancient file";
|
title = "Ancient file";
|
||||||
} else if (type === "newer") {
|
} else if (type === "newer") {
|
||||||
message = `The map version you are trying to load (${mapVersion}) is newer than the current version.<br>Please load the file in the appropriate version`;
|
INFO && console.info(`Loading map. Auto-downgrading from ${mapVersion} to ${VERSION}`);
|
||||||
title = "Newer file";
|
parseLoadedData(mapData, mapVersion);
|
||||||
|
return;
|
||||||
} else if (type === "outdated") {
|
} else if (type === "outdated") {
|
||||||
INFO && console.info(`Loading map. Auto-updating from ${mapVersion} to ${VERSION}`);
|
INFO && console.info(`Loading map. Auto-updating from ${mapVersion} to ${VERSION}`);
|
||||||
parseLoadedData(mapData, mapVersion);
|
parseLoadedData(mapData, mapVersion);
|
||||||
|
|
@ -727,6 +727,22 @@ async function parseLoadedData(data, mapVersion) {
|
||||||
// draw data layers (not kept in svg)
|
// draw data layers (not kept in svg)
|
||||||
if (rulers && layerIsOn("toggleRulers")) rulers.draw();
|
if (rulers && layerIsOn("toggleRulers")) rulers.draw();
|
||||||
if (layerIsOn("toggleGrid")) drawGrid();
|
if (layerIsOn("toggleGrid")) drawGrid();
|
||||||
|
|
||||||
|
// Fix for auto-downgraded maps (e.g. 1.109.x to 1.108.x):
|
||||||
|
// V1.109 changed how use tags scale, causing massive icons if not redrawn.
|
||||||
|
if (compareVersions(mapVersion, VERSION).isNewer) {
|
||||||
|
// 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); };
|
||||||
|
forceDefault(armies, "box-size", 3);
|
||||||
|
forceDefault(icons.select("#burgIcons > #cities"), "size", 1);
|
||||||
|
forceDefault(icons.select("#burgIcons > #towns"), "size", 0.5);
|
||||||
|
forceDefault(anchors.select("#cities"), "size", 2);
|
||||||
|
forceDefault(anchors.select("#towns"), "size", 1);
|
||||||
|
|
||||||
|
if (typeof drawBurgIcons === "function") drawBurgIcons();
|
||||||
|
if (typeof drawMarkers === "function") drawMarkers();
|
||||||
|
if (typeof drawMilitary === "function") drawMilitary();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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");
|
const isExternal = 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,5 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const isExternalIcon = (icon) => icon && (icon.startsWith("http") || icon.startsWith("data:image") || icon.includes(".svg") || icon.includes("/"));
|
||||||
|
|
||||||
function drawMilitary() {
|
function drawMilitary() {
|
||||||
TIME && console.time("drawMilitary");
|
TIME && console.time("drawMilitary");
|
||||||
|
|
||||||
|
|
@ -56,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 => (d.icon.startsWith("http") || d.icon.startsWith("data:image") ? "" : d.icon));
|
.text(d => (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 => (d.icon.startsWith("http") || d.icon.startsWith("data:image") ? d.icon : ""));
|
.attr("href", d => (isExternalIcon(d.icon) ? d.icon : ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawRegiment = function (reg, stateId) {
|
const drawRegiment = function (reg, stateId) {
|
||||||
|
|
@ -109,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(reg.icon.startsWith("http") || reg.icon.startsWith("data:image") ? "" : reg.icon);
|
.text(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", reg.icon.startsWith("http") || reg.icon.startsWith("data:image") ? reg.icon : "");
|
.attr("href", 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