From 24b4cd7c1c91b3f1468fea1cc85b5796307c14a2 Mon Sep 17 00:00:00 2001 From: CatLover <152669316+catloversg@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:16:40 +0700 Subject: [PATCH] API: Add ns.renderTail --- markdown/bitburner.ns.md | 1 + markdown/bitburner.ns.rendertail.md | 30 ++++++++++++++++++++++ src/Netscript/RamCostGenerator.ts | 1 + src/NetscriptFunctions.ts | 11 ++++++++ src/ScriptEditor/NetscriptDefinitions.d.ts | 13 ++++++++++ 5 files changed, 56 insertions(+) create mode 100644 markdown/bitburner.ns.rendertail.md diff --git a/markdown/bitburner.ns.md b/markdown/bitburner.ns.md index b0fe3cc365..1dc8fb22e4 100644 --- a/markdown/bitburner.ns.md +++ b/markdown/bitburner.ns.md @@ -148,6 +148,7 @@ export async function main(ns) { | [readPort(portNumber)](./bitburner.ns.readport.md) | Read data from a port. | | [relaysmtp(host)](./bitburner.ns.relaysmtp.md) | Runs relaySMTP.exe on a server. | | [renamePurchasedServer(hostname, newName)](./bitburner.ns.renamepurchasedserver.md) | Rename a purchased server. | +| [renderTail(pid)](./bitburner.ns.rendertail.md) | Render a tail window. | | [resizeTail(width, height, pid)](./bitburner.ns.resizetail.md) | Resize a tail window. | | [rm(name, host)](./bitburner.ns.rm.md) | Delete a file. | | [run(script, threadOrOptions, args)](./bitburner.ns.run.md) | Start another script on the current server. | diff --git a/markdown/bitburner.ns.rendertail.md b/markdown/bitburner.ns.rendertail.md new file mode 100644 index 0000000000..8aa9430a22 --- /dev/null +++ b/markdown/bitburner.ns.rendertail.md @@ -0,0 +1,30 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [renderTail](./bitburner.ns.rendertail.md) + +## NS.renderTail() method + +Render a tail window. + +**Signature:** + +```typescript +renderTail(pid?: number): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| pid | number | _(Optional)_ Optional. PID of the script having its tail rendered. If omitted, the current script is used. | + +**Returns:** + +void + +## Remarks + +RAM cost: 0 GB + +Tail windows are rendered at an interval defined in game settings. This function renders the tail window of the specified script immediately. + diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 05fe899b2c..71cee6c9c2 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -598,6 +598,7 @@ export const RamCosts: RamCostTree = { tail: 0, toast: 0, moveTail: 0, + renderTail: 0, resizeTail: 0, closeTail: 0, setTitle: 0, diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index ce1fc8c6bb..ba15647f33 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -568,6 +568,17 @@ export const ns: InternalAPI = { LogBoxEvents.emit(runningScriptObj); }, + renderTail: + (ctx) => + (_pid = ctx.workerScript.scriptRef.pid) => { + const pid = helpers.number(ctx, "pid", _pid); + const runningScriptObj = helpers.getRunningScript(ctx, pid); + if (runningScriptObj == null) { + helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid)); + return; + } + runningScriptObj.tailProps?.rerender(); + }, moveTail: (ctx) => (_x, _y, _pid = ctx.workerScript.scriptRef.pid) => { diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index b49a1e4603..93e5f94f22 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6374,6 +6374,19 @@ export interface NS { */ tail(fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void; + /** + * Render a tail window. + * + * @remarks + * RAM cost: 0 GB + * + * Tail windows are rendered at an interval defined in game settings. This function renders the tail window of the + * specified script immediately. + * + * @param pid - Optional. PID of the script having its tail rendered. If omitted, the current script is used. + */ + renderTail(pid?: number): void; + /** * Move a tail window. * @remarks