@@ -36,6 +36,7 @@ export default function Game(props: GameProps) {
36
36
37
37
const [ game , setGame ] = useState ( new Chess ( ) ) ;
38
38
const lastPlayedMoveRef = useRef < number > ( - 1 ) ;
39
+ const isFirstLoadRef = useRef ( true ) ;
39
40
40
41
const [ selfMove ] = useSound ( "../../../sounds/move-self.mp3" ) ;
41
42
const [ capture ] = useSound ( "../../../sounds/capture.mp3" ) ;
@@ -81,10 +82,13 @@ export default function Game(props: GameProps) {
81
82
const currentMoveNumber = numberOfMoves ( board ) ;
82
83
setGame ( board ) ;
83
84
84
- if ( currentMoveNumber > lastPlayedMoveRef . current ) {
85
+ if (
86
+ currentMoveNumber > lastPlayedMoveRef . current &&
87
+ ! isFirstLoadRef . current
88
+ ) {
85
89
playSound ( board , oldBoard ) ;
86
- lastPlayedMoveRef . current = currentMoveNumber ;
87
90
}
91
+ lastPlayedMoveRef . current = currentMoveNumber ;
88
92
} ,
89
93
[ playSound ]
90
94
) ;
@@ -98,6 +102,10 @@ export default function Game(props: GameProps) {
98
102
if ( numberOfMoves ( remoteBoard ) > numberOfMoves ( game ) ) {
99
103
updateBoard ( remoteBoard , game ) ;
100
104
}
105
+
106
+ if ( isFirstLoadRef . current ) {
107
+ isFirstLoadRef . current = false ;
108
+ }
101
109
} , [ remoteGame , game , updateBoard ] ) ;
102
110
103
111
const makeAMove = ( move : Move | string ) => {
@@ -119,6 +127,7 @@ export default function Game(props: GameProps) {
119
127
return false ;
120
128
}
121
129
130
+ isFirstLoadRef . current = false ;
122
131
submit ( "move" , { gameId : slug , move : move . san } ) ;
123
132
return true ;
124
133
}
0 commit comments