moved updateRam to first call to avoid lack of mocks for tests

* added wrapper funcs to simplify updateRam
* added static parser tests and skiped what isnt worker still for next person to try and fix
This commit is contained in:
phyzical
2022-03-31 21:41:19 +08:00
parent d814a81b79
commit 18af3f8413
13 changed files with 846 additions and 487 deletions
+13 -11
View File
@@ -21,22 +21,24 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
}
}
const updateRam = (funcName: string): void =>
helper.updateDynamicRam(funcName, getRamCost(player, "stanek", funcName));
return {
giftWidth: function (): number {
helper.updateDynamicRam("giftWidth", getRamCost(player, "stanek", "giftWidth"));
updateRam("giftWidth");
checkStanekAPIAccess("giftWidth");
return staneksGift.width();
},
giftHeight: function (): number {
helper.updateDynamicRam("giftHeight", getRamCost(player, "stanek", "giftHeight"));
updateRam("giftHeight");
checkStanekAPIAccess("giftHeight");
return staneksGift.height();
},
chargeFragment: function (_rootX: unknown, _rootY: unknown): Promise<void> {
updateRam("chargeFragment");
const rootX = helper.number("stanek.chargeFragment", "rootX", _rootX);
const rootY = helper.number("stanek.chargeFragment", "rootY", _rootY);
helper.updateDynamicRam("chargeFragment", getRamCost(player, "stanek", "chargeFragment"));
checkStanekAPIAccess("chargeFragment");
const fragment = staneksGift.findFragment(rootX, rootY);
if (!fragment)
@@ -49,13 +51,13 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
});
},
fragmentDefinitions: function (): IFragment[] {
helper.updateDynamicRam("fragmentDefinitions", getRamCost(player, "stanek", "fragmentDefinitions"));
updateRam("fragmentDefinitions");
checkStanekAPIAccess("fragmentDefinitions");
workerScript.log("stanek.fragmentDefinitions", () => `Returned ${Fragments.length} fragments`);
return Fragments.map((f) => f.copy());
},
activeFragments: function (): IActiveFragment[] {
helper.updateDynamicRam("activeFragments", getRamCost(player, "stanek", "activeFragments"));
updateRam("activeFragments");
checkStanekAPIAccess("activeFragments");
workerScript.log("stanek.activeFragments", () => `Returned ${staneksGift.fragments.length} fragments`);
return staneksGift.fragments.map((af) => {
@@ -63,17 +65,17 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
});
},
clearGift: function (): void {
helper.updateDynamicRam("clearGift", getRamCost(player, "stanek", "clearGift"));
updateRam("clearGift");
checkStanekAPIAccess("clearGift");
workerScript.log("stanek.clearGift", () => `Cleared Stanek's Gift.`);
staneksGift.clear();
},
canPlaceFragment: function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
updateRam("canPlaceFragment");
const rootX = helper.number("stanek.canPlaceFragment", "rootX", _rootX);
const rootY = helper.number("stanek.canPlaceFragment", "rootY", _rootY);
const rotation = helper.number("stanek.canPlaceFragment", "rotation", _rotation);
const fragmentId = helper.number("stanek.canPlaceFragment", "fragmentId", _fragmentId);
helper.updateDynamicRam("canPlaceFragment", getRamCost(player, "stanek", "canPlaceFragment"));
checkStanekAPIAccess("canPlaceFragment");
const fragment = FragmentById(fragmentId);
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.canPlaceFragment", `Invalid fragment id: ${fragmentId}`);
@@ -81,29 +83,29 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel
return can;
},
placeFragment: function (_rootX: unknown, _rootY: unknown, _rotation: unknown, _fragmentId: unknown): boolean {
updateRam("placeFragment");
const rootX = helper.number("stanek.placeFragment", "rootX", _rootX);
const rootY = helper.number("stanek.placeFragment", "rootY", _rootY);
const rotation = helper.number("stanek.placeFragment", "rotation", _rotation);
const fragmentId = helper.number("stanek.placeFragment", "fragmentId", _fragmentId);
helper.updateDynamicRam("placeFragment", getRamCost(player, "stanek", "placeFragment"));
checkStanekAPIAccess("placeFragment");
const fragment = FragmentById(fragmentId);
if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.placeFragment", `Invalid fragment id: ${fragmentId}`);
return staneksGift.place(rootX, rootY, rotation, fragment);
},
getFragment: function (_rootX: unknown, _rootY: unknown): IActiveFragment | undefined {
updateRam("getFragment");
const rootX = helper.number("stanek.getFragment", "rootX", _rootX);
const rootY = helper.number("stanek.getFragment", "rootY", _rootY);
helper.updateDynamicRam("getFragment", getRamCost(player, "stanek", "getFragment"));
checkStanekAPIAccess("getFragment");
const fragment = staneksGift.findFragment(rootX, rootY);
if (fragment !== undefined) return fragment.copy();
return undefined;
},
removeFragment: function (_rootX: unknown, _rootY: unknown): boolean {
updateRam("removeFragment");
const rootX = helper.number("stanek.removeFragment", "rootX", _rootX);
const rootY = helper.number("stanek.removeFragment", "rootY", _rootY);
helper.updateDynamicRam("removeFragment", getRamCost(player, "stanek", "removeFragment"));
checkStanekAPIAccess("removeFragment");
return staneksGift.delete(rootX, rootY);
},