/**
* JoystickInputPresenter
* ジョイスティック入力の受け取りと表示状態の橋渡しを担うプレゼンター
* 入力イベントをコントローラーへ委譲し,描画用状態をViewへ渡す
*/
import { useJoystickController } from "./useJoystickController";
import { JoystickView } from "./JoystickView";
import type { UseJoystickInputPresenterProps } from "./common";
/** 入力と表示状態の橋渡しを行う */
export const JoystickInputPresenter = ({
onInput,
maxDist,
isEnabled = true,
}: UseJoystickInputPresenterProps) => {
const {
isMoving,
center,
knobOffset,
radius,
handleStart,
handleMove,
handleEnd,
} = useJoystickController({ onInput, maxDist });
return (
<div
onPointerDown={isEnabled ? handleStart : undefined}
onPointerMove={isEnabled ? handleMove : undefined}
onPointerUp={isEnabled ? handleEnd : undefined}
onPointerCancel={isEnabled ? handleEnd : undefined}
onLostPointerCapture={isEnabled ? handleEnd : undefined}
style={{
position: "absolute",
top: 0,
left: 0,
width: "50%",
height: "100%",
// キャンバス前面入力キャプチャレイヤー
zIndex: 10,
touchAction: "none",
pointerEvents: isEnabled ? "auto" : "none",
}}
>
{/* 入力イベントをコントローラーへ渡し,描画用状態をViewへ渡す */}
<JoystickView
isActive={isMoving}
center={center}
knobOffset={knobOffset}
radius={radius}
/>
</div>
);
};