Converting random pieces of code to ts

This commit is contained in:
Olivier Gagnon
2021-03-14 01:08:24 -05:00
parent 642c7a107a
commit 6c0b5b3ed9
21 changed files with 198 additions and 688 deletions
+51
View File
@@ -0,0 +1,51 @@
import { Settings } from "./Settings/Settings";
export class NetscriptPort {
data: any[] = [];
constructor() {}
write(data: any): any {
this.data.push(data);
if (this.data.length > Settings.MaxPortCapacity) {
return this.data.shift();
}
return null;
}
tryWrite(data: any): boolean {
if (this.data.length >= Settings.MaxPortCapacity) {
return false;
}
this.data.push(data);
return true;
}
read(): any {
if (this.data.length === 0) {
return "NULL PORT DATA";
}
return this.data.shift();
}
peek(): any {
if (this.data.length === 0) {
return "NULL PORT DATA";
} else {
var foo = this.data.slice();
return foo[0];
}
}
full(): boolean {
return this.data.length == Settings.MaxPortCapacity;
}
empty(): boolean {
return this.data.length === 0;
}
clear(): void {
this.data.length = 0;
}
}