mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
draw halo along water, but not map border
This commit is contained in:
parent
cfb6e1eeeb
commit
805684f79e
1 changed files with 19 additions and 23 deletions
|
|
@ -890,10 +890,6 @@ function drawStates() {
|
||||||
const gap = new Array(states.length).fill(""); // path along water for each state to fill the gaps
|
const gap = new Array(states.length).fill(""); // path along water for each state to fill the gaps
|
||||||
const halo = new Array(states.length).fill(""); // path around states, but not lakes
|
const halo = new Array(states.length).fill(""); // path around states, but not lakes
|
||||||
|
|
||||||
// helper functions
|
|
||||||
const isLand = i => i[1] === "land";
|
|
||||||
const nextIsLand = (ar, i) => ar[i + 1]?.[1] === "land";
|
|
||||||
const prevIsLand = (ar, i) => ar[i - 1]?.[1] === "land";
|
|
||||||
const getStringPoint = v => vertices.p[v[0]].join(",");
|
const getStringPoint = v => vertices.p[v[0]].join(",");
|
||||||
|
|
||||||
// define inner-state lakes to omit on border render
|
// define inner-state lakes to omit on border render
|
||||||
|
|
@ -909,37 +905,34 @@ function drawStates() {
|
||||||
if (!cells.state[i] || used[i]) continue;
|
if (!cells.state[i] || used[i]) continue;
|
||||||
const state = cells.state[i];
|
const state = cells.state[i];
|
||||||
|
|
||||||
// if (state !== 5) continue;
|
|
||||||
|
|
||||||
const onborder = cells.c[i].some(n => cells.state[n] !== state);
|
const onborder = cells.c[i].some(n => cells.state[n] !== state);
|
||||||
if (!onborder) continue;
|
if (!onborder) continue;
|
||||||
|
|
||||||
const borderWith = cells.c[i].map(c => cells.state[c]).find(n => n !== state);
|
const borderWith = cells.c[i].map(c => cells.state[c]).find(n => n !== state);
|
||||||
const vertex = cells.v[i].find(v => vertices.c[v].some(i => cells.state[i] === borderWith));
|
const vertex = cells.v[i].find(v => vertices.c[v].some(i => cells.state[i] === borderWith));
|
||||||
const chain = connectVertices(vertex, state);
|
const chain = connectVertices(vertex, state);
|
||||||
if (chain.length < 3) continue;
|
|
||||||
|
|
||||||
// get path around state
|
const noInnerLakes = chain.filter(v => v[1] !== "innerLake");
|
||||||
const points = chain.filter(v => v[1] !== "innerLake").map(v => vertices.p[v[0]]);
|
if (noInnerLakes.length < 3) continue;
|
||||||
|
|
||||||
|
// get path around the state
|
||||||
if (!vArray[state]) vArray[state] = [];
|
if (!vArray[state]) vArray[state] = [];
|
||||||
|
const points = noInnerLakes.map(v => vertices.p[v[0]]);
|
||||||
if (points.length) {
|
vArray[state].push(points);
|
||||||
vArray[state].push(points);
|
body[state] += "M" + points.join("L");
|
||||||
body[state] += "M" + points.join("L");
|
|
||||||
}
|
|
||||||
|
|
||||||
// connect path for halo
|
// connect path for halo
|
||||||
let discontinued = true;
|
let discontinued = true;
|
||||||
halo[state] += chain
|
halo[state] += noInnerLakes
|
||||||
.map((v, i) => {
|
.map(v => {
|
||||||
if (isLand(v) || nextIsLand(chain, i) || prevIsLand(chain, i)) {
|
if (v[1] === "border") {
|
||||||
const operation = discontinued ? "M" : "L";
|
discontinued = true;
|
||||||
discontinued = false;
|
return "";
|
||||||
return `${operation}${getStringPoint(v)}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
discontinued = true;
|
const operation = discontinued ? "M" : "L";
|
||||||
return "";
|
discontinued = false;
|
||||||
|
return `${operation}${getStringPoint(v)}`;
|
||||||
})
|
})
|
||||||
.join("");
|
.join("");
|
||||||
|
|
||||||
|
|
@ -947,7 +940,7 @@ function drawStates() {
|
||||||
discontinued = true;
|
discontinued = true;
|
||||||
gap[state] += chain
|
gap[state] += chain
|
||||||
.map(v => {
|
.map(v => {
|
||||||
if (isLand(v)) {
|
if (v[1] === "land") {
|
||||||
discontinued = true;
|
discontinued = true;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
@ -982,6 +975,9 @@ function drawStates() {
|
||||||
function connectVertices(start, state) {
|
function connectVertices(start, state) {
|
||||||
const chain = []; // vertices chain to form a path
|
const chain = []; // vertices chain to form a path
|
||||||
const getType = c => {
|
const getType = c => {
|
||||||
|
const borderCell = c.find(i => cells.b[i]);
|
||||||
|
if (borderCell) return "border";
|
||||||
|
|
||||||
const waterCell = c.find(i => cells.h[i] < 20);
|
const waterCell = c.find(i => cells.h[i] < 20);
|
||||||
if (!waterCell) return "land";
|
if (!waterCell) return "land";
|
||||||
if (innerLakes[cells.f[waterCell]]) return "innerLake";
|
if (innerLakes[cells.f[waterCell]]) return "innerLake";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue