import { RefObject, useRef } from "react" import "../../style/player.css" <<<<<<< HEAD import { BallPiece } from "./BallPiece" ======= import {BallPiece} from "./BallPiece" >>>>>>> 20078f8 (can put the ball on the court if we want) import Draggable from "react-draggable" import { PlayerPiece } from "./PlayerPiece" import { Player } from "../../tactic/Player" import { calculateRatio } from "../../Utils" export interface PlayerProps { player: Player onChange: (p: Player) => void onRemove: () => void onBallDrop: (bounds: DOMRect) => void parentRef: RefObject } /** * A player that is placed on the court, which can be selected, and moved in the associated bounds * */ export default function CourtPlayer({ player, onChange, onRemove, onBallDrop, parentRef, }: PlayerProps) { const pieceRef = useRef(null) const ballPiece = useRef(null) const x = player.rightRatio const y = player.bottomRatio const hasBall = player.hasBall return ( { const pieceBounds = pieceRef.current!.getBoundingClientRect() const parentBounds = parentRef.current!.getBoundingClientRect() const { x, y } = calculateRatio(pieceBounds, parentBounds) onChange({ id: player.id, rightRatio: x, bottomRatio: y, team: player.team, role: player.role, hasBall: player.hasBall, }) }}>
{ if (e.key == "Delete") onRemove() }}>
<<<<<<< HEAD {hasBall && ( onBallDrop( ballPiece.current!.getBoundingClientRect(), ) } position={{ x: 0, y: 0 }}>
)} ======= {hasBall && ( onBallDrop(ballPiece.current!.getBoundingClientRect())} position={{x:0, y: 0}}>
)} >>>>>>> 20078f8 (can put the ball on the court if we want)
) }