mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-18 07:18:38 +02:00
CODEBASE: Add Jsonable Map and Set types, move player.sourceFiles to a map (#473)
This commit is contained in:
@@ -8,7 +8,6 @@ import * as workMethods from "./PlayerObjectWorkMethods";
|
||||
|
||||
import { setPlayer } from "../../Player";
|
||||
import { Sleeve } from "../Sleeve/Sleeve";
|
||||
import { PlayerOwnedSourceFile } from "../../SourceFile/PlayerOwnedSourceFile";
|
||||
import { Exploit } from "../../Exploits/Exploit";
|
||||
|
||||
import { LocationName } from "../../Enums";
|
||||
@@ -21,6 +20,7 @@ import { HashManager } from "../../Hacknet/HashManager";
|
||||
|
||||
import { MoneySourceTracker } from "../../utils/MoneySourceTracker";
|
||||
import { constructorsForReviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../../utils/JSONReviver";
|
||||
import { JSONMap } from "../../Types/Jsonable";
|
||||
import { PlayerAchievement } from "../../Achievements/Achievements";
|
||||
import { cyrb53 } from "../../utils/StringHelperFunctions";
|
||||
import { getRandomInt } from "../../utils/helpers/getRandomInt";
|
||||
@@ -59,7 +59,7 @@ export class PlayerObject extends Person implements IPlayer {
|
||||
scriptProdSinceLastAug = 0;
|
||||
sleeves: Sleeve[] = [];
|
||||
sleevesFromCovenant = 0;
|
||||
sourceFiles: PlayerOwnedSourceFile[] = [];
|
||||
sourceFiles: JSONMap<number, number> = new JSONMap();
|
||||
exploits: Exploit[] = [];
|
||||
achievements: PlayerAchievement[] = [];
|
||||
terminalCommandHistory: string[] = [];
|
||||
@@ -168,9 +168,15 @@ export class PlayerObject extends Person implements IPlayer {
|
||||
|
||||
/** Initializes a PlayerObject object from a JSON save state. */
|
||||
static fromJSON(value: IReviverValue): PlayerObject {
|
||||
if (!value.data.hp?.current || !value.data.hp?.max) value.data.hp = { current: 10, max: 10 };
|
||||
const player = Generic_fromJSON(PlayerObject, value.data);
|
||||
if (player.money === null) player.money = 0;
|
||||
player.hp = { current: player.hp?.current ?? 10, max: player.hp?.max ?? 10 };
|
||||
player.money ??= 0;
|
||||
player.updateSkillLevels();
|
||||
if (Array.isArray(player.sourceFiles)) {
|
||||
// Expect pre-2.3 sourcefile format here.
|
||||
type OldSourceFiles = { n: number; lvl: number }[];
|
||||
player.sourceFiles = new JSONMap((player.sourceFiles as OldSourceFiles).map(({ n, lvl }) => [n, lvl]));
|
||||
}
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user