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

0 commit comments

Comments
 (0)