sceneDidMount() {
this.eventSubscriber.on('click', event => {
- setState({ isDoorClosed: !getState().isDoorClosed })
})
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case CHECKMATE: { | |
if (state.status === STATUS.started) { | |
return Object.assign({}, state, { | |
status: STATUS.checkmate | |
}) | |
} | |
return state | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case UNREGISTER_PLAYER: { | |
const { playerWhite, playerBlack } = state | |
if (playerWhite === action.playerId || playerBlack === action.playerId) { | |
return initialState // one of the players playing left, so we reset the game | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case REGISTER_PLAYER: { | |
let { playerWhite, playerBlack, status } = state | |
if (playerWhite && playerBlack) { | |
return state // both players already registered | |
} | |
if (playerWhite === action.playerId || playerBlack === action.playerId) { | |
return state // this player is already registered | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/modules/match/reducer.js | |
import { INIT_SQUARES } from '../squares/actions' | |
import { REGISTER_PLAYER, UNREGISTER_PLAYER, CHECKMATE } from './actions' | |
const STATUS = { | |
idle: 'idle', | |
started: 'started', | |
checkmate: 'checkmate' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/modules/match/actions.js | |
export const REGISTER_PLAYER = 'chess/match/register_player' | |
export const UNREGISTER_PLAYER = 'chess/match/unregister_player' | |
export const CHECKMATE = 'chess/match/checkmate' | |
export const registerPlayer = (playerId, isWhite) => ({ | |
type: REGISTER_PLAYER, | |
playerId, | |
isWhite | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sceneDidMount() { | |
this.eventSubscriber.on('click', event => { | |
const { elementId } = event.data | |
if (elementId != null) { | |
const squareId = getSquareId(elementId) | |
const square = store | |
.getState() | |
.squares.find((square: any) => square.id === squareId) | |
store.dispatch(squareClick(square.id, square.pieceId, square.color)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getSquareId = (elementId: string) => elementId.split('-')[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { elementId } = event.data | |
if (elementId != null) { | |
// dispatch redux action | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tileSize = { x: 1, y: 0.1, z: 1 } | |
return ( | |
<entity position={position}> | |
<box color={color} scale={tileSize} id={`${square.id}-tile`} /> | |
{square.pieceId in modelsById ? ( | |
<gltf-model src={modelsById[square.pieceId]} id={`${square.id}-piece`} /> | |
) : null} | |
</entity> | |
) |