diff --git a/front/components/editor/CourtPlayer.tsx b/front/components/editor/CourtPlayer.tsx
index a5f9c51..e375c78 100644
--- a/front/components/editor/CourtPlayer.tsx
+++ b/front/components/editor/CourtPlayer.tsx
@@ -1,6 +1,10 @@
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"
@@ -67,6 +71,7 @@ export default function CourtPlayer({
if (e.key == "Delete") onRemove()
}}>
+<<<<<<< HEAD
{hasBall && (
)}
+=======
+ {hasBall && (
onBallDrop(ballPiece.current!.getBoundingClientRect())}
+ position={{x:0, y: 0}}>
+
+
+
+ )}
+>>>>>>> 20078f8 (can put the ball on the court if we want)
({})
@@ -129,15 +136,15 @@ function EditorView({
const [opponents, setOpponents] = useState(
getRackPlayers(Team.Opponents, content.players),
)
- const [objects, setObjects] = useState([{key: "ball"}])
+
+ const [objects, setObjects] = useState(
+ isBallOnCourt(content) ? [] : [{ key: "ball" }],
+ )
const courtDivContentRef = useRef(null)
const isBoundsOnCourt = (bounds: DOMRect) => {
- const courtDivContentRef = useRef(null)
-
- const canDetach = (bounds: DOMRect) => {
const courtBounds = courtDivContentRef.current!.getBoundingClientRect()
// check if refBounds overlaps courtBounds
@@ -174,6 +181,7 @@ function EditorView({
}
const onObjectDetach = (
+ ref: HTMLDivElement,
rackedObject: RackedCourtObject,
) => {
const refBounds = ref.getBoundingClientRect()
@@ -219,38 +227,9 @@ function EditorView({
...content,
objects: [...content.objects, courtObject],
}
-
- const onObjectDetach = (ref: HTMLDivElement, rackedObject: RackedCourtObject) => {
- const refBounds = ref.getBoundingClientRect()
- const courtBounds = courtDivContentRef.current!.getBoundingClientRect()
-
- const {x, y} = calculateRatio(refBounds, courtBounds)
-
- let courtObject: CourtObject
-
-
- switch (rackedObject.key) {
- case "ball":
- courtObject = {
- type: "ball",
- rightRatio: x,
- bottomRatio: y
- }
- break
- default:
- throw new Error("unknown court object ", rackedObject.key)
- }
-
- setContent((content) =>
- ({
- ...content,
- objects: [
- ...content.objects,
- courtObject,
- ]
- })
- )
+ })
}
+
const getPlayerCollided = (
bounds: DOMRect,
players: Player[],
@@ -487,7 +466,6 @@ function EditorView({
)
}
-
function isBallOnCourt(content: TacticContent) {
if (content.players.findIndex((p) => p.hasBall) != -1) {
return true
@@ -497,7 +475,7 @@ function isBallOnCourt(content: TacticContent) {
function renderCourtObject(courtObject: RackedCourtObject) {
if (courtObject.key == "ball") {
- return
+ return
}
throw new Error("unknown racked court object ", courtObject.key)
}
@@ -552,4 +530,4 @@ function toSplicedPlayers(
)
return players.toSpliced(idx, 1, ...(replace ? [player] : []))
-}
+}
\ No newline at end of file