From 52e01fc0269596bf58ebee02493cfd49d485f6db Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Tue, 12 Apr 2022 14:45:48 -0400 Subject: [PATCH] fix a few things about getRecentScritps --- src/Netscript/RamCostGenerator.ts | 3 ++- src/Netscript/RecentScripts.ts | 14 +++----------- src/NetscriptFunctions.ts | 5 ++++- src/ScriptEditor/NetscriptDefinitions.d.ts | 14 ++------------ src/ui/ActiveScripts/RecentScriptAccordion.tsx | 6 +++--- src/ui/ActiveScripts/RecentScriptsPage.tsx | 2 +- src/ui/React/GameOptionsRoot.tsx | 2 +- 7 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index c56ed1018..4e7733807 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -15,6 +15,7 @@ export const RamCostConstants: IMap = { ScriptWeakenRamCost: 0.15, ScriptWeakenAnalyzeRamCost: 1, ScriptScanRamCost: 0.2, + ScriptRecentScriptsRamCost: 0.2, ScriptPortProgramRamCost: 0.05, ScriptRunRamCost: 1.0, ScriptExecRamCost: 1.3, @@ -140,7 +141,7 @@ export const RamCosts: IMap = { scp: RamCostConstants.ScriptScpRamCost, ls: RamCostConstants.ScriptScanRamCost, ps: RamCostConstants.ScriptScanRamCost, - getRecentScripts: RamCostConstants.ScriptScanRamCost, + getRecentScripts: RamCostConstants.ScriptRecentScriptsRamCost, hasRootAccess: RamCostConstants.ScriptHasRootAccessRamCost, getIp: RamCostConstants.ScriptGetHostnameRamCost, getHostname: RamCostConstants.ScriptGetHostnameRamCost, diff --git a/src/Netscript/RecentScripts.ts b/src/Netscript/RecentScripts.ts index d2f4ef04a..ded6f8856 100644 --- a/src/Netscript/RecentScripts.ts +++ b/src/Netscript/RecentScripts.ts @@ -5,15 +5,11 @@ import { WorkerScript } from "./WorkerScript"; export const recentScripts: RecentScript[] = []; export function AddRecentScript(workerScript: WorkerScript): void { - if (recentScripts.find((r) => r.pid === workerScript.pid)) return; + if (recentScripts.find((r) => r.runningScript.pid === workerScript.pid)) return; const killedTime = new Date(); recentScripts.unshift({ - filename: workerScript.name, - args: workerScript.args, - pid: workerScript.pid, - timestamp: killedTime, - timestampEpoch: killedTime.getTime(), + timeOfDeath: killedTime, runningScript: workerScript.scriptRef, }); @@ -23,10 +19,6 @@ export function AddRecentScript(workerScript: WorkerScript): void { } export interface RecentScript { - filename: string; - args: string[]; - pid: number; - timestamp: Date; - timestampEpoch: number; + timeOfDeath: Date; runningScript: RunningScript; } diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index c110368e4..359aca3e0 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -1462,7 +1462,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { }, getRecentScripts: function (): IRecentScript[] { updateDynamicRam("getRecentScripts", getRamCost(Player, "getRecentScripts")); - return recentScripts.map((rs) => ({ ...rs, runningScript: createPublicRunningScript(rs.runningScript) })); + return recentScripts.map((rs) => ({ + timeOfDeath: rs.timeOfDeath, + ...createPublicRunningScript(rs.runningScript), + })); }, ps: function (_hostname: unknown = workerScript.hostname): ProcessInfo[] { updateDynamicRam("ps", getRamCost(Player, "ps")); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 64e5d8ddf..bb2124641 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -136,19 +136,9 @@ export interface RunningScript { /** * @public */ -interface RecentScript { - /** Arguments the script was called with */ - args: string[]; - /** Filename of the script */ - filename: string; - /** Process ID. Must be an integer */ - pid: number; +export interface RecentScript extends RunningScript { /** Timestamp of when the script was killed */ - timestamp: Date; - /** Numeric epoch of timestamp */ - timestampEpoch: number; - /** An inactive copy of the last `RunningScript` associated to the script */ - runningScript: RunningScript; + timeOfDeath: Date; } /** diff --git a/src/ui/ActiveScripts/RecentScriptAccordion.tsx b/src/ui/ActiveScripts/RecentScriptAccordion.tsx index 49e687540..e303ca2d6 100644 --- a/src/ui/ActiveScripts/RecentScriptAccordion.tsx +++ b/src/ui/ActiveScripts/RecentScriptAccordion.tsx @@ -57,8 +57,8 @@ export function RecentScriptAccordion(props: IProps): React.ReactElement { - └ {recentScript.filename} (died{" "} - {convertTimeMsToTimeElapsedString(new Date().getTime() - recentScript.timestamp.getTime())} ago) + └ {recentScript.runningScript.filename} (died{" "} + {convertTimeMsToTimeElapsedString(new Date().getTime() - recentScript.timeOfDeath.getTime())} ago) } /> @@ -78,7 +78,7 @@ export function RecentScriptAccordion(props: IProps): React.ReactElement { - └ Args: {arrayToString(recentScript.args)} + └ Args: {arrayToString(recentScript.runningScript.args)} diff --git a/src/ui/ActiveScripts/RecentScriptsPage.tsx b/src/ui/ActiveScripts/RecentScriptsPage.tsx index 46d04c5f9..9c598a61e 100644 --- a/src/ui/ActiveScripts/RecentScriptsPage.tsx +++ b/src/ui/ActiveScripts/RecentScriptsPage.tsx @@ -13,7 +13,7 @@ export function RecentScriptsPage(): React.ReactElement { <> List of all recently killed scripts. {recentScripts.map((r) => ( - + ))} ); diff --git a/src/ui/React/GameOptionsRoot.tsx b/src/ui/React/GameOptionsRoot.tsx index d717aeeb2..364ccae00 100644 --- a/src/ui/React/GameOptionsRoot.tsx +++ b/src/ui/React/GameOptionsRoot.tsx @@ -196,7 +196,7 @@ export function GameOptionsRoot(props: IProps): React.ReactElement { value={recentScriptsSize} onChange={handleRecentScriptsSizeChange} step={25} - min={25} + min={0} max={500} valueLabelDisplay="auto" />