@@ -65,25 +65,33 @@ export function Board({
65
65
let [ forbidden_x , forbidden_y ] = gameState . forbidden
66
66
let dragging = useLayoutStore ( state => state . dragging )
67
67
let muted = useMuteStore ( state => state . muted )
68
- let howler = useRef ( )
68
+ let howler = useRef ( { } )
69
69
let end = gameHasEnded ( gameState )
70
70
let showMoveNumbers = ctrlKeyDown && ( isKibitz ( gameState , auth ) || end )
71
+ let howlerActive = useRef ( false )
71
72
72
- let playClickSound = useCallback ( ( ) => {
73
+ let playSound = useCallback ( ( { file, volume} ) => {
74
+ if ( ! howlerActive . current ) {
75
+ return
76
+ }
73
77
if ( muted ) {
74
78
return
75
79
}
76
- if ( ! howler . current ) {
77
- howler . current = new Howl ( {
78
- src : [ base + "/stone1.wav" ] ,
79
- onloaderror : ( id , error ) => {
80
- throw new Error ( id + ": " + error )
81
- } ,
80
+ if ( ! howler . current [ file ] ) {
81
+ howler . current [ file ] = new Howl ( {
82
+ src : [ base + "/" + file + ".wav" ] ,
83
+ volume : volume ,
82
84
} )
83
85
}
84
- howler . current . play ( )
86
+ return howler . current [ file ] . play ( )
85
87
} , [ howler , muted ] )
86
88
89
+ useEffect ( ( ) => {
90
+ if ( ! end && ! counting && timeRemaining >= 1 && timeRemaining <= 9 ) {
91
+ playSound ( { file : "" + timeRemaining , volume : 1 } )
92
+ }
93
+ } , [ playSound , timeRemaining , end , counting ] )
94
+
87
95
useEffect ( ( ) => {
88
96
let onKeyDown = ( e ) => {
89
97
let activeElement = window . document . activeElement
@@ -160,6 +168,7 @@ export function Board({
160
168
} , [ context , setCursor_x , setCursor_y , board . length , dragging ] )
161
169
162
170
let onClick = useCallback ( ( ) => {
171
+ howlerActive . current = true
163
172
if ( ! context . canvasRef . current ) {
164
173
return
165
174
}
@@ -206,12 +215,12 @@ export function Board({
206
215
} ) )
207
216
}
208
217
resetCountdown ( )
209
- playClickSound ( )
218
+ playSound ( { file : "stone1" , volume : 0.04 } )
210
219
stompClient . publish ( {
211
220
destination : "/app/game/move" ,
212
221
body : JSON . stringify ( move ) ,
213
222
} )
214
- } , [ context , gameState , setGameState , auth , board , stompClient , counting , forbidden_x , forbidden_y , myColor , playClickSound , isCursorInBounds , showMoveNumbers , resetCountdown , end ] )
223
+ } , [ context , gameState , setGameState , auth , board , stompClient , counting , forbidden_x , forbidden_y , myColor , playSound , isCursorInBounds , showMoveNumbers , resetCountdown , end ] )
215
224
216
225
useEffect ( ( ) => {
217
226
if ( ! context . canvasRef . current ) {
0 commit comments