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