import { inject, injectable } from 'inversify'; import { PipelineRegistry } from './pipeline'; import { EditorState, EditorStateConfigEntity, LayerRegistry } from './layer'; import { AbleManager, AbleRegistry, EntityManager, EntityRegistry } from '../common'; import type { Playground } from './playground'; import { PlaygroundCommandRegistry, PlaygroundKeybindingRegistry, PlaygroundMenuRegistry } from './playground-registries'; import { PlaygroundConfig } from './playground-config'; export const PlaygroundContribution = Symbol('PlaygroundContribution'); export interface PlaygroundContribution { /** * 注册 Layer/Entity/Able 相关 * @param registry */ registerPlayground?(registry: PlaygroundRegistry): void /** * 初始化entity完毕后触发 * @param playground */ onReady?(playground: Playground): void /** * 销毁 * @param playground */ onDispose?(playground: Playground): void } @injectable() export class PlaygroundRegistry { @inject(PipelineRegistry) protected readonly pipeline: PipelineRegistry; @inject(AbleManager) readonly ableManager: AbleManager; @inject(EntityManager) readonly entityManager: EntityManager; @inject(PlaygroundConfig) readonly playgroundConfig: PlaygroundConfig; @inject(PlaygroundCommandRegistry) readonly commands: PlaygroundCommandRegistry; @inject(PlaygroundMenuRegistry) readonly menus: PlaygroundMenuRegistry; @inject(PlaygroundKeybindingRegistry) readonly keybindings: PlaygroundKeybindingRegistry; config(config: Partial): void { Object.assign(this.playgroundConfig, config); } registerLayer(layerRegistry: LayerRegistry): void { this.pipeline.registerLayer(layerRegistry); } registerEntity(entityRegistry: EntityRegistry): void { this.entityManager.registerEntity(entityRegistry); } registerAble(ableRegistry: AbleRegistry): void { this.ableManager.registerAble(ableRegistry); } registerEditorState(state: EditorState): void { const stateConfig = this.entityManager.getEntity(EditorStateConfigEntity); stateConfig?.registerState(state); } }