Files
esengine/packages/camera-editor/src/index.ts
YHH e24c850568 refactor: 类型安全与接口清理 (#311)
* refactor: 分解 IEngineBridge 为单一职责接口

- 新增 ITextureService, IDynamicAtlasService, ICoordinateService, IRenderConfigService
- 移除 EngineBridgeToken,改用具体服务 Token
- 更新 camera, ui, particle 等模块使用新接口
- 优化装饰器类型安全,使用 Symbol-based metadata 访问模式

* refactor: 删除 plugin-types 包,统一 createServiceToken 实现

- 移动 IEditorModuleBase 接口到 engine-core
- 移除 engine-core 和 editor-core 对 plugin-types 的依赖
- 删除冗余的 plugin-types 包
- 统一使用 core 中基于 Symbol.for() 的 createServiceToken

* refactor: 统一 IPlugin 接口,移除 deprecated 别名

- 移除 engine-core、editor-core、runtime-core 中的 IPlugin 别名
- 模块插件统一使用 IRuntimePlugin(运行时)或 IEditorPlugin(编辑器)
- 保留 core 包中的 IPlugin 作为 ECS 核心插件接口(不同概念)
- 更新所有消费方使用正确的类型

* refactor: 重命名 editor-core ComponentRegistry 为 EditorComponentRegistry

- 消除与 core 包 ComponentRegistry(ECS 位掩码管理)的命名歧义
- editor-core 的 EditorComponentRegistry 专用于编辑器组件元数据
- 更新所有编辑器包使用新名称
2025-12-19 17:48:18 +08:00

92 lines
2.7 KiB
TypeScript

/**
* @esengine/camera-editor
*
* Editor support for @esengine/camera
* 相机编辑器支持
*/
import type { Entity, ServiceContainer } from '@esengine/ecs-framework';
import { Core } from '@esengine/ecs-framework';
import { TransformComponent } from '@esengine/engine-core';
import type {
IEditorModuleLoader,
EntityCreationTemplate
} from '@esengine/editor-core';
import {
EntityStoreService,
MessageHub,
EditorComponentRegistry
} from '@esengine/editor-core';
import { CameraComponent } from '@esengine/camera';
export class CameraEditorModule implements IEditorModuleLoader {
async install(services: ServiceContainer): Promise<void> {
const componentRegistry = services.resolve(EditorComponentRegistry);
if (componentRegistry) {
componentRegistry.register({
name: 'Camera',
type: CameraComponent,
category: 'components.category.rendering',
description: 'Camera for 2D/3D rendering',
icon: 'Camera'
});
}
}
async uninstall(): Promise<void> {
// Nothing to cleanup
}
getEntityCreationTemplates(): EntityCreationTemplate[] {
return [
{
id: 'create-camera',
label: 'Camera',
icon: 'Camera',
category: 'rendering',
order: 50,
create: (): number => {
return this.createCameraEntity('Camera');
}
},
];
}
private createCameraEntity(baseName: string): number {
const scene = Core.scene;
if (!scene) {
throw new Error('Scene not available');
}
const entityStore = Core.services.resolve(EntityStoreService);
const messageHub = Core.services.resolve(MessageHub);
if (!entityStore || !messageHub) {
throw new Error('EntityStoreService or MessageHub not available');
}
const existingCount = entityStore.getAllEntities()
.filter((e: Entity) => e.name.startsWith(baseName)).length;
const entityName = existingCount > 0 ? `${baseName} ${existingCount + 1}` : baseName;
const entity = scene.createEntity(entityName);
const transform = new TransformComponent();
entity.addComponent(transform);
const camera = new CameraComponent();
entity.addComponent(camera);
entityStore.addEntity(entity);
messageHub.publish('entity:added', { entity });
messageHub.publish('scene:modified', {});
entityStore.selectEntity(entity);
return entity.id;
}
}
export const cameraEditorModule = new CameraEditorModule();
export default cameraEditorModule;