|
|
@ -14,7 +14,9 @@ import plainCourt from "../assets/court/full_court.svg"
|
|
|
|
import halfCourt from "../assets/court/half_court.svg"
|
|
|
|
import halfCourt from "../assets/court/half_court.svg"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { BallPiece } from "../components/editor/BallPiece"
|
|
|
|
import {BallPiece, CourtBall} from "../components/editor/BallPiece";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { Rack } from "../components/Rack"
|
|
|
|
import { Rack } from "../components/Rack"
|
|
|
|
import { PlayerPiece } from "../components/editor/PlayerPiece"
|
|
|
|
import { PlayerPiece } from "../components/editor/PlayerPiece"
|
|
|
@ -29,7 +31,6 @@ import SavingState, {
|
|
|
|
SaveState,
|
|
|
|
SaveState,
|
|
|
|
SaveStates,
|
|
|
|
SaveStates,
|
|
|
|
} from "../components/editor/SavingState"
|
|
|
|
} from "../components/editor/SavingState"
|
|
|
|
import * as Console from "console";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import {CourtObject} from "../tactic/CourtObjects";
|
|
|
|
import {CourtObject} from "../tactic/CourtObjects";
|
|
|
|
|
|
|
|
|
|
|
@ -122,6 +123,7 @@ function EditorView({
|
|
|
|
onNameChange,
|
|
|
|
onNameChange,
|
|
|
|
courtType,
|
|
|
|
courtType,
|
|
|
|
}: EditorViewProps) {
|
|
|
|
}: EditorViewProps) {
|
|
|
|
|
|
|
|
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
|
|
|
|
|
|
|
|
const [titleStyle, setTitleStyle] = useState<CSSProperties>({})
|
|
|
|
const [titleStyle, setTitleStyle] = useState<CSSProperties>({})
|
|
|
@ -146,6 +148,11 @@ function EditorView({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isBoundsOnCourt = (bounds: DOMRect) => {
|
|
|
|
const isBoundsOnCourt = (bounds: DOMRect) => {
|
|
|
|
|
|
|
|
const rackBallRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
|
|
const [rackBall, setRackBall] = useState<boolean>(true)
|
|
|
|
|
|
|
|
const courtDivContentRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const canDetach = (bounds: DOMRect) => {
|
|
|
|
const courtBounds = courtDivContentRef.current!.getBoundingClientRect()
|
|
|
|
const courtBounds = courtDivContentRef.current!.getBoundingClientRect()
|
|
|
|
|
|
|
|
|
|
|
|
// check if refBounds overlaps courtBounds
|
|
|
|
// check if refBounds overlaps courtBounds
|
|
|
@ -177,12 +184,12 @@ function EditorView({
|
|
|
|
hasBall: false,
|
|
|
|
hasBall: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
|
|
|
|
ball: content.ball
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const onObjectDetach = (
|
|
|
|
const onObjectDetach = (
|
|
|
|
ref: HTMLDivElement,
|
|
|
|
|
|
|
|
rackedObject: RackedCourtObject,
|
|
|
|
rackedObject: RackedCourtObject,
|
|
|
|
) => {
|
|
|
|
) => {
|
|
|
|
const refBounds = ref.getBoundingClientRect()
|
|
|
|
const refBounds = ref.getBoundingClientRect()
|
|
|
@ -228,6 +235,44 @@ function EditorView({
|
|
|
|
...content,
|
|
|
|
...content,
|
|
|
|
objects: [...content.objects, courtObject],
|
|
|
|
objects: [...content.objects, courtObject],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onBallDetach = (pos: DOMRect) => {
|
|
|
|
|
|
|
|
const courtBounds = courtDivContentRef.current!.getBoundingClientRect()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const {x, y} = calculateRatio(pos, courtBounds)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
players: content.players,
|
|
|
|
|
|
|
|
ball: {
|
|
|
|
|
|
|
|
rightRatio: x,
|
|
|
|
|
|
|
|
bottomRatio: y
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onBallDrop = (ballBounds: DOMRect) => {
|
|
|
|
|
|
|
|
let ballAssigned = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setContent(content => {
|
|
|
|
|
|
|
|
const players = content.players.map(player => {
|
|
|
|
|
|
|
|
if (ballAssigned) {
|
|
|
|
|
|
|
|
return {...player, hasBall: false}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const playerBounds = document.getElementById(player.id)!.getBoundingClientRect()
|
|
|
|
|
|
|
|
const doesOverlap = !(
|
|
|
|
|
|
|
|
ballBounds.top > playerBounds.bottom ||
|
|
|
|
|
|
|
|
ballBounds.right < playerBounds.left ||
|
|
|
|
|
|
|
|
ballBounds.bottom < playerBounds.top ||
|
|
|
|
|
|
|
|
ballBounds.left > playerBounds.right
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if (doesOverlap) {
|
|
|
|
|
|
|
|
ballAssigned = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return {...player, hasBall: doesOverlap}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return {players: players, ball: content.ball}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -362,7 +407,7 @@ function EditorView({
|
|
|
|
<div id="topbar-left">
|
|
|
|
<div id="topbar-left">
|
|
|
|
|
|
|
|
|
|
|
|
<SavingState state={saveState}/>
|
|
|
|
<SavingState state={saveState}/>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="title-input-div">
|
|
|
|
<div id="title-input-div">
|
|
|
|
<TitleInput
|
|
|
|
<TitleInput
|
|
|
@ -451,6 +496,7 @@ function EditorView({
|
|
|
|
player,
|
|
|
|
player,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
ball: content.ball
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
onPlayerRemove={(player) => {
|
|
|
|
onPlayerRemove={(player) => {
|
|
|
|