mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-23 22:52:29 +01:00
Removed closePid(fn, host, ...args) and fixed closePid(pid)
This commit is contained in:
parent
e17fe6f618
commit
8903cd2a8b
@ -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"));
|
||||
|
@ -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}
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user