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
11df349394
commit
12e1c9f334
45 changed files with 620 additions and 283 deletions
|
|
@ -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 {getMiddlePoint} from "@/utils/lineUtils";
|
||||
import {rn, minmax} from "/src/utils/numberUtils";
|
||||
|
||||
window.BurgsAndStates = (function () {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ let svgWidth;
|
|||
let svgHeight;
|
||||
|
||||
let options = {};
|
||||
let mapCoordinates = {};
|
||||
let populationRate;
|
||||
let distanceScale;
|
||||
let urbanization;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {getGridPolygon} from "/src/utils/graphUtils";
|
||||
import {unique} from "/src/utils/arrayUtils";
|
||||
import {tip} from "/src/scripts/tooltips";
|
||||
import {getCoordinates} from "@/utils/coordinateUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
|
||||
// download map as SVG
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ 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 {parseError} from "@/utils/errorUtils";
|
||||
import {rn, minmax} from "/src/utils/numberUtils";
|
||||
import {link} from "@/utils/linkUtils";
|
||||
import {ldb} from "@/scripts/indexedDB";
|
||||
|
||||
function quickLoad() {
|
||||
ldb.get("lastMap", blob => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {ldb} from "@/scripts/indexedDB";
|
||||
|
||||
// functions to save project as .map file
|
||||
|
||||
|
|
|
|||
|
|
@ -562,6 +562,14 @@ window.Markers = (function () {
|
|||
notes.push({id, name, legend});
|
||||
}
|
||||
|
||||
function generateDate(from = 100, to = 1000) {
|
||||
return new Date(rand(from, to), rand(12), rand(31)).toLocaleDateString("en", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric"
|
||||
});
|
||||
}
|
||||
|
||||
function listDungeons({cells}) {
|
||||
return cells.i.filter(i => !occupied[i] && cells.pop[i] && cells.pop[i] < 3);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {TIME} from "/src/config/logging";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {TIME} from "@/config/logging";
|
||||
import {clipPoly} from "@/utils/lineUtils";
|
||||
import {rn} from "@/utils/numberUtils";
|
||||
|
||||
window.OceanLayers = (function () {
|
||||
let cells, vertices, pointsN, used;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import {findCell} from "/src/utils/graphUtils";
|
||||
import {getMiddlePoint} from "@/utils/lineUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
|
||||
window.Submap = (function () {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {last} from "/src/utils/arrayUtils";
|
||||
import {tip} from "/src/scripts/tooltips";
|
||||
import {wiki} from "@/utils/linkUtils";
|
||||
import {rn, minmax} from "/src/utils/numberUtils";
|
||||
|
||||
export class Battle {
|
||||
|
|
|
|||
|
|
@ -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 {openURL} from "@/utils/linkUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
|
||||
export function editBiomes() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {findCell} from "/src/utils/graphUtils";
|
||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {prompt} from "@/scripts/prompt";
|
||||
|
||||
export function editBurg(id) {
|
||||
if (customization) return;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {restoreDefaultEvents} from "/src/scripts/events";
|
||||
import {findCell} from "/src/utils/graphUtils";
|
||||
import {tip, clearMainTip} from "/src/scripts/tooltips";
|
||||
import {getCoordinates} from "@/utils/coordinateUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
|
||||
export function overviewBurgs() {
|
||||
|
|
@ -500,8 +501,9 @@ export function overviewBurgs() {
|
|||
data += rn(b.population * populationRate * urbanization) + ",";
|
||||
|
||||
// add geography data
|
||||
data += getLatitude(b.y, 2) + ",";
|
||||
data += getLongitude(b.x, 2) + ",";
|
||||
const [lon, lat] = getCoordinates(b.x, b.y, 2);
|
||||
data += lat + ",";
|
||||
data += lon + ",";
|
||||
data += parseInt(getHeight(pack.cells.h[b.cell])) + ",";
|
||||
|
||||
// add status data
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {getPackPolygon} from "/src/utils/graphUtils";
|
||||
import {tip} from "/src/scripts/tooltips";
|
||||
import {clipPoly} from "@/utils/lineUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
|
||||
export function editCoastline(node = d3.event.target) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {clearMainTip} from "/src/scripts/tooltips";
|
||||
import {tip} from "/src/scripts/tooltips";
|
||||
import {openURL} from "@/utils/linkUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
|
||||
export function editEmblem(type, id, el) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import {findCell, findGridCell} from "/src/utils/graphUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
import {link} from "@/utils/linkUtils";
|
||||
import {getCoordinates, toDMS} from "@/utils/coordinateUtils";
|
||||
|
||||
// fit full-screen map if window is resized
|
||||
window.addEventListener("resize", function (e) {
|
||||
|
|
@ -29,8 +31,10 @@ function updateCellInfo(point, i, g) {
|
|||
const x = (infoX.innerHTML = rn(point[0]));
|
||||
const y = (infoY.innerHTML = rn(point[1]));
|
||||
const f = cells.f[i];
|
||||
infoLat.innerHTML = toDMS(getLatitude(y, 4), "lat");
|
||||
infoLon.innerHTML = toDMS(getLongitude(x, 4), "lon");
|
||||
|
||||
const [lon, lat] = getCoordinates(x, y, 4);
|
||||
infoLat.innerHTML = toDMS(lat, "lat");
|
||||
infoLon.innerHTML = toDMS(lon, "lon");
|
||||
|
||||
infoCell.innerHTML = i;
|
||||
infoArea.innerHTML = cells.area[i] ? si(getArea(cells.area[i])) + " " + getAreaUnit() : "n/a";
|
||||
|
|
@ -58,16 +62,6 @@ function updateCellInfo(point, i, g) {
|
|||
infoBiome.innerHTML = biomesData.name[cells.biome[i]];
|
||||
}
|
||||
|
||||
// convert coordinate to DMS format
|
||||
function toDMS(coord, c) {
|
||||
const degrees = Math.floor(Math.abs(coord));
|
||||
const minutesNotTruncated = (Math.abs(coord) - degrees) * 60;
|
||||
const minutes = Math.floor(minutesNotTruncated);
|
||||
const seconds = Math.floor((minutesNotTruncated - minutes) * 60);
|
||||
const cardinal = c === "lat" ? (coord >= 0 ? "N" : "S") : coord >= 0 ? "E" : "W";
|
||||
return degrees + "° " + minutes + "′ " + seconds + "″ " + cardinal;
|
||||
}
|
||||
|
||||
// get surface elevation
|
||||
function getElevation(f, h) {
|
||||
if (f.land) return getHeight(h) + " (" + h + ")"; // land: usual height
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ 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";
|
||||
import {link} from "@/utils/linkUtils";
|
||||
import {prompt} from "@/scripts/prompt";
|
||||
|
||||
export function editHeightmap(options) {
|
||||
const {mode, tool} = options || {};
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ 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 {clipPoly} from "@/utils/lineUtils";
|
||||
import {rn, minmax, normalize} from "/src/utils/numberUtils";
|
||||
import {isCtrlClick} from "@/utils/keyboardUtils";
|
||||
import {prompt} from "@/scripts/prompt";
|
||||
|
||||
let presets = {};
|
||||
restoreCustomPresets(); // run on-load
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import {tip} from "/src/scripts/tooltips";
|
||||
import {wiki} from "@/utils/linkUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
|
||||
export function overviewMilitary() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {unique} from "/src/utils/arrayUtils";
|
||||
import {tip} from "/src/scripts/tooltips";
|
||||
import {openURL} from "@/utils/linkUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
|
||||
export function editNamesbase() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
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";
|
||||
|
||||
export function editRiver(id) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import {tip, showMainTip, clearMainTip} from "/src/scripts/tooltips";
|
||||
import {getSegmentId} from "@/utils/lineUtils";
|
||||
import {rn} from "/src/utils/numberUtils";
|
||||
|
||||
export function editRoute(onClick) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {byId} from "/src/utils/shorthands";
|
||||
import {clearMainTip} from "/src/scripts/tooltips";
|
||||
import {parseError} from "@/utils/errorUtils";
|
||||
import {rn, minmax} from "/src/utils/numberUtils";
|
||||
|
||||
window.UISubmap = (function () {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ 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)
|
||||
import {isCtrlClick} from "@/utils/keyboardUtils";
|
||||
import {prompt} from "@/scripts/prompt";
|
||||
|
||||
toolsContent.addEventListener("click", function (event) {
|
||||
if (customization) return tip("Please exit the customization mode first", false, "warning");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {restoreDefaultEvents} from "/src/scripts/events";
|
||||
import {findCell} from "/src/utils/graphUtils";
|
||||
import {tip} from "/src/scripts/tooltips";
|
||||
import {prompt} from "@/scripts/prompt";
|
||||
|
||||
export function editUnits() {
|
||||
closeDialogs("#unitsEditor, .stable");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue