Skip to content

Commit 0e79fd5

Browse files
committed
🐛 完善了广度键盘扩展节点和深度键盘扩展节点
1 parent 9c2d20c commit 0e79fd5

File tree

1 file changed

+58
-39
lines changed

1 file changed

+58
-39
lines changed

app/src/core/service/controlService/keyboardOnlyEngine/keyboardOnlyEngine.tsx

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { v4 } from "uuid";
12
import { getEnterKey } from "../../../../utils/keyboardFunctions";
23
import { Vector } from "../../../dataStruct/Vector";
34
import { EdgeRenderer } from "../../../render/canvas2d/entityRenderer/edge/EdgeRenderer";
@@ -8,11 +9,12 @@ import { StageAutoAlignManager } from "../../../stage/stageManager/concreteMetho
89
import { StageNodeAdder } from "../../../stage/stageManager/concreteMethods/stageNodeAdder";
910
import { StageManager } from "../../../stage/stageManager/StageManager";
1011
import { ConnectableEntity } from "../../../stage/stageObject/abstract/ConnectableEntity";
12+
import { TextNode } from "../../../stage/stageObject/entity/TextNode";
1113
import { EntityDashTipEffect } from "../../feedbackService/effectEngine/concrete/EntityDashTipEffect";
1214
import { EntityShakeEffect } from "../../feedbackService/effectEngine/concrete/EntityShakeEffect";
1315
import { TextRiseEffect } from "../../feedbackService/effectEngine/concrete/TextRiseEffect";
1416
import { Settings } from "../../Settings";
15-
import { addTextNodeByLocation, editTextNode } from "../controller/concrete/utilsControl";
17+
import { editTextNode } from "../controller/concrete/utilsControl";
1618
import { KeyboardOnlyDirectionController } from "./keyboardOnlyDirectionController";
1719
import { NewTargetLocationSelector } from "./newTargetLocationSelector";
1820
import { SelectChangeEngine } from "./selectChangeEngine";
@@ -120,26 +122,34 @@ export namespace KeyboardOnlyEngine {
120122
const lastChild = childSet[childSet.length - 1];
121123
createLocation = lastChild.collisionBox.getRectangle().bottomCenter.add(new Vector(0, 10));
122124
}
123-
124-
addTextNodeByLocation(createLocation, true, (newUUID) => {
125-
const newNode = StageManager.getTextNodeByUUID(newUUID);
126-
if (!newNode) return;
127-
// 连接到之前的节点
128-
StageManager.connectEntity(rootNode, newNode);
129-
// 重新排列树形节点
130-
const rootNodeParents = GraphMethods.getRoots(rootNode);
131-
if (rootNodeParents.length === 1) {
132-
const rootNodeParent = rootNodeParents[0];
133-
if (GraphMethods.isTree(rootNodeParent)) {
134-
StageAutoAlignManager.autoLayoutSelectedFastTreeModeRight(rootNodeParent);
135-
// 更新选择状态
136-
rootNodeParent.isSelected = false;
137-
newNode.isSelected = true;
138-
}
139-
}
140-
141-
Stage.effectMachine.addEffects(EdgeRenderer.getConnectedEffects(rootNode, newNode));
125+
// 创建位置寻找完毕
126+
const newNode = new TextNode({
127+
text: "新节点",
128+
details: "",
129+
uuid: v4(),
130+
location: [createLocation.x, createLocation.y],
131+
size: [100, 100],
142132
});
133+
StageManager.addTextNode(newNode);
134+
// 连接节点
135+
StageManager.connectEntity(rootNode, newNode);
136+
// 重新排列树形节点
137+
const rootNodeParents = GraphMethods.getRoots(rootNode);
138+
if (rootNodeParents.length === 1) {
139+
const rootNodeParent = rootNodeParents[0];
140+
if (GraphMethods.isTree(rootNodeParent)) {
141+
StageAutoAlignManager.autoLayoutSelectedFastTreeModeRight(rootNodeParent);
142+
// 更新选择状态
143+
rootNodeParent.isSelected = false;
144+
newNode.isSelected = true;
145+
}
146+
}
147+
// 特效
148+
Stage.effectMachine.addEffects(EdgeRenderer.getConnectedEffects(rootNode, newNode));
149+
setTimeout(() => {
150+
// 防止把反引号给输入进去
151+
editTextNode(newNode);
152+
}, 100);
143153
}
144154

145155
function onBroadGenerateNode() {
@@ -152,26 +162,35 @@ export namespace KeyboardOnlyEngine {
152162
if (parents.length === 0) return;
153163
if (parents.length !== 1) return;
154164
const parent = parents[0];
155-
// 在自己的正下方创建一个节点
156-
const newLocation = parent.collisionBox.getRectangle().bottomCenter.add(new Vector(0, 100));
157-
addTextNodeByLocation(newLocation, true, (newUUID) => {
158-
const newNode = StageManager.getTextNodeByUUID(newUUID);
159-
if (!newNode) return;
160-
// 连接到之前的节点
161-
StageManager.connectEntity(parent, newNode);
162-
// 重新排列树形节点
163-
const rootNodeParents = GraphMethods.getRoots(parent);
164-
if (rootNodeParents.length === 1) {
165-
const rootNodeParent = rootNodeParents[0];
166-
if (GraphMethods.isTree(rootNodeParent)) {
167-
StageAutoAlignManager.autoLayoutSelectedFastTreeModeRight(rootNodeParent);
168-
// 更新选择状态
169-
rootNodeParent.isSelected = false;
170-
newNode.isSelected = true;
171-
}
172-
}
173-
Stage.effectMachine.addEffects(EdgeRenderer.getConnectedEffects(parent, newNode));
165+
// 当前选择的节点的正下方创建一个节点
166+
// 找到创建点
167+
const newLocation = currentSelectNode.collisionBox.getRectangle().leftBottom.add(new Vector(0, 1));
168+
const newNode = new TextNode({
169+
text: "新节点",
170+
details: "",
171+
uuid: v4(),
172+
location: [newLocation.x, newLocation.y],
173+
size: [100, 100],
174174
});
175+
StageManager.addTextNode(newNode);
176+
// 连接节点
177+
StageManager.connectEntity(parent, newNode);
178+
// 重新排列树形节点
179+
const rootNodeParents = GraphMethods.getRoots(parent);
180+
if (rootNodeParents.length === 1) {
181+
const rootNodeParent = rootNodeParents[0];
182+
if (GraphMethods.isTree(rootNodeParent)) {
183+
StageAutoAlignManager.autoLayoutSelectedFastTreeModeRight(rootNodeParent);
184+
// 更新选择状态
185+
rootNodeParent.isSelected = false;
186+
newNode.isSelected = true;
187+
}
188+
}
189+
Stage.effectMachine.addEffects(EdgeRenderer.getConnectedEffects(parent, newNode));
190+
setTimeout(() => {
191+
// 防止把反引号给输入进去
192+
editTextNode(newNode);
193+
}, 100);
175194
}
176195

177196
function addSuccessEffect() {

0 commit comments

Comments
 (0)