'use strict'; const React = require('react/addons'); const GameStore = require('../stores/GameStore'); const GameActions = require('../actions/GameActions'); const onGameChange = require('../mixins/onGameChange'); const Chessboard = require('./Chessboard'); const CapturedPieces = require('./CapturedPieces'); const TableOfMoves = require('./TableOfMoves'); const cx = require('classnames'); const ChessboardInterface = React.createClass({ propTypes: { io: React.PropTypes.object.isRequired }, mixins: [React.addons.PureRenderMixin, onGameChange], getInitialState() { return GameStore.getState(); }, render() { const {promotion, turn, gameOver} = this.state; const cxFeedback = cx({ feedback: true, whitefeedback: turn === 'w', blackfeedback: turn === 'b' }); console.log(turn); console.log(cxFeedback); const goType = gameOver.get('type'); const loser = gameOver.get('winner') === 'White' ? 'Black' : 'White'; return (
{!gameOver.get('status') ? {`${turn === 'w' ? 'White' : 'Black'} to move.`} : {goType === 'checkmate' ? `Checkmate. ${gameOver.get('winner')} wins!` :goType === 'timeout' ? `${loser}‘s time is out. ${gameOver.get('winner')} wins!` :goType === 'resign' ? `${loser} has resigned. ${gameOver.get('winner')} wins!` :goType === 'draw' ? 'Draw.' :goType === 'stalemate' ? 'Draw (Stalemate).' :goType === 'threefoldRepetition' ? 'Draw (Threefold Repetition).' :goType === 'insufficientMaterial' ? 'Draw (Insufficient Material)' :null} }
); }, _onGameChange() { this.setState(GameStore.getState()); }, _onPromotionChange(e) { GameActions.changePromotion(e.target.value); } }); module.exports = ChessboardInterface;