diff --git a/apps/client/src/scenes/game/GameInputManager.ts b/apps/client/src/scenes/game/GameInputManager.ts new file mode 100644 index 0000000..abf6670 --- /dev/null +++ b/apps/client/src/scenes/game/GameInputManager.ts @@ -0,0 +1,18 @@ +/** + * GameInputManager + * ゲーム側へ入力を集約して橋渡しする + */ +import { GameManager } from "./GameManager"; + +/** ジョイスティック入力をゲーム管理へ橋渡しするマネージャー */ +export class GameInputManager { + private gameManager: GameManager; + + constructor(gameManager: GameManager) { + this.gameManager = gameManager; + } + + public handleJoystickInput = (x: number, y: number) => { + this.gameManager.setJoystickInput(x, y); + }; +} diff --git a/apps/client/src/scenes/game/GameScene.tsx b/apps/client/src/scenes/game/GameScene.tsx index 6dce426..96b9d84 100644 --- a/apps/client/src/scenes/game/GameScene.tsx +++ b/apps/client/src/scenes/game/GameScene.tsx @@ -1,4 +1,10 @@ -import { useEffect, useRef, useState } from "react"; +/** + * GameScene + * メインゲーム画面の表示とライフサイクルを管理する + * GameManagerの初期化と入力配線を行う + */ +import { useCallback, useEffect, useRef, useState } from "react"; +import { GameInputManager } from "./GameInputManager"; import { GameManager } from "./GameManager"; import { GameView } from "./GameView"; import { config } from "@repo/shared"; @@ -15,6 +21,7 @@ export function GameScene({ myId }: GameSceneProps) { const pixiContainerRef = useRef(null); const gameManagerRef = useRef(null); + const inputManagerRef = useRef(null); // gameConfig から初期表示時間文字列を生成する関数 const getInitialTimeDisplay = () => { @@ -36,6 +43,7 @@ // 参照を保持(入力を渡すため) gameManagerRef.current = manager; + inputManagerRef.current = new GameInputManager(manager); // 描画用のタイマーループ (100msごとに更新して滑らかにする) const timerInterval = setInterval(() => { @@ -49,17 +57,20 @@ // コンポーネント破棄時のクリーンアップ return () => { manager.destroy(); + inputManagerRef.current = null; clearInterval(timerInterval); // クリーンアップ }; }, [myId]); + const handleInput = useCallback((x: number, y: number) => { + inputManagerRef.current?.handleJoystickInput(x, y); + }, []); + return ( { - gameManagerRef.current?.setJoystickInput(x, y); - }} + onJoystickInput={handleInput} /> ); } \ No newline at end of file diff --git a/apps/client/src/scenes/game/GameView.tsx b/apps/client/src/scenes/game/GameView.tsx index 7aa33b6..f31fea2 100644 --- a/apps/client/src/scenes/game/GameView.tsx +++ b/apps/client/src/scenes/game/GameView.tsx @@ -9,11 +9,11 @@ type Props = { timeLeft: string; pixiContainerRef: React.RefObject; - onInput: (x: number, y: number) => void; + onJoystickInput: (x: number, y: number) => void; }; /** 画面描画と入力UIをまとめて描画する */ -export const GameView = ({ timeLeft, pixiContainerRef, onInput }: Props) => { +export const GameView = ({ timeLeft, pixiContainerRef, onJoystickInput }: Props) => { return (
- +
);