Skip to content

Commit

Permalink
improve game log readability
Browse files Browse the repository at this point in the history
  • Loading branch information
JessicaMulein committed Oct 23, 2024
1 parent d6d8e19 commit 24fc1df
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
29 changes: 29 additions & 0 deletions src/components/ColoredPlayerName.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { IPlayer } from '@/game/interfaces/player';
import { Typography } from '@mui/material';
import React from 'react';

interface ColoredPlayerNameProps {
player: IPlayer;
marginDirection?: 'left' | 'right';
}

const ColoredPlayerName: React.FC<ColoredPlayerNameProps> = ({
player,
marginDirection = 'right',
}) => {
return (
<Typography
component="span"
sx={{
color: player.color,
fontWeight: 'bold',
marginRight: marginDirection === 'right' ? '4px' : '0',
marginLeft: marginDirection === 'left' ? '4px' : '0',
}}
>
&lt;{player.name}&gt;
</Typography>
);
};

export default ColoredPlayerName;
21 changes: 10 additions & 11 deletions src/components/GameLogEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { canUndoAction, undoAction } from '@/game/dominion-lib-undo';
import { getTimeSpanFromStartGame, logEntryToString } from '@/game/dominion-lib-log';
import { GameLogActionWithCount } from '@/game/enumerations/game-log-action-with-count';
import { AdjustmentActions } from '@/game/constants';
import ColoredPlayerName from '@/components/ColoredPlayerName';

interface GameLogEntryProps {
logIndex: number;
Expand Down Expand Up @@ -66,6 +67,10 @@ const GameLogEntry: React.FC<GameLogEntryProps> = ({ logIndex, entry, isCurrentP
const isNewTurn = entry.action === GameLogActionWithCount.NEXT_TURN;
const isAttributeChange = AdjustmentActions.includes(entry.action);
const isAttributeChangeOutOfTurn = isAttributeChange && !isActivePlayer;
const isNotTriggeredByPlayer = [
GameLogActionWithCount.SELECT_PLAYER,
GameLogActionWithCount.NEXT_TURN,
].includes(entry.action);

if (entry.playerIndex > -1 && !gameState.players[entry.playerIndex]) {
console.warn(`Player not found for index ${entry.playerIndex}`, {
Expand Down Expand Up @@ -106,17 +111,8 @@ const GameLogEntry: React.FC<GameLogEntryProps> = ({ logIndex, entry, isCurrentP
/>
)}
<Box display="flex" alignItems="center" flexGrow={1}>
{relevantPlayer !== undefined && (
<Typography
component="span"
sx={{
color: relevantPlayer.color,
fontWeight: 'bold',
marginRight: '4px',
}}
>
&lt;{relevantPlayer.name}&gt;:
</Typography>
{relevantPlayer !== undefined && !isNotTriggeredByPlayer && (
<ColoredPlayerName player={relevantPlayer} marginDirection="right" />
)}
<Typography
variant="body2"
Expand All @@ -128,6 +124,9 @@ const GameLogEntry: React.FC<GameLogEntryProps> = ({ logIndex, entry, isCurrentP
>
{actionText}
</Typography>
{isNotTriggeredByPlayer && relevantPlayer !== undefined && (
<ColoredPlayerName player={relevantPlayer} marginDirection="left" />
)}
{isAttributeChangeOutOfTurn && (
<ChangeCircleIcon
fontSize="small"
Expand Down

0 comments on commit 24fc1df

Please sign in to comment.