mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
refactor(es modules): migrate numberUtils
This commit is contained in:
parent
b425a9daf6
commit
ad252b54e6
63 changed files with 97 additions and 56 deletions
|
|
@ -7675,8 +7675,6 @@
|
||||||
|
|
||||||
<script src="utils/commonUtils.js"></script>
|
<script src="utils/commonUtils.js"></script>
|
||||||
<script src="utils/nodeUtils.js"></script>
|
<script src="utils/nodeUtils.js"></script>
|
||||||
<script src="utils/numberUtils.js"></script>
|
|
||||||
<script src="utils/polyfills.js"></script>
|
|
||||||
<script src="utils/probabilityUtils.js"></script>
|
<script src="utils/probabilityUtils.js"></script>
|
||||||
<script src="utils/stringUtils.js"></script>
|
<script src="utils/stringUtils.js"></script>
|
||||||
<script src="utils/languageUtils.js"></script>
|
<script src="utils/languageUtils.js"></script>
|
||||||
|
|
|
||||||
|
|
@ -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})`);
|
viewbox.attr("transform", `translate(${viewX} ${viewY}) scale(${scale})`);
|
||||||
|
|
||||||
if (isPositionChanged) drawCoordinates();
|
if (isPositionChanged) drawCoordinates();
|
||||||
|
|
@ -21,7 +23,7 @@ window.handleZoom = function (isScaleChanged, isPositionChanged) {
|
||||||
ctx.setTransform(scale, 0, 0, scale, viewX, viewY);
|
ctx.setTransform(scale, 0, 0, scale, viewX, viewY);
|
||||||
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// active zooming feature
|
// active zooming feature
|
||||||
export function invokeActiveZooming() {
|
export function invokeActiveZooming() {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {TIME} from "/src/config/logging";
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {layerIsOn} from "./ui/layers";
|
import {layerIsOn} from "./ui/layers";
|
||||||
import {getColors, getRandomColor, getMixedColor} from "/src/utils/colorUtils";
|
import {getColors, getRandomColor, getMixedColor} from "/src/utils/colorUtils";
|
||||||
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.BurgsAndStates = (function () {
|
window.BurgsAndStates = (function () {
|
||||||
const generate = function () {
|
const generate = function () {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {TIME} from "/src/config/logging";
|
import {TIME} from "/src/config/logging";
|
||||||
import {getColors} from "/src/utils/colorUtils";
|
import {getColors} from "/src/utils/colorUtils";
|
||||||
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.Cultures = (function () {
|
window.Cultures = (function () {
|
||||||
let cells;
|
let cells;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
// update old .map version to the current one
|
// update old .map version to the current one
|
||||||
export function resolveVersionConflicts(version) {
|
export function resolveVersionConflicts(version) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
|
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";
|
||||||
|
|
||||||
const $body = insertEditorHtml();
|
const $body = insertEditorHtml();
|
||||||
addListeners();
|
addListeners();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
|
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";
|
||||||
|
|
||||||
const $body = insertEditorHtml();
|
const $body = insertEditorHtml();
|
||||||
addListeners();
|
addListeners();
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
|
||||||
import {byId} from "/src/utils/shorthands";
|
import {byId} from "/src/utils/shorthands";
|
||||||
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
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";
|
||||||
|
|
||||||
const $body = insertEditorHtml();
|
const $body = insertEditorHtml();
|
||||||
addListeners();
|
addListeners();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {rollups} from "../../../utils/functionUtils.js";
|
||||||
import {isWater} from "/src/utils/graphUtils";
|
import {isWater} from "/src/utils/graphUtils";
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
import {byId} from "/src/utils/shorthands";
|
import {byId} from "/src/utils/shorthands";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
const entitiesMap = {
|
const entitiesMap = {
|
||||||
states: {
|
states: {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {getGridPolygon} from "/src/utils/graphUtils";
|
import {getGridPolygon} from "/src/utils/graphUtils";
|
||||||
import {unique} from "/src/utils/arrayUtils";
|
import {unique} from "/src/utils/arrayUtils";
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
// download map as SVG
|
// download map as SVG
|
||||||
async function saveSVG() {
|
async function saveSVG() {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {calculateVoronoi, findCell} from "/src/utils/graphUtils";
|
import {calculateVoronoi, findCell} from "/src/utils/graphUtils";
|
||||||
import {last} from "/src/utils/arrayUtils";
|
import {last} from "/src/utils/arrayUtils";
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
function quickLoad() {
|
function quickLoad() {
|
||||||
ldb.get("lastMap", blob => {
|
ldb.get("lastMap", blob => {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
// functions to save project as .map file
|
// functions to save project as .map file
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.Lakes = (function () {
|
window.Lakes = (function () {
|
||||||
const setClimateData = function (h) {
|
const setClimateData = function (h) {
|
||||||
const cells = pack.cells;
|
const cells = pack.cells;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {TIME} from "/src/config/logging";
|
import {TIME} from "/src/config/logging";
|
||||||
import {getFriendlyHeight} from "./ui/general";
|
import {getFriendlyHeight} from "./ui/general";
|
||||||
import {last} from "/src/utils/arrayUtils";
|
import {last} from "/src/utils/arrayUtils";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.Markers = (function () {
|
window.Markers = (function () {
|
||||||
let config = [];
|
let config = [];
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {TIME} from "/src/config/logging";
|
import {TIME} from "/src/config/logging";
|
||||||
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.Military = (function () {
|
window.Military = (function () {
|
||||||
const generate = function () {
|
const generate = function () {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {TIME} from "/src/config/logging";
|
import {TIME} from "/src/config/logging";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.OceanLayers = (function () {
|
window.OceanLayers = (function () {
|
||||||
let cells, vertices, pointsN, used;
|
let cells, vertices, pointsN, used;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {getPackPolygon} from "/src/utils/graphUtils";
|
import {getPackPolygon} from "/src/utils/graphUtils";
|
||||||
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.ReliefIcons = (function () {
|
window.ReliefIcons = (function () {
|
||||||
const ReliefIcons = function () {
|
const ReliefIcons = function () {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {TIME} from "/src/config/logging";
|
||||||
import {findAll} from "/src/utils/graphUtils";
|
import {findAll} from "/src/utils/graphUtils";
|
||||||
import {unique} from "/src/utils/arrayUtils";
|
import {unique} from "/src/utils/arrayUtils";
|
||||||
import {getRandomColor, getMixedColor} from "/src/utils/colorUtils";
|
import {getRandomColor, getMixedColor} from "/src/utils/colorUtils";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.Religions = (function () {
|
window.Religions = (function () {
|
||||||
// name generation approach and relative chance to be selected
|
// name generation approach and relative chance to be selected
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {TIME} from "/src/config/logging";
|
import {TIME} from "/src/config/logging";
|
||||||
import {last} from "/src/utils/arrayUtils";
|
import {last} from "/src/utils/arrayUtils";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.Rivers = (function () {
|
window.Rivers = (function () {
|
||||||
const generate = function (allowErosion = true) {
|
const generate = function (allowErosion = true) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.Submap = (function () {
|
window.Submap = (function () {
|
||||||
const isWater = (pack, id) => pack.cells.h[id] < 20;
|
const isWater = (pack, id) => pack.cells.h[id] < 20;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.ThreeD = (function () {
|
window.ThreeD = (function () {
|
||||||
const options = {
|
const options = {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {last} from "/src/utils/arrayUtils";
|
import {last} from "/src/utils/arrayUtils";
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export class Battle {
|
export class Battle {
|
||||||
constructor(attacker, defender) {
|
constructor(attacker, defender) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
|
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 {getRandomColor} from "/src/utils/colorUtils";
|
import {getRandomColor} from "/src/utils/colorUtils";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editBiomes() {
|
export function editBiomes() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editBurg(id) {
|
export function editBurg(id) {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {restoreDefaultEvents} from "/src/scripts/events";
|
import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function overviewBurgs() {
|
export function overviewBurgs() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {getPackPolygon} from "/src/utils/graphUtils";
|
import {getPackPolygon} from "/src/utils/graphUtils";
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
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 {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {byId} from "/src/utils/shorthands";
|
import {byId} from "/src/utils/shorthands";
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn, minmax, normalize} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
// clear elSelected variable
|
// clear elSelected variable
|
||||||
export function unselect() {
|
export function unselect() {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function showEPForRoute(node) {
|
export function showEPForRoute(node) {
|
||||||
const points = [];
|
const points = [];
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {clearMainTip} from "/src/scripts/tooltips";
|
import {clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editEmblem(type, id, el) {
|
export function editEmblem(type, id, el) {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import {findCell, findGridCell} from "/src/utils/graphUtils";
|
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
|
// fit full-screen map if window is resized
|
||||||
window.addEventListener("resize", function (e) {
|
window.addEventListener("resize", function (e) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {findGridCell, findGridAll, findCell, getPackPolygon, getGridPolygon} fro
|
||||||
import {last, createTypedArray} from "/src/utils/arrayUtils";
|
import {last, createTypedArray} from "/src/utils/arrayUtils";
|
||||||
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, minmax, lim} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editHeightmap(options) {
|
export function editHeightmap(options) {
|
||||||
const {mode, tool} = options || {};
|
const {mode, tool} = options || {};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {findGridCell, getGridPolygon} from "/src/utils/graphUtils";
|
import {findGridCell, getGridPolygon} from "/src/utils/graphUtils";
|
||||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editIce() {
|
export function editIce() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {getPackPolygon} from "/src/utils/graphUtils";
|
import {getPackPolygon} from "/src/utils/graphUtils";
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editLake() {
|
export function editLake() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import {last} from "/src/utils/arrayUtils";
|
||||||
import {stored, store} from "/src/utils/shorthands";
|
import {stored, store} from "/src/utils/shorthands";
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
import {byId} from "/src/utils/shorthands";
|
import {byId} from "/src/utils/shorthands";
|
||||||
|
import {rn, minmax, normalize} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
let presets = {};
|
let presets = {};
|
||||||
restoreCustomPresets(); // run on-load
|
restoreCustomPresets(); // run on-load
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {restoreDefaultEvents} from "/src/scripts/events";
|
import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {clearMainTip} from "/src/scripts/tooltips";
|
import {clearMainTip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editMarker(markerI) {
|
export function editMarker(markerI) {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function overviewMilitary() {
|
export function overviewMilitary() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {unique} from "/src/utils/arrayUtils";
|
import {unique} from "/src/utils/arrayUtils";
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editNamesbase() {
|
export function editNamesbase() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {last} from "/src/utils/arrayUtils";
|
||||||
import {lock, locked} from "/src/scripts/options/lock";
|
import {lock, locked} from "/src/scripts/options/lock";
|
||||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {byId, stored} from "/src/utils/shorthands";
|
import {byId, stored} from "/src/utils/shorthands";
|
||||||
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
$("#optionsContainer").draggable({handle: ".drag-trigger", snap: "svg", snapMode: "both"});
|
$("#optionsContainer").draggable({handle: ".drag-trigger", snap: "svg", snapMode: "both"});
|
||||||
$("#exitCustomization").draggable({handle: "div"});
|
$("#exitCustomization").draggable({handle: "div"});
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {findAll, findCell, getPackPolygon, isLand} from "/src/utils/graphUtils";
|
||||||
import {unique} from "/src/utils/arrayUtils";
|
import {unique} from "/src/utils/arrayUtils";
|
||||||
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
import {getRandomColor} from "/src/utils/colorUtils";
|
import {getRandomColor} from "/src/utils/colorUtils";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editProvinces() {
|
export function editProvinces() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {last} from "/src/utils/arrayUtils";
|
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";
|
||||||
|
|
||||||
export function editRegiment(selector) {
|
export function editRegiment(selector) {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {last} from "/src/utils/arrayUtils";
|
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";
|
||||||
|
|
||||||
export function overviewRegiments(state) {
|
export function overviewRegiments(state) {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import {restoreDefaultEvents} from "/src/scripts/events";
|
import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editReliefIcon() {
|
export function editReliefIcon() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {getPackPolygon, findCell} from "/src/utils/graphUtils";
|
import {getPackPolygon, findCell} from "/src/utils/graphUtils";
|
||||||
import {last} from "/src/utils/arrayUtils";
|
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";
|
||||||
|
|
||||||
export function createRiver() {
|
export function createRiver() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {findCell, getPackPolygon} from "/src/utils/graphUtils";
|
import {findCell, getPackPolygon} from "/src/utils/graphUtils";
|
||||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editRiver(id) {
|
export function editRiver(id) {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
"use strict";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
function overviewRivers() {
|
|
||||||
|
export function overviewRivers() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
closeDialogs("#riversOverview, .stable");
|
closeDialogs("#riversOverview, .stable");
|
||||||
if (!layerIsOn("toggleRivers")) toggleRivers();
|
if (!layerIsOn("toggleRivers")) toggleRivers();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editRoute(onClick) {
|
export function editRoute(onClick) {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
// add available filters to lists
|
// add available filters to lists
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {byId} from "/src/utils/shorthands";
|
import {byId} from "/src/utils/shorthands";
|
||||||
import {clearMainTip} from "/src/scripts/tooltips";
|
import {clearMainTip} from "/src/scripts/tooltips";
|
||||||
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
window.UISubmap = (function () {
|
window.UISubmap = (function () {
|
||||||
byId("submapPointsInput").addEventListener("input", function () {
|
byId("submapPointsInput").addEventListener("input", function () {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function showBurgTemperatureGraph(id) {
|
export function showBurgTemperatureGraph(id) {
|
||||||
const b = pack.burgs[id];
|
const b = pack.burgs[id];
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {last} from "/src/utils/arrayUtils";
|
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";
|
||||||
|
|
||||||
// module to control the Tools options (click to edit, to re-geenerate, tp add)
|
// module to control the Tools options (click to edit, to re-geenerate, tp add)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import {tip} from "/src/scripts/tooltips";
|
import {tip} from "/src/scripts/tooltips";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export function editWorld() {
|
export function editWorld() {
|
||||||
if (customization) return;
|
if (customization) return;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {restoreDefaultEvents} from "/src/scripts/events";
|
||||||
import {findAll, findCell, getPackPolygon} from "/src/utils/graphUtils";
|
import {findAll, findCell, getPackPolygon} from "/src/utils/graphUtils";
|
||||||
import {unique} from "/src/utils/arrayUtils";
|
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";
|
||||||
|
|
||||||
export function editZones() {
|
export function editZones() {
|
||||||
closeDialogs();
|
closeDialogs();
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,14 @@ import {
|
||||||
isLand,
|
isLand,
|
||||||
shouldRegenerateGrid
|
shouldRegenerateGrid
|
||||||
} from "./utils/graphUtils";
|
} from "./utils/graphUtils";
|
||||||
|
import {rn, minmax, normalize} from "./utils/numberUtils";
|
||||||
import {byId} from "./utils/shorthands";
|
import {byId} from "./utils/shorthands";
|
||||||
import "./components";
|
import "./components";
|
||||||
|
|
||||||
addGlobalListeners();
|
addGlobalListeners();
|
||||||
|
|
||||||
|
const d3 = window.d3;
|
||||||
|
|
||||||
window.fmg = {
|
window.fmg = {
|
||||||
modules: {}
|
modules: {}
|
||||||
};
|
};
|
||||||
|
|
@ -51,8 +54,8 @@ rulers = new Rulers();
|
||||||
biomesData = Biomes.getDefault();
|
biomesData = Biomes.getDefault();
|
||||||
nameBases = Names.getNameBases(); // cultures-related data
|
nameBases = Names.getNameBases(); // cultures-related data
|
||||||
|
|
||||||
color = d3.scaleSequential(d3.interpolateSpectral); // default color scheme
|
// color = d3.scaleSequential(d3.interpolateSpectral); // default color scheme
|
||||||
lineGen = d3.line().curve(d3.curveBasis); // d3 line generator with default curve interpolation
|
// lineGen = d3.line().curve(d3.curveBasis); // d3 line generator with default curve interpolation
|
||||||
|
|
||||||
// voronoi graph extension, cannot be changed after generation
|
// voronoi graph extension, cannot be changed after generation
|
||||||
graphWidth = +byId("mapWidthInput").value;
|
graphWidth = +byId("mapWidthInput").value;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import {rn} from "../utils/numberUtils";
|
||||||
|
|
||||||
export function drawLegend(name: string, data: unknown[]) {
|
export function drawLegend(name: string, data: unknown[]) {
|
||||||
legend.selectAll("*").remove(); // fully redraw every time
|
legend.selectAll("*").remove(); // fully redraw every time
|
||||||
legend.attr("data", data.join("|")); // store data
|
legend.attr("data", data.join("|")); // store data
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {findCell} from "/src/utils/graphUtils";
|
import {findCell} from "/src/utils/graphUtils";
|
||||||
import {last} from "/src/utils/arrayUtils";
|
import {last} from "/src/utils/arrayUtils";
|
||||||
|
import {rn} from "/src/utils/numberUtils";
|
||||||
|
|
||||||
export class Rulers {
|
export class Rulers {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
import {TIME} from "../config/logging";
|
import {TIME} from "../config/logging";
|
||||||
import {createTypedArray} from "./arrayUtils";
|
import {createTypedArray} from "./arrayUtils";
|
||||||
|
import {rn} from "./numberUtils";
|
||||||
import {byId} from "./shorthands";
|
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
|
// check if new grid graph should be generated or we can use the existing one
|
||||||
export function shouldRegenerateGrid(grid) {
|
export function shouldRegenerateGrid(grid) {
|
||||||
const cellsDesired = +byId("pointsInput").dataset.cells;
|
const cellsDesired = Number(byId("pointsInput")?.dataset.cells);
|
||||||
if (cellsDesired !== grid.cellsDesired) return true;
|
if (cellsDesired !== grid.cellsDesired) return true;
|
||||||
|
|
||||||
const newSpacing = rn(Math.sqrt((graphWidth * graphHeight) / cellsDesired), 2);
|
const newSpacing = rn(Math.sqrt((graphWidth * graphHeight) / cellsDesired), 2);
|
||||||
|
|
|
||||||
21
src/utils/numberUtils.ts
Normal file
21
src/utils/numberUtils.ts
Normal file
|
|
@ -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';
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
"use strict";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
// FMG helper functions
|
|
||||||
|
|
||||||
// clip polygon by graph bbox
|
// clip polygon by graph bbox
|
||||||
function clipPoly(points, secure = 0) {
|
function clipPoly(points, secure = 0) {
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
@ -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)), []);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
"use strict";
|
import {rn, minmax} from "/src/utils/numberUtils";
|
||||||
// FMG utils related to randomness
|
|
||||||
|
|
||||||
// random number in a range
|
// random number in a range
|
||||||
function rand(min, max) {
|
function rand(min, max) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
"use strict";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
// FMG utils related to strings
|
|
||||||
|
|
||||||
// round numbers in string to d decimals
|
// round numbers in string to d decimals
|
||||||
function round(s, d = 1) {
|
function round(s, d = 1) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
"use strict";
|
import {rn} from "/src/utils/numberUtils";
|
||||||
// FMG utils related to units
|
|
||||||
|
|
||||||
// conver temperature from °C to other scales
|
// conver temperature from °C to other scales
|
||||||
const temperatureConversionMap = {
|
const temperatureConversionMap = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue