mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
separete rivere rendering from generation
This commit is contained in:
parent
d9d349f3a1
commit
dbcf46f83b
6 changed files with 71 additions and 68 deletions
|
|
@ -197,6 +197,7 @@ function editHeightmap() {
|
|||
}
|
||||
}
|
||||
|
||||
drawRivers();
|
||||
Lakes.defineGroup();
|
||||
defineBiomes();
|
||||
rankCells();
|
||||
|
|
|
|||
|
|
@ -875,7 +875,6 @@ function toggleStates(event) {
|
|||
}
|
||||
}
|
||||
|
||||
// draw states
|
||||
function drawStates() {
|
||||
TIME && console.time("drawStates");
|
||||
regions.selectAll("path").remove();
|
||||
|
|
@ -1015,6 +1014,21 @@ function drawStates() {
|
|||
TIME && console.timeEnd("drawStates");
|
||||
}
|
||||
|
||||
function toggleBorders(event) {
|
||||
if (!layerIsOn("toggleBorders")) {
|
||||
turnButtonOn("toggleBorders");
|
||||
drawBorders();
|
||||
if (event && isCtrlClick(event)) editStyle("borders");
|
||||
} else {
|
||||
if (event && isCtrlClick(event)) {
|
||||
editStyle("borders");
|
||||
return;
|
||||
}
|
||||
turnButtonOff("toggleBorders");
|
||||
borders.selectAll("path").remove();
|
||||
}
|
||||
}
|
||||
|
||||
// draw state and province borders
|
||||
function drawBorders() {
|
||||
TIME && console.time("drawBorders");
|
||||
|
|
@ -1118,21 +1132,6 @@ function drawBorders() {
|
|||
TIME && console.timeEnd("drawBorders");
|
||||
}
|
||||
|
||||
function toggleBorders(event) {
|
||||
if (!layerIsOn("toggleBorders")) {
|
||||
turnButtonOn("toggleBorders");
|
||||
$("#borders").fadeIn();
|
||||
if (event && isCtrlClick(event)) editStyle("borders");
|
||||
} else {
|
||||
if (event && isCtrlClick(event)) {
|
||||
editStyle("borders");
|
||||
return;
|
||||
}
|
||||
turnButtonOff("toggleBorders");
|
||||
$("#borders").fadeOut();
|
||||
}
|
||||
}
|
||||
|
||||
function toggleProvinces(event) {
|
||||
if (!layerIsOn("toggleProvinces")) {
|
||||
turnButtonOn("toggleProvinces");
|
||||
|
|
@ -1454,14 +1453,18 @@ function toggleRivers(event) {
|
|||
}
|
||||
|
||||
function drawRivers() {
|
||||
TIME && console.time("drawRivers");
|
||||
const {addMeandering, getRiverPath} = Rivers;
|
||||
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
|
||||
const riverPaths = pack.rivers.map(river => {
|
||||
const riverMeandered = Rivers.addMeandering(river.cells, 0.5, river.points);
|
||||
const riverMeandered = 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];
|
||||
const path = getRiverPath(riverMeandered, widthFactor, startingWidth);
|
||||
return `<path id="river${river.i}" d="${path}"/>`;
|
||||
});
|
||||
rivers.html(riverPaths.map(d => `<path id="river${d[1]}" d="${d[0]}"/>`).join(""));
|
||||
rivers.html(riverPaths.join(""));
|
||||
TIME && console.timeEnd("drawRivers");
|
||||
}
|
||||
|
||||
function toggleRoutes(event) {
|
||||
|
|
|
|||
|
|
@ -538,7 +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 {alterHeights, resolveDepressions, addMeandering, getRiverPath, getBasin, getName, getType, getWidth, getOffset, getApproximateLength} = Rivers;
|
||||
const riverCells = [];
|
||||
let riverId = last(rivers).id + 1;
|
||||
let parent = 0;
|
||||
|
|
@ -614,22 +614,15 @@ function addRiverOnClick() {
|
|||
}
|
||||
|
||||
const river = rivers.find(r => r.i === riverId);
|
||||
const widthFactor = river?.widthFactor || (!parent || parent === riverId ? 1.2 : 1);
|
||||
|
||||
const riverMeandered = addMeandering(riverCells);
|
||||
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
|
||||
const [path, length, offset] = getRiverPath(riverMeandered, widthFactor);
|
||||
viewbox
|
||||
.select("#rivers")
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("id", "river" + riverId);
|
||||
|
||||
// add new river to data or change extended river attributes
|
||||
const source = riverCells[0];
|
||||
const mouth = riverCells[riverCells.length - 2];
|
||||
const widthFactor = river?.widthFactor || (!parent || parent === riverId ? 1.2 : 1);
|
||||
const riverMeandered = addMeandering(riverCells);
|
||||
|
||||
const discharge = cells.fl[mouth]; // m3 in second
|
||||
const width = rn((offset / 1.4) ** 2, 2); // mounth width in km
|
||||
const length = getApproximateLength(riverMeandered);
|
||||
const width = getWidth(getOffset(discharge, riverMeandered.length, widthFactor));
|
||||
|
||||
if (river) {
|
||||
river.source = source;
|
||||
|
|
@ -645,6 +638,13 @@ function addRiverOnClick() {
|
|||
rivers.push({i: riverId, source, mouth, discharge, length, width, widthFactor, sourceWidth: 0, parent, cells: riverCells, basin, name, type});
|
||||
}
|
||||
|
||||
// render river
|
||||
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
|
||||
const path = getRiverPath(riverMeandered, widthFactor);
|
||||
const id = "river" + riverId;
|
||||
const riversG = viewbox.select("#rivers");
|
||||
riversG.append("path").attr("d", path).attr("id", id);
|
||||
|
||||
if (d3.event.shiftKey === false) {
|
||||
Lakes.cleanupLakeData();
|
||||
unpressClickToAddButton();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue