11import { Viewport } from "./graphics/viewport" ;
2- import { DataGraph , isLinkNode , isNetworkNode } from "./types/graphs/datagraph" ;
2+ import { DataGraph } from "./types/graphs/datagraph" ;
33import { ViewGraph } from "./types/graphs/viewgraph" ;
44import {
55 loadFromLocalStorage ,
66 saveToLocalStorage ,
77 urManager ,
88} from "./types/viewportManager" ;
9- import { Layer } from "./types/devices/device" ;
109import { compareIps , IpAddress , IpAddressGenerator } from "./packets/ip" ;
11- import { layerFromName } from "./types/devices /layer" ;
12- import { SpeedMultiplier } from "./types/devices/ speedMultiplier" ;
10+ import { layerFromName , Layer } from "./types/layer" ;
11+ import { SpeedMultiplier } from "./types/speedMultiplier" ;
1312import {
1413 compareMacs ,
1514 MacAddress ,
1615 MacAddressGenerator ,
1716} from "./packets/ethernet" ;
17+ import { DataNetworkDevice } from "./types/data-devices" ;
1818import { Colors } from "./utils/utils" ;
1919
2020export class GlobalContext {
@@ -50,11 +50,12 @@ export class GlobalContext {
5050
5151 private setNetwork ( datagraph : DataGraph , layer : Layer ) {
5252 this . datagraph = datagraph ;
53- this . viewport . clear ( ) ;
5453 if ( this . viewgraph ) {
55- this . viewgraph . clear ( ) ;
54+ this . viewgraph . setDataGraph ( datagraph ) ;
55+ this . viewgraph . changeCurrLayer ( layer ) ;
56+ } else {
57+ this . viewgraph = new ViewGraph ( datagraph , this , layer ) ;
5658 }
57- this . viewgraph = new ViewGraph ( this . datagraph , this , layer ) ;
5859 this . setIpGenerator ( ) ;
5960 this . setMacGenerator ( ) ;
6061 }
@@ -149,14 +150,9 @@ export class GlobalContext {
149150 let maxIp = IpAddress . parse ( "10.0.0.0" ) ;
150151
151152 for ( const [ , device ] of this . datagraph . getDevices ( ) ) {
152- if ( isNetworkNode ( device ) ) {
153- const ip = IpAddress . parse ( device . ip ) ;
154- if ( ip === null ) {
155- console . error ( "Failed to parse IP address: " + device . ip ) ;
156- } else {
157- if ( compareIps ( maxIp , ip ) < 0 ) {
158- maxIp = ip ;
159- }
153+ if ( device instanceof DataNetworkDevice ) {
154+ if ( compareIps ( maxIp , device . ip ) < 0 ) {
155+ maxIp = device . ip ;
160156 }
161157 }
162158 }
@@ -168,11 +164,8 @@ export class GlobalContext {
168164 private setMacGenerator ( ) {
169165 let maxMac = MacAddress . parse ( "00:00:10:00:00:00" ) ;
170166 for ( const [ , device ] of this . datagraph . getDevices ( ) ) {
171- if ( isLinkNode ( device ) ) {
172- const mac = MacAddress . parse ( device . mac ) ;
173- if ( compareMacs ( maxMac , mac ) < 0 ) {
174- maxMac = mac ;
175- }
167+ if ( compareMacs ( maxMac , device . mac ) < 0 ) {
168+ maxMac = device . mac ;
176169 }
177170 }
178171 // TODO: we should use MacAddress instead of string here and in Datagraph
0 commit comments