Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: merge PC and Server into Host #56

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/graphics/renderables/device_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ function getTypeName(device: Device): string {
switch (device.getType()) {
case DeviceType.Router:
return "Router";
case DeviceType.Server:
return "Server";
case DeviceType.Pc:
return "PC";
case DeviceType.Host:
return "Host";
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { GlobalContext } from "./context";
// Doing this includes the file in the build
import "./style.css";
import RouterSvg from "./assets/router.svg";
import ServerSvg from "./assets/server.svg";
import ComputerSvg from "./assets/pc.svg";
import PlaySvg from "./assets/play-icon.svg";
import PauseSvg from "./assets/pause-icon.svg";
Expand All @@ -37,7 +36,6 @@ import PauseSvg from "./assets/pause-icon.svg";
const canvasPlaceholder = document.getElementById("canvas");
canvasPlaceholder.replaceWith(app.canvas);
await Assets.load(RouterSvg);
await Assets.load(ServerSvg);
await Assets.load(ComputerSvg);

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

// Add server button
// Add Host button
leftBar.addButton(
ServerSvg,
() => AddDevice(ctx, DeviceType.Server),
"Add Server",
ComputerSvg,
() => AddDevice(ctx, DeviceType.Host),
"Add Host",
);

// Add PC button
leftBar.addButton(ComputerSvg, () => AddDevice(ctx, DeviceType.Pc), "Add PC");

ctx.initialize(viewport);

// Ticker logic
Expand Down
3 changes: 1 addition & 2 deletions src/types/devices/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export enum Layer {

export enum DeviceType {
Router = 0,
Server = 1,
Pc = 2,
Host = 1,
}

export abstract class Device extends Sprite {
Expand Down
4 changes: 2 additions & 2 deletions src/types/devices/pc.ts → src/types/devices/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ViewGraph } from "../graphs/viewgraph";
import PcImage from "../../assets/pc.svg";
import { Position } from "../common";

export class Pc extends Device {
export class Host extends Device {
constructor(id: number, viewgraph: ViewGraph, position: Position) {
super(id, PcImage, viewgraph, position);
}
Expand All @@ -13,6 +13,6 @@ export class Pc extends Device {
}

getType(): DeviceType {
return DeviceType.Pc;
return DeviceType.Host;
}
}
3 changes: 1 addition & 2 deletions src/types/devices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

export { Device } from "./device";
export { Router } from "./router";
export { Server } from "./server";
export { Pc } from "./pc";
export { Host } from "./host";
export { createDevice } from "./utils";
18 changes: 0 additions & 18 deletions src/types/devices/server.ts

This file was deleted.

9 changes: 3 additions & 6 deletions src/types/devices/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ViewGraph } from "../graphs/viewgraph";
import { Device, DeviceType, Layer } from "./device";
import { Pc } from "./pc";
import { Host } from "./host";
import { Router } from "./router";
import { Server } from "./server";

export interface CreateDevice {
id: number;
Expand All @@ -21,10 +20,8 @@ export function createDevice(
switch (deviceInfo.type) {
case DeviceType.Router:
return new Router(deviceInfo.id, viewgraph, position);
case DeviceType.Server:
return new Server(deviceInfo.id, viewgraph, position);
case DeviceType.Pc:
return new Pc(deviceInfo.id, viewgraph, position);
case DeviceType.Host:
return new Host(deviceInfo.id, viewgraph, position);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/graphs/datagraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class DataGraph {
id: id,
x: info.x,
y: info.y,
type: info.type, // Save the device type (Router, Server, PC)
type: info.type, // Save the device type (Router, Host)
connections: Array.from(info.connections.values()),
});
});
Expand Down