From b9cc6321fd7d602c535b153481ed5f3b4c3b0345 Mon Sep 17 00:00:00 2001 From: nickofolas <60761231+nickofolas@users.noreply.github.com> Date: Fri, 8 Apr 2022 10:49:10 -0500 Subject: [PATCH] SF -1 related fixes --- src/Augmentation/ui/SourceFiles.tsx | 66 ++++++++++++++--------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/src/Augmentation/ui/SourceFiles.tsx b/src/Augmentation/ui/SourceFiles.tsx index 895119091..53c9e9102 100644 --- a/src/Augmentation/ui/SourceFiles.tsx +++ b/src/Augmentation/ui/SourceFiles.tsx @@ -14,11 +14,12 @@ interface SfMinus1 { info: React.ReactElement; n: number; name: string; + lvl: number; } const safeGetSf = (sfNum: number): SourceFile | SfMinus1 | null => { if (sfNum === -1) { - return { + const sfMinus1: SfMinus1 = { info: ( <> This Source-File can only be acquired with obscure knowledge of the game, javascript, and the web ecosystem. @@ -42,6 +43,7 @@ const safeGetSf = (sfNum: number): SourceFile | SfMinus1 | null => { n: -1, name: "Source-File -1: Exploits in the BitNodes", }; + return sfMinus1; } const srcFileKey = "SourceFile" + sfNum; @@ -53,9 +55,31 @@ const safeGetSf = (sfNum: number): SourceFile | SfMinus1 | null => { return sfObj; }; +const getMaxLevel = (sfObj: SourceFile | SfMinus1): string | number => { + let maxLevel; + switch (sfObj.n) { + case 12: + maxLevel = "∞"; + break; + case -1: + maxLevel = Object.keys(Exploit).length; + break; + default: + maxLevel = "3"; + } + return maxLevel; +}; + export function SourceFilesElement(): React.ReactElement { const sourceSfs = Player.sourceFiles.slice(); const exploits = Player.exploits; + // Create a fake SF for -1, if "owned" + if (exploits.length > 0) { + sourceSfs.unshift({ + n: -1, + lvl: exploits.length, + }); + } if (Settings.OwnedAugmentationsOrder === OwnedAugmentationsOrderSetting.Alphabetically) { sourceSfs.sort((sf1, sf2) => { @@ -63,12 +87,12 @@ export function SourceFilesElement(): React.ReactElement { }); } - const [selectedSf, setSelectedSf] = useState(sourceSfs[0]); - if (sourceSfs.length === 0) { return <>; } + const [selectedSf, setSelectedSf] = useState(sourceSfs[0]); + return ( @@ -80,29 +104,11 @@ export function SourceFilesElement(): React.ReactElement { sx={{ height: 400, overflowY: "scroll", borderRight: `1px solid ${Settings.theme.welllight}` }} disablePadding > - {exploits.length > 0 && ( - setSelectedSf({ n: -1, lvl: exploits.length })} - selected={selectedSf.n === -1} - sx={{ py: 0 }} - > - Source-File -1: Exploits in the BitNodes} - secondary={ - - Level {exploits.length} / {Object.keys(Exploit).length} - - } - /> - - )} - {sourceSfs.map((e, i) => { const sfObj = safeGetSf(e.n); if (!sfObj) return; - const maxLevel = sfObj?.n === 12 ? "∞" : "3"; + + const maxLevel = getMaxLevel(sfObj); return ( setSelectedSf(e)} selected={selectedSf === e} sx={{ py: 0 }}> @@ -129,24 +135,14 @@ export function SourceFilesElement(): React.ReactElement { const sfObj = safeGetSf(selectedSf.n); if (!sfObj) return; - let maxLevel; - switch (sfObj?.n) { - case 12: - maxLevel = "∞"; - break; - case -1: - maxLevel = Object.keys(Exploit).length; - break; - default: - maxLevel = "3"; - } + const maxLevel = getMaxLevel(sfObj); return ( <> Level {selectedSf.lvl} / {maxLevel}

- {sfObj?.info} + {sfObj.info} ); })()}