From 2f9eb324b446746bf4ace61b99eb8321f1477d7c Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 19 Dec 2021 15:20:02 +0000 Subject: [PATCH] fix(shortcut): job shortcut only run when have job The shortcut was always allowed to run, meaning when the player doesn't have a job, they were sent to the job screen with no job and lost the view context/sidebar. - Add utility method to check if the player 'hasJob', being at least 1 job. - Check if player has job when the key combination is pressed Resolves danielyxie/bitburner#2013 --- src/PersonObjects/IPlayer.ts | 1 + src/PersonObjects/Player/PlayerObject.ts | 2 ++ src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx | 9 +++++++++ src/Sidebar/ui/SidebarRoot.tsx | 2 +- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/PersonObjects/IPlayer.ts b/src/PersonObjects/IPlayer.ts index c5c3ef8c9..3153cb2b5 100644 --- a/src/PersonObjects/IPlayer.ts +++ b/src/PersonObjects/IPlayer.ts @@ -242,6 +242,7 @@ export interface IPlayer { getIntelligenceBonus(weight: number): number; getCasinoWinnings(): number; quitJob(company: string): void; + hasJob(): boolean; createHacknetServer(): HacknetServer; startCreateProgramWork(router: IRouter, programName: string, time: number, reqLevel: number): void; queueAugmentation(augmentationName: string): void; diff --git a/src/PersonObjects/Player/PlayerObject.ts b/src/PersonObjects/Player/PlayerObject.ts index bce4ec3c6..8497e94a1 100644 --- a/src/PersonObjects/Player/PlayerObject.ts +++ b/src/PersonObjects/Player/PlayerObject.ts @@ -247,6 +247,7 @@ export class PlayerObject implements IPlayer { getIntelligenceBonus: (weight: number) => number; getCasinoWinnings: () => number; quitJob: (company: string) => void; + hasJob: () => boolean; process: (router: IRouter, numCycles?: number) => void; createHacknetServer: () => HacknetServer; startCreateProgramWork: (router: IRouter, programName: string, time: number, reqLevel: number) => void; @@ -531,6 +532,7 @@ export class PlayerObject implements IPlayer { this.applyForJob = generalMethods.applyForJob; this.getNextCompanyPosition = generalMethods.getNextCompanyPosition; this.quitJob = generalMethods.quitJob; + this.hasJob = generalMethods.hasJob; this.applyForSoftwareJob = generalMethods.applyForSoftwareJob; this.applyForSoftwareConsultantJob = generalMethods.applyForSoftwareConsultantJob; this.applyForItJob = generalMethods.applyForItJob; diff --git a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx index 9847bc170..5d343dfe5 100644 --- a/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx +++ b/src/PersonObjects/Player/PlayerObjectGeneralMethods.tsx @@ -1782,6 +1782,15 @@ export function quitJob(this: IPlayer, company: string): void { delete this.jobs[company]; } +/** + * Method to see if the player has at least one job assigned to them + * @param this The player instance + * @returns Whether the user has at least one job + */ +export function hasJob(this: IPlayer): boolean { + return Boolean(Object.keys(this.jobs).length); +} + export function applyForSoftwareJob(this: IPlayer, sing = false): boolean { return this.applyForJob(CompanyPositions[posNames.SoftwareCompanyPositions[0]], sing); } diff --git a/src/Sidebar/ui/SidebarRoot.tsx b/src/Sidebar/ui/SidebarRoot.tsx index eb0877872..a974fbba9 100644 --- a/src/Sidebar/ui/SidebarRoot.tsx +++ b/src/Sidebar/ui/SidebarRoot.tsx @@ -292,7 +292,7 @@ export function SidebarRoot(props: IProps): React.ReactElement { } else if (event.keyCode === KEY.W && event.altKey) { event.preventDefault(); clickCity(); - } else if (event.keyCode === KEY.J && event.altKey && !event.ctrlKey && !event.metaKey) { + } else if (event.keyCode === KEY.J && event.altKey && !event.ctrlKey && !event.metaKey && props.player.hasJob()) { // ctrl/cmd + alt + j is shortcut to open Chrome dev tools event.preventDefault(); clickJob();