mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-20 16:22:56 +02:00
Add ns.getRecentScripts()
This commit is contained in:
+55
-1
@@ -99,22 +99,56 @@ interface Player {
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
interface RunningScript {
|
||||
export interface RunningScript {
|
||||
/** Arguments the script was called with */
|
||||
args: string[];
|
||||
/** Filename of the script */
|
||||
filename: string;
|
||||
/**
|
||||
* Script logs as an array. The newest log entries are at the bottom.
|
||||
* Timestamps, if enabled, are placed inside `[brackets]` at the start of each line.
|
||||
**/
|
||||
logs: string[];
|
||||
/** Total amount of hacking experience earned from this script when offline */
|
||||
offlineExpGained: number;
|
||||
/** Total amount of money made by this script when offline */
|
||||
offlineMoneyMade: number;
|
||||
/** Number of seconds that the script has been running offline */
|
||||
offlineRunningTime: number;
|
||||
/** Total amount of hacking experience earned from this script when online */
|
||||
onlineExpGained: number;
|
||||
/** Total amount of money made by this script when online */
|
||||
onlineMoneyMade: number;
|
||||
/** Number of seconds that this script has been running online */
|
||||
onlineRunningTime: number;
|
||||
/** Process ID. Must be an integer */
|
||||
pid: number;
|
||||
/** How much RAM this script uses for ONE thread */
|
||||
ramUsage: number;
|
||||
/** Hostname of the server on which this script runs */
|
||||
server: string;
|
||||
/** Number of threads that this script runs with */
|
||||
threads: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
interface RecentScript {
|
||||
/** Arguments the script was called with */
|
||||
args: string[];
|
||||
/** Filename of the script */
|
||||
filename: string;
|
||||
/** Process ID. Must be an integer */
|
||||
pid: number;
|
||||
/** Timestamp of when the script was killed */
|
||||
timestamp: Date;
|
||||
/** Numeric epoch of timestamp */
|
||||
timestampEpoch: number;
|
||||
/** An inactive copy of the last `RunningScript` associated to the script */
|
||||
runningScript: RunningScript;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data representing the internal values of a crime.
|
||||
* @public
|
||||
@@ -4567,6 +4601,26 @@ export interface NS extends Singularity {
|
||||
*/
|
||||
getScriptLogs(fn?: string, host?: string, ...args: any[]): string[];
|
||||
|
||||
/**
|
||||
* Get an array of recently killed scripts across all servers.
|
||||
* @remarks
|
||||
* RAM cost: 0.2 GB
|
||||
*
|
||||
* The most recently killed script is the first element in the array.
|
||||
* Note that there is a maximum number of recently killed scripts which are tracked.
|
||||
* This is configurable in the game's options as `Recently killed scripts size`.
|
||||
*
|
||||
* @usage below:
|
||||
* ```ts
|
||||
* let recentScripts = ns.getRecentScripts();
|
||||
* let mostRcent = recentScripts.pop()
|
||||
* ns.tprint(mostRecent.logs.join('\n'))
|
||||
* ```
|
||||
*
|
||||
* @returns Array with information about previously killed scripts.
|
||||
*/
|
||||
getRecentScripts(): RecentScript[];
|
||||
|
||||
/**
|
||||
* Open the tail window of a script.
|
||||
* @remarks
|
||||
|
||||
@@ -131,13 +131,12 @@ export function Root(props: IProps): React.ReactElement {
|
||||
// Prevent Crash if script is open on deleted server
|
||||
openScripts = openScripts.filter((script) => {
|
||||
return GetServer(script.hostname) !== null;
|
||||
})
|
||||
if (currentScript && (GetServer(currentScript.hostname) === null)) {
|
||||
});
|
||||
if (currentScript && GetServer(currentScript.hostname) === null) {
|
||||
currentScript = openScripts[0];
|
||||
if (currentScript === undefined) currentScript = null;
|
||||
}
|
||||
|
||||
|
||||
const [dimensions, setDimensions] = useState({
|
||||
height: window.innerHeight,
|
||||
width: window.innerWidth,
|
||||
@@ -205,7 +204,7 @@ export function Root(props: IProps): React.ReactElement {
|
||||
});
|
||||
editor.focus();
|
||||
});
|
||||
} catch { }
|
||||
} catch {}
|
||||
} else if (!options.vim) {
|
||||
// Whem vim mode is disabled
|
||||
vimEditor?.dispose();
|
||||
@@ -314,13 +313,18 @@ export function Root(props: IProps): React.ReactElement {
|
||||
.loader();
|
||||
// replaced the bare tokens with regexes surrounded by \b, e.g. \b{token}\b which matches a word-break on either side
|
||||
// this prevents the highlighter from highlighting pieces of variables that start with a reserved token name
|
||||
l.language.tokenizer.root.unshift([new RegExp('\\bns\\b'), { token: "ns" }]);
|
||||
for (const symbol of symbols) l.language.tokenizer.root.unshift([new RegExp(`\\b${symbol}\\b`), { token: "netscriptfunction" }]);
|
||||
l.language.tokenizer.root.unshift([new RegExp("\\bns\\b"), { token: "ns" }]);
|
||||
for (const symbol of symbols)
|
||||
l.language.tokenizer.root.unshift([new RegExp(`\\b${symbol}\\b`), { token: "netscriptfunction" }]);
|
||||
const otherKeywords = ["let", "const", "var", "function"];
|
||||
const otherKeyvars = ["true", "false", "null", "undefined"];
|
||||
otherKeywords.forEach((k) => l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeywords" }]));
|
||||
otherKeyvars.forEach((k) => l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeyvars" }]));
|
||||
l.language.tokenizer.root.unshift([new RegExp('\\bthis\\b'), { token: "this" }]);
|
||||
otherKeywords.forEach((k) =>
|
||||
l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeywords" }]),
|
||||
);
|
||||
otherKeyvars.forEach((k) =>
|
||||
l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeyvars" }]),
|
||||
);
|
||||
l.language.tokenizer.root.unshift([new RegExp("\\bthis\\b"), { token: "this" }]);
|
||||
})();
|
||||
|
||||
const source = (libSource + "").replace(/export /g, "");
|
||||
@@ -446,7 +450,7 @@ export function Root(props: IProps): React.ReactElement {
|
||||
}
|
||||
try {
|
||||
infLoop(newCode);
|
||||
} catch (err) { }
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
function saveScript(scriptToSave: OpenScript): void {
|
||||
@@ -755,13 +759,16 @@ export function Root(props: IProps): React.ReactElement {
|
||||
<Button
|
||||
onClick={() => onTabClick(index)}
|
||||
style={
|
||||
currentScript?.fileName === openScripts[index].fileName ? {
|
||||
background: Settings.theme.button,
|
||||
color: Settings.theme.primary
|
||||
} : {
|
||||
background: Settings.theme.backgroundsecondary,
|
||||
color: Settings.theme.secondary
|
||||
}}
|
||||
currentScript?.fileName === openScripts[index].fileName
|
||||
? {
|
||||
background: Settings.theme.button,
|
||||
color: Settings.theme.primary,
|
||||
}
|
||||
: {
|
||||
background: Settings.theme.backgroundsecondary,
|
||||
color: Settings.theme.secondary,
|
||||
}
|
||||
}
|
||||
>
|
||||
{hostname}:~/{fileName} {dirty(index)}
|
||||
</Button>
|
||||
@@ -770,13 +777,15 @@ export function Root(props: IProps): React.ReactElement {
|
||||
style={{
|
||||
maxWidth: "20px",
|
||||
minWidth: "20px",
|
||||
...(currentScript?.fileName === openScripts[index].fileName ? {
|
||||
background: Settings.theme.button,
|
||||
color: Settings.theme.primary
|
||||
} : {
|
||||
background: Settings.theme.backgroundsecondary,
|
||||
color: Settings.theme.secondary
|
||||
})
|
||||
...(currentScript?.fileName === openScripts[index].fileName
|
||||
? {
|
||||
background: Settings.theme.button,
|
||||
color: Settings.theme.primary,
|
||||
}
|
||||
: {
|
||||
background: Settings.theme.backgroundsecondary,
|
||||
color: Settings.theme.secondary,
|
||||
}),
|
||||
}}
|
||||
>
|
||||
x
|
||||
@@ -813,20 +822,30 @@ export function Root(props: IProps): React.ReactElement {
|
||||
></Box>
|
||||
|
||||
<Box display="flex" flexDirection="row" sx={{ m: 1 }} alignItems="center">
|
||||
<Button startIcon={<SettingsIcon />} onClick={() => setOptionsOpen(true)} sx={{ mr: 1 }}>Options</Button>
|
||||
<Button startIcon={<SettingsIcon />} onClick={() => setOptionsOpen(true)} sx={{ mr: 1 }}>
|
||||
Options
|
||||
</Button>
|
||||
<Button onClick={beautify}>Beautify</Button>
|
||||
<Button color={updatingRam ? "secondary" : "primary"} sx={{ mx: 1 }} onClick={() => { setRamInfoOpen(true) }}>
|
||||
<Button
|
||||
color={updatingRam ? "secondary" : "primary"}
|
||||
sx={{ mx: 1 }}
|
||||
onClick={() => {
|
||||
setRamInfoOpen(true);
|
||||
}}
|
||||
>
|
||||
{ram}
|
||||
</Button>
|
||||
<Button onClick={save}>Save (Ctrl/Cmd + s)</Button>
|
||||
<Button sx={{ mr: 1 }} onClick={save}>
|
||||
Save (Ctrl/Cmd + s)
|
||||
</Button>
|
||||
<Button onClick={props.router.toTerminal}>Close (Ctrl/Cmd + b)</Button>
|
||||
<Typography sx={{ mx: 1 }}>
|
||||
{" "}
|
||||
Documentation:{" "}
|
||||
<strong>Documentation:</strong>{" "}
|
||||
<Link target="_blank" href="https://bitburner.readthedocs.io/en/latest/index.html">
|
||||
Basic
|
||||
</Link>{" "}
|
||||
|
|
||||
</Link>
|
||||
{" | "}
|
||||
<Link target="_blank" href="https://github.com/danielyxie/bitburner/blob/dev/markdown/bitburner.ns.md">
|
||||
Full
|
||||
</Link>
|
||||
@@ -858,7 +877,9 @@ export function Root(props: IProps): React.ReactElement {
|
||||
<React.Fragment key={n + r}>
|
||||
<TableRow>
|
||||
<TableCell sx={{ color: Settings.theme.primary }}>{n}</TableCell>
|
||||
<TableCell align="right" sx={{ color: Settings.theme.primary }}>{r}</TableCell>
|
||||
<TableCell align="right" sx={{ color: Settings.theme.primary }}>
|
||||
{r}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</React.Fragment>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user