Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Sleeves UI shows and sets wrong task #1807

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const CONSTANTS = {

// Also update Documentation/doc/changelog.md when appropriate (when doing a release)
LatestUpdate: `
## v2.7.0 Dev: Last updated 27 November 2024
## v2.7.0 Dev: Last updated 28 November 2024

### MAJOR ADDITIONS

Expand Down Expand Up @@ -275,7 +275,8 @@ export const CONSTANTS = {
- Remove WD from Hashnet server list if TRP not installed (@gmcew)
- Deduct karma when successfully completing action involving killing (@catloversg)
- Fix: Hashserver UI shows wrong server list when purchasing upgrades (@catloversg)
- Fix wrong initial productionMult of new division (@catloversg)
- Fix: Wrong initial productionMult of new division (@catloversg)
- Fix: Sleeves UI shows and sets wrong task (@catloversg)

### CODEBASE/REFACTOR

Expand Down Expand Up @@ -330,5 +331,6 @@ export const CONSTANTS = {
- Fix: Generic Reviver does not handle Message class (@catloversg)
- Add tests for b1tflum3 and destroyW0r1dD43m0n API (@catloversg)
- Multiple large refactors to savegame loading for better validation and safety (@catloversg)
- Enable new lint rules (@catloversg)
`,
} as const;
8 changes: 6 additions & 2 deletions src/PersonObjects/Sleeve/ui/SleeveElem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Button, Paper, Tooltip, Typography } from "@mui/material";
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { CrimeType, FactionWorkType } from "@enums";
import { CONSTANTS } from "../../../Constants";
import { Player } from "@player";
Expand All @@ -9,7 +9,7 @@ import { Sleeve } from "../Sleeve";
import { MoreStatsModal } from "./MoreStatsModal";
import { SleeveAugmentationsModal } from "./SleeveAugmentationsModal";
import { EarningsElement, StatsElement } from "./StatsElement";
import { TaskSelector } from "./TaskSelector";
import { calculateABC, TaskSelector } from "./TaskSelector";
import { TravelModal } from "./TravelModal";
import { findCrime } from "../../../Crime/CrimeHelpers";
import { SleeveWorkType } from "../Work/Work";
Expand Down Expand Up @@ -85,6 +85,10 @@ export function SleeveElem(props: SleeveElemProps): React.ReactElement {

const [abc, setABC] = useState(["Idle", "------", "------"]);

useEffect(() => {
setABC(calculateABC(props.sleeve));
}, [props.sleeve, props.sleeve.currentWork]);

function setTask(): void {
switch (abc[0]) {
case "Idle":
Expand Down
20 changes: 13 additions & 7 deletions src/PersonObjects/Sleeve/ui/TaskSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Sleeve } from "../Sleeve";

import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { MenuItem, Select, SelectChangeEvent } from "@mui/material";

import { Player } from "@player";
Expand Down Expand Up @@ -42,7 +42,7 @@ const bladeburnerSelectorOptions: string[] = [

interface IProps {
sleeve: Sleeve;
setABC: (abc: string[]) => void;
setABC: (abc: [string, string, string]) => void;
}

interface ITaskDetails {
Expand Down Expand Up @@ -247,7 +247,7 @@ const canDo: {
Synchronize: (sleeve: Sleeve) => sleeve.sync < 100,
};

function getABC(sleeve: Sleeve): [string, string, string] {
export function calculateABC(sleeve: Sleeve): [string, string, string] {
const work = sleeve.currentWork;
if (work === null) return ["Idle", "------", "------"];
switch (work.type) {
Expand Down Expand Up @@ -290,10 +290,16 @@ function getABC(sleeve: Sleeve): [string, string, string] {
}

export function TaskSelector(props: IProps): React.ReactElement {
const abc = getABC(props.sleeve);
const [s0, setS0] = useState(abc[0]);
const [s1, setS1] = useState(abc[1]);
const [s2, setS2] = useState(abc[2]);
const [s0, setS0] = useState("Idle");
const [s1, setS1] = useState("------");
const [s2, setS2] = useState("------");

useEffect(() => {
catloversg marked this conversation as resolved.
Show resolved Hide resolved
const abc = calculateABC(props.sleeve);
setS0(abc[0]);
setS1(abc[1]);
setS2(abc[2]);
}, [props.sleeve, props.sleeve.currentWork]);

const validActions = Object.keys(canDo).filter((k) => (canDo[k] as (sleeve: Sleeve) => boolean)(props.sleeve));

Expand Down