Skip to content

Instantly share code, notes, and snippets.

this.eventSubscriber.on('click', event => {
const { elementId } = event.data
const state = store.getState()
const {
game: { whiteTurn },
match: { playerWhite, playerBlack }
} = state
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
async render() {
const status = store.getState().match.status
return (
<scene>
{status === 'idle' ? this.renderIdle() : this.renderBoard()}
</scene>
)
}
export default class Chess extends ScriptableScene {
+  public id: number = Math.random()
// 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) {
if (amountOfValidMoves === 0) {
if (store.getState().match.status === 'started') {
next(checkmate())
setTimeout(() => next(initSquares()), 10000)
}
}
const amountOfValidMoves = squaresWithPiecesFromPlayerInCheck.reduce(
(moves, square) => moves + engine(squares)(square.pieceId)(square.id).length,
0
)
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.