From ef1f376c092f70225bf5926d1903cc317a077c82 Mon Sep 17 00:00:00 2001 From: Snarling <84951833+Snarling@users.noreply.github.com> Date: Sat, 27 Aug 2022 22:32:48 -0400 Subject: [PATCH] format, lint, remove unused "running" property on ws --- src/Netscript/WorkerScript.ts | 5 ---- src/NetscriptFunctions.ts | 2 -- src/NetscriptFunctions/CodingContract.ts | 2 +- src/NetscriptFunctions/Singularity.ts | 3 --- src/NetscriptWorker.ts | 30 ++++++------------------ src/ui/React/LogBoxManager.tsx | 1 - 6 files changed, 8 insertions(+), 35 deletions(-) diff --git a/src/Netscript/WorkerScript.ts b/src/Netscript/WorkerScript.ts index c8c9515d3..3ef23d884 100644 --- a/src/Netscript/WorkerScript.ts +++ b/src/Netscript/WorkerScript.ts @@ -94,11 +94,6 @@ export class WorkerScript { */ ramUsage = 0; - /** - * Whether or not this workerScript is currently running - */ - running = false; - /** * Reference to underlying RunningScript object */ diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index df0c3532d..e9ab76745 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -745,7 +745,6 @@ const base: InternalAPI = { 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 = { 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 { diff --git a/src/NetscriptFunctions/CodingContract.ts b/src/NetscriptFunctions/CodingContract.ts index 93cd1b7b2..a95dbe0ec 100644 --- a/src/NetscriptFunctions/CodingContract.ts +++ b/src/NetscriptFunctions/CodingContract.ts @@ -37,7 +37,7 @@ export function NetscriptCodingContract(): InternalAPI { 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"); diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index c24bdd077..82ef6e3b2 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -235,8 +235,6 @@ export function NetscriptSingularity(): InternalAPI { 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 { runAfterReset(cbScript); }, 0); - ctx.workerScript.running = false; // Prevent ctx.workerScript from "finishing execution naturally" killWorkerScript(ctx.workerScript); return true; }, diff --git a/src/NetscriptWorker.ts b/src/NetscriptWorker.ts index 31a45fc48..6dc79dd0c 100644 --- a/src/NetscriptWorker.ts +++ b/src/NetscriptWorker.ts @@ -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 { - workerScript.running = true; return new Promise((resolve, reject) => { executeJSScript(Player, workerScript.getServer().scripts, workerScript) .then(() => { @@ -96,7 +95,6 @@ function startNetscript2Script(workerScript: WorkerScript): Promise { function startNetscript1Script(workerScript: WorkerScript): Promise { const code = workerScript.code; - workerScript.running = true; //Process imports let codeWithImports, codeLineOffset; @@ -107,7 +105,6 @@ function startNetscript1Script(workerScript: WorkerScript): Promise { } catch (e: unknown) { dialogBoxCreate("Error processing Imports in " + workerScript.name + ":
" + String(e)); workerScript.env.stopFlag = true; - workerScript.running = false; killWorkerScript(workerScript); return Promise.resolve(); } @@ -141,14 +138,13 @@ function startNetscript1Script(workerScript: WorkerScript): Promise { 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 { wrapNS1Layer(int, (intLayer as BasicObject).properties[name], [...path, name]); } } - }; + } let interpreter: Interpreter; try { @@ -165,7 +161,6 @@ function startNetscript1Script(workerScript: WorkerScript): Promise { } catch (e: unknown) { dialogBoxCreate("Syntax ERROR in " + workerScript.name + ":
" + 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); diff --git a/src/ui/React/LogBoxManager.tsx b/src/ui/React/LogBoxManager.tsx index 9a246c584..a9a2e6479 100644 --- a/src/ui/React/LogBoxManager.tsx +++ b/src/ui/React/LogBoxManager.tsx @@ -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";