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 专用于编辑器组件元数据 - 更新所有编辑器包使用新名称
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { IComponentRegistry, IScene } from '@esengine/ecs-framework';
|
||||
import type { IRuntimeModule, IRuntimePlugin, ModuleManifest, SystemContext } from '@esengine/engine-core';
|
||||
import { EngineBridgeToken } from '@esengine/engine-core';
|
||||
import { RenderConfigServiceToken } from '@esengine/engine-core';
|
||||
import { CameraComponent } from './CameraComponent';
|
||||
import { CameraSystem } from './CameraSystem';
|
||||
|
||||
@@ -10,15 +10,15 @@ class CameraRuntimeModule implements IRuntimeModule {
|
||||
}
|
||||
|
||||
createSystems(scene: IScene, context: SystemContext): void {
|
||||
// 从服务注册表获取 EngineBridge | Get EngineBridge from service registry
|
||||
const bridge = context.services.get(EngineBridgeToken);
|
||||
if (!bridge) {
|
||||
console.warn('[CameraPlugin] EngineBridge not found, CameraSystem will not be created');
|
||||
// 从服务注册表获取渲染配置服务 | Get render config service from registry
|
||||
const renderConfig = context.services.get(RenderConfigServiceToken);
|
||||
if (!renderConfig) {
|
||||
console.warn('[CameraPlugin] RenderConfigService not found, CameraSystem will not be created');
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建并添加 CameraSystem | Create and add CameraSystem
|
||||
const cameraSystem = new CameraSystem(bridge);
|
||||
const cameraSystem = new CameraSystem(renderConfig);
|
||||
scene.addSystem(cameraSystem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,18 @@
|
||||
*/
|
||||
|
||||
import { EntitySystem, Matcher, Entity, ECSSystem } from '@esengine/ecs-framework';
|
||||
import type { IEngineBridge } from '@esengine/engine-core';
|
||||
import type { IRenderConfigService } from '@esengine/engine-core';
|
||||
import { CameraComponent } from './CameraComponent';
|
||||
|
||||
@ECSSystem('Camera', { updateOrder: -100 })
|
||||
export class CameraSystem extends EntitySystem {
|
||||
private bridge: IEngineBridge;
|
||||
private renderConfig: IRenderConfigService;
|
||||
private lastAppliedCameraId: number | null = null;
|
||||
|
||||
constructor(bridge: IEngineBridge) {
|
||||
constructor(renderConfig: IRenderConfigService) {
|
||||
// Match entities with CameraComponent
|
||||
super(Matcher.empty().all(CameraComponent));
|
||||
this.bridge = bridge;
|
||||
this.renderConfig = renderConfig;
|
||||
}
|
||||
|
||||
protected override onBegin(): void {
|
||||
@@ -47,6 +47,6 @@ export class CameraSystem extends EntitySystem {
|
||||
const r = parseInt(bgColor.slice(1, 3), 16) / 255;
|
||||
const g = parseInt(bgColor.slice(3, 5), 16) / 255;
|
||||
const b = parseInt(bgColor.slice(5, 7), 16) / 255;
|
||||
this.bridge.setClearColor(r, g, b, 1.0);
|
||||
this.renderConfig.setClearColor(r, g, b, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user