chore: lint

This commit is contained in:
Marc Emmanuel 2026-02-08 10:00:04 +01:00
parent 2018a9f01d
commit 54fd34d3d7
2 changed files with 37 additions and 21 deletions

View file

@ -1,7 +1,18 @@
import Alea from "alea";
import { min } from 'd3';
import { clipPoly, getGridPolygon, getIsolines, lerp, minmax, normalize, P, ra, rand, rn } from "../utils";
import { Point } from "./voronoi";
import { min } from "d3";
import {
clipPoly,
getGridPolygon,
getIsolines,
lerp,
minmax,
normalize,
P,
ra,
rand,
rn,
} from "../utils";
import type { Point } from "./voronoi";
declare global {
var Ice: IceModule;
@ -12,7 +23,7 @@ class IceModule {
private getNextId() {
if (pack.ice.length === 0) return 0;
// 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++) {
if (!existingIds.includes(id)) return id;
}
@ -48,7 +59,7 @@ class IceModule {
pack.ice.push({
i: this.getNextId(),
points: clipped,
type: "glacier"
type: "glacier",
});
});
}
@ -70,7 +81,7 @@ class IceModule {
const [cx, cy] = grid.points[cellId];
const points = getGridPolygon(cellId, grid).map(([x, y]: Point) => [
rn(lerp(cx, x, size), 2),
rn(lerp(cy, y, size), 2)
rn(lerp(cy, y, size), 2),
]);
pack.ice.push({
@ -78,7 +89,7 @@ class IceModule {
points,
type: "iceberg",
cellId,
size
size,
});
}
}
@ -87,7 +98,7 @@ class IceModule {
const [cx, cy] = grid.points[cellId];
const points = getGridPolygon(cellId, grid).map(([x, y]: Point) => [
rn(lerp(cx, x, size), 2),
rn(lerp(cy, y, size), 2)
rn(lerp(cy, y, size), 2),
]);
const id = this.getNextId();
pack.ice.push({
@ -95,27 +106,26 @@ class IceModule {
points,
type: "iceberg",
cellId,
size
size,
});
redrawIceberg(id);
}
removeIce(id: number) {
const index = pack.ice.findIndex(element => element.i === id);
const index = pack.ice.findIndex((element) => element.i === id);
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);
if (type === "glacier") {
redrawGlacier(id);
} else {
redrawIceberg(id);
}
}
}
randomizeIcebergShape(id: number) {
const iceberg = pack.ice.find(element => element.i === id);
const iceberg = pack.ice.find((element) => element.i === id);
if (!iceberg) return;
const cellId = iceberg.cellId;
@ -125,17 +135,20 @@ class IceModule {
// Get a different random cell for the polygon template
const i = ra(grid.cells.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) => [
rn(cx + p[0] * size, 2),
rn(cy + p[1] * size, 2)
rn(cy + p[1] * size, 2),
]);
iceberg.points = points;
}
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;
const cellId = iceberg.cellId;
@ -145,10 +158,13 @@ class IceModule {
const flat = iceberg.points.flat();
const pairs = [];
while (flat.length) pairs.push(flat.splice(0, 2));
const poly = pairs.map(p => [(p[0] - cx) / oldSize, (p[1] - cy) / oldSize]);
const points = poly.map(p => [
const poly = pairs.map((p) => [
(p[0] - cx) / oldSize,
(p[1] - cy) / oldSize,
]);
const points = poly.map((p) => [
rn(cx + p[0] * newSize, 2),
rn(cy + p[1] * newSize, 2)
rn(cy + p[1] * newSize, 2),
]);
iceberg.points = points;
@ -156,4 +172,4 @@ class IceModule {
}
}
window.Ice = new IceModule();
window.Ice = new IceModule();

View file

@ -13,4 +13,4 @@ import "./states-generator";
import "./zones-generator";
import "./religions-generator";
import "./provinces-generator";
import "./ice";
import "./ice";