From a929667796fdd17c29dec967c4e0262a1b71e0e0 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Sat, 25 Jun 2022 18:03:38 +0300 Subject: [PATCH] refactor(es modules): continue migration --- modules/dynamic/editors/cultures-editor.js | 1 + modules/dynamic/editors/religions-editor.js | 1 + modules/dynamic/editors/states-editor.js | 1 + modules/dynamic/heightmap-selection.js | 1 + modules/dynamic/hierarchy-tree.js | 2 ++ modules/dynamic/overview/charts-overview.js | 1 + modules/heightmap-generator.js | 1 + modules/io/export.js | 1 + modules/religions-generator.js | 1 + modules/ui/editors.js | 1 + modules/ui/heightmap-editor.js | 3 ++- modules/ui/namesbase-editor.js | 5 +++-- modules/ui/options.js | 1 - modules/ui/provinces-editor.js | 1 + modules/ui/zones-editor.js | 1 + src/utils/arrayUtils.ts | 24 ++++++++++----------- 16 files changed, 30 insertions(+), 16 deletions(-) diff --git a/modules/dynamic/editors/cultures-editor.js b/modules/dynamic/editors/cultures-editor.js index 2fe11502..648679fb 100644 --- a/modules/dynamic/editors/cultures-editor.js +++ b/modules/dynamic/editors/cultures-editor.js @@ -1,4 +1,5 @@ import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils"; +import {byId} from "/src/utils/shorthands"; const $body = insertEditorHtml(); addListeners(); diff --git a/modules/dynamic/editors/religions-editor.js b/modules/dynamic/editors/religions-editor.js index cd926a7a..8bd934ed 100644 --- a/modules/dynamic/editors/religions-editor.js +++ b/modules/dynamic/editors/religions-editor.js @@ -1,4 +1,5 @@ import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils"; +import {byId} from "/src/utils/shorthands"; const $body = insertEditorHtml(); addListeners(); diff --git a/modules/dynamic/editors/states-editor.js b/modules/dynamic/editors/states-editor.js index fa870d30..8e22a943 100644 --- a/modules/dynamic/editors/states-editor.js +++ b/modules/dynamic/editors/states-editor.js @@ -1,4 +1,5 @@ import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils"; +import {byId} from "/src/utils/shorthands"; const $body = insertEditorHtml(); addListeners(); diff --git a/modules/dynamic/heightmap-selection.js b/modules/dynamic/heightmap-selection.js index 99fdc8a7..6b5dc1e3 100644 --- a/modules/dynamic/heightmap-selection.js +++ b/modules/dynamic/heightmap-selection.js @@ -1,4 +1,5 @@ import {shouldRegenerateGrid, generateGrid} from "/src/utils/graphUtils"; +import {byId} from "/src/utils/shorthands"; const initialSeed = generateSeed(); let graph = getGraph(grid); diff --git a/modules/dynamic/hierarchy-tree.js b/modules/dynamic/hierarchy-tree.js index 621f4427..b9409d91 100644 --- a/modules/dynamic/hierarchy-tree.js +++ b/modules/dynamic/hierarchy-tree.js @@ -1,3 +1,5 @@ +import {byId} from "/src/utils/shorthands"; + appendStyleSheet(); insertHtml(); diff --git a/modules/dynamic/overview/charts-overview.js b/modules/dynamic/overview/charts-overview.js index a40aa931..3baa6536 100644 --- a/modules/dynamic/overview/charts-overview.js +++ b/modules/dynamic/overview/charts-overview.js @@ -1,5 +1,6 @@ import {rollups} from "../../../utils/functionUtils.js"; import {isWater} from "/src/utils/graphUtils"; +import {byId} from "/src/utils/shorthands"; const entitiesMap = { states: { diff --git a/modules/heightmap-generator.js b/modules/heightmap-generator.js index efbf59d0..17be7314 100644 --- a/modules/heightmap-generator.js +++ b/modules/heightmap-generator.js @@ -1,6 +1,7 @@ import {TIME} from "/src/config/logging"; import {createTypedArray} from "/src/utils/arrayUtils"; import {findGridCell} from "/src/utils/graphUtils"; +import {byId} from "/src/utils/shorthands"; window.HeightmapGenerator = (function () { let grid = null; diff --git a/modules/io/export.js b/modules/io/export.js index 597894ef..6bb910d5 100644 --- a/modules/io/export.js +++ b/modules/io/export.js @@ -1,4 +1,5 @@ import {getGridPolygon} from "/src/utils/graphUtils"; +import {unique} from "/src/utils/arrayUtils"; // download map as SVG async function saveSVG() { diff --git a/modules/religions-generator.js b/modules/religions-generator.js index 139a3558..88bfa674 100644 --- a/modules/religions-generator.js +++ b/modules/religions-generator.js @@ -1,5 +1,6 @@ import {TIME} from "/src/config/logging"; import {findAll} from "/src/utils/graphUtils"; +import {unique} from "/src/utils/arrayUtils"; window.Religions = (function () { // name generation approach and relative chance to be selected diff --git a/modules/ui/editors.js b/modules/ui/editors.js index 1059be61..f897d273 100644 --- a/modules/ui/editors.js +++ b/modules/ui/editors.js @@ -1,4 +1,5 @@ import {findCell} from "/src/utils/graphUtils"; +import {byId} from "/src/utils/shorthands"; // restore default viewbox events function restoreDefaultEvents() { diff --git a/modules/ui/heightmap-editor.js b/modules/ui/heightmap-editor.js index 0b622441..2813fd06 100644 --- a/modules/ui/heightmap-editor.js +++ b/modules/ui/heightmap-editor.js @@ -1,5 +1,6 @@ import {findGridCell, findGridAll, findCell, getPackPolygon, getGridPolygon} from "/src/utils/graphUtils"; -import {last} from "/src/utils/arrayUtils"; +import {last, createTypedArray} from "/src/utils/arrayUtils"; +import {byId} from "/src/utils/shorthands"; export function editHeightmap(options) { const {mode, tool} = options || {}; diff --git a/modules/ui/namesbase-editor.js b/modules/ui/namesbase-editor.js index dca66754..66026ae3 100644 --- a/modules/ui/namesbase-editor.js +++ b/modules/ui/namesbase-editor.js @@ -1,5 +1,6 @@ -"use strict"; -function editNamesbase() { +import {unique} from "/src/utils/arrayUtils"; + +export function editNamesbase() { if (customization) return; closeDialogs("#namesbaseEditor, .stable"); $("#namesbaseEditor").dialog(); diff --git a/modules/ui/options.js b/modules/ui/options.js index 224734b8..67f90a21 100644 --- a/modules/ui/options.js +++ b/modules/ui/options.js @@ -1,7 +1,6 @@ import {stored, lock, locked, applyOption} from "./general"; import {last} from "/src/utils/arrayUtils"; import {byId} from "/src/utils/shorthands"; -import {last} from "/src/utils/arrayUtils"; $("#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 79b0ac35..2abc90a5 100644 --- a/modules/ui/provinces-editor.js +++ b/modules/ui/provinces-editor.js @@ -1,4 +1,5 @@ import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils"; +import {unique} from "/src/utils/arrayUtils"; export function editProvinces() { if (customization) return; diff --git a/modules/ui/zones-editor.js b/modules/ui/zones-editor.js index 1facd14b..4f08f30c 100644 --- a/modules/ui/zones-editor.js +++ b/modules/ui/zones-editor.js @@ -1,4 +1,5 @@ import {findAll, findCell, getPackPolygon} from "/src/utils/graphUtils"; +import {unique} from "/src/utils/arrayUtils"; export function editZones() { closeDialogs(); diff --git a/src/utils/arrayUtils.ts b/src/utils/arrayUtils.ts index 17a11f74..9fead55d 100644 --- a/src/utils/arrayUtils.ts +++ b/src/utils/arrayUtils.ts @@ -8,18 +8,6 @@ export function unique(array: T[]) { return [...new Set(array)]; } -function getTypedArray(maxValue: number) { - console.assert( - Number.isInteger(maxValue) && maxValue >= 0 && maxValue <= UINT32_MAX, - `Array maxValue must be an integer between 0 and ${UINT32_MAX}, got ${maxValue}` - ); - - if (maxValue <= UINT8_MAX) return Uint8Array; - if (maxValue <= UINT16_MAX) return Uint16Array; - if (maxValue <= UINT32_MAX) return Uint32Array; - return Uint32Array; -} - interface ICreateTypedArray { maxValue: number; length: number; @@ -31,3 +19,15 @@ export function createTypedArray({maxValue, length, from}: ICreateTypedArray) { if (!from) return new typedArray(length); return typedArray.from(from); } + +function getTypedArray(maxValue: number) { + console.assert( + Number.isInteger(maxValue) && maxValue >= 0 && maxValue <= UINT32_MAX, + `Array maxValue must be an integer between 0 and ${UINT32_MAX}, got ${maxValue}` + ); + + if (maxValue <= UINT8_MAX) return Uint8Array; + if (maxValue <= UINT16_MAX) return Uint16Array; + if (maxValue <= UINT32_MAX) return Uint32Array; + return Uint32Array; +}