feat: update relief rendering logic and version to 1.114.0

This commit is contained in:
Azgaar 2026-03-11 00:11:15 +01:00
parent dc06f3d65c
commit ab7baf83fd
6 changed files with 53 additions and 110 deletions

View file

@ -1112,4 +1112,23 @@ export function resolveVersionConflicts(mapVersion) {
zone.cells = unique(zone.cells);
});
}
if (isOlderThan("1.114.0")) {
// v1.114.0 add reliefIcon to pack data and changed rendering method to WebGL
const terrainEl = byId("terrain");
if (!terrainEl) return;
const relief = [];
terrainEl.querySelectorAll("use").forEach(u => {
const href = u.getAttribute("href") || u.getAttribute("xlink:href") || "";
if (!href) return;
const x = +u.getAttribute("x");
const y = +u.getAttribute("y");
const s = +u.getAttribute("width");
relief.push({i: relief.length, href, x, y, s});
});
terrainEl.innerHTML = "";
pack.relief = relief;
if (layerIsOn("toggleRelief")) drawRelief();
}
}

View file

@ -180,10 +180,7 @@ async function getMapURL(
fullMap = false
} = {}
) {
// Temporarily inject <use> elements so the clone includes relief icon data
if (typeof prepareReliefForSave === "function") prepareReliefForSave();
const cloneEl = byId("map").cloneNode(true); // clone svg
if (typeof restoreReliefAfterSave === "function") restoreReliefAfterSave();
cloneEl.id = "fantasyMap";
document.body.appendChild(cloneEl);
const clone = d3.select(cloneEl);
@ -261,6 +258,19 @@ async function getMapURL(
cloneDefs.querySelector("#defs-emblems")?.remove();
}
{
// render relief icons in svg and add used icons to defs
const terrainEl = cloneEl.getElementById("terrain");
if (terrainEl) drawRelief("svg", terrainEl);
const uniqueElements = new Set(pack.relief?.map(r => r.href) || []);
const defsRelief = svgDefs.getElementById("defs-relief");
for (const terrain of uniqueElements) {
const element = defsRelief.querySelector(terrain);
if (element) cloneDefs.appendChild(element.cloneNode(true));
}
}
{
// replace ocean pattern href to base64
const image = cloneEl.getElementById("oceanicPattern");
@ -289,22 +299,6 @@ async function getMapURL(
}
}
// add relief icons (from <use> elements canvas <image> is excluded)
if (cloneEl.getElementById("terrain")) {
const uniqueElements = new Set();
const terrainUses = cloneEl.getElementById("terrain").querySelectorAll("use");
for (let i = 0; i < terrainUses.length; i++) {
const href = terrainUses[i].getAttribute("href") || terrainUses[i].getAttribute("xlink:href");
if (href && href.startsWith("#")) uniqueElements.add(href);
}
const defsRelief = svgDefs.getElementById("defs-relief");
for (const terrain of [...uniqueElements]) {
const element = defsRelief.querySelector(terrain);
if (element) cloneDefs.appendChild(element.cloneNode(true));
}
}
// add wind rose
if (cloneEl.getElementById("compass")) {
const rose = svgDefs.getElementById("defs-compass-rose");

View file

@ -440,12 +440,7 @@ async function parseLoadedData(data, mapVersion) {
if (hasChildren(coordinates)) turnOn("toggleCoordinates");
if (isVisible(compass) && hasChild(compass, "use")) turnOn("toggleCompass");
if (hasChildren(rivers)) turnOn("toggleRivers");
if (isVisible(terrain) && hasChildren(terrain)) {
turnOn("toggleRelief");
}
// Migrate any legacy SVG <use> elements to canvas rendering
// (runs regardless of visibility to handle maps loaded with relief layer off)
if (typeof migrateReliefFromSvg === "function") migrateReliefFromSvg();
if (hasChildren(terrain)) turnOn("toggleRelief");
if (hasChildren(relig)) turnOn("toggleReligions");
if (hasChildren(cults)) turnOn("toggleCultures");
if (hasChildren(statesBody)) turnOn("toggleStates");

View file

@ -77,11 +77,7 @@ function prepareMapData() {
const rulersString = rulers.toString();
const fonts = JSON.stringify(getUsedFonts(svg.node()));
// save svg
// Temporarily inject <use> elements so the SVG snapshot includes relief icon data
if (typeof prepareReliefForSave === "function") prepareReliefForSave();
const cloneEl = document.getElementById("map").cloneNode(true);
if (typeof restoreReliefAfterSave === "function") restoreReliefAfterSave();
// reset transform values to default
cloneEl.setAttribute("width", graphWidth);