mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor(es modules): remove gloval var lineGen
This commit is contained in:
parent
32d7db765d
commit
aa214a7826
17 changed files with 27 additions and 22 deletions
|
|
@ -62,7 +62,6 @@ biomesData = Biomes.getDefault();
|
||||||
nameBases = Names.getNameBases(); // cultures-related data
|
nameBases = Names.getNameBases(); // cultures-related data
|
||||||
|
|
||||||
// color = d3.scaleSequential(d3.interpolateSpectral); // default color scheme
|
// color = d3.scaleSequential(d3.interpolateSpectral); // default color scheme
|
||||||
// lineGen = d3.line().curve(d3.curveBasis); // d3 line generator with default curve interpolation
|
|
||||||
|
|
||||||
// voronoi graph extension, cannot be changed after generation
|
// voronoi graph extension, cannot be changed after generation
|
||||||
graphWidth = +byId("mapWidthInput").value;
|
graphWidth = +byId("mapWidthInput").value;
|
||||||
|
|
@ -364,6 +363,8 @@ async function generate(options) {
|
||||||
applyMapSize();
|
applyMapSize();
|
||||||
randomizeOptions();
|
randomizeOptions();
|
||||||
|
|
||||||
|
debugger;
|
||||||
|
|
||||||
if (shouldRegenerateGrid(grid)) grid = precreatedGraph || generateGrid();
|
if (shouldRegenerateGrid(grid)) grid = precreatedGraph || generateGrid();
|
||||||
else delete grid.cells.h;
|
else delete grid.cells.h;
|
||||||
grid.cells.h = await HeightmapGenerator.generate(grid);
|
grid.cells.h = await HeightmapGenerator.generate(grid);
|
||||||
|
|
@ -954,7 +955,7 @@ function drawCoastline() {
|
||||||
);
|
);
|
||||||
const landMask = defs.select("#land");
|
const landMask = defs.select("#land");
|
||||||
const waterMask = defs.select("#water");
|
const waterMask = defs.select("#water");
|
||||||
lineGen.curve(d3.curveBasisClosed);
|
const lineGen = d3.line().curve(d3.curveBasis);
|
||||||
|
|
||||||
for (const i of cells.i) {
|
for (const i of cells.i) {
|
||||||
const startFromEdge = !i && cells.h[i] >= 20;
|
const startFromEdge = !i && cells.h[i] >= 20;
|
||||||
|
|
|
||||||
|
|
@ -503,7 +503,8 @@ window.BurgsAndStates = (function () {
|
||||||
TIME && console.time("drawStateLabels");
|
TIME && console.time("drawStateLabels");
|
||||||
const {cells, features, states} = pack;
|
const {cells, features, states} = pack;
|
||||||
const paths = []; // text paths
|
const paths = []; // text paths
|
||||||
lineGen.curve(d3.curveBundle.beta(1));
|
|
||||||
|
const lineGen = d3.line().curve(d3.curveBundle.beta(1));
|
||||||
const mode = options.stateLabelsMode || "auto";
|
const mode = options.stateLabelsMode || "auto";
|
||||||
|
|
||||||
for (const s of states) {
|
for (const s of states) {
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,6 @@ let rulers;
|
||||||
let biomesData;
|
let biomesData;
|
||||||
let nameBases;
|
let nameBases;
|
||||||
|
|
||||||
let color;
|
|
||||||
let lineGen;
|
|
||||||
|
|
||||||
// defined in main.js
|
// defined in main.js
|
||||||
let graphWidth;
|
let graphWidth;
|
||||||
let graphHeight;
|
let graphHeight;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
|
import {ERROR} from "../config/logging";
|
||||||
|
import {lim, minmax} from "../utils/numberUtils";
|
||||||
import {TIME} from "/src/config/logging";
|
import {TIME} from "/src/config/logging";
|
||||||
import {createTypedArray} from "/src/utils/arrayUtils";
|
import {createTypedArray} from "/src/utils/arrayUtils";
|
||||||
import {findGridCell} from "/src/utils/graphUtils";
|
import {findGridCell} from "/src/utils/graphUtils";
|
||||||
|
import {getNumberInRange, P, rand} from "/src/utils/probabilityUtils";
|
||||||
import {byId} from "/src/utils/shorthands";
|
import {byId} from "/src/utils/shorthands";
|
||||||
import {rand, P, getNumberInRange} from "/src/utils/probabilityUtils";
|
|
||||||
|
|
||||||
window.HeightmapGenerator = (function () {
|
window.HeightmapGenerator = (function () {
|
||||||
let grid = null;
|
let grid = null;
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,7 @@ export class Opisometer extends Measurer {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCurve() {
|
updateCurve() {
|
||||||
lineGen.curve(d3.curveCatmullRom.alpha(0.5));
|
const lineGen = d3.line().curve(d3.curveCatmullRom.alpha(0.5));
|
||||||
const path = round(lineGen(this.points));
|
const path = round(lineGen(this.points));
|
||||||
this.el.selectAll("path").attr("d", path);
|
this.el.selectAll("path").attr("d", path);
|
||||||
|
|
||||||
|
|
@ -470,7 +470,7 @@ export class RouteOpisometer extends Measurer {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCurve() {
|
updateCurve() {
|
||||||
lineGen.curve(d3.curveCatmullRom.alpha(0.5));
|
const lineGen = d3.line().curve(d3.curveCatmullRomClosed.alpha(0.5));
|
||||||
const path = round(lineGen(this.points));
|
const path = round(lineGen(this.points));
|
||||||
this.el.selectAll("path").attr("d", path);
|
this.el.selectAll("path").attr("d", path);
|
||||||
|
|
||||||
|
|
@ -525,7 +525,7 @@ export class Planimeter extends Measurer {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCurve() {
|
updateCurve() {
|
||||||
lineGen.curve(d3.curveCatmullRomClosed.alpha(0.5));
|
const lineGen = d3.line().curve(d3.curveCatmullRomClosed.alpha(0.5));
|
||||||
const path = round(lineGen(this.points));
|
const path = round(lineGen(this.points));
|
||||||
this.el.selectAll("path").attr("d", path);
|
this.el.selectAll("path").attr("d", path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ window.OceanLayers = (function () {
|
||||||
if (outline === "none") return;
|
if (outline === "none") return;
|
||||||
TIME && console.time("drawOceanLayers");
|
TIME && console.time("drawOceanLayers");
|
||||||
|
|
||||||
lineGen.curve(d3.curveBasisClosed);
|
const lineGen = d3.line().curve(d3.curveBasisClosed);
|
||||||
(cells = grid.cells), (pointsN = grid.cells.i.length), (vertices = grid.vertices);
|
(cells = grid.cells), (pointsN = grid.cells.i.length), (vertices = grid.vertices);
|
||||||
const limits = outline === "random" ? randomizeOutline() : outline.split(",").map(s => +s);
|
const limits = outline === "random" ? randomizeOutline() : outline.split(",").map(s => +s);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -401,6 +401,8 @@ window.Rivers = (function () {
|
||||||
return widthFactor * (lengthWidth + fluxWidth) + startingWidth;
|
return widthFactor * (lengthWidth + fluxWidth) + startingWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const lineGen = d3.line().curve(d3.curveBasis);
|
||||||
|
|
||||||
// build polygon from a list of points and calculated offset (width)
|
// build polygon from a list of points and calculated offset (width)
|
||||||
const getRiverPath = function (points, widthFactor, startingWidth = 0) {
|
const getRiverPath = function (points, widthFactor, startingWidth = 0) {
|
||||||
const riverPointsLeft = [];
|
const riverPointsLeft = [];
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,8 @@ window.Routes = (function () {
|
||||||
return paths;
|
return paths;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const lineGen = d3.line().curve(d3.curveBasis);
|
||||||
|
|
||||||
const draw = function (main, small, water) {
|
const draw = function (main, small, water) {
|
||||||
TIME && console.time("drawRoutes");
|
TIME && console.time("drawRoutes");
|
||||||
const {cells, burgs} = pack;
|
const {cells, burgs} = pack;
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,9 @@ export function editCoastline(node = d3.event.target) {
|
||||||
redrawCoastline();
|
redrawCoastline();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lineGen = d3.line().curve(d3.curveBasisClosed);
|
||||||
|
|
||||||
function redrawCoastline() {
|
function redrawCoastline() {
|
||||||
lineGen.curve(d3.curveBasisClosed);
|
|
||||||
const f = +elSelected.attr("data-f");
|
const f = +elSelected.attr("data-f");
|
||||||
const vertices = pack.features[f].vertices;
|
const vertices = pack.features[f].vertices;
|
||||||
const points = clipPoly(
|
const points = clipPoly(
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,10 @@ export function editLabel() {
|
||||||
redrawLabelPath();
|
redrawLabelPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lineGen = d3.line().curve(d3.curveBundle.beta(1));
|
||||||
|
|
||||||
function redrawLabelPath() {
|
function redrawLabelPath() {
|
||||||
const path = document.getElementById("textPath_" + elSelected.attr("id"));
|
const path = document.getElementById("textPath_" + elSelected.attr("id"));
|
||||||
lineGen.curve(d3.curveBundle.beta(1));
|
|
||||||
const points = [];
|
const points = [];
|
||||||
debug
|
debug
|
||||||
.select("#controlPoints")
|
.select("#controlPoints")
|
||||||
|
|
|
||||||
|
|
@ -117,8 +117,9 @@ export function editLake() {
|
||||||
redrawLake();
|
redrawLake();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lineGen = d3.line().curve(d3.curveBasisClosed);
|
||||||
|
|
||||||
function redrawLake() {
|
function redrawLake() {
|
||||||
lineGen.curve(d3.curveBasisClosed);
|
|
||||||
const feature = getLake();
|
const feature = getLake();
|
||||||
const points = feature.vertices.map(v => pack.vertices.p[v]);
|
const points = feature.vertices.map(v => pack.vertices.p[v]);
|
||||||
const d = round(lineGen(points));
|
const d = round(lineGen(points));
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,7 @@ function drawHeightmap() {
|
||||||
const skip = +terrs.attr("skip") + 1;
|
const skip = +terrs.attr("skip") + 1;
|
||||||
const simplification = +terrs.attr("relax");
|
const simplification = +terrs.attr("relax");
|
||||||
|
|
||||||
|
const lineGen = d3.line().curve(d3.curveBasis);
|
||||||
switch (+terrs.attr("curve")) {
|
switch (+terrs.attr("curve")) {
|
||||||
case 0:
|
case 0:
|
||||||
lineGen.curve(d3.curveBasisClosed);
|
lineGen.curve(d3.curveBasisClosed);
|
||||||
|
|
@ -383,7 +384,8 @@ function toggleTemp(event) {
|
||||||
function drawTemp() {
|
function drawTemp() {
|
||||||
TIME && console.time("drawTemp");
|
TIME && console.time("drawTemp");
|
||||||
temperature.selectAll("*").remove();
|
temperature.selectAll("*").remove();
|
||||||
lineGen.curve(d3.curveBasisClosed);
|
|
||||||
|
const lineGen = d3.line().curve(d3.curveBasisClosed);
|
||||||
const scheme = d3.scaleSequential(d3.interpolateSpectral);
|
const scheme = d3.scaleSequential(d3.interpolateSpectral);
|
||||||
const tMax = +temperatureEquatorOutput.max,
|
const tMax = +temperatureEquatorOutput.max,
|
||||||
tMin = +temperatureEquatorOutput.min,
|
tMin = +temperatureEquatorOutput.min,
|
||||||
|
|
@ -1615,7 +1617,6 @@ export function drawRivers() {
|
||||||
rivers.selectAll("*").remove();
|
rivers.selectAll("*").remove();
|
||||||
|
|
||||||
const {addMeandering, getRiverPath} = Rivers;
|
const {addMeandering, getRiverPath} = Rivers;
|
||||||
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
|
|
||||||
|
|
||||||
const riverPaths = pack.rivers.map(({cells, points, i, widthFactor, sourceWidth}) => {
|
const riverPaths = pack.rivers.map(({cells, points, i, widthFactor, sourceWidth}) => {
|
||||||
if (!cells || cells.length < 2) return;
|
if (!cells || cells.length < 2) return;
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,6 @@ export function createRiver() {
|
||||||
const id = "river" + riverId;
|
const id = "river" + riverId;
|
||||||
|
|
||||||
// render river
|
// render river
|
||||||
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
|
|
||||||
viewbox
|
viewbox
|
||||||
.select("#rivers")
|
.select("#rivers")
|
||||||
.append("path")
|
.append("path")
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,6 @@ export function editRiver(id) {
|
||||||
const {widthFactor, sourceWidth} = river;
|
const {widthFactor, sourceWidth} = river;
|
||||||
const meanderedPoints = Rivers.addMeandering(river.cells, river.points);
|
const meanderedPoints = Rivers.addMeandering(river.cells, river.points);
|
||||||
|
|
||||||
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
|
|
||||||
const path = Rivers.getRiverPath(meanderedPoints, widthFactor, sourceWidth);
|
const path = Rivers.getRiverPath(meanderedPoints, widthFactor, sourceWidth);
|
||||||
elSelected.attr("d", path);
|
elSelected.attr("d", path);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,9 @@ export function editRoute(onClick) {
|
||||||
redrawRoute();
|
redrawRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lineGen = d3.line().curve(d3.curveCatmullRom.alpha(0.1));
|
||||||
|
|
||||||
function redrawRoute() {
|
function redrawRoute() {
|
||||||
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
|
|
||||||
const points = [];
|
const points = [];
|
||||||
debug
|
debug
|
||||||
.select("#controlPoints")
|
.select("#controlPoints")
|
||||||
|
|
|
||||||
|
|
@ -691,7 +691,6 @@ function addRiverOnClick() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// render river
|
// render river
|
||||||
lineGen.curve(d3.curveCatmullRom.alpha(0.1));
|
|
||||||
const path = getRiverPath(meanderedPoints, widthFactor);
|
const path = getRiverPath(meanderedPoints, widthFactor);
|
||||||
const id = "river" + riverId;
|
const id = "river" + riverId;
|
||||||
const riversG = viewbox.select("#rivers");
|
const riversG = viewbox.select("#rivers");
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ import {byId} from "./shorthands";
|
||||||
import {Voronoi} from "/src/modules/voronoi";
|
import {Voronoi} from "/src/modules/voronoi";
|
||||||
|
|
||||||
const Delaunator = window.Delaunator;
|
const Delaunator = window.Delaunator;
|
||||||
const graphWidth = window.graphWidth;
|
|
||||||
const graphHeight = window.graphHeight;
|
|
||||||
|
|
||||||
// check if new grid graph should be generated or we can use the existing one
|
// check if new grid graph should be generated or we can use the existing one
|
||||||
export function shouldRegenerateGrid(grid) {
|
export function shouldRegenerateGrid(grid) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue