From f8c181836eec082942d5cacd06811dd25a8f27f7 Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Thu, 25 Dec 2025 13:07:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor(blueprint):=20=E4=BD=BF=E7=94=A8=20ecs?= =?UTF-8?q?-framework=20=E7=9A=84=20Entity=20=E5=92=8C=20IScene=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=20(#328)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从 @esengine/ecs-framework 导入 Entity 和 IScene 类型 - 移除 ExecutionContext.ts 中的自定义 IEntity 和 IScene 接口 - 更新 BlueprintComponent.ts、BlueprintVM.ts、BlueprintSystem.ts 使用正确的类型 这使得 blueprint 包与 ecs-framework 的类型保持一致,避免重复定义接口。 --- .../src/runtime/BlueprintComponent.ts | 4 +-- .../blueprint/src/runtime/BlueprintSystem.ts | 4 +-- packages/blueprint/src/runtime/BlueprintVM.ts | 5 ++-- .../blueprint/src/runtime/ExecutionContext.ts | 30 ++----------------- 4 files changed, 10 insertions(+), 33 deletions(-) diff --git a/packages/blueprint/src/runtime/BlueprintComponent.ts b/packages/blueprint/src/runtime/BlueprintComponent.ts index 16ddd6f3..7595b0e7 100644 --- a/packages/blueprint/src/runtime/BlueprintComponent.ts +++ b/packages/blueprint/src/runtime/BlueprintComponent.ts @@ -3,9 +3,9 @@ * 蓝图组件 - 将蓝图附加到实体 */ +import type { Entity, IScene } from '@esengine/ecs-framework'; import { BlueprintAsset } from '../types/blueprint'; import { BlueprintVM } from './BlueprintVM'; -import { IEntity, IScene } from './ExecutionContext'; /** * Component interface for ECS integration @@ -56,7 +56,7 @@ export function createBlueprintComponentData(): IBlueprintComponent { */ export function initializeBlueprintVM( component: IBlueprintComponent, - entity: IEntity, + entity: Entity, scene: IScene ): void { if (!component.blueprintAsset) { diff --git a/packages/blueprint/src/runtime/BlueprintSystem.ts b/packages/blueprint/src/runtime/BlueprintSystem.ts index 03297a8e..083a74cd 100644 --- a/packages/blueprint/src/runtime/BlueprintSystem.ts +++ b/packages/blueprint/src/runtime/BlueprintSystem.ts @@ -3,6 +3,7 @@ * 蓝图执行系统 - 管理蓝图生命周期和执行 */ +import type { Entity, IScene } from '@esengine/ecs-framework'; import { IBlueprintComponent, initializeBlueprintVM, @@ -10,7 +11,6 @@ import { tickBlueprint, cleanupBlueprint } from './BlueprintComponent'; -import { IEntity, IScene } from './ExecutionContext'; /** * Blueprint system interface for engine integration @@ -31,7 +31,7 @@ export interface IBlueprintSystem { * Entity with blueprint component * 带有蓝图组件的实体 */ -export interface IBlueprintEntity extends IEntity { +export interface IBlueprintEntity extends Entity { /** Blueprint component data (蓝图组件数据) */ blueprintComponent: IBlueprintComponent; } diff --git a/packages/blueprint/src/runtime/BlueprintVM.ts b/packages/blueprint/src/runtime/BlueprintVM.ts index f09d66e4..aab66f6d 100644 --- a/packages/blueprint/src/runtime/BlueprintVM.ts +++ b/packages/blueprint/src/runtime/BlueprintVM.ts @@ -3,9 +3,10 @@ * 蓝图虚拟机 - 执行蓝图图 */ +import type { Entity, IScene } from '@esengine/ecs-framework'; import { BlueprintNode } from '../types/nodes'; import { BlueprintAsset } from '../types/blueprint'; -import { ExecutionContext, ExecutionResult, IEntity, IScene } from './ExecutionContext'; +import { ExecutionContext, ExecutionResult } from './ExecutionContext'; import { NodeRegistry } from './NodeRegistry'; /** @@ -57,7 +58,7 @@ export class BlueprintVM { /** Debug mode (调试模式) */ debug: boolean = false; - constructor(blueprint: BlueprintAsset, entity: IEntity, scene: IScene) { + constructor(blueprint: BlueprintAsset, entity: Entity, scene: IScene) { this._context = new ExecutionContext(blueprint, entity, scene); this._cacheEventNodes(); } diff --git a/packages/blueprint/src/runtime/ExecutionContext.ts b/packages/blueprint/src/runtime/ExecutionContext.ts index aeaaf97d..0180714c 100644 --- a/packages/blueprint/src/runtime/ExecutionContext.ts +++ b/packages/blueprint/src/runtime/ExecutionContext.ts @@ -3,6 +3,7 @@ * 执行上下文 - 蓝图执行的运行时上下文 */ +import type { Entity, IScene } from '@esengine/ecs-framework'; import { BlueprintNode, BlueprintConnection } from '../types/nodes'; import { BlueprintAsset } from '../types/blueprint'; @@ -42,31 +43,6 @@ export interface ExecutionResult { error?: string; } -/** - * Entity interface (minimal for decoupling) - * 实体接口(最小化以解耦) - */ -export interface IEntity { - id: number; - name: string; - active: boolean; - getComponent(type: new (...args: unknown[]) => T): T | null; - addComponent(component: T): T; - removeComponent(type: new (...args: unknown[]) => T): void; - hasComponent(type: new (...args: unknown[]) => T): boolean; -} - -/** - * Scene interface (minimal for decoupling) - * 场景接口(最小化以解耦) - */ -export interface IScene { - createEntity(name?: string): IEntity; - destroyEntity(entity: IEntity): void; - findEntityByName(name: string): IEntity | null; - findEntitiesByTag(tag: number): IEntity[]; -} - /** * Execution context provides access to runtime services * 执行上下文提供对运行时服务的访问 @@ -76,7 +52,7 @@ export class ExecutionContext { readonly blueprint: BlueprintAsset; /** Owner entity (所有者实体) */ - readonly entity: IEntity; + readonly entity: Entity; /** Current scene (当前场景) */ readonly scene: IScene; @@ -105,7 +81,7 @@ export class ExecutionContext { /** Connection lookup by source (按源的连接查找) */ private _connectionsBySource: Map = new Map(); - constructor(blueprint: BlueprintAsset, entity: IEntity, scene: IScene) { + constructor(blueprint: BlueprintAsset, entity: Entity, scene: IScene) { this.blueprint = blueprint; this.entity = entity; this.scene = scene;