update pit color when onPitSelect

This commit is contained in:
Halit Aksoy 2022-05-22 17:58:11 +03:00
parent 2a600d6357
commit 1fdb296442

View File

@ -132,12 +132,20 @@ const Home: FunctionComponent<{ initial?: number }> = ({ initial = 0 }) => {
context.rtmt.sendMessage(channel_leave_game, {}); context.rtmt.sendMessage(channel_leave_game, {});
}; };
const getBoardIndex = (index: number) => {
if (userKey === game.player2Id) return index + game.board.pits.length / 2;
return index;
};
const onHoleSelect = (index: number, pit: Pit) => { const onHoleSelect = (index: number, pit: Pit) => {
//TODO : stoneCount comes from view model! //TODO : stoneCount comes from view model!
if (pit.stoneCount === 0) { if (pit.stoneCount === 0) {
//TODO : warn user //TODO : warn user
return; return;
} }
boardViewModel.pits[getBoardIndex(index)].pitColor =
context.themeManager.theme.pitSelectedColor;
updateBoardViewModel(boardViewModel);
const gameMove: GameMove = { index: index }; const gameMove: GameMove = { index: index };
context.rtmt.sendMessage(channel_game_move, gameMove); context.rtmt.sendMessage(channel_game_move, gameMove);
}; };