mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 04:35:46 +01:00
IPVGO: Remove opponent from react state (#1222)
This commit is contained in:
parent
f4fcb5cde1
commit
0f23c95737
@ -43,7 +43,6 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
|
|||||||
// Destructure boardState to allow useMemo to trigger correctly
|
// Destructure boardState to allow useMemo to trigger correctly
|
||||||
const traditional = Settings.GoTraditionalStyle;
|
const traditional = Settings.GoTraditionalStyle;
|
||||||
const [showPriorMove, setShowPriorMove] = useState(false);
|
const [showPriorMove, setShowPriorMove] = useState(false);
|
||||||
const [opponent, setOpponent] = useState<GoOpponent>(boardState.ai);
|
|
||||||
const [scoreOpen, setScoreOpen] = useState(false);
|
const [scoreOpen, setScoreOpen] = useState(false);
|
||||||
const [searchOpen, setSearchOpen] = useState(false);
|
const [searchOpen, setSearchOpen] = useState(false);
|
||||||
const [waitingOnAI, setWaitingOnAI] = useState(false);
|
const [waitingOnAI, setWaitingOnAI] = useState(false);
|
||||||
@ -75,7 +74,7 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
|
|||||||
|
|
||||||
// Lock the board when it isn't the player's turn
|
// Lock the board when it isn't the player's turn
|
||||||
const gameOver = boardState.previousPlayer === null;
|
const gameOver = boardState.previousPlayer === null;
|
||||||
const notYourTurn = boardState.previousPlayer === GoColor.black && opponent !== GoOpponent.none;
|
const notYourTurn = boardState.previousPlayer === GoColor.black && Go.currentGame.ai !== GoOpponent.none;
|
||||||
if (notYourTurn) {
|
if (notYourTurn) {
|
||||||
SnackbarEvents.emit(`It is not your turn to play.`, ToastVariant.WARNING, 2000);
|
SnackbarEvents.emit(`It is not your turn to play.`, ToastVariant.WARNING, 2000);
|
||||||
return;
|
return;
|
||||||
@ -94,7 +93,7 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
|
|||||||
const didUpdateBoard = makeMove(boardState, x, y, currentPlayer);
|
const didUpdateBoard = makeMove(boardState, x, y, currentPlayer);
|
||||||
if (didUpdateBoard) {
|
if (didUpdateBoard) {
|
||||||
rerender();
|
rerender();
|
||||||
opponent !== GoOpponent.none && takeAiTurn(boardState);
|
Go.currentGame.ai !== GoOpponent.none && takeAiTurn(boardState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +112,7 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
|
|||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
opponent !== GoOpponent.none && takeAiTurn(boardState);
|
Go.currentGame.ai !== GoOpponent.none && takeAiTurn(boardState);
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,10 +138,9 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
|
|||||||
setSearchOpen(true);
|
setSearchOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetState(newBoardSize = boardSize, newOpponent = opponent) {
|
function resetState(newBoardSize = boardSize, newOpponent = Go.currentGame.ai) {
|
||||||
setScoreOpen(false);
|
setScoreOpen(false);
|
||||||
setSearchOpen(false);
|
setSearchOpen(false);
|
||||||
setOpponent(newOpponent);
|
|
||||||
if (boardState.previousPlayer !== null && boardState.previousBoards.length) {
|
if (boardState.previousPlayer !== null && boardState.previousBoards.length) {
|
||||||
resetWinstreak(boardState.ai, false);
|
resetWinstreak(boardState.ai, false);
|
||||||
}
|
}
|
||||||
@ -173,7 +171,8 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
|
|||||||
const endGameAvailable = boardState.previousPlayer === GoColor.white && boardState.passCount;
|
const endGameAvailable = boardState.previousPlayer === GoColor.white && boardState.passCount;
|
||||||
const noLegalMoves =
|
const noLegalMoves =
|
||||||
boardState.previousPlayer === GoColor.white && !getAllValidMoves(boardState, GoColor.black).length;
|
boardState.previousPlayer === GoColor.white && !getAllValidMoves(boardState, GoColor.black).length;
|
||||||
const disablePassButton = opponent !== GoOpponent.none && boardState.previousPlayer === GoColor.black && waitingOnAI;
|
const disablePassButton =
|
||||||
|
Go.currentGame.ai !== GoOpponent.none && boardState.previousPlayer === GoColor.black && waitingOnAI;
|
||||||
|
|
||||||
const scoreBoxText = boardState.previousBoards.length
|
const scoreBoxText = boardState.previousBoards.length
|
||||||
? `Score: Black: ${score[GoColor.black].sum} White: ${score[GoColor.white].sum}`
|
? `Score: Black: ${score[GoColor.black].sum} White: ${score[GoColor.white].sum}`
|
||||||
@ -206,7 +205,7 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
|
|||||||
onClose={() => setScoreOpen(false)}
|
onClose={() => setScoreOpen(false)}
|
||||||
newSubnet={() => newSubnet()}
|
newSubnet={() => newSubnet()}
|
||||||
finalScore={score}
|
finalScore={score}
|
||||||
opponent={opponent}
|
opponent={Go.currentGame.ai}
|
||||||
></GoScoreModal>
|
></GoScoreModal>
|
||||||
<div className={classes.boardFrame}>
|
<div className={classes.boardFrame}>
|
||||||
{traditional ? (
|
{traditional ? (
|
||||||
@ -219,8 +218,12 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps
|
|||||||
<Box className={`${classes.inlineFlexBox} ${classes.opponentTitle}`}>
|
<Box className={`${classes.inlineFlexBox} ${classes.opponentTitle}`}>
|
||||||
<br />
|
<br />
|
||||||
<Typography variant={"h6"} className={classes.opponentLabel}>
|
<Typography variant={"h6"} className={classes.opponentLabel}>
|
||||||
{opponent !== GoOpponent.none ? "Subnet owner: " : ""}{" "}
|
{Go.currentGame.ai !== GoOpponent.none ? "Subnet owner: " : ""}{" "}
|
||||||
{opponent === GoOpponent.w0r1d_d43m0n ? <CorruptableText content={opponent} spoiler={false} /> : opponent}
|
{Go.currentGame.ai === GoOpponent.w0r1d_d43m0n ? (
|
||||||
|
<CorruptableText content={Go.currentGame.ai} spoiler={false} />
|
||||||
|
) : (
|
||||||
|
Go.currentGame.ai
|
||||||
|
)}
|
||||||
</Typography>
|
</Typography>
|
||||||
<br />
|
<br />
|
||||||
</Box>
|
</Box>
|
||||||
|
Loading…
Reference in New Issue
Block a user