mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-24 02:03:01 +02:00
UI: LogBox overhaul (#508)
This commit is contained in:
@@ -17,6 +17,8 @@ import { getKeyList } from "../utils/helpers/getKeyList";
|
||||
import { ScriptFilePath } from "../Paths/ScriptFilePath";
|
||||
import { ScriptKey, scriptKey } from "../utils/helpers/scriptKey";
|
||||
|
||||
import type { LogBoxProperties } from "../ui/React/LogBoxManager";
|
||||
|
||||
export class RunningScript {
|
||||
// Script arguments
|
||||
args: ScriptArg[] = [];
|
||||
@@ -65,6 +67,14 @@ export class RunningScript {
|
||||
// Cached key for ByArgs lookups. Will be overwritten by a correct ScriptKey in fromJSON or constructor
|
||||
scriptKey = "" as ScriptKey;
|
||||
|
||||
// Access to properties of the tail window. Can be used to get/set size, position, etc.
|
||||
tailProps = null as LogBoxProperties | null;
|
||||
|
||||
// The title, as shown in the script's log box. Defaults to the name + args,
|
||||
// but can be changed by the user. If it is set to a React element (only by the user),
|
||||
// that will not be persisted, and will be restored to default on load.
|
||||
title = "" as string | React.ReactElement;
|
||||
|
||||
// Number of threads that this script is running with
|
||||
threads = 1 as PositiveInteger;
|
||||
|
||||
@@ -83,6 +93,7 @@ export class RunningScript {
|
||||
this.server = script.server;
|
||||
this.ramUsage = ramUsage;
|
||||
this.dependencies = script.dependencies;
|
||||
this.title = `${this.filename} ${args.join(" ")}`;
|
||||
}
|
||||
|
||||
log(txt: React.ReactNode): void {
|
||||
@@ -140,7 +151,12 @@ export class RunningScript {
|
||||
|
||||
// Serialize the current object to a JSON save state
|
||||
toJSON(): IReviverValue {
|
||||
return Generic_toJSON("RunningScript", this, includedProperties);
|
||||
// Omit the title if it's a ReactNode, it will be filled in with the default on load.
|
||||
return Generic_toJSON(
|
||||
"RunningScript",
|
||||
this,
|
||||
typeof this.title === "string" ? includedProperties : includedPropsNoTitle,
|
||||
);
|
||||
}
|
||||
|
||||
// Initializes a RunningScript Object from a JSON save state
|
||||
@@ -150,6 +166,9 @@ export class RunningScript {
|
||||
return runningScript;
|
||||
}
|
||||
}
|
||||
const includedProperties = getKeyList(RunningScript, { removedKeys: ["logs", "dependencies", "logUpd", "pid"] });
|
||||
const includedProperties = getKeyList(RunningScript, {
|
||||
removedKeys: ["logs", "dependencies", "logUpd", "pid", "tailProps"],
|
||||
});
|
||||
const includedPropsNoTitle = includedProperties.filter((x) => x !== "title");
|
||||
|
||||
constructorsForReviver.RunningScript = RunningScript;
|
||||
|
||||
Reference in New Issue
Block a user