mirror of
https://github.com/LHY0125/Gobang-Game.git
synced 2026-06-29 00:45:55 +08:00
feat: Online 模式前端 UI — 房间管理/连接状态/remote-move/禁悔棋
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useRef, useCallback, useMemo } from 'react';
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
import { useGameStore, buildReplayBoard } from '../../store/gameStore';
|
||||
import {
|
||||
computeBoardDimensions,
|
||||
@@ -59,6 +60,20 @@ export default function BoardCanvas() {
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
}, [render]);
|
||||
|
||||
useEffect(() => {
|
||||
if (mode !== 'Online') return;
|
||||
let unlisten: (() => void) | undefined;
|
||||
|
||||
const setup = async () => {
|
||||
unlisten = await listen<{ x: number; y: number }>('remote-move', (event) => {
|
||||
placePiece(event.payload.x, event.payload.y);
|
||||
});
|
||||
};
|
||||
setup();
|
||||
|
||||
return () => { unlisten?.(); };
|
||||
}, [mode, placePiece]);
|
||||
|
||||
const handleClick = useCallback(
|
||||
(e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||
if (status !== 'playing') return;
|
||||
|
||||
Reference in New Issue
Block a user