mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 20:25:45 +01:00
Add documentation for ns.pid
This commit is contained in:
parent
52034ccedc
commit
75d2d8b7e8
@ -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<NS> | null = null;
|
||||
vars: ExternalAPI<NSFull> | null = null;
|
||||
}
|
||||
|
@ -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<API> = Omit<
|
||||
{
|
||||
[Property in keyof API]: API[Property] extends () => unknown ? number | (() => number) : RamCostTree<API[Property]>;
|
||||
},
|
||||
"enums" | "args"
|
||||
"enums"
|
||||
>;
|
||||
|
||||
/** Constants for assigning costs to ns functions */
|
||||
|
@ -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<NS>) {
|
||||
constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => ExternalAPI<NSFull>) {
|
||||
this.name = runningScriptObj.filename;
|
||||
this.hostname = runningScriptObj.server;
|
||||
|
||||
|
@ -91,10 +91,9 @@ export const enums: NSEnums = {
|
||||
LocationName,
|
||||
};
|
||||
|
||||
export type NSFull = Readonly<NS & INetscriptExtra>;
|
||||
export type NSFull = Readonly<Omit<NS & INetscriptExtra, "pid" | "args">>;
|
||||
|
||||
const base: InternalAPI<NS> = {
|
||||
args: [],
|
||||
export const ns: InternalAPI<NSFull> = {
|
||||
enums,
|
||||
singularity: NetscriptSingularity(),
|
||||
gang: NetscriptGang(),
|
||||
@ -1898,14 +1897,10 @@ const base: InternalAPI<NS> = {
|
||||
}
|
||||
},
|
||||
flags: Flags,
|
||||
};
|
||||
|
||||
// add undocumented functions
|
||||
export const ns = {
|
||||
...base,
|
||||
...NetscriptExtra(),
|
||||
};
|
||||
|
||||
// add undocumented functions
|
||||
export const wrappedNS = wrapAPILayer({} as ExternalAPI<NSFull>, 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
|
||||
|
@ -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<NS>) => unknown;
|
||||
main?: (ns: ExternalAPI<NSFull>) => unknown;
|
||||
autocomplete?: (data: AutocompleteData, flags: string[]) => unknown;
|
||||
}
|
||||
|
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user