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:
YHH
2025-12-19 17:48:18 +08:00
committed by GitHub
parent ecdb8f2021
commit e24c850568
51 changed files with 492 additions and 623 deletions

View File

@@ -11,23 +11,11 @@ import { Input, MouseButton, TransformComponent, SortingLayers } from '@esengine
import { ClickFxComponent, ClickFxTriggerMode } from '../ClickFxComponent';
import { ParticleSystemComponent, RenderSpace } from '../ParticleSystemComponent';
import { CoordinateServiceToken, type ICoordinateService } from '@esengine/ecs-engine-bindgen';
// ============================================================================
// 本地服务令牌定义 | Local Service Token Definitions
// ============================================================================
// 使用 createServiceToken() 本地定义(与 runtime-core 相同策略)
// createServiceToken() 使用 Symbol.for(),确保运行时与源模块令牌匹配
//
// Local token definitions using createServiceToken() (same strategy as runtime-core)
// createServiceToken() uses Symbol.for(), ensuring runtime match with source module tokens
// ============================================================================
/**
* EngineBridge 接口(最小定义,用于坐标转换)
* EngineBridge interface (minimal definition for coordinate conversion)
*/
interface IEngineBridge {
screenToWorld(screenX: number, screenY: number): { x: number; y: number };
}
/**
* EngineRenderSystem 接口(最小定义,用于获取 UI Canvas 尺寸)
@@ -37,10 +25,6 @@ interface IEngineRenderSystem {
getUICanvasSize(): { width: number; height: number };
}
// EngineBridge 令牌(与 engine-core 中的一致)
// EngineBridge token (consistent with engine-core)
const EngineBridgeToken = createServiceToken<IEngineBridge>('engineBridge');
// RenderSystem 令牌(与 ecs-engine-bindgen 中的一致)
// RenderSystem token (consistent with ecs-engine-bindgen)
const RenderSystemToken = createServiceToken<IEngineRenderSystem>('renderSystem');
@@ -62,7 +46,7 @@ const RenderSystemToken = createServiceToken<IEngineRenderSystem>('renderSystem'
*/
@ECSSystem('ClickFx', { updateOrder: 100 })
export class ClickFxSystem extends EntitySystem {
private _engineBridge: IEngineBridge | null = null;
private _coordinateService: ICoordinateService | null = null;
private _renderSystem: IEngineRenderSystem | null = null;
private _entitiesToDestroy: Entity[] = [];
private _canvas: HTMLCanvasElement | null = null;
@@ -72,20 +56,20 @@ export class ClickFxSystem extends EntitySystem {
}
/**
* 设置服务注册表(用于获取 EngineBridge 和 RenderSystem
* Set service registry (for getting EngineBridge and RenderSystem)
* 设置服务注册表(用于获取 CoordinateService 和 RenderSystem
* Set service registry (for getting CoordinateService and RenderSystem)
*/
setServiceRegistry(services: PluginServiceRegistry): void {
this._engineBridge = services.get(EngineBridgeToken) ?? null;
this._coordinateService = services.get(CoordinateServiceToken) ?? null;
this._renderSystem = services.get(RenderSystemToken) ?? null;
}
/**
* 设置 EngineBridge(直接注入)
* Set EngineBridge (direct injection)
* 设置坐标服务(直接注入)
* Set coordinate service (direct injection)
*/
setEngineBridge(bridge: IEngineBridge): void {
this._engineBridge = bridge;
setCoordinateService(coordinateService: ICoordinateService): void {
this._coordinateService = coordinateService;
}
/**

View File

@@ -1,5 +1,5 @@
import { EntitySystem, Matcher, ECSSystem, Time, Entity, type Component, type ComponentType } from '@esengine/ecs-framework';
import type { IEngineIntegration, IEngineBridge } from '@esengine/ecs-engine-bindgen';
import type { IEngineIntegration, ITextureService } from '@esengine/ecs-engine-bindgen';
import type { IAssetManager } from '@esengine/asset-system';
import { ParticleSystemComponent } from '../ParticleSystemComponent';
import { ParticleRenderDataProvider } from '../rendering/ParticleRenderDataProvider';
@@ -78,7 +78,7 @@ export class ParticleUpdateSystem extends EntitySystem {
private _transformType: ComponentType<Component & ITransformComponent> | null = null;
private _renderDataProvider: ParticleRenderDataProvider;
private _engineIntegration: IEngineIntegration | null = null;
private _engineBridge: IEngineBridge | null = null;
private _textureService: ITextureService | null = null;
private _physics2DQuery: IPhysics2DQuery | null = null;
private _assetManager: IAssetManager | null = null;
private _defaultTextureLoaded: boolean = false;
@@ -114,11 +114,11 @@ export class ParticleUpdateSystem extends EntitySystem {
}
/**
* 设置引擎桥接(用于加载默认纹理)
* Set engine bridge (for loading default texture)
* 设置纹理服务(用于加载默认纹理)
* Set texture service (for loading default texture)
*/
setEngineBridge(bridge: IEngineBridge): void {
this._engineBridge = bridge;
setTextureService(textureService: ITextureService): void {
this._textureService = textureService;
}
/**
@@ -487,8 +487,8 @@ export class ParticleUpdateSystem extends EntitySystem {
}
// 没有引擎桥接,无法加载 | No engine bridge, cannot load
if (!this._engineBridge) {
console.warn('[ParticleUpdateSystem] EngineBridge not set, cannot load default texture');
if (!this._textureService) {
console.warn('[ParticleUpdateSystem] TextureService not set, cannot load default texture');
return false;
}
@@ -496,15 +496,9 @@ export class ParticleUpdateSystem extends EntitySystem {
try {
const dataUrl = generateDefaultParticleTextureDataURL();
if (dataUrl) {
// 优先使用 loadTextureAsync等待纹理就绪
// Prefer loadTextureAsync (waits for texture ready)
if (this._engineBridge.loadTextureAsync) {
await this._engineBridge.loadTextureAsync(DEFAULT_PARTICLE_TEXTURE_ID, dataUrl);
} else {
// 回退到旧 API可能显示灰色占位符
// Fallback to old API (may show gray placeholder)
await this._engineBridge.loadTexture(DEFAULT_PARTICLE_TEXTURE_ID, dataUrl);
}
// 使用 loadTextureAsync等待纹理就绪
// Use loadTextureAsync (waits for texture ready)
await this._textureService.loadTextureAsync(DEFAULT_PARTICLE_TEXTURE_ID, dataUrl);
this._defaultTextureLoaded = true;
}
} catch (error) {