@@ -3,14 +3,16 @@ import { Vector } from "../../../dataStruct/Vector";
3
3
import { EdgeRenderer } from "../../../render/canvas2d/entityRenderer/edge/EdgeRenderer" ;
4
4
import { Camera } from "../../../stage/Camera" ;
5
5
import { Stage } from "../../../stage/Stage" ;
6
+ import { GraphMethods } from "../../../stage/stageManager/basicMethods/GraphMethods" ;
7
+ import { StageAutoAlignManager } from "../../../stage/stageManager/concreteMethods/StageAutoAlignManager" ;
6
8
import { StageNodeAdder } from "../../../stage/stageManager/concreteMethods/stageNodeAdder" ;
7
9
import { StageManager } from "../../../stage/stageManager/StageManager" ;
8
10
import { ConnectableEntity } from "../../../stage/stageObject/abstract/ConnectableEntity" ;
9
11
import { EntityDashTipEffect } from "../../feedbackService/effectEngine/concrete/EntityDashTipEffect" ;
10
12
import { EntityShakeEffect } from "../../feedbackService/effectEngine/concrete/EntityShakeEffect" ;
11
13
import { TextRiseEffect } from "../../feedbackService/effectEngine/concrete/TextRiseEffect" ;
12
14
import { Settings } from "../../Settings" ;
13
- import { editTextNode } from "../controller/concrete/utilsControl" ;
15
+ import { addTextNodeByLocation , editTextNode } from "../controller/concrete/utilsControl" ;
14
16
import { KeyboardOnlyDirectionController } from "./keyboardOnlyDirectionController" ;
15
17
import { NewTargetLocationSelector } from "./newTargetLocationSelector" ;
16
18
import { SelectChangeEngine } from "./selectChangeEngine" ;
@@ -52,6 +54,11 @@ export namespace KeyboardOnlyEngine {
52
54
*/
53
55
function bindKeyEvents ( ) {
54
56
window . addEventListener ( "keydown" , ( event ) => {
57
+ if ( event . key === "`" ) {
58
+ onDeepGenerateNode ( ) ;
59
+ } else if ( event . key === "\\" ) {
60
+ onBroadGenerateNode ( ) ;
61
+ }
55
62
if ( event . key === "Tab" ) {
56
63
// if (isEnableVirtualCreate()) {
57
64
// createStart();
@@ -93,6 +100,66 @@ export namespace KeyboardOnlyEngine {
93
100
// });
94
101
}
95
102
103
+ function onDeepGenerateNode ( ) {
104
+ const rootNode = StageManager . getConnectableEntity ( ) . find ( ( node ) => node . isSelected ) ;
105
+ if ( ! rootNode ) return ;
106
+ Camera . clearMoveCommander ( ) ;
107
+ Camera . speed = Vector . getZero ( ) ;
108
+ // 在自己的右下方创建一个节点
109
+ const newLocation = rootNode . collisionBox . getRectangle ( ) . rightCenter . add ( new Vector ( 100 , 100 ) ) ;
110
+ addTextNodeByLocation ( newLocation , true , ( newUUID ) => {
111
+ const newNode = StageManager . getTextNodeByUUID ( newUUID ) ;
112
+ if ( ! newNode ) return ;
113
+ // 连接到之前的节点
114
+ StageManager . connectEntity ( rootNode , newNode ) ;
115
+ // 重新排列树形节点
116
+ const rootNodeParents = GraphMethods . getRoots ( rootNode ) ;
117
+ if ( rootNodeParents . length === 1 ) {
118
+ const rootNodeParent = rootNodeParents [ 0 ] ;
119
+ if ( GraphMethods . isTree ( rootNodeParent ) ) {
120
+ StageAutoAlignManager . autoLayoutSelectedFastTreeModeRight ( rootNodeParent ) ;
121
+ // 更新选择状态
122
+ rootNodeParent . isSelected = false ;
123
+ newNode . isSelected = true ;
124
+ }
125
+ }
126
+
127
+ Stage . effectMachine . addEffects ( EdgeRenderer . getConnectedEffects ( rootNode , newNode ) ) ;
128
+ } ) ;
129
+ }
130
+
131
+ function onBroadGenerateNode ( ) {
132
+ const currentSelectNode = StageManager . getConnectableEntity ( ) . find ( ( node ) => node . isSelected ) ;
133
+ if ( ! currentSelectNode ) return ;
134
+ Camera . clearMoveCommander ( ) ;
135
+ Camera . speed = Vector . getZero ( ) ;
136
+ // 找到自己的父节点
137
+ const parents = GraphMethods . nodeParentArray ( currentSelectNode ) ;
138
+ if ( parents . length === 0 ) return ;
139
+ if ( parents . length !== 1 ) return ;
140
+ const parent = parents [ 0 ] ;
141
+ // 在自己的正下方创建一个节点
142
+ const newLocation = parent . collisionBox . getRectangle ( ) . bottomCenter . add ( new Vector ( 0 , 100 ) ) ;
143
+ addTextNodeByLocation ( newLocation , true , ( newUUID ) => {
144
+ const newNode = StageManager . getTextNodeByUUID ( newUUID ) ;
145
+ if ( ! newNode ) return ;
146
+ // 连接到之前的节点
147
+ StageManager . connectEntity ( parent , newNode ) ;
148
+ // 重新排列树形节点
149
+ const rootNodeParents = GraphMethods . getRoots ( parent ) ;
150
+ if ( rootNodeParents . length === 1 ) {
151
+ const rootNodeParent = rootNodeParents [ 0 ] ;
152
+ if ( GraphMethods . isTree ( rootNodeParent ) ) {
153
+ StageAutoAlignManager . autoLayoutSelectedFastTreeModeRight ( rootNodeParent ) ;
154
+ // 更新选择状态
155
+ rootNodeParent . isSelected = false ;
156
+ newNode . isSelected = true ;
157
+ }
158
+ }
159
+ Stage . effectMachine . addEffects ( EdgeRenderer . getConnectedEffects ( parent , newNode ) ) ;
160
+ } ) ;
161
+ }
162
+
96
163
function addSuccessEffect ( ) {
97
164
const textNodes = StageManager . getTextNodes ( ) . filter ( ( textNode ) => textNode . isSelected ) ;
98
165
for ( const textNode of textNodes ) {
0 commit comments