This commit is contained in:
Azgaar 2020-05-09 23:51:14 +03:00
parent bb0251c020
commit 617e8d4306
12 changed files with 86 additions and 163 deletions

View file

@ -214,8 +214,8 @@
<mask id="water"> <mask id="water">
<rect x="0" y="0" width="100%" height="100%" fill="white"></rect> <rect x="0" y="0" width="100%" height="100%" fill="white"></rect>
</mask> </mask>
<mask id="fog"> <mask id="fog" style="stroke-width: 10; stroke: black; stroke-linejoin: round; stroke-opacity: .1;">
<rect x="0" y="0" width="100%" height="100%" fill="white"></rect> <rect x="0" y="0" width="100%" height="100%" fill="white" stroke="none"></rect>
</mask> </mask>
<g id="textPaths"></g> <g id="textPaths"></g>
<g id="statePaths"></g> <g id="statePaths"></g>

15
main.js
View file

@ -61,8 +61,7 @@ let burgIcons = icons.append("g").attr("id", "burgIcons");
let anchors = icons.append("g").attr("id", "anchors"); let anchors = icons.append("g").attr("id", "anchors");
let armies = viewbox.append("g").attr("id", "armies").style("display", "none"); let armies = viewbox.append("g").attr("id", "armies").style("display", "none");
let markers = viewbox.append("g").attr("id", "markers").style("display", "none"); let markers = viewbox.append("g").attr("id", "markers").style("display", "none");
let fogging = viewbox.append("g").attr("id", "fogging-cont").attr("mask", "url(#fog)") let fogging = viewbox.append("g").attr("id", "fogging-cont").attr("mask", "url(#fog)").append("g").attr("id", "fogging").style("display", "none");
.append("g").attr("id", "fogging").style("display", "none");
let ruler = viewbox.append("g").attr("id", "ruler").style("display", "none"); let ruler = viewbox.append("g").attr("id", "ruler").style("display", "none");
let debug = viewbox.append("g").attr("id", "debug"); let debug = viewbox.append("g").attr("id", "debug");
@ -94,6 +93,7 @@ population.append("g").attr("id", "urban");
// fogging // fogging
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%");
fogging.append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%").attr("fill", "#e8f0f6").attr("filter", "url(#splotch)");
// assign events separately as not a viewbox child // assign events separately as not a viewbox child
scaleBar.on("mousemove", () => tip("Click to open Units Editor")); scaleBar.on("mousemove", () => tip("Click to open Units Editor"));
@ -335,7 +335,7 @@ function applyDefaultBiomesSystem() {
} }
function showWelcomeMessage() { function showWelcomeMessage() {
const post = link("https://www.reddit.com/r/FantasyMapGenerator/comments/ft5b41/update_new_version_is_published_military_update_v/", "Main changes:"); // announcement on Reddit const post = link("https://www.reddit.com/r/FantasyMapGenerator/comments/ft5b41/update_new_version_is_published_military_update_v14/", "Main changes:"); // announcement on Reddit
const changelog = link("https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Changelog", "previous version"); const changelog = link("https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Changelog", "previous version");
const reddit = link("https://www.reddit.com/r/FantasyMapGenerator", "Reddit community"); const reddit = link("https://www.reddit.com/r/FantasyMapGenerator", "Reddit community");
const discord = link("https://discordapp.com/invite/X7E84HU", "Discord server"); const discord = link("https://discordapp.com/invite/X7E84HU", "Discord server");
@ -346,10 +346,10 @@ function showWelcomeMessage() {
This version is compatible with ${changelog}, loaded <i>.map</i> files will be auto-updated. This version is compatible with ${changelog}, loaded <i>.map</i> files will be auto-updated.
<ul>${post} <ul>${post}
<li>Military Forces generation</li> <li>Battle simulation</li>
<li>Military Forces overview</li> <li>Ice layer and Ice editor</li>
<li>Military Units editor</li> <li>Route Elevation profile</li>
<li>Regiments editor</li> <li>Name generator improvement</li>
</ul> </ul>
<p>You can can also download a ${desktop}.</p> <p>You can can also download a ${desktop}.</p>
@ -528,7 +528,6 @@ function generate() {
elevateLakes(); elevateLakes();
Rivers.generate(); Rivers.generate();
defineBiomes(); defineBiomes();
drawIce();
rankCells(); rankCells();
Cultures.generate(); Cultures.generate();

View file

@ -140,46 +140,15 @@
// define burg coordinates, port status and define details // define burg coordinates, port status and define details
const specifyBurgs = function() { const specifyBurgs = function() {
console.time("specifyBurgs"); console.time("specifyBurgs");
const cells = pack.cells, vertices = pack.vertices, features = pack.features; const cells = pack.cells, vertices = pack.vertices, features = pack.features, temp = grid.cells.temp;
// separate arctic seas for correct searoutes generation
void function checkAccessibility() {
const oceanCells = cells.i.filter(i => cells.h[i] < 20 && features[cells.f[i]].type === "ocean");
const marked = [];
let firstCell = oceanCells.find(i => !marked[i]);
while (firstCell !== undefined) {
const queue = [firstCell];
const f = features[cells.f[firstCell]]; // old feature
const i = last(features).i+1; // new feature id to assign
const biome = cells.biome[firstCell];
marked[firstCell] = 1;
let cellNumber = 1;
while (queue.length) {
for (const c of cells.c[queue.pop()]) {
if (cells.biome[c] !== biome || cells.h[c] >= 20) continue;
if (marked[c]) continue;
queue.push(c);
cells.f[c] = i;
marked[c] = 1;
cellNumber++;
}
}
const group = biome ? "frozen " + f.group : f.group;
features.push({i, parent:f.i, land:false, border:f.border, type:"ocean", cells: cellNumber, firstCell, group});
firstCell = oceanCells.find(i => !marked[i]);
}
}()
for (const b of pack.burgs) { for (const b of pack.burgs) {
if (!b.i) continue; if (!b.i) continue;
const i = b.cell; const i = b.cell;
// asign port status // asign port status to some coastline burgs with temp > 0 °C
const haven = cells.haven[i]; const haven = cells.haven[i];
if (haven && cells.biome[haven] === 0) { if (haven && temp[cells.g[i]] > 0) {
const f = cells.f[haven]; // water body id const f = cells.f[haven]; // water body id
// port is a capital with any harbor OR town with good harbor // port is a capital with any harbor OR town with good harbor
const port = features[f].cells > 1 && ((b.capital && cells.harbor[i]) || cells.harbor[i] === 1); const port = features[f].cells > 1 && ((b.capital && cells.harbor[i]) || cells.harbor[i] === 1);

View file

@ -61,52 +61,35 @@
const getSearoutes = function() { const getSearoutes = function() {
console.time("generateSearoutes"); console.time("generateSearoutes");
const cells = pack.cells, allPorts = pack.burgs.filter(b => b.port > 0 && !b.removed); const allPorts = pack.burgs.filter(b => b.port > 0 && !b.removed);
if (allPorts.length < 2) return []; if (allPorts.length < 2) return [];
const bodies = new Set(allPorts.map(b => b.port)); // features with ports const bodies = new Set(allPorts.map(b => b.port)); // features with ports
let paths = []; // array to store path segments let paths = []; // array to store path segments
const connected = []; // store cell id of connected burgs
bodies.forEach(function(f) { bodies.forEach(function(f) {
const ports = allPorts.filter(b => b.port === f); const ports = allPorts.filter(b => b.port === f); // all ports on the same feature
if (ports.length < 2) return; if (ports.length < 2) return;
const first = ports[0].cell;
const farthest = ports[d3.scan(ports, (a, b) => ((b.y - ports[0].y) ** 2 + (b.x - ports[0].x) ** 2) - ((a.y - ports[0].y) ** 2 + (a.x - ports[0].x) ** 2))].cell;
// directly connect first port with the farthest one on the same island to remove gap for (let s=0; s < ports.length; s++) {
void function() { const source = ports[s].cell;
if (!pack.features[f] || pack.features[f].type === "lake") return; if (connected[source]) continue;
const portsOnIsland = ports.filter(b => cells.f[b.cell] === cells.f[first]);
if (portsOnIsland.length < 4) return;
const opposite = ports[d3.scan(portsOnIsland, (a, b) => ((b.y - ports[0].y) ** 2 + (b.x - ports[0].x) ** 2) - ((a.y - ports[0].y) ** 2 + (a.x - ports[0].x) ** 2))].cell;
//debug.append("circle").attr("cx", pack.cells.p[opposite][0]).attr("cy", pack.cells.p[opposite][1]).attr("r", 1);
//debug.append("circle").attr("cx", pack.cells.p[first][0]).attr("cy", pack.cells.p[first][1]).attr("fill", "red").attr("r", 1);
const [from, exit, passable] = findOceanPath(opposite, first);
if (!passable) return;
from[first] = cells.haven[first];
const path = restorePath(opposite, first, "ocean", from);
paths = paths.concat(path);
}()
// directly connect first port with the farthest one for (let t=s+1; t < ports.length; t++) {
void function() { const target = ports[t].cell;
const [from, exit, passable] = findOceanPath(farthest, first); if (connected[target]) continue;
if (!passable) return;
from[first] = cells.haven[first];
const path = restorePath(farthest, first, "ocean", from);
paths = paths.concat(path);
}()
// indirectly connect first port with all other ports const [from, exit, passable] = findOceanPath(target, source, true);
void function() {
if (ports.length < 3) return;
for (const p of ports) {
if (p.cell === first || p.cell === farthest) continue;
const [from, exit, passable] = findOceanPath(p.cell, first, true);
if (!passable) continue; if (!passable) continue;
const path = restorePath(p.cell, exit, "ocean", from);
const path = restorePath(target, exit, "ocean", from);
paths = paths.concat(path); paths = paths.concat(path);
connected[source] = 1;
connected[target] = 1;
}
} }
}()
}); });
@ -235,7 +218,7 @@
// find water paths // find water paths
function findOceanPath(start, exit = null, toRoute = null) { function findOceanPath(start, exit = null, toRoute = null) {
const cells = pack.cells; const cells = pack.cells, temp = grid.cells.temp;
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p}); const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
const cost = [], from = []; const cost = [], from = [];
queue.queue({e: start, p: 0}); queue.queue({e: start, p: 0});
@ -247,6 +230,7 @@
for (const c of cells.c[n]) { for (const c of cells.c[n]) {
if (c === exit) {from[c] = n; return [from, exit, true];} if (c === exit) {from[c] = n; return [from, exit, true];}
if (cells.h[c] >= 20) continue; // ignore land cells if (cells.h[c] >= 20) continue; // ignore land cells
if (temp[cells.g[c]] <= -5) continue; // ignore cells with term <= -5
const dist2 = (cells.p[c][1] - cells.p[n][1]) ** 2 + (cells.p[c][0] - cells.p[n][0]) ** 2; const dist2 = (cells.p[c][1] - cells.p[n][1]) ** 2 + (cells.p[c][0] - cells.p[n][0]) ** 2;
const totalCost = p + (cells.road[c] ? 1 + dist2 / 2 : dist2 + (cells.t[c] ? 1 : 100)); const totalCost = p + (cells.road[c] ? 1 + dist2 / 2 : dist2 + (cells.t[c] ? 1 : 100));

View file

@ -832,11 +832,9 @@ function parseLoadedData(data) {
if (!markers.selectAll("*").size()) {addMarkers(); turnButtonOn("toggleMarkers");} if (!markers.selectAll("*").size()) {addMarkers(); turnButtonOn("toggleMarkers");}
// 1.0 add fogging layer (state focus) // 1.0 add fogging layer (state focus)
fogging = viewbox.insert("g", "#ruler").attr("id", "fogging-cont").attr("mask", "url(#fog)") fogging = viewbox.insert("g", "#ruler").attr("id", "fogging-cont").attr("mask", "url(#fog)").append("g").attr("id", "fogging").style("display", "none");
.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%") defs.append("mask").attr("id", "fog").append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%").attr("fill", "white");
.attr("height", "100%").attr("fill", "white");
// 1.0 changes states opacity bask to regions level // 1.0 changes states opacity bask to regions level
if (statesBody.attr("opacity")) { if (statesBody.attr("opacity")) {

View file

@ -527,11 +527,26 @@ function changePickerSpace() {
openPicker.updateFill(); openPicker.updateFill();
} }
// remove all fogging // add fogging
function unfog() { function fog(id, path) {
defs.select("#fog").selectAll("path").remove(); if (defs.select("#fog #"+id).size()) return;
fogging.selectAll("path").remove(); const fadeIn = d3.transition().duration(2000).ease(d3.easeSinInOut);
fogging.style("display", "none"); if (defs.select("#fog path").size()) {
defs.select("#fog").append("path").attr("d", path).attr("id", id).attr("opacity", 0).transition(fadeIn).attr("opacity", 1);
} else {
defs.select("#fog").append("path").attr("d", path).attr("id", id).attr("opacity", 1);
const opacity = fogging.attr("opacity");
fogging.style("display", "block").attr("opacity", 0).transition(fadeIn).attr("opacity", opacity);
}
}
// remove fogging
function unfog(id) {
let el = defs.select("#fog #"+id);
if (!id || !el.size()) el = defs.select("#fog").selectAll("path");
el.remove();
if (!defs.selectAll("#fog path").size()) fogging.style("display", "none");
} }
function getFileName(dataType) { function getFileName(dataType) {

View file

@ -185,7 +185,6 @@ function editHeightmap() {
} }
defineBiomes(); defineBiomes();
rankCells(); rankCells();
Cultures.generate(); Cultures.generate();
Cultures.expand(); Cultures.expand();
@ -354,6 +353,8 @@ function editHeightmap() {
if (!b.i || b.removed) continue; if (!b.i || b.removed) continue;
b.cell = findBurgCell(b.x, b.y); b.cell = findBurgCell(b.x, b.y);
b.feature = pack.cells.f[b.cell]; b.feature = pack.cells.f[b.cell];
//if (b.port) b.port = pack.cells.f[pack.cells.haven[b.cell]]; // water body id
pack.cells.burg[b.cell] = b.i; pack.cells.burg[b.cell] = b.i;
if (!b.capital && pack.cells.h[b.cell] < 20) removeBurg(b.i); if (!b.capital && pack.cells.h[b.cell] < 20) removeBurg(b.i);
if (b.capital) pack.states[b.state].center = b.cell; if (b.capital) pack.states[b.state].center = b.cell;

View file

@ -460,6 +460,7 @@ function toggleIce() {
if (!layerIsOn("toggleIce")) { if (!layerIsOn("toggleIce")) {
turnButtonOn("toggleIce"); turnButtonOn("toggleIce");
$('#ice').fadeIn(); $('#ice').fadeIn();
if (!ice.selectAll("*").size()) drawIce();
if (event && isCtrlClick(event)) editStyle("ice"); if (event && isCtrlClick(event)) editStyle("ice");
} else { } else {
if (event && isCtrlClick(event)) {editStyle("ice"); return;} if (event && isCtrlClick(event)) {editStyle("ice"); return;}
@ -473,7 +474,7 @@ function drawIce() {
const used = new Uint8Array(cells.i.length); const used = new Uint8Array(cells.i.length);
Math.seedrandom(seed); Math.seedrandom(seed);
const shieldMin = -6; // min temp to form ice shield (glacier) const shieldMin = -6; // max temp to form ice shield (glacier)
const icebergMax = 2; // max temp to form an iceberg const icebergMax = 2; // max temp to form an iceberg
for (const i of grid.cells.i) { for (const i of grid.cells.i) {

View file

@ -42,7 +42,7 @@ function editProvinces() {
if (cl.contains("icon-star-empty")) capitalZoomIn(p); else if (cl.contains("icon-star-empty")) capitalZoomIn(p); else
if (cl.contains("icon-flag-empty")) triggerIndependencePromps(p); else if (cl.contains("icon-flag-empty")) triggerIndependencePromps(p); else
if (cl.contains("culturePopulation")) changePopulation(p); else if (cl.contains("culturePopulation")) changePopulation(p); else
if (cl.contains("icon-pin")) focusOn(p, cl); else if (cl.contains("icon-pin")) toggleFog(p, cl); else
if (cl.contains("icon-trash-empty")) removeProvince(p); if (cl.contains("icon-trash-empty")) removeProvince(p);
}); });
@ -282,7 +282,7 @@ function editProvinces() {
BurgsAndStates.drawStateLabels([newState, oldState]); BurgsAndStates.drawStateLabels([newState, oldState]);
// remove old province // remove old province
unfocus(p); unfog("focusProvince"+p);
if (states[oldState].provinces.includes(p)) states[oldState].provinces.splice(states[oldState].provinces.indexOf(p), 1); if (states[oldState].provinces.includes(p)) states[oldState].provinces.splice(states[oldState].provinces.indexOf(p), 1);
provinces[p].removed = true; provinces[p].removed = true;
@ -347,24 +347,10 @@ function editProvinces() {
} }
function focusOn(p, cl) { function toggleFog(p, cl) {
const inactive = cl.contains("inactive"); const path = provs.select("#province"+p).attr("d"), id = "focusProvince"+p;
cl.contains("inactive") ? fog(id, path) : unfog(id);
cl.toggle("inactive"); cl.toggle("inactive");
if (inactive) {
if (defs.select("#fog #focusProvince"+p).size()) return;
fogging.style("display", "block");
const path = provs.select("#province"+p).attr("d");
defs.select("#fog").append("path").attr("d", path).attr("fill", "black").attr("id", "focusProvince"+p);
fogging.append("path").attr("d", path).attr("id", "focusProvinceHalo"+p)
.attr("fill", "none").attr("stroke", pack.provinces[p].color).attr("filter", "url(#blur5)");
} else unfocus(p);
}
function unfocus(p) {
defs.select("#focusProvince"+p).remove();
fogging.select("#focusProvinceHalo"+p).remove();
if (!defs.selectAll("#fog path").size()) fogging.style("display", "none"); // all items are de-focused
} }
function removeProvince(p) { function removeProvince(p) {
@ -377,7 +363,7 @@ function editProvinces() {
const state = pack.provinces[p].state; const state = pack.provinces[p].state;
if (pack.states[state].provinces.includes(p)) pack.states[state].provinces.splice(pack.states[state].provinces.indexOf(p), 1); if (pack.states[state].provinces.includes(p)) pack.states[state].provinces.splice(pack.states[state].provinces.indexOf(p), 1);
pack.provinces[p].removed = true; pack.provinces[p].removed = true;
unfocus(p); unfog("focusProvince"+p);
const g = provs.select("#provincesBody"); const g = provs.select("#provincesBody");
g.select("#province"+p).remove(); g.select("#province"+p).remove();
@ -853,7 +839,7 @@ function editProvinces() {
$(this).dialog("close"); $(this).dialog("close");
pack.provinces.filter(p => p.i).forEach(p => { pack.provinces.filter(p => p.i).forEach(p => {
p.removed = true; p.removed = true;
unfocus(p.i); unfog("focusProvince"+p.i);
}); });
pack.cells.i.forEach(i => pack.cells.province[i] = 0); pack.cells.i.forEach(i => pack.cells.province[i] = 0);
pack.states.filter(s => s.i && !s.removed).forEach(s => s.provinces = []); pack.states.filter(s => s.i && !s.removed).forEach(s => s.provinces = []);

View file

@ -45,7 +45,7 @@ function editStates() {
if (cl.contains("icon-coa")) stateOpenCOA(ev, state); else if (cl.contains("icon-coa")) stateOpenCOA(ev, state); else
if (cl.contains("icon-star-empty")) stateCapitalZoomIn(state); else if (cl.contains("icon-star-empty")) stateCapitalZoomIn(state); else
if (cl.contains("culturePopulation")) changePopulation(state); else if (cl.contains("culturePopulation")) changePopulation(state); else
if (cl.contains("icon-pin")) focusOnState(state, cl); else if (cl.contains("icon-pin")) toggleFog(state, cl); else
if (cl.contains("icon-trash-empty")) stateRemovePrompt(state); if (cl.contains("icon-trash-empty")) stateRemovePrompt(state);
}); });
@ -171,6 +171,8 @@ function editStates() {
function stateHighlightOn(event) { function stateHighlightOn(event) {
if (!layerIsOn("toggleStates")) return; if (!layerIsOn("toggleStates")) return;
if (defs.select("#fog path").size()) return;
const state = +event.target.dataset.id; const state = +event.target.dataset.id;
if (customization || !state) return; if (customization || !state) return;
const d = regions.select("#state"+state).attr("d"); const d = regions.select("#state"+state).attr("d");
@ -405,26 +407,11 @@ function editStates() {
recalculateStates(); recalculateStates();
} }
function focusOnState(state, cl) { function toggleFog(state, cl) {
if (customization) return; if (customization) return;
const path = statesBody.select("#state"+state).attr("d"), id = "focusState"+state;
const inactive = cl.contains("inactive"); cl.contains("inactive") ? fog(id, path) : unfog(id);
cl.toggle("inactive"); cl.toggle("inactive");
if (inactive) {
if (defs.select("#fog #focusState"+state).size()) return;
fogging.style("display", "block");
const path = statesBody.select("#state"+state).attr("d");
defs.select("#fog").append("path").attr("d", path).attr("fill", "black").attr("id", "focusState"+state);
fogging.append("path").attr("d", path).attr("id", "focusStateHalo"+state)
.attr("fill", "none").attr("stroke", pack.states[state].color).attr("filter", "url(#blur5)");
} else unfocus(state);
}
function unfocus(s) {
defs.select("#focusState"+s).remove();
fogging.select("#focusStateHalo"+s).remove();
if (!defs.selectAll("#fog path").size()) fogging.style("display", "none"); // all items are de-focused
} }
function stateRemovePrompt(state) { function stateRemovePrompt(state) {
@ -446,7 +433,7 @@ function editStates() {
statesBody.select("#state"+state).remove(); statesBody.select("#state"+state).remove();
statesBody.select("#state-gap"+state).remove(); statesBody.select("#state-gap"+state).remove();
statesHalo.select("#state-border"+state).remove(); statesHalo.select("#state-border"+state).remove();
unfocus(state); unfog("focusState"+state);
const label = document.querySelector("#stateLabel"+state); const label = document.querySelector("#stateLabel"+state);
if (label) label.remove(); if (label) label.remove();
pack.burgs.forEach(b => {if(b.state === state) b.state = 0;}); pack.burgs.forEach(b => {if(b.state === state) b.state = 0;});

File diff suppressed because one or more lines are too long

View file

@ -30,7 +30,7 @@ function editZones() {
if (cl.contains("culturePopulation")) {changePopulation(zone); return;} if (cl.contains("culturePopulation")) {changePopulation(zone); return;}
if (cl.contains("icon-trash-empty")) {zoneRemove(zone); return;} if (cl.contains("icon-trash-empty")) {zoneRemove(zone); return;}
if (cl.contains("icon-eye")) {toggleVisibility(el); return;} if (cl.contains("icon-eye")) {toggleVisibility(el); return;}
if (cl.contains("icon-pin")) {focusOnZone(zone, cl); return;} if (cl.contains("icon-pin")) {toggleFog(zone, cl); return;}
if (cl.contains("fillRect")) {changeFill(el); return;} if (cl.contains("fillRect")) {changeFill(el); return;}
if (customization) selectZone(el); if (customization) selectZone(el);
}); });
@ -194,7 +194,7 @@ function editZones() {
zones.selectAll("g").each(function() { zones.selectAll("g").each(function() {
if (this.dataset.cells) return; if (this.dataset.cells) return;
// all zone cells are removed // all zone cells are removed
unfocus(this.id); unfog("focusZone"+this.id);
this.style.display = "block"; this.style.display = "block";
}); });
@ -253,24 +253,13 @@ function editZones() {
el.classList.toggle("inactive"); el.classList.toggle("inactive");
} }
function focusOnZone(zone, cl) { function toggleFog(z, cl) {
const inactive = cl.contains("inactive"); const dataCells = zones.select("#"+z).attr("data-cells");
cl.toggle("inactive");
if (inactive) {
if (defs.select("#fog #focus"+zone).size()) return;
const dataCells = zones.select("#"+zone).attr("data-cells");
if (!dataCells) return; if (!dataCells) return;
const data = dataCells.split(",").map(c => +c);
const g = defs.select("#fog").append("g").attr("fill", "black").attr("stroke", "black").attr("id", "focus"+zone);
g.selectAll("path").data(data).enter().append("path").attr("d", d => "M" + getPackPolygon(d) + "Z");
fogging.style("display", "block");
} else unfocus(zone);
}
function unfocus(z) { const path = "M" + dataCells.split(",").map(c => getPackPolygon(+c)).join("M") + "Z", id = "focusZone"+z;
defs.select("#focus"+z).remove(); cl.contains("inactive") ? fog(id, path) : unfog(id);
if (!defs.selectAll("#fog path").size()) fogging.style("display", "none"); // all states are de-focused cl.toggle("inactive");
} }
function toggleLegend() { function toggleLegend() {
@ -414,7 +403,7 @@ function editZones() {
function zoneRemove(zone) { function zoneRemove(zone) {
zones.select("#"+zone).remove(); zones.select("#"+zone).remove();
unfocus(zone); unfog("focusZone"+zone);
zonesEditorAddLines(); zonesEditorAddLines();
} }