feat(core): 添加module.json和类型定义更新
This commit is contained in:
19
packages/runtime-core/module.json
Normal file
19
packages/runtime-core/module.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"id": "runtime-core",
|
||||
"name": "@esengine/runtime-core",
|
||||
"displayName": "Runtime Core",
|
||||
"description": "Core runtime framework | 核心运行时框架",
|
||||
"version": "1.0.0",
|
||||
"category": "Core",
|
||||
"icon": "Play",
|
||||
"tags": ["runtime", "core", "framework"],
|
||||
"isCore": true,
|
||||
"defaultEnabled": true,
|
||||
"isEngineModule": true,
|
||||
"canContainContent": false,
|
||||
"platforms": ["web", "desktop", "mobile"],
|
||||
"dependencies": ["core", "asset-system"],
|
||||
"exports": {},
|
||||
"requiresWasm": false,
|
||||
"outputPath": "dist/index.js"
|
||||
}
|
||||
@@ -42,7 +42,7 @@ export async function loadPlugin(
|
||||
const exportName = packageInfo.pluginExport || 'default';
|
||||
const plugin = module[exportName] as IPlugin;
|
||||
|
||||
if (!plugin || !plugin.descriptor) {
|
||||
if (!plugin || !plugin.manifest) {
|
||||
console.warn(`[PluginLoader] Invalid plugin export from ${packageId}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -5,35 +5,9 @@
|
||||
|
||||
import { ComponentRegistry, ServiceContainer } from '@esengine/ecs-framework';
|
||||
import type { IScene } from '@esengine/ecs-framework';
|
||||
import type { IPlugin, IRuntimeModule, SystemContext, ModuleManifest } from '@esengine/engine-core';
|
||||
|
||||
export interface SystemContext {
|
||||
isEditor: boolean;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface PluginDescriptor {
|
||||
id: string;
|
||||
name: string;
|
||||
version: string;
|
||||
description?: string;
|
||||
category?: string;
|
||||
enabledByDefault?: boolean;
|
||||
isEnginePlugin?: boolean;
|
||||
}
|
||||
|
||||
export interface IRuntimeModule {
|
||||
registerComponents?(registry: typeof ComponentRegistry): void;
|
||||
registerServices?(services: ServiceContainer): void;
|
||||
createSystems?(scene: IScene, context: SystemContext): void;
|
||||
onSystemsCreated?(scene: IScene, context: SystemContext): void;
|
||||
onInitialize?(): Promise<void>;
|
||||
onDestroy?(): void;
|
||||
}
|
||||
|
||||
export interface IPlugin {
|
||||
readonly descriptor: PluginDescriptor;
|
||||
readonly runtimeModule?: IRuntimeModule;
|
||||
}
|
||||
export type { IPlugin, IRuntimeModule, SystemContext, ModuleManifest };
|
||||
|
||||
export class RuntimePluginManager {
|
||||
private _plugins = new Map<string, IPlugin>();
|
||||
@@ -41,12 +15,12 @@ export class RuntimePluginManager {
|
||||
private _bInitialized = false;
|
||||
|
||||
register(plugin: IPlugin): void {
|
||||
const id = plugin.descriptor.id;
|
||||
const id = plugin.manifest.id;
|
||||
if (this._plugins.has(id)) {
|
||||
return;
|
||||
}
|
||||
this._plugins.set(id, plugin);
|
||||
if (plugin.descriptor.enabledByDefault !== false) {
|
||||
if (plugin.manifest.defaultEnabled !== false) {
|
||||
this._enabledPlugins.add(id);
|
||||
}
|
||||
}
|
||||
@@ -68,9 +42,9 @@ export class RuntimePluginManager {
|
||||
for (const id of config.enabledPlugins) {
|
||||
this._enabledPlugins.add(id);
|
||||
}
|
||||
// 始终启用引擎核心插件
|
||||
// 始终启用引擎核心模块
|
||||
for (const [id, plugin] of this._plugins) {
|
||||
if (plugin.descriptor.isEnginePlugin) {
|
||||
if (plugin.manifest.isEngineModule) {
|
||||
this._enabledPlugins.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
runtimePluginManager,
|
||||
type IPlugin,
|
||||
type IRuntimeModule,
|
||||
type PluginDescriptor,
|
||||
type ModuleManifest,
|
||||
type SystemContext
|
||||
} from './PluginManager';
|
||||
|
||||
@@ -22,10 +22,10 @@ export interface RuntimeConfig {
|
||||
* 创建插件(简化工厂)
|
||||
*/
|
||||
export function createPlugin(
|
||||
descriptor: PluginDescriptor,
|
||||
manifest: ModuleManifest,
|
||||
runtimeModule: IRuntimeModule
|
||||
): IPlugin {
|
||||
return { descriptor, runtimeModule };
|
||||
return { manifest, runtimeModule };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,7 @@ export async function initializeRuntime(config?: RuntimeConfig): Promise<void> {
|
||||
runtimePluginManager.loadConfig({ enabledPlugins: config.enabledPlugins });
|
||||
} else {
|
||||
for (const plugin of runtimePluginManager.getPlugins()) {
|
||||
runtimePluginManager.enable(plugin.descriptor.id);
|
||||
runtimePluginManager.enable(plugin.manifest.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ export {
|
||||
RuntimePluginManager,
|
||||
runtimePluginManager,
|
||||
type SystemContext,
|
||||
type PluginDescriptor,
|
||||
type ModuleManifest,
|
||||
type IRuntimeModule,
|
||||
type IPlugin
|
||||
} from './PluginManager';
|
||||
|
||||
Reference in New Issue
Block a user