From d59601f8485226b172d43b2e4218d9899eaf305f Mon Sep 17 00:00:00 2001 From: theit8514 Date: Wed, 15 Dec 2021 20:48:19 -0500 Subject: [PATCH] Add return value and code style cleanup --- src/Faction/ui/FactionRoot.tsx | 2 +- src/NetscriptFunctions/Singularity.ts | 9 ++++++--- src/ScriptEditor/NetscriptDefinitions.d.ts | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Faction/ui/FactionRoot.tsx b/src/Faction/ui/FactionRoot.tsx index 256efe865..dd43d2f94 100644 --- a/src/Faction/ui/FactionRoot.tsx +++ b/src/Faction/ui/FactionRoot.tsx @@ -82,7 +82,7 @@ function MainPage({ faction, rerender, onAugmentations }: IMainProps): React.Rea setGangOpen(true); } - function startWork() { + function startWork(): void { player.startFocusing(); router.toWork(); } diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 6dfb17205..5ebc5c965 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -627,7 +627,7 @@ export function NetscriptSingularity( helper.checkSingularityAccess("isFocused", 2); return player.focus; }, - setFocus: function(focus: boolean): any { + setFocus: function(focus: boolean): boolean { helper.updateDynamicRam("setFocus", getRamCost("setFocus")); helper.checkSingularityAccess("setFocus", 2); if (!player.isWorking) { @@ -636,13 +636,16 @@ export function NetscriptSingularity( if (!(player.workType == CONSTANTS.WorkTypeFaction || player.workType == CONSTANTS.WorkTypeCompany || player.workType == CONSTANTS.WorkTypeCompanyPartTime)) { throw helper.makeRuntimeErrorMsg("setFocus", "Cannot change focus for current job"); } - if (!player.focus && focus === true) { + if (!player.focus && focus) { player.startFocusing(); Router.toWork(); - } else if (player.focus && focus === false) { + return true; + } else if (player.focus && !focus) { player.stopFocusing(); Router.toTerminal(); + return true; } + return false; }, getStats: function (): any { helper.updateDynamicRam("getStats", getRamCost("getStats")); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index d81149677..bd0dbd032 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -2001,8 +2001,9 @@ export interface Singularity { * @remarks * RAM cost: 0.1 GB * + * @returns True if the focus was changed. */ - setFocus(focus: boolean): void; + setFocus(focus: boolean): boolean; } /**