Skip to content

Commit 944ab72

Browse files
committed
✨ 支持序列化ConnectPoint
1 parent 9548153 commit 944ab72

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

app/src/core/stage/stageObject/abstract/StageEntity.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { StageObject } from "@/core/stage/stageObject/abstract/StageObject";
12
import { Vector } from "@graphif/data-structures";
3+
import { serializable } from "@graphif/serializer";
24
import { Rectangle } from "@graphif/shapes";
3-
import { StageObject } from "@/core/stage/stageObject/abstract/StageObject";
45
/**
56
* 一切独立存在、能被移动的东西,且放在框里能被连带移动的东西
67
* 实体
@@ -24,6 +25,7 @@ export abstract class Entity extends StageObject {
2425
*/
2526
abstract moveTo(location: Vector): void;
2627

28+
@serializable
2729
public details: string = "";
2830
public isEditingDetails: boolean = false;
2931
/** 用于交互使用,比如鼠标悬浮显示details */

app/src/core/stage/stageObject/entity/ConnectPoint.tsx

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
import { Vector } from "@graphif/data-structures";
2-
import { Rectangle } from "@graphif/shapes";
3-
import { Serialized } from "@/types/node";
41
import { Project } from "@/core/Project";
52
import { CircleChangeRadiusEffect } from "@/core/service/feedbackService/effectEngine/concrete/CircleChangeRadiusEffect";
63
import { ConnectableEntity } from "@/core/stage/stageObject/abstract/ConnectableEntity";
74
import { CollisionBox } from "@/core/stage/stageObject/collisionBox/collisionBox";
5+
import { Vector } from "@graphif/data-structures";
6+
import { passExtraAtArg1, passObject, serializable } from "@graphif/serializer";
7+
import { Rectangle } from "@graphif/shapes";
88

9-
// TODO: 这里继承了ConnectableEntity的话,TextNode模块就会报错,原因未知
9+
// HACK: 【现在没问题了2025-7-9】这里继承了ConnectableEntity的话,TextNode模块就会报错,原因未知
1010
// Uncaught ReferenceError: can't access lexical declaration 'ConnectableEntity' before initialization
11+
@passExtraAtArg1
12+
@passObject
1113
export class ConnectPoint extends ConnectableEntity {
1214
get geometryCenter(): Vector {
13-
return this.location;
15+
return this.collisionBox.getRectangle().center;
1416
}
1517

1618
isHiddenBySectionCollapse: boolean = false;
1719

18-
private _collisionBox: CollisionBox;
19-
20-
public get collisionBox(): CollisionBox {
21-
return this._collisionBox;
22-
}
20+
@serializable
21+
collisionBox: CollisionBox;
22+
@serializable
2323
uuid: string;
24-
private location: Vector;
2524

2625
private _radius = 10;
2726
get radius(): number {
2827
return this._radius;
2928
}
3029
set radius(value: number) {
3130
this._radius = value;
32-
const rectangle = this._collisionBox.shapes[0];
31+
const rectangle = this.collisionBox.shapes[0];
3332
if (rectangle instanceof Rectangle) {
3433
rectangle.size = new Vector(value * 2, value * 2);
3534
rectangle.location = this.geometryCenter.subtract(new Vector(value, value));
@@ -72,36 +71,31 @@ export class ConnectPoint extends ConnectableEntity {
7271

7372
constructor(
7473
protected readonly project: Project,
75-
{ uuid, location = [0, 0], details = "" }: Partial<Serialized.ConnectPoint> & { uuid: string },
74+
{
75+
uuid = crypto.randomUUID() as string,
76+
collisionBox = new CollisionBox([new Rectangle(Vector.getZero(), Vector.getZero())]),
77+
details = "",
78+
},
7679
public unknown = false,
7780
) {
78-
// super();
81+
super();
7982
this.uuid = uuid;
80-
this.location = new Vector(...location);
83+
this.collisionBox = collisionBox;
8184
this.details = details;
82-
this._collisionBox = new CollisionBox([
83-
new Rectangle(this.location.subtract(new Vector(10, 10)), new Vector(20, 20)),
84-
]);
8585
this.radius = 1;
8686
}
8787

8888
move(delta: Vector): void {
89-
this.location = this.location.add(delta);
90-
91-
const rectangle = this._collisionBox.shapes[0];
92-
if (rectangle instanceof Rectangle) {
93-
rectangle.location = rectangle.location.add(delta);
94-
}
89+
const newRectangle = this.collisionBox.getRectangle();
90+
newRectangle.location = newRectangle.location.add(delta);
91+
this.collisionBox.shapes[0] = newRectangle;
9592
this.updateFatherSectionByMove();
9693
}
9794

9895
moveTo(location: Vector): void {
99-
this.location = location;
100-
101-
const rectangle = this._collisionBox.shapes[0];
102-
if (rectangle instanceof Rectangle) {
103-
rectangle.location = location.subtract(new Vector(10, 10));
104-
}
96+
const newRectangle = this.collisionBox.getRectangle();
97+
newRectangle.location = location;
98+
this.collisionBox.shapes[0] = newRectangle;
10599
this.updateFatherSectionByMove();
106100
}
107101
}

0 commit comments

Comments
 (0)