export default class Chess extends ScriptableScene {
+ public id: number = Math.random()
This file contains 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
this.eventSubscriber.on('click', event => { | |
const { elementId } = event.data | |
const state = store.getState() | |
const { | |
game: { whiteTurn }, | |
match: { playerWhite, playerBlack } | |
} = state |
This file contains 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
renderIdle() { | |
const { playerWhite, playerBlack } = store.getState().match | |
return ( | |
<entity> | |
<gltf-model | |
src={modelsById['Q']} | |
id="register-white" | |
position={{ x: 3.5, y: playerWhite ? 1 : 0, z: 5 }} | |
/> | |
<gltf-model |
This file contains 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
async render() { | |
const status = store.getState().match.status | |
return ( | |
<scene> | |
{status === 'idle' ? this.renderIdle() : this.renderBoard()} | |
</scene> | |
) | |
} |
// scene/server/Server.ts
import { connectedClients } from './ConnectedClients'
import { WebSocketTransport } from 'metaverse-api'
import RemoteScene from './RemoteScene'
+import store, { unregisterPlayer } from './Store'
// ...
wss.on('connection', function connection(ws, req) {
This file contains 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
if (amountOfValidMoves === 0) { | |
if (store.getState().match.status === 'started') { | |
next(checkmate()) | |
setTimeout(() => next(initSquares()), 10000) | |
} | |
} |
This file contains 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 amountOfValidMoves = squaresWithPiecesFromPlayerInCheck.reduce( | |
(moves, square) => moves + engine(squares)(square.pieceId)(square.id).length, | |
0 | |
) |
This file contains 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 squares = store.getState().squares | |
const squaresWithPiecesFromPlayerInCheck = squares.filter( | |
square => | |
square.pieceId !== '_' && | |
(isWhite ? square.color === 'piece_black' : 'piece_white') | |
) |
// src/modules/middleware/analysis-middleware.js
import {
addPiece,
removePiece,
checkSquare,
+ initSquares
} from '../../modules/squares/actions'
import {
wasKingCastle,
import squares from './modules/squares/reducer'
import pieces from './modules/pieces/reducer'
import game from './modules/game/reducer'
+import match from './modules/match/reducer'
const rootReducer = combineReducers({
squares: squares, // main ui slice of the state.
takenPieces: pieces, // taken pieces list.
game: game, // move recording.