Skip to content

优化代码结构和命名,修复延迟线和Ctrl左键单击边的报错 #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Shape } from "./Shape";
/**
* CR曲线形状
*/
export class CublicCatmullRomSpline extends Shape {
export class CubicCatmullRomSpline extends Shape {
public controlPoints: Vector[];
public alpha: number;
public tension: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Color } from "../../../dataStruct/Color";
import { Circle } from "../../../dataStruct/shape/Circle";
import { CublicCatmullRomSpline } from "../../../dataStruct/shape/CublicCatmullRomSpline";
import { CubicCatmullRomSpline } from "../../../dataStruct/shape/CubicCatmullRomSpline";
import { SymmetryCurve } from "../../../dataStruct/shape/Curve";
import { Line } from "../../../dataStruct/shape/Line";
import { Rectangle } from "../../../dataStruct/shape/Rectangle";
Expand Down Expand Up @@ -50,8 +50,8 @@ export namespace CollisionBoxRenderer {
// const size = 15; // 箭头大小
// shape.end = shape.end.subtract(shape.endDirection.multiply(size / -2));
WorldRenderUtils.renderSymmetryCurve(shape, color, 10);
} else if (shape instanceof CublicCatmullRomSpline) {
WorldRenderUtils.renderCublicCatmullRomSpline(shape, color, 10);
} else if (shape instanceof CubicCatmullRomSpline) {
WorldRenderUtils.renderCubicCatmullRomSpline(shape, color, 10);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Color } from "../../../../dataStruct/Color";
import { Vector } from "../../../../dataStruct/Vector";
import { Settings } from "../../../../service/Settings";
import { Camera } from "../../../../stage/Camera";
import { CublicCatmullRomSplineEdge } from "../../../../stage/stageObject/association/CublicCatmullRomSplineEdge";
import { CubicCatmullRomSplineEdge } from "../../../../stage/stageObject/association/CubicCatmullRomSplineEdge";
import { LineEdge } from "../../../../stage/stageObject/association/LineEdge";
import { Section } from "../../../../stage/stageObject/entity/Section";

Expand Down Expand Up @@ -106,14 +106,14 @@ export namespace EdgeRenderer {
}
}

