Skip to content

Commit 8e8c677

Browse files
authored
refactor: merge PC and Server into Host (#56)
This PR merges the `Pc` and `Server` classes into a single one called `Host`
1 parent bd25698 commit 8e8c677

File tree

8 files changed

+14
-44
lines changed

8 files changed

+14
-44
lines changed

src/graphics/renderables/device_info.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ function getTypeName(device: Device): string {
7474
switch (device.getType()) {
7575
case DeviceType.Router:
7676
return "Router";
77-
case DeviceType.Server:
78-
return "Server";
79-
case DeviceType.Pc:
80-
return "PC";
77+
case DeviceType.Host:
78+
return "Host";
8179
}
8280
}
8381

src/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { GlobalContext } from "./context";
1818
// Doing this includes the file in the build
1919
import "./style.css";
2020
import RouterSvg from "./assets/router.svg";
21-
import ServerSvg from "./assets/server.svg";
2221
import ComputerSvg from "./assets/pc.svg";
2322
import PlaySvg from "./assets/play-icon.svg";
2423
import PauseSvg from "./assets/pause-icon.svg";
@@ -37,7 +36,6 @@ import PauseSvg from "./assets/pause-icon.svg";
3736
const canvasPlaceholder = document.getElementById("canvas");
3837
canvasPlaceholder.replaceWith(app.canvas);
3938
await Assets.load(RouterSvg);
40-
await Assets.load(ServerSvg);
4139
await Assets.load(ComputerSvg);
4240

4341
// Context initialization
@@ -58,16 +56,13 @@ import PauseSvg from "./assets/pause-icon.svg";
5856
"Add Router",
5957
);
6058

61-
// Add server button
59+
// Add Host button
6260
leftBar.addButton(
63-
ServerSvg,
64-
() => AddDevice(ctx, DeviceType.Server),
65-
"Add Server",
61+
ComputerSvg,
62+
() => AddDevice(ctx, DeviceType.Host),
63+
"Add Host",
6664
);
6765

68-
// Add PC button
69-
leftBar.addButton(ComputerSvg, () => AddDevice(ctx, DeviceType.Pc), "Add PC");
70-
7166
ctx.initialize(viewport);
7267

7368
// Ticker logic

src/types/devices/device.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export enum Layer {
2828

2929
export enum DeviceType {
3030
Router = 0,
31-
Server = 1,
32-
Pc = 2,
31+
Host = 1,
3332
}
3433

3534
export abstract class Device extends Sprite {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ViewGraph } from "../graphs/viewgraph";
33
import PcImage from "../../assets/pc.svg";
44
import { Position } from "../common";
55

6-
export class Pc extends Device {
6+
export class Host extends Device {
77
constructor(id: number, viewgraph: ViewGraph, position: Position) {
88
super(id, PcImage, viewgraph, position);
99
}
@@ -13,6 +13,6 @@ export class Pc extends Device {
1313
}
1414

1515
getType(): DeviceType {
16-
return DeviceType.Pc;
16+
return DeviceType.Host;
1717
}
1818
}

src/types/devices/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
export { Device } from "./device";
44
export { Router } from "./router";
5-
export { Server } from "./server";
6-
export { Pc } from "./pc";
5+
export { Host } from "./host";
76
export { createDevice } from "./utils";

src/types/devices/server.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/types/devices/utils.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { ViewGraph } from "../graphs/viewgraph";
22
import { Device, DeviceType, Layer } from "./device";
3-
import { Pc } from "./pc";
3+
import { Host } from "./host";
44
import { Router } from "./router";
5-
import { Server } from "./server";
65

76
export interface CreateDevice {
87
id: number;
@@ -21,10 +20,8 @@ export function createDevice(
2120
switch (deviceInfo.type) {
2221
case DeviceType.Router:
2322
return new Router(deviceInfo.id, viewgraph, position);
24-
case DeviceType.Server:
25-
return new Server(deviceInfo.id, viewgraph, position);
26-
case DeviceType.Pc:
27-
return new Pc(deviceInfo.id, viewgraph, position);
23+
case DeviceType.Host:
24+
return new Host(deviceInfo.id, viewgraph, position);
2825
}
2926
}
3027

src/types/graphs/datagraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class DataGraph {
5454
id: id,
5555
x: info.x,
5656
y: info.y,
57-
type: info.type, // Save the device type (Router, Server, PC)
57+
type: info.type, // Save the device type (Router, Host)
5858
connections: Array.from(info.connections.values()),
5959
});
6060
});

0 commit comments

Comments
 (0)