mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: lake name generator
This commit is contained in:
parent
4b874246e3
commit
b2f16c4b8f
6 changed files with 25 additions and 27 deletions
|
|
@ -252,7 +252,6 @@ export function open(options) {
|
|||
BurgsAndStates.drawStateLabels();
|
||||
|
||||
Rivers.specify();
|
||||
Lakes.generateName();
|
||||
|
||||
Military.generate();
|
||||
Markers.generate();
|
||||
|
|
@ -441,7 +440,6 @@ export function open(options) {
|
|||
|
||||
if (erosionAllowed) {
|
||||
Rivers.specify();
|
||||
Lakes.generateName();
|
||||
}
|
||||
|
||||
// restore zones from grid
|
||||
|
|
|
|||
|
|
@ -8,20 +8,6 @@ import {DISTANCE_FIELD, MIN_LAND_HEIGHT} from "config/generation";
|
|||
import {byId} from "utils/shorthands";
|
||||
|
||||
window.Lakes = (function () {
|
||||
const generateName = function () {
|
||||
Math.random = aleaPRNG(seed);
|
||||
for (const feature of pack.features) {
|
||||
if (feature.type !== "lake") continue;
|
||||
feature.name = getName(feature);
|
||||
}
|
||||
};
|
||||
|
||||
const getName = function (feature) {
|
||||
const landCell = pack.cells.c[feature.firstCell].find(c => pack.cells.h[c] >= 20);
|
||||
const culture = pack.cells.culture[landCell];
|
||||
return Names.getCulture(culture);
|
||||
};
|
||||
|
||||
const {LAND_COAST, WATER_COAST} = DISTANCE_FIELD;
|
||||
|
||||
function addLakesInDeepDepressions(grid: IGraph & Partial<IGrid>) {
|
||||
|
|
|
|||
|
|
@ -281,7 +281,6 @@ window.Submap = (function () {
|
|||
BurgsAndStates.drawStateLabels();
|
||||
|
||||
Rivers.specify();
|
||||
Lakes.generateName();
|
||||
|
||||
stage("Porting military.");
|
||||
for (const s of pack.states) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
// @ts-nocheckd
|
||||
import * as d3 from "d3";
|
||||
|
||||
import {rn} from "utils/numberUtils";
|
||||
import {getRealHeight} from "utils/unitUtils";
|
||||
|
||||
const {Names} = window;
|
||||
|
||||
export interface ILakeClimateData extends IPackFeatureLake {
|
||||
flux: number;
|
||||
temp: number;
|
||||
|
|
@ -45,7 +46,7 @@ export const getClimateData = function (
|
|||
return lakeData;
|
||||
};
|
||||
|
||||
export const mergeLakeDataToFeatures = function (
|
||||
export const mergeLakeData = function (
|
||||
features: TPackFeatures,
|
||||
lakeData: ILakeClimateData[],
|
||||
rivers: Pick<IRiver, "i">[]
|
||||
|
|
@ -101,3 +102,17 @@ function defineLakeGroup({
|
|||
|
||||
return "freshwater";
|
||||
}
|
||||
|
||||
export function generateLakeNames(features: TPackFeatures, culture: UintArray) {
|
||||
const updatedFeatures = features.map(feature => {
|
||||
if (!feature) return 0;
|
||||
if (feature.type !== "lake") return feature;
|
||||
|
||||
const landCell = feature.shoreline[0];
|
||||
const cultureId = culture[landCell];
|
||||
const name = Names.getCulture(cultureId) as string;
|
||||
return {...feature, name};
|
||||
});
|
||||
|
||||
return updatedFeatures as TPackFeatures;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ export function createPack(grid: IGrid): IPack {
|
|||
// BurgsAndStates.drawStateLabels();
|
||||
|
||||
// Rivers.specify();
|
||||
// Lakes.generateName();
|
||||
// const updatedFeatures = generateLakeNames();
|
||||
|
||||
// Military.generate();
|
||||
// Markers.generate();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import {DISTANCE_FIELD, MAX_HEIGHT, MIN_LAND_HEIGHT} from "config/generation";
|
|||
import {getInputNumber} from "utils/nodeUtils";
|
||||
import {pick} from "utils/functionUtils";
|
||||
import {byId} from "utils/shorthands";
|
||||
import {mergeLakeDataToFeatures, getClimateData, ILakeClimateData} from "./lakes";
|
||||
import {mergeLakeData, getClimateData, ILakeClimateData} from "./lakes";
|
||||
import {drawArrow} from "utils/debugUtils";
|
||||
|
||||
const {Rivers} = window;
|
||||
|
|
@ -44,7 +44,7 @@ export function generateRivers(
|
|||
const {r, conf, rivers} = defineRivers();
|
||||
const heights = downcutRivers(currentCellHeights);
|
||||
|
||||
const mergedFeatures = mergeLakeDataToFeatures(features, lakeData, rivers);
|
||||
const mergedFeatures = mergeLakeData(features, lakeData, rivers);
|
||||
|
||||
TIME && console.timeEnd("generateRivers");
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ export function generateRivers(
|
|||
}
|
||||
|
||||
lake.outlet = riverIds[lakeCell];
|
||||
flowDown(lakeCell, cellId, flux[lakeCell], lake.outlet);
|
||||
flowDown(cellId, flux[lakeCell], lake.outlet);
|
||||
}
|
||||
|
||||
if (lakesDrainingToCell.length && lakesDrainingToCell[0].outlet) {
|
||||
|
|
@ -125,6 +125,8 @@ export function generateRivers(
|
|||
min = cells.c[cellId].sort((a, b) => currentCellHeights[a] - currentCellHeights[b])[0];
|
||||
}
|
||||
|
||||
// drawArrow(cells.p[fromCell], cells.p[toCell]);
|
||||
|
||||
// cells is depressed
|
||||
if (currentCellHeights[cellId] <= currentCellHeights[min]) return;
|
||||
|
||||
|
|
@ -141,14 +143,12 @@ export function generateRivers(
|
|||
nextRiverId++;
|
||||
}
|
||||
|
||||
flowDown(cellId, min, flux[cellId], riverIds[cellId]);
|
||||
flowDown(min, flux[cellId], riverIds[cellId]);
|
||||
});
|
||||
|
||||
return {flux, lakeData};
|
||||
|
||||
function flowDown(fromCell: number, toCell: number, fromFlux: number, riverId: number) {
|
||||
// drawArrow(cells.p[fromCell], cells.p[toCell]);
|
||||
|
||||
function flowDown(toCell: number, fromFlux: number, riverId: number) {
|
||||
const toFlux = flux[toCell] - confluence[toCell];
|
||||
const toRiver = riverIds[toCell];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue