import { RefObject, useRef, useState } from "react" import "../../style/player.css" import RemoveIcon from "../../assets/icon/remove.svg?react" import BallIcon from "../../assets/icon/ball.svg?react" 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 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, assignBall, parentRef, }: PlayerProps) { const pieceRef = useRef(null) const x = player.rightRatio const y = player.bottomRatio return ( { const pieceBounds = pieceRef.current!.getBoundingClientRect() const parentBounds = parentRef.current!.getBoundingClientRect() const { x, y } = calculateRatio(pieceBounds, parentBounds) onChange({ rightRatio: x, bottomRatio: y, team: player.team, role: player.role, hasBall: false }) }}>
{ if (e.key == "Delete") onRemove() }}>
) }