mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-02 05:47:14 +02:00
No more player/router context
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
*/
|
||||
import React from "react";
|
||||
import { Modal } from "../../ui/React/Modal";
|
||||
import { use } from "../../ui/Context";
|
||||
import { Router } from "../../ui/GameRoot";
|
||||
import { Player } from "../../Player";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Button from "@mui/material/Button";
|
||||
import { KEY } from "../../utils/helpers/keyCodes";
|
||||
@@ -16,8 +17,6 @@ interface IProps {
|
||||
}
|
||||
|
||||
export function CreateGangModal(props: IProps): React.ReactElement {
|
||||
const player = use.Player();
|
||||
const router = use.Router();
|
||||
const combatGangText =
|
||||
"This is a COMBAT gang. Members in this gang will have different tasks than HACKING gangs. " +
|
||||
"Compared to hacking gangs, progression with combat gangs can be more difficult as territory management " +
|
||||
@@ -33,9 +32,9 @@ export function CreateGangModal(props: IProps): React.ReactElement {
|
||||
}
|
||||
|
||||
function createGang(): void {
|
||||
player.startGang(props.facName, isHacking());
|
||||
Player.startGang(props.facName, isHacking());
|
||||
props.onClose();
|
||||
router.toGang();
|
||||
Router.toGang();
|
||||
}
|
||||
|
||||
function onKeyUp(event: React.KeyboardEvent): void {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Button, Typography, Box, Paper, Tooltip } from "@mui/material";
|
||||
import React, { useState } from "react";
|
||||
import { GangConstants } from "../../Gang/data/Constants";
|
||||
import { use } from "../../ui/Context";
|
||||
import { Router } from "../../ui/GameRoot";
|
||||
import { Player } from "../../Player";
|
||||
import { Faction } from "../Faction";
|
||||
import { CreateGangModal } from "./CreateGangModal";
|
||||
|
||||
@@ -10,14 +11,12 @@ type IProps = {
|
||||
};
|
||||
|
||||
export function GangButton({ faction }: IProps): React.ReactElement {
|
||||
const player = use.Player();
|
||||
const router = use.Router();
|
||||
const [gangOpen, setGangOpen] = useState(false);
|
||||
|
||||
if (
|
||||
!GangConstants.Names.includes(faction.name) || // not even a gang
|
||||
!player.isAwareOfGang() || // doesn't know about gang
|
||||
(player.inGang() && player.getGangName() !== faction.name) // already in another gang
|
||||
!Player.isAwareOfGang() || // doesn't know about gang
|
||||
(Player.inGang() && Player.getGangName() !== faction.name) // already in another gang
|
||||
) {
|
||||
return <></>;
|
||||
}
|
||||
@@ -29,7 +28,7 @@ export function GangButton({ faction }: IProps): React.ReactElement {
|
||||
description: "",
|
||||
};
|
||||
|
||||
if (player.inGang()) {
|
||||
if (Player.inGang()) {
|
||||
data = {
|
||||
enabled: true,
|
||||
title: "Manage Gang",
|
||||
@@ -38,9 +37,9 @@ export function GangButton({ faction }: IProps): React.ReactElement {
|
||||
};
|
||||
} else {
|
||||
data = {
|
||||
enabled: player.canAccessGang(),
|
||||
enabled: Player.canAccessGang(),
|
||||
title: "Create Gang",
|
||||
tooltip: !player.canAccessGang() ? (
|
||||
tooltip: !Player.canAccessGang() ? (
|
||||
<Typography>Unlocked when reaching {GangConstants.GangKarmaRequirement} karma</Typography>
|
||||
) : (
|
||||
""
|
||||
@@ -51,8 +50,8 @@ export function GangButton({ faction }: IProps): React.ReactElement {
|
||||
|
||||
const manageGang = (): void => {
|
||||
// If player already has a gang, just go to the gang UI
|
||||
if (player.inGang()) {
|
||||
return router.toGang();
|
||||
if (Player.inGang()) {
|
||||
return Router.toGang();
|
||||
}
|
||||
|
||||
setGangOpen(true);
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from "react";
|
||||
import { joinFaction } from "../FactionHelpers";
|
||||
import { Faction } from "../Faction";
|
||||
import { Modal } from "../../ui/React/Modal";
|
||||
import { use } from "../../ui/Context";
|
||||
import { Player } from "../../Player";
|
||||
import { EventEmitter } from "../../utils/EventEmitter";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Button from "@mui/material/Button";
|
||||
@@ -11,11 +11,10 @@ export const InvitationEvent = new EventEmitter<[Faction]>();
|
||||
|
||||
export function InvitationModal(): React.ReactElement {
|
||||
const [faction, setFaction] = useState<Faction | null>(null);
|
||||
const player = use.Player();
|
||||
function join(): void {
|
||||
if (faction === null) return;
|
||||
//Remove from invited factions
|
||||
const i = player.factionInvitations.findIndex((facName) => facName === faction.name);
|
||||
const i = Player.factionInvitations.findIndex((facName) => facName === faction.name);
|
||||
if (i === -1) {
|
||||
console.error("Could not find faction in Player.factionInvitations");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user