add possibility to remove ball from the court

pull/77/head
Vivien DUFOUR 1 year ago
parent 0cd937cd3b
commit c68344dab0

@ -5,10 +5,10 @@ import {Ball} from "../../tactic/CourtObjects";
export interface CourtBallProps { export interface CourtBallProps {
onMoved: (rect: DOMRect) => void onMoved: (rect: DOMRect) => void
onRemove: () => void
ball: Ball ball: Ball
} }
export function BallPiece() { export function BallPiece() {
return ( return (
<BallSvg className={"ball"}/> <BallSvg className={"ball"}/>

@ -13,6 +13,8 @@ export interface BasketCourtProps {
onPlayerRemove: (p: Player) => void onPlayerRemove: (p: Player) => void
onPlayerChange: (p: Player) => void onPlayerChange: (p: Player) => void
onBallRemove : () => void
onBallMoved: (ball: DOMRect) => void, onBallMoved: (ball: DOMRect) => void,
courtImage: string courtImage: string
@ -20,10 +22,10 @@ export interface BasketCourtProps {
} }
export function BasketCourt({ export function BasketCourt({
players, players,
objects, objects,
onPlayerRemove, onPlayerRemove,
onBallRemove,
onBallMoved, onBallMoved,
onPlayerChange, onPlayerChange,
courtImage, courtImage,
@ -54,6 +56,7 @@ export function BasketCourt({
return <CourtBall return <CourtBall
onMoved={onBallMoved} onMoved={onBallMoved}
ball={object} ball={object}
onRemove={onBallRemove}
key="ball" key="ball"
/> />
} }

@ -2,7 +2,8 @@ import React, {useRef} from "react";
import Draggable from "react-draggable"; import Draggable from "react-draggable";
import {BallPiece, CourtBallProps} from "./BallPiece"; import {BallPiece, CourtBallProps} from "./BallPiece";
export function CourtBall({onMoved, ball}: CourtBallProps) {
export function CourtBall({onMoved, ball, onRemove}: CourtBallProps) {
const pieceRef = useRef<HTMLDivElement>(null) const pieceRef = useRef<HTMLDivElement>(null)
const x = ball.rightRatio const x = ball.rightRatio
@ -15,6 +16,10 @@ export function CourtBall({onMoved, ball}: CourtBallProps) {
> >
<div className={"ball-div"} <div className={"ball-div"}
ref={pieceRef} ref={pieceRef}
tabIndex={0}
onKeyUp={(e) => {
if (e.key == "Delete") onRemove()
}}
style={{ style={{
position: "absolute", position: "absolute",
left: `${x * 100}%`, left: `${x * 100}%`,

@ -8,4 +8,9 @@
width: 20px; width: 20px;
height: 20px; height: 20px;
cursor: pointer; cursor: pointer;
tabIndex: 0;
}
.ball-div:focus-within {
} }

@ -111,3 +111,5 @@
.save-state-guest { .save-state-guest {
color: gray; color: gray;
} }

@ -400,6 +400,16 @@ function EditorView({
}, },
]) ])
}} }}
onBallRemove={() => {
setContent((content) => {
const ballObj = content.objects.findIndex(o => o.type == "ball")
return {
...content,
objects: content.objects.toSpliced(ballObj, 1)
}
})
setObjects([{key: "ball"}])
}}
/> />
</div> </div>
</div> </div>

Loading…
Cancel
Save