mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-21 13:45:44 +01:00
format, lint, remove unused "running" property on ws
This commit is contained in:
parent
6f36e9cdc5
commit
ef1f376c09
@ -94,11 +94,6 @@ export class WorkerScript {
|
||||
*/
|
||||
ramUsage = 0;
|
||||
|
||||
/**
|
||||
* Whether or not this workerScript is currently running
|
||||
*/
|
||||
running = false;
|
||||
|
||||
/**
|
||||
* Reference to underlying RunningScript object
|
||||
*/
|
||||
|
@ -745,7 +745,6 @@ const base: InternalAPI<NS> = {
|
||||
|
||||
helpers.log(ctx, () => `Will execute '${scriptname}' in ${spawnDelay} seconds`);
|
||||
|
||||
ctx.workerScript.running = false; // Prevent workerScript from "finishing execution naturally"
|
||||
if (killWorkerScript(ctx.workerScript)) {
|
||||
helpers.log(ctx, () => "Exiting...");
|
||||
}
|
||||
@ -820,7 +819,6 @@ const base: InternalAPI<NS> = {
|
||||
return scriptsKilled > 0;
|
||||
},
|
||||
exit: (ctx: NetscriptContext) => (): void => {
|
||||
ctx.workerScript.running = false; // Prevent workerScript from "finishing execution naturally"
|
||||
if (killWorkerScript(ctx.workerScript)) {
|
||||
helpers.log(ctx, () => "Exiting...");
|
||||
} else {
|
||||
|
@ -37,7 +37,7 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
|
||||
throw new Error("The answer provided was not a number, string, or array");
|
||||
|
||||
// Convert answer to string.
|
||||
const answerStr = typeof answer === 'string' ? answer : JSON.stringify(answer);
|
||||
const answerStr = typeof answer === "string" ? answer : JSON.stringify(answer);
|
||||
const creward = contract.reward;
|
||||
if (creward === null) throw new Error("Somehow solved a contract that didn't have a reward");
|
||||
|
||||
|
@ -235,8 +235,6 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
runAfterReset(cbScript);
|
||||
}, 0);
|
||||
|
||||
// Prevent ctx.workerScript from "finishing execution naturally"
|
||||
ctx.workerScript.running = false;
|
||||
killWorkerScript(ctx.workerScript);
|
||||
},
|
||||
installAugmentations: (ctx: NetscriptContext) =>
|
||||
@ -255,7 +253,6 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
runAfterReset(cbScript);
|
||||
}, 0);
|
||||
|
||||
ctx.workerScript.running = false; // Prevent ctx.workerScript from "finishing execution naturally"
|
||||
killWorkerScript(ctx.workerScript);
|
||||
return true;
|
||||
},
|
||||
|
@ -60,7 +60,6 @@ export function prestigeWorkerScripts(): void {
|
||||
// promises. This does said massaging and kicks the script off. It returns a promise
|
||||
// that resolves or rejects when the corresponding worker script is done.
|
||||
function startNetscript2Script(workerScript: WorkerScript): Promise<void> {
|
||||
workerScript.running = true;
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
executeJSScript(Player, workerScript.getServer().scripts, workerScript)
|
||||
.then(() => {
|
||||
@ -96,7 +95,6 @@ function startNetscript2Script(workerScript: WorkerScript): Promise<void> {
|
||||
|
||||
function startNetscript1Script(workerScript: WorkerScript): Promise<void> {
|
||||
const code = workerScript.code;
|
||||
workerScript.running = true;
|
||||
|
||||
//Process imports
|
||||
let codeWithImports, codeLineOffset;
|
||||
@ -107,7 +105,6 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<void> {
|
||||
} catch (e: unknown) {
|
||||
dialogBoxCreate("Error processing Imports in " + workerScript.name + ":<br>" + String(e));
|
||||
workerScript.env.stopFlag = true;
|
||||
workerScript.running = false;
|
||||
killWorkerScript(workerScript);
|
||||
return Promise.resolve();
|
||||
}
|
||||
@ -141,14 +138,13 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<void> {
|
||||
msg += errorMsg;
|
||||
dialogBoxCreate(msg);
|
||||
workerScript.env.stopFlag = true;
|
||||
workerScript.running = false;
|
||||
killWorkerScript(workerScript);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
int.setProperty(intLayer, name, int.createAsyncFunction(wrapper));
|
||||
} else if (Array.isArray(entry) || typeof entry !== "object"){
|
||||
} else if (Array.isArray(entry) || typeof entry !== "object") {
|
||||
// args, strings on enums, etc
|
||||
int.setProperty(intLayer, name, int.nativeToPseudo(entry));
|
||||
} else {
|
||||
@ -157,7 +153,7 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<void> {
|
||||
wrapNS1Layer(int, (intLayer as BasicObject).properties[name], [...path, name]);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let interpreter: Interpreter;
|
||||
try {
|
||||
@ -165,7 +161,6 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<void> {
|
||||
} catch (e: unknown) {
|
||||
dialogBoxCreate("Syntax ERROR in " + workerScript.name + ":<br>" + String(e));
|
||||
workerScript.env.stopFlag = true;
|
||||
workerScript.running = false;
|
||||
killWorkerScript(workerScript);
|
||||
return Promise.resolve();
|
||||
}
|
||||
@ -364,11 +359,7 @@ function processNetscript1Imports(code: string, workerScript: WorkerScript): { c
|
||||
* corresponding WorkerScript), and add the RunningScript to the server on which
|
||||
* it is active
|
||||
*/
|
||||
export function startWorkerScript(
|
||||
runningScript: RunningScript,
|
||||
server: BaseServer,
|
||||
parent?: WorkerScript,
|
||||
): number {
|
||||
export function startWorkerScript(runningScript: RunningScript, server: BaseServer, parent?: WorkerScript): number {
|
||||
if (createAndAddWorkerScript(runningScript, server, parent)) {
|
||||
// Push onto runningScripts.
|
||||
// This has to come after createAndAddWorkerScript() because that fn updates RAM usage
|
||||
@ -389,11 +380,7 @@ export function startWorkerScript(
|
||||
* @param {Server} server - Server on which the script is to be run
|
||||
* returns {boolean} indicating whether or not the workerScript was successfully added
|
||||
*/
|
||||
function createAndAddWorkerScript(
|
||||
runningScriptObj: RunningScript,
|
||||
server: BaseServer,
|
||||
parent?: WorkerScript,
|
||||
): boolean {
|
||||
function createAndAddWorkerScript(runningScriptObj: RunningScript, server: BaseServer, parent?: WorkerScript): boolean {
|
||||
// Update server's ram usage
|
||||
let threads = 1;
|
||||
if (runningScriptObj.threads && !isNaN(runningScriptObj.threads)) {
|
||||
@ -449,14 +436,11 @@ function createAndAddWorkerScript(
|
||||
// running status to false
|
||||
scriptExecution
|
||||
.then(function () {
|
||||
workerScript.running = false;
|
||||
workerScript.env.stopFlag = true;
|
||||
// On natural death, the earnings are transfered to the parent if it still exists.
|
||||
if (parent !== undefined) {
|
||||
if (parent.running) {
|
||||
parent.scriptRef.onlineExpGained += runningScriptObj.onlineExpGained;
|
||||
parent.scriptRef.onlineMoneyMade += runningScriptObj.onlineMoneyMade;
|
||||
}
|
||||
if (parent !== undefined && !parent.env.stopFlag) {
|
||||
parent.scriptRef.onlineExpGained += runningScriptObj.onlineExpGained;
|
||||
parent.scriptRef.onlineMoneyMade += runningScriptObj.onlineMoneyMade;
|
||||
}
|
||||
|
||||
killWorkerScript(workerScript);
|
||||
|
@ -15,7 +15,6 @@ import { workerScripts } from "../../Netscript/WorkerScripts";
|
||||
import { startWorkerScript } from "../../NetscriptWorker";
|
||||
import { GetServer } from "../../Server/AllServers";
|
||||
import { findRunningScript } from "../../Script/ScriptHelpers";
|
||||
import { Player } from "../../Player";
|
||||
import { debounce } from "lodash";
|
||||
import { Settings } from "../../Settings/Settings";
|
||||
import { ANSIITypography } from "./ANSIITypography";
|
||||
|
Loading…
Reference in New Issue
Block a user