diff --git a/src/NetscriptFunctions/Grafting.ts b/src/NetscriptFunctions/Grafting.ts index 22d8a0853..94862db15 100644 --- a/src/NetscriptFunctions/Grafting.ts +++ b/src/NetscriptFunctions/Grafting.ts @@ -89,7 +89,6 @@ export function NetscriptGrafting(): InternalAPI { Player.startFocusing(); Router.toPage(Page.Work); } else if (wasFocusing) { - Player.stopFocusing(); Router.toPage(Page.Terminal); } diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 06cb750ea..4fe090f5b 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -283,7 +283,6 @@ export function NetscriptSingularity(): InternalAPI { Player.startFocusing(); Router.toPage(Page.Work); } else if (wasFocusing) { - Player.stopFocusing(); Router.toPage(Page.Terminal); } helpers.log(ctx, () => `Started ${classType} at ${universityName}`); @@ -365,7 +364,6 @@ export function NetscriptSingularity(): InternalAPI { Player.startFocusing(); Router.toPage(Page.Work); } else if (wasFocusing) { - Player.stopFocusing(); Router.toPage(Page.Terminal); } helpers.log(ctx, () => `Started training ${classType} at ${gymName}`); @@ -570,7 +568,6 @@ export function NetscriptSingularity(): InternalAPI { Router.toPage(Page.Work); return true; } else if (Player.focus && !focus) { - Player.stopFocusing(); Router.toPage(Page.Terminal); return true; } @@ -709,7 +706,6 @@ export function NetscriptSingularity(): InternalAPI { Player.startFocusing(); Router.toPage(Page.Work); } else if (wasFocused) { - Player.stopFocusing(); Router.toPage(Page.Terminal); } helpers.log(ctx, () => `Began working at '${companyName}' with position '${jobName}'`); @@ -834,7 +830,6 @@ export function NetscriptSingularity(): InternalAPI { Player.startFocusing(); Router.toPage(Page.Work); } else if (wasFocusing) { - Player.stopFocusing(); Router.toPage(Page.Terminal); } helpers.log(ctx, () => `Started carrying out hacking contracts for '${faction.name}'`); @@ -855,7 +850,6 @@ export function NetscriptSingularity(): InternalAPI { Player.startFocusing(); Router.toPage(Page.Work); } else if (wasFocusing) { - Player.stopFocusing(); Router.toPage(Page.Terminal); } helpers.log(ctx, () => `Started carrying out field missions for '${faction.name}'`); @@ -876,7 +870,6 @@ export function NetscriptSingularity(): InternalAPI { Player.startFocusing(); Router.toPage(Page.Work); } else if (wasFocusing) { - Player.stopFocusing(); Router.toPage(Page.Terminal); } helpers.log(ctx, () => `Started carrying out security work for '${faction.name}'`); @@ -1009,7 +1002,6 @@ export function NetscriptSingularity(): InternalAPI { Player.startFocusing(); Router.toPage(Page.Work); } else if (wasFocusing) { - Player.stopFocusing(); Router.toPage(Page.Terminal); } helpers.log(ctx, () => `Began creating program: '${programName}'`); @@ -1059,7 +1051,6 @@ export function NetscriptSingularity(): InternalAPI { Player.startFocusing(); Router.toPage(Page.Work); } else if (wasFocusing) { - Player.stopFocusing(); Router.toPage(Page.Terminal); } return crimeTime; diff --git a/src/ui/GameRoot.tsx b/src/ui/GameRoot.tsx index 709b143bc..36ff458cf 100644 --- a/src/ui/GameRoot.tsx +++ b/src/ui/GameRoot.tsx @@ -266,6 +266,13 @@ export function GameRoot(): React.ReactElement { } break; } + // If the current page is Page.Work, the player is focusing on their current work. Switching to another page ends + // that focus, so we must call Player.stopFocusing() immediately after Router.toPage() to keep Player.focus in + // sync. Instead of repeating this logic wherever Router.toPage() is called, we should centralize the check and + // the Player.stopFocusing() call here. + if (pageWithContext.page === Page.Work && page !== Page.Work && Player.currentWork && Player.focus) { + Player.stopFocusing(); + } setNextPage({ page, ...context } as PageWithContext); }, back: () => { diff --git a/src/ui/WorkInProgressRoot.tsx b/src/ui/WorkInProgressRoot.tsx index 2a26f6d10..957490ef1 100644 --- a/src/ui/WorkInProgressRoot.tsx +++ b/src/ui/WorkInProgressRoot.tsx @@ -219,7 +219,6 @@ export function WorkInProgressRoot(): React.ReactElement { }, unfocus: () => { Router.toPage(Page.City); - Player.stopFocusing(); }, }, title: `You are attempting ${crime.workName}`, @@ -266,7 +265,6 @@ export function WorkInProgressRoot(): React.ReactElement { }, unfocus: () => { Router.toPage(Page.Location, { location: Locations[classWork.location] }); - Player.stopFocusing(); }, }, title: ( @@ -303,7 +301,6 @@ export function WorkInProgressRoot(): React.ReactElement { }, unfocus: () => { Router.toPage(Page.Terminal); - Player.stopFocusing(); }, }, title: ( @@ -334,7 +331,6 @@ export function WorkInProgressRoot(): React.ReactElement { }, unfocus: () => { Router.toPage(Page.Terminal); - Player.stopFocusing(); }, }, title: ( @@ -388,7 +384,6 @@ export function WorkInProgressRoot(): React.ReactElement { }, unfocus: () => { Router.toPage(Page.Faction, { faction }); - Player.stopFocusing(); }, }, title: ( @@ -439,7 +434,6 @@ export function WorkInProgressRoot(): React.ReactElement { Router.toPage(Page.Job); }, unfocus: () => { - Player.stopFocusing(); Router.toPage(Page.Job); }, },