mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-04 17:41:23 +01:00
chore: add biome for linting/formatting + CI action for linting in SRC folder (#1284)
* chore: add npm + vite for progressive enhancement * fix: update Dockerfile to copy only the dist folder contents * fix: update Dockerfile to use multi-stage build for optimized production image * fix: correct nginx config file copy command in Dockerfile * chore: add netlify configuration for build and redirects * fix: add NODE_VERSION to environment in Netlify configuration * remove wrong dist folder * Update package.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: split public and src * migrating all util files from js to ts * feat: Implement HeightmapGenerator and Voronoi module - Added HeightmapGenerator class for generating heightmaps with various tools (Hill, Pit, Range, Trough, Strait, etc.). - Introduced Voronoi class for creating Voronoi diagrams using Delaunator. - Updated index.html to include new modules. - Created index.ts to manage module imports. - Enhanced arrayUtils and graphUtils with type definitions and improved functionality. - Added utility functions for generating grids and calculating Voronoi cells. * chore: add GitHub Actions workflow for deploying to GitHub Pages * fix: update branch name in GitHub Actions workflow from 'main' to 'master' * chore: update package.json to specify Node.js engine version and remove unused launch.json * Initial plan * Update copilot guidelines to reflect NPM/Vite/TypeScript migration Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com> * Update src/modules/heightmap-generator.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/utils/graphUtils.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/modules/heightmap-generator.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * feat: Add TIME and ERROR variables to global scope in HeightmapGenerator * fix: Update base path in vite.config.ts for Netlify deployment * refactor: Migrate features to a new module and remove legacy script reference * refactor: Update feature interfaces and improve type safety in FeatureModule * refactor: Add documentation for markupPack and defineGroups methods in FeatureModule * refactor: Remove legacy ocean-layers.js and migrate functionality to ocean-layers.ts * refactor: Remove river-generator.js script reference and migrate river generation logic to river-generator.ts * refactor: Remove river-generator.js reference and add biomes module * refactor: Migrate lakes functionality to lakes.ts and update related interfaces * refactor: clean up global variable declarations and improve type definitions * refactor: update shoreline calculation and improve type imports in PackedGraph * fix: e2e tests * chore: add biome for linting/formatting * chore: add linting workflow using Biome * refactor: improve code readability by standardizing string quotes and simplifying function calls --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Azgaar <maxganiev@yandex.com> Co-authored-by: Azgaar <azgaar.fmg@yandex.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
This commit is contained in:
parent
e37fce1eed
commit
9db40a5230
31 changed files with 2001 additions and 782 deletions
|
|
@ -1,6 +1,16 @@
|
|||
import { clipPoly, connectVertices, createTypedArray, distanceSquared, isLand, isWater, rn, TYPED_ARRAY_MAX_VALUES, unique } from "../utils";
|
||||
import Alea from "alea";
|
||||
import { polygonArea } from "d3";
|
||||
import {
|
||||
clipPoly,
|
||||
connectVertices,
|
||||
createTypedArray,
|
||||
distanceSquared,
|
||||
isLand,
|
||||
isWater,
|
||||
rn,
|
||||
TYPED_ARRAY_MAX_VALUES,
|
||||
unique,
|
||||
} from "../utils";
|
||||
|
||||
declare global {
|
||||
var Features: FeatureModule;
|
||||
|
|
@ -52,14 +62,24 @@ class FeatureModule {
|
|||
/**
|
||||
* calculate distance to coast for every cell
|
||||
*/
|
||||
private markup({ distanceField, neighbors, start, increment, limit = TYPED_ARRAY_MAX_VALUES.INT8_MAX }: {
|
||||
private markup({
|
||||
distanceField,
|
||||
neighbors,
|
||||
start,
|
||||
increment,
|
||||
limit = TYPED_ARRAY_MAX_VALUES.INT8_MAX,
|
||||
}: {
|
||||
distanceField: Int8Array;
|
||||
neighbors: number[][];
|
||||
start: number;
|
||||
increment: number;
|
||||
limit?: number;
|
||||
}) {
|
||||
for (let distance = start, marked = Infinity; marked > 0 && distance !== limit; distance += increment) {
|
||||
for (
|
||||
let distance = start, marked = Infinity;
|
||||
marked > 0 && distance !== limit;
|
||||
distance += increment
|
||||
) {
|
||||
marked = 0;
|
||||
const prevDistance = distance - increment;
|
||||
for (let cellId = 0; cellId < neighbors.length; cellId++) {
|
||||
|
|
@ -115,11 +135,17 @@ class FeatureModule {
|
|||
const type = land ? "island" : border ? "ocean" : "lake";
|
||||
features.push({ i: featureId, land, border, type });
|
||||
|
||||
queue[0] = featureIds.findIndex(f => f === this.UNMARKED); // find unmarked cell
|
||||
queue[0] = featureIds.indexOf(this.UNMARKED); // find unmarked cell
|
||||
}
|
||||
|
||||
// markup deep ocean cells
|
||||
this.markup({ distanceField, neighbors, start: this.DEEP_WATER, increment: -1, limit: -10 });
|
||||
this.markup({
|
||||
distanceField,
|
||||
neighbors,
|
||||
start: this.DEEP_WATER,
|
||||
increment: -1,
|
||||
limit: -10,
|
||||
});
|
||||
grid.cells.t = distanceField;
|
||||
grid.cells.f = featureIds;
|
||||
grid.features = [0, ...features];
|
||||
|
|
@ -132,15 +158,22 @@ class FeatureModule {
|
|||
*/
|
||||
markupPack() {
|
||||
const defineHaven = (cellId: number) => {
|
||||
const waterCells = neighbors[cellId].filter((index: number) => isWater(index, pack));
|
||||
const distances = waterCells.map((neibCellId: number) => distanceSquared(cells.p[cellId], cells.p[neibCellId]));
|
||||
const waterCells = neighbors[cellId].filter((index: number) =>
|
||||
isWater(index, pack),
|
||||
);
|
||||
const distances = waterCells.map((neibCellId: number) =>
|
||||
distanceSquared(cells.p[cellId], cells.p[neibCellId]),
|
||||
);
|
||||
const closest = distances.indexOf(Math.min.apply(Math, distances));
|
||||
|
||||
haven[cellId] = waterCells[closest];
|
||||
harbor[cellId] = waterCells.length;
|
||||
}
|
||||
};
|
||||
|
||||
const getCellsData = (featureType: string, firstCell: number): [number, number[]] => {
|
||||
const getCellsData = (
|
||||
featureType: string,
|
||||
firstCell: number,
|
||||
): [number, number[]] => {
|
||||
if (featureType === "ocean") return [firstCell, []];
|
||||
|
||||
const getType = (cellId: number) => featureIds[cellId];
|
||||
|
|
@ -153,29 +186,55 @@ class FeatureModule {
|
|||
return [startCell, featureVertices];
|
||||
|
||||
function findOnBorderCell(firstCell: number) {
|
||||
const isOnBorder = (cellId: number) => borderCells[cellId] || neighbors[cellId].some(ofDifferentType);
|
||||
const isOnBorder = (cellId: number) =>
|
||||
borderCells[cellId] || neighbors[cellId].some(ofDifferentType);
|
||||
if (isOnBorder(firstCell)) return firstCell;
|
||||
|
||||
const startCell = cells.i.filter(ofSameType).find(isOnBorder);
|
||||
if (startCell === undefined)
|
||||
throw new Error(`Markup: firstCell ${firstCell} is not on the feature or map border`);
|
||||
throw new Error(
|
||||
`Markup: firstCell ${firstCell} is not on the feature or map border`,
|
||||
);
|
||||
|
||||
return startCell;
|
||||
}
|
||||
|
||||
function getFeatureVertices(startCell: number) {
|
||||
const startingVertex = cells.v[startCell].find((v: number) => vertices.c[v].some(ofDifferentType));
|
||||
const startingVertex = cells.v[startCell].find((v: number) =>
|
||||
vertices.c[v].some(ofDifferentType),
|
||||
);
|
||||
if (startingVertex === undefined)
|
||||
throw new Error(`Markup: startingVertex for cell ${startCell} is not found`);
|
||||
throw new Error(
|
||||
`Markup: startingVertex for cell ${startCell} is not found`,
|
||||
);
|
||||
|
||||
return connectVertices({ vertices, startingVertex, ofSameType, closeRing: false });
|
||||
return connectVertices({
|
||||
vertices,
|
||||
startingVertex,
|
||||
ofSameType,
|
||||
closeRing: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const addFeature = ({ firstCell, land, border, featureId, totalCells }: { firstCell: number; land: boolean; border: boolean; featureId: number; totalCells: number }): PackedGraphFeature => {
|
||||
const addFeature = ({
|
||||
firstCell,
|
||||
land,
|
||||
border,
|
||||
featureId,
|
||||
totalCells,
|
||||
}: {
|
||||
firstCell: number;
|
||||
land: boolean;
|
||||
border: boolean;
|
||||
featureId: number;
|
||||
totalCells: number;
|
||||
}): PackedGraphFeature => {
|
||||
const type = land ? "island" : border ? "ocean" : "lake";
|
||||
const [startCell, featureVertices] = getCellsData(type, firstCell);
|
||||
const points = clipPoly(featureVertices.map((vertex: number) => vertices.p[vertex]));
|
||||
const points = clipPoly(
|
||||
featureVertices.map((vertex: number) => vertices.p[vertex]),
|
||||
);
|
||||
const area = polygonArea(points); // feature perimiter area
|
||||
const absArea = Math.abs(rn(area));
|
||||
|
||||
|
|
@ -193,20 +252,20 @@ class FeatureModule {
|
|||
};
|
||||
|
||||
if (type === "lake") {
|
||||
if (area > 0) feature.vertices = (feature.vertices as number[]).reverse();
|
||||
if (area > 0)
|
||||
feature.vertices = (feature.vertices as number[]).reverse();
|
||||
feature.shoreline = unique(
|
||||
(feature.vertices as number[])
|
||||
.flatMap(
|
||||
vertexIndex => vertices.c[vertexIndex].filter((index) => isLand(index, pack))
|
||||
)
|
||||
(feature.vertices as number[]).flatMap((vertexIndex) =>
|
||||
vertices.c[vertexIndex].filter((index) => isLand(index, pack)),
|
||||
),
|
||||
);
|
||||
feature.height = Lakes.getHeight(feature as PackedGraphFeature);
|
||||
}
|
||||
|
||||
return {
|
||||
...feature
|
||||
...feature,
|
||||
} as PackedGraphFeature;
|
||||
}
|
||||
};
|
||||
|
||||
TIME && console.time("markupPack");
|
||||
|
||||
|
|
@ -217,7 +276,10 @@ class FeatureModule {
|
|||
|
||||
const distanceField = new Int8Array(packCellsNumber); // pack.cells.t
|
||||
const featureIds = new Uint16Array(packCellsNumber); // pack.cells.f
|
||||
const haven = createTypedArray({ maxValue: packCellsNumber, length: packCellsNumber }); // haven: opposite water cell
|
||||
const haven = createTypedArray({
|
||||
maxValue: packCellsNumber,
|
||||
length: packCellsNumber,
|
||||
}); // haven: opposite water cell
|
||||
const harbor = new Uint8Array(packCellsNumber); // harbor: number of adjacent water cells
|
||||
const features: PackedGraphFeature[] = [];
|
||||
|
||||
|
|
@ -242,9 +304,15 @@ class FeatureModule {
|
|||
distanceField[neighborId] = this.WATER_COAST;
|
||||
if (!haven[cellId]) defineHaven(cellId);
|
||||
} else if (land && isNeibLand) {
|
||||
if (distanceField[neighborId] === this.UNMARKED && distanceField[cellId] === this.LAND_COAST)
|
||||
if (
|
||||
distanceField[neighborId] === this.UNMARKED &&
|
||||
distanceField[cellId] === this.LAND_COAST
|
||||
)
|
||||
distanceField[neighborId] = this.LANDLOCKED;
|
||||
else if (distanceField[cellId] === this.UNMARKED && distanceField[neighborId] === this.LAND_COAST)
|
||||
else if (
|
||||
distanceField[cellId] === this.UNMARKED &&
|
||||
distanceField[neighborId] === this.LAND_COAST
|
||||
)
|
||||
distanceField[cellId] = this.LANDLOCKED;
|
||||
}
|
||||
|
||||
|
|
@ -256,12 +324,25 @@ class FeatureModule {
|
|||
}
|
||||
}
|
||||
|
||||
features.push(addFeature({ firstCell, land, border, featureId, totalCells }));
|
||||
queue[0] = featureIds.findIndex(f => f === this.UNMARKED); // find unmarked cell
|
||||
features.push(
|
||||
addFeature({ firstCell, land, border, featureId, totalCells }),
|
||||
);
|
||||
queue[0] = featureIds.indexOf(this.UNMARKED); // find unmarked cell
|
||||
}
|
||||
|
||||
this.markup({ distanceField, neighbors, start: this.DEEPER_LAND, increment: 1 }); // markup pack land
|
||||
this.markup({ distanceField, neighbors, start: this.DEEP_WATER, increment: -1, limit: -10 }); // markup pack water
|
||||
this.markup({
|
||||
distanceField,
|
||||
neighbors,
|
||||
start: this.DEEPER_LAND,
|
||||
increment: 1,
|
||||
}); // markup pack land
|
||||
this.markup({
|
||||
distanceField,
|
||||
neighbors,
|
||||
start: this.DEEP_WATER,
|
||||
increment: -1,
|
||||
limit: -10,
|
||||
}); // markup pack water
|
||||
|
||||
pack.cells.t = distanceField;
|
||||
pack.cells.f = featureIds;
|
||||
|
|
@ -287,34 +368,40 @@ class FeatureModule {
|
|||
if (feature.cells > CONTINENT_MIN_SIZE) return "continent";
|
||||
if (feature.cells > ISLAND_MIN_SIZE) return "island";
|
||||
return "isle";
|
||||
}
|
||||
};
|
||||
|
||||
const defineOceanGroup = (feature: PackedGraphFeature) => {
|
||||
if (feature.cells > OCEAN_MIN_SIZE) return "ocean";
|
||||
if (feature.cells > SEA_MIN_SIZE) return "sea";
|
||||
return "gulf";
|
||||
}
|
||||
};
|
||||
|
||||
const defineLakeGroup = (feature: PackedGraphFeature) => {
|
||||
if (feature.temp < -3) return "frozen";
|
||||
if (feature.height > 60 && feature.cells < 10 && feature.firstCell % 10 === 0) return "lava";
|
||||
if (
|
||||
feature.height > 60 &&
|
||||
feature.cells < 10 &&
|
||||
feature.firstCell % 10 === 0
|
||||
)
|
||||
return "lava";
|
||||
|
||||
if (!feature.inlets && !feature.outlet) {
|
||||
if (feature.evaporation > feature.flux * 4) return "dry";
|
||||
if (feature.cells < 3 && feature.firstCell % 10 === 0) return "sinkhole";
|
||||
if (feature.cells < 3 && feature.firstCell % 10 === 0)
|
||||
return "sinkhole";
|
||||
}
|
||||
|
||||
if (!feature.outlet && feature.evaporation > feature.flux) return "salt";
|
||||
|
||||
return "freshwater";
|
||||
}
|
||||
};
|
||||
|
||||
const defineGroup = (feature: PackedGraphFeature) => {
|
||||
if (feature.type === "island") return defineIslandGroup(feature);
|
||||
if (feature.type === "ocean") return defineOceanGroup(feature);
|
||||
if (feature.type === "lake") return defineLakeGroup(feature);
|
||||
throw new Error(`Markup: unknown feature type ${feature.type}`);
|
||||
}
|
||||
};
|
||||
|
||||
for (const feature of pack.features) {
|
||||
if (!feature || feature.type === "ocean") continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue