mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-03-26 00:57:23 +01:00
chore: lint
This commit is contained in:
parent
2018a9f01d
commit
54fd34d3d7
2 changed files with 37 additions and 21 deletions
|
|
@ -1,7 +1,18 @@
|
||||||
import Alea from "alea";
|
import Alea from "alea";
|
||||||
import { min } from 'd3';
|
import { min } from "d3";
|
||||||
import { clipPoly, getGridPolygon, getIsolines, lerp, minmax, normalize, P, ra, rand, rn } from "../utils";
|
import {
|
||||||
import { Point } from "./voronoi";
|
clipPoly,
|
||||||
|
getGridPolygon,
|
||||||
|
getIsolines,
|
||||||
|
lerp,
|
||||||
|
minmax,
|
||||||
|
normalize,
|
||||||
|
P,
|
||||||
|
ra,
|
||||||
|
rand,
|
||||||
|
rn,
|
||||||
|
} from "../utils";
|
||||||
|
import type { Point } from "./voronoi";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
var Ice: IceModule;
|
var Ice: IceModule;
|
||||||
|
|
@ -12,7 +23,7 @@ class IceModule {
|
||||||
private getNextId() {
|
private getNextId() {
|
||||||
if (pack.ice.length === 0) return 0;
|
if (pack.ice.length === 0) return 0;
|
||||||
// find gaps in existing ids
|
// find gaps in existing ids
|
||||||
const existingIds = pack.ice.map(e => e.i).sort((a, b) => a - b);
|
const existingIds = pack.ice.map((e) => e.i).sort((a, b) => a - b);
|
||||||
for (let id = 0; id < existingIds[existingIds.length - 1]; id++) {
|
for (let id = 0; id < existingIds[existingIds.length - 1]; id++) {
|
||||||
if (!existingIds.includes(id)) return id;
|
if (!existingIds.includes(id)) return id;
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +59,7 @@ class IceModule {
|
||||||
pack.ice.push({
|
pack.ice.push({
|
||||||
i: this.getNextId(),
|
i: this.getNextId(),
|
||||||
points: clipped,
|
points: clipped,
|
||||||
type: "glacier"
|
type: "glacier",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +81,7 @@ class IceModule {
|
||||||
const [cx, cy] = grid.points[cellId];
|
const [cx, cy] = grid.points[cellId];
|
||||||
const points = getGridPolygon(cellId, grid).map(([x, y]: Point) => [
|
const points = getGridPolygon(cellId, grid).map(([x, y]: Point) => [
|
||||||
rn(lerp(cx, x, size), 2),
|
rn(lerp(cx, x, size), 2),
|
||||||
rn(lerp(cy, y, size), 2)
|
rn(lerp(cy, y, size), 2),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
pack.ice.push({
|
pack.ice.push({
|
||||||
|
|
@ -78,7 +89,7 @@ class IceModule {
|
||||||
points,
|
points,
|
||||||
type: "iceberg",
|
type: "iceberg",
|
||||||
cellId,
|
cellId,
|
||||||
size
|
size,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +98,7 @@ class IceModule {
|
||||||
const [cx, cy] = grid.points[cellId];
|
const [cx, cy] = grid.points[cellId];
|
||||||
const points = getGridPolygon(cellId, grid).map(([x, y]: Point) => [
|
const points = getGridPolygon(cellId, grid).map(([x, y]: Point) => [
|
||||||
rn(lerp(cx, x, size), 2),
|
rn(lerp(cx, x, size), 2),
|
||||||
rn(lerp(cy, y, size), 2)
|
rn(lerp(cy, y, size), 2),
|
||||||
]);
|
]);
|
||||||
const id = this.getNextId();
|
const id = this.getNextId();
|
||||||
pack.ice.push({
|
pack.ice.push({
|
||||||
|
|
@ -95,27 +106,26 @@ class IceModule {
|
||||||
points,
|
points,
|
||||||
type: "iceberg",
|
type: "iceberg",
|
||||||
cellId,
|
cellId,
|
||||||
size
|
size,
|
||||||
});
|
});
|
||||||
redrawIceberg(id);
|
redrawIceberg(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeIce(id: number) {
|
removeIce(id: number) {
|
||||||
const index = pack.ice.findIndex(element => element.i === id);
|
const index = pack.ice.findIndex((element) => element.i === id);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
const type = pack.ice.find(element => element.i === id).type;
|
const type = pack.ice.find((element) => element.i === id).type;
|
||||||
pack.ice.splice(index, 1);
|
pack.ice.splice(index, 1);
|
||||||
if (type === "glacier") {
|
if (type === "glacier") {
|
||||||
redrawGlacier(id);
|
redrawGlacier(id);
|
||||||
} else {
|
} else {
|
||||||
redrawIceberg(id);
|
redrawIceberg(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
randomizeIcebergShape(id: number) {
|
randomizeIcebergShape(id: number) {
|
||||||
const iceberg = pack.ice.find(element => element.i === id);
|
const iceberg = pack.ice.find((element) => element.i === id);
|
||||||
if (!iceberg) return;
|
if (!iceberg) return;
|
||||||
|
|
||||||
const cellId = iceberg.cellId;
|
const cellId = iceberg.cellId;
|
||||||
|
|
@ -125,17 +135,20 @@ class IceModule {
|
||||||
// Get a different random cell for the polygon template
|
// Get a different random cell for the polygon template
|
||||||
const i = ra(grid.cells.i);
|
const i = ra(grid.cells.i);
|
||||||
const cn = grid.points[i];
|
const cn = grid.points[i];
|
||||||
const poly = getGridPolygon(i, grid).map((p: Point) => [p[0] - cn[0], p[1] - cn[1]]);
|
const poly = getGridPolygon(i, grid).map((p: Point) => [
|
||||||
|
p[0] - cn[0],
|
||||||
|
p[1] - cn[1],
|
||||||
|
]);
|
||||||
const points = poly.map((p: Point) => [
|
const points = poly.map((p: Point) => [
|
||||||
rn(cx + p[0] * size, 2),
|
rn(cx + p[0] * size, 2),
|
||||||
rn(cy + p[1] * size, 2)
|
rn(cy + p[1] * size, 2),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
iceberg.points = points;
|
iceberg.points = points;
|
||||||
}
|
}
|
||||||
|
|
||||||
changeIcebergSize(id: number, newSize: number) {
|
changeIcebergSize(id: number, newSize: number) {
|
||||||
const iceberg = pack.ice.find(element => element.i === id);
|
const iceberg = pack.ice.find((element) => element.i === id);
|
||||||
if (!iceberg) return;
|
if (!iceberg) return;
|
||||||
|
|
||||||
const cellId = iceberg.cellId;
|
const cellId = iceberg.cellId;
|
||||||
|
|
@ -145,10 +158,13 @@ class IceModule {
|
||||||
const flat = iceberg.points.flat();
|
const flat = iceberg.points.flat();
|
||||||
const pairs = [];
|
const pairs = [];
|
||||||
while (flat.length) pairs.push(flat.splice(0, 2));
|
while (flat.length) pairs.push(flat.splice(0, 2));
|
||||||
const poly = pairs.map(p => [(p[0] - cx) / oldSize, (p[1] - cy) / oldSize]);
|
const poly = pairs.map((p) => [
|
||||||
const points = poly.map(p => [
|
(p[0] - cx) / oldSize,
|
||||||
|
(p[1] - cy) / oldSize,
|
||||||
|
]);
|
||||||
|
const points = poly.map((p) => [
|
||||||
rn(cx + p[0] * newSize, 2),
|
rn(cx + p[0] * newSize, 2),
|
||||||
rn(cy + p[1] * newSize, 2)
|
rn(cy + p[1] * newSize, 2),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
iceberg.points = points;
|
iceberg.points = points;
|
||||||
|
|
@ -156,4 +172,4 @@ class IceModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.Ice = new IceModule();
|
window.Ice = new IceModule();
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,4 @@ import "./states-generator";
|
||||||
import "./zones-generator";
|
import "./zones-generator";
|
||||||
import "./religions-generator";
|
import "./religions-generator";
|
||||||
import "./provinces-generator";
|
import "./provinces-generator";
|
||||||
import "./ice";
|
import "./ice";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue