Skip to content

Commit 7559119

Browse files
authored
优化代码结构和命名,修复延迟线和Ctrl左键单击边的报错 (#439)
2 parents 94849ab + 373311b commit 7559119

26 files changed

+618
-90
lines changed

app/src/core/dataStruct/shape/CublicCatmullRomSpline.tsx renamed to app/src/core/dataStruct/shape/CubicCatmullRomSpline.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Shape } from "./Shape";
77
/**
88
* CR曲线形状
99
*/
10-
export class CublicCatmullRomSpline extends Shape {
10+
export class CubicCatmullRomSpline extends Shape {
1111
public controlPoints: Vector[];
1212
public alpha: number;
1313
public tension: number;

app/src/core/render/canvas2d/entityRenderer/CollisionBoxRenderer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Color } from "../../../dataStruct/Color";
22
import { Circle } from "../../../dataStruct/shape/Circle";
3-
import { CublicCatmullRomSpline } from "../../../dataStruct/shape/CublicCatmullRomSpline";
3+
import { CubicCatmullRomSpline } from "../../../dataStruct/shape/CubicCatmullRomSpline";
44
import { SymmetryCurve } from "../../../dataStruct/shape/Curve";
55
import { Line } from "../../../dataStruct/shape/Line";
66
import { Rectangle } from "../../../dataStruct/shape/Rectangle";
@@ -50,8 +50,8 @@ export namespace CollisionBoxRenderer {
5050
// const size = 15; // 箭头大小
5151
// shape.end = shape.end.subtract(shape.endDirection.multiply(size / -2));
5252
WorldRenderUtils.renderSymmetryCurve(shape, color, 10);
53-
} else if (shape instanceof CublicCatmullRomSpline) {
54-
WorldRenderUtils.renderCublicCatmullRomSpline(shape, color, 10);
53+
} else if (shape instanceof CubicCatmullRomSpline) {
54+
WorldRenderUtils.renderCubicCatmullRomSpline(shape, color, 10);
5555
}
5656
}
5757
}

app/src/core/render/canvas2d/entityRenderer/edge/EdgeRenderer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Color } from "../../../../dataStruct/Color";
33
import { Vector } from "../../../../dataStruct/Vector";
44
import { Settings } from "../../../../service/Settings";
55
import { Camera } from "../../../../stage/Camera";
6-
import { CublicCatmullRomSplineEdge } from "../../../../stage/stageObject/association/CublicCatmullRomSplineEdge";
6+
import { CubicCatmullRomSplineEdge } from "../../../../stage/stageObject/association/CubicCatmullRomSplineEdge";
77
import { LineEdge } from "../../../../stage/stageObject/association/LineEdge";
88
import { Section } from "../../../../stage/stageObject/entity/Section";
99

@@ -106,14 +106,14 @@ export namespace EdgeRenderer {
106106
}
107107
}
108108

