mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 03:51:23 +01:00
Code cleanup
This commit is contained in:
parent
1d5d96b862
commit
bf5a3b8870
3 changed files with 10 additions and 17 deletions
1
main.js
1
main.js
|
|
@ -530,7 +530,6 @@ function generate() {
|
||||||
reGraph();
|
reGraph();
|
||||||
drawCoastline();
|
drawCoastline();
|
||||||
|
|
||||||
elevateLakes();
|
|
||||||
Rivers.generate();
|
Rivers.generate();
|
||||||
defineBiomes();
|
defineBiomes();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,17 +91,19 @@
|
||||||
const x = p[i][0], y = p[i][1];
|
const x = p[i][0], y = p[i][1];
|
||||||
|
|
||||||
// lake outlets draw from lake
|
// lake outlets draw from lake
|
||||||
let n = -1, out2 = 0;
|
let out2;
|
||||||
while (outlets.includes(i, n+1)) {
|
for (let n = outlets.indexOf(i); n !== -1; n = outlets.indexOf(i, n+1)) { // in case multiple lakes share outlet
|
||||||
n = outlets.indexOf(i, n+1);
|
|
||||||
const l = features[n];
|
const l = features[n];
|
||||||
if ( ! l ) {continue;}
|
if ( ! l ) {continue;}
|
||||||
const j = cells.haven[i];
|
const j = cells.haven[i];
|
||||||
if(cells.r[j] === l.river) {
|
// allow chain lakes to retain identity
|
||||||
} else {
|
if(cells.r[j] !== l.river) {
|
||||||
let touch = false;
|
let touch = false;
|
||||||
for (const c of cells.c[j]){
|
for (const c of cells.c[j]){
|
||||||
if (cells.r[c] === l.river) touch = true;
|
if (cells.r[c] === l.river) {
|
||||||
|
touch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (touch) {
|
if (touch) {
|
||||||
cells.r[j] = l.river;
|
cells.r[j] = l.river;
|
||||||
|
|
@ -114,7 +116,7 @@
|
||||||
}
|
}
|
||||||
flowDown(i, cells.fl[i], l.totalFlux, cells.r[j]);
|
flowDown(i, cells.fl[i], l.totalFlux, cells.r[j]);
|
||||||
// prevent dropping imediately back into the lake
|
// prevent dropping imediately back into the lake
|
||||||
out2 = cells.c[i].filter(c => h[c] >= 20).sort((a,b) => h[a] - h[b])[0]; // downhill land cell
|
out2 = cells.c[i].filter(c => cells.f[c] !== cells.f[j]).sort((a,b) => h[a] - h[b])[0]; // downhill cell not in the source lake
|
||||||
}
|
}
|
||||||
|
|
||||||
// near-border cell: pour out of the screen
|
// near-border cell: pour out of the screen
|
||||||
|
|
@ -203,10 +205,6 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
lakes.forEach(copy => {
|
|
||||||
pack.features[copy.i].height = copy.height;
|
|
||||||
pack.features[copy.i].shoreline = copy.shoreline;
|
|
||||||
}); // write to real data
|
|
||||||
land.sort((a,b) => h[b] - h[a]); // highest cells go first
|
land.sort((a,b) => h[b] - h[a]); // highest cells go first
|
||||||
let depressed = false;
|
let depressed = false;
|
||||||
|
|
||||||
|
|
@ -221,11 +219,9 @@
|
||||||
depressed = true;
|
depressed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// write changed
|
|
||||||
depression && lakes.forEach(copy => pack.features[copy.i].height = copy.height);
|
|
||||||
for (const i of land) {
|
for (const i of land) {
|
||||||
const minHeight = d3.min(cells.c[i].map(c => cells.t[c] > 0 ? h[c] :
|
const minHeight = d3.min(cells.c[i].map(c => cells.t[c] > 0 ? h[c] :
|
||||||
pack.features[cells.f[c]].height || h[c] // NB undefined is falsy
|
pack.features[cells.f[c]].height || h[c] // NB undefined is falsy (a || b is short for a ? a : b)
|
||||||
));
|
));
|
||||||
if (minHeight === 100) continue; // already max height
|
if (minHeight === 100) continue; // already max height
|
||||||
if (h[i] <= minHeight) {
|
if (h[i] <= minHeight) {
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,6 @@ function editHeightmap() {
|
||||||
drawCoastline();
|
drawCoastline();
|
||||||
|
|
||||||
if (changeHeights.checked) {
|
if (changeHeights.checked) {
|
||||||
// elevateLakes();
|
|
||||||
Rivers.generate(changeHeights.checked);
|
Rivers.generate(changeHeights.checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -313,7 +312,6 @@ function editHeightmap() {
|
||||||
|
|
||||||
for (const i of pack.cells.i) {
|
for (const i of pack.cells.i) {
|
||||||
const g = pack.cells.g[i];
|
const g = pack.cells.g[i];
|
||||||
// if (pack.features[pack.cells.f[i]].group === "freshwater") pack.cells.h[i] = 19; // de-elevate lakes
|
|
||||||
const land = pack.cells.h[i] >= 20;
|
const land = pack.cells.h[i] >= 20;
|
||||||
|
|
||||||
// check biome
|
// check biome
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue