diff --git a/index.html b/index.html
index d74da411..c86e75cf 100644
--- a/index.html
+++ b/index.html
@@ -1425,9 +1425,9 @@
|
Canvas size |
-
+
x
-
+
px
|
@@ -7688,34 +7688,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/modules/ui/biomes-editor.js b/src/dialogs/dialogs/biomes-editor.js
similarity index 99%
rename from src/modules/ui/biomes-editor.js
rename to src/dialogs/dialogs/biomes-editor.js
index 92735700..97406487 100644
--- a/src/modules/ui/biomes-editor.js
+++ b/src/dialogs/dialogs/biomes-editor.js
@@ -7,9 +7,9 @@ import {getRandomColor} from "utils/colorUtils";
import {openURL} from "utils/linkUtils";
import {rn} from "utils/numberUtils";
import {si} from "utils/unitUtils";
+import {closeDialogs} from "dialogs/utils";
-export function editBiomes() {
- if (customization) return;
+export function open() {
closeDialogs("#biomesEditor, .stable");
if (!layerIsOn("toggleBiomes")) toggleBiomes();
if (layerIsOn("toggleStates")) toggleStates();
diff --git a/src/modules/ui/burg-editor.js b/src/dialogs/dialogs/burg-editor.js
similarity index 98%
rename from src/modules/ui/burg-editor.js
rename to src/dialogs/dialogs/burg-editor.js
index 3adc6bd7..8a85269a 100644
--- a/src/modules/ui/burg-editor.js
+++ b/src/dialogs/dialogs/burg-editor.js
@@ -1,14 +1,19 @@
import * as d3 from "d3";
-import {findCell} from "utils/graphUtils";
-import {tip, clearMainTip} from "scripts/tooltips";
-import {rn} from "utils/numberUtils";
+import {closeDialogs} from "dialogs/utils";
+import {layerIsOn} from "layers";
import {prompt} from "scripts/prompt";
+import {clearMainTip, tip} from "scripts/tooltips";
+import {findCell} from "utils/graphUtils";
+import {rn} from "utils/numberUtils";
import {rand} from "utils/probabilityUtils";
import {parseTransform} from "utils/stringUtils";
-import {getHeight} from "utils/unitUtils";
+import {convertTemperature, getHeight} from "utils/unitUtils";
+import {getMFCGlink, getBurgSeed} from "modules/ui/editors";
-export function editBurg(id) {
+let isLoaded = false;
+
+export function open({id} = {}) {
if (customization) return;
closeDialogs(".stable");
if (!layerIsOn("toggleIcons")) toggleIcons();
@@ -26,8 +31,8 @@ export function editBurg(id) {
position: {my: "left top", at: "left+10 top+10", of: "svg", collision: "fit"}
});
- if (fmg.modules.editBurg) return;
- fmg.modules.editBurg = true;
+ if (isLoaded) return;
+ isLoaded = true;
// add listeners
document.getElementById("burgGroupShow").addEventListener("click", showGroupSection);
diff --git a/src/modules/dynamic/overview/charts-overview.js b/src/dialogs/dialogs/charts-overview.js
similarity index 99%
rename from src/modules/dynamic/overview/charts-overview.js
rename to src/dialogs/dialogs/charts-overview.js
index fa9b1f2d..60564f1b 100644
--- a/src/modules/dynamic/overview/charts-overview.js
+++ b/src/dialogs/dialogs/charts-overview.js
@@ -7,6 +7,7 @@ import {rn} from "utils/numberUtils";
import {capitalize} from "utils/stringUtils";
import {si, convertTemperature, getFriendlyPrecipitation} from "utils/unitUtils";
import {rollups} from "utils/functionUtils";
+import {closeDialogs} from "dialogs/utils";
const entitiesMap = {
states: {
diff --git a/src/modules/dynamic/editors/cultures-editor.js b/src/dialogs/dialogs/cultures-editor.js
similarity index 99%
rename from src/modules/dynamic/editors/cultures-editor.js
rename to src/dialogs/dialogs/cultures-editor.js
index 5bd613cb..833c5d6c 100644
--- a/src/modules/dynamic/editors/cultures-editor.js
+++ b/src/dialogs/dialogs/cultures-editor.js
@@ -9,6 +9,8 @@ import {capitalize} from "utils/stringUtils";
import {si} from "utils/unitUtils";
import {abbreviate} from "utils/languageUtils";
import {debounce} from "utils/functionUtils";
+import {closeDialogs} from "dialogs/utils";
+import {openDialog} from "dialogs";
const $body = insertEditorHtml();
addListeners();
@@ -639,9 +641,6 @@ function togglePercentageMode() {
}
async function showHierarchy() {
- if (customization) return;
- const HeirarchyTree = await import("../hierarchy-tree.js");
-
const getDescription = culture => {
const {name, type, rural, urban} = culture;
@@ -660,7 +659,7 @@ async function showHierarchy() {
if (type === "Hunting") return "pentagon";
};
- HeirarchyTree.open({
+ openDialog("hierarchyTree", null, {
type: "cultures",
data: pack.cultures,
onNodeEnter: cultureHighlightOn,
diff --git a/src/modules/dynamic/heightmap-selection.js b/src/dialogs/dialogs/heightmap-selection.js
similarity index 99%
rename from src/modules/dynamic/heightmap-selection.js
rename to src/dialogs/dialogs/heightmap-selection.js
index d5073bf9..0f8c72c6 100644
--- a/src/modules/dynamic/heightmap-selection.js
+++ b/src/dialogs/dialogs/heightmap-selection.js
@@ -7,6 +7,7 @@ import {byId} from "utils/shorthands";
import {generateSeed} from "utils/probabilityUtils";
import {getColorScheme} from "utils/colorUtils";
import {aleaPRNG} from "scripts/aleaPRNG";
+import {closeDialogs} from "dialogs/utils";
const initialSeed = generateSeed();
let graph = getGraph(grid);
diff --git a/src/modules/dynamic/hierarchy-tree.js b/src/dialogs/dialogs/hierarchy-tree.js
similarity index 99%
rename from src/modules/dynamic/hierarchy-tree.js
rename to src/dialogs/dialogs/hierarchy-tree.js
index fb77c921..74ec40b0 100644
--- a/src/modules/dynamic/hierarchy-tree.js
+++ b/src/dialogs/dialogs/hierarchy-tree.js
@@ -3,6 +3,7 @@ import * as d3 from "d3";
import {byId} from "utils/shorthands";
import {tip} from "scripts/tooltips";
import {capitalize} from "utils/stringUtils";
+import {closeDialogs} from "dialogs/utils";
appendStyleSheet();
insertHtml();
diff --git a/src/modules/dynamic/editors/religions-editor.js b/src/dialogs/dialogs/religions-editor.js
similarity index 99%
rename from src/modules/dynamic/editors/religions-editor.js
rename to src/dialogs/dialogs/religions-editor.js
index 70def4c4..e02ceab3 100644
--- a/src/modules/dynamic/editors/religions-editor.js
+++ b/src/dialogs/dialogs/religions-editor.js
@@ -8,6 +8,8 @@ import {rn} from "utils/numberUtils";
import {si} from "utils/unitUtils";
import {abbreviate} from "utils/languageUtils";
import {debounce} from "utils/functionUtils";
+import {closeDialogs} from "dialogs/utils";
+import {openDialog} from "dialogs";
const $body = insertEditorHtml();
addListeners();
@@ -543,9 +545,6 @@ function togglePercentageMode() {
}
async function showHierarchy() {
- if (customization) return;
- const HeirarchyTree = await import("../hierarchy-tree.js");
-
const getDescription = religion => {
const {name, type, form, rural, urban} = religion;
@@ -570,7 +569,7 @@ async function showHierarchy() {
if (type === "Heresy") return "diamond";
};
- HeirarchyTree.open({
+ openDialog("hierarchyTree", null, {
type: "religions",
data: pack.religions,
onNodeEnter: religionHighlightOn,
diff --git a/src/modules/dynamic/editors/states-editor.js b/src/dialogs/dialogs/states-editor.js
similarity index 99%
rename from src/modules/dynamic/editors/states-editor.js
rename to src/dialogs/dialogs/states-editor.js
index 65d3f4c0..0636e091 100644
--- a/src/modules/dynamic/editors/states-editor.js
+++ b/src/dialogs/dialogs/states-editor.js
@@ -9,6 +9,7 @@ import {rn} from "utils/numberUtils";
import {rand, P} from "utils/probabilityUtils";
import {si} from "utils/unitUtils";
import {getAdjective} from "utils/languageUtils";
+import {closeDialogs} from "dialogs/utils";
const $body = insertEditorHtml();
addListeners();
diff --git a/src/modules/ui/units-editor.js b/src/dialogs/dialogs/units-editor.js
similarity index 99%
rename from src/modules/ui/units-editor.js
rename to src/dialogs/dialogs/units-editor.js
index db5d1cc8..ea15bc91 100644
--- a/src/modules/ui/units-editor.js
+++ b/src/dialogs/dialogs/units-editor.js
@@ -4,6 +4,8 @@ import {restoreDefaultEvents} from "scripts/events";
import {findCell} from "utils/graphUtils";
import {tip} from "scripts/tooltips";
import {prompt} from "scripts/prompt";
+import {closeDialogs} from "dialogs/utils";
+import {fitScaleBar} from "modules/measurers";
export function open() {
closeDialogs("#unitsEditor, .stable");
diff --git a/src/dialogs/index.ts b/src/dialogs/index.ts
new file mode 100644
index 00000000..cc993839
--- /dev/null
+++ b/src/dialogs/index.ts
@@ -0,0 +1,27 @@
+const dialogsMap = {
+ biomesEditor: "biomes-editor",
+ burgEditor: "burg-editor",
+ chartsOverview: "charts-overview",
+ culturesEditor: "cultures-editor",
+ heightmapSelection: "heightmap-selection",
+ hierarchyTree: "hierarchy-tree",
+ religionsEditor: "religions-editor",
+ statesEditor: "states-editor",
+ unitsEditor: "units-editor"
+};
+
+type TDialog = keyof typeof dialogsMap;
+
+const defaultOptions = {
+ allowDuringCustomization: false
+};
+
+// dynamically load UI dialog
+// dialog is a es module with the only exported function 'open'
+export async function openDialog(dialog: TDialog, options: null | typeof defaultOptions, props?: UnknownObject) {
+ const {allowDuringCustomization} = options || defaultOptions;
+ if (customization && !allowDuringCustomization) return;
+
+ const Dialog = await import(`./dialogs/${dialogsMap[dialog]}.js`);
+ Dialog.open(props);
+}
diff --git a/src/dialogs/utils.ts b/src/dialogs/utils.ts
new file mode 100644
index 00000000..fa1c4199
--- /dev/null
+++ b/src/dialogs/utils.ts
@@ -0,0 +1,10 @@
+// close all dialogs except stated
+export function closeDialogs(except = "#except") {
+ try {
+ $(".dialog:visible")
+ .not(except)
+ .each(function () {
+ $(this).dialog("close");
+ });
+ } catch (error) {}
+}
diff --git a/src/layers/toggles.ts b/src/layers/toggles.ts
index 96458f98..2d0c0f0c 100644
--- a/src/layers/toggles.ts
+++ b/src/layers/toggles.ts
@@ -3,13 +3,12 @@ import * as d3 from "d3";
import {tip} from "scripts/tooltips";
import {getBase64} from "utils/functionUtils";
import {isCtrlPressed} from "utils/keyboardUtils";
+import {openDialog} from "dialogs";
// @ts-expect-error js module
-import {editStyle, calculateFriendlyGridSize, shiftCompass} from "modules/ui/style";
-import {turnLayerButtonOn, turnLayerButtonOff, layerIsOn} from "./utils";
-import {renderLayer} from "./renderers";
+import {calculateFriendlyGridSize, editStyle, shiftCompass} from "modules/ui/style";
import {getInputNumber, getInputValue} from "utils/nodeUtils";
-// @ts-expect-error js module
-import {editUnits} from "modules/ui/editors";
+import {renderLayer} from "./renderers";
+import {layerIsOn, turnLayerButtonOff, turnLayerButtonOn} from "./utils";
const layerTogglesMap = {
toggleBiomes,
@@ -467,9 +466,9 @@ function toggleScaleBar(event?: MouseEvent) {
if (!layerIsOn("toggleScaleBar")) {
turnLayerButtonOn("toggleScaleBar");
$("#scaleBar").fadeIn();
- if (isCtrlPressed(event)) editUnits();
+ if (isCtrlPressed(event)) openDialog("unitsEditor");
} else {
- if (isCtrlPressed(event)) editUnits();
+ if (isCtrlPressed(event)) openDialog("unitsEditor");
else {
$("#scaleBar").fadeOut();
turnLayerButtonOff("toggleScaleBar");
diff --git a/src/main.ts b/src/main.ts
index 1d639b5c..93312bdb 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -11,14 +11,8 @@ import {Rulers} from "./modules/measurers";
// @ts-expect-error js-module
import {applyStoredOptions} from "./modules/ui/options";
import {addGlobalListeners} from "./scripts/listeners";
-import {tip} from "./scripts/tooltips";
import {checkForUpdates} from "./scripts/updater";
import {getInputNumber} from "utils/nodeUtils";
-// @ts-expect-error js module
-import {editUnits} from "modules/ui/editors";
-
-checkForUpdates();
-addGlobalListeners();
window.fmg = {
modules: {}
@@ -32,14 +26,15 @@ options = {
stateLabelsMode: "auto"
};
+checkForUpdates();
+applyStoredOptions();
+
populationRate = getInputNumber("populationRateInput");
distanceScale = getInputNumber("distanceScaleInput");
urbanization = getInputNumber("urbanizationInput");
urbanDensity = getInputNumber("urbanDensityInput");
statesNeutral = 1; // statesEditor growth parameter
-applyStoredOptions();
-
rulers = new Rulers();
biomesData = window.Biomes.getDefault();
nameBases = window.Names.getNameBases(); // cultures-related data
@@ -53,8 +48,4 @@ svgWidth = graphWidth;
svgHeight = graphHeight;
defineSvg(graphWidth, graphHeight);
-
-scaleBar.on("mousemove", () => tip("Click to open Units Editor")).on("click", editUnits);
-legend
- .on("mousemove", () => tip("Drag to change the position. Click to hide the legend"))
- .on("click", () => clearLegend());
+addGlobalListeners();
diff --git a/src/modules/dynamic/export-json.js b/src/modules/dynamic/export-json.js
index b3a822a6..7c949077 100644
--- a/src/modules/dynamic/export-json.js
+++ b/src/modules/dynamic/export-json.js
@@ -1,4 +1,5 @@
import {tip} from "scripts/tooltips";
+import {closeDialogs} from "dialogs/utils";
export function exportToJson(type) {
if (customization)
diff --git a/src/modules/io/load.js b/src/modules/io/load.js
index b7a43994..78db8434 100644
--- a/src/modules/io/load.js
+++ b/src/modules/io/load.js
@@ -11,7 +11,7 @@ import {link} from "utils/linkUtils";
import {minmax, rn} from "utils/numberUtils";
import {regenerateMap} from "scripts/generation";
import {reMarkFeatures} from "modules/markup";
-import {editUnits} from "modules/ui/editors";
+import {closeDialogs} from "dialogs/utils";
// add drag to upload logic, pull request from @evyatron
export function addDragToUpload() {
@@ -480,13 +480,6 @@ async function parseLoadedData(data) {
updatePresetInput();
})();
- void (function restoreEvents() {
- scaleBar.on("mousemove", () => tip("Click to open Units Editor")).on("click", editUnits);
- legend
- .on("mousemove", () => tip("Drag to change the position. Click to hide the legend"))
- .on("click", () => clearLegend());
- })();
-
{
// dynamically import and run auto-udpdate script
const versionNumber = parseFloat(params[0]);
diff --git a/src/modules/io/save.js b/src/modules/io/save.js
index dd77e11f..83a12736 100644
--- a/src/modules/io/save.js
+++ b/src/modules/io/save.js
@@ -2,6 +2,7 @@ import {tip} from "scripts/tooltips";
import {rn} from "utils/numberUtils";
import {ldb} from "scripts/indexedDB";
import {ra} from "utils/probabilityUtils";
+import {closeDialogs} from "dialogs/utils";
// functions to save project as .map file
diff --git a/src/modules/ui/battle-screen.js b/src/modules/ui/battle-screen.js
index 8b2b8e84..f11982ae 100644
--- a/src/modules/ui/battle-screen.js
+++ b/src/modules/ui/battle-screen.js
@@ -7,6 +7,7 @@ import {rn, minmax} from "utils/numberUtils";
import {rand, P, Pint} from "utils/probabilityUtils";
import {capitalize} from "utils/stringUtils";
import {getAdjective, list} from "utils/languageUtils";
+import {closeDialogs} from "dialogs/utils";
export class Battle {
constructor(attacker, defender) {
@@ -172,35 +173,38 @@ export class Battle {
const state = pack.states[regiment.state];
const distance = (Math.hypot(this.y - regiment.by, this.x - regiment.bx) * distanceScaleInput.value) | 0; // distance between regiment and its base
const color = state.color[0] === "#" ? state.color : "#999";
- const icon = ` |