refactor: dynamically load modules

This commit is contained in:
Azgaar 2022-07-08 22:01:11 +03:00
parent a107c58643
commit 347083291f
46 changed files with 161 additions and 164 deletions

27
src/dialogs/index.ts Normal file
View file

@ -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);
}