From 8903cd2a8b20ec43533b0cbbe72dfa985d730154 Mon Sep 17 00:00:00 2001 From: Undeemiss Date: Tue, 17 May 2022 15:19:35 -0500 Subject: [PATCH] Removed closePid(fn, host, ...args) and fixed closePid(pid) --- src/NetscriptFunctions.ts | 33 +++++---------------------------- src/ui/React/LogBoxManager.tsx | 28 +++++++++++++++++----------- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index df6016d45..367eb7bcf 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -987,37 +987,14 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { LogBoxEvents.emit(runningScriptObj); }, - closeTail: function (fn: any, hostname: any = workerScript.hostname, ...scriptArgs: any[]): void { + closeTail: function (pid?: number): void { updateDynamicRam("closeTail", getRamCost(Player, "closeTail")); - //Get the script details - let server; - let filename; - let args; - if (arguments.length === 0) { - //Get the details from the script calling the function - const runningScriptObj = workerScript.scriptRef; - server = runningScriptObj.server; - filename = runningScriptObj.filename; - args = runningScriptObj.args; - } else if (typeof fn === "number") { - //Get the details via the pid of a running script - const runningScriptObj = getRunningScriptByPid(fn, "tail"); - if (runningScriptObj == null) { - workerScript.log("closeTail", () => getCannotFindRunningScriptErrorMessage(`${fn}`, hostname, scriptArgs)); - return; - } - server = runningScriptObj.server; - filename = runningScriptObj.filename; - args = runningScriptObj.args; - } else { - //Get the details from the input directly - server = hostname; - filename = fn; - args = scriptArgs; + //Get the pid of the calling script if no pid is given + if (pid === undefined) { + pid = workerScript.scriptRef.pid; } - //Emit an event to tell the game to close the tail window if it exists - LogBoxCloserEvents.emit(server, filename, args.map((x: any): string => `${x}`)); + LogBoxCloserEvents.emit(pid); }, nuke: function (_hostname: unknown): boolean { updateDynamicRam("nuke", getRamCost(Player, "nuke")); diff --git a/src/ui/React/LogBoxManager.tsx b/src/ui/React/LogBoxManager.tsx index 514d06e38..eeec501fe 100644 --- a/src/ui/React/LogBoxManager.tsx +++ b/src/ui/React/LogBoxManager.tsx @@ -23,7 +23,7 @@ import { Settings } from "../../Settings/Settings"; let layerCounter = 0; export const LogBoxEvents = new EventEmitter<[RunningScript]>(); -export const LogBoxCloserEvents = new EventEmitter<[any, any, any[]]>(); +export const LogBoxCloserEvents = new EventEmitter<[number]>(); export const LogBoxClearEvents = new EventEmitter<[]>(); interface Log { @@ -55,9 +55,8 @@ export function LogBoxManager(): React.ReactElement { //Event used by ns.closeTail to close tail windows useEffect( () => - LogBoxCloserEvents.subscribe((hostname: any, filename: any, stringArgs: any[]) => { - const id = hostname + "-" + filename + stringArgs.map((x: any): string => `${x}`).join("-"); - close(id); + LogBoxCloserEvents.subscribe((pid: number) => { + closePid(pid); }), [], ); @@ -69,11 +68,18 @@ export function LogBoxManager(): React.ReactElement { }), ); + //Close tail windows by their id function close(id: string): void { logs = logs.filter((l) => l.id !== id); rerender(); } + //Close tail windows by their pid + function closePid(pid: number): void { + logs = logs.filter((log) => log.script.pid != pid); + rerender(); + } + return ( <> {logs.map((log) => ( @@ -249,14 +255,14 @@ function LogWindow(props: IProps): React.ReactElement { minHeight: `${minConstraints[1]}px`, ...(minimized ? { - border: "none", - margin: 0, - maxHeight: 0, - padding: 0, - } + border: "none", + margin: 0, + maxHeight: 0, + padding: 0, + } : { - border: `1px solid ${Settings.theme.welllight}`, - }), + border: `1px solid ${Settings.theme.welllight}`, + }), }} ref={container} >