Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NETSCRIPT: Added changing tail font size through scripts #1852

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions markdown/bitburner.ns.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export async function main(ns) {
| [scriptRunning(script, host)](./bitburner.ns.scriptrunning.md) | Check if any script with a filename is running. |
| [self()](./bitburner.ns.self.md) | Returns the currently running script. |
| [serverExists(host)](./bitburner.ns.serverexists.md) | Returns a boolean denoting whether or not the specified server exists. |
| [setTailFontSize(pixel, pid)](./bitburner.ns.settailfontsize.md) | Set the font size of the tail window of a script. |
| [setTitle(title, pid)](./bitburner.ns.settitle.md) | Set the title of the tail window of a script. |
| [share()](./bitburner.ns.share.md) | Share the server's ram with your factions. |
| [sleep(millis)](./bitburner.ns.sleep.md) | Suspends the script for n milliseconds. |
Expand Down
37 changes: 37 additions & 0 deletions markdown/bitburner.ns.settailfontsize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [NS](./bitburner.ns.md) &gt; [setTailFontSize](./bitburner.ns.settailfontsize.md)

## NS.setTailFontSize() method

Set the font size of the tail window of a script.

**Signature:**

```typescript
setTailFontSize(pixel?: number, pid?: number): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| pixel | number | _(Optional)_ Optional. The new font size in pixels. If omitted, the default tail font size is used. |
| pid | number | _(Optional)_ Optional. PID of the script having its tail closed. If omitted, the current script is used. |

**Returns:**

void

## Remarks

RAM cost: 0 GB

This overwrites the tail font size and forces an update of the tail window's contents.

The font size is saved across restarts.

If the pid is unspecified, it will modify the current script's logs.

Otherwise, the pid argument can be used to change the logs from another script.

13 changes: 13 additions & 0 deletions markdown/bitburner.runningscript.fontsize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [RunningScript](./bitburner.runningscript.md) &gt; [fontSize](./bitburner.runningscript.fontsize.md)

## RunningScript.fontSize property

The font size of the tail window. Defaults to the font size set in the style editor.

**Signature:**

```typescript
fontSize: number;
```
1 change: 1 addition & 0 deletions markdown/bitburner.runningscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface RunningScript
| [args](./bitburner.runningscript.args.md) | | [ScriptArg](./bitburner.scriptarg.md)<!-- -->\[\] | Arguments the script was called with |
| [dynamicRamUsage](./bitburner.runningscript.dynamicramusage.md) | | number \| undefined | <p>The dynamic RAM usage of (one thread of) this script instance. Does not affect overall RAM consumption (ramUsage is for that), but rather shows how much of the reserved RAM is currently in use via all the ns functions the script has called. Initially 1.6GB, this increases as new functions are called.</p><p>Only set for scripts that are still running.</p> |
| [filename](./bitburner.runningscript.filename.md) | | string | Filename of the script |
| [fontSize](./bitburner.runningscript.fontsize.md) | | number | The font size of the tail window. Defaults to the font size set in the style editor. |
| [logs](./bitburner.runningscript.logs.md) | | string\[\] | Script logs as an array. The newest log entries are at the bottom. Timestamps, if enabled, are placed inside <code>[brackets]</code> at the start of each line. |
| [offlineExpGained](./bitburner.runningscript.offlineexpgained.md) | | number | Total amount of hacking experience earned from this script when offline |
| [offlineMoneyMade](./bitburner.runningscript.offlinemoneymade.md) | | number | Total amount of money made by this script when offline |
Expand Down
1 change: 1 addition & 0 deletions src/Netscript/NetscriptHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ function createPublicRunningScript(runningScript: RunningScript, workerScript?:
height: logProps.height,
},
title: runningScript.title,
fontSize: runningScript.fontSize,
threads: runningScript.threads,
temporary: runningScript.temporary,
};
Expand Down
1 change: 1 addition & 0 deletions src/Netscript/RamCostGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ export const RamCosts: RamCostTree<NSFull> = {
resizeTail: 0,
closeTail: 0,
setTitle: 0,
setTailFontSize: 0,
clearPort: 0,
openDevMenu: 0,
alert: 0,
Expand Down
14 changes: 14 additions & 0 deletions src/NetscriptFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import { assertFunction } from "./Netscript/TypeAssertion";
import { Router } from "./ui/GameRoot";
import { Page } from "./ui/Router";
import { canAccessBitNodeFeature, validBitNodes } from "./BitNode/BitNodeUtils";
import { Settings } from "./Settings/Settings";

export const enums: NSEnums = {
CityName,
Expand Down Expand Up @@ -613,6 +614,19 @@ export const ns: InternalAPI<NSFull> = {
runningScriptObj.title = typeof title === "string" ? title : wrapUserNode(title);
runningScriptObj.tailProps?.rerender();
},
setTailFontSize:
(ctx) =>
(_pixel = Settings.styles.tailFontSize, _pid = ctx.workerScript.scriptRef.pid) => {
const pixel = helpers.number(ctx, "pixel", _pixel);
const pid = helpers.number(ctx, "pid", _pid);
const runningSCriptObj = helpers.getRunningScript(ctx, pid);
if (runningSCriptObj == null) {
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(pid));
return;
}
runningSCriptObj.fontSize = pixel;
runningSCriptObj.tailProps?.rerender();
},
nuke: (ctx) => (_hostname) => {
const hostname = helpers.string(ctx, "hostname", _hostname);

Expand Down
3 changes: 3 additions & 0 deletions src/Script/RunningScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export class RunningScript {
// that will not be persisted, and will be restored to default on load.
title = "" as string | React.ReactElement;

// The font size of the tail window. Defaults to the font size set in the style editor.
fontSize = Settings.styles.tailFontSize;

// Number of threads that this script is running with
threads = 1 as PositiveInteger;

Expand Down
20 changes: 20 additions & 0 deletions src/ScriptEditor/NetscriptDefinitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ interface RunningScript {
* load.
*/
title: string | ReactElement;
/** The font size of the tail window. Defaults to the font size set in the style editor. */
fontSize: number;
/** Number of threads that this script runs with */
threads: number;
/** Whether this RunningScript is excluded from saves */
Expand Down Expand Up @@ -6460,6 +6462,24 @@ export interface NS {
*/
setTitle(title: string | ReactNode, pid?: number): void;

/**
* Set the font size of the tail window of a script.
* @remarks
* RAM cost: 0 GB
*
* This overwrites the tail font size and forces an update of the tail window's contents.
*
* The font size is saved across restarts.
*
* If the pid is unspecified, it will modify the current script's logs.
*
* Otherwise, the pid argument can be used to change the logs from another script.
*
* @param pixel - Optional. The new font size in pixels. If omitted, the default tail font size is used.
* @param pid - Optional. PID of the script having its tail closed. If omitted, the current script is used.
*/
setTailFontSize(pixel?: number, pid?: number): void;

/**
* Get the list of servers connected to a server.
* @remarks
Expand Down
2 changes: 1 addition & 1 deletion src/ui/React/LogBoxManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem
text={line}
color={lineColor(line)}
styles={{
fontSize: Settings.styles.tailFontSize,
fontSize: script.fontSize,
}}
/>
),
Expand Down
1 change: 1 addition & 0 deletions test/jest/Save.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function loadStandardServers() {
"server": "home",
"scriptKey": "script.js*[]",
"title": "Awesome Script",
"fontSize": 16,
"dependencies": [
{
"filename": "script.js",
Expand Down
1 change: 1 addition & 0 deletions test/jest/__snapshots__/Save.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ exports[`load/saveAllServers 1`] = `
"server": "home",
"scriptKey": "script.js*[]",
"title": "Awesome Script",
"fontSize": 16,
"threads": 1,
"temporary": false
}
Expand Down
Loading