|
|
@ -24,6 +24,7 @@ import SavingState, {
|
|
|
|
SaveState,
|
|
|
|
SaveState,
|
|
|
|
SaveStates,
|
|
|
|
SaveStates,
|
|
|
|
} from "../components/editor/SavingState"
|
|
|
|
} from "../components/editor/SavingState"
|
|
|
|
|
|
|
|
import Draggable from "react-draggable";
|
|
|
|
|
|
|
|
|
|
|
|
const ERROR_STYLE: CSSProperties = {
|
|
|
|
const ERROR_STYLE: CSSProperties = {
|
|
|
|
borderColor: "red",
|
|
|
|
borderColor: "red",
|
|
|
@ -113,8 +114,7 @@ function EditorView({
|
|
|
|
getRackPlayers(Team.Opponents, content.players),
|
|
|
|
getRackPlayers(Team.Opponents, content.players),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ballPiece = useRef<HTMLDivElement>(null)
|
|
|
|
const [ball, setBall] = useState<Ball[]>([]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const courtDivContentRef = useRef<HTMLDivElement>(null)
|
|
|
|
const courtDivContentRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
|
|
|
|
|
@ -143,6 +143,7 @@ function EditorView({
|
|
|
|
players: [
|
|
|
|
players: [
|
|
|
|
...content.players,
|
|
|
|
...content.players,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
id: "player-" + content.players.length,
|
|
|
|
team: element.team,
|
|
|
|
team: element.team,
|
|
|
|
role: element.key,
|
|
|
|
role: element.key,
|
|
|
|
rightRatio: x,
|
|
|
|
rightRatio: x,
|
|
|
@ -154,37 +155,22 @@ function EditorView({
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const canDetachBall = (ref: HTMLDivElement) => {
|
|
|
|
const onElementDetachBall = () => {
|
|
|
|
const refBounds = ref.getBoundingClientRect();
|
|
|
|
const ballBounds = ballPiece.current!.getBoundingClientRect()
|
|
|
|
const courtBounds = courtDivContentRef.current!.getBoundingClientRect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//check if we give the ball to a player on the court
|
|
|
|
for (const player of content.players) {
|
|
|
|
if (!canDetach(ref)) {
|
|
|
|
const playerBounds = document.getElementById(player.id)!.getBoundingClientRect()
|
|
|
|
return false;
|
|
|
|
const doesNotOverlap = (
|
|
|
|
|
|
|
|
ballBounds.top > playerBounds.bottom ||
|
|
|
|
|
|
|
|
ballBounds.right < playerBounds.left ||
|
|
|
|
|
|
|
|
ballBounds.bottom < playerBounds.top ||
|
|
|
|
|
|
|
|
ballBounds.left > playerBounds.right
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if (doesNotOverlap) {
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*for(const player in players) {
|
|
|
|
player.hasBall = true
|
|
|
|
const rightRatio = player
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const onElementDetachBall = (ref: HTMLDivElement) => {
|
|
|
|
|
|
|
|
const refBounds = ref.getBoundingClientRect()
|
|
|
|
|
|
|
|
const courtBounds = courtDivContentRef.current!.getBoundingClientRect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const relativeXPixels = refBounds.x - courtBounds.x;
|
|
|
|
|
|
|
|
const relativeYPixels = refBounds.y - courtBounds.y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const xPercent = relativeXPixels / courtBounds.width;
|
|
|
|
|
|
|
|
const yPercent = relativeYPixels / courtBounds.height;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setBall(ball => {
|
|
|
|
|
|
|
|
return [...ball, {
|
|
|
|
|
|
|
|
right_percentage: xPercent,
|
|
|
|
|
|
|
|
bottom_percentage: yPercent,
|
|
|
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -220,13 +206,15 @@ function EditorView({
|
|
|
|
<PlayerPiece team={team} text={key} key={key}/>
|
|
|
|
<PlayerPiece team={team} text={key} key={key}/>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<Rack
|
|
|
|
|
|
|
|
id="ball-rack"
|
|
|
|
<Draggable
|
|
|
|
objects={ball}
|
|
|
|
onStop={onElementDetachBall}
|
|
|
|
onChange={setBall}
|
|
|
|
>
|
|
|
|
canDetach={canDetachBall}
|
|
|
|
<div ref={ballPiece}>
|
|
|
|
onElementDetached={onElementDetachBall}
|
|
|
|
<BallPiece/>
|
|
|
|
render={({pos}) => <BallPiece key={pos}/>}/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</Draggable>
|
|
|
|
|
|
|
|
|
|
|
|
<Rack
|
|
|
|
<Rack
|
|
|
|
id="opponent-rack"
|
|
|
|
id="opponent-rack"
|
|
|
|
objects={opponents}
|
|
|
|
objects={opponents}
|
|
|
|