66 TextStyle ,
77 Text ,
88} from "pixi.js" ;
9- import { EdgeId , ViewGraph } from "./../graphs/viewgraph" ;
9+ import { ViewGraph } from "./../graphs/viewgraph" ;
1010import {
1111 deselectElement ,
1212 refreshElement ,
@@ -19,7 +19,7 @@ import { Position } from "../common";
1919import { DeviceInfo } from "../../graphics/renderables/device_info" ;
2020import { IpAddress } from "../../packets/ip" ;
2121import { DeviceId } from "../graphs/datagraph" ;
22- import { DragDeviceMove , EdgeData , AddEdgeMove } from "../undo-redo" ;
22+ import { DragDeviceMove , AddEdgeMove } from "../undo-redo" ;
2323import { Layer } from "./layer" ;
2424
2525export { Layer } from "./layer" ;
@@ -43,7 +43,7 @@ export function layerFromType(type: DeviceType) {
4343export abstract class Device extends Sprite {
4444 readonly id : DeviceId ;
4545 readonly viewgraph : ViewGraph ;
46- connections = new Map < EdgeId , DeviceId > ( ) ;
46+ connections = new Set < DeviceId > ( ) ;
4747
4848 highlightMarker : Graphics | null = null ; // Marker to indicate selection
4949
@@ -99,19 +99,15 @@ export abstract class Device extends Sprite {
9999 this . addChild ( idText ) ; // Add the ID text as a child of the device
100100 }
101101
102- getConnections ( ) : { edgeId : EdgeId ; adyacentId : DeviceId } [ ] {
103- return Array . from ( this . connections . entries ( ) ) . map (
104- ( [ edgeId , adyacentId ] ) => {
105- return { edgeId, adyacentId } ;
106- } ,
107- ) ;
102+ getConnections ( ) : DeviceId [ ] {
103+ return Array . from ( this . connections . values ( ) ) ;
108104 }
109105
110- addConnection ( edgeId : EdgeId , adyacentId : DeviceId ) {
111- this . connections . set ( edgeId , adyacentId ) ;
106+ addConnection ( adyacentId : DeviceId ) {
107+ this . connections . add ( adyacentId ) ;
112108 }
113109
114- removeConnection ( id : EdgeId ) {
110+ removeConnection ( id : DeviceId ) {
115111 this . connections . delete ( id ) ;
116112 }
117113
@@ -145,22 +141,18 @@ export abstract class Device extends Sprite {
145141 this . parent . on ( "pointerup" , onPointerUp ) ;
146142 }
147143
148- connectTo ( adyacentId : number ) : boolean {
144+ connectTo ( adyacentId : DeviceId ) : boolean {
149145 // Connects both devices with an edge.
150146 // console.log("Entered connectTo");
151147
152148 const edgeId = this . viewgraph . addEdge ( this . id , adyacentId ) ;
153149 if ( edgeId ) {
154150 const adyacentDevice = this . viewgraph . getDevice ( adyacentId ) ;
155- this . addConnection ( edgeId , adyacentId ) ;
156- adyacentDevice . addConnection ( edgeId , this . id ) ;
151+ this . addConnection ( adyacentId ) ;
152+ adyacentDevice . addConnection ( this . id ) ;
157153
158154 // Register move
159- const moveData : EdgeData = {
160- edgeId,
161- connectedNodes : { n1 : this . id , n2 : adyacentId } ,
162- } ;
163- const move = new AddEdgeMove ( moveData ) ;
155+ const move = new AddEdgeMove ( { n1 : this . id , n2 : adyacentId } ) ;
164156 urManager . push ( move ) ;
165157
166158 return true ;
0 commit comments