From 75d2d8b7e8a57ee3c9406544cca822625a3dc757 Mon Sep 17 00:00:00 2001 From: omuretsu <84951833+Snarling@users.noreply.github.com> Date: Tue, 13 Dec 2022 09:08:23 -0500 Subject: [PATCH] Add documentation for ns.pid --- src/Netscript/Environment.ts | 4 ++-- src/Netscript/RamCostGenerator.ts | 4 ++-- src/Netscript/WorkerScript.ts | 4 ++-- src/NetscriptFunctions.ts | 11 +++-------- src/Script/ScriptModule.ts | 5 +++-- src/ScriptEditor/NetscriptDefinitions.d.ts | 3 +++ 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Netscript/Environment.ts b/src/Netscript/Environment.ts index 72a252b03..2a2443d73 100644 --- a/src/Netscript/Environment.ts +++ b/src/Netscript/Environment.ts @@ -1,4 +1,4 @@ -import { NS } from "../ScriptEditor/NetscriptDefinitions"; +import { NSFull } from "../NetscriptFunctions"; import { ExternalAPI } from "./APIWrapper"; /** @@ -14,5 +14,5 @@ export class Environment { runningFn = ""; /** Environment variables (currently only Netscript functions) */ - vars: ExternalAPI | null = null; + vars: ExternalAPI | null = null; } diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 909bf2b36..1cf529465 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -1,12 +1,12 @@ import { Player } from "@player"; import { NSFull } from "../NetscriptFunctions"; -/** This type assumes any value that isn't an API layer or a function has been omitted (args and enum) */ +/** This type assumes any value that isn't an API layer or a function has been omitted (enum) */ type RamCostTree = Omit< { [Property in keyof API]: API[Property] extends () => unknown ? number | (() => number) : RamCostTree; }, - "enums" | "args" + "enums" >; /** Constants for assigning costs to ns functions */ diff --git a/src/Netscript/WorkerScript.ts b/src/Netscript/WorkerScript.ts index 49e5931a5..ee1db7ec0 100644 --- a/src/Netscript/WorkerScript.ts +++ b/src/Netscript/WorkerScript.ts @@ -13,10 +13,10 @@ import { RunningScript } from "../Script/RunningScript"; import { Script } from "../Script/Script"; import { GetServer } from "../Server/AllServers"; import { BaseServer } from "../Server/BaseServer"; -import { NS } from "../ScriptEditor/NetscriptDefinitions"; import { ScriptDeath } from "./ScriptDeath"; import { ScriptArg } from "./ScriptArg"; import { ExternalAPI } from "./APIWrapper"; +import { NSFull } from "../NetscriptFunctions"; export class WorkerScript { /** Script's arguments */ @@ -83,7 +83,7 @@ export class WorkerScript { /** Function called when the script ends. */ atExit?: () => void; - constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => ExternalAPI) { + constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => ExternalAPI) { this.name = runningScriptObj.filename; this.hostname = runningScriptObj.server; diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 81e551cd4..25b889e19 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -91,10 +91,9 @@ export const enums: NSEnums = { LocationName, }; -export type NSFull = Readonly; +export type NSFull = Readonly>; -const base: InternalAPI = { - args: [], +export const ns: InternalAPI = { enums, singularity: NetscriptSingularity(), gang: NetscriptGang(), @@ -1898,14 +1897,10 @@ const base: InternalAPI = { } }, flags: Flags, -}; - -// add undocumented functions -export const ns = { - ...base, ...NetscriptExtra(), }; +// add undocumented functions export const wrappedNS = wrapAPILayer({} as ExternalAPI, ns, []); // Figure out once which layers of ns have functions on them and will need to be stamped with a private workerscript field for API access diff --git a/src/Script/ScriptModule.ts b/src/Script/ScriptModule.ts index 67bcd0d43..825e73772 100644 --- a/src/Script/ScriptModule.ts +++ b/src/Script/ScriptModule.ts @@ -1,7 +1,8 @@ +import { NSFull } from "../NetscriptFunctions"; import { ExternalAPI } from "../Netscript/APIWrapper"; -import { AutocompleteData, NS } from "../ScriptEditor/NetscriptDefinitions"; +import { AutocompleteData } from "../ScriptEditor/NetscriptDefinitions"; export interface ScriptModule { - main?: (ns: ExternalAPI) => unknown; + main?: (ns: ExternalAPI) => unknown; autocomplete?: (data: AutocompleteData, flags: string[]) => unknown; } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 840b35a65..82fba83a7 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -4611,6 +4611,9 @@ export interface NS { */ readonly args: (string | number | boolean)[]; + /** The current script's PID */ + readonly pid: number; + /** * Steal a server's money. * @remarks