Skip to content

Commit

Permalink
Improve titles, move canUndo CurrentStep check into canUndoAction
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaMulein committed Oct 16, 2024
1 parent e062c67 commit 31e943c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 21 deletions.
6 changes: 1 addition & 5 deletions src/components/DominionAssistant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ const DominionAssistant: React.FC<DominionAssistantProps> = ({ route, navigation
const { showAlert } = useAlert();

useEffect(() => {
setCanUndo(
gameState.currentStep === CurrentStep.GameScreen
? canUndoAction(gameState, gameState.log.length - 1)
: false
);
setCanUndo(canUndoAction(gameState, gameState.log.length - 1));
}, [gameState, gameState.log]);

const undoLastAction = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/GameScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const ButtonContainer = styled(Box)(({ theme }) => ({

const FabContainer = styled(Box)(({ theme }) => ({
position: 'fixed',
bottom: theme.spacing(2),
bottom: theme.spacing(10),
right: theme.spacing(2),
display: 'flex',
flexDirection: 'row',
Expand Down
13 changes: 2 additions & 11 deletions src/components/Player.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import React, { useState } from 'react';
import {
Checkbox,
Paper,
Box,
IconButton,
Popover,
Tooltip,
Typography,
useTheme,
} from '@mui/material';
import { Checkbox, Paper, Box, IconButton, Popover, Tooltip, Typography } from '@mui/material';
import { styled } from '@mui/system';
import ArrowRightIcon from '@mui/icons-material/ArrowRight';
import SettingsIcon from '@mui/icons-material/Settings';
Expand All @@ -23,6 +14,7 @@ import { GameLogActionWithCount } from '@/game/enumerations/game-log-action-with
import { PlayerFieldMap } from '@/game/types';
import { useAlert } from '@/components/AlertContext';
import { FailedAddLogEntryError } from '@/game/errors/failed-add-log';
import theme from '@/components/theme';

const StyledPaper = styled(Paper)(({ theme }) => ({
padding: 5,
Expand Down Expand Up @@ -54,7 +46,6 @@ interface PlayerProps {
}

const Player: React.FC<PlayerProps> = ({ addLogEntry }) => {
const theme = useTheme();
const { gameState, setGameState } = useGameContext();
const { showAlert } = useAlert();
const [showNewTurnSettings, setShowNewTurnSettings] = useState(false);
Expand Down
3 changes: 1 addition & 2 deletions src/components/SelectFirstPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import {
ListItemIcon,
ListItemText,
ListItemButton,
useTheme,
} from '@mui/material';
import ArrowRightIcon from '@mui/icons-material/ArrowRight';
import { useGameContext } from '@/components/GameContext';
import theme from '@/components/theme';

interface SelectFirstPlayerProps {
nextStep: () => void;
}

const SelectFirstPlayer: React.FC<SelectFirstPlayerProps> = ({ nextStep }) => {
const { gameState, setGameState } = useGameContext();
const theme = useTheme();

const selectRandomFirstPlayer = useCallback(() => {
if (gameState.players.length > 0) {
Expand Down
6 changes: 4 additions & 2 deletions src/components/screens/DominionAssistantScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import { Box, Typography, styled } from '@mui/material';
import { Box, Typography } from '@mui/material';
import { styled } from '@mui/system';
import { useNavigate, useLocation } from 'react-router-dom';
import DominionAssistant from '@/components/DominionAssistant';
import SuperCapsText from '@/components/SuperCapsText';

const StyledContainer = styled(Box)(({ theme }) => ({
display: 'flex',
Expand All @@ -22,7 +24,7 @@ export default function DominionAssistantScreen() {

return (
<StyledContainer>
<StyledTitle variant="h4">Unofficial Dominion Assistant</StyledTitle>
<SuperCapsText fontSize={24}>Unofficial Dominion Assistant</SuperCapsText>
<DominionAssistant route={location} navigation={navigate} />
</StyledContainer>
);
Expand Down
5 changes: 5 additions & 0 deletions src/game/dominion-lib-undo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NotEnoughProphecyError } from '@/game/errors/not-enough-prophecy';
import { NotEnoughSupplyError } from './errors/not-enough-supply';
import { NotEnoughSubfieldError } from './errors/not-enough-subfield';
import * as undoHelpers from './dominion-lib-undo-helpers';
import { CurrentStep } from './enumerations/current-step';

/**
* Returns the linked actions for the given log entry.
Expand Down Expand Up @@ -41,6 +42,10 @@ export function canUndoAction(game: IGame, logIndex: number): boolean {
return false;
}

if (game.currentStep !== CurrentStep.GameScreen) {
return false;
}

const actionToUndo = game.log[logIndex];

// Find the main action if this is a linked action
Expand Down

0 comments on commit 31e943c

Please sign in to comment.