bitburner-src/src/Player.ts

24 lines
827 B
TypeScript
Raw Normal View History

2021-03-09 02:31:34 +01:00
import { sanitizeExploits } from "./Exploits/Exploit";
2021-09-25 20:42:57 +02:00
import { Reviver } from "./utils/JSONReviver";
import type { PlayerObject } from "./PersonObjects/Player/PlayerObject";
export let Player: PlayerObject;
export function setPlayer(playerObj: PlayerObject): void {
Player = playerObj;
}
export function loadPlayer(saveString: string): PlayerObject {
/**
* If we want to check player with "instanceof PlayerObject", we have to import PlayerObject normally (not "import
* type"). It will create a cyclic dependency. Fixing this cyclic dependency is really hard. It's not worth the
* effort, so we typecast it here.
*/
2024-11-04 07:35:14 +01:00
const player = JSON.parse(saveString, Reviver) as PlayerObject;
player.money = parseFloat(player.money + "");
player.exploits = sanitizeExploits(player.exploits);
return player;
}