Skip to content

Commit eb27770

Browse files
authored
Packets removed when setting a new or loaded graph (#186)
Before setting the graph, the _Packet Manager_ clears all its packets in transit
1 parent 325a6b5 commit eb27770

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

src/context.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ export class GlobalContext {
5151
private setNetwork(datagraph: DataGraph, layer: Layer) {
5252
this.datagraph = datagraph;
5353
if (this.viewgraph) {
54-
this.viewgraph.setDataGraph(datagraph);
55-
this.viewgraph.changeCurrLayer(layer);
56-
} else {
57-
this.viewgraph = new ViewGraph(datagraph, this, layer);
54+
this.viewgraph.clearPacketsInTransit();
55+
this.viewgraph.clear();
5856
}
57+
this.viewgraph = new ViewGraph(datagraph, this, layer);
5958
this.setIpGenerator();
6059
this.setMacGenerator();
6160
}
@@ -106,9 +105,9 @@ export class GlobalContext {
106105
return this.datagraph;
107106
}
108107

109-
changeViewGraph(selectedLayer: string) {
108+
changeLayer(selectedLayer: string) {
110109
const layer = layerFromName(selectedLayer);
111-
this.setNetwork(this.datagraph, layer);
110+
this.viewgraph.changeCurrLayer(layer);
112111
}
113112

114113
pause() {

src/handlers/layerSelectorHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class LayerHandler {
6464
}
6565

6666
console.debug(`Layer selected: ${selectedLayer}`);
67-
this.ctx.changeViewGraph(selectedLayer);
67+
this.ctx.changeLayer(selectedLayer);
6868
saveToLocalStorage(this.ctx);
6969
this.leftBar.setButtonsByLayer(selectedLayer);
7070
deselectElement();

src/types/graphs/viewgraph.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ export class ViewGraph {
338338
});
339339
}
340340

341+
clearPacketsInTransit() {
342+
this.packetManager.clear();
343+
}
344+
341345
hasDevice(id: DeviceId) {
342346
return this.graph.hasVertex(id);
343347
}

src/types/packetManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ export class PacketManager {
2121
this.packetsInTransit.delete(packetId);
2222
}
2323

24+
/**
25+
* Deletes each packet in transit.
26+
*/
27+
clear() {
28+
const packetsInTransit = Array.from(this.packetsInTransit.values());
29+
packetsInTransit.forEach((packet) => packet.delete());
30+
}
31+
2432
// SE CAMBIA CAPA (borrar luego)
2533
// va paquete por paquete
2634
// se fija si el paquete corresponde a la nueva capa (es visible o no)

0 commit comments

Comments
 (0)