Moved Player initialization point (#452)

Now initialized as side effect in PlayerObject, instead of in Player file that is imported everywhere.
This commit is contained in:
David Walker 2023-03-28 21:30:27 -07:00 committed by GitHub
parent 798da75d83
commit 8445af5f2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 43 additions and 11 deletions

@ -1,4 +1,3 @@
import { PlayerObject } from "../PersonObjects/Player/PlayerObject";
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
import { SkillNames } from "../Bladeburner/data/SkillNames";
import { Skills } from "../Bladeburner/Skills";
@ -26,6 +25,8 @@ import { BlackOperationNames } from "../Bladeburner/data/BlackOperationNames";
import { isClassWork } from "../Work/ClassWork";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import type { PlayerObject } from "../PersonObjects/Player/PlayerObject";
// Unable to correctly cast the JSON data into AchievementDataJson type otherwise...
const achievementData = (<AchievementDataJson>(<unknown>data)).achievements;

@ -6,6 +6,7 @@ import * as generalMethods from "./PlayerObjectGeneralMethods";
import * as serverMethods from "./PlayerObjectServerMethods";
import * as workMethods from "./PlayerObjectWorkMethods";
import { setPlayer } from "../../Player";
import { Sleeve } from "../Sleeve/Sleeve";
import { PlayerOwnedSourceFile } from "../../SourceFile/PlayerOwnedSourceFile";
import { Exploit } from "../../Exploits/Exploit";
@ -172,4 +173,6 @@ export class PlayerObject extends Person implements IPlayer {
}
}
setPlayer(new PlayerObject());
Reviver.constructors.PlayerObject = PlayerObject;

@ -1,7 +1,8 @@
/** Augmentation-related methods for the Player class (PlayerObject) */
import { PlayerObject } from "./PlayerObject";
import { calculateEntropy } from "../Grafting/EntropyAccumulation";
import type { PlayerObject } from "./PlayerObject";
export function applyEntropy(this: PlayerObject, stacks = 1): void {
// Re-apply all multipliers
this.reapplyAllAugmentations();

@ -1,5 +1,6 @@
import { Bladeburner } from "../../Bladeburner/Bladeburner";
import { PlayerObject } from "./PlayerObject";
import type { PlayerObject } from "./PlayerObject";
export function canAccessBladeburner(this: PlayerObject): boolean {
return this.bitNodeN === 6 || this.bitNodeN === 7 || this.sourceFileLvl(6) > 0 || this.sourceFileLvl(7) > 0;

@ -3,9 +3,10 @@ import {
CorporationUnlockUpgradeIndex,
CorporationUnlockUpgrades,
} from "../../Corporation/data/CorporationUnlockUpgrades";
import { PlayerObject } from "./PlayerObject";
import { resetIndustryResearchTrees } from "../../Corporation/IndustryData";
import type { PlayerObject } from "./PlayerObject";
export function canAccessCorporation(this: PlayerObject): boolean {
return this.bitNodeN === 3 || this.sourceFileLvl(3) > 0;
}

@ -1,10 +1,11 @@
import { Factions } from "../../Faction/Factions";
import { Faction } from "../../Faction/Faction";
import { Gang } from "../../Gang/Gang";
import { PlayerObject } from "./PlayerObject";
import { GangConstants } from "../../Gang/data/Constants";
import { isFactionWork } from "../../Work/FactionWork";
import type { PlayerObject } from "./PlayerObject";
export function canAccessGang(this: PlayerObject): boolean {
if (this.bitNodeN === 2) {
return true;

@ -1,4 +1,3 @@
import { PlayerObject } from "./PlayerObject";
import { applyAugmentation } from "../../Augmentation/AugmentationHelpers";
import { PlayerOwnedAugmentation } from "../../Augmentation/PlayerOwnedAugmentation";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
@ -45,6 +44,8 @@ import { FactionNames } from "../../Faction/data/FactionNames";
import { isCompanyWork } from "../../Work/CompanyWork";
import { serverMetadata } from "../../Server/data/servers";
import type { PlayerObject } from "./PlayerObject";
export function init(this: PlayerObject): void {
/* Initialize Player's home computer */
const t_homeComp = safelyCreateUniqueServer({

@ -1,6 +1,4 @@
// Server and HacknetServer-related methods for the Player class (PlayerObject)
import { PlayerObject } from "./PlayerObject";
import { CONSTANTS } from "../../Constants";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
@ -11,6 +9,8 @@ import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/A
import { SpecialServers } from "../../Server/data/SpecialServers";
import { hasHacknetServers } from "../../Hacknet/HacknetHelpers";
import type { PlayerObject } from "./PlayerObject";
export function hasTorRouter(this: PlayerObject): boolean {
return this.getHomeComputer().serversOnNetwork.includes(SpecialServers.DarkWeb);
}

@ -1,5 +1,6 @@
import { Work } from "../../Work/Work";
import { PlayerObject } from "./PlayerObject";
import type { PlayerObject } from "./PlayerObject";
export function startWork(this: PlayerObject, w: Work): void {
if (this.currentWork !== null) {

@ -1,9 +1,14 @@
import { PlayerObject } from "./PersonObjects/Player/PlayerObject";
import { sanitizeExploits } from "./Exploits/Exploit";
import { Reviver } from "./utils/JSONReviver";
export let Player = new PlayerObject();
import type { PlayerObject } from "./PersonObjects/Player/PlayerObject";
export let Player: PlayerObject;
export function setPlayer(playerObj: PlayerObject): void {
Player = playerObj;
}
export function loadPlayer(saveString: string): void {
Player = JSON.parse(saveString, Reviver);

@ -11,6 +11,7 @@ import { Reviver } from "../utils/JSONReviver";
import { isValidIPAddress } from "../utils/helpers/isValidIPAddress";
import { SpecialServers } from "./data/SpecialServers";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import "../Script/RunningScript"; // For reviver side-effect
import type { RunningScript } from "../Script/RunningScript";

@ -12,6 +12,7 @@ import { processPassiveFactionRepGain, inviteToFaction } from "./Faction/Faction
import { Router } from "./ui/GameRoot";
import { Page } from "./ui/Router";
import { SetupTextEditor } from "./ScriptEditor/ui/ScriptEditorRoot";
import "./PersonObjects/Player/PlayerObject"; // For side-effect of creating Player
import {
getHackingWorkRepGain,

@ -0,0 +1,5 @@
import { HacknetServer } from "../../../src/Hacknet/HacknetServer";
test("Can import only HacknetServer", () => {
new HacknetServer();
});

@ -0,0 +1,5 @@
import { Server } from "../../../src/Server/Server";
test("Can import only Server", () => {
new Server();
});

@ -0,0 +1,5 @@
import { WorkerScript } from "../../../src/Netscript/WorkerScript";
test("Can import only WorkerScript", () => {
WorkerScript;
});