Merge pull request #2542 from daanflore/dev

NetscriptDefinition.d.ts correcting based on code
This commit is contained in:
hydroflame 2022-01-11 11:15:35 -05:00 committed by GitHub
commit 7207e6db11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

@ -1901,7 +1901,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
const iport = helper.getValidPort("clearPort", port);
return iport.clear();
},
getPortHandle: function (port: any): any {
getPortHandle: function (port: any): IPort {
updateDynamicRam("getPortHandle", getRamCost(Player, "getPortHandle"));
const iport = helper.getValidPort("getPortHandle", port);
return iport;

@ -109,6 +109,32 @@ interface RunningScript {
threads: number;
}
/**
* Interface of a netscript port
* @public
*/
export interface IPort {
/** write data to the port and removes and returns first element if full */
write: (value: any) => any;
/** add data to port if not full.
* @returns true if added and false if full and not added */
tryWrite: (value: any) => boolean;
/** reads and removes first element from port
* if no data in port returns "NULL PORT DATA"
*/
read: () => any;
/** reads first element without removing it from port
* if no data in port returns "NULL PORT DATA"
*/
peek: () => any;
/** check if port is full */
full: () => boolean;
/** check if port is empty */
empty: () => boolean;
/** removes all data from port */
clear: () => void;
}
/**
* Data representing the internal values of a crime.
* @public
@ -5409,7 +5435,7 @@ export interface NS extends Singularity {
* @param port - Port number. Must be an integer between 1 and 20.
* @returns Data in the specified port.
*/
getPortHandle(port: number): any[];
getPortHandle(port: number): IPort;
/**
* Delete a file.