mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor(es modules): modulize utils
This commit is contained in:
parent
7ccebec048
commit
21fc303320
20 changed files with 25 additions and 6 deletions
|
|
@ -4,6 +4,7 @@ import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {byId} from "/src/utils/shorthands";
|
import {byId} from "/src/utils/shorthands";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {capitalize} from "@/utils/stringUtils";
|
import {capitalize} from "@/utils/stringUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
const $body = insertEditorHtml();
|
const $body = insertEditorHtml();
|
||||||
addListeners();
|
addListeners();
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
|
||||||
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {byId} from "/src/utils/shorthands";
|
import {byId} from "/src/utils/shorthands";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
const $body = insertEditorHtml();
|
const $body = insertEditorHtml();
|
||||||
addListeners();
|
addListeners();
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {getRandomColor, getMixedColor} from "/src/utils/colorUtils";
|
import {getRandomColor, getMixedColor} from "/src/utils/colorUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {rand, P} from "@/utils/probabilityUtils";
|
import {rand, P} from "@/utils/probabilityUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
const $body = insertEditorHtml();
|
const $body = insertEditorHtml();
|
||||||
addListeners();
|
addListeners();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {tip} from "/src/scripts/tooltips";
|
||||||
import {byId} from "/src/utils/shorthands";
|
import {byId} from "/src/utils/shorthands";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {capitalize} from "@/utils/stringUtils";
|
import {capitalize} from "@/utils/stringUtils";
|
||||||
|
import {si, convertTemperature} from "@/utils/unitUtils";
|
||||||
|
|
||||||
const entitiesMap = {
|
const entitiesMap = {
|
||||||
states: {
|
states: {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {last} from "/src/utils/arrayUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {rand, P, gauss, ra, rw} from "@/utils/probabilityUtils";
|
import {rand, P, gauss, ra, rw} from "@/utils/probabilityUtils";
|
||||||
import {capitalize} from "@/utils/stringUtils";
|
import {capitalize} from "@/utils/stringUtils";
|
||||||
|
import {convertTemperature} from "@/utils/unitUtils";
|
||||||
|
|
||||||
window.Markers = (function () {
|
window.Markers = (function () {
|
||||||
let config = [];
|
let config = [];
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {TIME} from "/src/config/logging";
|
import {TIME} from "/src/config/logging";
|
||||||
import {rn, minmax} from "/src/utils/numberUtils";
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
import {rand, gauss, ra} from "@/utils/probabilityUtils";
|
import {rand, gauss, ra} from "@/utils/probabilityUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
window.Military = (function () {
|
window.Military = (function () {
|
||||||
const generate = function () {
|
const generate = function () {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {getRandomColor} from "/src/utils/colorUtils";
|
import {getRandomColor} from "/src/utils/colorUtils";
|
||||||
import {openURL} from "@/utils/linkUtils";
|
import {openURL} from "@/utils/linkUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export function editBiomes() {
|
export function editBiomes() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {findCell} from "/src/utils/graphUtils";
|
||||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {getCoordinates} from "@/utils/coordinateUtils";
|
import {getCoordinates} from "@/utils/coordinateUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
import {si, siToInteger} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export function overviewBurgs() {
|
export function overviewBurgs() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
@ -202,7 +203,7 @@ export function overviewBurgs() {
|
||||||
this.value = si(this.value);
|
this.value = si(this.value);
|
||||||
|
|
||||||
const population = [];
|
const population = [];
|
||||||
body.querySelectorAll(":scope > div").forEach(el => population.push(+getInteger(el.dataset.population)));
|
body.querySelectorAll(":scope > div").forEach(el => population.push(siToInteger(el.dataset.population)));
|
||||||
burgsFooterPopulation.innerHTML = si(d3.mean(population));
|
burgsFooterPopulation.innerHTML = si(d3.mean(population));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {tip} from "/src/scripts/tooltips";
|
||||||
import {clipPoly} from "@/utils/lineUtils";
|
import {clipPoly} from "@/utils/lineUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {round} from "@/utils/stringUtils";
|
import {round} from "@/utils/stringUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export function editCoastline(node = d3.event.target) {
|
export function editCoastline(node = d3.event.target) {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {findCell, findGridCell} from "/src/utils/graphUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {link} from "@/utils/linkUtils";
|
import {link} from "@/utils/linkUtils";
|
||||||
import {getCoordinates, toDMS} from "@/utils/coordinateUtils";
|
import {getCoordinates, toDMS} from "@/utils/coordinateUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
// fit full-screen map if window is resized
|
// fit full-screen map if window is resized
|
||||||
window.addEventListener("resize", function (e) {
|
window.addEventListener("resize", function (e) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {tip} from "/src/scripts/tooltips";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {rand} from "@/utils/probabilityUtils";
|
import {rand} from "@/utils/probabilityUtils";
|
||||||
import {round} from "@/utils/stringUtils";
|
import {round} from "@/utils/stringUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export function editLake() {
|
export function editLake() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import {rn, minmax, normalize} from "/src/utils/numberUtils";
|
||||||
import {isCtrlClick} from "@/utils/keyboardUtils";
|
import {isCtrlClick} from "@/utils/keyboardUtils";
|
||||||
import {prompt} from "@/scripts/prompt";
|
import {prompt} from "@/scripts/prompt";
|
||||||
import {rand, P} from "@/utils/probabilityUtils";
|
import {rand, P} from "@/utils/probabilityUtils";
|
||||||
|
import {convertTemperature} from "@/utils/unitUtils";
|
||||||
|
|
||||||
let presets = {};
|
let presets = {};
|
||||||
restoreCustomPresets(); // run on-load
|
restoreCustomPresets(); // run on-load
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {tip} from "/src/scripts/tooltips";
|
||||||
import {wiki} from "@/utils/linkUtils";
|
import {wiki} from "@/utils/linkUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {capitalize} from "@/utils/stringUtils";
|
import {capitalize} from "@/utils/stringUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export function overviewMilitary() {
|
export function overviewMilitary() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import {getRandomColor} from "/src/utils/colorUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {rand, P} from "@/utils/probabilityUtils";
|
import {rand, P} from "@/utils/probabilityUtils";
|
||||||
import {parseTransform} from "@/utils/stringUtils";
|
import {parseTransform} from "@/utils/stringUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export function editProvinces() {
|
export function editProvinces() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {last} from "/src/utils/arrayUtils";
|
||||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {capitalize} from "@/utils/stringUtils";
|
import {capitalize} from "@/utils/stringUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export function overviewRegiments(state) {
|
export function overviewRegiments(state) {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {round} from "@/utils/stringUtils";
|
import {round} from "@/utils/stringUtils";
|
||||||
|
import {convertTemperature} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export function showBurgTemperatureGraph(id) {
|
export function showBurgTemperatureGraph(id) {
|
||||||
const b = pack.burgs[id];
|
const b = pack.burgs[id];
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {unique} from "/src/utils/arrayUtils";
|
||||||
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {getNextId} from "@/utils/nodeUtils";
|
import {getNextId} from "@/utils/nodeUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export function editZones() {
|
export function editZones() {
|
||||||
closeDialogs();
|
closeDialogs();
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {last} from "/src/utils/arrayUtils";
|
||||||
import {getSegmentId} from "@/utils/lineUtils";
|
import {getSegmentId} from "@/utils/lineUtils";
|
||||||
import {rn} from "/src/utils/numberUtils";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
import {round, parseTransform} from "@/utils/stringUtils";
|
import {round, parseTransform} from "@/utils/stringUtils";
|
||||||
|
import {si} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export class Rulers {
|
export class Rulers {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {dragLegendBox} from "../modules/legend";
|
import {dragLegendBox} from "../modules/legend";
|
||||||
import {findCell, findGridCell} from "../utils/graphUtils";
|
import {findCell, findGridCell} from "../utils/graphUtils";
|
||||||
import {tip, showMainTip} from "./tooltips";
|
import {tip, showMainTip} from "./tooltips";
|
||||||
|
import {si, convertTemperature} from "@/utils/unitUtils";
|
||||||
|
|
||||||
export function restoreDefaultEvents() {
|
export function restoreDefaultEvents() {
|
||||||
Zoom.setZoomBehavior();
|
Zoom.setZoomBehavior();
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,13 @@ const temperatureConversionMap = {
|
||||||
"°Rø": temp => rn((temp * 21) / 40 + 7.5) + "°Rø"
|
"°Rø": temp => rn((temp * 21) / 40 + 7.5) + "°Rø"
|
||||||
};
|
};
|
||||||
|
|
||||||
function convertTemperature(temp) {
|
export function convertTemperature(temp) {
|
||||||
const scale = temperatureScale.value || "°C";
|
const scale = temperatureScale.value || "°C";
|
||||||
return temperatureConversionMap[scale](temp);
|
return temperatureConversionMap[scale](temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// corvent number to short string with SI postfix
|
// corvert number to short string with SI postfix
|
||||||
function si(n) {
|
export function si(n) {
|
||||||
if (n >= 1e9) return rn(n / 1e9, 1) + "B";
|
if (n >= 1e9) return rn(n / 1e9, 1) + "B";
|
||||||
if (n >= 1e8) return rn(n / 1e6) + "M";
|
if (n >= 1e8) return rn(n / 1e6) + "M";
|
||||||
if (n >= 1e6) return rn(n / 1e6, 1) + "M";
|
if (n >= 1e6) return rn(n / 1e6, 1) + "M";
|
||||||
|
|
@ -27,8 +27,8 @@ function si(n) {
|
||||||
return rn(n);
|
return rn(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
// getInteger number from user input data
|
// convert SI number to integer
|
||||||
function getInteger(value) {
|
export function siToInteger(value) {
|
||||||
const metric = value.slice(-1);
|
const metric = value.slice(-1);
|
||||||
if (metric === "K") return parseInt(value.slice(0, -1) * 1e3);
|
if (metric === "K") return parseInt(value.slice(0, -1) * 1e3);
|
||||||
if (metric === "M") return parseInt(value.slice(0, -1) * 1e6);
|
if (metric === "M") return parseInt(value.slice(0, -1) * 1e6);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue