import {ReactNode, RefObject, useRef} from "react" import "../../style/player.css" import Draggable from "react-draggable" import {PlayerPiece} from "./PlayerPiece" import {BallState, PlayerInfo} from "../../model/tactic/Player" import {NULL_POS, Pos, ratioWithinBase} from "../../geo/Pos" export interface CourtPlayerProps { playerInfo: PlayerInfo className?: string onMoves: () => void onPositionValidated: (newPos: Pos) => void onRemove: () => void courtRef: RefObject availableActions: (ro: HTMLElement) => ReactNode[] } /** * A player that is placed on the court, which can be selected, and moved in the associated bounds * */ export default function CourtPlayer({ playerInfo, className, onMoves, onPositionValidated, onRemove, courtRef, availableActions, }: CourtPlayerProps) { const usesBall = playerInfo.ballState != BallState.NONE const x = playerInfo.rightRatio const y = playerInfo.bottomRatio const pieceRef = useRef(null) return ( { const pieceBounds = pieceRef.current!.getBoundingClientRect() const parentBounds = courtRef.current!.getBoundingClientRect() const pos = ratioWithinBase(pieceBounds, parentBounds) onPositionValidated(pos) }}>
{ if (e.key == "Delete") onRemove() }}>
{availableActions(pieceRef.current!)}
) }