GameBoard provide player names for all views
This commit is contained in:
parent
8611ede4b4
commit
f27eafa3f0
@ -27,6 +27,8 @@ export function Stone({ color }) {
|
|||||||
return BlackStone();
|
return BlackStone();
|
||||||
|
|
||||||
case '':
|
case '':
|
||||||
|
case undefined:
|
||||||
|
case null:
|
||||||
return; // no color :)
|
return; // no color :)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -7,32 +7,32 @@ import './GameBoard.css';
|
|||||||
|
|
||||||
export default function GameBoard() {
|
export default function GameBoard() {
|
||||||
const games = useContext(GamesContext);
|
const games = useContext(GamesContext);
|
||||||
const {pathname} = useLocation();
|
const { pathname } = useLocation();
|
||||||
|
|
||||||
let opponentName = '';
|
const [opponentName, opponentColor, myColor] = (() => {
|
||||||
let opponentColor = Color.white; // defaut color
|
if (matchPath('/games/new', pathname))
|
||||||
|
return [games.newGame.opponentName, games.newGame.opponentColor, Color.opposite(games.newGame.opponentColor)];
|
||||||
|
|
||||||
if (matchPath('/games/new', pathname)) {
|
let selectedGame;
|
||||||
opponentName = games.newGame.opponentName;
|
|
||||||
opponentColor = games.newGame.opponentColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (matchPath('/games/proposal', pathname)) {
|
if (matchPath('/games/proposal', pathname))
|
||||||
// const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID });
|
selectedGame = games.findGame({ uuid: games.proposal.selectedUUID });
|
||||||
|
else if (matchPath('/games/active', pathname))
|
||||||
|
selectedGame = games.findGame({ uuid: games.active.selectedUUID });
|
||||||
|
else if (matchPath('/games/archive', pathname))
|
||||||
|
selectedGame = games.findGame({ uuid: games.archive.selectedUUID });
|
||||||
|
|
||||||
// const opponentColor = selectedGame
|
if (selectedGame)
|
||||||
|
return [selectedGame?.opponentName, Color.opposite(selectedGame?.myColor), selectedGame?.myColor];
|
||||||
// whiteName = selectedGame.newGame.whitePlayer;
|
else
|
||||||
// blackName = games.newGame.blackPlayer;
|
return ['', Color.white, Color.black]; // defaults
|
||||||
// }
|
})(); // <<-- Execute
|
||||||
|
|
||||||
const myColor = Color.opposite(opponentColor);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='GameBoard'>
|
<div className='GameBoard'>
|
||||||
<Player color={opponentColor} name={opponentName} />
|
<Player color={opponentColor} name={opponentName} />
|
||||||
<Board />
|
<Board />
|
||||||
<Player color={myColor} name='MyName' />
|
<Player color={myColor} name={opponentName ? 'MyName' : ''} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user