Compare commits
9 Commits
@esengine/
...
@esengine/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54c8ff4d8f | ||
|
|
caf3be72cd | ||
|
|
ec3e449681 | ||
|
|
b95a46edaf | ||
|
|
f493f2d6cc | ||
|
|
6970394717 | ||
|
|
0e4b66aac4 | ||
|
|
7399e91a5b | ||
|
|
c84addaa0b |
@@ -49,7 +49,6 @@
|
||||
"@esengine/material-editor",
|
||||
"@esengine/shader-editor",
|
||||
"@esengine/world-streaming-editor",
|
||||
"@esengine/node-editor",
|
||||
"@esengine/sdk",
|
||||
"@esengine/worker-generator",
|
||||
"@esengine/engine"
|
||||
|
||||
1
.github/workflows/release-changesets.yml
vendored
1
.github/workflows/release-changesets.yml
vendored
@@ -62,6 +62,7 @@ jobs:
|
||||
pnpm --filter "@esengine/transaction" build
|
||||
pnpm --filter "@esengine/cli" build
|
||||
pnpm --filter "create-esengine-server" build
|
||||
pnpm --filter "@esengine/node-editor" build
|
||||
|
||||
- name: Create Release Pull Request or Publish
|
||||
id: changesets
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"packages/network-ext/*",
|
||||
"packages/editor/*",
|
||||
"packages/editor/plugins/*",
|
||||
"packages/devtools/*",
|
||||
"packages/rust/*",
|
||||
"packages/tools/*"
|
||||
],
|
||||
|
||||
21
packages/devtools/node-editor/CHANGELOG.md
Normal file
21
packages/devtools/node-editor/CHANGELOG.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# @esengine/node-editor
|
||||
|
||||
## 1.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#430](https://github.com/esengine/esengine/pull/430) [`caf3be7`](https://github.com/esengine/esengine/commit/caf3be72cdcc730492c63abe5f1715893f3579ac) Thanks [@esengine](https://github.com/esengine)! - feat(node-editor): 添加 Shadow DOM 样式注入支持 | Add Shadow DOM style injection support
|
||||
|
||||
**@esengine/node-editor**
|
||||
- 新增 `nodeEditorCssText` 导出,包含所有编辑器样式的 CSS 文本 | Added `nodeEditorCssText` export containing all editor styles as CSS text
|
||||
- 新增 `injectNodeEditorStyles(root)` 函数,支持将样式注入到 Shadow DOM | Added `injectNodeEditorStyles(root)` function for injecting styles into Shadow DOM
|
||||
- 支持在 Cocos Creator 等使用 Shadow DOM 的环境中使用 | Support usage in Shadow DOM environments like Cocos Creator
|
||||
|
||||
## 1.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#426](https://github.com/esengine/esengine/pull/426) [`6970394`](https://github.com/esengine/esengine/commit/6970394717ab8f743b0a41e248e3404a3b6fc7dc) Thanks [@esengine](https://github.com/esengine)! - feat: 独立发布节点编辑器 | Standalone node editor release
|
||||
- 移动到 packages/devtools 目录 | Move to packages/devtools directory
|
||||
- 清理依赖,使包可独立使用 | Clean dependencies for standalone use
|
||||
- 可用于 Cocos Creator / LayaAir 插件开发 | Available for Cocos/Laya plugin development
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@esengine/node-editor",
|
||||
"version": "1.0.0",
|
||||
"version": "1.2.0",
|
||||
"description": "Universal node-based visual editor for blueprint, shader graph, and state machine",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
@@ -9,7 +9,8 @@
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./dist/index.js"
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"./styles": {
|
||||
"import": "./dist/styles/index.css"
|
||||
@@ -30,17 +31,18 @@
|
||||
"blueprint",
|
||||
"shader-graph",
|
||||
"state-machine",
|
||||
"ecs",
|
||||
"game-engine"
|
||||
"react"
|
||||
],
|
||||
"author": "yhh",
|
||||
"author": "ESEngine Team",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"react": "^18.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"react": "^18.3.1",
|
||||
"zustand": "^5.0.8",
|
||||
"@types/node": "^20.19.17",
|
||||
"@types/react": "^18.3.12",
|
||||
"@vitejs/plugin-react": "^4.7.0",
|
||||
"react": "^18.3.1",
|
||||
"rimraf": "^5.0.0",
|
||||
"typescript": "^5.8.3",
|
||||
"vite": "^6.0.7",
|
||||
@@ -56,7 +58,6 @@
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/esengine/esengine.git",
|
||||
"directory": "packages/node-editor"
|
||||
},
|
||||
"private": true
|
||||
"directory": "packages/devtools/node-editor"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useRef, useCallback, useState, useMemo } from 'react';
|
||||
import React, { useRef, useCallback, useState, useMemo, useEffect } from 'react';
|
||||
import { Graph } from '../../domain/models/Graph';
|
||||
import { GraphNode, NodeTemplate } from '../../domain/models/GraphNode';
|
||||
import { Connection } from '../../domain/models/Connection';
|
||||
@@ -127,6 +127,18 @@ export const NodeEditor: React.FC<NodeEditorProps> = ({
|
||||
const [connectionDrag, setConnectionDrag] = useState<ConnectionDragState | null>(null);
|
||||
const [hoveredPin, setHoveredPin] = useState<Pin | null>(null);
|
||||
|
||||
// Force re-render after mount to ensure connections are drawn correctly
|
||||
// 挂载后强制重渲染以确保连接线正确绘制
|
||||
const [, forceUpdate] = useState(0);
|
||||
useEffect(() => {
|
||||
// Use requestAnimationFrame to wait for DOM to be fully rendered
|
||||
// 使用 requestAnimationFrame 等待 DOM 完全渲染
|
||||
const rafId = requestAnimationFrame(() => {
|
||||
forceUpdate(n => n + 1);
|
||||
});
|
||||
return () => cancelAnimationFrame(rafId);
|
||||
}, [graph.id]);
|
||||
|
||||
/**
|
||||
* Converts screen coordinates to canvas coordinates
|
||||
* 将屏幕坐标转换为画布坐标
|
||||
@@ -10,6 +10,9 @@
|
||||
// Import styles (导入样式)
|
||||
import './styles/index.css';
|
||||
|
||||
// CSS utilities for Shadow DOM (Shadow DOM 的 CSS 工具)
|
||||
export { nodeEditorCssText, injectNodeEditorStyles } from './styles/cssText';
|
||||
|
||||
// Domain models (领域模型)
|
||||
export {
|
||||
// Models
|
||||
55
packages/devtools/node-editor/src/styles/cssText.ts
Normal file
55
packages/devtools/node-editor/src/styles/cssText.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @zh 节点编辑器 CSS 样式文本
|
||||
* @en Node Editor CSS style text
|
||||
*
|
||||
* @zh 此文件在构建时由 vite 插件自动生成
|
||||
* @en This file is auto-generated by vite plugin during build
|
||||
*/
|
||||
|
||||
// Placeholder - will be replaced by vite plugin during build
|
||||
export const nodeEditorCssText = '__NODE_EDITOR_CSS_PLACEHOLDER__';
|
||||
|
||||
/**
|
||||
* @zh 将 CSS 注入到指定的根节点(支持 Shadow DOM)
|
||||
* @en Inject CSS into specified root node (supports Shadow DOM)
|
||||
*
|
||||
* @param root - @zh 目标根节点(Document 或 ShadowRoot)@en Target root node (Document or ShadowRoot)
|
||||
* @param styleId - @zh 样式标签的 ID @en ID for the style tag
|
||||
* @returns @zh 创建的 style 元素 @en The created style element
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Inject into Shadow DOM
|
||||
* const shadowRoot = element.attachShadow({ mode: 'open' });
|
||||
* injectNodeEditorStyles(shadowRoot);
|
||||
*
|
||||
* // Inject into document (with custom ID)
|
||||
* injectNodeEditorStyles(document, 'my-editor-styles');
|
||||
* ```
|
||||
*/
|
||||
export function injectNodeEditorStyles(
|
||||
root: Document | ShadowRoot | DocumentFragment,
|
||||
styleId: string = 'esengine-node-editor-styles'
|
||||
): HTMLStyleElement | null {
|
||||
// Check if already injected
|
||||
const existingStyle = (root as any).getElementById?.(styleId) ||
|
||||
(root as any).querySelector?.(`#${styleId}`);
|
||||
if (existingStyle) {
|
||||
return existingStyle as HTMLStyleElement;
|
||||
}
|
||||
|
||||
// Create and inject style element
|
||||
const style = document.createElement('style');
|
||||
style.id = styleId;
|
||||
style.textContent = nodeEditorCssText;
|
||||
|
||||
if ('head' in root) {
|
||||
// Document
|
||||
(root as Document).head.appendChild(style);
|
||||
} else {
|
||||
// ShadowRoot or DocumentFragment
|
||||
root.appendChild(style);
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
@@ -4,12 +4,14 @@ import dts from 'vite-plugin-dts';
|
||||
import react from '@vitejs/plugin-react';
|
||||
|
||||
/**
|
||||
* Custom plugin: Convert CSS to self-executing style injection code
|
||||
* 自定义插件:将 CSS 转换为自执行的样式注入代码
|
||||
* Custom plugin: Handle CSS for node editor
|
||||
* 自定义插件:处理节点编辑器的 CSS
|
||||
*
|
||||
* This plugin does two things:
|
||||
* 1. Auto-injects CSS into document.head for normal usage
|
||||
* 2. Replaces placeholder in cssText.ts with actual CSS for Shadow DOM usage
|
||||
*/
|
||||
function injectCSSPlugin(): any {
|
||||
let cssCounter = 0;
|
||||
|
||||
return {
|
||||
name: 'inject-css-plugin',
|
||||
enforce: 'post' as const,
|
||||
@@ -23,19 +25,28 @@ function injectCSSPlugin(): any {
|
||||
const cssChunk = bundle[cssFile];
|
||||
if (!cssChunk || !cssChunk.source) continue;
|
||||
|
||||
const cssContent = cssChunk.source;
|
||||
const styleId = `esengine-node-editor-style-${cssCounter++}`;
|
||||
const cssContent = cssChunk.source as string;
|
||||
const styleId = 'esengine-node-editor-styles';
|
||||
|
||||
// Generate style injection code (生成样式注入代码)
|
||||
const injectCode = `(function(){if(typeof document!=='undefined'){var s=document.createElement('style');s.id='${styleId}';if(!document.getElementById(s.id)){s.textContent=${JSON.stringify(cssContent)};document.head.appendChild(s);}}})();`;
|
||||
|
||||
// Inject into index.js (注入到 index.js)
|
||||
// Process all JS bundles (处理所有 JS 包)
|
||||
for (const jsKey of bundleKeys) {
|
||||
if (!jsKey.endsWith('.js')) continue;
|
||||
if (!jsKey.endsWith('.js') && !jsKey.endsWith('.cjs')) continue;
|
||||
const jsChunk = bundle[jsKey];
|
||||
if (!jsChunk || jsChunk.type !== 'chunk' || !jsChunk.code) continue;
|
||||
|
||||
if (jsKey === 'index.js') {
|
||||
// Replace CSS placeholder with actual CSS content
|
||||
// 将 CSS 占位符替换为实际的 CSS 内容
|
||||
// Match both single and double quotes (ESM uses single, CJS uses double)
|
||||
jsChunk.code = jsChunk.code.replace(
|
||||
/['"]__NODE_EDITOR_CSS_PLACEHOLDER__['"]/g,
|
||||
JSON.stringify(cssContent)
|
||||
);
|
||||
|
||||
// Auto-inject CSS for index bundles (为 index 包自动注入 CSS)
|
||||
if (jsKey === 'index.js' || jsKey === 'index.cjs') {
|
||||
jsChunk.code = injectCode + '\n' + jsChunk.code;
|
||||
}
|
||||
}
|
||||
@@ -65,8 +76,11 @@ export default defineConfig({
|
||||
entry: {
|
||||
index: resolve(__dirname, 'src/index.ts')
|
||||
},
|
||||
formats: ['es'],
|
||||
fileName: (format, entryName) => `${entryName}.js`
|
||||
formats: ['es', 'cjs'],
|
||||
fileName: (format, entryName) => {
|
||||
if (format === 'cjs') return `${entryName}.cjs`;
|
||||
return `${entryName}.js`;
|
||||
}
|
||||
},
|
||||
rollupOptions: {
|
||||
external: [
|
||||
@@ -1,5 +1,17 @@
|
||||
# @esengine/blueprint
|
||||
|
||||
## 4.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#430](https://github.com/esengine/esengine/pull/430) [`caf3be7`](https://github.com/esengine/esengine/commit/caf3be72cdcc730492c63abe5f1715893f3579ac) Thanks [@esengine](https://github.com/esengine)! - feat(blueprint): 重构装饰器系统,移除 Reflect 依赖 | Refactor decorator system, remove Reflect dependency
|
||||
|
||||
**@esengine/blueprint**
|
||||
- 移除 `Reflect.getMetadata` 依赖,装饰器现在要求显式指定类型 | Removed `Reflect.getMetadata` dependency, decorators now require explicit type specification
|
||||
- 简化 `BlueprintProperty` 和 `BlueprintMethod` 装饰器的元数据结构 | Simplified metadata structure for `BlueprintProperty` and `BlueprintMethod` decorators
|
||||
- 新增 `inferPinType` 工具函数用于类型推断 | Added `inferPinType` utility function for type inference
|
||||
- 优化组件节点生成器以适配新的元数据结构 | Optimized component node generator for new metadata structure
|
||||
|
||||
## 4.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@esengine/blueprint",
|
||||
"version": "4.0.1",
|
||||
"version": "4.1.0",
|
||||
"description": "Visual scripting system - works with any ECS framework (ESEngine, Cocos, Laya, etc.)",
|
||||
"main": "dist/index.js",
|
||||
"module": "dist/index.js",
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* @zh ESEngine 蓝图插件
|
||||
* @en ESEngine Blueprint Plugin
|
||||
*
|
||||
* @zh 此文件包含与 ESEngine 引擎核心集成的代码。
|
||||
* 使用 Cocos/Laya 等其他引擎时不需要此文件。
|
||||
*
|
||||
* @en This file contains code for integrating with ESEngine engine-core.
|
||||
* Not needed when using other engines like Cocos/Laya.
|
||||
*/
|
||||
|
||||
import type { IRuntimePlugin, ModuleManifest, IRuntimeModule } from '@esengine/engine-core';
|
||||
|
||||
/**
|
||||
* @zh 蓝图运行时模块
|
||||
* @en Blueprint Runtime Module
|
||||
*
|
||||
* @zh 注意:蓝图使用自定义系统 (IBlueprintSystem) 而非 EntitySystem,
|
||||
* 因此这里不实现 createSystems。蓝图系统应使用 createBlueprintSystem(scene) 手动创建。
|
||||
*
|
||||
* @en Note: Blueprint uses a custom system (IBlueprintSystem) instead of EntitySystem,
|
||||
* so createSystems is not implemented here. Blueprint systems should be created
|
||||
* manually using createBlueprintSystem(scene).
|
||||
*/
|
||||
class BlueprintRuntimeModule implements IRuntimeModule {
|
||||
async onInitialize(): Promise<void> {
|
||||
// Blueprint system initialization
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
// Cleanup
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 蓝图的插件清单
|
||||
* @en Plugin manifest for Blueprint
|
||||
*/
|
||||
const manifest: ModuleManifest = {
|
||||
id: 'blueprint',
|
||||
name: '@esengine/blueprint',
|
||||
displayName: 'Blueprint',
|
||||
version: '1.0.0',
|
||||
description: '可视化脚本系统',
|
||||
category: 'AI',
|
||||
icon: 'Workflow',
|
||||
isCore: false,
|
||||
defaultEnabled: false,
|
||||
isEngineModule: true,
|
||||
dependencies: ['core'],
|
||||
exports: {
|
||||
components: ['BlueprintComponent'],
|
||||
systems: ['BlueprintSystem']
|
||||
},
|
||||
requiresWasm: false
|
||||
};
|
||||
|
||||
/**
|
||||
* @zh 蓝图插件
|
||||
* @en Blueprint Plugin
|
||||
*/
|
||||
export const BlueprintPlugin: IRuntimePlugin = {
|
||||
manifest,
|
||||
runtimeModule: new BlueprintRuntimeModule()
|
||||
};
|
||||
|
||||
export { BlueprintRuntimeModule };
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* @zh ESEngine 集成入口
|
||||
* @en ESEngine integration entry point
|
||||
*
|
||||
* @zh 此模块包含与 ESEngine 引擎核心集成所需的所有代码。
|
||||
* 使用 Cocos/Laya 等其他引擎时,只需导入主模块即可。
|
||||
*
|
||||
* @en This module contains all code required for ESEngine engine-core integration.
|
||||
* When using other engines like Cocos/Laya, just import the main module.
|
||||
*
|
||||
* @example ESEngine 使用方式 / ESEngine usage:
|
||||
* ```typescript
|
||||
* import { BlueprintPlugin } from '@esengine/blueprint/esengine';
|
||||
*
|
||||
* // Register with ESEngine plugin system
|
||||
* engine.registerPlugin(BlueprintPlugin);
|
||||
* ```
|
||||
*
|
||||
* @example Cocos/Laya 使用方式 / Cocos/Laya usage:
|
||||
* ```typescript
|
||||
* import {
|
||||
* createBlueprintSystem,
|
||||
* createBlueprintComponentData
|
||||
* } from '@esengine/blueprint';
|
||||
*
|
||||
* // Create blueprint system for your scene
|
||||
* const blueprintSystem = createBlueprintSystem(scene);
|
||||
*
|
||||
* // Add to your game loop
|
||||
* function update(dt) {
|
||||
* blueprintSystem.process(blueprintEntities, dt);
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
|
||||
// Runtime module and plugin
|
||||
export { BlueprintPlugin, BlueprintRuntimeModule } from './BlueprintPlugin';
|
||||
@@ -1,32 +1,47 @@
|
||||
/**
|
||||
* @esengine/blueprint - Visual scripting system for ECS Framework
|
||||
*
|
||||
* @zh 蓝图可视化脚本系统 - 可与任何 ECS 框架配合使用
|
||||
* @en Visual scripting system - works with any ECS framework
|
||||
* @zh 蓝图可视化脚本系统 - 与 ECS 框架深度集成
|
||||
* @en Visual scripting system - Deep integration with ECS framework
|
||||
*
|
||||
* @zh 此包是通用的可视化脚本实现,可以与任何 ECS 框架配合使用。
|
||||
* 对于 ESEngine 集成,请从 '@esengine/blueprint/esengine' 导入插件。
|
||||
* @zh 此包提供完整的可视化脚本功能:
|
||||
* - 内置 ECS 操作节点(Entity、Component、Flow)
|
||||
* - 组件自动节点生成(使用装饰器标记)
|
||||
* - 运行时蓝图执行
|
||||
*
|
||||
* @en This package is a generic visual scripting implementation that works with any ECS framework.
|
||||
* For ESEngine integration, import the plugin from '@esengine/blueprint/esengine'.
|
||||
* @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 Cocos/Laya/通用 ECS 使用方式:
|
||||
* @example 基础使用 | Basic usage:
|
||||
* ```typescript
|
||||
* import {
|
||||
* createBlueprintSystem,
|
||||
* createBlueprintComponentData
|
||||
* registerAllComponentNodes
|
||||
* } from '@esengine/blueprint';
|
||||
*
|
||||
* // Create blueprint system for your scene
|
||||
* // 注册所有标记的组件节点 | Register all marked component nodes
|
||||
* registerAllComponentNodes();
|
||||
*
|
||||
* // 创建蓝图系统 | Create blueprint system
|
||||
* const blueprintSystem = createBlueprintSystem(scene);
|
||||
* ```
|
||||
*
|
||||
* // Create component data
|
||||
* const componentData = createBlueprintComponentData();
|
||||
* componentData.blueprintAsset = loadedAsset;
|
||||
* @example 标记组件 | Mark components:
|
||||
* ```typescript
|
||||
* import { BlueprintExpose, BlueprintProperty, BlueprintMethod } from '@esengine/blueprint';
|
||||
*
|
||||
* // Add to your game loop
|
||||
* function update(dt) {
|
||||
* blueprintSystem.process(blueprintEntities, dt);
|
||||
* @ECSComponent('Health')
|
||||
* @BlueprintExpose({ displayName: '生命值' })
|
||||
* export class HealthComponent extends Component {
|
||||
* @BlueprintProperty({ displayName: '当前生命值' })
|
||||
* current: number = 100;
|
||||
*
|
||||
* @BlueprintMethod({ displayName: '治疗' })
|
||||
* heal(amount: number): void {
|
||||
* this.current += amount;
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
@@ -45,7 +60,10 @@ export * from './triggers';
|
||||
// Composition
|
||||
export * from './composition';
|
||||
|
||||
// Nodes (import to register)
|
||||
// Registry (decorators & auto-generation)
|
||||
export * from './registry';
|
||||
|
||||
// Nodes (import to register built-in nodes)
|
||||
import './nodes';
|
||||
|
||||
// Re-export commonly used items
|
||||
@@ -65,3 +83,12 @@ export {
|
||||
triggerCustomBlueprintEvent
|
||||
} from './runtime/BlueprintSystem';
|
||||
export { createEmptyBlueprint, validateBlueprintAsset } from './types/blueprint';
|
||||
|
||||
// Re-export registry for convenience
|
||||
export {
|
||||
BlueprintExpose,
|
||||
BlueprintProperty,
|
||||
BlueprintMethod,
|
||||
registerAllComponentNodes,
|
||||
registerComponentNodes
|
||||
} from './registry';
|
||||
|
||||
354
packages/framework/blueprint/src/nodes/ecs/ComponentNodes.ts
Normal file
354
packages/framework/blueprint/src/nodes/ecs/ComponentNodes.ts
Normal file
@@ -0,0 +1,354 @@
|
||||
/**
|
||||
* @zh ECS 组件操作节点
|
||||
* @en ECS Component Operation Nodes
|
||||
*
|
||||
* @zh 提供蓝图中对 ECS 组件的完整操作支持
|
||||
* @en Provides complete ECS component operations in blueprint
|
||||
*/
|
||||
|
||||
import type { Entity, Component } from '@esengine/ecs-framework';
|
||||
import { BlueprintNodeTemplate, BlueprintNode } from '../../types/nodes';
|
||||
import { ExecutionContext, ExecutionResult } from '../../runtime/ExecutionContext';
|
||||
import { INodeExecutor, RegisterNode } from '../../runtime/NodeRegistry';
|
||||
|
||||
// ============================================================================
|
||||
// Has Component | 是否有组件
|
||||
// ============================================================================
|
||||
|
||||
export const HasComponentTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_HasComponent',
|
||||
title: 'Has Component',
|
||||
category: 'component',
|
||||
color: '#1e8b8b',
|
||||
isPure: true,
|
||||
description: 'Checks if an entity has a component of the specified type (检查实体是否拥有指定类型的组件)',
|
||||
keywords: ['component', 'has', 'check', 'exists', 'contains'],
|
||||
menuPath: ['ECS', 'Component', 'Has Component'],
|
||||
inputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' },
|
||||
{ name: 'componentType', type: 'string', displayName: 'Component Type', defaultValue: '' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'hasComponent', type: 'bool', displayName: 'Has Component' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(HasComponentTemplate)
|
||||
export class HasComponentExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
const componentType = context.evaluateInput(node.id, 'componentType', '') as string;
|
||||
|
||||
if (!entity || entity.isDestroyed || !componentType) {
|
||||
return { outputs: { hasComponent: false } };
|
||||
}
|
||||
|
||||
const hasIt = entity.components.some(c =>
|
||||
c.constructor.name === componentType ||
|
||||
(c.constructor as any).__componentName__ === componentType
|
||||
);
|
||||
|
||||
return { outputs: { hasComponent: hasIt } };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Get Component | 获取组件
|
||||
// ============================================================================
|
||||
|
||||
export const GetComponentTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_GetComponent',
|
||||
title: 'Get Component',
|
||||
category: 'component',
|
||||
color: '#1e8b8b',
|
||||
isPure: true,
|
||||
description: 'Gets a component from an entity by type name (按类型名称从实体获取组件)',
|
||||
keywords: ['component', 'get', 'find', 'access'],
|
||||
menuPath: ['ECS', 'Component', 'Get Component'],
|
||||
inputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' },
|
||||
{ name: 'componentType', type: 'string', displayName: 'Component Type', defaultValue: '' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'component', type: 'component', displayName: 'Component' },
|
||||
{ name: 'found', type: 'bool', displayName: 'Found' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(GetComponentTemplate)
|
||||
export class GetComponentExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
const componentType = context.evaluateInput(node.id, 'componentType', '') as string;
|
||||
|
||||
if (!entity || entity.isDestroyed || !componentType) {
|
||||
return { outputs: { component: null, found: false } };
|
||||
}
|
||||
|
||||
const component = entity.components.find(c =>
|
||||
c.constructor.name === componentType ||
|
||||
(c.constructor as any).__componentName__ === componentType
|
||||
);
|
||||
|
||||
return {
|
||||
outputs: {
|
||||
component: component ?? null,
|
||||
found: component != null
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Get All Components | 获取所有组件
|
||||
// ============================================================================
|
||||
|
||||
export const GetAllComponentsTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_GetAllComponents',
|
||||
title: 'Get All Components',
|
||||
category: 'component',
|
||||
color: '#1e8b8b',
|
||||
isPure: true,
|
||||
description: 'Gets all components from an entity (获取实体的所有组件)',
|
||||
keywords: ['component', 'get', 'all', 'list'],
|
||||
menuPath: ['ECS', 'Component', 'Get All Components'],
|
||||
inputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'components', type: 'array', displayName: 'Components', arrayType: 'component' },
|
||||
{ name: 'count', type: 'int', displayName: 'Count' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(GetAllComponentsTemplate)
|
||||
export class GetAllComponentsExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
|
||||
if (!entity || entity.isDestroyed) {
|
||||
return { outputs: { components: [], count: 0 } };
|
||||
}
|
||||
|
||||
const components = [...entity.components];
|
||||
return {
|
||||
outputs: {
|
||||
components,
|
||||
count: components.length
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Remove Component | 移除组件
|
||||
// ============================================================================
|
||||
|
||||
export const RemoveComponentTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_RemoveComponent',
|
||||
title: 'Remove Component',
|
||||
category: 'component',
|
||||
color: '#8b1e1e',
|
||||
description: 'Removes a component from an entity (从实体移除组件)',
|
||||
keywords: ['component', 'remove', 'delete', 'destroy'],
|
||||
menuPath: ['ECS', 'Component', 'Remove Component'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' },
|
||||
{ name: 'componentType', type: 'string', displayName: 'Component Type', defaultValue: '' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'removed', type: 'bool', displayName: 'Removed' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(RemoveComponentTemplate)
|
||||
export class RemoveComponentExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
const componentType = context.evaluateInput(node.id, 'componentType', '') as string;
|
||||
|
||||
if (!entity || entity.isDestroyed || !componentType) {
|
||||
return { outputs: { removed: false }, nextExec: 'exec' };
|
||||
}
|
||||
|
||||
const component = entity.components.find(c =>
|
||||
c.constructor.name === componentType ||
|
||||
(c.constructor as any).__componentName__ === componentType
|
||||
);
|
||||
|
||||
if (component) {
|
||||
entity.removeComponent(component);
|
||||
return { outputs: { removed: true }, nextExec: 'exec' };
|
||||
}
|
||||
|
||||
return { outputs: { removed: false }, nextExec: 'exec' };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Get Component Property | 获取组件属性
|
||||
// ============================================================================
|
||||
|
||||
export const GetComponentPropertyTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_GetComponentProperty',
|
||||
title: 'Get Component Property',
|
||||
category: 'component',
|
||||
color: '#1e8b8b',
|
||||
isPure: true,
|
||||
description: 'Gets a property value from a component (从组件获取属性值)',
|
||||
keywords: ['component', 'property', 'get', 'value', 'field'],
|
||||
menuPath: ['ECS', 'Component', 'Get Property'],
|
||||
inputs: [
|
||||
{ name: 'component', type: 'component', displayName: 'Component' },
|
||||
{ name: 'propertyName', type: 'string', displayName: 'Property Name', defaultValue: '' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'value', type: 'any', displayName: 'Value' },
|
||||
{ name: 'found', type: 'bool', displayName: 'Found' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(GetComponentPropertyTemplate)
|
||||
export class GetComponentPropertyExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const component = context.evaluateInput(node.id, 'component', null) as Component | null;
|
||||
const propertyName = context.evaluateInput(node.id, 'propertyName', '') as string;
|
||||
|
||||
if (!component || !propertyName) {
|
||||
return { outputs: { value: null, found: false } };
|
||||
}
|
||||
|
||||
if (propertyName in component) {
|
||||
return {
|
||||
outputs: {
|
||||
value: (component as any)[propertyName],
|
||||
found: true
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return { outputs: { value: null, found: false } };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Set Component Property | 设置组件属性
|
||||
// ============================================================================
|
||||
|
||||
export const SetComponentPropertyTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_SetComponentProperty',
|
||||
title: 'Set Component Property',
|
||||
category: 'component',
|
||||
color: '#1e8b8b',
|
||||
description: 'Sets a property value on a component (设置组件的属性值)',
|
||||
keywords: ['component', 'property', 'set', 'value', 'field', 'modify'],
|
||||
menuPath: ['ECS', 'Component', 'Set Property'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'component', type: 'component', displayName: 'Component' },
|
||||
{ name: 'propertyName', type: 'string', displayName: 'Property Name', defaultValue: '' },
|
||||
{ name: 'value', type: 'any', displayName: 'Value' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'success', type: 'bool', displayName: 'Success' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(SetComponentPropertyTemplate)
|
||||
export class SetComponentPropertyExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const component = context.evaluateInput(node.id, 'component', null) as Component | null;
|
||||
const propertyName = context.evaluateInput(node.id, 'propertyName', '') as string;
|
||||
const value = context.evaluateInput(node.id, 'value', null);
|
||||
|
||||
if (!component || !propertyName) {
|
||||
return { outputs: { success: false }, nextExec: 'exec' };
|
||||
}
|
||||
|
||||
if (propertyName in component) {
|
||||
(component as any)[propertyName] = value;
|
||||
return { outputs: { success: true }, nextExec: 'exec' };
|
||||
}
|
||||
|
||||
return { outputs: { success: false }, nextExec: 'exec' };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Get Component Type Name | 获取组件类型名称
|
||||
// ============================================================================
|
||||
|
||||
export const GetComponentTypeNameTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_GetComponentTypeName',
|
||||
title: 'Get Component Type',
|
||||
category: 'component',
|
||||
color: '#1e8b8b',
|
||||
isPure: true,
|
||||
description: 'Gets the type name of a component (获取组件的类型名称)',
|
||||
keywords: ['component', 'type', 'name', 'class'],
|
||||
menuPath: ['ECS', 'Component', 'Get Type Name'],
|
||||
inputs: [
|
||||
{ name: 'component', type: 'component', displayName: 'Component' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'typeName', type: 'string', displayName: 'Type Name' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(GetComponentTypeNameTemplate)
|
||||
export class GetComponentTypeNameExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const component = context.evaluateInput(node.id, 'component', null) as Component | null;
|
||||
|
||||
if (!component) {
|
||||
return { outputs: { typeName: '' } };
|
||||
}
|
||||
|
||||
const typeName = (component.constructor as any).__componentName__ ?? component.constructor.name;
|
||||
return { outputs: { typeName } };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Get Entity From Component | 从组件获取实体
|
||||
// ============================================================================
|
||||
|
||||
export const GetEntityFromComponentTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_GetEntityFromComponent',
|
||||
title: 'Get Owner Entity',
|
||||
category: 'component',
|
||||
color: '#1e8b8b',
|
||||
isPure: true,
|
||||
description: 'Gets the entity that owns a component (获取拥有组件的实体)',
|
||||
keywords: ['component', 'entity', 'owner', 'parent'],
|
||||
menuPath: ['ECS', 'Component', 'Get Owner Entity'],
|
||||
inputs: [
|
||||
{ name: 'component', type: 'component', displayName: 'Component' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' },
|
||||
{ name: 'found', type: 'bool', displayName: 'Found' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(GetEntityFromComponentTemplate)
|
||||
export class GetEntityFromComponentExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const component = context.evaluateInput(node.id, 'component', null) as Component | null;
|
||||
|
||||
if (!component || component.entityId == null) {
|
||||
return { outputs: { entity: null, found: false } };
|
||||
}
|
||||
|
||||
const entity = context.scene.findEntityById(component.entityId);
|
||||
return {
|
||||
outputs: {
|
||||
entity: entity ?? null,
|
||||
found: entity != null
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
485
packages/framework/blueprint/src/nodes/ecs/EntityNodes.ts
Normal file
485
packages/framework/blueprint/src/nodes/ecs/EntityNodes.ts
Normal file
@@ -0,0 +1,485 @@
|
||||
/**
|
||||
* @zh ECS 实体操作节点
|
||||
* @en ECS Entity Operation Nodes
|
||||
*
|
||||
* @zh 提供蓝图中对 ECS 实体的完整操作支持
|
||||
* @en Provides complete ECS entity operations in blueprint
|
||||
*/
|
||||
|
||||
import type { Entity } from '@esengine/ecs-framework';
|
||||
import { BlueprintNodeTemplate, BlueprintNode } from '../../types/nodes';
|
||||
import { ExecutionContext, ExecutionResult } from '../../runtime/ExecutionContext';
|
||||
import { INodeExecutor, RegisterNode } from '../../runtime/NodeRegistry';
|
||||
|
||||
// ============================================================================
|
||||
// Self Entity | 自身实体
|
||||
// ============================================================================
|
||||
|
||||
export const GetSelfTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_GetSelf',
|
||||
title: 'Get Self',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
isPure: true,
|
||||
description: 'Gets the entity that owns this blueprint (获取拥有此蓝图的实体)',
|
||||
keywords: ['self', 'this', 'owner', 'entity', 'me'],
|
||||
menuPath: ['ECS', 'Entity', 'Get Self'],
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Self' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(GetSelfTemplate)
|
||||
export class GetSelfExecutor implements INodeExecutor {
|
||||
execute(_node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
return { outputs: { entity: context.entity } };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Create Entity | 创建实体
|
||||
// ============================================================================
|
||||
|
||||
export const CreateEntityTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_CreateEntity',
|
||||
title: 'Create Entity',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
description: 'Creates a new entity in the scene (在场景中创建新实体)',
|
||||
keywords: ['entity', 'create', 'spawn', 'new', 'instantiate'],
|
||||
menuPath: ['ECS', 'Entity', 'Create Entity'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'name', type: 'string', displayName: 'Name', defaultValue: 'NewEntity' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(CreateEntityTemplate)
|
||||
export class CreateEntityExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const name = context.evaluateInput(node.id, 'name', 'NewEntity') as string;
|
||||
const entity = context.scene.createEntity(name);
|
||||
return { outputs: { entity }, nextExec: 'exec' };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Destroy Entity | 销毁实体
|
||||
// ============================================================================
|
||||
|
||||
export const DestroyEntityTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_DestroyEntity',
|
||||
title: 'Destroy Entity',
|
||||
category: 'entity',
|
||||
color: '#8b1e1e',
|
||||
description: 'Destroys an entity from the scene (从场景中销毁实体)',
|
||||
keywords: ['entity', 'destroy', 'remove', 'delete', 'kill'],
|
||||
menuPath: ['ECS', 'Entity', 'Destroy Entity'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(DestroyEntityTemplate)
|
||||
export class DestroyEntityExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', null) as Entity | null;
|
||||
if (entity && !entity.isDestroyed) {
|
||||
entity.destroy();
|
||||
}
|
||||
return { nextExec: 'exec' };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Destroy Self | 销毁自身
|
||||
// ============================================================================
|
||||
|
||||
export const DestroySelfTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_DestroySelf',
|
||||
title: 'Destroy Self',
|
||||
category: 'entity',
|
||||
color: '#8b1e1e',
|
||||
description: 'Destroys the entity that owns this blueprint (销毁拥有此蓝图的实体)',
|
||||
keywords: ['self', 'destroy', 'suicide', 'remove', 'delete'],
|
||||
menuPath: ['ECS', 'Entity', 'Destroy Self'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' }
|
||||
],
|
||||
outputs: []
|
||||
};
|
||||
|
||||
@RegisterNode(DestroySelfTemplate)
|
||||
export class DestroySelfExecutor implements INodeExecutor {
|
||||
execute(_node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
if (!context.entity.isDestroyed) {
|
||||
context.entity.destroy();
|
||||
}
|
||||
return { nextExec: null };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Is Valid | 是否有效
|
||||
// ============================================================================
|
||||
|
||||
export const IsValidTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_IsValid',
|
||||
title: 'Is Valid',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
isPure: true,
|
||||
description: 'Checks if an entity reference is valid and not destroyed (检查实体引用是否有效且未被销毁)',
|
||||
keywords: ['entity', 'valid', 'null', 'check', 'exists', 'alive'],
|
||||
menuPath: ['ECS', 'Entity', 'Is Valid'],
|
||||
inputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'isValid', type: 'bool', displayName: 'Is Valid' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(IsValidTemplate)
|
||||
export class IsValidExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', null) as Entity | null;
|
||||
const isValid = entity != null && !entity.isDestroyed;
|
||||
return { outputs: { isValid } };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Get Entity Name | 获取实体名称
|
||||
// ============================================================================
|
||||
|
||||
export const GetEntityNameTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_GetEntityName',
|
||||
title: 'Get Entity Name',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
isPure: true,
|
||||
description: 'Gets the name of an entity (获取实体的名称)',
|
||||
keywords: ['entity', 'name', 'get', 'string'],
|
||||
menuPath: ['ECS', 'Entity', 'Get Name'],
|
||||
inputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'name', type: 'string', displayName: 'Name' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(GetEntityNameTemplate)
|
||||
export class GetEntityNameExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
return { outputs: { name: entity?.name ?? '' } };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Set Entity Name | 设置实体名称
|
||||
// ============================================================================
|
||||
|
||||
export const SetEntityNameTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_SetEntityName',
|
||||
title: 'Set Entity Name',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
description: 'Sets the name of an entity (设置实体的名称)',
|
||||
keywords: ['entity', 'name', 'set', 'rename'],
|
||||
menuPath: ['ECS', 'Entity', 'Set Name'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' },
|
||||
{ name: 'name', type: 'string', displayName: 'Name', defaultValue: '' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(SetEntityNameTemplate)
|
||||
export class SetEntityNameExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
const name = context.evaluateInput(node.id, 'name', '') as string;
|
||||
if (entity && !entity.isDestroyed) {
|
||||
entity.name = name;
|
||||
}
|
||||
return { nextExec: 'exec' };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Get Entity Tag | 获取实体标签
|
||||
// ============================================================================
|
||||
|
||||
export const GetEntityTagTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_GetEntityTag',
|
||||
title: 'Get Entity Tag',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
isPure: true,
|
||||
description: 'Gets the tag of an entity (获取实体的标签)',
|
||||
keywords: ['entity', 'tag', 'get', 'category'],
|
||||
menuPath: ['ECS', 'Entity', 'Get Tag'],
|
||||
inputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'tag', type: 'int', displayName: 'Tag' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(GetEntityTagTemplate)
|
||||
export class GetEntityTagExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
return { outputs: { tag: entity?.tag ?? 0 } };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Set Entity Tag | 设置实体标签
|
||||
// ============================================================================
|
||||
|
||||
export const SetEntityTagTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_SetEntityTag',
|
||||
title: 'Set Entity Tag',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
description: 'Sets the tag of an entity (设置实体的标签)',
|
||||
keywords: ['entity', 'tag', 'set', 'category'],
|
||||
menuPath: ['ECS', 'Entity', 'Set Tag'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' },
|
||||
{ name: 'tag', type: 'int', displayName: 'Tag', defaultValue: 0 }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(SetEntityTagTemplate)
|
||||
export class SetEntityTagExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
const tag = context.evaluateInput(node.id, 'tag', 0) as number;
|
||||
if (entity && !entity.isDestroyed) {
|
||||
entity.tag = tag;
|
||||
}
|
||||
return { nextExec: 'exec' };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Set Entity Active | 设置实体激活状态
|
||||
// ============================================================================
|
||||
|
||||
export const SetEntityActiveTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_SetEntityActive',
|
||||
title: 'Set Active',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
description: 'Sets whether an entity is active (设置实体是否激活)',
|
||||
keywords: ['entity', 'active', 'enable', 'disable', 'visible'],
|
||||
menuPath: ['ECS', 'Entity', 'Set Active'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' },
|
||||
{ name: 'active', type: 'bool', displayName: 'Active', defaultValue: true }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(SetEntityActiveTemplate)
|
||||
export class SetEntityActiveExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
const active = context.evaluateInput(node.id, 'active', true) as boolean;
|
||||
if (entity && !entity.isDestroyed) {
|
||||
entity.active = active;
|
||||
}
|
||||
return { nextExec: 'exec' };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Is Entity Active | 实体是否激活
|
||||
// ============================================================================
|
||||
|
||||
export const IsEntityActiveTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_IsEntityActive',
|
||||
title: 'Is Active',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
isPure: true,
|
||||
description: 'Checks if an entity is active (检查实体是否激活)',
|
||||
keywords: ['entity', 'active', 'enabled', 'check'],
|
||||
menuPath: ['ECS', 'Entity', 'Is Active'],
|
||||
inputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'isActive', type: 'bool', displayName: 'Is Active' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(IsEntityActiveTemplate)
|
||||
export class IsEntityActiveExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
return { outputs: { isActive: entity?.active ?? false } };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Find Entity By Name | 按名称查找实体
|
||||
// ============================================================================
|
||||
|
||||
export const FindEntityByNameTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_FindEntityByName',
|
||||
title: 'Find Entity By Name',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
isPure: true,
|
||||
description: 'Finds an entity by name in the scene (在场景中按名称查找实体)',
|
||||
keywords: ['entity', 'find', 'name', 'search', 'get', 'lookup'],
|
||||
menuPath: ['ECS', 'Entity', 'Find By Name'],
|
||||
inputs: [
|
||||
{ name: 'name', type: 'string', displayName: 'Name', defaultValue: '' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' },
|
||||
{ name: 'found', type: 'bool', displayName: 'Found' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(FindEntityByNameTemplate)
|
||||
export class FindEntityByNameExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const name = context.evaluateInput(node.id, 'name', '') as string;
|
||||
const entity = context.scene.findEntity(name);
|
||||
return {
|
||||
outputs: {
|
||||
entity: entity ?? null,
|
||||
found: entity != null
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Find Entities By Tag | 按标签查找实体
|
||||
// ============================================================================
|
||||
|
||||
export const FindEntitiesByTagTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_FindEntitiesByTag',
|
||||
title: 'Find Entities By Tag',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
isPure: true,
|
||||
description: 'Finds all entities with a specific tag (查找所有具有特定标签的实体)',
|
||||
keywords: ['entity', 'find', 'tag', 'search', 'get', 'all'],
|
||||
menuPath: ['ECS', 'Entity', 'Find By Tag'],
|
||||
inputs: [
|
||||
{ name: 'tag', type: 'int', displayName: 'Tag', defaultValue: 0 }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'entities', type: 'array', displayName: 'Entities', arrayType: 'entity' },
|
||||
{ name: 'count', type: 'int', displayName: 'Count' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(FindEntitiesByTagTemplate)
|
||||
export class FindEntitiesByTagExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const tag = context.evaluateInput(node.id, 'tag', 0) as number;
|
||||
const entities = context.scene.findEntitiesByTag(tag);
|
||||
return {
|
||||
outputs: {
|
||||
entities,
|
||||
count: entities.length
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Get Entity ID | 获取实体 ID
|
||||
// ============================================================================
|
||||
|
||||
export const GetEntityIdTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_GetEntityId',
|
||||
title: 'Get Entity ID',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
isPure: true,
|
||||
description: 'Gets the unique ID of an entity (获取实体的唯一ID)',
|
||||
keywords: ['entity', 'id', 'identifier', 'unique'],
|
||||
menuPath: ['ECS', 'Entity', 'Get ID'],
|
||||
inputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'id', type: 'int', displayName: 'ID' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(GetEntityIdTemplate)
|
||||
export class GetEntityIdExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
return { outputs: { id: entity?.id ?? -1 } };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Find Entity By ID | 按 ID 查找实体
|
||||
// ============================================================================
|
||||
|
||||
export const FindEntityByIdTemplate: BlueprintNodeTemplate = {
|
||||
type: 'ECS_FindEntityById',
|
||||
title: 'Find Entity By ID',
|
||||
category: 'entity',
|
||||
color: '#1e5a8b',
|
||||
isPure: true,
|
||||
description: 'Finds an entity by its unique ID (通过唯一ID查找实体)',
|
||||
keywords: ['entity', 'find', 'id', 'identifier'],
|
||||
menuPath: ['ECS', 'Entity', 'Find By ID'],
|
||||
inputs: [
|
||||
{ name: 'id', type: 'int', displayName: 'ID', defaultValue: 0 }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' },
|
||||
{ name: 'found', type: 'bool', displayName: 'Found' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(FindEntityByIdTemplate)
|
||||
export class FindEntityByIdExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const id = context.evaluateInput(node.id, 'id', 0) as number;
|
||||
const entity = context.scene.findEntityById(id);
|
||||
return {
|
||||
outputs: {
|
||||
entity: entity ?? null,
|
||||
found: entity != null
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
301
packages/framework/blueprint/src/nodes/ecs/FlowNodes.ts
Normal file
301
packages/framework/blueprint/src/nodes/ecs/FlowNodes.ts
Normal file
@@ -0,0 +1,301 @@
|
||||
/**
|
||||
* @zh 流程控制节点
|
||||
* @en Flow Control Nodes
|
||||
*
|
||||
* @zh 提供蓝图中的流程控制支持(分支、循环等)
|
||||
* @en Provides flow control in blueprint (branch, loop, etc.)
|
||||
*/
|
||||
|
||||
import { BlueprintNodeTemplate, BlueprintNode } from '../../types/nodes';
|
||||
import { ExecutionContext, ExecutionResult } from '../../runtime/ExecutionContext';
|
||||
import { INodeExecutor, RegisterNode } from '../../runtime/NodeRegistry';
|
||||
|
||||
// ============================================================================
|
||||
// Branch | 分支
|
||||
// ============================================================================
|
||||
|
||||
export const BranchTemplate: BlueprintNodeTemplate = {
|
||||
type: 'Flow_Branch',
|
||||
title: 'Branch',
|
||||
category: 'flow',
|
||||
color: '#4a4a4a',
|
||||
description: 'Executes one of two paths based on a condition (根据条件执行两条路径之一)',
|
||||
keywords: ['if', 'branch', 'condition', 'switch', 'else'],
|
||||
menuPath: ['Flow', 'Branch'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'condition', type: 'bool', displayName: 'Condition', defaultValue: false }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'true', type: 'exec', displayName: 'True' },
|
||||
{ name: 'false', type: 'exec', displayName: 'False' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(BranchTemplate)
|
||||
export class BranchExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const condition = context.evaluateInput(node.id, 'condition', false) as boolean;
|
||||
return { nextExec: condition ? 'true' : 'false' };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Sequence | 序列
|
||||
// ============================================================================
|
||||
|
||||
export const SequenceTemplate: BlueprintNodeTemplate = {
|
||||
type: 'Flow_Sequence',
|
||||
title: 'Sequence',
|
||||
category: 'flow',
|
||||
color: '#4a4a4a',
|
||||
description: 'Executes multiple outputs in order (按顺序执行多个输出)',
|
||||
keywords: ['sequence', 'order', 'serial', 'chain'],
|
||||
menuPath: ['Flow', 'Sequence'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'then0', type: 'exec', displayName: 'Then 0' },
|
||||
{ name: 'then1', type: 'exec', displayName: 'Then 1' },
|
||||
{ name: 'then2', type: 'exec', displayName: 'Then 2' },
|
||||
{ name: 'then3', type: 'exec', displayName: 'Then 3' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(SequenceTemplate)
|
||||
export class SequenceExecutor implements INodeExecutor {
|
||||
private currentIndex = 0;
|
||||
|
||||
execute(_node: BlueprintNode, _context: ExecutionContext): ExecutionResult {
|
||||
const outputs = ['then0', 'then1', 'then2', 'then3'];
|
||||
const nextPin = outputs[this.currentIndex];
|
||||
this.currentIndex = (this.currentIndex + 1) % outputs.length;
|
||||
|
||||
if (this.currentIndex === 0) {
|
||||
return { nextExec: null };
|
||||
}
|
||||
|
||||
return { nextExec: nextPin };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Do Once | 只执行一次
|
||||
// ============================================================================
|
||||
|
||||
export const DoOnceTemplate: BlueprintNodeTemplate = {
|
||||
type: 'Flow_DoOnce',
|
||||
title: 'Do Once',
|
||||
category: 'flow',
|
||||
color: '#4a4a4a',
|
||||
description: 'Executes the output only once, subsequent calls are ignored (只执行一次,后续调用被忽略)',
|
||||
keywords: ['once', 'single', 'first', 'one'],
|
||||
menuPath: ['Flow', 'Do Once'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'reset', type: 'exec', displayName: 'Reset' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(DoOnceTemplate)
|
||||
export class DoOnceExecutor implements INodeExecutor {
|
||||
private executed = false;
|
||||
|
||||
execute(node: BlueprintNode, _context: ExecutionContext): ExecutionResult {
|
||||
const inputPin = node.data._lastInputPin as string | undefined;
|
||||
|
||||
if (inputPin === 'reset') {
|
||||
this.executed = false;
|
||||
return { nextExec: null };
|
||||
}
|
||||
|
||||
if (this.executed) {
|
||||
return { nextExec: null };
|
||||
}
|
||||
|
||||
this.executed = true;
|
||||
return { nextExec: 'exec' };
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Flip Flop | 触发器
|
||||
// ============================================================================
|
||||
|
||||
export const FlipFlopTemplate: BlueprintNodeTemplate = {
|
||||
type: 'Flow_FlipFlop',
|
||||
title: 'Flip Flop',
|
||||
category: 'flow',
|
||||
color: '#4a4a4a',
|
||||
description: 'Alternates between two outputs on each execution (每次执行时在两个输出之间交替)',
|
||||
keywords: ['flip', 'flop', 'toggle', 'alternate', 'switch'],
|
||||
menuPath: ['Flow', 'Flip Flop'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'a', type: 'exec', displayName: 'A' },
|
||||
{ name: 'b', type: 'exec', displayName: 'B' },
|
||||
{ name: 'isA', type: 'bool', displayName: 'Is A' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(FlipFlopTemplate)
|
||||
export class FlipFlopExecutor implements INodeExecutor {
|
||||
private isA = true;
|
||||
|
||||
execute(_node: BlueprintNode, _context: ExecutionContext): ExecutionResult {
|
||||
const currentIsA = this.isA;
|
||||
this.isA = !this.isA;
|
||||
|
||||
return {
|
||||
outputs: { isA: currentIsA },
|
||||
nextExec: currentIsA ? 'a' : 'b'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Gate | 门
|
||||
// ============================================================================
|
||||
|
||||
export const GateTemplate: BlueprintNodeTemplate = {
|
||||
type: 'Flow_Gate',
|
||||
title: 'Gate',
|
||||
category: 'flow',
|
||||
color: '#4a4a4a',
|
||||
description: 'Controls execution flow with open/close state (通过开/关状态控制执行流)',
|
||||
keywords: ['gate', 'open', 'close', 'block', 'allow'],
|
||||
menuPath: ['Flow', 'Gate'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: 'Enter' },
|
||||
{ name: 'open', type: 'exec', displayName: 'Open' },
|
||||
{ name: 'close', type: 'exec', displayName: 'Close' },
|
||||
{ name: 'toggle', type: 'exec', displayName: 'Toggle' },
|
||||
{ name: 'startOpen', type: 'bool', displayName: 'Start Open', defaultValue: true }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: 'Exit' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(GateTemplate)
|
||||
export class GateExecutor implements INodeExecutor {
|
||||
private isOpen: boolean | null = null;
|
||||
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
if (this.isOpen === null) {
|
||||
this.isOpen = context.evaluateInput(node.id, 'startOpen', true) as boolean;
|
||||
}
|
||||
|
||||
const inputPin = node.data._lastInputPin as string | undefined;
|
||||
|
||||
switch (inputPin) {
|
||||
case 'open':
|
||||
this.isOpen = true;
|
||||
return { nextExec: null };
|
||||
case 'close':
|
||||
this.isOpen = false;
|
||||
return { nextExec: null };
|
||||
case 'toggle':
|
||||
this.isOpen = !this.isOpen;
|
||||
return { nextExec: null };
|
||||
default:
|
||||
return { nextExec: this.isOpen ? 'exec' : null };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// For Loop | For 循环
|
||||
// ============================================================================
|
||||
|
||||
export const ForLoopTemplate: BlueprintNodeTemplate = {
|
||||
type: 'Flow_ForLoop',
|
||||
title: 'For Loop',
|
||||
category: 'flow',
|
||||
color: '#4a4a4a',
|
||||
description: 'Executes the loop body for each index in range (对范围内的每个索引执行循环体)',
|
||||
keywords: ['for', 'loop', 'iterate', 'repeat', 'count'],
|
||||
menuPath: ['Flow', 'For Loop'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'start', type: 'int', displayName: 'Start', defaultValue: 0 },
|
||||
{ name: 'end', type: 'int', displayName: 'End', defaultValue: 10 }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'loopBody', type: 'exec', displayName: 'Loop Body' },
|
||||
{ name: 'completed', type: 'exec', displayName: 'Completed' },
|
||||
{ name: 'index', type: 'int', displayName: 'Index' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(ForLoopTemplate)
|
||||
export class ForLoopExecutor implements INodeExecutor {
|
||||
private currentIndex = 0;
|
||||
private endIndex = 0;
|
||||
private isRunning = false;
|
||||
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
if (!this.isRunning) {
|
||||
this.currentIndex = context.evaluateInput(node.id, 'start', 0) as number;
|
||||
this.endIndex = context.evaluateInput(node.id, 'end', 10) as number;
|
||||
this.isRunning = true;
|
||||
}
|
||||
|
||||
if (this.currentIndex < this.endIndex) {
|
||||
const index = this.currentIndex;
|
||||
this.currentIndex++;
|
||||
|
||||
return {
|
||||
outputs: { index },
|
||||
nextExec: 'loopBody'
|
||||
};
|
||||
}
|
||||
|
||||
this.isRunning = false;
|
||||
return {
|
||||
outputs: { index: this.endIndex },
|
||||
nextExec: 'completed'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// While Loop | While 循环
|
||||
// ============================================================================
|
||||
|
||||
export const WhileLoopTemplate: BlueprintNodeTemplate = {
|
||||
type: 'Flow_WhileLoop',
|
||||
title: 'While Loop',
|
||||
category: 'flow',
|
||||
color: '#4a4a4a',
|
||||
description: 'Executes the loop body while condition is true (当条件为真时执行循环体)',
|
||||
keywords: ['while', 'loop', 'repeat', 'condition'],
|
||||
menuPath: ['Flow', 'While Loop'],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'condition', type: 'bool', displayName: 'Condition', defaultValue: true }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'loopBody', type: 'exec', displayName: 'Loop Body' },
|
||||
{ name: 'completed', type: 'exec', displayName: 'Completed' }
|
||||
]
|
||||
};
|
||||
|
||||
@RegisterNode(WhileLoopTemplate)
|
||||
export class WhileLoopExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const condition = context.evaluateInput(node.id, 'condition', true) as boolean;
|
||||
|
||||
if (condition) {
|
||||
return { nextExec: 'loopBody' };
|
||||
}
|
||||
|
||||
return { nextExec: 'completed' };
|
||||
}
|
||||
}
|
||||
16
packages/framework/blueprint/src/nodes/ecs/index.ts
Normal file
16
packages/framework/blueprint/src/nodes/ecs/index.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @zh ECS 核心节点
|
||||
* @en ECS Core Nodes
|
||||
*
|
||||
* @zh 提供与 ECS 框架交互的蓝图节点
|
||||
* @en Provides blueprint nodes for ECS framework interaction
|
||||
*/
|
||||
|
||||
// Entity operations | 实体操作
|
||||
export * from './EntityNodes';
|
||||
|
||||
// Component operations | 组件操作
|
||||
export * from './ComponentNodes';
|
||||
|
||||
// Flow control | 流程控制
|
||||
export * from './FlowNodes';
|
||||
@@ -1,118 +0,0 @@
|
||||
/**
|
||||
* @zh 碰撞事件节点 - 碰撞发生时触发
|
||||
* @en Event Collision Node - Triggered on collision events
|
||||
*/
|
||||
|
||||
import { BlueprintNodeTemplate, BlueprintNode } from '../../types/nodes';
|
||||
import { ExecutionResult } from '../../runtime/ExecutionContext';
|
||||
import { INodeExecutor, RegisterNode } from '../../runtime/NodeRegistry';
|
||||
|
||||
/**
|
||||
* @zh EventCollisionEnter 节点模板
|
||||
* @en EventCollisionEnter node template
|
||||
*/
|
||||
export const EventCollisionEnterTemplate: BlueprintNodeTemplate = {
|
||||
type: 'EventCollisionEnter',
|
||||
title: 'Event Collision Enter',
|
||||
category: 'event',
|
||||
color: '#CC0000',
|
||||
description: 'Triggered when collision starts / 碰撞开始时触发',
|
||||
keywords: ['collision', 'enter', 'hit', 'overlap', 'event'],
|
||||
menuPath: ['Event', 'Collision', 'Enter'],
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
name: 'exec',
|
||||
type: 'exec',
|
||||
displayName: ''
|
||||
},
|
||||
{
|
||||
name: 'otherEntityId',
|
||||
type: 'string',
|
||||
displayName: 'Other Entity'
|
||||
},
|
||||
{
|
||||
name: 'pointX',
|
||||
type: 'float',
|
||||
displayName: 'Point X'
|
||||
},
|
||||
{
|
||||
name: 'pointY',
|
||||
type: 'float',
|
||||
displayName: 'Point Y'
|
||||
},
|
||||
{
|
||||
name: 'normalX',
|
||||
type: 'float',
|
||||
displayName: 'Normal X'
|
||||
},
|
||||
{
|
||||
name: 'normalY',
|
||||
type: 'float',
|
||||
displayName: 'Normal Y'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* @zh EventCollisionEnter 节点执行器
|
||||
* @en EventCollisionEnter node executor
|
||||
*/
|
||||
@RegisterNode(EventCollisionEnterTemplate)
|
||||
export class EventCollisionEnterExecutor implements INodeExecutor {
|
||||
execute(_node: BlueprintNode): ExecutionResult {
|
||||
return {
|
||||
nextExec: 'exec',
|
||||
outputs: {
|
||||
otherEntityId: '',
|
||||
pointX: 0,
|
||||
pointY: 0,
|
||||
normalX: 0,
|
||||
normalY: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh EventCollisionExit 节点模板
|
||||
* @en EventCollisionExit node template
|
||||
*/
|
||||
export const EventCollisionExitTemplate: BlueprintNodeTemplate = {
|
||||
type: 'EventCollisionExit',
|
||||
title: 'Event Collision Exit',
|
||||
category: 'event',
|
||||
color: '#CC0000',
|
||||
description: 'Triggered when collision ends / 碰撞结束时触发',
|
||||
keywords: ['collision', 'exit', 'end', 'separate', 'event'],
|
||||
menuPath: ['Event', 'Collision', 'Exit'],
|
||||
inputs: [],
|
||||
outputs: [
|
||||
{
|
||||
name: 'exec',
|
||||
type: 'exec',
|
||||
displayName: ''
|
||||
},
|
||||
{
|
||||
name: 'otherEntityId',
|
||||
type: 'string',
|
||||
displayName: 'Other Entity'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* @zh EventCollisionExit 节点执行器
|
||||
* @en EventCollisionExit node executor
|
||||
*/
|
||||
@RegisterNode(EventCollisionExitTemplate)
|
||||
export class EventCollisionExitExecutor implements INodeExecutor {
|
||||
execute(_node: BlueprintNode): ExecutionResult {
|
||||
return {
|
||||
nextExec: 'exec',
|
||||
outputs: {
|
||||
otherEntityId: ''
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/**
|
||||
* @zh 输入事件节点 - 输入触发时触发
|
||||
* @en Event Input Node - Triggered on input events
|
||||
*/
|
||||
|
||||
import { BlueprintNodeTemplate, BlueprintNode } from '../../types/nodes';
|
||||
import { ExecutionContext, ExecutionResult } from '../../runtime/ExecutionContext';
|
||||
import { INodeExecutor, RegisterNode } from '../../runtime/NodeRegistry';
|
||||
|
||||
/**
|
||||
* @zh EventInput 节点模板
|
||||
* @en EventInput node template
|
||||
*/
|
||||
export const EventInputTemplate: BlueprintNodeTemplate = {
|
||||
type: 'EventInput',
|
||||
title: 'Event Input',
|
||||
category: 'event',
|
||||
color: '#CC0000',
|
||||
description: 'Triggered when input action occurs / 输入动作发生时触发',
|
||||
keywords: ['input', 'key', 'button', 'action', 'event'],
|
||||
menuPath: ['Event', 'Input'],
|
||||
inputs: [
|
||||
{
|
||||
name: 'action',
|
||||
type: 'string',
|
||||
displayName: 'Action',
|
||||
defaultValue: ''
|
||||
}
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
name: 'exec',
|
||||
type: 'exec',
|
||||
displayName: ''
|
||||
},
|
||||
{
|
||||
name: 'action',
|
||||
type: 'string',
|
||||
displayName: 'Action'
|
||||
},
|
||||
{
|
||||
name: 'value',
|
||||
type: 'float',
|
||||
displayName: 'Value'
|
||||
},
|
||||
{
|
||||
name: 'pressed',
|
||||
type: 'bool',
|
||||
displayName: 'Pressed'
|
||||
},
|
||||
{
|
||||
name: 'released',
|
||||
type: 'bool',
|
||||
displayName: 'Released'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* @zh EventInput 节点执行器
|
||||
* @en EventInput node executor
|
||||
*
|
||||
* @zh 注意:事件节点的输出由 VM 在触发时通过 setOutputs 设置
|
||||
* @en Note: Event node outputs are set by VM via setOutputs when triggered
|
||||
*/
|
||||
@RegisterNode(EventInputTemplate)
|
||||
export class EventInputExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode, _context: ExecutionContext): ExecutionResult {
|
||||
return {
|
||||
nextExec: 'exec',
|
||||
outputs: {
|
||||
action: node.data?.action ?? '',
|
||||
value: 0,
|
||||
pressed: false,
|
||||
released: false
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/**
|
||||
* @zh 消息事件节点 - 接收消息时触发
|
||||
* @en Event Message Node - Triggered when message is received
|
||||
*/
|
||||
|
||||
import { BlueprintNodeTemplate, BlueprintNode } from '../../types/nodes';
|
||||
import { ExecutionResult } from '../../runtime/ExecutionContext';
|
||||
import { INodeExecutor, RegisterNode } from '../../runtime/NodeRegistry';
|
||||
|
||||
/**
|
||||
* @zh EventMessage 节点模板
|
||||
* @en EventMessage node template
|
||||
*/
|
||||
export const EventMessageTemplate: BlueprintNodeTemplate = {
|
||||
type: 'EventMessage',
|
||||
title: 'Event Message',
|
||||
category: 'event',
|
||||
color: '#CC0000',
|
||||
description: 'Triggered when a message is received / 接收到消息时触发',
|
||||
keywords: ['message', 'receive', 'broadcast', 'event', 'signal'],
|
||||
menuPath: ['Event', 'Message'],
|
||||
inputs: [
|
||||
{
|
||||
name: 'messageName',
|
||||
type: 'string',
|
||||
displayName: 'Message Name',
|
||||
defaultValue: ''
|
||||
}
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
name: 'exec',
|
||||
type: 'exec',
|
||||
displayName: ''
|
||||
},
|
||||
{
|
||||
name: 'messageName',
|
||||
type: 'string',
|
||||
displayName: 'Message'
|
||||
},
|
||||
{
|
||||
name: 'senderId',
|
||||
type: 'string',
|
||||
displayName: 'Sender ID'
|
||||
},
|
||||
{
|
||||
name: 'payload',
|
||||
type: 'any',
|
||||
displayName: 'Payload'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* @zh EventMessage 节点执行器
|
||||
* @en EventMessage node executor
|
||||
*/
|
||||
@RegisterNode(EventMessageTemplate)
|
||||
export class EventMessageExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode): ExecutionResult {
|
||||
return {
|
||||
nextExec: 'exec',
|
||||
outputs: {
|
||||
messageName: node.data?.messageName ?? '',
|
||||
senderId: '',
|
||||
payload: null
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/**
|
||||
* @zh 状态事件节点 - 状态机状态变化时触发
|
||||
* @en Event State Node - Triggered on state machine state changes
|
||||
*/
|
||||
|
||||
import { BlueprintNodeTemplate, BlueprintNode } from '../../types/nodes';
|
||||
import { ExecutionResult } from '../../runtime/ExecutionContext';
|
||||
import { INodeExecutor, RegisterNode } from '../../runtime/NodeRegistry';
|
||||
|
||||
/**
|
||||
* @zh EventStateEnter 节点模板
|
||||
* @en EventStateEnter node template
|
||||
*/
|
||||
export const EventStateEnterTemplate: BlueprintNodeTemplate = {
|
||||
type: 'EventStateEnter',
|
||||
title: 'Event State Enter',
|
||||
category: 'event',
|
||||
color: '#CC0000',
|
||||
description: 'Triggered when entering a state / 进入状态时触发',
|
||||
keywords: ['state', 'enter', 'fsm', 'machine', 'event'],
|
||||
menuPath: ['Event', 'State', 'Enter'],
|
||||
inputs: [
|
||||
{
|
||||
name: 'stateName',
|
||||
type: 'string',
|
||||
displayName: 'State Name',
|
||||
defaultValue: ''
|
||||
}
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
name: 'exec',
|
||||
type: 'exec',
|
||||
displayName: ''
|
||||
},
|
||||
{
|
||||
name: 'stateMachineId',
|
||||
type: 'string',
|
||||
displayName: 'State Machine'
|
||||
},
|
||||
{
|
||||
name: 'currentState',
|
||||
type: 'string',
|
||||
displayName: 'Current State'
|
||||
},
|
||||
{
|
||||
name: 'previousState',
|
||||
type: 'string',
|
||||
displayName: 'Previous State'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* @zh EventStateEnter 节点执行器
|
||||
* @en EventStateEnter node executor
|
||||
*/
|
||||
@RegisterNode(EventStateEnterTemplate)
|
||||
export class EventStateEnterExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode): ExecutionResult {
|
||||
return {
|
||||
nextExec: 'exec',
|
||||
outputs: {
|
||||
stateMachineId: '',
|
||||
currentState: node.data?.stateName ?? '',
|
||||
previousState: ''
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh EventStateExit 节点模板
|
||||
* @en EventStateExit node template
|
||||
*/
|
||||
export const EventStateExitTemplate: BlueprintNodeTemplate = {
|
||||
type: 'EventStateExit',
|
||||
title: 'Event State Exit',
|
||||
category: 'event',
|
||||
color: '#CC0000',
|
||||
description: 'Triggered when exiting a state / 退出状态时触发',
|
||||
keywords: ['state', 'exit', 'leave', 'fsm', 'machine', 'event'],
|
||||
menuPath: ['Event', 'State', 'Exit'],
|
||||
inputs: [
|
||||
{
|
||||
name: 'stateName',
|
||||
type: 'string',
|
||||
displayName: 'State Name',
|
||||
defaultValue: ''
|
||||
}
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
name: 'exec',
|
||||
type: 'exec',
|
||||
displayName: ''
|
||||
},
|
||||
{
|
||||
name: 'stateMachineId',
|
||||
type: 'string',
|
||||
displayName: 'State Machine'
|
||||
},
|
||||
{
|
||||
name: 'currentState',
|
||||
type: 'string',
|
||||
displayName: 'Current State'
|
||||
},
|
||||
{
|
||||
name: 'previousState',
|
||||
type: 'string',
|
||||
displayName: 'Previous State'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* @zh EventStateExit 节点执行器
|
||||
* @en EventStateExit node executor
|
||||
*/
|
||||
@RegisterNode(EventStateExitTemplate)
|
||||
export class EventStateExitExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode): ExecutionResult {
|
||||
return {
|
||||
nextExec: 'exec',
|
||||
outputs: {
|
||||
stateMachineId: '',
|
||||
currentState: '',
|
||||
previousState: node.data?.stateName ?? ''
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/**
|
||||
* @zh 定时器事件节点 - 定时器触发时调用
|
||||
* @en Event Timer Node - Triggered when timer fires
|
||||
*/
|
||||
|
||||
import { BlueprintNodeTemplate, BlueprintNode } from '../../types/nodes';
|
||||
import { ExecutionResult } from '../../runtime/ExecutionContext';
|
||||
import { INodeExecutor, RegisterNode } from '../../runtime/NodeRegistry';
|
||||
|
||||
/**
|
||||
* @zh EventTimer 节点模板
|
||||
* @en EventTimer node template
|
||||
*/
|
||||
export const EventTimerTemplate: BlueprintNodeTemplate = {
|
||||
type: 'EventTimer',
|
||||
title: 'Event Timer',
|
||||
category: 'event',
|
||||
color: '#CC0000',
|
||||
description: 'Triggered when a timer fires / 定时器触发时执行',
|
||||
keywords: ['timer', 'delay', 'schedule', 'event', 'interval'],
|
||||
menuPath: ['Event', 'Timer'],
|
||||
inputs: [
|
||||
{
|
||||
name: 'timerId',
|
||||
type: 'string',
|
||||
displayName: 'Timer ID',
|
||||
defaultValue: ''
|
||||
}
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
name: 'exec',
|
||||
type: 'exec',
|
||||
displayName: ''
|
||||
},
|
||||
{
|
||||
name: 'timerId',
|
||||
type: 'string',
|
||||
displayName: 'Timer ID'
|
||||
},
|
||||
{
|
||||
name: 'isRepeating',
|
||||
type: 'bool',
|
||||
displayName: 'Is Repeating'
|
||||
},
|
||||
{
|
||||
name: 'timesFired',
|
||||
type: 'int',
|
||||
displayName: 'Times Fired'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* @zh EventTimer 节点执行器
|
||||
* @en EventTimer node executor
|
||||
*/
|
||||
@RegisterNode(EventTimerTemplate)
|
||||
export class EventTimerExecutor implements INodeExecutor {
|
||||
execute(node: BlueprintNode): ExecutionResult {
|
||||
return {
|
||||
nextExec: 'exec',
|
||||
outputs: {
|
||||
timerId: node.data?.timerId ?? '',
|
||||
isRepeating: false,
|
||||
timesFired: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,8 @@
|
||||
/**
|
||||
* @zh 事件节点 - 蓝图执行的入口点
|
||||
* @en Event Nodes - Entry points for blueprint execution
|
||||
* @zh 生命周期事件节点 - 蓝图执行的入口点
|
||||
* @en Lifecycle Event Nodes - Entry points for blueprint execution
|
||||
*/
|
||||
|
||||
// 生命周期事件 | Lifecycle events
|
||||
export * from './EventBeginPlay';
|
||||
export * from './EventTick';
|
||||
export * from './EventEndPlay';
|
||||
|
||||
// 触发器事件 | Trigger events
|
||||
export * from './EventInput';
|
||||
export * from './EventCollision';
|
||||
export * from './EventMessage';
|
||||
export * from './EventTimer';
|
||||
export * from './EventState';
|
||||
|
||||
@@ -1,11 +1,33 @@
|
||||
/**
|
||||
* Blueprint Nodes - All node definitions and executors
|
||||
* 蓝图节点 - 所有节点定义和执行器
|
||||
* @zh 蓝图节点 - 所有节点定义和执行器
|
||||
* @en Blueprint Nodes - All node definitions and executors
|
||||
*
|
||||
* @zh 节点分类:
|
||||
* - events: 生命周期事件(BeginPlay, Tick, EndPlay)
|
||||
* - ecs: ECS 操作(Entity, Component, Flow)
|
||||
* - math: 数学运算
|
||||
* - time: 时间工具
|
||||
* - debug: 调试工具
|
||||
*
|
||||
* @en Node categories:
|
||||
* - events: Lifecycle events (BeginPlay, Tick, EndPlay)
|
||||
* - ecs: ECS operations (Entity, Component, Flow)
|
||||
* - math: Math operations
|
||||
* - time: Time utilities
|
||||
* - debug: Debug utilities
|
||||
*/
|
||||
|
||||
// Import all nodes to trigger registration
|
||||
// 导入所有节点以触发注册
|
||||
// Lifecycle events | 生命周期事件
|
||||
export * from './events';
|
||||
export * from './debug';
|
||||
export * from './time';
|
||||
|
||||
// ECS operations | ECS 操作
|
||||
export * from './ecs';
|
||||
|
||||
// Math operations | 数学运算
|
||||
export * from './math';
|
||||
|
||||
// Time utilities | 时间工具
|
||||
export * from './time';
|
||||
|
||||
// Debug utilities | 调试工具
|
||||
export * from './debug';
|
||||
|
||||
334
packages/framework/blueprint/src/registry/BlueprintDecorators.ts
Normal file
334
packages/framework/blueprint/src/registry/BlueprintDecorators.ts
Normal file
@@ -0,0 +1,334 @@
|
||||
/**
|
||||
* @zh 蓝图装饰器 - 用于标记可在蓝图中使用的组件、属性和方法
|
||||
* @en Blueprint Decorators - Mark components, properties and methods for blueprint use
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { BlueprintExpose, BlueprintProperty, BlueprintMethod } from '@esengine/blueprint';
|
||||
*
|
||||
* @ECSComponent('Health')
|
||||
* @BlueprintExpose({ displayName: '生命值组件', category: 'gameplay' })
|
||||
* export class HealthComponent extends Component {
|
||||
*
|
||||
* @BlueprintProperty({ displayName: '当前生命值', type: 'float' })
|
||||
* current: number = 100;
|
||||
*
|
||||
* @BlueprintProperty({ displayName: '最大生命值', type: 'float', readonly: true })
|
||||
* max: number = 100;
|
||||
*
|
||||
* @BlueprintMethod({
|
||||
* displayName: '治疗',
|
||||
* params: [{ name: 'amount', type: 'float' }]
|
||||
* })
|
||||
* heal(amount: number): void {
|
||||
* this.current = Math.min(this.current + amount, this.max);
|
||||
* }
|
||||
*
|
||||
* @BlueprintMethod({
|
||||
* displayName: '受伤',
|
||||
* params: [{ name: 'amount', type: 'float' }],
|
||||
* returnType: 'bool'
|
||||
* })
|
||||
* takeDamage(amount: number): boolean {
|
||||
* this.current -= amount;
|
||||
* return this.current <= 0;
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
|
||||
import type { BlueprintPinType } from '../types/pins';
|
||||
|
||||
// ============================================================================
|
||||
// Types | 类型定义
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* @zh 参数定义
|
||||
* @en Parameter definition
|
||||
*/
|
||||
export interface BlueprintParamDef {
|
||||
/** @zh 参数名称 @en Parameter name */
|
||||
name: string;
|
||||
/** @zh 显示名称 @en Display name */
|
||||
displayName?: string;
|
||||
/** @zh 引脚类型 @en Pin type */
|
||||
type?: BlueprintPinType;
|
||||
/** @zh 默认值 @en Default value */
|
||||
defaultValue?: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 蓝图暴露选项
|
||||
* @en Blueprint expose options
|
||||
*/
|
||||
export interface BlueprintExposeOptions {
|
||||
/** @zh 组件显示名称 @en Component display name */
|
||||
displayName?: string;
|
||||
/** @zh 组件描述 @en Component description */
|
||||
description?: string;
|
||||
/** @zh 组件分类 @en Component category */
|
||||
category?: string;
|
||||
/** @zh 组件颜色 @en Component color */
|
||||
color?: string;
|
||||
/** @zh 组件图标 @en Component icon */
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 蓝图属性选项
|
||||
* @en Blueprint property options
|
||||
*/
|
||||
export interface BlueprintPropertyOptions {
|
||||
/** @zh 属性显示名称 @en Property display name */
|
||||
displayName?: string;
|
||||
/** @zh 属性描述 @en Property description */
|
||||
description?: string;
|
||||
/** @zh 引脚类型 @en Pin type */
|
||||
type?: BlueprintPinType;
|
||||
/** @zh 是否只读(不生成 Set 节点)@en Readonly (no Set node generated) */
|
||||
readonly?: boolean;
|
||||
/** @zh 默认值 @en Default value */
|
||||
defaultValue?: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 蓝图方法选项
|
||||
* @en Blueprint method options
|
||||
*/
|
||||
export interface BlueprintMethodOptions {
|
||||
/** @zh 方法显示名称 @en Method display name */
|
||||
displayName?: string;
|
||||
/** @zh 方法描述 @en Method description */
|
||||
description?: string;
|
||||
/** @zh 是否是纯函数(无副作用)@en Is pure function (no side effects) */
|
||||
isPure?: boolean;
|
||||
/** @zh 参数列表 @en Parameter list */
|
||||
params?: BlueprintParamDef[];
|
||||
/** @zh 返回值类型 @en Return type */
|
||||
returnType?: BlueprintPinType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 属性元数据
|
||||
* @en Property metadata
|
||||
*/
|
||||
export interface PropertyMetadata {
|
||||
propertyKey: string;
|
||||
displayName: string;
|
||||
description?: string;
|
||||
pinType: BlueprintPinType;
|
||||
readonly: boolean;
|
||||
defaultValue?: unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 方法元数据
|
||||
* @en Method metadata
|
||||
*/
|
||||
export interface MethodMetadata {
|
||||
methodKey: string;
|
||||
displayName: string;
|
||||
description?: string;
|
||||
isPure: boolean;
|
||||
params: BlueprintParamDef[];
|
||||
returnType: BlueprintPinType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 组件蓝图元数据
|
||||
* @en Component blueprint metadata
|
||||
*/
|
||||
export interface ComponentBlueprintMetadata extends BlueprintExposeOptions {
|
||||
componentName: string;
|
||||
properties: PropertyMetadata[];
|
||||
methods: MethodMetadata[];
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Registry | 注册表
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* @zh 已注册的蓝图组件
|
||||
* @en Registered blueprint components
|
||||
*/
|
||||
const registeredComponents = new Map<Function, ComponentBlueprintMetadata>();
|
||||
|
||||
/**
|
||||
* @zh 获取所有已注册的蓝图组件
|
||||
* @en Get all registered blueprint components
|
||||
*/
|
||||
export function getRegisteredBlueprintComponents(): Map<Function, ComponentBlueprintMetadata> {
|
||||
return registeredComponents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 获取组件的蓝图元数据
|
||||
* @en Get blueprint metadata for a component
|
||||
*/
|
||||
export function getBlueprintMetadata(componentClass: Function): ComponentBlueprintMetadata | undefined {
|
||||
return registeredComponents.get(componentClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 清除所有注册的蓝图组件(用于测试)
|
||||
* @en Clear all registered blueprint components (for testing)
|
||||
*/
|
||||
export function clearRegisteredComponents(): void {
|
||||
registeredComponents.clear();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Internal Helpers | 内部辅助函数
|
||||
// ============================================================================
|
||||
|
||||
function getOrCreateMetadata(constructor: Function): ComponentBlueprintMetadata {
|
||||
let metadata = registeredComponents.get(constructor);
|
||||
if (!metadata) {
|
||||
metadata = {
|
||||
componentName: (constructor as any).__componentName__ ?? constructor.name,
|
||||
properties: [],
|
||||
methods: []
|
||||
};
|
||||
registeredComponents.set(constructor, metadata);
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Decorators | 装饰器
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* @zh 标记组件可在蓝图中使用
|
||||
* @en Mark component as usable in blueprint
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* @ECSComponent('Player')
|
||||
* @BlueprintExpose({ displayName: '玩家', category: 'gameplay' })
|
||||
* export class PlayerComponent extends Component { }
|
||||
* ```
|
||||
*/
|
||||
export function BlueprintExpose(options: BlueprintExposeOptions = {}): ClassDecorator {
|
||||
return function (target: Function) {
|
||||
const metadata = getOrCreateMetadata(target);
|
||||
Object.assign(metadata, options);
|
||||
metadata.componentName = (target as any).__componentName__ ?? target.name;
|
||||
return target as any;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 标记属性可在蓝图中访问
|
||||
* @en Mark property as accessible in blueprint
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* @BlueprintProperty({ displayName: '生命值', type: 'float' })
|
||||
* health: number = 100;
|
||||
*
|
||||
* @BlueprintProperty({ displayName: '名称', type: 'string', readonly: true })
|
||||
* name: string = 'Player';
|
||||
* ```
|
||||
*/
|
||||
export function BlueprintProperty(options: BlueprintPropertyOptions = {}): PropertyDecorator {
|
||||
return function (target: Object, propertyKey: string | symbol) {
|
||||
const key = String(propertyKey);
|
||||
const metadata = getOrCreateMetadata(target.constructor);
|
||||
|
||||
const propMeta: PropertyMetadata = {
|
||||
propertyKey: key,
|
||||
displayName: options.displayName ?? key,
|
||||
description: options.description,
|
||||
pinType: options.type ?? 'any',
|
||||
readonly: options.readonly ?? false,
|
||||
defaultValue: options.defaultValue
|
||||
};
|
||||
|
||||
const existingIndex = metadata.properties.findIndex(p => p.propertyKey === key);
|
||||
if (existingIndex >= 0) {
|
||||
metadata.properties[existingIndex] = propMeta;
|
||||
} else {
|
||||
metadata.properties.push(propMeta);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 标记方法可在蓝图中调用
|
||||
* @en Mark method as callable in blueprint
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* @BlueprintMethod({
|
||||
* displayName: '攻击',
|
||||
* params: [
|
||||
* { name: 'target', type: 'entity' },
|
||||
* { name: 'damage', type: 'float' }
|
||||
* ],
|
||||
* returnType: 'bool'
|
||||
* })
|
||||
* attack(target: Entity, damage: number): boolean { }
|
||||
*
|
||||
* @BlueprintMethod({ displayName: '获取速度', isPure: true, returnType: 'float' })
|
||||
* getSpeed(): number { return this.speed; }
|
||||
* ```
|
||||
*/
|
||||
export function BlueprintMethod(options: BlueprintMethodOptions = {}): MethodDecorator {
|
||||
return function (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) {
|
||||
const key = String(propertyKey);
|
||||
const metadata = getOrCreateMetadata(target.constructor);
|
||||
|
||||
const methodMeta: MethodMetadata = {
|
||||
methodKey: key,
|
||||
displayName: options.displayName ?? key,
|
||||
description: options.description,
|
||||
isPure: options.isPure ?? false,
|
||||
params: options.params ?? [],
|
||||
returnType: options.returnType ?? 'any'
|
||||
};
|
||||
|
||||
const existingIndex = metadata.methods.findIndex(m => m.methodKey === key);
|
||||
if (existingIndex >= 0) {
|
||||
metadata.methods[existingIndex] = methodMeta;
|
||||
} else {
|
||||
metadata.methods.push(methodMeta);
|
||||
}
|
||||
|
||||
return descriptor;
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Utility Functions | 工具函数
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* @zh 从 TypeScript 类型名推断蓝图引脚类型
|
||||
* @en Infer blueprint pin type from TypeScript type name
|
||||
*/
|
||||
export function inferPinType(typeName: string): BlueprintPinType {
|
||||
const typeMap: Record<string, BlueprintPinType> = {
|
||||
'number': 'float',
|
||||
'Number': 'float',
|
||||
'string': 'string',
|
||||
'String': 'string',
|
||||
'boolean': 'bool',
|
||||
'Boolean': 'bool',
|
||||
'Entity': 'entity',
|
||||
'Component': 'component',
|
||||
'Vector2': 'vector2',
|
||||
'Vec2': 'vector2',
|
||||
'Vector3': 'vector3',
|
||||
'Vec3': 'vector3',
|
||||
'Color': 'color',
|
||||
'Array': 'array',
|
||||
'Object': 'object',
|
||||
'void': 'exec',
|
||||
'undefined': 'exec'
|
||||
};
|
||||
|
||||
return typeMap[typeName] ?? 'any';
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
/**
|
||||
* @zh 组件节点生成器 - 自动为标记的组件生成蓝图节点
|
||||
* @en Component Node Generator - Auto-generate blueprint nodes for marked components
|
||||
*
|
||||
* @zh 根据 @BlueprintExpose、@BlueprintProperty、@BlueprintMethod 装饰器
|
||||
* 自动生成对应的 Get/Set/Call 节点并注册到 NodeRegistry
|
||||
*
|
||||
* @en Based on @BlueprintExpose, @BlueprintProperty, @BlueprintMethod decorators,
|
||||
* auto-generate corresponding Get/Set/Call nodes and register to NodeRegistry
|
||||
*/
|
||||
|
||||
import type { Component, Entity } from '@esengine/ecs-framework';
|
||||
import type { BlueprintNodeTemplate, BlueprintNode } from '../types/nodes';
|
||||
import type { BlueprintPinType } from '../types/pins';
|
||||
import type { ExecutionContext, ExecutionResult } from '../runtime/ExecutionContext';
|
||||
import type { INodeExecutor } from '../runtime/NodeRegistry';
|
||||
import { NodeRegistry } from '../runtime/NodeRegistry';
|
||||
import {
|
||||
getRegisteredBlueprintComponents,
|
||||
type ComponentBlueprintMetadata,
|
||||
type PropertyMetadata,
|
||||
type MethodMetadata
|
||||
} from './BlueprintDecorators';
|
||||
|
||||
// ============================================================================
|
||||
// Node Generator | 节点生成器
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* @zh 为组件生成所有蓝图节点
|
||||
* @en Generate all blueprint nodes for a component
|
||||
*/
|
||||
export function generateComponentNodes(
|
||||
componentClass: Function,
|
||||
metadata: ComponentBlueprintMetadata
|
||||
): void {
|
||||
const { componentName, properties, methods } = metadata;
|
||||
const category = metadata.category ?? 'component';
|
||||
const color = metadata.color ?? '#1e8b8b';
|
||||
|
||||
generateGetComponentNode(componentClass, componentName, metadata, color);
|
||||
|
||||
for (const prop of properties) {
|
||||
generatePropertyGetNode(componentName, prop, category, color);
|
||||
if (!prop.readonly) {
|
||||
generatePropertySetNode(componentName, prop, category, color);
|
||||
}
|
||||
}
|
||||
|
||||
for (const method of methods) {
|
||||
generateMethodCallNode(componentName, method, category, color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 生成 Get Component 节点
|
||||
* @en Generate Get Component node
|
||||
*/
|
||||
function generateGetComponentNode(
|
||||
componentClass: Function,
|
||||
componentName: string,
|
||||
metadata: ComponentBlueprintMetadata,
|
||||
color: string
|
||||
): void {
|
||||
const nodeType = `Get_${componentName}`;
|
||||
const displayName = metadata.displayName ?? componentName;
|
||||
|
||||
const template: BlueprintNodeTemplate = {
|
||||
type: nodeType,
|
||||
title: `Get ${displayName}`,
|
||||
category: 'component',
|
||||
color,
|
||||
isPure: true,
|
||||
description: `Gets ${displayName} component from entity (从实体获取 ${displayName} 组件)`,
|
||||
keywords: ['get', 'component', componentName.toLowerCase()],
|
||||
menuPath: ['Components', displayName, `Get ${displayName}`],
|
||||
inputs: [
|
||||
{ name: 'entity', type: 'entity', displayName: 'Entity' }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'component', type: 'component', displayName: displayName },
|
||||
{ name: 'found', type: 'bool', displayName: 'Found' }
|
||||
]
|
||||
};
|
||||
|
||||
const executor: INodeExecutor = {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const entity = context.evaluateInput(node.id, 'entity', context.entity) as Entity;
|
||||
|
||||
if (!entity || entity.isDestroyed) {
|
||||
return { outputs: { component: null, found: false } };
|
||||
}
|
||||
|
||||
const component = entity.components.find(c =>
|
||||
c.constructor === componentClass ||
|
||||
c.constructor.name === componentName ||
|
||||
(c.constructor as any).__componentName__ === componentName
|
||||
);
|
||||
|
||||
return {
|
||||
outputs: {
|
||||
component: component ?? null,
|
||||
found: component != null
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
NodeRegistry.instance.register(template, executor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 生成属性 Get 节点
|
||||
* @en Generate property Get node
|
||||
*/
|
||||
function generatePropertyGetNode(
|
||||
componentName: string,
|
||||
prop: PropertyMetadata,
|
||||
category: string,
|
||||
color: string
|
||||
): void {
|
||||
const nodeType = `Get_${componentName}_${prop.propertyKey}`;
|
||||
const { displayName, pinType } = prop;
|
||||
|
||||
const template: BlueprintNodeTemplate = {
|
||||
type: nodeType,
|
||||
title: `Get ${displayName}`,
|
||||
subtitle: componentName,
|
||||
category: category as any,
|
||||
color,
|
||||
isPure: true,
|
||||
description: prop.description ?? `Gets ${displayName} from ${componentName} (从 ${componentName} 获取 ${displayName})`,
|
||||
keywords: ['get', 'property', componentName.toLowerCase(), prop.propertyKey.toLowerCase()],
|
||||
menuPath: ['Components', componentName, `Get ${displayName}`],
|
||||
inputs: [
|
||||
{ name: 'component', type: 'component', displayName: componentName }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'value', type: pinType, displayName }
|
||||
]
|
||||
};
|
||||
|
||||
const propertyKey = prop.propertyKey;
|
||||
const defaultValue = prop.defaultValue;
|
||||
|
||||
const executor: INodeExecutor = {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const component = context.evaluateInput(node.id, 'component', null) as Component | null;
|
||||
|
||||
if (!component) {
|
||||
return { outputs: { value: defaultValue ?? null } };
|
||||
}
|
||||
|
||||
const value = (component as any)[propertyKey];
|
||||
return { outputs: { value } };
|
||||
}
|
||||
};
|
||||
|
||||
NodeRegistry.instance.register(template, executor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 生成属性 Set 节点
|
||||
* @en Generate property Set node
|
||||
*/
|
||||
function generatePropertySetNode(
|
||||
componentName: string,
|
||||
prop: PropertyMetadata,
|
||||
category: string,
|
||||
color: string
|
||||
): void {
|
||||
const nodeType = `Set_${componentName}_${prop.propertyKey}`;
|
||||
const { displayName, pinType, defaultValue } = prop;
|
||||
|
||||
const template: BlueprintNodeTemplate = {
|
||||
type: nodeType,
|
||||
title: `Set ${displayName}`,
|
||||
subtitle: componentName,
|
||||
category: category as any,
|
||||
color,
|
||||
description: prop.description ?? `Sets ${displayName} on ${componentName} (设置 ${componentName} 的 ${displayName})`,
|
||||
keywords: ['set', 'property', componentName.toLowerCase(), prop.propertyKey.toLowerCase()],
|
||||
menuPath: ['Components', componentName, `Set ${displayName}`],
|
||||
inputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' },
|
||||
{ name: 'component', type: 'component', displayName: componentName },
|
||||
{ name: 'value', type: pinType, displayName, defaultValue }
|
||||
],
|
||||
outputs: [
|
||||
{ name: 'exec', type: 'exec', displayName: '' }
|
||||
]
|
||||
};
|
||||
|
||||
const propertyKey = prop.propertyKey;
|
||||
|
||||
const executor: INodeExecutor = {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const component = context.evaluateInput(node.id, 'component', null) as Component | null;
|
||||
const value = context.evaluateInput(node.id, 'value', defaultValue);
|
||||
|
||||
if (component) {
|
||||
(component as any)[propertyKey] = value;
|
||||
}
|
||||
|
||||
return { nextExec: 'exec' };
|
||||
}
|
||||
};
|
||||
|
||||
NodeRegistry.instance.register(template, executor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 生成方法调用节点
|
||||
* @en Generate method call node
|
||||
*/
|
||||
function generateMethodCallNode(
|
||||
componentName: string,
|
||||
method: MethodMetadata,
|
||||
category: string,
|
||||
color: string
|
||||
): void {
|
||||
const nodeType = `Call_${componentName}_${method.methodKey}`;
|
||||
const { displayName, isPure, params, returnType } = method;
|
||||
|
||||
const inputs: BlueprintNodeTemplate['inputs'] = [];
|
||||
|
||||
if (!isPure) {
|
||||
inputs.push({ name: 'exec', type: 'exec', displayName: '' });
|
||||
}
|
||||
|
||||
inputs.push({ name: 'component', type: 'component', displayName: componentName });
|
||||
|
||||
const paramNames: string[] = [];
|
||||
for (const param of params) {
|
||||
inputs.push({
|
||||
name: param.name,
|
||||
type: param.type ?? 'any',
|
||||
displayName: param.displayName ?? param.name,
|
||||
defaultValue: param.defaultValue
|
||||
});
|
||||
paramNames.push(param.name);
|
||||
}
|
||||
|
||||
const outputs: BlueprintNodeTemplate['outputs'] = [];
|
||||
|
||||
if (!isPure) {
|
||||
outputs.push({ name: 'exec', type: 'exec', displayName: '' });
|
||||
}
|
||||
|
||||
if (returnType !== 'exec' && returnType !== 'any') {
|
||||
outputs.push({
|
||||
name: 'result',
|
||||
type: returnType as BlueprintPinType,
|
||||
displayName: 'Result'
|
||||
});
|
||||
}
|
||||
|
||||
const template: BlueprintNodeTemplate = {
|
||||
type: nodeType,
|
||||
title: displayName,
|
||||
subtitle: componentName,
|
||||
category: category as any,
|
||||
color,
|
||||
isPure,
|
||||
description: method.description ?? `Calls ${displayName} on ${componentName} (调用 ${componentName} 的 ${displayName})`,
|
||||
keywords: ['call', 'method', componentName.toLowerCase(), method.methodKey.toLowerCase()],
|
||||
menuPath: ['Components', componentName, displayName],
|
||||
inputs,
|
||||
outputs
|
||||
};
|
||||
|
||||
const methodKey = method.methodKey;
|
||||
|
||||
const executor: INodeExecutor = {
|
||||
execute(node: BlueprintNode, context: ExecutionContext): ExecutionResult {
|
||||
const component = context.evaluateInput(node.id, 'component', null) as Component | null;
|
||||
|
||||
if (!component) {
|
||||
return isPure ? { outputs: { result: null } } : { nextExec: 'exec' };
|
||||
}
|
||||
|
||||
const args: unknown[] = paramNames.map(name =>
|
||||
context.evaluateInput(node.id, name, undefined)
|
||||
);
|
||||
|
||||
const fn = (component as any)[methodKey];
|
||||
if (typeof fn !== 'function') {
|
||||
console.warn(`Method ${methodKey} not found on component ${componentName}`);
|
||||
return isPure ? { outputs: { result: null } } : { nextExec: 'exec' };
|
||||
}
|
||||
|
||||
const result = fn.apply(component, args);
|
||||
|
||||
return isPure
|
||||
? { outputs: { result } }
|
||||
: { outputs: { result }, nextExec: 'exec' };
|
||||
}
|
||||
};
|
||||
|
||||
NodeRegistry.instance.register(template, executor);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Registration | 注册
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* @zh 注册所有已标记的组件节点
|
||||
* @en Register all marked component nodes
|
||||
*
|
||||
* @zh 应该在蓝图系统初始化时调用,会扫描所有使用 @BlueprintExpose 装饰的组件
|
||||
* 并自动生成对应的蓝图节点
|
||||
*
|
||||
* @en Should be called during blueprint system initialization, scans all components
|
||||
* decorated with @BlueprintExpose and auto-generates corresponding blueprint nodes
|
||||
*/
|
||||
export function registerAllComponentNodes(): void {
|
||||
const components = getRegisteredBlueprintComponents();
|
||||
|
||||
for (const [componentClass, metadata] of components) {
|
||||
try {
|
||||
generateComponentNodes(componentClass, metadata);
|
||||
console.log(`[Blueprint] Registered component: ${metadata.componentName} (${metadata.properties.length} properties, ${metadata.methods.length} methods)`);
|
||||
} catch (error) {
|
||||
console.error(`[Blueprint] Failed to register component ${metadata.componentName}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[Blueprint] Registered ${components.size} component(s)`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh 手动注册单个组件
|
||||
* @en Manually register a single component
|
||||
*/
|
||||
export function registerComponentNodes(componentClass: Function): void {
|
||||
const components = getRegisteredBlueprintComponents();
|
||||
const metadata = components.get(componentClass);
|
||||
|
||||
if (!metadata) {
|
||||
console.warn(`[Blueprint] Component ${componentClass.name} is not marked with @BlueprintExpose`);
|
||||
return;
|
||||
}
|
||||
|
||||
generateComponentNodes(componentClass, metadata);
|
||||
}
|
||||
69
packages/framework/blueprint/src/registry/index.ts
Normal file
69
packages/framework/blueprint/src/registry/index.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @zh 蓝图注册系统
|
||||
* @en Blueprint Registry System
|
||||
*
|
||||
* @zh 提供组件自动节点生成功能,用户只需使用装饰器标记组件,
|
||||
* 即可自动在蓝图编辑器中生成对应的 Get/Set/Call 节点
|
||||
*
|
||||
* @en Provides automatic node generation for components. Users only need to
|
||||
* mark components with decorators, and corresponding Get/Set/Call nodes
|
||||
* will be auto-generated in the blueprint editor
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // 1. 定义组件时使用装饰器 | Define component with decorators
|
||||
* @ECSComponent('Health')
|
||||
* @BlueprintExpose({ displayName: '生命值', category: 'gameplay' })
|
||||
* export class HealthComponent extends Component {
|
||||
* @BlueprintProperty({ displayName: '当前生命值', type: 'float' })
|
||||
* current: number = 100;
|
||||
*
|
||||
* @BlueprintMethod({
|
||||
* displayName: '治疗',
|
||||
* params: [{ name: 'amount', type: 'float' }]
|
||||
* })
|
||||
* heal(amount: number): void {
|
||||
* this.current = Math.min(this.current + amount, 100);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // 2. 初始化蓝图系统时注册 | Register when initializing blueprint system
|
||||
* import { registerAllComponentNodes } from '@esengine/blueprint';
|
||||
* registerAllComponentNodes();
|
||||
*
|
||||
* // 3. 现在蓝图编辑器中会出现以下节点:
|
||||
* // Now these nodes appear in blueprint editor:
|
||||
* // - Get Health(获取组件)
|
||||
* // - Get 当前生命值(获取属性)
|
||||
* // - Set 当前生命值(设置属性)
|
||||
* // - 治疗(调用方法)
|
||||
* ```
|
||||
*/
|
||||
|
||||
// Decorators | 装饰器
|
||||
export {
|
||||
BlueprintExpose,
|
||||
BlueprintProperty,
|
||||
BlueprintMethod,
|
||||
getRegisteredBlueprintComponents,
|
||||
getBlueprintMetadata,
|
||||
clearRegisteredComponents,
|
||||
inferPinType
|
||||
} from './BlueprintDecorators';
|
||||
|
||||
export type {
|
||||
BlueprintParamDef,
|
||||
BlueprintExposeOptions,
|
||||
BlueprintPropertyOptions,
|
||||
BlueprintMethodOptions,
|
||||
PropertyMetadata,
|
||||
MethodMetadata,
|
||||
ComponentBlueprintMetadata
|
||||
} from './BlueprintDecorators';
|
||||
|
||||
// Node Generator | 节点生成器
|
||||
export {
|
||||
generateComponentNodes,
|
||||
registerAllComponentNodes,
|
||||
registerComponentNodes
|
||||
} from './ComponentNodeGenerator';
|
||||
@@ -1,5 +1,12 @@
|
||||
# @esengine/fsm
|
||||
|
||||
## 5.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`caf3be7`](https://github.com/esengine/esengine/commit/caf3be72cdcc730492c63abe5f1715893f3579ac)]:
|
||||
- @esengine/blueprint@4.1.0
|
||||
|
||||
## 4.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@esengine/fsm",
|
||||
"version": "4.0.1",
|
||||
"version": "5.0.0",
|
||||
"description": "Finite State Machine for ECS Framework / ECS 框架的有限状态机",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @esengine/network
|
||||
|
||||
## 6.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`caf3be7`](https://github.com/esengine/esengine/commit/caf3be72cdcc730492c63abe5f1715893f3579ac)]:
|
||||
- @esengine/blueprint@4.1.0
|
||||
|
||||
## 5.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@esengine/network",
|
||||
"version": "5.0.3",
|
||||
"version": "6.0.0",
|
||||
"description": "Network synchronization for multiplayer games",
|
||||
"esengine": {
|
||||
"plugin": true,
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @esengine/pathfinding
|
||||
|
||||
## 5.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`caf3be7`](https://github.com/esengine/esengine/commit/caf3be72cdcc730492c63abe5f1715893f3579ac)]:
|
||||
- @esengine/blueprint@4.1.0
|
||||
|
||||
## 4.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@esengine/pathfinding",
|
||||
"version": "4.0.1",
|
||||
"version": "5.0.0",
|
||||
"description": "寻路系统 | Pathfinding System - A*, Grid, NavMesh",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @esengine/procgen
|
||||
|
||||
## 5.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`caf3be7`](https://github.com/esengine/esengine/commit/caf3be72cdcc730492c63abe5f1715893f3579ac)]:
|
||||
- @esengine/blueprint@4.1.0
|
||||
|
||||
## 4.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@esengine/procgen",
|
||||
"version": "4.0.1",
|
||||
"version": "5.0.0",
|
||||
"description": "Procedural generation tools for ECS Framework / ECS 框架的程序化生成工具",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @esengine/spatial
|
||||
|
||||
## 5.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`caf3be7`](https://github.com/esengine/esengine/commit/caf3be72cdcc730492c63abe5f1715893f3579ac)]:
|
||||
- @esengine/blueprint@4.1.0
|
||||
|
||||
## 4.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@esengine/spatial",
|
||||
"version": "4.0.1",
|
||||
"version": "5.0.0",
|
||||
"description": "Spatial query and indexing system for ECS Framework / ECS 框架的空间查询和索引系统",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @esengine/timer
|
||||
|
||||
## 5.0.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [[`caf3be7`](https://github.com/esengine/esengine/commit/caf3be72cdcc730492c63abe5f1715893f3579ac)]:
|
||||
- @esengine/blueprint@4.1.0
|
||||
|
||||
## 4.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@esengine/timer",
|
||||
"version": "4.0.1",
|
||||
"version": "5.0.0",
|
||||
"description": "Timer and cooldown system for ECS Framework / ECS 框架的定时器和冷却系统",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
# @esengine/demos
|
||||
|
||||
## 1.0.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies []:
|
||||
- @esengine/fsm@5.0.0
|
||||
- @esengine/pathfinding@5.0.0
|
||||
- @esengine/procgen@5.0.0
|
||||
- @esengine/spatial@5.0.0
|
||||
- @esengine/timer@5.0.0
|
||||
|
||||
## 1.0.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@esengine/demos",
|
||||
"version": "1.0.10",
|
||||
"version": "1.0.11",
|
||||
"private": true,
|
||||
"description": "Demo tests for ESEngine modules documentation",
|
||||
"type": "module",
|
||||
|
||||
69
pnpm-lock.yaml
generated
69
pnpm-lock.yaml
generated
@@ -178,6 +178,37 @@ importers:
|
||||
specifier: ^3.5.26
|
||||
version: 3.5.26(typescript@5.9.3)
|
||||
|
||||
packages/devtools/node-editor:
|
||||
dependencies:
|
||||
tslib:
|
||||
specifier: ^2.8.1
|
||||
version: 2.8.1
|
||||
devDependencies:
|
||||
'@types/node':
|
||||
specifier: ^20.19.17
|
||||
version: 20.19.27
|
||||
'@types/react':
|
||||
specifier: ^18.3.12
|
||||
version: 18.3.27
|
||||
'@vitejs/plugin-react':
|
||||
specifier: ^4.7.0
|
||||
version: 4.7.0(vite@6.4.1(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))
|
||||
react:
|
||||
specifier: ^18.3.1
|
||||
version: 18.3.1
|
||||
rimraf:
|
||||
specifier: ^5.0.0
|
||||
version: 5.0.10
|
||||
typescript:
|
||||
specifier: ^5.8.3
|
||||
version: 5.9.3
|
||||
vite:
|
||||
specifier: ^6.0.7
|
||||
version: 6.4.1(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2)
|
||||
vite-plugin-dts:
|
||||
specifier: ^3.7.0
|
||||
version: 3.9.1(@types/node@20.19.27)(rollup@4.54.0)(typescript@5.9.3)(vite@6.4.1(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))
|
||||
|
||||
packages/editor/editor-app:
|
||||
dependencies:
|
||||
'@esengine/asset-system':
|
||||
@@ -589,7 +620,7 @@ importers:
|
||||
version: link:../../../engine/engine-core
|
||||
'@esengine/node-editor':
|
||||
specifier: workspace:*
|
||||
version: link:../node-editor
|
||||
version: link:../../../devtools/node-editor
|
||||
'@types/react':
|
||||
specifier: ^18.3.12
|
||||
version: 18.3.27
|
||||
@@ -632,7 +663,7 @@ importers:
|
||||
version: link:../../../engine/engine-core
|
||||
'@esengine/node-editor':
|
||||
specifier: workspace:*
|
||||
version: link:../node-editor
|
||||
version: link:../../../devtools/node-editor
|
||||
'@types/react':
|
||||
specifier: ^18.3.12
|
||||
version: 18.3.27
|
||||
@@ -812,40 +843,6 @@ importers:
|
||||
specifier: ^5.3.3
|
||||
version: 5.9.3
|
||||
|
||||
packages/editor/plugins/node-editor:
|
||||
dependencies:
|
||||
tslib:
|
||||
specifier: ^2.8.1
|
||||
version: 2.8.1
|
||||
devDependencies:
|
||||
'@types/node':
|
||||
specifier: ^20.19.17
|
||||
version: 20.19.27
|
||||
'@types/react':
|
||||
specifier: ^18.3.12
|
||||
version: 18.3.27
|
||||
'@vitejs/plugin-react':
|
||||
specifier: ^4.7.0
|
||||
version: 4.7.0(vite@6.4.1(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))
|
||||
react:
|
||||
specifier: ^18.3.1
|
||||
version: 18.3.1
|
||||
rimraf:
|
||||
specifier: ^5.0.0
|
||||
version: 5.0.10
|
||||
typescript:
|
||||
specifier: ^5.8.3
|
||||
version: 5.9.3
|
||||
vite:
|
||||
specifier: ^6.0.7
|
||||
version: 6.4.1(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2)
|
||||
vite-plugin-dts:
|
||||
specifier: ^3.7.0
|
||||
version: 3.9.1(@types/node@20.19.27)(rollup@4.54.0)(typescript@5.9.3)(vite@6.4.1(@types/node@20.19.27)(jiti@2.6.1)(lightningcss@1.30.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))
|
||||
zustand:
|
||||
specifier: ^5.0.8
|
||||
version: 5.0.9(@types/react@18.3.27)(react@18.3.1)(use-sync-external-store@1.6.0(react@18.3.1))
|
||||
|
||||
packages/editor/plugins/particle-editor:
|
||||
dependencies:
|
||||
'@esengine/particle':
|
||||
|
||||
@@ -7,6 +7,7 @@ packages:
|
||||
- 'packages/network-ext/*'
|
||||
- 'packages/editor/*'
|
||||
- 'packages/editor/plugins/*'
|
||||
- 'packages/devtools/*'
|
||||
- 'packages/rust/*'
|
||||
- 'packages/tools/*'
|
||||
- 'docs'
|
||||
|
||||
Reference in New Issue
Block a user