|
|
|
@ -22,7 +22,10 @@ import {PlayerPiece} from "../components/editor/PlayerPiece"
|
|
|
|
|
import { Tactic, TacticComponent, TacticContent } from "../model/tactic/Tactic"
|
|
|
|
|
import { fetchAPI } from "../Fetcher"
|
|
|
|
|
|
|
|
|
|
import SavingState, {SaveState, SaveStates,} from "../components/editor/SavingState"
|
|
|
|
|
import SavingState, {
|
|
|
|
|
SaveState,
|
|
|
|
|
SaveStates,
|
|
|
|
|
} from "../components/editor/SavingState"
|
|
|
|
|
|
|
|
|
|
import { BALL_TYPE } from "../model/tactic/CourtObjects"
|
|
|
|
|
import { CourtAction } from "./editor/CourtAction"
|
|
|
|
@ -39,15 +42,30 @@ import {
|
|
|
|
|
removeBall,
|
|
|
|
|
updateComponent,
|
|
|
|
|
} from "../editor/TacticContentDomains"
|
|
|
|
|
import {BallState, Player, PlayerInfo, PlayerPhantom, PlayerTeam,} from "../model/tactic/Player"
|
|
|
|
|
import {
|
|
|
|
|
BallState,
|
|
|
|
|
Player,
|
|
|
|
|
PlayerInfo,
|
|
|
|
|
PlayerPhantom,
|
|
|
|
|
PlayerTeam,
|
|
|
|
|
} from "../model/tactic/Player"
|
|
|
|
|
import { RackedCourtObject, RackedPlayer } from "../editor/RackedItems"
|
|
|
|
|
import CourtPlayer from "../components/editor/CourtPlayer"
|
|
|
|
|
import {createAction, getActionKind, isActionValid, removeAction} from "../editor/ActionsDomains"
|
|
|
|
|
import {
|
|
|
|
|
createAction,
|
|
|
|
|
getActionKind,
|
|
|
|
|
isActionValid,
|
|
|
|
|
removeAction,
|
|
|
|
|
} from "../editor/ActionsDomains"
|
|
|
|
|
import ArrowAction from "../components/actions/ArrowAction"
|
|
|
|
|
import { middlePos, Pos, ratioWithinBase } from "../geo/Pos"
|
|
|
|
|
import { Action, ActionKind } from "../model/tactic/Action"
|
|
|
|
|
import BallAction from "../components/actions/BallAction"
|
|
|
|
|
import {changePlayerBallState, getOrigin, removePlayer,} from "../editor/PlayerDomains"
|
|
|
|
|
import {
|
|
|
|
|
changePlayerBallState,
|
|
|
|
|
getOrigin,
|
|
|
|
|
removePlayer,
|
|
|
|
|
} from "../editor/PlayerDomains"
|
|
|
|
|
import { CourtBall } from "../components/editor/CourtBall"
|
|
|
|
|
import { BASE } from "../Constants"
|
|
|
|
|
|
|
|
|
@ -122,7 +140,6 @@ function EditorView({
|
|
|
|
|
onNameChange,
|
|
|
|
|
courtType,
|
|
|
|
|
}: EditorViewProps) {
|
|
|
|
|
|
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
|
|
|
|
|
|
const [titleStyle, setTitleStyle] = useState<CSSProperties>({})
|
|
|
|
@ -167,11 +184,14 @@ function EditorView({
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const courtBounds = useCallback(() => courtRef.current!.getBoundingClientRect(), [courtRef])
|
|
|
|
|
const courtBounds = useCallback(
|
|
|
|
|
() => courtRef.current!.getBoundingClientRect(),
|
|
|
|
|
[courtRef],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setObjects(isBallOnCourt(content) ? [] : [{ key: "ball" }])
|
|
|
|
|
}, [setObjects, content]);
|
|
|
|
|
}, [setObjects, content])
|
|
|
|
|
|
|
|
|
|
const insertRackedPlayer = (player: Player) => {
|
|
|
|
|
let setter
|
|
|
|
@ -195,28 +215,35 @@ function EditorView({
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const doRemovePlayer = useCallback((component: Player | PlayerPhantom) => {
|
|
|
|
|
const doRemovePlayer = useCallback(
|
|
|
|
|
(component: Player | PlayerPhantom) => {
|
|
|
|
|
setContent((c) => removePlayer(component, c))
|
|
|
|
|
if (component.type == "player") insertRackedPlayer(component)
|
|
|
|
|
}, [setContent])
|
|
|
|
|
},
|
|
|
|
|
[setContent],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const doMoveBall = useCallback((newBounds: DOMRect, from?: Player | PlayerPhantom) => {
|
|
|
|
|
const doMoveBall = useCallback(
|
|
|
|
|
(newBounds: DOMRect, from?: Player | PlayerPhantom) => {
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
if (from) {
|
|
|
|
|
content = changePlayerBallState(from, BallState.NONE, content)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content = placeBallAt(
|
|
|
|
|
newBounds,
|
|
|
|
|
courtBounds(),
|
|
|
|
|
content = changePlayerBallState(
|
|
|
|
|
from,
|
|
|
|
|
BallState.NONE,
|
|
|
|
|
content,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content = placeBallAt(newBounds, courtBounds(), content)
|
|
|
|
|
|
|
|
|
|
return content
|
|
|
|
|
})
|
|
|
|
|
}, [courtBounds, setContent])
|
|
|
|
|
},
|
|
|
|
|
[courtBounds, setContent],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const validatePlayerPosition = useCallback((player: Player | PlayerPhantom, info: PlayerInfo, newPos: Pos) => {
|
|
|
|
|
const validatePlayerPosition = useCallback(
|
|
|
|
|
(player: Player | PlayerPhantom, info: PlayerInfo, newPos: Pos) => {
|
|
|
|
|
setContent((content) =>
|
|
|
|
|
moveComponent(
|
|
|
|
|
newPos,
|
|
|
|
@ -231,9 +258,12 @@ function EditorView({
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}, [courtBounds, setContent])
|
|
|
|
|
},
|
|
|
|
|
[courtBounds, setContent],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const renderAvailablePlayerActions = useCallback((info: PlayerInfo, player: Player | PlayerPhantom) => {
|
|
|
|
|
const renderAvailablePlayerActions = useCallback(
|
|
|
|
|
(info: PlayerInfo, player: Player | PlayerPhantom) => {
|
|
|
|
|
let canPlaceArrows: boolean
|
|
|
|
|
|
|
|
|
|
if (player.type == "player") {
|
|
|
|
@ -259,7 +289,6 @@ function EditorView({
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
canPlaceArrows && (
|
|
|
|
|
<CourtPlayerArrowAction
|
|
|
|
@ -273,15 +302,22 @@ function EditorView({
|
|
|
|
|
setContent={setContent}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
(info.ballState === BallState.HOLDS_ORIGIN || info.ballState === BallState.PASSED_ORIGIN) && (
|
|
|
|
|
<BallAction key={2} onDrop={(ballBounds) => {
|
|
|
|
|
(info.ballState === BallState.HOLDS_ORIGIN ||
|
|
|
|
|
info.ballState === BallState.PASSED_ORIGIN) && (
|
|
|
|
|
<BallAction
|
|
|
|
|
key={2}
|
|
|
|
|
onDrop={(ballBounds) => {
|
|
|
|
|
doMoveBall(ballBounds, player)
|
|
|
|
|
}}/>
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
}, [content, doMoveBall, previewAction?.isInvalid, setContent])
|
|
|
|
|
},
|
|
|
|
|
[content, doMoveBall, previewAction?.isInvalid, setContent],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const renderPlayer = useCallback((component: Player | PlayerPhantom) => {
|
|
|
|
|
const renderPlayer = useCallback(
|
|
|
|
|
(component: Player | PlayerPhantom) => {
|
|
|
|
|
let info: PlayerInfo
|
|
|
|
|
const isPhantom = component.type == "phantom"
|
|
|
|
|
if (isPhantom) {
|
|
|
|
@ -303,29 +339,39 @@ function EditorView({
|
|
|
|
|
key={component.id}
|
|
|
|
|
className={isPhantom ? "phantom" : "player"}
|
|
|
|
|
playerInfo={info}
|
|
|
|
|
onPositionValidated={(newPos) => validatePlayerPosition(component, info, newPos)}
|
|
|
|
|
onPositionValidated={(newPos) =>
|
|
|
|
|
validatePlayerPosition(component, info, newPos)
|
|
|
|
|
}
|
|
|
|
|
onRemove={() => doRemovePlayer(component)}
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
availableActions={() => renderAvailablePlayerActions(info, component)}
|
|
|
|
|
availableActions={() =>
|
|
|
|
|
renderAvailablePlayerActions(info, component)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}, [content.components, doRemovePlayer, renderAvailablePlayerActions, validatePlayerPosition])
|
|
|
|
|
},
|
|
|
|
|
[
|
|
|
|
|
content.components,
|
|
|
|
|
doRemovePlayer,
|
|
|
|
|
renderAvailablePlayerActions,
|
|
|
|
|
validatePlayerPosition,
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const doDeleteAction = useCallback((
|
|
|
|
|
action: Action,
|
|
|
|
|
idx: number,
|
|
|
|
|
origin: TacticComponent,
|
|
|
|
|
) => {
|
|
|
|
|
const doDeleteAction = useCallback(
|
|
|
|
|
(action: Action, idx: number, origin: TacticComponent) => {
|
|
|
|
|
setContent((content) => removeAction(origin, action, idx, content))
|
|
|
|
|
}, [setContent])
|
|
|
|
|
},
|
|
|
|
|
[setContent],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const doUpdateAction = useCallback((component: TacticComponent, action: Action, actionIndex: number) => {
|
|
|
|
|
const doUpdateAction = useCallback(
|
|
|
|
|
(component: TacticComponent, action: Action, actionIndex: number) => {
|
|
|
|
|
setContent((content) =>
|
|
|
|
|
updateComponent(
|
|
|
|
|
{
|
|
|
|
|
...component,
|
|
|
|
|
actions:
|
|
|
|
|
component.actions.toSpliced(
|
|
|
|
|
actions: component.actions.toSpliced(
|
|
|
|
|
actionIndex,
|
|
|
|
|
1,
|
|
|
|
|
action,
|
|
|
|
@ -334,13 +380,13 @@ function EditorView({
|
|
|
|
|
content,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}, [setContent])
|
|
|
|
|
},
|
|
|
|
|
[setContent],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const renderComponent = useCallback((component: TacticComponent) => {
|
|
|
|
|
if (
|
|
|
|
|
component.type == "player" ||
|
|
|
|
|
component.type == "phantom"
|
|
|
|
|
) {
|
|
|
|
|
const renderComponent = useCallback(
|
|
|
|
|
(component: TacticComponent) => {
|
|
|
|
|
if (component.type == "player" || component.type == "phantom") {
|
|
|
|
|
return renderPlayer(component)
|
|
|
|
|
}
|
|
|
|
|
if (component.type == BALL_TYPE) {
|
|
|
|
@ -350,9 +396,7 @@ function EditorView({
|
|
|
|
|
ball={component}
|
|
|
|
|
onPosValidated={doMoveBall}
|
|
|
|
|
onRemove={() => {
|
|
|
|
|
setContent((content) =>
|
|
|
|
|
removeBall(content),
|
|
|
|
|
)
|
|
|
|
|
setContent((content) => removeBall(content))
|
|
|
|
|
setObjects((objects) => [
|
|
|
|
|
...objects,
|
|
|
|
|
{ key: "ball" },
|
|
|
|
@ -361,12 +405,13 @@ function EditorView({
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
throw new Error(
|
|
|
|
|
"unknown tactic component " + component,
|
|
|
|
|
throw new Error("unknown tactic component " + component)
|
|
|
|
|
},
|
|
|
|
|
[renderPlayer, doMoveBall, setContent],
|
|
|
|
|
)
|
|
|
|
|
}, [renderPlayer, doMoveBall, setContent])
|
|
|
|
|
|
|
|
|
|
const renderActions = useCallback((component: TacticComponent) =>
|
|
|
|
|
const renderActions = useCallback(
|
|
|
|
|
(component: TacticComponent) =>
|
|
|
|
|
component.actions.map((action, i) => {
|
|
|
|
|
return (
|
|
|
|
|
<CourtAction
|
|
|
|
@ -383,7 +428,9 @@ function EditorView({
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}), [doDeleteAction, doUpdateAction])
|
|
|
|
|
}),
|
|
|
|
|
[doDeleteAction, doUpdateAction],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div id="main-div">
|
|
|
|
@ -398,28 +445,42 @@ function EditorView({
|
|
|
|
|
<TitleInput
|
|
|
|
|
style={titleStyle}
|
|
|
|
|
default_value={name}
|
|
|
|
|
onValidated={useCallback((new_name) => {
|
|
|
|
|
onValidated={useCallback(
|
|
|
|
|
(new_name) => {
|
|
|
|
|
onNameChange(new_name).then((success) => {
|
|
|
|
|
setTitleStyle(success ? {} : ERROR_STYLE)
|
|
|
|
|
})
|
|
|
|
|
}, [onNameChange])}
|
|
|
|
|
},
|
|
|
|
|
[onNameChange],
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="topbar-right" />
|
|
|
|
|
</div>
|
|
|
|
|
<div id="edit-div">
|
|
|
|
|
<div id="racks">
|
|
|
|
|
<PlayerRack id={"allies"} objects={allies} setObjects={setAllies} setComponents={setComponents}
|
|
|
|
|
courtRef={courtRef}/>
|
|
|
|
|
<PlayerRack
|
|
|
|
|
id={"allies"}
|
|
|
|
|
objects={allies}
|
|
|
|
|
setObjects={setAllies}
|
|
|
|
|
setComponents={setComponents}
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<Rack
|
|
|
|
|
id={"objects"}
|
|
|
|
|
objects={objects}
|
|
|
|
|
onChange={setObjects}
|
|
|
|
|
canDetach={useCallback((div) =>
|
|
|
|
|
overlaps(courtBounds(), div.getBoundingClientRect())
|
|
|
|
|
, [courtBounds])}
|
|
|
|
|
onElementDetached={useCallback((r, e: RackedCourtObject) =>
|
|
|
|
|
canDetach={useCallback(
|
|
|
|
|
(div) =>
|
|
|
|
|
overlaps(
|
|
|
|
|
courtBounds(),
|
|
|
|
|
div.getBoundingClientRect(),
|
|
|
|
|
),
|
|
|
|
|
[courtBounds],
|
|
|
|
|
)}
|
|
|
|
|
onElementDetached={useCallback(
|
|
|
|
|
(r, e: RackedCourtObject) =>
|
|
|
|
|
setContent((content) =>
|
|
|
|
|
placeObjectAt(
|
|
|
|
|
r.getBoundingClientRect(),
|
|
|
|
@ -427,13 +488,19 @@ function EditorView({
|
|
|
|
|
e,
|
|
|
|
|
content,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
, [courtBounds, setContent])}
|
|
|
|
|
),
|
|
|
|
|
[courtBounds, setContent],
|
|
|
|
|
)}
|
|
|
|
|
render={renderCourtObject}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<PlayerRack id={"opponents"} objects={opponents} setObjects={setOpponents}
|
|
|
|
|
setComponents={setComponents} courtRef={courtRef}/>
|
|
|
|
|
<PlayerRack
|
|
|
|
|
id={"opponents"}
|
|
|
|
|
objects={opponents}
|
|
|
|
|
setObjects={setOpponents}
|
|
|
|
|
setComponents={setComponents}
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="court-div">
|
|
|
|
|
<div id="court-div-bounds">
|
|
|
|
@ -456,23 +523,35 @@ interface PlayerRackProps {
|
|
|
|
|
id: string
|
|
|
|
|
objects: RackedPlayer[]
|
|
|
|
|
setObjects: (state: RackedPlayer[]) => void
|
|
|
|
|
setComponents: (f: (components: TacticComponent[]) => TacticComponent[]) => void
|
|
|
|
|
setComponents: (
|
|
|
|
|
f: (components: TacticComponent[]) => TacticComponent[],
|
|
|
|
|
) => void
|
|
|
|
|
courtRef: RefObject<HTMLDivElement>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function PlayerRack({id, objects, setObjects, courtRef, setComponents}: PlayerRackProps) {
|
|
|
|
|
|
|
|
|
|
const courtBounds = useCallback(() => courtRef.current!.getBoundingClientRect(), [courtRef])
|
|
|
|
|
function PlayerRack({
|
|
|
|
|
id,
|
|
|
|
|
objects,
|
|
|
|
|
setObjects,
|
|
|
|
|
courtRef,
|
|
|
|
|
setComponents,
|
|
|
|
|
}: PlayerRackProps) {
|
|
|
|
|
const courtBounds = useCallback(
|
|
|
|
|
() => courtRef.current!.getBoundingClientRect(),
|
|
|
|
|
[courtRef],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Rack
|
|
|
|
|
id={id}
|
|
|
|
|
objects={objects}
|
|
|
|
|
onChange={setObjects}
|
|
|
|
|
canDetach={useCallback((div) =>
|
|
|
|
|
overlaps(courtBounds(), div.getBoundingClientRect())
|
|
|
|
|
, [courtBounds])}
|
|
|
|
|
onElementDetached={useCallback((r, e: RackedPlayer) =>
|
|
|
|
|
canDetach={useCallback(
|
|
|
|
|
(div) => overlaps(courtBounds(), div.getBoundingClientRect()),
|
|
|
|
|
[courtBounds],
|
|
|
|
|
)}
|
|
|
|
|
onElementDetached={useCallback(
|
|
|
|
|
(r, e: RackedPlayer) =>
|
|
|
|
|
setComponents((components) => [
|
|
|
|
|
...components,
|
|
|
|
|
placePlayerAt(
|
|
|
|
@ -480,16 +559,20 @@ function PlayerRack({id, objects, setObjects, courtRef, setComponents}: PlayerRa
|
|
|
|
|
courtBounds(),
|
|
|
|
|
e,
|
|
|
|
|
),
|
|
|
|
|
])
|
|
|
|
|
, [courtBounds, setComponents])}
|
|
|
|
|
render={useCallback(({team, key}: { team: PlayerTeam, key: string }) => (
|
|
|
|
|
]),
|
|
|
|
|
[courtBounds, setComponents],
|
|
|
|
|
)}
|
|
|
|
|
render={useCallback(
|
|
|
|
|
({ team, key }: { team: PlayerTeam; key: string }) => (
|
|
|
|
|
<PlayerPiece
|
|
|
|
|
team={team}
|
|
|
|
|
text={key}
|
|
|
|
|
key={key}
|
|
|
|
|
hasBall={false}
|
|
|
|
|
/>
|
|
|
|
|
), [])}
|
|
|
|
|
),
|
|
|
|
|
[],
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
@ -513,10 +596,12 @@ function CourtPlayerArrowAction({
|
|
|
|
|
content,
|
|
|
|
|
setContent,
|
|
|
|
|
setPreviewAction,
|
|
|
|
|
courtRef
|
|
|
|
|
courtRef,
|
|
|
|
|
}: CourtPlayerArrowActionProps) {
|
|
|
|
|
|
|
|
|
|
const courtBounds = useCallback(() => courtRef.current!.getBoundingClientRect(), [courtRef])
|
|
|
|
|
const courtBounds = useCallback(
|
|
|
|
|
() => courtRef.current!.getBoundingClientRect(),
|
|
|
|
|
[courtRef],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ArrowAction
|
|
|
|
@ -533,29 +618,22 @@ function CourtPlayerArrowAction({
|
|
|
|
|
...action!,
|
|
|
|
|
segments: [
|
|
|
|
|
{
|
|
|
|
|
next: ratioWithinBase(
|
|
|
|
|
arrowHeadPos,
|
|
|
|
|
courtBounds(),
|
|
|
|
|
),
|
|
|
|
|
next: ratioWithinBase(arrowHeadPos, courtBounds()),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
type: getActionKind(
|
|
|
|
|
target,
|
|
|
|
|
playerInfo.ballState,
|
|
|
|
|
),
|
|
|
|
|
isInvalid: !overlaps(headPos, courtBounds()) || !isActionValid(player, target, content.components)
|
|
|
|
|
type: getActionKind(target, playerInfo.ballState),
|
|
|
|
|
isInvalid:
|
|
|
|
|
!overlaps(headPos, courtBounds()) ||
|
|
|
|
|
!isActionValid(player, target, content.components),
|
|
|
|
|
}))
|
|
|
|
|
}}
|
|
|
|
|
onHeadPicked={(headPos) => {
|
|
|
|
|
(document.activeElement as HTMLElement).blur()
|
|
|
|
|
;(document.activeElement as HTMLElement).blur()
|
|
|
|
|
|
|
|
|
|
setPreviewAction({
|
|
|
|
|
origin: playerInfo.id,
|
|
|
|
|
type: getActionKind(null, playerInfo.ballState),
|
|
|
|
|
target: ratioWithinBase(
|
|
|
|
|
headPos,
|
|
|
|
|
courtBounds(),
|
|
|
|
|
),
|
|
|
|
|
target: ratioWithinBase(headPos, courtBounds()),
|
|
|
|
|
segments: [
|
|
|
|
|
{
|
|
|
|
|
next: ratioWithinBase(
|
|
|
|
@ -564,7 +642,7 @@ function CourtPlayerArrowAction({
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
isInvalid: false
|
|
|
|
|
isInvalid: false,
|
|
|
|
|
})
|
|
|
|
|
}}
|
|
|
|
|
onHeadDropped={(headRect) => {
|
|
|
|
@ -574,27 +652,21 @@ function CourtPlayerArrowAction({
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
let {createdAction, newContent} =
|
|
|
|
|
createAction(
|
|
|
|
|
let { createdAction, newContent } = createAction(
|
|
|
|
|
player,
|
|
|
|
|
courtBounds(),
|
|
|
|
|
headRect,
|
|
|
|
|
content,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
createdAction.type == ActionKind.SHOOT
|
|
|
|
|
) {
|
|
|
|
|
const targetIdx =
|
|
|
|
|
newContent.components.findIndex(
|
|
|
|
|
(c) =>
|
|
|
|
|
c.id ==
|
|
|
|
|
createdAction.target,
|
|
|
|
|
if (createdAction.type == ActionKind.SHOOT) {
|
|
|
|
|
const targetIdx = newContent.components.findIndex(
|
|
|
|
|
(c) => c.id == createdAction.target,
|
|
|
|
|
)
|
|
|
|
|
newContent = dropBallOnComponent(
|
|
|
|
|
targetIdx,
|
|
|
|
|
newContent,
|
|
|
|
|
false
|
|
|
|
|
false,
|
|
|
|
|
)
|
|
|
|
|
newContent = updateComponent(
|
|
|
|
|
{
|
|
|
|
@ -607,7 +679,6 @@ function CourtPlayerArrowAction({
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return newContent
|
|
|
|
|
})
|
|
|
|
|
setPreviewAction(null)
|
|
|
|
@ -620,8 +691,10 @@ function isBallOnCourt(content: TacticContent) {
|
|
|
|
|
return (
|
|
|
|
|
content.components.findIndex(
|
|
|
|
|
(c) =>
|
|
|
|
|
(c.type == "player" && (c.ballState === BallState.HOLDS_ORIGIN || c.ballState === BallState.HOLDS_BY_PASS)) ||
|
|
|
|
|
c.type == BALL_TYPE,
|
|
|
|
|
((c.type === "player" || c.type === "phantom") &&
|
|
|
|
|
(c.ballState === BallState.HOLDS_ORIGIN ||
|
|
|
|
|
c.ballState === BallState.PASSED_ORIGIN)) ||
|
|
|
|
|
c.type === BALL_TYPE,
|
|
|
|
|
) != -1
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|