Files
esengine/packages/behavior-tree/src/Runtime/NodeMetadata.ts
YHH ddc7a7750e Chore/lint fixes (#212)
* fix(eslint): 修复装饰器缩进配置

* fix(eslint): 修复装饰器缩进配置

* chore: 删除未使用的导入

* chore(lint): 移除未使用的导入和变量

* chore(lint): 修复editor-app中未使用的函数参数

* chore(lint): 修复未使用的赋值变量

* chore(eslint): 将所有错误级别改为警告以通过CI

* fix(codeql): 修复GitHub Advanced Security检测到的问题
2025-11-02 23:50:41 +08:00

80 lines
2.4 KiB
TypeScript

import { NodeType } from '../Types/TaskStatus';
/**
* 配置参数定义
*/
export interface ConfigFieldDefinition {
type: 'string' | 'number' | 'boolean' | 'object' | 'array';
default?: any;
description?: string;
min?: number;
max?: number;
options?: string[];
supportBinding?: boolean;
allowMultipleConnections?: boolean;
}
/**
* 节点元数据
*/
export interface NodeMetadata {
implementationType: string;
nodeType: NodeType;
displayName: string;
description?: string;
category?: string;
configSchema?: Record<string, ConfigFieldDefinition>;
}
/**
* 节点元数据注册表
*/
export class NodeMetadataRegistry {
private static metadataMap: Map<string, NodeMetadata> = new Map();
private static executorClassMap: Map<Function, string> = new Map();
private static executorConstructors: Map<string, new () => any> = new Map();
static register(target: Function, metadata: NodeMetadata): void {
this.metadataMap.set(metadata.implementationType, metadata);
this.executorClassMap.set(target, metadata.implementationType);
this.executorConstructors.set(metadata.implementationType, target as new () => any);
}
static getMetadata(implementationType: string): NodeMetadata | undefined {
return this.metadataMap.get(implementationType);
}
static getAllMetadata(): NodeMetadata[] {
return Array.from(this.metadataMap.values());
}
static getByCategory(category: string): NodeMetadata[] {
return this.getAllMetadata().filter((m) => m.category === category);
}
static getByNodeType(nodeType: NodeType): NodeMetadata[] {
return this.getAllMetadata().filter((m) => m.nodeType === nodeType);
}
static getImplementationType(executorClass: Function): string | undefined {
return this.executorClassMap.get(executorClass);
}
static getExecutorConstructor(implementationType: string): (new () => any) | undefined {
return this.executorConstructors.get(implementationType);
}
static getAllExecutorConstructors(): Map<string, new () => any> {
return new Map(this.executorConstructors);
}
}
/**
* 节点执行器元数据装饰器
*/
export function NodeExecutorMetadata(metadata: NodeMetadata) {
return function (target: Function) {
NodeMetadataRegistry.register(target, metadata);
};
}