mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-28 17:07:32 +01:00
23 lines
636 B
TypeScript
23 lines
636 B
TypeScript
import { GetServer } from "../Server/AllServers";
|
|
import { RunningScript } from "./RunningScript";
|
|
|
|
export function getRamUsageFromRunningScript(script: RunningScript): number {
|
|
if (script.ramUsage != null && script.ramUsage > 0) {
|
|
return script.ramUsage; // Use cached value
|
|
}
|
|
|
|
const server = GetServer(script.server);
|
|
if (server == null) {
|
|
return 0;
|
|
}
|
|
for (let i = 0; i < server.scripts.length; ++i) {
|
|
if (server.scripts[i].filename === script.filename) {
|
|
// Cache the ram usage for the next call
|
|
script.ramUsage = server.scripts[i].ramUsage;
|
|
return script.ramUsage;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|