TYPESAFETY: FactionName (#644)

This commit is contained in:
Snarling
2023-06-25 22:53:35 -04:00
committed by GitHub
parent 1de676972f
commit 9a0a843ffc
31 changed files with 295 additions and 751 deletions
@@ -1,7 +1,4 @@
import React, { useState } from "react";
import { Player } from "@player";
import { FactionName } from "@enums";
import {
Accordion,
AccordionSummary,
@@ -11,27 +8,33 @@ import {
IconButton,
InputLabel,
MenuItem,
Select,
SelectChangeEvent,
Typography,
} from "@mui/material";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import Select, { SelectChangeEvent } from "@mui/material/Select";
import { Adjuster } from "./Adjuster";
import { Factions as AllFaction } from "../../Faction/Factions";
import ReplyAllIcon from "@mui/icons-material/ReplyAll";
import ReplyIcon from "@mui/icons-material/Reply";
import { Player } from "@player";
import { FactionName } from "@enums";
import { Adjuster } from "./Adjuster";
import { Factions } from "../../Faction/Factions";
import { getRecordValues } from "../../Types/Record";
import { getEnumHelper } from "../../utils/EnumHelper";
const bigNumber = 1e12;
export function Factions(): React.ReactElement {
const [faction, setFaction] = useState(FactionName.Illuminati as string);
export function FactionsDev(): React.ReactElement {
const [factionName, setFactionName] = useState(FactionName.Illuminati);
function setFactionDropdown(event: SelectChangeEvent): void {
setFaction(event.target.value);
if (!getEnumHelper("FactionName").isMember(event.target.value)) return;
setFactionName(event.target.value);
}
function receiveInvite(): void {
Player.receiveInvite(faction);
Player.receiveInvite(factionName);
}
function receiveAllInvites(): void {
@@ -40,57 +43,53 @@ export function Factions(): React.ReactElement {
function modifyFactionRep(modifier: number): (x: number) => void {
return function (reputation: number): void {
const fac = AllFaction[faction];
if (fac != null && !isNaN(reputation)) {
const fac = Factions[factionName];
if (!isNaN(reputation)) {
fac.playerReputation += reputation * modifier;
}
};
}
function resetFactionRep(): void {
const fac = AllFaction[faction];
if (fac != null) {
fac.playerReputation = 0;
}
const fac = Factions[factionName];
fac.playerReputation = 0;
}
function modifyFactionFavor(modifier: number): (x: number) => void {
return function (favor: number): void {
const fac = AllFaction[faction];
if (fac != null && !isNaN(favor)) {
const fac = Factions[factionName];
if (!isNaN(favor)) {
fac.favor += favor * modifier;
}
};
}
function resetFactionFavor(): void {
const fac = AllFaction[faction];
if (fac != null) {
fac.favor = 0;
}
const fac = Factions[factionName];
fac.favor = 0;
}
function tonsOfRep(): void {
for (const i of Object.keys(AllFaction)) {
AllFaction[i].playerReputation = bigNumber;
for (const faction of getRecordValues(Factions)) {
faction.playerReputation = bigNumber;
}
}
function resetAllRep(): void {
for (const i of Object.keys(AllFaction)) {
AllFaction[i].playerReputation = 0;
for (const faction of getRecordValues(Factions)) {
faction.playerReputation = 0;
}
}
function tonsOfFactionFavor(): void {
for (const i of Object.keys(AllFaction)) {
AllFaction[i].favor = bigNumber;
for (const faction of getRecordValues(Factions)) {
faction.favor = bigNumber;
}
}
function resetAllFactionFavor(): void {
for (const i of Object.keys(AllFaction)) {
AllFaction[i].favor = 0;
for (const faction of getRecordValues(Factions)) {
faction.favor = 0;
}
}
@@ -113,7 +112,7 @@ export function Factions(): React.ReactElement {
labelId="factions-select"
id="factions-dropdown"
onChange={setFactionDropdown}
value={faction}
value={factionName}
startAdornment={
<>
<IconButton onClick={receiveAllInvites} size="large" arial-label="receive-all-invitation">
@@ -125,7 +124,7 @@ export function Factions(): React.ReactElement {
</>
}
>
{Object.values(AllFaction).map((faction) => (
{Object.values(Factions).map((faction) => (
<MenuItem key={faction.name} value={faction.name}>
{faction.name}
</MenuItem>
+21 -10
View File
@@ -1,24 +1,31 @@
import React, { useEffect, useState } from "react";
import Accordion from "@mui/material/Accordion";
import AccordionSummary from "@mui/material/AccordionSummary";
import AccordionDetails from "@mui/material/AccordionDetails";
import {
Accordion,
AccordionSummary,
AccordionDetails,
Button,
MenuItem,
Select,
SelectChangeEvent,
TextField,
Typography,
} from "@mui/material";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import { Money } from "../../ui/React/Money";
import { Player } from "@player";
import { FactionName } from "@enums";
import { Money } from "../../ui/React/Money";
import { Router } from "../../ui/GameRoot";
import { MenuItem, SelectChangeEvent, TextField, Select } from "@mui/material";
import { Bladeburner } from "../../Bladeburner/Bladeburner";
import { GangConstants } from "../../Gang/data/Constants";
import { FactionName } from "@enums";
import { checkForMessagesToSend } from "../../Message/MessageHelpers";
import { ThemeEvents } from "../../Themes/ui/Theme";
import { getEnumHelper } from "../../utils/EnumHelper";
export function General(): React.ReactElement {
const [error, setError] = useState(false);
const [corporationName, setCorporationName] = useState("");
const [gangFaction, setGangFaction] = useState("Slum Snakes");
const [gangFaction, setGangFaction] = useState(FactionName.SlumSnakes);
const [devMoney, setDevMoney] = useState(0);
// Money functions
@@ -71,7 +78,11 @@ export function General(): React.ReactElement {
// Rerender so the gang menu option will be removed immediately on the devmenu page selection
ThemeEvents.emit();
};
const setGangFactionDropdown = (event: SelectChangeEvent) => setGangFaction(event.target.value);
const setGangFactionDropdown = (event: SelectChangeEvent) => {
// Todo: Make this a more specific check when a GangName enumlike is added
if (!getEnumHelper("FactionName").isMember(event.target.value)) return;
setGangFaction(event.target.value);
};
// Misc functions
const checkMessages = () => checkForMessagesToSend();