diff --git a/apps/client/src/app.tsx b/apps/client/src/app.tsx index e4393d1..ea6e82f 100644 --- a/apps/client/src/app.tsx +++ b/apps/client/src/app.tsx @@ -4,12 +4,12 @@ // シーン(画面)コンポーネント import { TitleScene } from "./scenes/TitleScene"; import { LobbyScene } from "./scenes/LobbyScene"; -import { GameScene } from "./scenes/GameScene"; // 👈 追加 +import { GameScene } from "./scenes/GameScene"; -import type { Room } from "@repo/shared/src/types/room"; +import { GameState, type Room } from "@repo/shared/src/types/room"; export default function App() { - const [gameState, setGameState] = useState<"title" | "lobby" | "playing">("title"); + const [gameState, setGameState] = useState(GameState.TITLE); const [room, setRoom] = useState(null); const [myId, setMyId] = useState(null); @@ -17,17 +17,17 @@ socketClient.onConnect((id) => setMyId(id)); socketClient.onRoomUpdate((updatedRoom) => { setRoom(updatedRoom); - setGameState("lobby"); + setGameState(GameState.LOBBY); }); - socketClient.onGameStart(() => setGameState("playing")); + socketClient.onGameStart(() => setGameState(GameState.PLAYING)); }, []); // レンダリング分岐 - if (gameState === "title") { - return socketClient.joinRoom(roomId, playerName)} />; + if (gameState === GameState.TITLE) { + return socketClient.joinRoom(payload.roomId, payload.playerName)} />; } - if (gameState === "lobby") { + if (gameState === GameState.LOBBY) { return socketClient.startGame()} />; } diff --git a/apps/client/src/network/SocketClient.ts b/apps/client/src/network/SocketClient.ts index a14d709..11bdc85 100644 --- a/apps/client/src/network/SocketClient.ts +++ b/apps/client/src/network/SocketClient.ts @@ -1,13 +1,6 @@ import { io, Socket } from "socket.io-client"; import { SocketEvents } from "@repo/shared/src/protocol/events"; - -// プレイヤーの基本情報を定義する型 -export type PlayerData = { - id: string; - x: number; - y: number; - color: string; -}; +import type { PlayerData } from "@repo/shared/src/types/player"; /** * サーバーとのWebSocket通信を管理するクライアントクラス diff --git a/apps/client/src/scenes/TitleScene.tsx b/apps/client/src/scenes/TitleScene.tsx index a559685..1c8e8b0 100644 --- a/apps/client/src/scenes/TitleScene.tsx +++ b/apps/client/src/scenes/TitleScene.tsx @@ -1,13 +1,25 @@ import { useState } from "react"; +// sharedからのインポート(パスは環境に合わせて調整してください) +import type { JoinRoomPayload } from "@repo/shared/src/types/room"; type Props = { - onJoin: (roomId: string, playerName: string) => void; + // バラバラの引数から、共通のペイロード型に変更 + onJoin: (payload: JoinRoomPayload) => void; }; export const TitleScene = ({ onJoin }: Props) => { const [playerName, setPlayerName] = useState(""); const [roomIdInput, setRoomIdInput] = useState(""); + // 元の条件を維持(両方入力されていればOK) + const canJoin = playerName !== "" && roomIdInput !== ""; + + const handleJoin = () => { + if (canJoin) { + onJoin({ roomId: roomIdInput, playerName }); + } + }; + return (

Pixel Paint War

@@ -28,13 +40,13 @@