File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
app/src/core/service/controlService/shortcutKeysEngine Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments