Also added player and ball remove by drag and drop them out of the court Co-authored-by: vivien.dufour <vivien.dufour@etu.uca.fr> Co-authored-by: maxime <maximebatista18@gmail.com> Reviewed-on: #77pull/82/head
parent
7042b48ffe
commit
eb744d0da4
@ -1,21 +1,8 @@
|
||||
import React, { RefObject } from "react"
|
||||
|
||||
import "../../style/ball.css"
|
||||
|
||||
import Ball from "../../assets/icon/ball.svg?react"
|
||||
import Draggable from "react-draggable"
|
||||
|
||||
export interface BallPieceProps {
|
||||
onDrop: () => void
|
||||
pieceRef: RefObject<HTMLDivElement>
|
||||
}
|
||||
import BallSvg from "../../assets/icon/ball.svg?react"
|
||||
import { Ball } from "../../tactic/CourtObjects"
|
||||
|
||||
export function BallPiece({ onDrop, pieceRef }: BallPieceProps) {
|
||||
return (
|
||||
<Draggable onStop={onDrop} nodeRef={pieceRef} position={{ x: 0, y: 0 }}>
|
||||
<div className={`ball-div`} ref={pieceRef}>
|
||||
<Ball className={"ball"} />
|
||||
</div>
|
||||
</Draggable>
|
||||
)
|
||||
export function BallPiece() {
|
||||
return <BallSvg className={"ball"} />
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
import React, { useRef } from "react"
|
||||
import Draggable from "react-draggable"
|
||||
import { BallPiece } from "./BallPiece"
|
||||
import { Ball } from "../../tactic/CourtObjects"
|
||||
|
||||
export interface CourtBallProps {
|
||||
onMoved: (rect: DOMRect) => void
|
||||
onRemove: () => void
|
||||
ball: Ball
|
||||
}
|
||||
|
||||
export function CourtBall({ onMoved, ball, onRemove }: CourtBallProps) {
|
||||
const pieceRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const x = ball.rightRatio
|
||||
const y = ball.bottomRatio
|
||||
|
||||
return (
|
||||
<Draggable
|
||||
onStop={() => onMoved(pieceRef.current!.getBoundingClientRect())}
|
||||
nodeRef={pieceRef}>
|
||||
<div
|
||||
className={"ball-div"}
|
||||
ref={pieceRef}
|
||||
tabIndex={0}
|
||||
onKeyUp={(e) => {
|
||||
if (e.key == "Delete") onRemove()
|
||||
}}
|
||||
style={{
|
||||
position: "absolute",
|
||||
left: `${x * 100}%`,
|
||||
top: `${y * 100}%`,
|
||||
}}>
|
||||
<BallPiece />
|
||||
</div>
|
||||
</Draggable>
|
||||
)
|
||||
}
|
@ -1,11 +1,17 @@
|
||||
export type CourtObject = { type: "ball" } & Ball
|
||||
|
||||
export interface Ball {
|
||||
/**
|
||||
* Percentage of the player's position to the bottom (0 means top, 1 means bottom, 0.5 means middle)
|
||||
* The ball is a "ball" court object
|
||||
*/
|
||||
bottom_percentage: number
|
||||
readonly type: "ball"
|
||||
|
||||
/**
|
||||
* Percentage of the player's position to the bottom (0 means top, 1 means bottom, 0.5 means middle)
|
||||
*/
|
||||
readonly bottomRatio: number
|
||||
/**
|
||||
* Percentage of the player's position to the right (0 means left, 1 means right, 0.5 means middle)
|
||||
*/
|
||||
right_percentage: number
|
||||
readonly rightRatio: number
|
||||
}
|
@ -1,26 +1,26 @@
|
||||
import { Team } from "./Team"
|
||||
|
||||
export interface Player {
|
||||
id: string
|
||||
readonly id: string
|
||||
/**
|
||||
* the player's team
|
||||
* */
|
||||
team: Team
|
||||
readonly team: Team
|
||||
|
||||
/**
|
||||
* player's role
|
||||
* */
|
||||
role: string
|
||||
readonly role: string
|
||||
|
||||
/**
|
||||
* Percentage of the player's position to the bottom (0 means top, 1 means bottom, 0.5 means middle)
|
||||
*/
|
||||
bottomRatio: number
|
||||
readonly bottomRatio: number
|
||||
|
||||
/**
|
||||
* Percentage of the player's position to the right (0 means left, 1 means right, 0.5 means middle)
|
||||
*/
|
||||
rightRatio: number
|
||||
readonly rightRatio: number
|
||||
|
||||
hasBall: boolean
|
||||
readonly hasBall: boolean
|
||||
}
|
||||
|
Loading…
Reference in new issue