Files
esengine/packages/framework/blueprint/src/index.ts
YHH 2e84942ea1 feat(blueprint): refactor BlueprintComponent as proper ECS Component (#433)
* feat(blueprint): refactor BlueprintComponent as proper ECS Component

- Convert BlueprintComponent from interface to actual ECS Component class
- Add ready-to-use BlueprintSystem that extends EntitySystem
- Remove deprecated legacy APIs (createBlueprintSystem, etc.)
- Update all blueprint documentation (Chinese & English)
- Simplify user API: just add BlueprintSystem and BlueprintComponent

BREAKING CHANGE: BlueprintComponent is now a class extending Component,
not an interface. Use `new BlueprintComponent()` instead of
`createBlueprintComponentData()`.

* chore(blueprint): add changeset for ECS component refactor

* fix(node-editor): fix connections not rendering when node is collapsed

- getPinPosition now returns node header position when pin element is not found
- Added collapsedNodesKey to force re-render connections after collapse/expand
- Input pins connect to left side, output pins to right side of collapsed nodes

* chore(node-editor): add changeset for collapse connection fix

* feat(blueprint): add Add Component nodes for entity-component creation

- Add type-specific Add_ComponentName nodes via ComponentNodeGenerator
- Add generic ECS_AddComponent node for dynamic component creation
- Add ExecutionContext.getComponentClass() for component lookup
- Add registerComponentClass() helper for manual component registration
- Each Add node supports initial property values from @BlueprintProperty

* docs: update changeset with Add Component feature

* feat(blueprint): improve event nodes with Self output and auto-create BeginPlay

- Event Begin Play now outputs Self entity
- Event Tick now outputs Self entity + Delta Seconds
- Event End Play now outputs Self entity
- createEmptyBlueprint() now includes Event Begin Play by default
- Added menuPath to all event nodes for better organization
2026-01-04 11:50:16 +08:00

109 lines
3.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @esengine/blueprint - Visual scripting system for ECS Framework
*
* @zh 蓝图可视化脚本系统 - 与 ECS 框架深度集成
* @en Visual scripting system - Deep integration with ECS framework
*
* @zh 此包提供完整的可视化脚本功能:
* - 内置 ECS 操作节点Entity、Component、Flow
* - 组件自动节点生成(使用装饰器标记)
* - 运行时蓝图执行
*
* @en This package provides complete visual scripting features:
* - Built-in ECS operation nodes (Entity, Component, Flow)
* - Auto component node generation (using decorators)
* - Runtime blueprint execution
*
* @example 基础使用 | Basic Usage:
* ```typescript
* import { BlueprintSystem, BlueprintComponent } from '@esengine/blueprint';
* import { Scene, Core } from '@esengine/ecs-framework';
*
* // 创建场景并添加蓝图系统
* const scene = new Scene();
* scene.addSystem(new BlueprintSystem());
* Core.setScene(scene);
*
* // 为实体添加蓝图
* const entity = scene.createEntity('Player');
* const blueprint = new BlueprintComponent();
* blueprint.blueprintAsset = await loadBlueprintAsset('player.bp');
* entity.addComponent(blueprint);
* ```
*
* @example 标记组件 | Mark Components:
* ```typescript
* import { BlueprintExpose, BlueprintProperty, BlueprintMethod } from '@esengine/blueprint';
* import { Component, ECSComponent } from '@esengine/ecs-framework';
*
* @ECSComponent('Health')
* @BlueprintExpose({ displayName: '生命值' })
* export class HealthComponent extends Component {
* @BlueprintProperty({ displayName: '当前生命值' })
* current: number = 100;
*
* @BlueprintMethod({ displayName: '治疗' })
* heal(amount: number): void {
* this.current += amount;
* }
* }
* ```
*
* @packageDocumentation
*/
// Types
export * from './types';
// Runtime
export * from './runtime';
// Triggers
export * from './triggers';
// Composition
export * from './composition';
// Registry (decorators & auto-generation)
export * from './registry';
// Nodes (import to register built-in nodes)
import './nodes';
// Re-export commonly used items
export { NodeRegistry, RegisterNode } from './runtime/NodeRegistry';
export { BlueprintVM } from './runtime/BlueprintVM';
export { BlueprintComponent } from './runtime/BlueprintComponent';
export { BlueprintSystem } from './runtime/BlueprintSystem';
export { ExecutionContext } from './runtime/ExecutionContext';
export { createEmptyBlueprint, validateBlueprintAsset } from './types/blueprint';
// Component registration helper
import { ExecutionContext } from './runtime/ExecutionContext';
import type { Component } from '@esengine/ecs-framework';
/**
* @zh 注册组件类以支持在蓝图中动态创建
* @en Register a component class for dynamic creation in blueprints
*
* @example
* ```typescript
* import { registerComponentClass } from '@esengine/blueprint';
* import { MyComponent } from './MyComponent';
*
* registerComponentClass('MyComponent', MyComponent);
* ```
*/
export function registerComponentClass(typeName: string, componentClass: new () => Component): void {
ExecutionContext.registerComponentClass(typeName, componentClass);
}
// Re-export registry for convenience
export {
BlueprintExpose,
BlueprintProperty,
BlueprintMethod,
registerAllComponentNodes,
registerComponentNodes
} from './registry';