Skip to content

Commit bb4e55e

Browse files
committed
feat: 增加shift+R交换两个实体的位置快捷键
1 parent 2542537 commit bb4e55e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

app/src/core/service/controlService/shortcutKeysEngine/shortcutKeysRegister.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,5 +1115,30 @@ export class KeyBindsRegistrar {
11151115
}
11161116
}
11171117
});
1118+
1119+
// 交换两个选中实体的位置
1120+
await this.project.keyBinds.create("swapTwoSelectedEntitiesPositions", "S-r", () => {
1121+
if (!this.project.keyboardOnlyEngine.isOpenning()) return;
1122+
1123+
const selectedEntities = this.project.stageManager.getSelectedEntities();
1124+
// 只有当恰好选中两个实体时才执行交换
1125+
if (selectedEntities.length !== 2) {
1126+
return;
1127+
}
1128+
1129+
// 记录操作历史
1130+
this.project.historyManager.recordStep();
1131+
1132+
// 获取两个实体的碰撞箱外接矩形左上角位置
1133+
const entity1 = selectedEntities[0];
1134+
const entity2 = selectedEntities[1];
1135+
1136+
const position1 = entity1.collisionBox.getRectangle().location.clone();
1137+
const position2 = entity2.collisionBox.getRectangle().location.clone();
1138+
1139+
// 交换两个实体的位置
1140+
entity1.moveTo(position2);
1141+
entity2.moveTo(position1);
1142+
});
11181143
}
11191144
}

0 commit comments

Comments
 (0)