mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-20 13:15:48 +01:00
Merge pull request #3666 from Undeemiss/ns-close-tail
MISC: Added NS function closeTail to close tail windows
This commit is contained in:
commit
71f24e3077
@ -55,7 +55,7 @@ import { makeRuntimeRejectMsg, netscriptDelay, resolveNetscriptRequestedThreads
|
|||||||
import { numeralWrapper } from "./ui/numeralFormat";
|
import { numeralWrapper } from "./ui/numeralFormat";
|
||||||
import { convertTimeMsToTimeElapsedString } from "./utils/StringHelperFunctions";
|
import { convertTimeMsToTimeElapsedString } from "./utils/StringHelperFunctions";
|
||||||
|
|
||||||
import { LogBoxEvents } from "./ui/React/LogBoxManager";
|
import { LogBoxEvents, LogBoxCloserEvents } from "./ui/React/LogBoxManager";
|
||||||
import { arrayToString } from "./utils/helpers/arrayToString";
|
import { arrayToString } from "./utils/helpers/arrayToString";
|
||||||
import { isString } from "./utils/helpers/isString";
|
import { isString } from "./utils/helpers/isString";
|
||||||
|
|
||||||
@ -988,6 +988,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
|
|
||||||
LogBoxEvents.emit(runningScriptObj);
|
LogBoxEvents.emit(runningScriptObj);
|
||||||
},
|
},
|
||||||
|
closeTail: function (_pid: unknown = workerScript.scriptRef.pid): void {
|
||||||
|
updateDynamicRam("closeTail", getRamCost(Player, "closeTail"));
|
||||||
|
const pid = helper.number("closeTail", "pid", _pid);
|
||||||
|
//Emit an event to tell the game to close the tail window if it exists
|
||||||
|
LogBoxCloserEvents.emit(pid);
|
||||||
|
},
|
||||||
nuke: function (_hostname: unknown): boolean {
|
nuke: function (_hostname: unknown): boolean {
|
||||||
updateDynamicRam("nuke", getRamCost(Player, "nuke"));
|
updateDynamicRam("nuke", getRamCost(Player, "nuke"));
|
||||||
const hostname = helper.string("tail", "hostname", _hostname);
|
const hostname = helper.string("tail", "hostname", _hostname);
|
||||||
|
15
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
15
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -4981,6 +4981,21 @@ export interface NS {
|
|||||||
*/
|
*/
|
||||||
tail(fn?: FilenameOrPID, host?: string, ...args: any[]): void;
|
tail(fn?: FilenameOrPID, host?: string, ...args: any[]): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the tail window of a script.
|
||||||
|
* @remarks
|
||||||
|
* RAM cost: 0 GB
|
||||||
|
*
|
||||||
|
* Closes a script’s logs. This is functionally the same pressing the "Close" button on the tail window.
|
||||||
|
*
|
||||||
|
* If the function is called with no arguments, it will close the current script’s logs.
|
||||||
|
*
|
||||||
|
* Otherwise, the pid argument can be used to close the logs from another script.
|
||||||
|
*
|
||||||
|
* @param pid - Optional. PID of the script having its tail closed. If omitted, the current script is used.
|
||||||
|
*/
|
||||||
|
closeTail(pid?: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of servers connected to a server.
|
* Get the list of servers connected to a server.
|
||||||
* @remarks
|
* @remarks
|
||||||
|
@ -23,6 +23,7 @@ import { Settings } from "../../Settings/Settings";
|
|||||||
let layerCounter = 0;
|
let layerCounter = 0;
|
||||||
|
|
||||||
export const LogBoxEvents = new EventEmitter<[RunningScript]>();
|
export const LogBoxEvents = new EventEmitter<[RunningScript]>();
|
||||||
|
export const LogBoxCloserEvents = new EventEmitter<[number]>();
|
||||||
export const LogBoxClearEvents = new EventEmitter<[]>();
|
export const LogBoxClearEvents = new EventEmitter<[]>();
|
||||||
|
|
||||||
interface Log {
|
interface Log {
|
||||||
@ -51,6 +52,15 @@ export function LogBoxManager(): React.ReactElement {
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//Event used by ns.closeTail to close tail windows
|
||||||
|
useEffect(
|
||||||
|
() =>
|
||||||
|
LogBoxCloserEvents.subscribe((pid: number) => {
|
||||||
|
closePid(pid);
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
LogBoxClearEvents.subscribe(() => {
|
LogBoxClearEvents.subscribe(() => {
|
||||||
logs = [];
|
logs = [];
|
||||||
@ -58,11 +68,18 @@ export function LogBoxManager(): React.ReactElement {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//Close tail windows by their id
|
||||||
function close(id: string): void {
|
function close(id: string): void {
|
||||||
logs = logs.filter((l) => l.id !== id);
|
logs = logs.filter((l) => l.id !== id);
|
||||||
rerender();
|
rerender();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Close tail windows by their pid
|
||||||
|
function closePid(pid: number): void {
|
||||||
|
logs = logs.filter((log) => log.script.pid != pid);
|
||||||
|
rerender();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{logs.map((log) => (
|
{logs.map((log) => (
|
||||||
|
Loading…
Reference in New Issue
Block a user