mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-18 02:01:22 +01:00
refactor(es modules): modulize utils
This commit is contained in:
parent
12e1c9f334
commit
7ccebec048
54 changed files with 168 additions and 134 deletions
|
|
@ -4,6 +4,8 @@ import {layerIsOn} from "./ui/layers";
|
|||
import {getColors, getRandomColor, getMixedColor} from "/src/utils/colorUtils";
|
||||
import {getMiddlePoint} from "@/utils/lineUtils";
|
||||
import {rn, minmax} from "/src/utils/numberUtils";
|
||||
import {rand, P, each, gauss, ra, rw, generateSeed} from "@/utils/probabilityUtils";
|
||||
import {round, splitInTwo} from "@/utils/stringUtils";
|
||||
|
||||
window.BurgsAndStates = (function () {
|
||||
const generate = function () {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import {P, rw} from "@/utils/probabilityUtils";
|
||||
|
||||
window.COA = (function () {
|
||||
const tinctures = {
|
||||
field: {metals: 3, colours: 4, stains: +P(0.03), patterns: 1},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {TIME} from "/src/config/logging";
|
||||
import {getColors} from "/src/utils/colorUtils";
|
||||
import {rn, minmax} from "/src/utils/numberUtils";
|
||||
import {rand, P, rw, biased} from "@/utils/probabilityUtils";
|
||||
|
||||
window.Cultures = (function () {
|
||||
let cells;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import {findCell} from "/src/utils/graphUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {rand, P, rw} from "@/utils/probabilityUtils";
|
||||
import {parseTransform} from "@/utils/stringUtils";
|
||||
|
||||
// update old .map version to the current one
|
||||
export function resolveVersionConflicts(version) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ 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";
|
||||
import {capitalize} from "@/utils/stringUtils";
|
||||
|
||||
const $body = insertEditorHtml();
|
||||
addListeners();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ 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";
|
||||
import {rand, P} from "@/utils/probabilityUtils";
|
||||
|
||||
const $body = insertEditorHtml();
|
||||
addListeners();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {shouldRegenerateGrid, generateGrid} from "/src/utils/graphUtils";
|
||||
import {byId} from "/src/utils/shorthands";
|
||||
import {generateSeed} from "@/utils/probabilityUtils";
|
||||
|
||||
const initialSeed = generateSeed();
|
||||
let graph = getGraph(grid);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {byId} from "/src/utils/shorthands";
|
||||
import {tip} from "/src/scripts/tooltips";
|
||||
import {capitalize} from "@/utils/stringUtils";
|
||||
|
||||
appendStyleSheet();
|
||||
insertHtml();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {isWater} from "/src/utils/graphUtils";
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {byId} from "/src/utils/shorthands";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {capitalize} from "@/utils/stringUtils";
|
||||
|
||||
const entitiesMap = {
|
||||
states: {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import {capitalize} from "@/utils/stringUtils";
|
||||
|
||||
const capitalize = text => text.charAt(0).toUpperCase() + text.slice(1);
|
||||
|
||||
const format = rawList =>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,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";
|
||||
import {rand, P, getNumberInRange} from "@/utils/probabilityUtils";
|
||||
|
||||
window.HeightmapGenerator = (function () {
|
||||
let grid = null;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {ldb} from "@/scripts/indexedDB";
|
||||
import {ra} from "@/utils/probabilityUtils";
|
||||
|
||||
// functions to save project as .map file
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import {TIME} from "/src/config/logging";
|
|||
import {getFriendlyHeight} from "./ui/general";
|
||||
import {last} from "/src/utils/arrayUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {rand, P, gauss, ra, rw} from "@/utils/probabilityUtils";
|
||||
import {capitalize} from "@/utils/stringUtils";
|
||||
|
||||
window.Markers = (function () {
|
||||
let config = [];
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {TIME} from "/src/config/logging";
|
||||
import {rn, minmax} from "/src/utils/numberUtils";
|
||||
import {rand, gauss, ra} from "@/utils/probabilityUtils";
|
||||
|
||||
window.Military = (function () {
|
||||
const generate = function () {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import {last} from "/src/utils/arrayUtils";
|
||||
import {locked} from "/src/scripts/options/lock";
|
||||
import {tip} from "/src/scripts/tooltips";
|
||||
import {rand, P, ra} from "@/utils/probabilityUtils";
|
||||
import {capitalize} from "@/utils/stringUtils";
|
||||
|
||||
window.Names = (function () {
|
||||
let chains = [];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import {TIME} from "@/config/logging";
|
||||
import {clipPoly} from "@/utils/lineUtils";
|
||||
import {rn} from "@/utils/numberUtils";
|
||||
import {P} from "@/utils/probabilityUtils";
|
||||
import {round} from "@/utils/stringUtils";
|
||||
|
||||
window.OceanLayers = (function () {
|
||||
let cells, vertices, pointsN, used;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {getPackPolygon} from "/src/utils/graphUtils";
|
||||
import {rn, minmax} from "/src/utils/numberUtils";
|
||||
import {rand} from "@/utils/probabilityUtils";
|
||||
|
||||
window.ReliefIcons = (function () {
|
||||
const ReliefIcons = function () {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ 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";
|
||||
import {rand, P, ra, rw, biased} from "@/utils/probabilityUtils";
|
||||
|
||||
window.Religions = (function () {
|
||||
// name generation approach and relative chance to be selected
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {TIME} from "/src/config/logging";
|
||||
import {last} from "/src/utils/arrayUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {round} from "@/utils/stringUtils";
|
||||
|
||||
window.Rivers = (function () {
|
||||
const generate = function (allowErosion = true) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {TIME} from "/src/config/logging";
|
||||
import {findCell} from "/src/utils/graphUtils";
|
||||
import {last} from "/src/utils/arrayUtils";
|
||||
import {round} from "@/utils/stringUtils";
|
||||
|
||||
window.Routes = (function () {
|
||||
const getRoads = function () {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import {last} from "/src/utils/arrayUtils";
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {wiki} from "@/utils/linkUtils";
|
||||
import {rn, minmax} from "/src/utils/numberUtils";
|
||||
import {rand, P, Pint} from "@/utils/probabilityUtils";
|
||||
import {capitalize} from "@/utils/stringUtils";
|
||||
|
||||
export class Battle {
|
||||
constructor(attacker, defender) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import {findCell} from "/src/utils/graphUtils";
|
|||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {prompt} from "@/scripts/prompt";
|
||||
import {rand} from "@/utils/probabilityUtils";
|
||||
import {parseTransform} from "@/utils/stringUtils";
|
||||
|
||||
export function editBurg(id) {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import {getPackPolygon} from "/src/utils/graphUtils";
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {clipPoly} from "@/utils/lineUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {round} from "@/utils/stringUtils";
|
||||
|
||||
export function editCoastline(node = d3.event.target) {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ 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";
|
||||
import {parseTransform} from "@/utils/stringUtils";
|
||||
|
||||
// clear elSelected variable
|
||||
export function unselect() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import {clearMainTip} from "/src/scripts/tooltips";
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {openURL} from "@/utils/linkUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {parseTransform} from "@/utils/stringUtils";
|
||||
|
||||
export function editEmblem(type, id, el) {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import {findGridCell, getGridPolygon} from "/src/utils/graphUtils";
|
||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {ra} from "@/utils/probabilityUtils";
|
||||
import {parseTransform} from "@/utils/stringUtils";
|
||||
|
||||
export function editIce() {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import {findCell} from "/src/utils/graphUtils";
|
||||
import {tip, showMainTip} from "/src/scripts/tooltips";
|
||||
import {round, parseTransform} from "@/utils/stringUtils";
|
||||
import {parseTransform} from "@/utils/stringUtils";
|
||||
|
||||
export function editLabel() {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import {getPackPolygon} from "/src/utils/graphUtils";
|
||||
import {tip} from "/src/scripts/tooltips";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {rand} from "@/utils/probabilityUtils";
|
||||
import {round} from "@/utils/stringUtils";
|
||||
|
||||
export function editLake() {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import {clipPoly} from "@/utils/lineUtils";
|
|||
import {rn, minmax, normalize} from "/src/utils/numberUtils";
|
||||
import {isCtrlClick} from "@/utils/keyboardUtils";
|
||||
import {prompt} from "@/scripts/prompt";
|
||||
import {rand, P} from "@/utils/probabilityUtils";
|
||||
|
||||
let presets = {};
|
||||
restoreCustomPresets(); // run on-load
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {wiki} from "@/utils/linkUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {capitalize} from "@/utils/stringUtils";
|
||||
|
||||
export function overviewMilitary() {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ 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";
|
||||
import {rand, P, gauss} from "@/utils/probabilityUtils";
|
||||
|
||||
$("#optionsContainer").draggable({handle: ".drag-trigger", snap: "svg", snapMode: "both"});
|
||||
$("#exitCustomization").draggable({handle: "div"});
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ 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";
|
||||
import {rand, P} from "@/utils/probabilityUtils";
|
||||
import {parseTransform} from "@/utils/stringUtils";
|
||||
|
||||
export function editProvinces() {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,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";
|
||||
import {capitalize} from "@/utils/stringUtils";
|
||||
|
||||
export function editRegiment(selector) {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,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";
|
||||
import {capitalize} from "@/utils/stringUtils";
|
||||
|
||||
export function overviewRegiments(state) {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import {findCell, getPackPolygon} from "/src/utils/graphUtils";
|
|||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||
import {getSegmentId} from "@/utils/lineUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {rand} from "@/utils/probabilityUtils";
|
||||
|
||||
export function editRiver(id) {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
||||
import {getSegmentId} from "@/utils/lineUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {getNextId} from "@/utils/nodeUtils";
|
||||
import {round} from "@/utils/stringUtils";
|
||||
|
||||
export function editRoute(onClick) {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {parseTransform} from "@/utils/stringUtils";
|
||||
|
||||
// add available filters to lists
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {isJsonValid} from "@/utils/stringUtils";
|
||||
|
||||
const systemPresets = [
|
||||
"default",
|
||||
|
|
@ -45,7 +46,7 @@ async function getStylePreset(desiredPreset) {
|
|||
ERROR && console.error(`Custom style ${desiredPreset} in not found in localStorage. Applying default style`);
|
||||
presetToLoad = "default";
|
||||
} else {
|
||||
const isValid = JSON.isValid(storedStyleJSON);
|
||||
const isValid = isJsonValid(storedStyleJSON);
|
||||
if (isValid) return [desiredPreset, JSON.parse(storedStyleJSON)];
|
||||
|
||||
ERROR &&
|
||||
|
|
@ -330,7 +331,7 @@ function addStylePreset() {
|
|||
const desiredName = styleSaverName.value;
|
||||
|
||||
if (!styleJSON) return tip("Please provide a style JSON", false, "error");
|
||||
if (!JSON.isValid(styleJSON)) return tip("JSON string is not valid, please check the format", false, "error");
|
||||
if (!isJsonValid(styleJSON)) return tip("JSON string is not valid, please check the format", false, "error");
|
||||
if (!desiredName) return tip("Please provide a preset name", false, "error");
|
||||
if (styleSaverTip.innerHTML === "default")
|
||||
return tip("You cannot overwrite default preset, please change the name", false, "error");
|
||||
|
|
@ -350,7 +351,7 @@ function addStylePreset() {
|
|||
const styleName = styleSaverName.value;
|
||||
|
||||
if (!styleJSON) return tip("Please provide a style JSON", false, "error");
|
||||
if (!JSON.isValid(styleJSON)) return tip("JSON string is not valid, please check the format", false, "error");
|
||||
if (!isJsonValid(styleJSON)) return tip("JSON string is not valid, please check the format", false, "error");
|
||||
if (!styleName) return tip("Please provide a preset name", false, "error");
|
||||
|
||||
downloadFile(styleJSON, styleName + ".json", "application/json");
|
||||
|
|
@ -362,7 +363,7 @@ function addStylePreset() {
|
|||
|
||||
function styleUpload(dataLoaded) {
|
||||
if (!dataLoaded) return tip("Cannot load the file. Please check the data format", false, "error");
|
||||
const isValid = JSON.isValid(dataLoaded);
|
||||
const isValid = isJsonValid(dataLoaded);
|
||||
if (!isValid) return tip("Loaded data is not a valid JSON, please check the format", false, "error");
|
||||
|
||||
styleSaverJSON.value = JSON.stringify(JSON.parse(dataLoaded), null, 2);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {round} from "@/utils/stringUtils";
|
||||
|
||||
export function showBurgTemperatureGraph(id) {
|
||||
const b = pack.burgs[id];
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import {tip, clearMainTip} from "/src/scripts/tooltips";
|
|||
import {rn} from "/src/utils/numberUtils";
|
||||
import {isCtrlClick} from "@/utils/keyboardUtils";
|
||||
import {prompt} from "@/scripts/prompt";
|
||||
import {getNextId} from "@/utils/nodeUtils";
|
||||
import {P, generateSeed} from "@/utils/probabilityUtils";
|
||||
|
||||
toolsContent.addEventListener("click", function (event) {
|
||||
if (customization) return tip("Please exit the customization mode first", false, "warning");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {round, parseTransform} from "@/utils/stringUtils";
|
||||
|
||||
export function editWorld() {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ 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";
|
||||
import {getNextId} from "@/utils/nodeUtils";
|
||||
|
||||
export function editZones() {
|
||||
closeDialogs();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue