mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
delete rendered rivers on layer off
This commit is contained in:
parent
d5b2e7ed14
commit
d9d349f3a1
3 changed files with 30 additions and 21 deletions
|
|
@ -1444,18 +1444,26 @@ function toggleTexture(event) {
|
|||
function toggleRivers(event) {
|
||||
if (!layerIsOn("toggleRivers")) {
|
||||
turnButtonOn("toggleRivers");
|
||||
$("#rivers").fadeIn();
|
||||
drawRivers();
|
||||
if (event && isCtrlClick(event)) editStyle("rivers");
|
||||
} else {
|
||||
if (event && isCtrlClick(event)) {
|
||||
editStyle("rivers");
|
||||
return;
|
||||
}
|
||||
$("#rivers").fadeOut();
|
||||
if (event && isCtrlClick(event)) return editStyle("rivers");
|
||||
rivers.selectAll("*").remove();
|
||||
turnButtonOff("toggleRivers");
|
||||
}
|
||||
}
|
||||
|
||||
function drawRivers() {
|
||||
const riverPaths = pack.rivers.map(river => {
|
||||
const riverMeandered = Rivers.addMeandering(river.cells, 0.5, river.points);
|
||||
const widthFactor = river.widthFactor || 1;
|
||||
const startingWidth = river.startingWidth || 0;
|
||||
const [path] = Rivers.getRiverPath(riverMeandered, widthFactor, startingWidth);
|
||||
return [path, river.i];
|
||||
});
|
||||
rivers.html(riverPaths.map(d => `<path id="river${d[1]}" d="${d[0]}"/>`).join(""));
|
||||
}
|
||||
|
||||
function toggleRoutes(event) {
|
||||
if (!layerIsOn("toggleRoutes")) {
|
||||
turnButtonOn("toggleRoutes");
|
||||
|
|
|
|||
|
|
@ -538,6 +538,7 @@ function addRiverOnClick() {
|
|||
if (cells.h[i] < 20) return tip("Cannot create river in water cell", false, "error");
|
||||
if (cells.b[i]) return;
|
||||
|
||||
const {alterHeights, resolveDepressions, addMeandering, getRiverPath, getBasin, getName, getType} = Rivers;
|
||||
const riverCells = [];
|
||||
let riverId = last(rivers).id + 1;
|
||||
let parent = 0;
|
||||
|
|
@ -545,8 +546,8 @@ function addRiverOnClick() {
|
|||
const initialFlux = grid.cells.prec[cells.g[i]];
|
||||
cells.fl[i] = initialFlux;
|
||||
|
||||
const h = Rivers.alterHeights();
|
||||
Rivers.resolveDepressions(h);
|
||||
const h = alterHeights();
|
||||
resolveDepressions(h);
|
||||
|
||||
while (i) {
|
||||
cells.r[i] = riverId;
|
||||
|
|
@ -615,9 +616,9 @@ function addRiverOnClick() {
|
|||
const river = rivers.find(r => r.i === riverId);
|
||||
const widthFactor = river?.widthFactor || (!parent || parent === riverId ? 1.2 : 1);
|
||||
|
||||
const riverMeandered = Rivers.addMeandering(riverCells, 1);
|
||||
const riverMeandered = addMeandering(riverCells);
|
||||
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
|
||||
const [path, length, offset] = Rivers.getRiverPath(riverMeandered, widthFactor);
|
||||
const [path, length, offset] = getRiverPath(riverMeandered, widthFactor);
|
||||
viewbox
|
||||
.select("#rivers")
|
||||
.append("path")
|
||||
|
|
@ -637,9 +638,9 @@ function addRiverOnClick() {
|
|||
river.width = width;
|
||||
river.cells = riverCells;
|
||||
} else {
|
||||
const basin = Rivers.getBasin(parent);
|
||||
const name = Rivers.getName(mouth);
|
||||
const type = Rivers.getType({i: riverId, length, parent});
|
||||
const basin = getBasin(parent);
|
||||
const name = getName(mouth);
|
||||
const type = getType({i: riverId, length, parent});
|
||||
|
||||
rivers.push({i: riverId, source, mouth, discharge, length, width, widthFactor, sourceWidth: 0, parent, cells: riverCells, basin, name, type});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue