mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-18 02:01:22 +01:00
refactor: generation script
This commit is contained in:
parent
c0f6ce00ef
commit
87d8c1024d
31 changed files with 364 additions and 324 deletions
|
|
@ -168,6 +168,8 @@ optionsContent.on("click", function (event) {
|
|||
else if (id === "translateExtent") toggleTranslateExtent(event.target);
|
||||
else if (id === "speakerTest") testSpeaker();
|
||||
else if (id === "themeColorRestore") restoreDefaultThemeColor();
|
||||
else if (id === "configureWorld") openDialog("worldConfigurator");
|
||||
else if (id === "optionsReset") restoreDefaultOptions();
|
||||
});
|
||||
|
||||
function mapSizeInputChange() {
|
||||
|
|
@ -1025,6 +1027,7 @@ export function toggle3dOptions() {
|
|||
isLoaded = true;
|
||||
|
||||
byId("options3dUpdate").on("click", ThreeD.update);
|
||||
byId("options3dConfigureWorld").on("click", () => openDialog("worldConfigurator"));
|
||||
byId("options3dSave").on("click", ThreeD.saveScreenshot);
|
||||
byId("options3dOBJSave").on("click", ThreeD.saveOBJ);
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ export function createRiver() {
|
|||
const defaultWidthFactor = rn(1 / (pointsInput.dataset.cells / 10000) ** 0.25, 2);
|
||||
const widthFactor = 1.2 * defaultWidthFactor;
|
||||
|
||||
const meanderedPoints = addMeandering(riverCells);
|
||||
const meanderedPoints = addMeandering(pack, riverCells);
|
||||
|
||||
const discharge = cells.fl[mouth]; // m3 in second
|
||||
const length = getApproximateLength(meanderedPoints);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export function editRiver(id) {
|
|||
|
||||
const river = getRiver();
|
||||
const {cells, points} = river;
|
||||
const riverPoints = Rivers.getRiverPoints(cells, points);
|
||||
const riverPoints = Rivers.getRiverPoints(pack, cells, points);
|
||||
drawControlPoints(riverPoints);
|
||||
drawCells(cells);
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ export function editRiver(id) {
|
|||
function updateRiverWidth(river) {
|
||||
const {addMeandering, getWidth, getOffset} = Rivers;
|
||||
const {cells, discharge, widthFactor, sourceWidth} = river;
|
||||
const meanderedPoints = addMeandering(cells);
|
||||
const meanderedPoints = addMeandering(pack, cells);
|
||||
river.width = getWidth(getOffset(discharge, meanderedPoints.length, widthFactor, sourceWidth));
|
||||
|
||||
const width = `${rn(river.width * distanceScaleInput.value, 3)} ${distanceUnitInput.value}`;
|
||||
|
|
@ -169,7 +169,7 @@ export function editRiver(id) {
|
|||
river.cells = river.points.map(([x, y]) => findCell(x, y));
|
||||
|
||||
const {widthFactor, sourceWidth} = river;
|
||||
const meanderedPoints = Rivers.addMeandering(river.cells, river.points);
|
||||
const meanderedPoints = Rivers.addMeandering(pack, river.cells, river.points);
|
||||
|
||||
const path = Rivers.getRiverPath(meanderedPoints, widthFactor, sourceWidth);
|
||||
elSelected.attr("d", path);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {debounce} from "utils/functionUtils";
|
|||
import {restoreLayers} from "layers";
|
||||
import {undraw} from "scripts/generation/generation";
|
||||
import {closeDialogs} from "dialogs/utils";
|
||||
import {openDialog} from "dialogs";
|
||||
|
||||
window.UISubmap = (function () {
|
||||
byId("submapPointsInput").addEventListener("input", function () {
|
||||
|
|
@ -312,7 +313,7 @@ window.UISubmap = (function () {
|
|||
|
||||
restoreLayers();
|
||||
if (ThreeD.options.isOn) ThreeD.redraw();
|
||||
if ($("#worldConfigurator").is(":visible")) editWorld();
|
||||
if ($("#worldConfigurator").is(":visible")) openDialog("worldConfigurator");
|
||||
}
|
||||
|
||||
function changeStyles(scale) {
|
||||
|
|
|
|||
|
|
@ -131,11 +131,11 @@ async function openEmblemEditor() {
|
|||
}
|
||||
|
||||
function regenerateRivers() {
|
||||
Rivers.generate();
|
||||
Rivers.generate(pack, grid);
|
||||
Lakes.defineGroup();
|
||||
Rivers.specify();
|
||||
if (!layerIsOn("toggleRivers")) toggleLayer("toggleRivers");
|
||||
else renderLayer("rivers");
|
||||
else renderLayer("rivers", pack);
|
||||
}
|
||||
|
||||
function recalculatePopulation() {
|
||||
|
|
@ -588,8 +588,8 @@ function addRiverOnClick() {
|
|||
const initialFlux = grid.cells.prec[cells.g[i]];
|
||||
cells.fl[i] = initialFlux;
|
||||
|
||||
const h = alterHeights();
|
||||
resolveDepressions(h);
|
||||
const h = alterHeights(pacl.cells);
|
||||
resolveDepressions(pack, h);
|
||||
|
||||
while (i) {
|
||||
cells.r[i] = riverId;
|
||||
|
|
@ -663,7 +663,7 @@ function addRiverOnClick() {
|
|||
const defaultWidthFactor = rn(1 / (pointsInput.dataset.cells / 10000) ** 0.25, 2);
|
||||
const widthFactor =
|
||||
river?.widthFactor || (!parent || parent === riverId ? defaultWidthFactor * 1.2 : defaultWidthFactor);
|
||||
const meanderedPoints = addMeandering(riverCells);
|
||||
const meanderedPoints = addMeandering(pack, riverCells);
|
||||
|
||||
const discharge = cells.fl[mouth]; // m3 in second
|
||||
const length = getApproximateLength(meanderedPoints);
|
||||
|
|
@ -704,7 +704,7 @@ function addRiverOnClick() {
|
|||
riversG.append("path").attr("id", id).attr("d", path);
|
||||
|
||||
if (d3.event.shiftKey === false) {
|
||||
Lakes.cleanupLakeData();
|
||||
Lakes.cleanupLakeData(pack);
|
||||
unpressClickToAddButton();
|
||||
document.getElementById("addNewRiver").classList.remove("pressed");
|
||||
if (addNewRiver.offsetParent) riversOverviewRefresh.click();
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ import {renderLayer} from "layers";
|
|||
|
||||
let isLoaded = false;
|
||||
|
||||
export function editWorld() {
|
||||
if (customization) return;
|
||||
export function open() {
|
||||
$("#worldConfigurator").dialog({
|
||||
title: "Configure World",
|
||||
resizable: false,
|
||||
|
|
@ -63,7 +62,7 @@ export function editWorld() {
|
|||
calculateTemperatures(grid);
|
||||
generatePrecipitation(grid);
|
||||
const heights = new Uint8Array(pack.cells.h);
|
||||
Rivers.generate();
|
||||
Rivers.generate(pack, grid);
|
||||
Lakes.defineGroup();
|
||||
Rivers.specify();
|
||||
pack.cells.h = new Float32Array(heights);
|
||||
|
|
@ -73,7 +72,7 @@ export function editWorld() {
|
|||
if (layerIsOn("togglePrec")) renderLayer("precipitation");
|
||||
if (layerIsOn("toggleBiomes")) renderLayer("biomes");
|
||||
if (layerIsOn("toggleCoordinates")) drawCoordinates();
|
||||
if (layerIsOn("toggleRivers")) renderLayer("rivers");
|
||||
if (layerIsOn("toggleRivers")) renderLayer("rivers", pack);
|
||||
if (document.getElementById("canvas3d")) setTimeout(ThreeD.update(), 500);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue