diff --git a/index.html b/index.html index 6909d1cb..a818a90b 100644 --- a/index.html +++ b/index.html @@ -7857,7 +7857,7 @@ - + @@ -7883,7 +7883,7 @@ - + @@ -7897,7 +7897,7 @@ - + diff --git a/modules/river-generator.js b/modules/river-generator.js index 957fe6fc..fd8a95b4 100644 --- a/modules/river-generator.js +++ b/modules/river-generator.js @@ -48,7 +48,9 @@ window.Rivers = (function () { cells.fl[i] += prec[cells.g[i]] / cellsNumberModifier; // add flux from precipitation // create lake outlet if lake is not in deep depression and flux > evaporation - const lakes = lakeOutCells[i] ? features.filter(feature => i === feature.outCell && feature.flux > feature.evaporation) : []; + const lakes = lakeOutCells[i] + ? features.filter(feature => i === feature.outCell && feature.flux > feature.evaporation) + : []; for (const lake of lakes) { const lakeCell = cells.c[i].find(c => h[c] < 20 && cells.f[c] === lake.i); cells.fl[lakeCell] += Math.max(lake.flux - lake.evaporation, 0); // not evaporated lake water drains to outlet @@ -191,7 +193,18 @@ window.Rivers = (function () { const length = getApproximateLength(meanderedPoints); const width = getWidth(getOffset(discharge, meanderedPoints.length, widthFactor, 0)); - pack.rivers.push({i: riverId, source, mouth, discharge, length, width, widthFactor, sourceWidth: 0, parent, cells: riverCells}); + pack.rivers.push({ + i: riverId, + source, + mouth, + discharge, + length, + width, + widthFactor, + sourceWidth: 0, + parent, + cells: riverCells + }); } } @@ -479,6 +492,10 @@ window.Rivers = (function () { return getBasin(parent); }; + const getNextId = function (rivers) { + return rivers.length ? Math.max(...rivers.map(r => r.i)) + 1 : 1; + }; + return { generate, alterHeights, @@ -493,6 +510,7 @@ window.Rivers = (function () { getOffset, getApproximateLength, getRiverPoints, - remove + remove, + getNextId }; })(); diff --git a/modules/ui/rivers-creator.js b/modules/ui/rivers-creator.js index 83a4d1b9..a8600917 100644 --- a/modules/ui/rivers-creator.js +++ b/modules/ui/rivers-creator.js @@ -74,12 +74,13 @@ function createRiver() { function addRiver() { const {rivers, cells} = pack; - const {addMeandering, getApproximateLength, getWidth, getOffset, getName, getRiverPath, getBasin} = Rivers; + const {addMeandering, getApproximateLength, getWidth, getOffset, getName, getRiverPath, getBasin, getNextId} = + Rivers; const riverCells = createRiver.cells; if (riverCells.length < 2) return tip("Add at least 2 cells", false, "error"); - const riverId = rivers.length ? last(rivers).i + 1 : 1; + const riverId = getNextId(rivers); const parent = cells.r[last(riverCells)] || riverId; riverCells.forEach(cell => { @@ -100,12 +101,30 @@ function createRiver() { const name = getName(mouth); const basin = getBasin(parent); - rivers.push({i: riverId, source, mouth, discharge, length, width, widthFactor, sourceWidth, parent, cells: riverCells, basin, name, type: "River"}); + rivers.push({ + i: riverId, + source, + mouth, + discharge, + length, + width, + widthFactor, + sourceWidth, + parent, + cells: riverCells, + basin, + name, + type: "River" + }); const id = "river" + riverId; // render river lineGen.curve(d3.curveCatmullRom.alpha(0.1)); - viewbox.select("#rivers").append("path").attr("id", id).attr("d", getRiverPath(meanderedPoints, widthFactor, sourceWidth)); + viewbox + .select("#rivers") + .append("path") + .attr("id", id) + .attr("d", getRiverPath(meanderedPoints, widthFactor, sourceWidth)); editRiver(id); } diff --git a/modules/ui/tools.js b/modules/ui/tools.js index 00913e0b..7fbc1ebf 100644 --- a/modules/ui/tools.js +++ b/modules/ui/tools.js @@ -626,10 +626,11 @@ function addRiverOnClick() { getType, getWidth, getOffset, - getApproximateLength + getApproximateLength, + getNextId } = Rivers; const riverCells = []; - let riverId = rivers.length ? last(rivers).i + 1 : 1; + let riverId = getNextId(rivers); let parent = riverId; const initialFlux = grid.cells.prec[cells.g[i]]; diff --git a/versioning.js b/versioning.js index 9e10745c..b9e12c80 100644 --- a/versioning.js +++ b/versioning.js @@ -1,7 +1,7 @@ "use strict"; // version and caching control -const version = "1.89.12"; // generator version, update each time +const version = "1.89.13"; // generator version, update each time { document.title += " v" + version;