|
1 | | -import { Vector } from "@graphif/data-structures"; |
2 | | -import { Rectangle } from "@graphif/shapes"; |
3 | | -import { Serialized } from "@/types/node"; |
4 | 1 | import { Project } from "@/core/Project"; |
5 | 2 | import { CircleChangeRadiusEffect } from "@/core/service/feedbackService/effectEngine/concrete/CircleChangeRadiusEffect"; |
6 | 3 | import { ConnectableEntity } from "@/core/stage/stageObject/abstract/ConnectableEntity"; |
7 | 4 | 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"; |
8 | 8 |
|
9 | | -// TODO: 这里继承了ConnectableEntity的话,TextNode模块就会报错,原因未知 |
| 9 | +// HACK: 【现在没问题了2025-7-9】这里继承了ConnectableEntity的话,TextNode模块就会报错,原因未知 |
10 | 10 | // Uncaught ReferenceError: can't access lexical declaration 'ConnectableEntity' before initialization |
| 11 | +@passExtraAtArg1 |
| 12 | +@passObject |
11 | 13 | export class ConnectPoint extends ConnectableEntity { |
12 | 14 | get geometryCenter(): Vector { |
13 | | - return this.location; |
| 15 | + return this.collisionBox.getRectangle().center; |
14 | 16 | } |
15 | 17 |
|
16 | 18 | isHiddenBySectionCollapse: boolean = false; |
17 | 19 |
|
18 | | - private _collisionBox: CollisionBox; |
19 | | - |
20 | | - public get collisionBox(): CollisionBox { |
21 | | - return this._collisionBox; |
22 | | - } |
| 20 | + @serializable |
| 21 | + collisionBox: CollisionBox; |
| 22 | + @serializable |
23 | 23 | uuid: string; |
24 | | - private location: Vector; |
25 | 24 |
|
26 | 25 | private _radius = 10; |
27 | 26 | get radius(): number { |
28 | 27 | return this._radius; |
29 | 28 | } |
30 | 29 | set radius(value: number) { |
31 | 30 | this._radius = value; |
32 | | - const rectangle = this._collisionBox.shapes[0]; |
| 31 | + const rectangle = this.collisionBox.shapes[0]; |
33 | 32 | if (rectangle instanceof Rectangle) { |
34 | 33 | rectangle.size = new Vector(value * 2, value * 2); |
35 | 34 | rectangle.location = this.geometryCenter.subtract(new Vector(value, value)); |
@@ -72,36 +71,31 @@ export class ConnectPoint extends ConnectableEntity { |
72 | 71 |
|
73 | 72 | constructor( |
74 | 73 | 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 | + }, |
76 | 79 | public unknown = false, |
77 | 80 | ) { |
78 | | - // super(); |
| 81 | + super(); |
79 | 82 | this.uuid = uuid; |
80 | | - this.location = new Vector(...location); |
| 83 | + this.collisionBox = collisionBox; |
81 | 84 | this.details = details; |
82 | | - this._collisionBox = new CollisionBox([ |
83 | | - new Rectangle(this.location.subtract(new Vector(10, 10)), new Vector(20, 20)), |
84 | | - ]); |
85 | 85 | this.radius = 1; |
86 | 86 | } |
87 | 87 |
|
88 | 88 | 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; |
95 | 92 | this.updateFatherSectionByMove(); |
96 | 93 | } |
97 | 94 |
|
98 | 95 | 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; |
105 | 99 | this.updateFatherSectionByMove(); |
106 | 100 | } |
107 | 101 | } |
0 commit comments