From e1741778f937a4294fba57035bc09ae314b65c07 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Wed, 22 Sep 2021 02:56:15 -0400 Subject: [PATCH] add new sort option --- src/Faction/ui/AugmentationsPage.tsx | 42 +++++++++++++++++++++ src/Faction/ui/PurchaseableAugmentation.tsx | 32 ++++------------ src/Settings/SettingEnums.ts | 1 + 3 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/Faction/ui/AugmentationsPage.tsx b/src/Faction/ui/AugmentationsPage.tsx index 1c5116a2f..2e5db62be 100644 --- a/src/Faction/ui/AugmentationsPage.tsx +++ b/src/Faction/ui/AugmentationsPage.tsx @@ -10,6 +10,7 @@ import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; import { Faction } from "../../Faction/Faction"; import { PurchaseAugmentationsOrderSetting } from "../../Settings/SettingEnums"; import { Settings } from "../../Settings/Settings"; +import { hasAugmentationPrereqs } from "../FactionHelpers"; import { StdButton } from "../../ui/React/StdButton"; import { use } from "../../ui/Context"; @@ -59,6 +60,9 @@ export function AugmentationsPage(props: IProps): React.ReactElement { case PurchaseAugmentationsOrderSetting.Reputation: { return getAugsSortedByReputation(); } + case PurchaseAugmentationsOrderSetting.Purchasable: { + return getAugsSortedByPurchasable(); + } default: return getAugsSortedByDefault(); } @@ -79,6 +83,41 @@ export function AugmentationsPage(props: IProps): React.ReactElement { return augs; } + function getAugsSortedByPurchasable(): string[] { + const augs = getAugs(); + function canBuy(augName: string): boolean { + const aug = Augmentations[augName]; + const moneyCost = aug.baseCost * props.faction.getInfo().augmentationPriceMult; + const repCost = aug.baseRepRequirement * props.faction.getInfo().augmentationRepRequirementMult; + const hasReq = props.faction.playerReputation >= repCost; + const hasRep = hasAugmentationPrereqs(aug); + const hasCost = + aug.baseCost !== 0 && player.money.gt(aug.baseCost * props.faction.getInfo().augmentationPriceMult); + return hasCost && hasReq && hasRep; + } + const buy = augs.filter(canBuy).sort((augName1, augName2) => { + const aug1 = Augmentations[augName1], + aug2 = Augmentations[augName2]; + if (aug1 == null || aug2 == null) { + throw new Error("Invalid Augmentation Names"); + } + + return aug1.baseCost - aug2.baseCost; + }); + const cantBuy = augs + .filter((aug) => !canBuy(aug)) + .sort((augName1, augName2) => { + const aug1 = Augmentations[augName1], + aug2 = Augmentations[augName2]; + if (aug1 == null || aug2 == null) { + throw new Error("Invalid Augmentation Names"); + } + return aug1.baseRepRequirement - aug2.baseRepRequirement; + }); + + return buy.concat(cantBuy); + } + function getAugsSortedByReputation(): string[] { const augs = getAugs(); augs.sort((augName1, augName2) => { @@ -148,6 +187,9 @@ export function AugmentationsPage(props: IProps): React.ReactElement { +
diff --git a/src/Faction/ui/PurchaseableAugmentation.tsx b/src/Faction/ui/PurchaseableAugmentation.tsx index 98492fd61..f4a0d99d8 100644 --- a/src/Faction/ui/PurchaseableAugmentation.tsx +++ b/src/Faction/ui/PurchaseableAugmentation.tsx @@ -55,12 +55,14 @@ function Requirements(props: IReqProps): React.ReactElement { return ( - + - Requires {Reputation(props.rep)} faction reputation + + Requires {Reputation(props.rep)} faction reputation + ); @@ -78,24 +80,6 @@ export function PurchaseableAugmentation(props: IProps): React.ReactElement { const aug = Augmentations[props.augName]; if (aug == null) throw new Error(`aug ${props.augName} does not exists`); - function getMoneyCost(): number { - return aug.baseCost * props.faction.getInfo().augmentationPriceMult; - } - - function getRepCost(): number { - return aug.baseRepRequirement * props.faction.getInfo().augmentationRepRequirementMult; - } - - // Whether the player has the prerequisite Augmentations - function hasPrereqs(): boolean { - return hasAugmentationPrereqs(aug); - } - - // Whether the player has enough rep for this Augmentation - function hasReputation(): boolean { - return props.faction.playerReputation >= getRepCost(); - } - // Whether the player has this augmentations (purchased OR installed) function owned(): boolean { let owned = false; @@ -123,10 +107,10 @@ export function PurchaseableAugmentation(props: IProps): React.ReactElement { return <>; } - const moneyCost = getMoneyCost(); - const repCost = getRepCost(); - const hasReq = hasPrereqs(); - const hasRep = hasReputation(); + const moneyCost = aug.baseCost * props.faction.getInfo().augmentationPriceMult; + const repCost = aug.baseRepRequirement * props.faction.getInfo().augmentationRepRequirementMult; + const hasReq = hasAugmentationPrereqs(aug); + const hasRep = props.faction.playerReputation >= repCost; const hasCost = aug.baseCost !== 0 && props.p.money.gt(aug.baseCost * props.faction.getInfo().augmentationPriceMult); // Determine UI properties diff --git a/src/Settings/SettingEnums.ts b/src/Settings/SettingEnums.ts index 05d08b80c..098e12585 100644 --- a/src/Settings/SettingEnums.ts +++ b/src/Settings/SettingEnums.ts @@ -96,6 +96,7 @@ export enum PurchaseAugmentationsOrderSetting { Cost, Default, Reputation, + Purchasable, } /**