mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
refactor: dynamically load modules
This commit is contained in:
parent
a107c58643
commit
347083291f
46 changed files with 161 additions and 164 deletions
27
src/dialogs/index.ts
Normal file
27
src/dialogs/index.ts
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue