You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Application-Web/outputs/public/front/components/editor/BasketCourt.tsx-f01fc52b.js

2 lines
2.9 KiB

import{r as a,j as l}from"../../../jsx-runtime-2e2d9038.js";import{CourtBall as F}from"./CourtBall.tsx-df87788c.js";import L from"./CourtPlayer.tsx-3da10617.js";import{ActionKind as s}from"../../tactic/Action.ts-d727cf33.js";import M from"../actions/ArrowAction.tsx-b082b6c9.js";import{ratioWithinBase as r,middlePos as m}from"../arrows/Pos.ts-9fe07952.js";import N from"../actions/BallAction.tsx-c8825b1d.js";import{contains as T}from"../arrows/Box.ts-eca59774.js";import{CourtAction as V}from"../../views/editor/CourtAction.tsx-15785ac7.js";import"../../../cjs-ff7eb0e1.js";import"../../../index-ca121481.js";import"./BallPiece.tsx-1b2eb023.js";import"./PlayerPiece.tsx-964e2db3.js";import"../arrows/BendableArrow.tsx-f8a85d9b.js";function tt({players:B,actions:C,objects:R,renderAction:x,setActions:p,onPlayerRemove:h,onPlayerChange:v,onBallMoved:E,onBallRemove:P,courtImage:A,courtRef:d}){function y(t,o){const n=document.getElementById(t.id),e=d.current.getBoundingClientRect(),c=r(m(n.getBoundingClientRect()),e);for(const i of B){if(i.id==t.id)continue;const g=document.getElementById(i.id).getBoundingClientRect();if(!(g.top>o.bottom||g.right<o.left||g.bottom<o.top||g.left>o.right)){const O=document.getElementById(i.id).getBoundingClientRect(),S=r(m(O),e),w={fromPlayerId:n.id,toPlayerId:i.id,type:t.hasBall?s.SHOOT:s.SCREEN,moveFrom:c,segments:[{next:S}]};p(k=>[...k,w]);return}}const u={fromPlayerId:n.id,type:t.hasBall?s.DRIBBLE:s.MOVE,moveFrom:r(m(n.getBoundingClientRect()),e),segments:[{next:r(m(o),e)}]};p(i=>[...i,u])}const[I,f]=a.useState(null),b=a.useCallback(t=>{const o=r(m(document.getElementById(t.id).getBoundingClientRect()),d.current.getBoundingClientRect());p(n=>n.map(e=>{if(e.fromPlayerId==t.id)return{...e,moveFrom:o};if(e.toPlayerId==t.id){const c=e.segments.toSpliced(e.segments.length-1,1,{...e.segments[e.segments.length-1],next:o});return{...e,segments:c}}return e}))},[]),[j,D]=a.useState([]);return a.useLayoutEffect(()=>D(C),[C]),l.jsxs("div",{className:"court-container",ref:d,style:{position:"relative"},children:[A,B.map(t=>l.jsx(L,{player:t,onDrag:()=>b(t),onChange:v,onRemove:()=>h(t),courtRef:d,availableActions:o=>[l.jsx(M,{onHeadMoved:n=>{const e=d.current.getBoundingClientRect(),c=m(n),u=B.find(i=>i!=t&&T(document.getElementById(i.id).getBoundingClientRect(),c));f(i=>({...i,segments:[{next:r(c,e)}],type:t.hasBall?u?s.SHOOT:s.DRIBBLE:u?s.SCREEN:s.MOVE}))},onHeadPicked:n=>{document.activeElement.blur();const e=d.current.getBoundingClientRect();f({type:t.hasBall?s.DRIBBLE:s.MOVE,fromPlayerId:t.id,toPlayerId:void 0,moveFrom:r(m(o.getBoundingClientRect()),e),segments:[{next:r(m(n),e)}]})},onHeadDropped:n=>{y(t,n),f(null)}},1),t.hasBall&&l.jsx(N,{onDrop:n=>E(n.getBoundingClientRect())},2)]},t.id)),j.map((t,o)=>x(t,o)),R.map(t=>{if(t.type=="ball")return l.jsx(F,{onMoved:E,ball:t,onRemove:P},"ball");throw new Error("unknown court object",t.type)}),I&&l.jsx(V,{courtRef:d,action:I,onActionDeleted:()=>{},onActionChanges:()=>{}})]})}export{tt as BasketCourt};