bitburner-src/src/Diagnostic/FileDiagnosticPopup.tsx

85 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-08-27 20:17:25 +02:00
import React from "react";
import { AllServers } from "../Server/AllServers";
import { Script } from "../Script/Script";
import { TextFile } from "../TextFile";
import { Accordion } from "../ui/React/Accordion";
import { numeralWrapper } from "../ui/numeralFormat";
interface IServerProps {
2021-09-05 01:09:30 +02:00
ip: string;
2021-08-27 20:17:25 +02:00
}
export function ServerAccordion(props: IServerProps): React.ReactElement {
2021-09-05 01:09:30 +02:00
const server = AllServers[props.ip];
let totalSize = 0;
for (const f of server.scripts) {
totalSize += f.code.length;
}
2021-08-27 20:17:25 +02:00
2021-09-05 01:09:30 +02:00
for (const f of server.textFiles) {
totalSize += f.text.length;
}
2021-08-27 20:17:25 +02:00
2021-09-05 01:09:30 +02:00
if (totalSize === 0) {
return <></>;
}
2021-08-27 20:17:25 +02:00
2021-09-05 01:09:30 +02:00
interface File {
name: string;
size: number;
}
2021-08-27 20:17:25 +02:00
2021-09-05 01:09:30 +02:00
const files: File[] = [];
2021-08-27 20:17:25 +02:00
2021-09-05 01:09:30 +02:00
for (const f of server.scripts) {
files.push({ name: f.filename, size: f.code.length });
}
2021-08-27 20:17:25 +02:00
2021-09-05 01:09:30 +02:00
for (const f of server.textFiles) {
files.push({ name: f.fn, size: f.text.length });
}
2021-08-27 20:17:25 +02:00
2021-09-05 01:09:30 +02:00
files.sort((a: File, b: File): number => b.size - a.size);
2021-08-27 20:17:25 +02:00
2021-09-05 01:09:30 +02:00
return (
<Accordion
headerContent={
<>
{server.hostname} ({numeralWrapper.formatBigNumber(totalSize)}b)
</>
}
panelContent={
<ul>
{files.map((file: File) => (
<li key={file.name}>
{file.name}: {numeralWrapper.formatBigNumber(file.size)}b
</li>
))}
</ul>
}
2021-08-27 20:17:25 +02:00
/>
2021-09-05 01:09:30 +02:00
);
2021-08-27 20:17:25 +02:00
}
interface IProps {}
export function FileDiagnosticPopup(props: IProps): React.ReactElement {
2021-09-05 01:09:30 +02:00
const ips: string[] = [];
for (const ip of Object.keys(AllServers)) {
ips.push(ip);
}
2021-08-27 20:17:25 +02:00
2021-09-05 01:09:30 +02:00
return (
<>
<p>
Welcome to the file diagnostic! If your save file is really big it's
likely because you have too many text/scripts. This tool can help you
narrow down where they are.
</p>
{ips.map((ip: string) => (
<ServerAccordion key={ip} ip={ip} />
))}
</>
);
}