mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-18 07:18:38 +02:00
API: Move tail-related APIs to another namespace (#1935)
* API: Move tail-related APIs to another namespace * Add missing RAM cost config * Remove setTailFontSize from NS namespace
This commit is contained in:
@@ -7,14 +7,103 @@ import { CONSTANTS } from "../Constants";
|
||||
import { commitHash } from "../utils/helpers/commitHash";
|
||||
import { InternalAPI } from "../Netscript/APIWrapper";
|
||||
import { Terminal } from "../../src/Terminal";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { helpers, wrapUserNode } from "../Netscript/NetscriptHelpers";
|
||||
import { assertAndSanitizeMainTheme, assertAndSanitizeStyles } from "../JsonSchema/JSONSchemaAssertion";
|
||||
import { LogBoxCloserEvents, LogBoxEvents } from "../ui/React/LogBoxManager";
|
||||
|
||||
export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
return {
|
||||
openTail:
|
||||
(ctx) =>
|
||||
(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;
|
||||
}
|
||||
|
||||
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) => {
|
||||
const x = helpers.number(ctx, "x", _x);
|
||||
const y = helpers.number(ctx, "y", _y);
|
||||
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?.setPosition(x, y);
|
||||
},
|
||||
|
||||
resizeTail:
|
||||
(ctx) =>
|
||||
(_w, _h, _pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const w = helpers.number(ctx, "w", _w);
|
||||
const h = helpers.number(ctx, "h", _h);
|
||||
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?.setSize(w, h);
|
||||
},
|
||||
|
||||
closeTail:
|
||||
(ctx) =>
|
||||
(_pid = ctx.workerScript.scriptRef.pid) => {
|
||||
const pid = helpers.number(ctx, "pid", _pid);
|
||||
//Emit an event to tell the game to close the tail window if it exists
|
||||
LogBoxCloserEvents.emit(pid);
|
||||
},
|
||||
|
||||
setTailTitle:
|
||||
(ctx) =>
|
||||
(title, _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.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));
|
||||
},
|
||||
|
||||
windowSize: () => () => {
|
||||
return [window.innerWidth, window.innerHeight];
|
||||
},
|
||||
|
||||
getTheme: () => () => {
|
||||
return { ...Settings.theme };
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user