mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-20 13:15:48 +01:00
fix args not beign passed to scripts
This commit is contained in:
parent
28b9c821d2
commit
e0a24cf381
@ -122,29 +122,24 @@ export function wrapAPI(
|
||||
helpers: INetscriptHelper,
|
||||
wrappedAPI: ExternalAPI,
|
||||
workerScript: WorkerScript,
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
namespace: object,
|
||||
...tree: string[]
|
||||
): WrappedNetscriptAPI {
|
||||
if (typeof namespace !== "object") throw new Error("Invalid namespace?");
|
||||
for (const [key, value] of Object.entries(namespace)) {
|
||||
switch (typeof value) {
|
||||
case "function": {
|
||||
wrapFunction(helpers, wrappedAPI, workerScript, value, ...tree, key);
|
||||
break;
|
||||
}
|
||||
case "object": {
|
||||
wrapAPI(helpers, wrappedAPI, workerScript, value, ...tree, key);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
setNestedProperty(wrappedAPI, value, ...tree, key);
|
||||
}
|
||||
if (typeof value === "function") {
|
||||
wrapFunction(helpers, wrappedAPI, workerScript, value, ...tree, key);
|
||||
} else if (Array.isArray(value)) {
|
||||
setNestedProperty(wrappedAPI, value, key);
|
||||
} else if (typeof value === "object") {
|
||||
wrapAPI(helpers, wrappedAPI, workerScript, value, ...tree, key);
|
||||
} else {
|
||||
setNestedProperty(wrappedAPI, value, ...tree, key);
|
||||
}
|
||||
}
|
||||
return wrappedAPI;
|
||||
}
|
||||
|
||||
// TODO: This doesn't even work properly.
|
||||
function setNestedProperty(root: object, value: unknown, ...tree: string[]): void {
|
||||
let target = root;
|
||||
const key = tree.pop();
|
||||
|
@ -2596,5 +2596,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const possibleLogs = Object.fromEntries([...getFunctionNames(ns, "")].map((a) => [a, true]));
|
||||
|
||||
const wrappedNS = wrapAPI(helper, {}, workerScript, ns) as unknown as INS;
|
||||
(wrappedNS as any).args = ns.args;
|
||||
(wrappedNS as any).enums = ns.enums;
|
||||
return wrappedNS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user