* feat(ui): 完善 UI 布局系统和编辑器可视化工具 * refactor: 移除 ModuleRegistry,统一使用 PluginManager 插件系统 * fix: 修复 CodeQL 警告并提升测试覆盖率 * refactor: 分离运行时入口点,解决 runtime bundle 包含 React 的问题 * fix(ci): 添加 editor-core 和 editor-runtime 到 CI 依赖构建步骤 * docs: 完善 ServiceContainer 文档,新增 Symbol.for 模式和 @InjectProperty 说明 * fix(ci): 修复 type-check 失败问题 * fix(ci): 修复类型检查失败问题 * fix(ci): 修复类型检查失败问题 * fix(ci): behavior-tree 构建添加 @tauri-apps 外部依赖 * fix(ci): behavior-tree 添加 @tauri-apps/plugin-fs 类型依赖 * fix(ci): platform-web 添加缺失的 behavior-tree 依赖 * fix(lint): 移除正则表达式中不必要的转义字符
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { TaskStatus, NodeType } from '../../Types/TaskStatus';
|
|
import { INodeExecutor, NodeExecutionContext, BindingHelper } from '../NodeExecutor';
|
|
import { NodeExecutorMetadata } from '../NodeMetadata';
|
|
|
|
/**
|
|
* 黑板比较条件执行器
|
|
*
|
|
* 比较黑板中的值
|
|
*/
|
|
@NodeExecutorMetadata({
|
|
implementationType: 'BlackboardCompare',
|
|
nodeType: NodeType.Condition,
|
|
displayName: '黑板比较',
|
|
description: '比较黑板中的值',
|
|
category: 'Condition',
|
|
configSchema: {
|
|
key: {
|
|
type: 'string',
|
|
default: '',
|
|
description: '黑板变量名'
|
|
},
|
|
compareValue: {
|
|
type: 'object',
|
|
description: '比较值',
|
|
supportBinding: true
|
|
},
|
|
operator: {
|
|
type: 'string',
|
|
default: 'equals',
|
|
description: '比较运算符',
|
|
options: ['equals', 'notEquals', 'greaterThan', 'lessThan', 'greaterOrEqual', 'lessOrEqual']
|
|
}
|
|
}
|
|
})
|
|
export class BlackboardCompare implements INodeExecutor {
|
|
execute(context: NodeExecutionContext): TaskStatus {
|
|
const { runtime } = context;
|
|
const key = BindingHelper.getValue<string>(context, 'key', '');
|
|
const compareValue = BindingHelper.getValue(context, 'compareValue');
|
|
const operator = BindingHelper.getValue<string>(context, 'operator', 'equals');
|
|
|
|
if (!key) {
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
const actualValue = runtime.getBlackboardValue(key);
|
|
|
|
if (this.compare(actualValue, compareValue, operator)) {
|
|
return TaskStatus.Success;
|
|
}
|
|
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
private compare(actualValue: any, compareValue: any, operator: string): boolean {
|
|
switch (operator) {
|
|
case 'equals':
|
|
return actualValue === compareValue;
|
|
case 'notEquals':
|
|
return actualValue !== compareValue;
|
|
case 'greaterThan':
|
|
return actualValue > compareValue;
|
|
case 'lessThan':
|
|
return actualValue < compareValue;
|
|
case 'greaterOrEqual':
|
|
return actualValue >= compareValue;
|
|
case 'lessOrEqual':
|
|
return actualValue <= compareValue;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
}
|