import RemoteScene from './RemoteScene'
+import store from './Store'
export const connectedClients: Set<RemoteScene> = new Set()
-export function updateAll() {
+store.subscribe(() => {
connectedClients.forEach(function each(client) {
client.forceUpdate()// scene/server/RemoteScene.tsx
-import { setState, getState } from './State'
+import store, { squareClick } from './Store'
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
| async render() { | |
| return <scene>{this.renderBoard()}</scene> | |
| } |
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
| renderBoard() { | |
| return ( | |
| <entity | |
| position={{ | |
| x: 1.5, | |
| y: 0, | |
| z: 1.5 | |
| }} | |
| > | |
| {store.getState().squares.map(this.renderSquare)} |
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
| renderSquare(square: any, index: number) { | |
| const x = 7 - (index % 8) | |
| const y = 0 | |
| const z = Math.floor(index / 8) | |
| const position = { x, y, z } |
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
| let color = (x + z) % 2 === 0 ? '#FFFFFF' : '#000000' | |
| if (square.selected) { | |
| color = '#7FFF00' | |
| } else if (square.highlighted) { | |
| color = square.pieceId !== '_' ? '#FF0000' : '#FFFF00' | |
| } else if (square.check) { | |
| color = '#FFA500' | |
| } |
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 modelsById: { [key: string]: string } = { | |
| B: 'assets/LP Bishop_White.gltf', | |
| b: 'assets/LP Bishop_Black.gltf', | |
| K: 'assets/LP King_White.gltf', | |
| k: 'assets/LP King_Black.gltf', | |
| N: 'assets/LP Knight_White.gltf', | |
| n: 'assets/LP Knight_Black.gltf', | |
| P: 'assets/LP Pawn_White.gltf', | |
| p: 'assets/LP Pawn_Black.gltf', | |
| Q: 'assets/LP Queen_White.gltf', |
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> | |
| ) |
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
| const { elementId } = event.data | |
| if (elementId != null) { | |
| // dispatch redux action | |
| } |