* refactor: 编辑器/运行时架构拆分与构建系统升级 * feat(core): 层级系统重构与UI变换矩阵修复 * refactor: 移除 ecs-components 聚合包并修复跨包组件查找问题 * fix(physics): 修复跨包组件类引用问题 * feat: 统一运行时架构与浏览器运行支持 * feat(asset): 实现浏览器运行时资产加载系统 * fix: 修复文档、CodeQL安全问题和CI类型检查错误 * fix: 修复文档、CodeQL安全问题和CI类型检查错误 * fix: 修复文档、CodeQL安全问题、CI类型检查和测试错误 * test: 补齐核心模块测试用例,修复CI构建配置 * fix: 修复测试用例中的类型错误和断言问题 * fix: 修复 turbo build:npm 任务的依赖顺序问题 * fix: 修复 CI 构建错误并优化构建性能
75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
import { Position } from '../../../domain/value-objects/Position';
|
|
import { BaseCommand, ICommand } from '@esengine/editor-runtime';
|
|
import { ITreeState } from '../ITreeState';
|
|
|
|
/**
|
|
* 移动节点命令
|
|
* 支持合并连续的移动操作
|
|
*/
|
|
export class MoveNodeCommand extends BaseCommand {
|
|
private oldPosition: Position;
|
|
|
|
constructor(
|
|
private readonly state: ITreeState,
|
|
private readonly nodeId: string,
|
|
private readonly newPosition: Position
|
|
) {
|
|
super();
|
|
const tree = this.state.getTree();
|
|
const node = tree.getNode(nodeId);
|
|
this.oldPosition = node.position;
|
|
}
|
|
|
|
execute(): void {
|
|
const tree = this.state.getTree();
|
|
const newTree = tree.updateNode(this.nodeId, (node) =>
|
|
node.moveToPosition(this.newPosition)
|
|
);
|
|
this.state.setTree(newTree);
|
|
}
|
|
|
|
undo(): void {
|
|
const tree = this.state.getTree();
|
|
const newTree = tree.updateNode(this.nodeId, (node) =>
|
|
node.moveToPosition(this.oldPosition)
|
|
);
|
|
this.state.setTree(newTree);
|
|
}
|
|
|
|
getDescription(): string {
|
|
return `移动节点: ${this.nodeId}`;
|
|
}
|
|
|
|
/**
|
|
* 移动命令可以合并
|
|
*/
|
|
canMergeWith(other: ICommand): boolean {
|
|
if (!(other instanceof MoveNodeCommand)) {
|
|
return false;
|
|
}
|
|
return this.nodeId === other.nodeId;
|
|
}
|
|
|
|
/**
|
|
* 合并移动命令
|
|
* 保留初始位置,更新最终位置
|
|
*/
|
|
mergeWith(other: ICommand): ICommand {
|
|
if (!(other instanceof MoveNodeCommand)) {
|
|
throw new Error('只能与 MoveNodeCommand 合并');
|
|
}
|
|
|
|
if (this.nodeId !== other.nodeId) {
|
|
throw new Error('只能合并同一节点的移动命令');
|
|
}
|
|
|
|
const merged = new MoveNodeCommand(
|
|
this.state,
|
|
this.nodeId,
|
|
other.newPosition
|
|
);
|
|
merged.oldPosition = this.oldPosition;
|
|
return merged;
|
|
}
|
|
}
|