Spaces:
Sleeping
Sleeping
File size: 4,125 Bytes
3568151 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
import React from 'react'
import { GameState, CHESS_MODELS } from '../types/chess'
import { VolumeSlider } from './VolumeSlider'
import '../styles/GameControls.css'
export const GameControls: React.FC<{
gameState: GameState
audioEnabled: boolean
volumeSettings: {
ambient: number
game: number
}
selectedModel: string
onStartGame: () => void
onResignGame: () => void
onToggleColor: () => void
onToggleAudio: () => void
onVolumeChange: (type: "ambient" | "game", value: number) => void
onModelChange: (modelId: string) => void
}> = ({
gameState,
audioEnabled,
volumeSettings,
selectedModel,
onStartGame,
onResignGame,
onToggleColor,
onToggleAudio,
onVolumeChange,
onModelChange
}) => {
const getMainButtonText = () => {
if (gameState.gameActive) {
return 'โ Resign Game'
}
return '๐ฎ Start Game'
}
const getMainButtonAction = () => {
if (gameState.gameActive) {
return onResignGame
}
return onStartGame
}
const getColorButtonText = () => {
return `โช Play as ${gameState.playerColor === 'w' ? 'White' : 'Black'}`
}
const getAudioButtonText = () => {
return `๐ Audio: ${audioEnabled ? 'ON' : 'OFF'}`
}
const getGameStatus = () => {
if (gameState.aiModelLoading) {
return (
<div className="thinking-indicator">
Loading AI model<span className="thinking-dots"></span>
</div>
)
}
if (gameState.gameActive) {
if (gameState.aiThinking) {
return (
<div className="thinking-indicator">
AI is thinking<span className="thinking-dots"></span>
</div>
)
} else if (gameState.board.turn() === gameState.playerColor) {
return `Your turn (${gameState.playerColor === 'w' ? 'White' : 'Black'})`
} else {
return `AI turn (${gameState.playerColor === 'w' ? 'Black' : 'White'})`
}
} else if (gameState.gameResult?.isGameOver) {
return gameState.gameResult.message
} else {
const aiStatusText = gameState.aiModelLoaded ? '' : ' (AI: Fallback mode)'
return `Click 'Start Game' to begin${aiStatusText}`
}
}
return (
<div className="game-controls">
<div className="game-status">
{getGameStatus()}
</div>
<div className="control-buttons">
<button
className="button main-button"
onClick={getMainButtonAction()}
>
{getMainButtonText()}
</button>
{!gameState.gameActive && (
<>
<button
className="button color-button"
onClick={onToggleColor}
>
{getColorButtonText()}
</button>
<div className="model-selector">
<label htmlFor="model-select">๐ค Chess Model:</label>
<select
id="model-select"
className="model-dropdown"
value={selectedModel}
onChange={(e) => onModelChange(e.target.value)}
disabled={gameState.aiModelLoading}
>
{CHESS_MODELS.map((model) => (
<option key={model} value={model}>
{model}
</option>
))}
</select>
</div>
</>
)}
<button
className="button audio-button"
onClick={onToggleAudio}
>
{getAudioButtonText()}
</button>
</div>
{audioEnabled && (
<div className="volume-controls">
<h3 className="volume-controls-title">Audio Volume</h3>
<VolumeSlider
label="๐ต Initative Tempo"
value={volumeSettings.ambient}
onChange={(value) => onVolumeChange('ambient', value)}
/>
<VolumeSlider
label="โ๏ธ Move Notes"
value={volumeSettings.game}
onChange={(value) => onVolumeChange('game', value)}
/>
</div>
)}
</div>
)
} |