export function renderCrEdge(edge: CublicCatmullRomSplineEdge) {
export function renderCrEdge(edge: CubicCatmullRomSplineEdge) {
if (edge.source.isHiddenBySectionCollapse && edge.target.isHiddenBySectionCollapse) {
return;
}
const crShape = edge.getShape();
const edgeColor = edge.color.a === 0 ? StageStyleManager.currentStyle.StageObjectBorder : edge.color;
// 画曲线
WorldRenderUtils.renderCublicCatmullRomSpline(crShape, edgeColor, 2);
WorldRenderUtils.renderCubicCatmullRomSpline(crShape, edgeColor, 2);
if (edge.isSelected) {
CollisionBoxRenderer.render(edge.collisionBox, StageStyleManager.currentStyle.CollideBoxSelected);
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/core/render/canvas2d/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { StageHistoryManager } from "../../stage/stageManager/StageHistoryManage
import { StageManager } from "../../stage/stageManager/StageManager";
import { StageObjectSelectCounter } from "../../stage/stageManager/concreteMethods/StageObjectSelectCounter";
import { StageObject } from "../../stage/stageObject/abstract/StageObject";
import { CublicCatmullRomSplineEdge } from "../../stage/stageObject/association/CublicCatmullRomSplineEdge";
import { CubicCatmullRomSplineEdge } from "../../stage/stageObject/association/CubicCatmullRomSplineEdge";
import { LineEdge } from "../../stage/stageObject/association/LineEdge";
import { MultiTargetUndirectedEdge } from "../../stage/stageObject/association/MutiTargetUndirectedEdge";
import { CurveRenderer } from "./basicRenderer/curveRenderer";
Expand Down Expand Up @@ -635,7 +635,7 @@ export namespace Renderer {
if (association instanceof LineEdge) {
EdgeRenderer.renderLineEdge(association);
}
if (association instanceof CublicCatmullRomSplineEdge) {
if (association instanceof CubicCatmullRomSplineEdge) {
EdgeRenderer.renderCrEdge(association);
}
renderedEdges++;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color } from "../../../dataStruct/Color";
import { CublicCatmullRomSpline } from "../../../dataStruct/shape/CublicCatmullRomSpline";
import { CubicCatmullRomSpline } from "../../../dataStruct/shape/CubicCatmullRomSpline";
import { CubicBezierCurve, SymmetryCurve } from "../../../dataStruct/shape/Curve";
import { Rectangle } from "../../../dataStruct/shape/Rectangle";
import { Vector } from "../../../dataStruct/Vector";
Expand All @@ -19,7 +19,7 @@ export namespace WorldRenderUtils {
* 绘制一条Catmull-Rom样条线
* @param curve
*/
export function renderCublicCatmullRomSpline(spline: CublicCatmullRomSpline, color: Color, width: number): void {
export function renderCubicCatmullRomSpline(spline: CubicCatmullRomSpline, color: Color, width: number): void {
const points = spline.computePath().map(Renderer.transformWorld2View);
width *= Camera.currentScale;
const start = Renderer.transformWorld2View(spline.controlPoints[1]);
Expand Down
21 changes: 12 additions & 9 deletions app/src/core/service/controlService/controller/ControllerClass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ export class ControllerClass {

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Renderer } from "../../../../render/canvas2d/renderer";
import { LeftMouseModeEnum, Stage } from "../../../../stage/Stage";
import { StageMultiTargetEdgeMove } from "../../../../stage/stageManager/concreteMethods/StageMultiTargetEdgeMove";
import { StageNodeConnector } from "../../../../stage/stageManager/concreteMethods/StageNodeConnector";
import { StageNodeRotate } from "../../../../stage/stageManager/concreteMethods/stageNodeRotate";
import { StageNodeRotate } from "../../../../stage/stageManager/concreteMethods/StageNodeRotate";
import { StageHistoryManager } from "../../../../stage/stageManager/StageHistoryManager";
import { StageManager } from "../../../../stage/stageManager/StageManager";
import { MultiTargetUndirectedEdge } from "../../../../stage/stageObject/association/MutiTargetUndirectedEdge";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class ControllerEntityClickSelectAndMoveClass extends ControllerClass {
} else if (Controller.pressingKeySet.has("shift")) {
// shift 按下,只选中节点
clickedStageObject.isSelected = true;
// 没有实体被选中则return
if (StageManager.getSelectedEntities().length === 0) return;
const rectangles = StageManager.getSelectedEntities().map((entity) => entity.collisionBox.getRectangle());
const boundingRectangle = Rectangle.getBoundingRectangle(rectangles);
Stage.effectMachine.addEffect(RectangleRenderEffect.fromShiftClickSelect(boundingRectangle));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Vector } from "../../../../dataStruct/Vector";
import { Renderer } from "../../../../render/canvas2d/renderer";
import { LeftMouseModeEnum, Stage } from "../../../../stage/Stage";
import { SectionMethods } from "../../../../stage/stageManager/basicMethods/SectionMethods";
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/stageNodeAdder";
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/StageNodeAdder";
import { StageObjectSelectCounter } from "../../../../stage/stageManager/concreteMethods/StageObjectSelectCounter";
import { StageManager } from "../../../../stage/stageManager/StageManager";
import { Section } from "../../../../stage/stageObject/entity/Section";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ControllerClass } from "../ControllerClass";
import { addTextNodeByLocation } from "./utilsControl";
import { StageStyleManager } from "../../../feedbackService/stageStyle/StageStyleManager";
import { SectionMethods } from "../../../../stage/stageManager/basicMethods/SectionMethods";
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/stageNodeAdder";
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/StageNodeAdder";
import { Line } from "../../../../dataStruct/shape/Line";
import { Direction } from "../../../../../types/directions";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { InputElement } from "../../../../render/domElement/inputElement";
import { Camera } from "../../../../stage/Camera";
import { Stage } from "../../../../stage/Stage";
import { SectionMethods } from "../../../../stage/stageManager/basicMethods/SectionMethods";
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/stageNodeAdder";
import { StageNodeAdder } from "../../../../stage/stageManager/concreteMethods/StageNodeAdder";
import { StageObjectSelectCounter } from "../../../../stage/stageManager/concreteMethods/StageObjectSelectCounter";
import { StageHistoryManager } from "../../../../stage/stageManager/StageHistoryManager";
import { StageManager } from "../../../../stage/stageManager/StageManager";
Expand Down Expand Up @@ -126,6 +126,7 @@ export function editEdgeText(clickedLineEdge: Edge, selectAll = true) {
selectAll,
).then(() => {
// clickedLineEdge!.isEditing = false;
// 因为这里用的是不透明文本框,所以不需要停止节点上文字的渲染
Controller.isCameraLocked = false;
StageHistoryManager.recordStep();
});
Expand Down Expand Up @@ -160,6 +161,7 @@ export function editMultiTargetEdgeText(clickedEdge: MultiTargetUndirectedEdge,
selectAll,
).then(() => {
// clickedLineEdge!.isEditing = false;
// 因为这里用的是不透明文本框,所以不需要停止节点上文字的渲染
Controller.isCameraLocked = false;
StageHistoryManager.recordStep();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Vector } from "../../../dataStruct/Vector";
import { EdgeRenderer } from "../../../render/canvas2d/entityRenderer/edge/EdgeRenderer";
// import { Camera } from "../../../stage/Camera";
import { Stage } from "../../../stage/Stage";
import { StageNodeAdder } from "../../../stage/stageManager/concreteMethods/stageNodeAdder";
import { StageNodeAdder } from "../../../stage/stageManager/concreteMethods/StageNodeAdder";
import { StageManager } from "../../../stage/stageManager/StageManager";
import { ConnectableEntity } from "../../../stage/stageObject/abstract/ConnectableEntity";
import { TextRiseEffect } from "../../feedbackService/effectEngine/concrete/TextRiseEffect";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { StageManager } from "../../../stage/stageManager/StageManager";
import { SectionMethods } from "../../../stage/stageManager/basicMethods/SectionMethods";
import { LayoutManualAlignManager } from "../../../stage/stageManager/concreteMethods/layoutManager/layoutManualAlignManager";
import { ConnectableEntity } from "../../../stage/stageObject/abstract/ConnectableEntity";
import { CublicCatmullRomSplineEdge } from "../../../stage/stageObject/association/CublicCatmullRomSplineEdge";
import { CubicCatmullRomSplineEdge } from "../../../stage/stageObject/association/CubicCatmullRomSplineEdge";
import { LineEdge } from "../../../stage/stageObject/association/LineEdge";
import { PortalNode } from "../../../stage/stageObject/entity/PortalNode";
import { Section } from "../../../stage/stageObject/entity/Section";
Expand Down Expand Up @@ -626,7 +626,7 @@ export class SecretKeysEngine {
isHidden: true,
func() {
const selectedCREdge = StageManager.getSelectedAssociations().filter(
(edge) => edge instanceof CublicCatmullRomSplineEdge,
(edge) => edge instanceof CubicCatmullRomSplineEdge,
);
for (const edge of selectedCREdge) {
edge.addControlPoint();
Expand Down
6 changes: 3 additions & 3 deletions app/src/core/service/dataFileService/fileLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { PortalNode } from "../../stage/stageObject/entity/PortalNode";
import { PathString } from "../../../utils/pathString";
import { isWeb } from "../../../utils/platform";
import { Vector } from "../../dataStruct/Vector";
import { CublicCatmullRomSplineEdge } from "../../stage/stageObject/association/CublicCatmullRomSplineEdge";
import { CubicCatmullRomSplineEdge } from "../../stage/stageObject/association/CubicCatmullRomSplineEdge";
import { MultiTargetUndirectedEdge } from "../../stage/stageObject/association/MutiTargetUndirectedEdge";
import { RecentFileManager } from "./RecentFileManager";
import { SvgNode } from "../../stage/stageObject/entity/SvgNode";
Expand Down Expand Up @@ -169,8 +169,8 @@ export namespace FileLoader {
let newAssociation = null;
if (Serialized.isLineEdge(edge)) {
newAssociation = new LineEdge(edge);
} else if (Serialized.isCublicCatmullRomSplineEdge(edge)) {
newAssociation = new CublicCatmullRomSplineEdge(edge);
} else if (Serialized.isCubicCatmullRomSplineEdge(edge)) {
newAssociation = new CubicCatmullRomSplineEdge(edge);
} else if (Serialized.isMultiTargetUndirectedEdge(edge)) {
newAssociation = new MultiTargetUndirectedEdge(edge);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { ConnectPoint } from "../../../../stage/stageObject/entity/ConnectPoint"
*/
export namespace NodeLogic {
export const delayStates: Map<string, Record<number, string>> = new Map();
let step: number = 0;
/* eslint-disable prefer-const */
export let step: number = 0;
// step 是一个计数器,每当逻辑引擎实际执行一次时,step 就会加一
// TODO: 可以考虑把 step 放到逻辑引擎层面,甚至可以出一个节点获取当前步数,可以加一个每次只运行一步的快捷键
// 现在的好处是只有在用延迟复制时才会有这个计数器,其他时候step不存在
/**
* 输入三个数字节点,并将所有的孩子节点更改为相应的颜色
* @param fatherNodes
Expand Down Expand Up @@ -686,13 +686,10 @@ export namespace NodeLogic {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_childNodes: ConnectableEntity[],
): string[] {
step++;
if (fatherNodes.length < 4) {
// 多了一个逻辑节点本身,所以实际进来的节点比延迟复制需要的节点节点多一个
return ["Error: input node contains less than 3 nodes"];
}
console.log("delayCopy", fatherNodes);
console.log(delayStates);
if (
fatherNodes[0] instanceof TextNode &&
fatherNodes[1] instanceof TextNode &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export function autoComputeEngineTick(tickNumber: number) {
)) {
computeEdge(edge);
}
NodeLogic.step++;
// 逻辑引擎执行一步,计数器+1
}

export function isTextNodeLogic(node: TextNode): boolean {
Expand Down
10 changes: 5 additions & 5 deletions app/src/core/stage/StageDumper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SectionMethods } from "./stageManager/basicMethods/SectionMethods";
import { StageManager } from "./stageManager/StageManager";
import { Association } from "./stageObject/abstract/Association";
import { Entity } from "./stageObject/abstract/StageEntity";
import { CublicCatmullRomSplineEdge } from "./stageObject/association/CublicCatmullRomSplineEdge";
import { CubicCatmullRomSplineEdge } from "./stageObject/association/CubicCatmullRomSplineEdge";
import { LineEdge } from "./stageObject/association/LineEdge";
import { MultiTargetUndirectedEdge } from "./stageObject/association/MutiTargetUndirectedEdge";
import { ConnectPoint } from "./stageObject/entity/ConnectPoint";
Expand Down Expand Up @@ -49,13 +49,13 @@ export namespace StageDumper {
targetRectRate: [edge.targetRectangleRate.x, edge.targetRectangleRate.y],
};
}
export function dumpCrEdge(edge: CublicCatmullRomSplineEdge): Serialized.CublicCatmullRomSplineEdge {
export function dumpCrEdge(edge: CubicCatmullRomSplineEdge): Serialized.CubicCatmullRomSplineEdge {
return {
source: edge.source.uuid,
target: edge.target.uuid,
text: edge.text,
uuid: edge.uuid,
type: "core:cublic_catmull_rom_spline_edge",
type: "core:cubic_catmull_rom_spline_edge",
controlPoints: edge.getControlPoints().map((point) => [point.x, point.y]),
alpha: edge.alpha,
tension: edge.tension,
Expand Down Expand Up @@ -193,7 +193,7 @@ export namespace StageDumper {
export function dumpOneAssociation(association: Association): Serialized.CoreAssociation {
if (association instanceof LineEdge) {
return dumpEdge(association);
} else if (association instanceof CublicCatmullRomSplineEdge) {
} else if (association instanceof CubicCatmullRomSplineEdge) {
return dumpCrEdge(association);
} else if (association instanceof MultiTargetUndirectedEdge) {
return dumpMTUEdge(association);
Expand Down Expand Up @@ -297,7 +297,7 @@ export namespace StageDumper {
if (entities.includes(edge.source) && entities.includes(edge.target)) {
result.push(dumpEdge(edge));
}
} else if (edge instanceof CublicCatmullRomSplineEdge) {
} else if (edge instanceof CubicCatmullRomSplineEdge) {
if (entities.includes(edge.source) && entities.includes(edge.target)) {
result.push(dumpCrEdge(edge));
}
Expand Down
Loading