Compare commits

..

No commits in common. "a9eae999f6f1eea3ec8824c1323914d4e453c16b" and "34f71a46589ed1ba5b23695748cde4e432094259" have entirely different histories.

6 changed files with 14 additions and 34 deletions

View File

@ -73,7 +73,7 @@ export default function useGamesApi() {
const pushGameMove = ({ uuid, move, message }) => { const pushGameMove = ({ uuid, move, message }) => {
doPushing(`/api/game/${uuid}/move`, 'PUT', { move, message }, { doPushing(`/api/game/${uuid}/move`, 'PUT', { move, message }, {
onPushing: (isPushing) => dispatchGuide({ type: 'UUIDpushing', uuid, what: isPushing && {moveFrom: move[0], moveTo: move[1]} }), onPushing: (isPushing) => dispatchGuide({ type: 'UUIDpushing', uuid, what: isPushing && 'move' }),
onSuccess: (game) => { onSuccess: (game) => {
dispatchState({ type: 'update', game }); dispatchState({ type: 'update', game });
dispatchGuide({ type: 'UUIDmessage', uuid, message: ''}); dispatchGuide({ type: 'UUIDmessage', uuid, message: ''});

View File

@ -7,7 +7,7 @@
.Board { .Board {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
} }
.Board.flip { .Board.flip {
@ -16,7 +16,6 @@
.Tile { .Tile {
border: 1px solid #e4e4e4; border: 1px solid #e4e4e4;
padding: 0;
float: left; float: left;
text-align: center; text-align: center;
} }
@ -31,8 +30,4 @@
.Tile.selected { .Tile.selected {
color: grey; color: grey;
}
.Tile.prevmove {
background-color:bisque;
} }

View File

@ -71,29 +71,16 @@ export function Player({ color, name }) {
/* /*
* Board * Board
*/ */
export function Board({ board, flip, prevMove, currMove, onStoneClick, onStoneMove }) { export function Board({ board, flip, onStoneClick, onStoneMove }) {
// ugly & lazy
if (!board)
board = [];
if (!prevMove)
prevMove = [];
if (!currMove)
currMove = [];
const [[moveId, moveX, moveY], setMove] = useState([0, 0, 0]); const [[moveId, moveX, moveY], setMove] = useState([0, 0, 0]);
const isInteractive = (board && (typeof onStoneClick === 'function' || typeof onStoneMove === 'function')) ? ' interactive' : ''; const isInteractive = (board && (typeof onStoneClick === 'function' || typeof onStoneMove === 'function')) ? ' interactive' : '';
const WhiteTile = ({ id }) => { const WhiteTile = ({ id }) => {
const stone = (id === currMove[1]) ? board[currMove[0]] : board[id]; const stone = board[id];
return ( return (
<div className={'Tile white' <div className={'Tile white' + isInteractive + (id === moveId ? ' selected' : '')}
+ isInteractive
+ (id === moveId ? ' selected' : '')
+ (id === currMove[0] || id === currMove[1] ? ' selected' : '')
+ (id === prevMove[0] || id === prevMove[1] ? ' prevmove' : '')
}
onClick={!onStoneClick ? null : onClick={!onStoneClick ? null :
() => onStoneClick(id) () => onStoneClick(id)
} }

View File

@ -23,10 +23,8 @@ export default function GameBoard({ username, getGame, onStoneClick, onStoneMove
name={game.opponentName} name={game.opponentName}
/> />
<Board <Board
board={game.board} board={game.board || []}
flip={flipBoard} flip={flipBoard}
prevMove={game.previousMove}
currMove={[isPushing?.moveFrom, isPushing?.moveTo]}
onStoneClick={optionalOnStoneClick} onStoneClick={optionalOnStoneClick}
onStoneMove={optionalOnStoneMove} onStoneMove={optionalOnStoneMove}
/> />
@ -34,6 +32,7 @@ export default function GameBoard({ username, getGame, onStoneClick, onStoneMove
color={game.myColor || Color.white} color={game.myColor || Color.white}
name={myName} name={myName}
/> />
{(isPushing === 'move') ? <span>Moving...</span> : null}
</div> </div>
) )
} }

View File

@ -30,14 +30,14 @@
.Selectable .Board { .Selectable .Board {
margin: 5px; margin: 5px;
border: 0.5px solid #e4e4e4;
} }
.Selectable .Board .Tile { .Selectable .Board .Tile {
font-size: 50%; font-size: 33.3%;
line-height: 6px; line-height: 4px;
height: 6px; height: 4px;
width: 6px; width: 4px;
border: none; margin-right: -1px;
margin-top: -1px;
} }
.Selectable .Message { .Selectable .Message {

View File

@ -138,9 +138,8 @@ function Selectable({ game, selected, onClick }) {
onClick={() => onClick(game.uuid)} onClick={() => onClick(game.uuid)}
> >
<Board <Board
board={game.board} board={game.board || []}
flip={flipBoard} flip={flipBoard}
prevMove={game.previousMove}
/> />
<div className='Message'> <div className='Message'>
<Player <Player