Files
esengine/packages/runtime-core/src/RuntimeBootstrap.ts

67 lines
1.5 KiB
TypeScript
Raw Normal View History

/**
* Runtime Bootstrap
* -
*/
import { Core } from '@esengine/ecs-framework';
import type { IScene } from '@esengine/ecs-framework';
import {
runtimePluginManager,
type IPlugin,
type IRuntimeModule,
type PluginDescriptor,
type SystemContext
} from './PluginManager';
export interface RuntimeConfig {
enabledPlugins?: string[];
isEditor?: boolean;
}
/**
*
*/
export function createPlugin(
descriptor: PluginDescriptor,
runtimeModule: IRuntimeModule
): IPlugin {
return { descriptor, runtimeModule };
}
/**
*
*/
export function registerPlugin(plugin: IPlugin): void {
runtimePluginManager.register(plugin);
}
/**
*
* @param config
*/
export async function initializeRuntime(config?: RuntimeConfig): Promise<void> {
if (config?.enabledPlugins) {
runtimePluginManager.loadConfig({ enabledPlugins: config.enabledPlugins });
} else {
for (const plugin of runtimePluginManager.getPlugins()) {
runtimePluginManager.enable(plugin.descriptor.id);
}
}
await runtimePluginManager.initializeRuntime(Core.services);
}
/**
*
*/
export function createSystemsForScene(scene: IScene, context: SystemContext): void {
runtimePluginManager.createSystemsForScene(scene, context);
}
/**
*
*/
export function resetRuntime(): void {
runtimePluginManager.reset();
}