separete rivere rendering from generation

This commit is contained in:
Azgaar 2021-07-24 18:42:10 +03:00
parent d9d349f3a1
commit dbcf46f83b
6 changed files with 71 additions and 68 deletions

View file

@ -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) {