From 8b3206e1c66c7a4bb2cb42893b0fe8295bdbfced Mon Sep 17 00:00:00 2001
From: catloversg <152669316+catloversg@users.noreply.github.com>
Date: Sat, 8 Jun 2024 03:34:47 +0700
Subject: [PATCH] BLADEBURNER: Add Stop button and refactor code (#1363)
---
src/Bladeburner/ui/ActionHeader.tsx | 55 +++++++++++++++++++++++
src/Bladeburner/ui/BlackOpElem.tsx | 55 +++++------------------
src/Bladeburner/ui/BlackOpPage.tsx | 8 ++--
src/Bladeburner/ui/ContractElem.tsx | 32 ++-----------
src/Bladeburner/ui/GeneralActionElem.tsx | 37 ++-------------
src/Bladeburner/ui/OperationElem.tsx | 57 ++++++------------------
src/Bladeburner/ui/OperationPage.tsx | 4 +-
src/Bladeburner/ui/StartButton.tsx | 6 ++-
src/Bladeburner/ui/StopButton.tsx | 6 ++-
src/Bladeburner/ui/TeamSizeButton.tsx | 2 +-
10 files changed, 104 insertions(+), 158 deletions(-)
create mode 100644 src/Bladeburner/ui/ActionHeader.tsx
diff --git a/src/Bladeburner/ui/ActionHeader.tsx b/src/Bladeburner/ui/ActionHeader.tsx
new file mode 100644
index 000000000..51caf9733
--- /dev/null
+++ b/src/Bladeburner/ui/ActionHeader.tsx
@@ -0,0 +1,55 @@
+import type { Bladeburner } from "../Bladeburner";
+import type { Action } from "../Types";
+
+import React from "react";
+import { Box, Typography } from "@mui/material";
+import { CopyableText } from "../../ui/React/CopyableText";
+import { createProgressBarText } from "../../utils/helpers/createProgressBarText";
+import { StartButton } from "./StartButton";
+import { StopButton } from "./StopButton";
+import { TeamSizeButton } from "./TeamSizeButton";
+
+import { formatNumberNoSuffix } from "../../ui/formatNumber";
+import { BlackOperation, Operation } from "../Actions";
+
+interface ActionHeaderProps {
+ bladeburner: Bladeburner;
+ action: Action;
+ rerender: () => void;
+}
+export function ActionHeader({ bladeburner, action, rerender }: ActionHeaderProps): React.ReactElement {
+ const isActive = action.name === bladeburner.action?.name;
+ const computedActionTimeCurrent = Math.min(
+ bladeburner.actionTimeCurrent + bladeburner.actionTimeOverflow,
+ bladeburner.actionTimeToComplete,
+ );
+ const allowTeam = action instanceof Operation || action instanceof BlackOperation;
+
+ if (isActive) {
+ return (
+ <>
+
+
+
+
+
+ (IN PROGRESS - {formatNumberNoSuffix(computedActionTimeCurrent, 0)} /{" "}
+ {formatNumberNoSuffix(bladeburner.actionTimeToComplete, 0)})
+
+
+ {createProgressBarText({
+ progress: computedActionTimeCurrent / bladeburner.actionTimeToComplete,
+ })}
+
+ >
+ );
+ }
+
+ return (
+
+
+
+ {allowTeam && }
+
+ );
+}
diff --git a/src/Bladeburner/ui/BlackOpElem.tsx b/src/Bladeburner/ui/BlackOpElem.tsx
index fdf524313..5eed70a7a 100644
--- a/src/Bladeburner/ui/BlackOpElem.tsx
+++ b/src/Bladeburner/ui/BlackOpElem.tsx
@@ -7,72 +7,41 @@ import { Paper, Typography } from "@mui/material";
import { Player } from "@player";
import { formatNumberNoSuffix } from "../../ui/formatNumber";
import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions";
-import { createProgressBarText } from "../../utils/helpers/createProgressBarText";
-import { TeamSizeButton } from "./TeamSizeButton";
-import { CopyableText } from "../../ui/React/CopyableText";
import { SuccessChance } from "./SuccessChance";
-import { StartButton } from "./StartButton";
import { useRerender } from "../../ui/React/hooks";
+import { ActionHeader } from "./ActionHeader";
interface BlackOpElemProps {
bladeburner: Bladeburner;
- blackOp: BlackOperation;
+ action: BlackOperation;
}
-export function BlackOpElem({ bladeburner, blackOp }: BlackOpElemProps): React.ReactElement {
+export function BlackOpElem({ bladeburner, action }: BlackOpElemProps): React.ReactElement {
const rerender = useRerender();
- const isCompleted = bladeburner.numBlackOpsComplete > blackOp.n;
+ const isCompleted = bladeburner.numBlackOpsComplete > action.n;
if (isCompleted) {
return (
- {blackOp.name} (COMPLETED)
+ {action.name} (COMPLETED)
);
}
- const isActive = bladeburner.action?.name === blackOp.name;
- const actionTime = blackOp.getActionTime(bladeburner, Player);
- const hasReqdRank = bladeburner.rank >= blackOp.reqdRank;
- const computedActionTimeCurrent = Math.min(
- bladeburner.actionTimeCurrent + bladeburner.actionTimeOverflow,
- bladeburner.actionTimeToComplete,
- );
+ const actionTime = action.getActionTime(bladeburner, Player);
+ const hasRequiredRank = bladeburner.rank >= action.reqdRank;
return (
- {isActive ? (
- <>
-
-
- (IN PROGRESS - {formatNumberNoSuffix(computedActionTimeCurrent, 0)} /{" "}
- {formatNumberNoSuffix(bladeburner.actionTimeToComplete, 0)})
-
-
- {createProgressBarText({
- progress: computedActionTimeCurrent / bladeburner.actionTimeToComplete,
- })}
-
- >
- ) : (
- <>
-
-
-
-
- >
- )}
-
+
+ {action.desc}
- {blackOp.desc}
-
-
-
- Required Rank: {formatNumberNoSuffix(blackOp.reqdRank, 0)}
+
+ Required Rank: {formatNumberNoSuffix(action.reqdRank, 0)}
-
+
Time Required: {convertTimeMsToTimeElapsedString(actionTime * 1000)}
diff --git a/src/Bladeburner/ui/BlackOpPage.tsx b/src/Bladeburner/ui/BlackOpPage.tsx
index c0d5aadcc..b53b379c4 100644
--- a/src/Bladeburner/ui/BlackOpPage.tsx
+++ b/src/Bladeburner/ui/BlackOpPage.tsx
@@ -1,6 +1,6 @@
import type { Bladeburner } from "../Bladeburner";
-import * as React from "react";
+import React from "react";
import { Button, Typography } from "@mui/material";
import { FactionName } from "@enums";
import { BlackOpElem } from "./BlackOpElem";
@@ -14,7 +14,7 @@ interface BlackOpPageProps {
}
export function BlackOpPage({ bladeburner }: BlackOpPageProps): React.ReactElement {
- const blackOps = blackOpsArray.slice(0, bladeburner.numBlackOpsComplete + 1).reverse();
+ const blackOperations = blackOpsArray.slice(0, bladeburner.numBlackOpsComplete + 1).reverse();
return (
<>
@@ -38,8 +38,8 @@ export function BlackOpPage({ bladeburner }: BlackOpPageProps): React.ReactEleme
) : (
<>
- {blackOps.map((blackOp) => (
-
+ {blackOperations.map((blackOperation) => (
+
))}
>
)}
diff --git a/src/Bladeburner/ui/ContractElem.tsx b/src/Bladeburner/ui/ContractElem.tsx
index f587f5d5b..8ad66dfc7 100644
--- a/src/Bladeburner/ui/ContractElem.tsx
+++ b/src/Bladeburner/ui/ContractElem.tsx
@@ -2,18 +2,16 @@ import type { Bladeburner } from "../Bladeburner";
import type { Contract } from "../Actions/Contract";
import React from "react";
-import { createProgressBarText } from "../../utils/helpers/createProgressBarText";
import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions";
import { Player } from "@player";
import { SuccessChance } from "./SuccessChance";
-import { CopyableText } from "../../ui/React/CopyableText";
import { ActionLevel } from "./ActionLevel";
import { Autolevel } from "./Autolevel";
-import { StartButton } from "./StartButton";
-import { formatNumberNoSuffix, formatBigNumber } from "../../ui/formatNumber";
+import { formatBigNumber } from "../../ui/formatNumber";
import { Paper, Typography } from "@mui/material";
import { useRerender } from "../../ui/React/hooks";
import { getEnumHelper } from "../../utils/EnumHelper";
+import { ActionHeader } from "./ActionHeader";
interface ContractElemProps {
bladeburner: Bladeburner;
@@ -25,38 +23,14 @@ export function ContractElem({ bladeburner, action }: ContractElemProps): React.
// Temp special return
if (!getEnumHelper("BladeContractName").isMember(action.name)) return <>>;
const isActive = action.name === bladeburner.action?.name;
- const computedActionTimeCurrent = Math.min(
- bladeburner.actionTimeCurrent + bladeburner.actionTimeOverflow,
- bladeburner.actionTimeToComplete,
- );
const actionTime = action.getActionTime(bladeburner, Player);
return (
- {isActive ? (
- <>
-
-
- (IN PROGRESS - {formatNumberNoSuffix(computedActionTimeCurrent, 0)} /{" "}
- {formatNumberNoSuffix(bladeburner.actionTimeToComplete, 0)})
-
-
- {createProgressBarText({
- progress: computedActionTimeCurrent / bladeburner.actionTimeToComplete,
- })}
-
- >
- ) : (
- <>
-
-
- >
- )}
-
+
-
{action.desc}
diff --git a/src/Bladeburner/ui/GeneralActionElem.tsx b/src/Bladeburner/ui/GeneralActionElem.tsx
index d35a72d9e..006b479bf 100644
--- a/src/Bladeburner/ui/GeneralActionElem.tsx
+++ b/src/Bladeburner/ui/GeneralActionElem.tsx
@@ -2,15 +2,12 @@ import type { Bladeburner } from "../Bladeburner";
import type { GeneralAction } from "../Actions/GeneralAction";
import React from "react";
-import { createProgressBarText } from "../../utils/helpers/createProgressBarText";
import { formatNumberNoSuffix } from "../../ui/formatNumber";
import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions";
import { Player } from "@player";
-import { CopyableText } from "../../ui/React/CopyableText";
-import { StartButton } from "./StartButton";
-import { StopButton } from "./StopButton";
-import { Box, Paper, Typography } from "@mui/material";
+import { Paper, Typography } from "@mui/material";
import { useRerender } from "../../ui/React/hooks";
+import { ActionHeader } from "./ActionHeader";
interface GeneralActionElemProps {
bladeburner: Bladeburner;
@@ -19,44 +16,16 @@ interface GeneralActionElemProps {
export function GeneralActionElem({ bladeburner, action }: GeneralActionElemProps): React.ReactElement {
const rerender = useRerender();
- const isActive = action.name === bladeburner.action?.name;
- const computedActionTimeCurrent = Math.min(
- bladeburner.actionTimeCurrent + bladeburner.actionTimeOverflow,
- bladeburner.actionTimeToComplete,
- );
const actionTime = action.getActionTime(bladeburner, Player);
const successChance =
action.name === "Recruitment" ? Math.max(0, Math.min(bladeburner.getRecruitmentSuccessChance(Player), 1)) : -1;
return (
- {isActive ? (
- <>
-
-
-
-
-
- (IN PROGRESS - {formatNumberNoSuffix(computedActionTimeCurrent, 0)} /{" "}
- {formatNumberNoSuffix(bladeburner.actionTimeToComplete, 0)})
-
-
- {createProgressBarText({
- progress: computedActionTimeCurrent / bladeburner.actionTimeToComplete,
- })}
-
- >
- ) : (
-
-
-
-
- )}
-
+
{action.desc}
-
Time Required: {convertTimeMsToTimeElapsedString(actionTime * 1000)}
{successChance !== -1 && (
diff --git a/src/Bladeburner/ui/OperationElem.tsx b/src/Bladeburner/ui/OperationElem.tsx
index 487456410..83244ea4d 100644
--- a/src/Bladeburner/ui/OperationElem.tsx
+++ b/src/Bladeburner/ui/OperationElem.tsx
@@ -5,76 +5,47 @@ import React from "react";
import { Paper, Typography } from "@mui/material";
import { Player } from "@player";
-import { createProgressBarText } from "../../utils/helpers/createProgressBarText";
import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions";
import { SuccessChance } from "./SuccessChance";
import { ActionLevel } from "./ActionLevel";
import { Autolevel } from "./Autolevel";
-import { StartButton } from "./StartButton";
-import { TeamSizeButton } from "./TeamSizeButton";
-import { CopyableText } from "../../ui/React/CopyableText";
-import { formatNumberNoSuffix, formatBigNumber } from "../../ui/formatNumber";
+import { formatBigNumber } from "../../ui/formatNumber";
import { useRerender } from "../../ui/React/hooks";
import { BladeActionType } from "@enums";
+import { ActionHeader } from "./ActionHeader";
interface OperationElemProps {
bladeburner: Bladeburner;
- operation: Operation;
+ action: Operation;
}
-export function OperationElem({ bladeburner, operation }: OperationElemProps): React.ReactElement {
+export function OperationElem({ bladeburner, action }: OperationElemProps): React.ReactElement {
const rerender = useRerender();
- const isActive =
- bladeburner.action?.type === BladeActionType.operation && operation.name === bladeburner.action?.name;
- const computedActionTimeCurrent = Math.min(
- bladeburner.actionTimeCurrent + bladeburner.actionTimeOverflow,
- bladeburner.actionTimeToComplete,
- );
- const actionTime = operation.getActionTime(bladeburner, Player);
+ const isActive = bladeburner.action?.type === BladeActionType.operation && action.name === bladeburner.action?.name;
+ const actionTime = action.getActionTime(bladeburner, Player);
return (
- {isActive ? (
- <>
-
- (IN PROGRESS - {formatNumberNoSuffix(computedActionTimeCurrent, 0)}{" "}
- / {formatNumberNoSuffix(bladeburner.actionTimeToComplete, 0)})
-
-
- {createProgressBarText({
- progress: computedActionTimeCurrent / bladeburner.actionTimeToComplete,
- })}
-
- >
- ) : (
- <>
-
-
-
- >
- )}
-
-
-
-
+
+
- {operation.desc}
+ {action.desc}
-
+
Time Required: {convertTimeMsToTimeElapsedString(actionTime * 1000)}
- Operations remaining: {formatBigNumber(Math.floor(operation.count))}
+ Operations remaining: {formatBigNumber(Math.floor(action.count))}
- Successes: {formatBigNumber(operation.successes)}
+ Successes: {formatBigNumber(action.successes)}
- Failures: {formatBigNumber(operation.failures)}
+ Failures: {formatBigNumber(action.failures)}
-
+
);
}
diff --git a/src/Bladeburner/ui/OperationPage.tsx b/src/Bladeburner/ui/OperationPage.tsx
index 4559dcee6..8682cf2bf 100644
--- a/src/Bladeburner/ui/OperationPage.tsx
+++ b/src/Bladeburner/ui/OperationPage.tsx
@@ -1,6 +1,6 @@
import type { Bladeburner } from "../Bladeburner";
-import * as React from "react";
+import React from "react";
import { OperationElem } from "./OperationElem";
import { Typography } from "@mui/material";
@@ -30,7 +30,7 @@ export function OperationPage({ bladeburner }: OperationPageProps): React.ReactE
difficult, but grant more rank and experience.
{operations.map((operation) => (
-
+
))}
>
);
diff --git a/src/Bladeburner/ui/StartButton.tsx b/src/Bladeburner/ui/StartButton.tsx
index d307ed4db..2c7109919 100644
--- a/src/Bladeburner/ui/StartButton.tsx
+++ b/src/Bladeburner/ui/StartButton.tsx
@@ -20,7 +20,11 @@ export function StartButton({ bladeburner, action, rerender }: StartButtonProps)
}
return (
-
+
Start
);
diff --git a/src/Bladeburner/ui/StopButton.tsx b/src/Bladeburner/ui/StopButton.tsx
index 75bf88f41..58d4764c4 100644
--- a/src/Bladeburner/ui/StopButton.tsx
+++ b/src/Bladeburner/ui/StopButton.tsx
@@ -13,5 +13,9 @@ export function StopButton({ bladeburner, rerender }: StopButtonProps): React.Re
rerender();
}
- return ;
+ return (
+
+ );
}
diff --git a/src/Bladeburner/ui/TeamSizeButton.tsx b/src/Bladeburner/ui/TeamSizeButton.tsx
index 76913c9a4..bb1cf4ab1 100644
--- a/src/Bladeburner/ui/TeamSizeButton.tsx
+++ b/src/Bladeburner/ui/TeamSizeButton.tsx
@@ -15,7 +15,7 @@ export function TeamSizeButton({ action, bladeburner }: TeamSizeButtonProps): Re
return (
<>
-