Files
esengine/packages/behavior-tree-editor/src/application/use-cases/MoveNodeUseCase.ts
T

33 lines
990 B
TypeScript
Raw Normal View History

2025-11-03 21:22:16 +08:00
import { Position } from '../../domain/value-objects/Position';
import { CommandManager } from '@esengine/editor-core';
2025-11-03 21:22:16 +08:00
import { MoveNodeCommand } from '../commands/tree/MoveNodeCommand';
import { ITreeState } from '../commands/ITreeState';
/**
* 移动节点用例
*/
export class MoveNodeUseCase {
constructor(
private readonly commandManager: CommandManager,
private readonly treeState: ITreeState
) {}
/**
* 移动单个节点
*/
execute(nodeId: string, newPosition: Position): void {
const command = new MoveNodeCommand(this.treeState, nodeId, newPosition);
this.commandManager.execute(command);
}
/**
* 批量移动节点
*/
executeBatch(moves: Array<{ nodeId: string; position: Position }>): void {
const commands = moves.map(
({ nodeId, position }) => new MoveNodeCommand(this.treeState, nodeId, position)
);
this.commandManager.executeBatch(commands);
}
}