2021-03-09 02:31:34 +01:00
|
|
|
import { sanitizeExploits } from "./Exploits/Exploit";
|
2019-04-01 11:23:25 +02:00
|
|
|
|
2021-09-25 20:42:57 +02:00
|
|
|
import { Reviver } from "./utils/JSONReviver";
|
2019-04-01 11:23:25 +02:00
|
|
|
|
2023-03-29 06:30:27 +02:00
|
|
|
import type { PlayerObject } from "./PersonObjects/Player/PlayerObject";
|
|
|
|
|
|
|
|
export let Player: PlayerObject;
|
|
|
|
|
|
|
|
export function setPlayer(playerObj: PlayerObject): void {
|
|
|
|
Player = playerObj;
|
|
|
|
}
|
2019-04-01 11:23:25 +02:00
|
|
|
|
2023-04-18 09:19:45 +02:00
|
|
|
export function loadPlayer(saveString: string): PlayerObject {
|
2024-11-21 08:47:02 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
2023-04-18 09:19:45 +02:00
|
|
|
player.money = parseFloat(player.money + "");
|
|
|
|
player.exploits = sanitizeExploits(player.exploits);
|
|
|
|
return player;
|
2017-08-30 19:44:29 +02:00
|
|
|
}
|