mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-21 00:32:51 +02:00
NETSCRIPT: Add "temporary" as a RunOption to run/exec/spawn (#432)
This commit is contained in:
@@ -6,7 +6,7 @@ import { ScriptDeath } from "./ScriptDeath";
|
||||
import { formatExp, formatMoney, formatRam, formatThreads } from "../ui/formatNumber";
|
||||
import { ScriptArg } from "./ScriptArg";
|
||||
import { CityName } from "../Enums";
|
||||
import { BasicHGWOptions, RunningScript as IRunningScript, Person as IPerson } from "@nsdefs";
|
||||
import { BasicHGWOptions, RunOptions, RunningScript as IRunningScript, Person as IPerson } from "@nsdefs";
|
||||
import { Server } from "../Server/Server";
|
||||
import {
|
||||
calculateHackingChance,
|
||||
@@ -41,6 +41,7 @@ export const helpers = {
|
||||
number,
|
||||
positiveInteger,
|
||||
scriptArgs,
|
||||
runOptions,
|
||||
argsToString,
|
||||
makeBasicErrorMsg,
|
||||
makeRuntimeErrorMsg,
|
||||
@@ -67,6 +68,12 @@ export const helpers = {
|
||||
failOnHacknetServer,
|
||||
};
|
||||
|
||||
// RunOptions with non-optional, type-validated members, for passing between internal functions.
|
||||
export interface CompleteRunOptions {
|
||||
threads: PositiveInteger;
|
||||
temporary: boolean;
|
||||
}
|
||||
|
||||
export function assertMember<T extends string>(
|
||||
ctx: NetscriptContext,
|
||||
obj: Record<string, T> | T[],
|
||||
@@ -174,6 +181,23 @@ function scriptArgs(ctx: NetscriptContext, args: unknown) {
|
||||
return args;
|
||||
}
|
||||
|
||||
function runOptions(ctx: NetscriptContext, thread_or_opt: unknown): CompleteRunOptions {
|
||||
let threads: any = 1;
|
||||
let temporary: any = false;
|
||||
if (typeof thread_or_opt !== "object" || thread_or_opt === null) {
|
||||
threads = thread_or_opt ?? 1;
|
||||
} else {
|
||||
// Lie and pretend it's a RunOptions. It could be anything, we'll deal with that below.
|
||||
const options = thread_or_opt as RunOptions;
|
||||
threads = options.threads ?? 1;
|
||||
temporary = options.temporary ?? false;
|
||||
}
|
||||
return {
|
||||
threads: positiveInteger(ctx, "thread", threads),
|
||||
temporary: !!temporary,
|
||||
};
|
||||
}
|
||||
|
||||
/** Convert multiple arguments for tprint or print into a single string. */
|
||||
function argsToString(args: unknown[]): string {
|
||||
let out = "";
|
||||
@@ -718,6 +742,7 @@ function createPublicRunningScript(runningScript: RunningScript): IRunningScript
|
||||
ramUsage: runningScript.ramUsage,
|
||||
server: runningScript.server,
|
||||
threads: runningScript.threads,
|
||||
temporary: runningScript.temporary,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user