change sf4

This commit is contained in:
Olivier Gagnon
2022-01-04 19:09:34 -05:00
parent c06087c634
commit c59a267437
32 changed files with 431 additions and 455 deletions
+6 -1
View File
@@ -14,6 +14,7 @@ import { RamCosts, RamCostConstants } from "../Netscript/RamCostGenerator";
import { Script } from "../Script/Script";
import { WorkerScript } from "../Netscript/WorkerScript";
import { areImportsEquals } from "../Terminal/DirectoryHelpers";
import { IPlayer } from "../PersonObjects/IPlayer";
// These special strings are used to reference the presence of a given logical
// construct within a user script.
@@ -33,6 +34,7 @@ const memCheckGlobalKey = ".__GLOBAL__";
* keep track of what functions have/havent been accounted for
*/
async function parseOnlyRamCalculate(
player: IPlayer,
otherScripts: Script[],
code: string,
workerScript: WorkerScript,
@@ -169,6 +171,8 @@ async function parseOnlyRamCalculate(
function applyFuncRam(cost: any): number {
if (typeof cost === "number") {
return cost;
} else if (typeof cost === "function") {
return cost(player);
} else {
return 0;
}
@@ -375,6 +379,7 @@ function parseOnlyCalculateDeps(code: string, currentModule: string): any {
* Used to account for imported scripts
*/
export async function calculateRamUsage(
player: IPlayer,
codeCopy: string,
otherScripts: Script[],
): Promise<RamCalculationErrorCode | number> {
@@ -388,7 +393,7 @@ export async function calculateRamUsage(
} as WorkerScript;
try {
return await parseOnlyRamCalculate(otherScripts, codeCopy, workerScript);
return await parseOnlyRamCalculate(player, otherScripts, codeCopy, workerScript);
} catch (e) {
console.error(`Failed to parse script for RAM calculations:`);
console.error(e);