109-
export function renderCrEdge(edge: CublicCatmullRomSplineEdge) {
109+
export function renderCrEdge(edge: CubicCatmullRomSplineEdge) {
110110
if (edge.source.isHiddenBySectionCollapse && edge.target.isHiddenBySectionCollapse) {
111111
return;
112112
}
113113
const crShape = edge.getShape();
114114
const edgeColor = edge.color.a === 0 ? StageStyleManager.currentStyle.StageObjectBorder : edge.color;
115115
// 画曲线
116-
WorldRenderUtils.renderCublicCatmullRomSpline(crShape, edgeColor, 2);
116+
WorldRenderUtils.renderCubicCatmullRomSpline(crShape, edgeColor, 2);
117117
if (edge.isSelected) {
118118
CollisionBoxRenderer.render(edge.collisionBox, StageStyleManager.currentStyle.CollideBoxSelected);
119119
}

app/src/core/render/canvas2d/renderer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { StageHistoryManager } from "../../stage/stageManager/StageHistoryManage
1818
import { StageManager } from "../../stage/stageManager/StageManager";
1919
import { StageObjectSelectCounter } from "../../stage/stageManager/concreteMethods/StageObjectSelectCounter";
2020
import { StageObject } from "../../stage/stageObject/abstract/StageObject";
21-
import { CublicCatmullRomSplineEdge } from "../../stage/stageObject/association/CublicCatmullRomSplineEdge";
21+
import { CubicCatmullRomSplineEdge } from "../../stage/stageObject/association/CubicCatmullRomSplineEdge";
2222
import { LineEdge } from "../../stage/stageObject/association/LineEdge";
2323
import { MultiTargetUndirectedEdge } from "../../stage/stageObject/association/MutiTargetUndirectedEdge";
2424
import { CurveRenderer } from "./basicRenderer/curveRenderer";
@@ -635,7 +635,7 @@ export namespace Renderer {
635635
if (association instanceof LineEdge) {
636636
EdgeRenderer.renderLineEdge(association);
637637
}
638-
if (association instanceof CublicCatmullRomSplineEdge) {
638+
if (association instanceof CubicCatmullRomSplineEdge) {
639639
EdgeRenderer.renderCrEdge(association);
640640
}
641641
renderedEdges++;

app/src/core/render/canvas2d/utilsRenderer/WorldRenderUtils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Color } from "../../../dataStruct/Color";
2-
import { CublicCatmullRomSpline } from "../../../dataStruct/shape/CublicCatmullRomSpline";
2+
import { CubicCatmullRomSpline } from "../../../dataStruct/shape/CubicCatmullRomSpline";
33
import { CubicBezierCurve, SymmetryCurve } from "../../../dataStruct/shape/Curve";
44
import { Rectangle } from "../../../dataStruct/shape/Rectangle";
55
import { Vector } from "../../../dataStruct/Vector";
@@ -19,7 +19,7 @@ export namespace WorldRenderUtils {
1919
* 绘制一条Catmull-Rom样条线
2020
* @param curve
2121
*/
22-
export function renderCublicCatmullRomSpline(spline: CublicCatmullRomSpline, color: Color, width: number): void {
22+
export function renderCubicCatmullRomSpline(spline: CubicCatmullRomSpline, color: Color, width: number): void {
2323
const points = spline.computePath().map(Renderer.transformWorld2View);
2424
width *= Camera.currentScale;
2525
const start = Renderer.transformWorld2View(spline.controlPoints[1]);

app/src/core/service/controlService/controller/ControllerClass.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ export class ControllerClass {
105105

106106
private _touchstart = (event: TouchEvent) => {
107107
event.preventDefault();
108-
const touch = event.touches[event.touches.length - 1] as any as MouseEvent;
109-
// @ts-expect-error 必须给他来一个button属性
110-
touch.button = 0;
108+
const touch = {
109+
...(event.touches[event.touches.length - 1] as unknown as MouseEvent),
110+
button: 0, // 通过对象展开实现相对安全的属性合并
111+
} as MouseEvent;
111112
if (event.touches.length > 1) {
112113
Stage.selectMachine.shutDown();
113114
}
@@ -116,17 +117,19 @@ export class ControllerClass {
116117

117118
private _touchmove = (event: TouchEvent) => {
118119
event.preventDefault();
119-
const touch = event.touches[event.touches.length - 1] as any as MouseEvent;
120-
// @ts-expect-error 必须给他来一个button属性
121-
touch.button = 0;
120+
const touch = {
121+
...(event.touches[event.touches.length - 1] as unknown as MouseEvent),
122+
button: 0, // 通过对象展开实现相对安全的属性合并
123+
} as MouseEvent;
122124
this.mousemove(touch);
123125
};
124126

125127
private _touchend = (event: TouchEvent) => {
126128
event.preventDefault();
127-
const touch = event.changedTouches[event.changedTouches.length - 1] as any as MouseEvent;
128-
// @ts-expect-error 必须给他来一个button属性
129-
touch.button = 0;
129+
const touch = {
130+
...(event.touches[event.touches.length - 1] as unknown as MouseEvent),
131+
button: 0, // 通过对象展开实现相对安全的属性合并
132+
} as MouseEvent;
130133
this._mouseup(touch);
131134
};
132135

app/src/core/service/controlService/controller/concrete/ControllerAssociationReshape.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Renderer } from "../../../../render/canvas2d/renderer";
44
import { LeftMouseModeEnum, Stage } from "../../../../stage/Stage";
55
import { StageMultiTargetEdgeMove } from "../../../../stage/stageManager/concreteMethods/StageMultiTargetEdgeMove";
66
import { StageNodeConnector } from "../../../../stage/stageManager/concreteMethods/StageNodeConnector";
7-
import { StageNodeRotate } from "../../../../stage/stageManager/concreteMethods/stageNodeRotate";
7+
import { StageNodeRotate } from "../../../../stage/stageManager/concreteMethods/StageNodeRotate";
88
import { StageHistoryManager } from "../../../../stage/stageManager/StageHistoryManager";
99
import { StageManager } from "../../../../stage/stageManager/StageManager";
1010
import { MultiTargetUndirectedEdge } from "../../../../stage/stageObject/association/MutiTargetUndirectedEdge";

app/src/core/service/controlService/controller/concrete/ControllerEntityClickSelectAndMove.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class ControllerEntityClickSelectAndMoveClass extends ControllerClass {
5050
} else if (Controller.pressingKeySet.has("shift")) {
5151
// shift 按下,只选中节点
5252
clickedStageObject.isSelected = true;
53+
// 没有实体被选中则return
54+
if (StageManager.getSelectedEntities().length === 0) return;
5355
const rectangles = StageManager.getSelectedEntities().map((entity) => entity.collisionBox.getRectangle());
5456
const boundingRectangle = Rectangle.getBoundingRectangle(rectangles);
5557
Stage.effectMachine.addEffect(RectangleRenderEffect.fromShiftClickSelect(boundingRectangle));

app/src/core/service/controlService/controller/concrete/ControllerEntityCreate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Vector } from "../../../../dataStruct/Vector";
22
import { Renderer } from "../../../../render/canvas2d/renderer";
33
import { LeftMouseModeEnum, Stage } from "../../../../stage/Stage";
44
import { SectionMethods } from "../../../../stage/stageManager/basicMethods/SectionMethods";
5-
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/stageNodeAdder";
5+
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/StageNodeAdder";
66
import { StageObjectSelectCounter } from "../../../../stage/stageManager/concreteMethods/StageObjectSelectCounter";
77
import { StageManager } from "../../../../stage/stageManager/StageManager";
88
import { Section } from "../../../../stage/stageObject/entity/Section";

app/src/core/service/controlService/controller/concrete/ControllerNodeConnection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ControllerClass } from "../ControllerClass";
1414
import { addTextNodeByLocation } from "./utilsControl";
1515
import { StageStyleManager } from "../../../feedbackService/stageStyle/StageStyleManager";
1616
import { SectionMethods } from "../../../../stage/stageManager/basicMethods/SectionMethods";
17-
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/stageNodeAdder";
17+
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/StageNodeAdder";
1818
import { Line } from "../../../../dataStruct/shape/Line";
1919
import { Direction } from "../../../../../types/directions";
2020

app/src/core/service/controlService/controller/concrete/utilsControl.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { InputElement } from "../../../../render/domElement/inputElement";
77
import { Camera } from "../../../../stage/Camera";
88
import { Stage } from "../../../../stage/Stage";
99
import { SectionMethods } from "../../../../stage/stageManager/basicMethods/SectionMethods";
10-
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/stageNodeAdder";
10+
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/StageNodeAdder";
1111
import { StageObjectSelectCounter } from "../../../../stage/stageManager/concreteMethods/StageObjectSelectCounter";
1212
import { StageHistoryManager } from "../../../../stage/stageManager/StageHistoryManager";
1313
import { StageManager } from "../../../../stage/stageManager/StageManager";
@@ -126,6 +126,7 @@ export function editEdgeText(clickedLineEdge: Edge, selectAll = true) {
126126
selectAll,
127127
).then(() => {
128128
// clickedLineEdge!.isEditing = false;
129+
// 因为这里用的是不透明文本框,所以不需要停止节点上文字的渲染
129130
Controller.isCameraLocked = false;
130131
StageHistoryManager.recordStep();
131132
});
@@ -160,6 +161,7 @@ export function editMultiTargetEdgeText(clickedEdge: MultiTargetUndirectedEdge,
160161
selectAll,
161162
).then(() => {
162163
// clickedLineEdge!.isEditing = false;
164+
// 因为这里用的是不透明文本框,所以不需要停止节点上文字的渲染
163165
Controller.isCameraLocked = false;
164166
StageHistoryManager.recordStep();
165167
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Vector } from "../../../dataStruct/Vector";
22
import { EdgeRenderer } from "../../../render/canvas2d/entityRenderer/edge/EdgeRenderer";
33
// import { Camera } from "../../../stage/Camera";
44
import { Stage } from "../../../stage/Stage";
5-
import { StageNodeAdder } from "../../../stage/stageManager/concreteMethods/stageNodeAdder";
5+
import { StageNodeAdder } from "../../../stage/stageManager/concreteMethods/StageNodeAdder";
66
import { StageManager } from "../../../stage/stageManager/StageManager";
77
import { ConnectableEntity } from "../../../stage/stageObject/abstract/ConnectableEntity";
88
import { TextRiseEffect } from "../../feedbackService/effectEngine/concrete/TextRiseEffect";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { StageManager } from "../../../stage/stageManager/StageManager";
1313
import { SectionMethods } from "../../../stage/stageManager/basicMethods/SectionMethods";
1414
import { LayoutManualAlignManager } from "../../../stage/stageManager/concreteMethods/layoutManager/layoutManualAlignManager";
1515
import { ConnectableEntity } from "../../../stage/stageObject/abstract/ConnectableEntity";
16-
import { CublicCatmullRomSplineEdge } from "../../../stage/stageObject/association/CublicCatmullRomSplineEdge";
16+
import { CubicCatmullRomSplineEdge } from "../../../stage/stageObject/association/CubicCatmullRomSplineEdge";
1717
import { LineEdge } from "../../../stage/stageObject/association/LineEdge";
1818
import { PortalNode } from "../../../stage/stageObject/entity/PortalNode";
1919
import { Section } from "../../../stage/stageObject/entity/Section";
@@ -626,7 +626,7 @@ export class SecretKeysEngine {
626626
isHidden: true,
627627
func() {
628628
const selectedCREdge = StageManager.getSelectedAssociations().filter(
629-
(edge) => edge instanceof CublicCatmullRomSplineEdge,
629+
(edge) => edge instanceof CubicCatmullRomSplineEdge,
630630
);
631631
for (const edge of selectedCREdge) {
632632
edge.addControlPoint();

app/src/core/service/dataFileService/fileLoader.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { PortalNode } from "../../stage/stageObject/entity/PortalNode";
1515
import { PathString } from "../../../utils/pathString";
1616
import { isWeb } from "../../../utils/platform";
1717
import { Vector } from "../../dataStruct/Vector";
18-
import { CublicCatmullRomSplineEdge } from "../../stage/stageObject/association/CublicCatmullRomSplineEdge";
18+
import { CubicCatmullRomSplineEdge } from "../../stage/stageObject/association/CubicCatmullRomSplineEdge";
1919
import { MultiTargetUndirectedEdge } from "../../stage/stageObject/association/MutiTargetUndirectedEdge";
2020
import { RecentFileManager } from "./RecentFileManager";
2121
import { SvgNode } from "../../stage/stageObject/entity/SvgNode";
@@ -169,8 +169,8 @@ export namespace FileLoader {
169169
let newAssociation = null;
170170
if (Serialized.isLineEdge(edge)) {
171171
newAssociation = new LineEdge(edge);
172-
} else if (Serialized.isCublicCatmullRomSplineEdge(edge)) {
173-
newAssociation = new CublicCatmullRomSplineEdge(edge);
172+
} else if (Serialized.isCubicCatmullRomSplineEdge(edge)) {
173+
newAssociation = new CubicCatmullRomSplineEdge(edge);
174174
} else if (Serialized.isMultiTargetUndirectedEdge(edge)) {
175175
newAssociation = new MultiTargetUndirectedEdge(edge);
176176
}

app/src/core/service/dataGenerateService/autoComputeEngine/functions/nodeLogic.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import { ConnectPoint } from "../../../../stage/stageObject/entity/ConnectPoint"
2525
*/
2626
export namespace NodeLogic {
2727
export const delayStates: Map<string, Record<number, string>> = new Map();
28-
let step: number = 0;
28+
/* eslint-disable prefer-const */
29+
export let step: number = 0;
2930
// step 是一个计数器,每当逻辑引擎实际执行一次时,step 就会加一
3031
// TODO: 可以考虑把 step 放到逻辑引擎层面,甚至可以出一个节点获取当前步数,可以加一个每次只运行一步的快捷键
31-
// 现在的好处是只有在用延迟复制时才会有这个计数器,其他时候step不存在
3232
/**
3333
* 输入三个数字节点,并将所有的孩子节点更改为相应的颜色
3434
* @param fatherNodes
@@ -686,13 +686,10 @@ export namespace NodeLogic {
686686
// eslint-disable-next-line @typescript-eslint/no-unused-vars
687687
_childNodes: ConnectableEntity[],
688688
): string[] {
689-
step++;
690689
if (fatherNodes.length < 4) {
691690
// 多了一个逻辑节点本身,所以实际进来的节点比延迟复制需要的节点节点多一个
692691
return ["Error: input node contains less than 3 nodes"];
693692
}
694-
console.log("delayCopy", fatherNodes);
695-
console.log(delayStates);
696693
if (
697694
fatherNodes[0] instanceof TextNode &&
698695
fatherNodes[1] instanceof TextNode &&

app/src/core/service/dataGenerateService/autoComputeEngine/mainTick.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ export function autoComputeEngineTick(tickNumber: number) {
201201
)) {
202202
computeEdge(edge);
203203
}
204+
NodeLogic.step++;
205+
// 逻辑引擎执行一步,计数器+1
204206
}
205207

206208
export function isTextNodeLogic(node: TextNode): boolean {

app/src/core/stage/StageDumper.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SectionMethods } from "./stageManager/basicMethods/SectionMethods";
33
import { StageManager } from "./stageManager/StageManager";
44
import { Association } from "./stageObject/abstract/Association";
55
import { Entity } from "./stageObject/abstract/StageEntity";
6-
import { CublicCatmullRomSplineEdge } from "./stageObject/association/CublicCatmullRomSplineEdge";
6+
import { CubicCatmullRomSplineEdge } from "./stageObject/association/CubicCatmullRomSplineEdge";
77
import { LineEdge } from "./stageObject/association/LineEdge";
88
import { MultiTargetUndirectedEdge } from "./stageObject/association/MutiTargetUndirectedEdge";
99
import { ConnectPoint } from "./stageObject/entity/ConnectPoint";
@@ -49,13 +49,13 @@ export namespace StageDumper {
4949
targetRectRate: [edge.targetRectangleRate.x, edge.targetRectangleRate.y],
5050
};
5151
}
52-
export function dumpCrEdge(edge: CublicCatmullRomSplineEdge): Serialized.CublicCatmullRomSplineEdge {
52+
export function dumpCrEdge(edge: CubicCatmullRomSplineEdge): Serialized.CubicCatmullRomSplineEdge {
5353
return {
5454
source: edge.source.uuid,
5555
target: edge.target.uuid,
5656
text: edge.text,
5757
uuid: edge.uuid,
58-
type: "core:cublic_catmull_rom_spline_edge",
58+
type: "core:cubic_catmull_rom_spline_edge",
5959
controlPoints: edge.getControlPoints().map((point) => [point.x, point.y]),
6060
alpha: edge.alpha,
6161
tension: edge.tension,
@@ -193,7 +193,7 @@ export namespace StageDumper {
193193
export function dumpOneAssociation(association: Association): Serialized.CoreAssociation {
194194
if (association instanceof LineEdge) {
195195
return dumpEdge(association);
196-
} else if (association instanceof CublicCatmullRomSplineEdge) {
196+
} else if (association instanceof CubicCatmullRomSplineEdge) {
197197
return dumpCrEdge(association);
198198
} else if (association instanceof MultiTargetUndirectedEdge) {
199199
return dumpMTUEdge(association);
@@ -297,7 +297,7 @@ export namespace StageDumper {
297297
if (entities.includes(edge.source) && entities.includes(edge.target)) {
298298
result.push(dumpEdge(edge));
299299
}
300-
} else if (edge instanceof CublicCatmullRomSplineEdge) {
300+
} else if (edge instanceof CubicCatmullRomSplineEdge) {
301301
if (entities.includes(edge.source) && entities.includes(edge.target)) {
302302
result.push(dumpCrEdge(edge));
303303
}

0 commit comments

Comments
 (0)