GameBoard: show previous and current moves
This commit is contained in:
parent
5639b5e8c9
commit
a9eae999f6
@ -73,7 +73,7 @@ export default function useGamesApi() {
|
||||
|
||||
const pushGameMove = ({ uuid, move, message }) => {
|
||||
doPushing(`/api/game/${uuid}/move`, 'PUT', { move, message }, {
|
||||
onPushing: (isPushing) => dispatchGuide({ type: 'UUIDpushing', uuid, what: isPushing && 'move' }),
|
||||
onPushing: (isPushing) => dispatchGuide({ type: 'UUIDpushing', uuid, what: isPushing && {moveFrom: move[0], moveTo: move[1]} }),
|
||||
onSuccess: (game) => {
|
||||
dispatchState({ type: 'update', game });
|
||||
dispatchGuide({ type: 'UUIDmessage', uuid, message: ''});
|
||||
|
@ -7,7 +7,7 @@
|
||||
.Board {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.Board.flip {
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
.Tile {
|
||||
border: 1px solid #e4e4e4;
|
||||
padding: 0;
|
||||
float: left;
|
||||
text-align: center;
|
||||
}
|
||||
@ -30,4 +31,8 @@
|
||||
|
||||
.Tile.selected {
|
||||
color: grey;
|
||||
}
|
||||
|
||||
.Tile.prevmove {
|
||||
background-color:bisque;
|
||||
}
|
@ -71,16 +71,29 @@ export function Player({ color, name }) {
|
||||
/*
|
||||
* Board
|
||||
*/
|
||||
export function Board({ board, flip, onStoneClick, onStoneMove }) {
|
||||
export function Board({ board, flip, prevMove, currMove, onStoneClick, onStoneMove }) {
|
||||
// ugly & lazy
|
||||
if (!board)
|
||||
board = [];
|
||||
if (!prevMove)
|
||||
prevMove = [];
|
||||
if (!currMove)
|
||||
currMove = [];
|
||||
|
||||
const [[moveId, moveX, moveY], setMove] = useState([0, 0, 0]);
|
||||
|
||||
const isInteractive = (board && (typeof onStoneClick === 'function' || typeof onStoneMove === 'function')) ? ' interactive' : '';
|
||||
|
||||
const WhiteTile = ({ id }) => {
|
||||
const stone = board[id];
|
||||
const stone = (id === currMove[1]) ? board[currMove[0]] : board[id];
|
||||
|
||||
return (
|
||||
<div className={'Tile white' + isInteractive + (id === moveId ? ' selected' : '')}
|
||||
<div className={'Tile white'
|
||||
+ isInteractive
|
||||
+ (id === moveId ? ' selected' : '')
|
||||
+ (id === currMove[0] || id === currMove[1] ? ' selected' : '')
|
||||
+ (id === prevMove[0] || id === prevMove[1] ? ' prevmove' : '')
|
||||
}
|
||||
onClick={!onStoneClick ? null :
|
||||
() => onStoneClick(id)
|
||||
}
|
||||
|
@ -23,8 +23,10 @@ export default function GameBoard({ username, getGame, onStoneClick, onStoneMove
|
||||
name={game.opponentName}
|
||||
/>
|
||||
<Board
|
||||
board={game.board || []}
|
||||
board={game.board}
|
||||
flip={flipBoard}
|
||||
prevMove={game.previousMove}
|
||||
currMove={[isPushing?.moveFrom, isPushing?.moveTo]}
|
||||
onStoneClick={optionalOnStoneClick}
|
||||
onStoneMove={optionalOnStoneMove}
|
||||
/>
|
||||
@ -32,7 +34,6 @@ export default function GameBoard({ username, getGame, onStoneClick, onStoneMove
|
||||
color={game.myColor || Color.white}
|
||||
name={myName}
|
||||
/>
|
||||
{(isPushing === 'move') ? <span>Moving...</span> : null}
|
||||
</div>
|
||||
)
|
||||
}
|
@ -138,8 +138,9 @@ function Selectable({ game, selected, onClick }) {
|
||||
onClick={() => onClick(game.uuid)}
|
||||
>
|
||||
<Board
|
||||
board={game.board || []}
|
||||
board={game.board}
|
||||
flip={flipBoard}
|
||||
prevMove={game.previousMove}
|
||||
/>
|
||||
<div className='Message'>
|
||||
<Player
|
||||
|
Loading…
Reference in New Issue
Block a user