2025-11-03 21:22:16 +08:00
|
|
|
import { NodeTemplate } from '@esengine/behavior-tree';
|
|
|
|
|
import { Node } from '../../domain/models/Node';
|
|
|
|
|
import { Position } from '../../domain/value-objects/Position';
|
|
|
|
|
import { INodeFactory } from '../../domain/interfaces/INodeFactory';
|
2025-11-18 14:46:51 +08:00
|
|
|
import { CommandManager } from '@esengine/editor-core';
|
2025-11-03 21:22:16 +08:00
|
|
|
import { CreateNodeCommand } from '../commands/tree/CreateNodeCommand';
|
|
|
|
|
import { ITreeState } from '../commands/ITreeState';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建节点用例
|
|
|
|
|
*/
|
|
|
|
|
export class CreateNodeUseCase {
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly nodeFactory: INodeFactory,
|
|
|
|
|
private readonly commandManager: CommandManager,
|
|
|
|
|
private readonly treeState: ITreeState
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 执行创建节点操作
|
|
|
|
|
*/
|
|
|
|
|
execute(template: NodeTemplate, position: Position, data?: Record<string, unknown>): Node {
|
|
|
|
|
const node = this.nodeFactory.createNode(template, position, data);
|
|
|
|
|
|
|
|
|
|
const command = new CreateNodeCommand(this.treeState, node);
|
|
|
|
|
this.commandManager.execute(command);
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据类型创建节点
|
|
|
|
|
*/
|
|
|
|
|
executeByType(nodeType: string, position: Position, data?: Record<string, unknown>): Node {
|
|
|
|
|
const node = this.nodeFactory.createNodeByType(nodeType, position, data);
|
|
|
|
|
|
|
|
|
|
const command = new CreateNodeCommand(this.treeState, node);
|
|
|
|
|
this.commandManager.execute(command);
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
}
|