2025-11-18 14:46:51 +08:00
|
|
|
import { IService } from '@esengine/ecs-framework';
|
|
|
|
|
import { ICompiler } from './ICompiler';
|
|
|
|
|
|
|
|
|
|
export class CompilerRegistry implements IService {
|
|
|
|
|
private compilers: Map<string, ICompiler> = new Map();
|
|
|
|
|
|
|
|
|
|
register(compiler: ICompiler): void {
|
|
|
|
|
if (this.compilers.has(compiler.id)) {
|
|
|
|
|
console.warn(`Compiler with id "${compiler.id}" is already registered. Overwriting.`);
|
|
|
|
|
}
|
|
|
|
|
this.compilers.set(compiler.id, compiler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unregister(compilerId: string): void {
|
|
|
|
|
this.compilers.delete(compilerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get(compilerId: string): ICompiler | undefined {
|
|
|
|
|
return this.compilers.get(compilerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getAll(): ICompiler[] {
|
|
|
|
|
return Array.from(this.compilers.values());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clear(): void {
|
|
|
|
|
this.compilers.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dispose(): void {
|
|
|
|
|
this.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-25 22:23:19 +08:00
|
|
|
|
|
|
|
|
// Service identifier for DI registration (用于跨包插件访问)
|
|
|
|
|
// 使用 Symbol.for 确保跨包共享同一个 Symbol
|
|
|
|
|
export const ICompilerRegistry = Symbol.for('ICompilerRegistry');
|