mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
NETSCRIPT: Added changing tail font size through scripts (#1852)
This commit is contained in:
@@ -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, fn, host, args)](./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. |
|
||||
|
||||
39
markdown/bitburner.ns.settailfontsize.md
Normal file
39
markdown/bitburner.ns.settailfontsize.md
Normal file
@@ -0,0 +1,39 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [setTailFontSize](./bitburner.ns.settailfontsize.md)
|
||||
|
||||
## NS.setTailFontSize() method
|
||||
|
||||
Set the font size of the tail window of a script.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
setTailFontSize(pixel?: number, fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| pixel | number | _(Optional)_ Optional. The new font size in pixels. If omitted, the default tail font size is used. |
|
||||
| fn | [FilenameOrPID](./bitburner.filenameorpid.md) | _(Optional)_ Optional. Filename or PID of the target script. If omitted, the current script is used. |
|
||||
| host | string | _(Optional)_ Optional. Hostname of the target script. Defaults to the server this script is running on. If args are specified, this is not optional. |
|
||||
| args | [ScriptArg](./bitburner.scriptarg.md)<!-- -->\[\] | Arguments for the target script. |
|
||||
|
||||
**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 ran without a filename or pid, this will affect the current script's tail window.
|
||||
|
||||
Otherwise, the PID or filename, hostname/ip, and args… arguments can be used to target the tail window from another script. Remember that scripts are uniquely identified by both their names and arguments.
|
||||
|
||||
13
markdown/bitburner.tailproperties.fontsize.md
Normal file
13
markdown/bitburner.tailproperties.fontsize.md
Normal file
@@ -0,0 +1,13 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [TailProperties](./bitburner.tailproperties.md) > [fontSize](./bitburner.tailproperties.fontsize.md)
|
||||
|
||||
## TailProperties.fontSize property
|
||||
|
||||
The font size of the tail window. Defaults to the font size set in the style editor.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
fontSize: number;
|
||||
```
|
||||
@@ -15,6 +15,7 @@ interface TailProperties
|
||||
|
||||
| Property | Modifiers | Type | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [fontSize](./bitburner.tailproperties.fontsize.md) | | number | The font size of the tail window. Defaults to the font size set in the style editor. |
|
||||
| [height](./bitburner.tailproperties.height.md) | | number | Height of the log window content area |
|
||||
| [width](./bitburner.tailproperties.width.md) | | number | Width of the log window content area |
|
||||
| [x](./bitburner.tailproperties.x.md) | | number | X-coordinate of the log window |
|
||||
|
||||
@@ -63,6 +63,7 @@ import {
|
||||
validateSourceFileOverrides,
|
||||
} from "../BitNode/BitNodeUtils";
|
||||
import { JSONMap } from "../Types/Jsonable";
|
||||
import { Settings } from "../Settings/Settings";
|
||||
|
||||
export const helpers = {
|
||||
string,
|
||||
@@ -747,6 +748,7 @@ function createPublicRunningScript(runningScript: RunningScript, workerScript?:
|
||||
y: logProps.y,
|
||||
width: logProps.width,
|
||||
height: logProps.height,
|
||||
fontSize: logProps.fontSize ?? Settings.styles.tailFontSize,
|
||||
},
|
||||
title: runningScript.title,
|
||||
threads: runningScript.threads,
|
||||
|
||||
@@ -602,6 +602,7 @@ export const RamCosts: RamCostTree<NSFull> = {
|
||||
resizeTail: 0,
|
||||
closeTail: 0,
|
||||
setTitle: 0,
|
||||
setTailFontSize: 0,
|
||||
clearPort: 0,
|
||||
openDevMenu: 0,
|
||||
alert: 0,
|
||||
|
||||
@@ -616,6 +616,18 @@ export const ns: InternalAPI<NSFull> = {
|
||||
runningScriptObj.title = typeof title === "string" ? title : wrapUserNode(title);
|
||||
runningScriptObj.tailProps?.rerender();
|
||||
},
|
||||
setTailFontSize:
|
||||
(ctx) =>
|
||||
(_pixel, scriptID, hostname, ...scriptArgs) => {
|
||||
const ident = helpers.scriptIdentifier(ctx, scriptID, hostname, scriptArgs);
|
||||
const runningScriptObj = helpers.getRunningScript(ctx, ident);
|
||||
if (runningScriptObj == null) {
|
||||
helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(ident));
|
||||
return;
|
||||
}
|
||||
if (_pixel === undefined) runningScriptObj.tailProps?.setFontSize(undefined);
|
||||
else runningScriptObj.tailProps?.setFontSize(helpers.number(ctx, "pixel", _pixel));
|
||||
},
|
||||
nuke: (ctx) => (_hostname) => {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
|
||||
|
||||
21
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
21
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -192,6 +192,8 @@ interface TailProperties {
|
||||
width: number;
|
||||
/** Height of the log window content area */
|
||||
height: number;
|
||||
/** The font size of the tail window. Defaults to the font size set in the style editor. */
|
||||
fontSize: number;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -6467,6 +6469,25 @@ 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.
|
||||
*
|
||||
* If ran without a filename or pid, this will affect the current script's tail window.
|
||||
*
|
||||
* Otherwise, the PID or filename, hostname/ip, and args… arguments can be used to target the tail window from another script.
|
||||
* Remember that scripts are uniquely identified by both their names and arguments.
|
||||
*
|
||||
* @param pixel - Optional. The new font size in pixels. If omitted, the default tail font size is used.
|
||||
* @param fn - Optional. Filename or PID of the target script. If omitted, the current script is used.
|
||||
* @param host - Optional. Hostname of the target script. Defaults to the server this script is running on. If args are specified, this is not optional.
|
||||
* @param args - Arguments for the target script.
|
||||
*/
|
||||
setTailFontSize(pixel?: number, fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void;
|
||||
|
||||
/**
|
||||
* Get the list of servers connected to a server.
|
||||
* @remarks
|
||||
|
||||
@@ -39,6 +39,7 @@ export class LogBoxProperties {
|
||||
y = window.innerHeight * 0.3;
|
||||
width = 500;
|
||||
height = 500;
|
||||
fontSize: number | undefined = undefined;
|
||||
|
||||
rerender: () => void;
|
||||
rootRef: React.RefObject<Draggable>;
|
||||
@@ -68,6 +69,11 @@ export class LogBoxProperties {
|
||||
this.rerender();
|
||||
}
|
||||
|
||||
setFontSize(size?: number): void {
|
||||
this.fontSize = size;
|
||||
this.rerender();
|
||||
}
|
||||
|
||||
isVisible(): boolean {
|
||||
return this.rootRef.current !== null;
|
||||
}
|
||||
@@ -415,7 +421,7 @@ function LogWindow({ hidden, script, onClose }: LogWindowProps): React.ReactElem
|
||||
text={line}
|
||||
color={lineColor(line)}
|
||||
styles={{
|
||||
fontSize: Settings.styles.tailFontSize,
|
||||
fontSize: propsRef.current.fontSize ?? Settings.styles.tailFontSize,
|
||||
}}
|
||||
/>
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user