mirror of
https://github.com/LHY0125/Gobang-Game.git
synced 2026-06-28 16:35:55 +08:00
refactor: 提取 refreshBoard status 计算逻辑提高可读性
This commit is contained in:
@@ -100,10 +100,15 @@ export const useGameStore = create<GameState>((set, get) => ({
|
||||
refreshBoard: async () => {
|
||||
const state: { board: CellState[][]; current_color: string; game_over: boolean } =
|
||||
await invoke('get_game_state');
|
||||
const newStatus: GameStatus = state.game_over
|
||||
? 'game_over'
|
||||
: get().status === 'ai_thinking'
|
||||
? 'ai_thinking'
|
||||
: 'playing';
|
||||
set({
|
||||
board: state.board,
|
||||
currentColor: state.current_color as Color,
|
||||
status: state.game_over ? 'game_over' : get().status === 'ai_thinking' ? 'ai_thinking' : 'playing',
|
||||
status: newStatus,
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user