mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
add only used hatchings on export
This commit is contained in:
parent
81f037004c
commit
451cd60d4d
2 changed files with 56 additions and 48 deletions
|
|
@ -184,9 +184,6 @@ async function getMapURL(type, options = {}) {
|
||||||
filters[i].remove();
|
filters[i].remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
const hatching = svgDefs.getElementById("defs-hatching");
|
|
||||||
if (hatching) cloneDefs.appendChild(hatching.cloneNode(true));
|
|
||||||
|
|
||||||
// remove unused patterns
|
// remove unused patterns
|
||||||
const patterns = cloneEl.querySelectorAll("pattern");
|
const patterns = cloneEl.querySelectorAll("pattern");
|
||||||
for (let i = 0; i < patterns.length; i++) {
|
for (let i = 0; i < patterns.length; i++) {
|
||||||
|
|
@ -265,17 +262,17 @@ async function getMapURL(type, options = {}) {
|
||||||
if (pattern) cloneDefs.appendChild(pattern.cloneNode(true));
|
if (pattern) cloneDefs.appendChild(pattern.cloneNode(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cloneEl.getElementById("defs-hatching").children.length) cloneEl.getElementById("defs-hatching")?.remove(); // remove unused hatching group
|
|
||||||
if (!cloneEl.getElementById("fogging-cont")) cloneEl.getElementById("fog")?.remove(); // remove unused fog
|
if (!cloneEl.getElementById("fogging-cont")) cloneEl.getElementById("fog")?.remove(); // remove unused fog
|
||||||
if (!cloneEl.getElementById("regions")) cloneEl.getElementById("statePaths")?.remove(); // removed unused statePaths
|
if (!cloneEl.getElementById("regions")) cloneEl.getElementById("statePaths")?.remove(); // removed unused statePaths
|
||||||
if (!cloneEl.getElementById("labels")) cloneEl.getElementById("textPaths")?.remove(); // removed unused textPaths
|
if (!cloneEl.getElementById("labels")) cloneEl.getElementById("textPaths")?.remove(); // removed unused textPaths
|
||||||
|
|
||||||
// add armies style
|
// add armies style
|
||||||
if (cloneEl.getElementById("armies"))
|
if (cloneEl.getElementById("armies")) {
|
||||||
cloneEl.insertAdjacentHTML(
|
cloneEl.insertAdjacentHTML(
|
||||||
"afterbegin",
|
"afterbegin",
|
||||||
"<style>#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;}</style>"
|
"<style>#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;}</style>"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// add xlink: for href to support svg 1.1
|
// add xlink: for href to support svg 1.1
|
||||||
if (type === "svg") {
|
if (type === "svg") {
|
||||||
|
|
@ -286,6 +283,16 @@ async function getMapURL(type, options = {}) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add hatchings
|
||||||
|
const hatchingUsers = cloneEl.querySelectorAll(`[fill^='url(#hatch']`);
|
||||||
|
const hatchingFills = unique(Array.from(hatchingUsers).map(el => el.getAttribute("fill")));
|
||||||
|
const hatchingIds = hatchingFills.map(fill => fill.slice(5, -1));
|
||||||
|
for (const hatchingId of hatchingIds) {
|
||||||
|
const hatching = svgDefs.getElementById(hatchingId);
|
||||||
|
if (hatching) cloneDefs.appendChild(hatching.cloneNode(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// load fonts
|
||||||
const usedFonts = getUsedFonts(cloneEl);
|
const usedFonts = getUsedFonts(cloneEl);
|
||||||
const fontsToLoad = usedFonts.filter(font => font.src);
|
const fontsToLoad = usedFonts.filter(font => font.src);
|
||||||
if (fontsToLoad.length) {
|
if (fontsToLoad.length) {
|
||||||
|
|
|
||||||
|
|
@ -425,16 +425,16 @@ function parseLoadedData(data) {
|
||||||
void (function resolveVersionConflicts() {
|
void (function resolveVersionConflicts() {
|
||||||
const version = parseFloat(data[0].split("|")[0]);
|
const version = parseFloat(data[0].split("|")[0]);
|
||||||
if (version < 0.9) {
|
if (version < 0.9) {
|
||||||
// 0.9 has additional relief icons to be included into older maps
|
// v0.9 has additional relief icons to be included into older maps
|
||||||
document.getElementById("defs-relief").innerHTML = reliefIcons;
|
document.getElementById("defs-relief").innerHTML = reliefIcons;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version < 1) {
|
if (version < 1) {
|
||||||
// 1.0 adds a new religions layer
|
// v1.0 adds a new religions layer
|
||||||
relig = viewbox.insert("g", "#terrain").attr("id", "relig");
|
relig = viewbox.insert("g", "#terrain").attr("id", "relig");
|
||||||
Religions.generate();
|
Religions.generate();
|
||||||
|
|
||||||
// 1.0 adds a legend box
|
// v1.0 adds a legend box
|
||||||
legend = svg.append("g").attr("id", "legend");
|
legend = svg.append("g").attr("id", "legend");
|
||||||
legend
|
legend
|
||||||
.attr("font-family", "Almendra SC")
|
.attr("font-family", "Almendra SC")
|
||||||
|
|
@ -447,7 +447,7 @@ function parseLoadedData(data) {
|
||||||
.attr("stroke-dasharray", "0 4 10 4")
|
.attr("stroke-dasharray", "0 4 10 4")
|
||||||
.attr("stroke-linecap", "round");
|
.attr("stroke-linecap", "round");
|
||||||
|
|
||||||
// 1.0 separated drawBorders fron drawStates()
|
// v1.0 separated drawBorders fron drawStates()
|
||||||
stateBorders = borders.append("g").attr("id", "stateBorders");
|
stateBorders = borders.append("g").attr("id", "stateBorders");
|
||||||
provinceBorders = borders.append("g").attr("id", "provinceBorders");
|
provinceBorders = borders.append("g").attr("id", "provinceBorders");
|
||||||
borders
|
borders
|
||||||
|
|
@ -460,7 +460,7 @@ function parseLoadedData(data) {
|
||||||
stateBorders.attr("opacity", 0.8).attr("stroke", "#56566d").attr("stroke-width", 1).attr("stroke-dasharray", "2").attr("stroke-linecap", "butt");
|
stateBorders.attr("opacity", 0.8).attr("stroke", "#56566d").attr("stroke-width", 1).attr("stroke-dasharray", "2").attr("stroke-linecap", "butt");
|
||||||
provinceBorders.attr("opacity", 0.8).attr("stroke", "#56566d").attr("stroke-width", 0.5).attr("stroke-dasharray", "1").attr("stroke-linecap", "butt");
|
provinceBorders.attr("opacity", 0.8).attr("stroke", "#56566d").attr("stroke-width", 0.5).attr("stroke-dasharray", "1").attr("stroke-linecap", "butt");
|
||||||
|
|
||||||
// 1.0 adds state relations, provinces, forms and full names
|
// v1.0 adds state relations, provinces, forms and full names
|
||||||
provs = viewbox.insert("g", "#borders").attr("id", "provs").attr("opacity", 0.6);
|
provs = viewbox.insert("g", "#borders").attr("id", "provs").attr("opacity", 0.6);
|
||||||
BurgsAndStates.collectStatistics();
|
BurgsAndStates.collectStatistics();
|
||||||
BurgsAndStates.generateCampaigns();
|
BurgsAndStates.generateCampaigns();
|
||||||
|
|
@ -472,7 +472,7 @@ function parseLoadedData(data) {
|
||||||
if (!layerIsOn("toggleBorders")) $("#borders").fadeOut();
|
if (!layerIsOn("toggleBorders")) $("#borders").fadeOut();
|
||||||
if (!layerIsOn("toggleStates")) regions.attr("display", "none").selectAll("path").remove();
|
if (!layerIsOn("toggleStates")) regions.attr("display", "none").selectAll("path").remove();
|
||||||
|
|
||||||
// 1.0 adds zones layer
|
// v1.0 adds zones layer
|
||||||
zones = viewbox.insert("g", "#borders").attr("id", "zones").attr("display", "none");
|
zones = viewbox.insert("g", "#borders").attr("id", "zones").attr("display", "none");
|
||||||
zones.attr("opacity", 0.6).attr("stroke", null).attr("stroke-width", 0).attr("stroke-dasharray", null).attr("stroke-linecap", "butt");
|
zones.attr("opacity", 0.6).attr("stroke", null).attr("stroke-width", 0).attr("stroke-dasharray", null).attr("stroke-linecap", "butt");
|
||||||
addZones();
|
addZones();
|
||||||
|
|
@ -481,25 +481,25 @@ function parseLoadedData(data) {
|
||||||
turnButtonOn("toggleMarkers");
|
turnButtonOn("toggleMarkers");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.0 add fogging layer (state focus)
|
// v1.0 add fogging layer (state focus)
|
||||||
fogging = viewbox.insert("g", "#ruler").attr("id", "fogging-cont").attr("mask", "url(#fog)").append("g").attr("id", "fogging").style("display", "none");
|
fogging = viewbox.insert("g", "#ruler").attr("id", "fogging-cont").attr("mask", "url(#fog)").append("g").attr("id", "fogging").style("display", "none");
|
||||||
fogging.append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%");
|
fogging.append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%");
|
||||||
defs.append("mask").attr("id", "fog").append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%").attr("fill", "white");
|
defs.append("mask").attr("id", "fog").append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%").attr("fill", "white");
|
||||||
|
|
||||||
// 1.0 changes states opacity bask to regions level
|
// v1.0 changes states opacity bask to regions level
|
||||||
if (statesBody.attr("opacity")) {
|
if (statesBody.attr("opacity")) {
|
||||||
regions.attr("opacity", statesBody.attr("opacity"));
|
regions.attr("opacity", statesBody.attr("opacity"));
|
||||||
statesBody.attr("opacity", null);
|
statesBody.attr("opacity", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.0 changed labels to multi-lined
|
// v1.0 changed labels to multi-lined
|
||||||
labels.selectAll("textPath").each(function () {
|
labels.selectAll("textPath").each(function () {
|
||||||
const text = this.textContent;
|
const text = this.textContent;
|
||||||
const shift = this.getComputedTextLength() / -1.5;
|
const shift = this.getComputedTextLength() / -1.5;
|
||||||
this.innerHTML = `<tspan x="${shift}">${text}</tspan>`;
|
this.innerHTML = `<tspan x="${shift}">${text}</tspan>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 1.0 added new biome - Wetland
|
// v1.0 added new biome - Wetland
|
||||||
biomesData.name.push("Wetland");
|
biomesData.name.push("Wetland");
|
||||||
biomesData.color.push("#0b9131");
|
biomesData.color.push("#0b9131");
|
||||||
biomesData.habitability.push(12);
|
biomesData.habitability.push(12);
|
||||||
|
|
@ -664,7 +664,7 @@ function parseLoadedData(data) {
|
||||||
else return "⚔️";
|
else return "⚔️";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.4 added state reference for regiments
|
// v1.4 added state reference for regiments
|
||||||
pack.states.filter(s => s.military).forEach(s => s.military.forEach(r => (r.state = s.i)));
|
pack.states.filter(s => s.military).forEach(s => s.military.forEach(r => (r.state = s.i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -798,7 +798,7 @@ function parseLoadedData(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version < 1.63) {
|
if (version < 1.63) {
|
||||||
// v.1.63 changed ocean pattern opacity element
|
// v1.63 changed ocean pattern opacity element
|
||||||
const oceanPattern = document.getElementById("oceanPattern");
|
const oceanPattern = document.getElementById("oceanPattern");
|
||||||
if (oceanPattern) oceanPattern.removeAttribute("opacity");
|
if (oceanPattern) oceanPattern.removeAttribute("opacity");
|
||||||
const oceanicPattern = document.getElementById("oceanicPattern");
|
const oceanicPattern = document.getElementById("oceanicPattern");
|
||||||
|
|
@ -812,7 +812,7 @@ function parseLoadedData(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version < 1.64) {
|
if (version < 1.64) {
|
||||||
// v.1.64 change states style
|
// v1.64 change states style
|
||||||
const opacity = regions.attr("opacity");
|
const opacity = regions.attr("opacity");
|
||||||
const filter = regions.attr("filter");
|
const filter = regions.attr("filter");
|
||||||
statesBody.attr("opacity", opacity).attr("filter", filter);
|
statesBody.attr("opacity", opacity).attr("filter", filter);
|
||||||
|
|
@ -927,6 +927,7 @@ function parseLoadedData(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version < 1.72) {
|
if (version < 1.72) {
|
||||||
|
// v1.72 renamed custom style presets
|
||||||
const storedStyles = Object.keys(localStorage).filter(key => key.startsWith("style"));
|
const storedStyles = Object.keys(localStorage).filter(key => key.startsWith("style"));
|
||||||
storedStyles.forEach(styleName => {
|
storedStyles.forEach(styleName => {
|
||||||
const style = localStorage.getItem(styleName);
|
const style = localStorage.getItem(styleName);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue