diff --git a/index.html b/index.html
index d10e35b5..012df0bc 100644
--- a/index.html
+++ b/index.html
@@ -7675,8 +7675,6 @@
-
-
diff --git a/modules/activeZooming.js b/modules/activeZooming.js
index 20097bbb..d60438aa 100644
--- a/modules/activeZooming.js
+++ b/modules/activeZooming.js
@@ -1,4 +1,6 @@
-window.handleZoom = function (isScaleChanged, isPositionChanged) {
+import {rn} from "/src/utils/numberUtils";
+
+export function handleZoom(isScaleChanged, isPositionChanged) {
viewbox.attr("transform", `translate(${viewX} ${viewY}) scale(${scale})`);
if (isPositionChanged) drawCoordinates();
@@ -21,7 +23,7 @@ window.handleZoom = function (isScaleChanged, isPositionChanged) {
ctx.setTransform(scale, 0, 0, scale, viewX, viewY);
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
}
-};
+}
// active zooming feature
export function invokeActiveZooming() {
diff --git a/modules/burgs-and-states.js b/modules/burgs-and-states.js
index 69db110d..dbdfd184 100644
--- a/modules/burgs-and-states.js
+++ b/modules/burgs-and-states.js
@@ -2,6 +2,7 @@ import {TIME} from "/src/config/logging";
import {findCell} from "/src/utils/graphUtils";
import {layerIsOn} from "./ui/layers";
import {getColors, getRandomColor, getMixedColor} from "/src/utils/colorUtils";
+import {rn, minmax} from "/src/utils/numberUtils";
window.BurgsAndStates = (function () {
const generate = function () {
diff --git a/modules/cultures-generator.js b/modules/cultures-generator.js
index c281089d..cd013f7c 100644
--- a/modules/cultures-generator.js
+++ b/modules/cultures-generator.js
@@ -1,5 +1,6 @@
import {TIME} from "/src/config/logging";
import {getColors} from "/src/utils/colorUtils";
+import {rn, minmax} from "/src/utils/numberUtils";
window.Cultures = (function () {
let cells;
diff --git a/modules/dynamic/auto-update.js b/modules/dynamic/auto-update.js
index 70e5bcd8..2808b65e 100644
--- a/modules/dynamic/auto-update.js
+++ b/modules/dynamic/auto-update.js
@@ -1,4 +1,5 @@
import {findCell} from "/src/utils/graphUtils";
+import {rn} from "/src/utils/numberUtils";
// update old .map version to the current one
export function resolveVersionConflicts(version) {
diff --git a/modules/dynamic/editors/cultures-editor.js b/modules/dynamic/editors/cultures-editor.js
index a1969ca3..1ff37614 100644
--- a/modules/dynamic/editors/cultures-editor.js
+++ b/modules/dynamic/editors/cultures-editor.js
@@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
import {byId} from "/src/utils/shorthands";
+import {rn} from "/src/utils/numberUtils";
const $body = insertEditorHtml();
addListeners();
diff --git a/modules/dynamic/editors/religions-editor.js b/modules/dynamic/editors/religions-editor.js
index 3c582dd7..fd173e20 100644
--- a/modules/dynamic/editors/religions-editor.js
+++ b/modules/dynamic/editors/religions-editor.js
@@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
import {byId} from "/src/utils/shorthands";
+import {rn} from "/src/utils/numberUtils";
const $body = insertEditorHtml();
addListeners();
diff --git a/modules/dynamic/editors/states-editor.js b/modules/dynamic/editors/states-editor.js
index b6abd930..875ebca8 100644
--- a/modules/dynamic/editors/states-editor.js
+++ b/modules/dynamic/editors/states-editor.js
@@ -3,6 +3,7 @@ import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
import {byId} from "/src/utils/shorthands";
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
import {getRandomColor, getMixedColor} from "/src/utils/colorUtils";
+import {rn} from "/src/utils/numberUtils";
const $body = insertEditorHtml();
addListeners();
diff --git a/modules/dynamic/overview/charts-overview.js b/modules/dynamic/overview/charts-overview.js
index a491fcdf..0b659f8f 100644
--- a/modules/dynamic/overview/charts-overview.js
+++ b/modules/dynamic/overview/charts-overview.js
@@ -2,6 +2,7 @@ import {rollups} from "../../../utils/functionUtils.js";
import {isWater} from "/src/utils/graphUtils";
import {tip} from "/src/scripts/tooltips";
import {byId} from "/src/utils/shorthands";
+import {rn} from "/src/utils/numberUtils";
const entitiesMap = {
states: {
diff --git a/modules/io/export.js b/modules/io/export.js
index 33f592f2..17432728 100644
--- a/modules/io/export.js
+++ b/modules/io/export.js
@@ -1,6 +1,7 @@
import {getGridPolygon} from "/src/utils/graphUtils";
import {unique} from "/src/utils/arrayUtils";
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
// download map as SVG
async function saveSVG() {
diff --git a/modules/io/load.js b/modules/io/load.js
index 8dfd355f..5c8c8a82 100644
--- a/modules/io/load.js
+++ b/modules/io/load.js
@@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
import {calculateVoronoi, findCell} from "/src/utils/graphUtils";
import {last} from "/src/utils/arrayUtils";
import {tip} from "/src/scripts/tooltips";
+import {rn, minmax} from "/src/utils/numberUtils";
function quickLoad() {
ldb.get("lastMap", blob => {
diff --git a/modules/io/save.js b/modules/io/save.js
index 99d95e99..2aadf6db 100644
--- a/modules/io/save.js
+++ b/modules/io/save.js
@@ -1,4 +1,5 @@
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
// functions to save project as .map file
diff --git a/modules/lakes.js b/modules/lakes.js
index fa6427b6..a78bad36 100644
--- a/modules/lakes.js
+++ b/modules/lakes.js
@@ -1,3 +1,5 @@
+import {rn} from "/src/utils/numberUtils";
+
window.Lakes = (function () {
const setClimateData = function (h) {
const cells = pack.cells;
diff --git a/modules/markers-generator.js b/modules/markers-generator.js
index 01d1eacb..3bfc0006 100644
--- a/modules/markers-generator.js
+++ b/modules/markers-generator.js
@@ -1,6 +1,7 @@
import {TIME} from "/src/config/logging";
import {getFriendlyHeight} from "./ui/general";
import {last} from "/src/utils/arrayUtils";
+import {rn} from "/src/utils/numberUtils";
window.Markers = (function () {
let config = [];
diff --git a/modules/military-generator.js b/modules/military-generator.js
index 7990fe0e..b8a164fc 100644
--- a/modules/military-generator.js
+++ b/modules/military-generator.js
@@ -1,4 +1,5 @@
import {TIME} from "/src/config/logging";
+import {rn, minmax} from "/src/utils/numberUtils";
window.Military = (function () {
const generate = function () {
diff --git a/modules/ocean-layers.js b/modules/ocean-layers.js
index ae042c82..2cbba31c 100644
--- a/modules/ocean-layers.js
+++ b/modules/ocean-layers.js
@@ -1,4 +1,5 @@
import {TIME} from "/src/config/logging";
+import {rn} from "/src/utils/numberUtils";
window.OceanLayers = (function () {
let cells, vertices, pointsN, used;
diff --git a/modules/relief-icons.js b/modules/relief-icons.js
index cd3934fc..87c43183 100644
--- a/modules/relief-icons.js
+++ b/modules/relief-icons.js
@@ -1,4 +1,5 @@
import {getPackPolygon} from "/src/utils/graphUtils";
+import {rn, minmax} from "/src/utils/numberUtils";
window.ReliefIcons = (function () {
const ReliefIcons = function () {
diff --git a/modules/religions-generator.js b/modules/religions-generator.js
index b682f38f..6359463c 100644
--- a/modules/religions-generator.js
+++ b/modules/religions-generator.js
@@ -2,6 +2,7 @@ import {TIME} from "/src/config/logging";
import {findAll} from "/src/utils/graphUtils";
import {unique} from "/src/utils/arrayUtils";
import {getRandomColor, getMixedColor} from "/src/utils/colorUtils";
+import {rn} from "/src/utils/numberUtils";
window.Religions = (function () {
// name generation approach and relative chance to be selected
diff --git a/modules/river-generator.js b/modules/river-generator.js
index 13df194d..40902565 100644
--- a/modules/river-generator.js
+++ b/modules/river-generator.js
@@ -1,5 +1,6 @@
import {TIME} from "/src/config/logging";
import {last} from "/src/utils/arrayUtils";
+import {rn} from "/src/utils/numberUtils";
window.Rivers = (function () {
const generate = function (allowErosion = true) {
diff --git a/modules/submap.js b/modules/submap.js
index 6f7d3d2b..5fb3668f 100644
--- a/modules/submap.js
+++ b/modules/submap.js
@@ -1,4 +1,5 @@
import {findCell} from "/src/utils/graphUtils";
+import {rn} from "/src/utils/numberUtils";
window.Submap = (function () {
const isWater = (pack, id) => pack.cells.h[id] < 20;
diff --git a/modules/ui/3d.js b/modules/ui/3d.js
index ea290279..c320f20e 100644
--- a/modules/ui/3d.js
+++ b/modules/ui/3d.js
@@ -1,4 +1,5 @@
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
window.ThreeD = (function () {
const options = {
diff --git a/modules/ui/battle-screen.js b/modules/ui/battle-screen.js
index 8c6f5b49..81f51b15 100644
--- a/modules/ui/battle-screen.js
+++ b/modules/ui/battle-screen.js
@@ -1,5 +1,6 @@
import {last} from "/src/utils/arrayUtils";
import {tip} from "/src/scripts/tooltips";
+import {rn, minmax} from "/src/utils/numberUtils";
export class Battle {
constructor(attacker, defender) {
diff --git a/modules/ui/biomes-editor.js b/modules/ui/biomes-editor.js
index 2e3f266b..342d05a5 100644
--- a/modules/ui/biomes-editor.js
+++ b/modules/ui/biomes-editor.js
@@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
import {getRandomColor} from "/src/utils/colorUtils";
+import {rn} from "/src/utils/numberUtils";
export function editBiomes() {
if (customization) return;
diff --git a/modules/ui/burg-editor.js b/modules/ui/burg-editor.js
index e236a30b..5f153879 100644
--- a/modules/ui/burg-editor.js
+++ b/modules/ui/burg-editor.js
@@ -1,5 +1,6 @@
import {findCell} from "/src/utils/graphUtils";
import {tip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editBurg(id) {
if (customization) return;
diff --git a/modules/ui/burgs-overview.js b/modules/ui/burgs-overview.js
index 64867852..5903391e 100644
--- a/modules/ui/burgs-overview.js
+++ b/modules/ui/burgs-overview.js
@@ -1,6 +1,7 @@
import {restoreDefaultEvents} from "/src/scripts/events";
import {findCell} from "/src/utils/graphUtils";
import {tip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function overviewBurgs() {
if (customization) return;
diff --git a/modules/ui/coastline-editor.js b/modules/ui/coastline-editor.js
index 52ac98c9..228e242b 100644
--- a/modules/ui/coastline-editor.js
+++ b/modules/ui/coastline-editor.js
@@ -1,5 +1,6 @@
import {getPackPolygon} from "/src/utils/graphUtils";
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editCoastline(node = d3.event.target) {
if (customization) return;
diff --git a/modules/ui/editors.js b/modules/ui/editors.js
index d475fb8c..9c31cde6 100644
--- a/modules/ui/editors.js
+++ b/modules/ui/editors.js
@@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
import {findCell} from "/src/utils/graphUtils";
import {byId} from "/src/utils/shorthands";
import {tip} from "/src/scripts/tooltips";
+import {rn, minmax, normalize} from "/src/utils/numberUtils";
// clear elSelected variable
export function unselect() {
diff --git a/modules/ui/elevation-profile.js b/modules/ui/elevation-profile.js
index 6793ce46..597e8d48 100644
--- a/modules/ui/elevation-profile.js
+++ b/modules/ui/elevation-profile.js
@@ -1,4 +1,5 @@
import {findCell} from "/src/utils/graphUtils";
+import {rn} from "/src/utils/numberUtils";
export function showEPForRoute(node) {
const points = [];
diff --git a/modules/ui/emblems-editor.js b/modules/ui/emblems-editor.js
index bcfeb80a..1a1b0b1a 100644
--- a/modules/ui/emblems-editor.js
+++ b/modules/ui/emblems-editor.js
@@ -1,5 +1,6 @@
import {clearMainTip} from "/src/scripts/tooltips";
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editEmblem(type, id, el) {
if (customization) return;
diff --git a/modules/ui/general.js b/modules/ui/general.js
index 383b443d..768322af 100644
--- a/modules/ui/general.js
+++ b/modules/ui/general.js
@@ -1,5 +1,5 @@
import {findCell, findGridCell} from "/src/utils/graphUtils";
-import {MOBILE} from "/src/constants";
+import {rn} from "/src/utils/numberUtils";
// fit full-screen map if window is resized
window.addEventListener("resize", function (e) {
diff --git a/modules/ui/heightmap-editor.js b/modules/ui/heightmap-editor.js
index b209bbe2..fa72a78f 100644
--- a/modules/ui/heightmap-editor.js
+++ b/modules/ui/heightmap-editor.js
@@ -3,6 +3,7 @@ import {findGridCell, findGridAll, findCell, getPackPolygon, getGridPolygon} fro
import {last, createTypedArray} from "/src/utils/arrayUtils";
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
import {byId} from "/src/utils/shorthands";
+import {rn, minmax, lim} from "/src/utils/numberUtils";
export function editHeightmap(options) {
const {mode, tool} = options || {};
diff --git a/modules/ui/ice-editor.js b/modules/ui/ice-editor.js
index da156f02..b9c24ad0 100644
--- a/modules/ui/ice-editor.js
+++ b/modules/ui/ice-editor.js
@@ -1,5 +1,6 @@
import {findGridCell, getGridPolygon} from "/src/utils/graphUtils";
import {tip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editIce() {
if (customization) return;
diff --git a/modules/ui/lakes-editor.js b/modules/ui/lakes-editor.js
index 5ea9a24d..9d1cd339 100644
--- a/modules/ui/lakes-editor.js
+++ b/modules/ui/lakes-editor.js
@@ -1,5 +1,6 @@
import {getPackPolygon} from "/src/utils/graphUtils";
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editLake() {
if (customization) return;
diff --git a/modules/ui/layers.js b/modules/ui/layers.js
index f7d86691..9362d363 100644
--- a/modules/ui/layers.js
+++ b/modules/ui/layers.js
@@ -5,6 +5,7 @@ import {last} from "/src/utils/arrayUtils";
import {stored, store} from "/src/utils/shorthands";
import {tip} from "/src/scripts/tooltips";
import {byId} from "/src/utils/shorthands";
+import {rn, minmax, normalize} from "/src/utils/numberUtils";
let presets = {};
restoreCustomPresets(); // run on-load
diff --git a/modules/ui/markers-editor.js b/modules/ui/markers-editor.js
index dcfe2c89..45571ba3 100644
--- a/modules/ui/markers-editor.js
+++ b/modules/ui/markers-editor.js
@@ -1,6 +1,7 @@
import {restoreDefaultEvents} from "/src/scripts/events";
import {findCell} from "/src/utils/graphUtils";
import {clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editMarker(markerI) {
if (customization) return;
diff --git a/modules/ui/military-overview.js b/modules/ui/military-overview.js
index 72f6607c..41b17563 100644
--- a/modules/ui/military-overview.js
+++ b/modules/ui/military-overview.js
@@ -1,4 +1,5 @@
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function overviewMilitary() {
if (customization) return;
diff --git a/modules/ui/namesbase-editor.js b/modules/ui/namesbase-editor.js
index 9e46839d..61a71015 100644
--- a/modules/ui/namesbase-editor.js
+++ b/modules/ui/namesbase-editor.js
@@ -1,5 +1,6 @@
import {unique} from "/src/utils/arrayUtils";
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editNamesbase() {
if (customization) return;
diff --git a/modules/ui/options.js b/modules/ui/options.js
index 7376056c..cb05634f 100644
--- a/modules/ui/options.js
+++ b/modules/ui/options.js
@@ -3,6 +3,7 @@ import {last} from "/src/utils/arrayUtils";
import {lock, locked} from "/src/scripts/options/lock";
import {tip, clearMainTip} from "/src/scripts/tooltips";
import {byId, stored} from "/src/utils/shorthands";
+import {rn, minmax} from "/src/utils/numberUtils";
$("#optionsContainer").draggable({handle: ".drag-trigger", snap: "svg", snapMode: "both"});
$("#exitCustomization").draggable({handle: "div"});
diff --git a/modules/ui/provinces-editor.js b/modules/ui/provinces-editor.js
index 8815fe54..36990772 100644
--- a/modules/ui/provinces-editor.js
+++ b/modules/ui/provinces-editor.js
@@ -3,6 +3,7 @@ import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
import {unique} from "/src/utils/arrayUtils";
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
import {getRandomColor} from "/src/utils/colorUtils";
+import {rn} from "/src/utils/numberUtils";
export function editProvinces() {
if (customization) return;
diff --git a/modules/ui/regiment-editor.js b/modules/ui/regiment-editor.js
index 400423fc..f943eb24 100644
--- a/modules/ui/regiment-editor.js
+++ b/modules/ui/regiment-editor.js
@@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
import {findCell} from "/src/utils/graphUtils";
import {last} from "/src/utils/arrayUtils";
import {tip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editRegiment(selector) {
if (customization) return;
diff --git a/modules/ui/regiments-overview.js b/modules/ui/regiments-overview.js
index 4497f5fd..b8faae7e 100644
--- a/modules/ui/regiments-overview.js
+++ b/modules/ui/regiments-overview.js
@@ -1,6 +1,7 @@
import {findCell} from "/src/utils/graphUtils";
import {last} from "/src/utils/arrayUtils";
import {tip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function overviewRegiments(state) {
if (customization) return;
diff --git a/modules/ui/relief-editor.js b/modules/ui/relief-editor.js
index e02dffec..ec7fa6d9 100644
--- a/modules/ui/relief-editor.js
+++ b/modules/ui/relief-editor.js
@@ -1,6 +1,7 @@
import {restoreDefaultEvents} from "/src/scripts/events";
import {findCell} from "/src/utils/graphUtils";
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editReliefIcon() {
if (customization) return;
diff --git a/modules/ui/rivers-creator.js b/modules/ui/rivers-creator.js
index c798d7fa..139cf9fc 100644
--- a/modules/ui/rivers-creator.js
+++ b/modules/ui/rivers-creator.js
@@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
import {getPackPolygon, findCell} from "/src/utils/graphUtils";
import {last} from "/src/utils/arrayUtils";
import {tip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function createRiver() {
if (customization) return;
diff --git a/modules/ui/rivers-editor.js b/modules/ui/rivers-editor.js
index 73e11a4a..4deeb4ae 100644
--- a/modules/ui/rivers-editor.js
+++ b/modules/ui/rivers-editor.js
@@ -1,5 +1,6 @@
import {findCell, getPackPolygon} from "/src/utils/graphUtils";
import {tip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editRiver(id) {
if (customization) return;
diff --git a/modules/ui/rivers-overview.js b/modules/ui/rivers-overview.js
index 88169559..16186259 100644
--- a/modules/ui/rivers-overview.js
+++ b/modules/ui/rivers-overview.js
@@ -1,5 +1,6 @@
-"use strict";
-function overviewRivers() {
+import {rn} from "/src/utils/numberUtils";
+
+export function overviewRivers() {
if (customization) return;
closeDialogs("#riversOverview, .stable");
if (!layerIsOn("toggleRivers")) toggleRivers();
diff --git a/modules/ui/routes-editor.js b/modules/ui/routes-editor.js
index 14b5eecf..d5427d57 100644
--- a/modules/ui/routes-editor.js
+++ b/modules/ui/routes-editor.js
@@ -1,4 +1,5 @@
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editRoute(onClick) {
if (customization) return;
diff --git a/modules/ui/style.js b/modules/ui/style.js
index 60c9b783..c89a70d5 100644
--- a/modules/ui/style.js
+++ b/modules/ui/style.js
@@ -1,4 +1,5 @@
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
// add available filters to lists
{
diff --git a/modules/ui/submap.js b/modules/ui/submap.js
index becd666f..ef79a1bf 100644
--- a/modules/ui/submap.js
+++ b/modules/ui/submap.js
@@ -1,5 +1,6 @@
import {byId} from "/src/utils/shorthands";
import {clearMainTip} from "/src/scripts/tooltips";
+import {rn, minmax} from "/src/utils/numberUtils";
window.UISubmap = (function () {
byId("submapPointsInput").addEventListener("input", function () {
diff --git a/modules/ui/temperature-graph.js b/modules/ui/temperature-graph.js
index a79f5d78..18bce918 100644
--- a/modules/ui/temperature-graph.js
+++ b/modules/ui/temperature-graph.js
@@ -1,4 +1,5 @@
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function showBurgTemperatureGraph(id) {
const b = pack.burgs[id];
diff --git a/modules/ui/tools.js b/modules/ui/tools.js
index 5c70ed0d..e1fff299 100644
--- a/modules/ui/tools.js
+++ b/modules/ui/tools.js
@@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
import {findCell} from "/src/utils/graphUtils";
import {last} from "/src/utils/arrayUtils";
import {tip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
// module to control the Tools options (click to edit, to re-geenerate, tp add)
diff --git a/modules/ui/world-configurator.js b/modules/ui/world-configurator.js
index 371bfab0..3e04229b 100644
--- a/modules/ui/world-configurator.js
+++ b/modules/ui/world-configurator.js
@@ -1,4 +1,5 @@
import {tip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editWorld() {
if (customization) return;
diff --git a/modules/ui/zones-editor.js b/modules/ui/zones-editor.js
index 16d0ba2f..fab5163c 100644
--- a/modules/ui/zones-editor.js
+++ b/modules/ui/zones-editor.js
@@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
import {findAll, findCell, getPackPolygon} from "/src/utils/graphUtils";
import {unique} from "/src/utils/arrayUtils";
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
+import {rn} from "/src/utils/numberUtils";
export function editZones() {
closeDialogs();
diff --git a/src/main.ts b/src/main.ts
index 2a8f49e4..843d63fe 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -22,11 +22,14 @@ import {
isLand,
shouldRegenerateGrid
} from "./utils/graphUtils";
+import {rn, minmax, normalize} from "./utils/numberUtils";
import {byId} from "./utils/shorthands";
import "./components";
addGlobalListeners();
+const d3 = window.d3;
+
window.fmg = {
modules: {}
};
@@ -51,8 +54,8 @@ rulers = new Rulers();
biomesData = Biomes.getDefault();
nameBases = Names.getNameBases(); // cultures-related data
-color = d3.scaleSequential(d3.interpolateSpectral); // default color scheme
-lineGen = d3.line().curve(d3.curveBasis); // d3 line generator with default curve interpolation
+// color = d3.scaleSequential(d3.interpolateSpectral); // default color scheme
+// lineGen = d3.line().curve(d3.curveBasis); // d3 line generator with default curve interpolation
// voronoi graph extension, cannot be changed after generation
graphWidth = +byId("mapWidthInput").value;
diff --git a/src/modules/legend.ts b/src/modules/legend.ts
index 615cb88f..2e0e4649 100644
--- a/src/modules/legend.ts
+++ b/src/modules/legend.ts
@@ -1,3 +1,5 @@
+import {rn} from "../utils/numberUtils";
+
export function drawLegend(name: string, data: unknown[]) {
legend.selectAll("*").remove(); // fully redraw every time
legend.attr("data", data.join("|")); // store data
diff --git a/src/modules/measurers.js b/src/modules/measurers.js
index e31aba1b..fb2f75e9 100644
--- a/src/modules/measurers.js
+++ b/src/modules/measurers.js
@@ -1,5 +1,6 @@
import {findCell} from "/src/utils/graphUtils";
import {last} from "/src/utils/arrayUtils";
+import {rn} from "/src/utils/numberUtils";
export class Rulers {
constructor() {
diff --git a/src/utils/graphUtils.ts b/src/utils/graphUtils.ts
index e282bcf7..4e740e0b 100644
--- a/src/utils/graphUtils.ts
+++ b/src/utils/graphUtils.ts
@@ -1,10 +1,16 @@
import {TIME} from "../config/logging";
import {createTypedArray} from "./arrayUtils";
+import {rn} from "./numberUtils";
import {byId} from "./shorthands";
+const Delaunator = window.Delaunator;
+const Voronoi = window.Voronoi;
+const graphWidth = window.graphWidth;
+const graphHeight = window.graphHeight;
+
// check if new grid graph should be generated or we can use the existing one
export function shouldRegenerateGrid(grid) {
- const cellsDesired = +byId("pointsInput").dataset.cells;
+ const cellsDesired = Number(byId("pointsInput")?.dataset.cells);
if (cellsDesired !== grid.cellsDesired) return true;
const newSpacing = rn(Math.sqrt((graphWidth * graphHeight) / cellsDesired), 2);
diff --git a/src/utils/numberUtils.ts b/src/utils/numberUtils.ts
new file mode 100644
index 00000000..b4a67410
--- /dev/null
+++ b/src/utils/numberUtils.ts
@@ -0,0 +1,21 @@
+// round value to d decimals
+export function rn(value: number, decimals: number = 0) {
+ const multiplier = Math.pow(10, decimals);
+ return Math.round(value * multiplier) / multiplier;
+}
+
+export function minmax(value: number, min: number, max: number) {
+ return Math.min(Math.max(value, min), max);
+}
+
+// return value clamped to [0, 100]
+export function lim(value: number) {
+ return minmax(value, 0, 100);
+}
+
+// normalization function
+export function normalize(val: number, min: number, max: number) {
+ return minmax((val - min) / (max - min), 0, 1);
+}
+
+// import {rn, minmax, lim, normalize} from '/src/utils/numberUtils';
diff --git a/utils/commonUtils.js b/utils/commonUtils.js
index b8b35352..c18fb7b1 100644
--- a/utils/commonUtils.js
+++ b/utils/commonUtils.js
@@ -1,5 +1,4 @@
-"use strict";
-// FMG helper functions
+import {rn} from "/src/utils/numberUtils";
// clip polygon by graph bbox
function clipPoly(points, secure = 0) {
diff --git a/utils/numberUtils.js b/utils/numberUtils.js
deleted file mode 100644
index e3f143a5..00000000
--- a/utils/numberUtils.js
+++ /dev/null
@@ -1,22 +0,0 @@
-"use strict";
-// FMG utils related to numbers
-
-// round value to d decimals
-function rn(v, d = 0) {
- const m = Math.pow(10, d);
- return Math.round(v * m) / m;
-}
-
-function minmax(value, min, max) {
- return Math.min(Math.max(value, min), max);
-}
-
-// return value in range [0, 100]
-function lim(v) {
- return minmax(v, 0, 100);
-}
-
-// normalization function
-function normalize(val, min, max) {
- return minmax((val - min) / (max - min), 0, 1);
-}
diff --git a/utils/polyfills.js b/utils/polyfills.js
deleted file mode 100644
index 369e647f..00000000
--- a/utils/polyfills.js
+++ /dev/null
@@ -1,16 +0,0 @@
-"use strict";
-
-// replaceAll
-if (String.prototype.replaceAll === undefined) {
- String.prototype.replaceAll = function (str, newStr) {
- if (Object.prototype.toString.call(str).toLowerCase() === "[object regexp]") return this.replace(str, newStr);
- return this.replace(new RegExp(str, "g"), newStr);
- };
-}
-
-// flat
-if (Array.prototype.flat === undefined) {
- Array.prototype.flat = function () {
- return this.reduce((acc, val) => (Array.isArray(val) ? acc.concat(val.flat()) : acc.concat(val)), []);
- };
-}
diff --git a/utils/probabilityUtils.js b/utils/probabilityUtils.js
index 7759e330..1c098bdc 100644
--- a/utils/probabilityUtils.js
+++ b/utils/probabilityUtils.js
@@ -1,5 +1,4 @@
-"use strict";
-// FMG utils related to randomness
+import {rn, minmax} from "/src/utils/numberUtils";
// random number in a range
function rand(min, max) {
diff --git a/utils/stringUtils.js b/utils/stringUtils.js
index 6325d278..2380e325 100644
--- a/utils/stringUtils.js
+++ b/utils/stringUtils.js
@@ -1,5 +1,4 @@
-"use strict";
-// FMG utils related to strings
+import {rn} from "/src/utils/numberUtils";
// round numbers in string to d decimals
function round(s, d = 1) {
diff --git a/utils/unitUtils.js b/utils/unitUtils.js
index a9a933df..12b9b84b 100644
--- a/utils/unitUtils.js
+++ b/utils/unitUtils.js
@@ -1,5 +1,4 @@
-"use strict";
-// FMG utils related to units
+import {rn} from "/src/utils/numberUtils";
// conver temperature from °C to other scales
const temperatureConversionMap = {