diff --git a/src/scripts/rankCells.js b/src/scripts/rankCells.ts similarity index 98% rename from src/scripts/rankCells.js rename to src/scripts/rankCells.ts index 0d738949..08ff3d55 100644 --- a/src/scripts/rankCells.js +++ b/src/scripts/rankCells.ts @@ -1,3 +1,4 @@ +// @ts-nocheck global variables import {TIME} from "config/logging"; import {normalize} from "utils/numberUtils"; diff --git a/src/scripts/reGraph.js b/src/scripts/reGraph.ts similarity index 89% rename from src/scripts/reGraph.js rename to src/scripts/reGraph.ts index 6fdc24ca..71e28f9b 100644 --- a/src/scripts/reGraph.js +++ b/src/scripts/reGraph.ts @@ -1,3 +1,4 @@ +// @ts-nocheck global variables import {TIME} from "config/logging"; import {UINT16_MAX} from "constants"; import {createTypedArray} from "utils/arrayUtils"; @@ -8,7 +9,7 @@ import {rn} from "utils/numberUtils"; export function reGraph() { TIME && console.time("reGraph"); const {cells: gridCells, points, features} = grid; - const newCells = {p: [], g: [], h: []}; // store new data + const newCells: {p: number[][]; g: number[]; h: number[]} = {p: [], g: [], h: []}; // store new data const spacing2 = grid.spacing ** 2; for (const i of gridCells.i) { @@ -36,13 +37,13 @@ export function reGraph() { } } - function addNewPoint(i, x, y, height) { + function addNewPoint(i: number, x: number, y: number, height: number) { newCells.p.push([x, y]); newCells.g.push(i); newCells.h.push(height); } - function getCellArea(i) { + function getCellArea(i: number) { const area = Math.abs(d3.polygonArea(getPackPolygon(i))); return Math.min(area, UINT16_MAX); } diff --git a/src/scripts/statistics b/src/scripts/statistics.ts similarity index 89% rename from src/scripts/statistics rename to src/scripts/statistics.ts index d437f715..606befb2 100644 --- a/src/scripts/statistics +++ b/src/scripts/statistics.ts @@ -1,11 +1,12 @@ +// @ts-nocheck global variables import {INFO} from "config/logging"; -import {byId} from "utils/shorthands"; import {heightmapTemplates} from "config/heightmap-templates"; import {locked} from "scripts/options/lock"; +import {getInputValue} from "utils/nodeUtils"; // show map stats on generation complete export function showStatistics() { - const heightmap = byId("templateInput").value; + const heightmap = getInputValue("templateInput"); const isTemplate = heightmap in heightmapTemplates; const heightmapType = isTemplate ? "template" : "precreated"; const isRandomTemplate = isTemplate && !locked("template") ? "random " : ""; diff --git a/src/utils/arrayUtils.ts b/src/utils/arrayUtils.ts index 9fead55d..8786fca6 100644 --- a/src/utils/arrayUtils.ts +++ b/src/utils/arrayUtils.ts @@ -8,16 +8,25 @@ export function unique(array: T[]) { return [...new Set(array)]; } -interface ICreateTypedArray { +interface ICreateTypesArrayLength { maxValue: number; length: number; - from?: ArrayLike; } -export function createTypedArray({maxValue, length, from}: ICreateTypedArray) { - const typedArray = getTypedArray(maxValue); - if (!from) return new typedArray(length); - return typedArray.from(from); +interface ICreateTypesArrayFrom { + maxValue: number; + from: ArrayLike; +} + +export function createTypedArray(params: ICreateTypesArrayLength | ICreateTypesArrayFrom) { + const typedArray = getTypedArray(params.maxValue); + if ("from" in params) { + typedArray.from(params.from); + } else if ("length" in params) { + return new typedArray(params.length); + } + + return typedArray; } function getTypedArray(maxValue: number) {