UI: LogBox overhaul (#508)

This commit is contained in:
David Walker
2023-05-26 05:07:37 -07:00
committed by GitHub
parent 113af6e711
commit 4503da6226
26 changed files with 431 additions and 114 deletions
@@ -1,3 +1,4 @@
import React from "react";
import { NetscriptContext } from "./APIWrapper";
import { WorkerScript } from "./WorkerScript";
import { killWorkerScript } from "./killWorkerScript";
@@ -38,6 +39,7 @@ import { isPositiveInteger, PositiveInteger, Unknownify } from "../types";
import { Engine } from "../engine";
import { resolveFilePath, FilePath } from "../Paths/FilePath";
import { hasScriptExtension, ScriptFilePath } from "../Paths/ScriptFilePath";
import { CustomBoundary } from "../ui/Components/CustomBoundary";
export const helpers = {
string,
@@ -736,6 +738,7 @@ function getCannotFindRunningScriptErrorMessage(ident: ScriptIdentifier): string
* @returns A sanitized, NS-facing copy of the RunningScript
*/
function createPublicRunningScript(runningScript: RunningScript): IRunningScript {
const logProps = runningScript.tailProps;
return {
args: runningScript.args.slice(),
filename: runningScript.filename,
@@ -749,6 +752,16 @@ function createPublicRunningScript(runningScript: RunningScript): IRunningScript
pid: runningScript.pid,
ramUsage: runningScript.ramUsage,
server: runningScript.server,
tailProperties:
!logProps || !logProps.isVisible()
? null
: {
x: logProps.x,
y: logProps.y,
width: logProps.width,
height: logProps.height,
},
title: runningScript.title,
threads: runningScript.threads,
temporary: runningScript.temporary,
};
@@ -800,3 +813,14 @@ export function handleUnknownError(e: unknown, ws: WorkerScript | ScriptDeath |
}
dialogBoxCreate(initialText + e);
}
// Incrementing value for custom element keys
let customElementKey = 0;
/**
* Wrap a user-provided React Element (or maybe invalid junk) in an Error-catching component,
* so the game won't crash and the user gets sensible messages.
*/
export function wrapUserNode(value: unknown) {
return <CustomBoundary key={`PlayerContent${customElementKey++}`} children={value as React.ReactNode} />;
}
+1
View File
@@ -540,6 +540,7 @@ export const RamCosts: RamCostTree<NSFull> = {
moveTail: 0,
resizeTail: 0,
closeTail: 0,
setTitle: 0,
clearPort: 0,
openDevMenu: 0,
alert: 0,