pull/11/head
Override-6 1 year ago committed by maxime.batista
parent 37cb541df9
commit 57db0e094a

@ -3,6 +3,7 @@ import '../../style/basket_court.css';
import React, {MouseEvent, ReactElement, useRef, useState} from "react"; import React, {MouseEvent, ReactElement, useRef, useState} from "react";
import Player from "./Player"; import Player from "./Player";
const TEAM_MAX_PLAYER = 5;
export function BasketCourt() { export function BasketCourt() {
const [players, setPlayers] = useState<ReactElement[]>([]) const [players, setPlayers] = useState<ReactElement[]>([])
@ -15,11 +16,18 @@ export function BasketCourt() {
backgroundImage: `url(${courtSvg})` backgroundImage: `url(${courtSvg})`
}} }}
onClick={(e: MouseEvent) => { onClick={(e: MouseEvent) => {
let bounds = divRef.current.getBoundingClientRect(); if (e.target != divRef.current)
return
let bounds = divRef.current!.getBoundingClientRect();
let playerCount = players.length;
if (playerCount >= TEAM_MAX_PLAYER) {
return;
}
const player = ( const player = (
<Player key={players.length} <Player key={playerCount}
id={players.length + 1} id={playerCount + 1}
x={e.clientX - bounds.x} x={e.clientX - bounds.x}
y={e.clientY - bounds.y} y={e.clientY - bounds.y}
bounds={{bottom: bounds.height, top: 0, left: 0, right: bounds.width}} bounds={{bottom: bounds.height, top: 0, left: 0, right: bounds.width}}

@ -1,6 +1,6 @@
import React, {useEffect, useRef, useState} from "react"; import React, {useEffect, useRef} from "react";
import "../../style/player.css"; import "../../style/player.css";
import Draggable, {ControlPosition, DraggableBounds} from "react-draggable"; import Draggable, {DraggableBounds} from "react-draggable";
export default function Player({id, x, y, bounds}: { export default function Player({id, x, y, bounds}: {
id: number, id: number,
@ -9,11 +9,11 @@ export default function Player({id, x, y, bounds}: {
bounds: DraggableBounds bounds: DraggableBounds
}) { }) {
const ref = useRef<HTMLDivElement>(); const ref = useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
const playerRect = ref.current?.getBoundingClientRect(); const playerRect = ref.current!.getBoundingClientRect();
bounds.bottom -= playerRect.height / 2; bounds.bottom! -= playerRect.height / 2;
bounds.right -= playerRect.width / 2; bounds.right! -= playerRect.width / 2;
}, [ref]) }, [ref])
return ( return (

@ -29,7 +29,6 @@
] ]
}, },
"devDependencies": { "devDependencies": {
"@svgr/webpack": "^8.1.0",
"@vitejs/plugin-react": "^4.1.0", "@vitejs/plugin-react": "^4.1.0",
"vite-plugin-svgr": "^4.1.0" "vite-plugin-svgr": "^4.1.0"
} }

@ -2,7 +2,6 @@ import {defineConfig} from "vite";
import react from '@vitejs/plugin-react'; import react from '@vitejs/plugin-react';
import fs from "fs"; import fs from "fs";
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'; import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
import svgr from 'vite-plugin-svgr';
function resolve_entries(dirname: string): [string, string][] { function resolve_entries(dirname: string): [string, string][] {
@ -40,8 +39,5 @@ export default defineConfig({
cssInjectedByJsPlugin({ cssInjectedByJsPlugin({
relativeCSSInjection: true, relativeCSSInjection: true,
}), }),
svgr({
include: "**/*.svg",
})
] ]
}) })

Loading…
Cancel
Save