2025-11-03 21:22:16 +08:00
|
|
|
import { Position } from '../../domain/value-objects/Position';
|
2025-11-27 20:42:46 +08:00
|
|
|
import { CommandManager } from '@esengine/editor-runtime';
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|