Files
esengine/packages/core/src/Core/Plugin.ts

125 lines
2.3 KiB
TypeScript
Raw Normal View History

2025-10-11 09:26:36 +08:00
import type { Core } from '../Core';
import type { ServiceContainer } from './ServiceContainer';
/**
*
*/
export enum PluginState {
/**
*
*/
NotInstalled = 'not_installed',
/**
*
*/
Installed = 'installed',
/**
*
*/
Failed = 'failed'
}
/**
*
*
*
*
*
* @example
* ```typescript
* class MyPlugin implements IPlugin {
* readonly name = 'my-plugin';
* readonly version = '1.0.0';
* readonly dependencies = ['other-plugin'];
*
* async install(core: Core, services: ServiceContainer) {
* // 注册服务
* services.registerSingleton(MyService);
*
* // 添加系统
* const world = core.getWorld();
* if (world) {
* world.addSystem(new MySystem());
* }
* }
*
* async uninstall() {
* // 清理资源
* }
* }
* ```
*/
export interface IPlugin {
/**
*
*
*
*/
readonly name: string;
/**
*
*
* (semver)
*/
readonly version: string;
/**
*
*
*
*/
readonly dependencies?: readonly string[];
/**
*
*
*
*
*
* @param core - Core实例访World等
* @param services -
*/
install(core: Core, services: ServiceContainer): void | Promise<void>;
/**
*
*
*
*
*/
uninstall(): void | Promise<void>;
}
/**
*
*/
export interface IPluginMetadata {
/**
*
*/
name: string;
/**
*
*/
version: string;
/**
*
*/
state: PluginState;
/**
*
*/
installedAt?: number;
/**
*
*/
error?: string;
}