|
|
@ -1,8 +1,10 @@
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
CSSProperties,
|
|
|
|
CSSProperties,
|
|
|
|
Dispatch,
|
|
|
|
Dispatch,
|
|
|
|
|
|
|
|
RefObject,
|
|
|
|
SetStateAction,
|
|
|
|
SetStateAction,
|
|
|
|
useCallback,
|
|
|
|
useCallback,
|
|
|
|
|
|
|
|
useEffect,
|
|
|
|
useMemo,
|
|
|
|
useMemo,
|
|
|
|
useRef,
|
|
|
|
useRef,
|
|
|
|
useState,
|
|
|
|
useState,
|
|
|
@ -20,10 +22,7 @@ import { PlayerPiece } from "../components/editor/PlayerPiece"
|
|
|
|
import {Tactic, TacticComponent, TacticContent} from "../model/tactic/Tactic"
|
|
|
|
import {Tactic, TacticComponent, TacticContent} from "../model/tactic/Tactic"
|
|
|
|
import {fetchAPI} from "../Fetcher"
|
|
|
|
import {fetchAPI} from "../Fetcher"
|
|
|
|
|
|
|
|
|
|
|
|
import SavingState, {
|
|
|
|
import SavingState, {SaveState, SaveStates,} from "../components/editor/SavingState"
|
|
|
|
SaveState,
|
|
|
|
|
|
|
|
SaveStates,
|
|
|
|
|
|
|
|
} from "../components/editor/SavingState"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import {BALL_TYPE} from "../model/tactic/CourtObjects"
|
|
|
|
import {BALL_TYPE} from "../model/tactic/CourtObjects"
|
|
|
|
import {CourtAction} from "./editor/CourtAction"
|
|
|
|
import {CourtAction} from "./editor/CourtAction"
|
|
|
@ -40,25 +39,15 @@ import {
|
|
|
|
removeBall,
|
|
|
|
removeBall,
|
|
|
|
updateComponent,
|
|
|
|
updateComponent,
|
|
|
|
} from "../editor/TacticContentDomains"
|
|
|
|
} from "../editor/TacticContentDomains"
|
|
|
|
import {
|
|
|
|
import {BallState, Player, PlayerInfo, PlayerPhantom, PlayerTeam,} from "../model/tactic/Player"
|
|
|
|
BallState,
|
|
|
|
import {RackedCourtObject, RackedPlayer} from "../editor/RackedItems"
|
|
|
|
Player,
|
|
|
|
|
|
|
|
PlayerInfo,
|
|
|
|
|
|
|
|
PlayerPhantom,
|
|
|
|
|
|
|
|
PlayerTeam,
|
|
|
|
|
|
|
|
} from "../model/tactic/Player"
|
|
|
|
|
|
|
|
import { RackedCourtObject } from "../editor/RackedItems"
|
|
|
|
|
|
|
|
import CourtPlayer from "../components/editor/CourtPlayer"
|
|
|
|
import CourtPlayer from "../components/editor/CourtPlayer"
|
|
|
|
import { getActionKind, placeArrow } from "../editor/ActionsDomains"
|
|
|
|
import {createAction, getActionKind, isActionValid, removeAction} from "../editor/ActionsDomains"
|
|
|
|
import ArrowAction from "../components/actions/ArrowAction"
|
|
|
|
import ArrowAction from "../components/actions/ArrowAction"
|
|
|
|
import { middlePos, ratioWithinBase } from "../geo/Pos"
|
|
|
|
import {middlePos, Pos, ratioWithinBase} from "../geo/Pos"
|
|
|
|
import {Action, ActionKind} from "../model/tactic/Action"
|
|
|
|
import {Action, ActionKind} from "../model/tactic/Action"
|
|
|
|
import BallAction from "../components/actions/BallAction"
|
|
|
|
import BallAction from "../components/actions/BallAction"
|
|
|
|
import {
|
|
|
|
import {changePlayerBallState, getOrigin, removePlayer,} from "../editor/PlayerDomains"
|
|
|
|
getOrigin,
|
|
|
|
|
|
|
|
removePlayer,
|
|
|
|
|
|
|
|
truncatePlayerPath,
|
|
|
|
|
|
|
|
} from "../editor/PlayerDomains"
|
|
|
|
|
|
|
|
import {CourtBall} from "../components/editor/CourtBall"
|
|
|
|
import {CourtBall} from "../components/editor/CourtBall"
|
|
|
|
import {BASE} from "../Constants"
|
|
|
|
import {BASE} from "../Constants"
|
|
|
|
|
|
|
|
|
|
|
@ -133,6 +122,7 @@ function EditorView({
|
|
|
|
onNameChange,
|
|
|
|
onNameChange,
|
|
|
|
courtType,
|
|
|
|
courtType,
|
|
|
|
}: EditorViewProps) {
|
|
|
|
}: EditorViewProps) {
|
|
|
|
|
|
|
|
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
|
|
|
|
|
|
|
|
const [titleStyle, setTitleStyle] = useState<CSSProperties>({})
|
|
|
|
const [titleStyle, setTitleStyle] = useState<CSSProperties>({})
|
|
|
@ -169,8 +159,6 @@ function EditorView({
|
|
|
|
|
|
|
|
|
|
|
|
const courtRef = useRef<HTMLDivElement>(null)
|
|
|
|
const courtRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
|
|
|
|
|
|
const actionsReRenderHooks = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const setComponents = (action: SetStateAction<TacticComponent[]>) => {
|
|
|
|
const setComponents = (action: SetStateAction<TacticComponent[]>) => {
|
|
|
|
setContent((c) => ({
|
|
|
|
setContent((c) => ({
|
|
|
|
...c,
|
|
|
|
...c,
|
|
|
@ -179,6 +167,12 @@ function EditorView({
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const courtBounds = useCallback(() => courtRef.current!.getBoundingClientRect(), [courtRef])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
setObjects(isBallOnCourt(content) ? [] : [{key: "ball"}])
|
|
|
|
|
|
|
|
}, [setObjects, content]);
|
|
|
|
|
|
|
|
|
|
|
|
const insertRackedPlayer = (player: Player) => {
|
|
|
|
const insertRackedPlayer = (player: Player) => {
|
|
|
|
let setter
|
|
|
|
let setter
|
|
|
|
switch (player.team) {
|
|
|
|
switch (player.team) {
|
|
|
@ -188,7 +182,7 @@ function EditorView({
|
|
|
|
case PlayerTeam.Allies:
|
|
|
|
case PlayerTeam.Allies:
|
|
|
|
setter = setAllies
|
|
|
|
setter = setAllies
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (player.ballState == BallState.HOLDS) {
|
|
|
|
if (player.ballState == BallState.HOLDS_BY_PASS) {
|
|
|
|
setObjects([{key: "ball"}])
|
|
|
|
setObjects([{key: "ball"}])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setter((players) => [
|
|
|
|
setter((players) => [
|
|
|
@ -201,47 +195,97 @@ function EditorView({
|
|
|
|
])
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const doMoveBall = (newBounds: DOMRect) => {
|
|
|
|
const doRemovePlayer = useCallback((component: Player | PlayerPhantom) => {
|
|
|
|
|
|
|
|
setContent((c) => removePlayer(component, c))
|
|
|
|
|
|
|
|
if (component.type == "player") insertRackedPlayer(component)
|
|
|
|
|
|
|
|
}, [setContent])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const doMoveBall = useCallback((newBounds: DOMRect, from?: Player | PlayerPhantom) => {
|
|
|
|
setContent((content) => {
|
|
|
|
setContent((content) => {
|
|
|
|
const { newContent, removed } = placeBallAt(
|
|
|
|
if (from) {
|
|
|
|
|
|
|
|
content = changePlayerBallState(from, BallState.NONE, content)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content = placeBallAt(
|
|
|
|
newBounds,
|
|
|
|
newBounds,
|
|
|
|
courtBounds(),
|
|
|
|
courtBounds(),
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if (removed) {
|
|
|
|
return content
|
|
|
|
setObjects((objects) => [...objects, { key: "ball" }])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return newContent
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}, [courtBounds, setContent])
|
|
|
|
|
|
|
|
|
|
|
|
const courtBounds = () => courtRef.current!.getBoundingClientRect()
|
|
|
|
const validatePlayerPosition = useCallback((player: Player | PlayerPhantom, info: PlayerInfo, newPos: Pos) => {
|
|
|
|
|
|
|
|
setContent((content) =>
|
|
|
|
|
|
|
|
moveComponent(
|
|
|
|
|
|
|
|
newPos,
|
|
|
|
|
|
|
|
player,
|
|
|
|
|
|
|
|
info,
|
|
|
|
|
|
|
|
courtBounds(),
|
|
|
|
|
|
|
|
content,
|
|
|
|
|
|
|
|
|
|
|
|
const renderPlayer = (component: Player | PlayerPhantom) => {
|
|
|
|
(content) => {
|
|
|
|
let info: PlayerInfo
|
|
|
|
if (player.type == "player") insertRackedPlayer(player)
|
|
|
|
|
|
|
|
return removePlayer(player, content)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}, [courtBounds, setContent])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const renderAvailablePlayerActions = useCallback((info: PlayerInfo, player: Player | PlayerPhantom) => {
|
|
|
|
let canPlaceArrows: boolean
|
|
|
|
let canPlaceArrows: boolean
|
|
|
|
const isPhantom = component.type == "phantom"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isPhantom) {
|
|
|
|
if (player.type == "player") {
|
|
|
|
const origin = getOrigin(component, content.components)
|
|
|
|
canPlaceArrows =
|
|
|
|
|
|
|
|
player.path == null ||
|
|
|
|
|
|
|
|
player.actions.findIndex(
|
|
|
|
|
|
|
|
(p) => p.type != ActionKind.SHOOT,
|
|
|
|
|
|
|
|
) == -1
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const origin = getOrigin(player, content.components)
|
|
|
|
const path = origin.path!
|
|
|
|
const path = origin.path!
|
|
|
|
// phantoms can only place other arrows if they are the head of the path
|
|
|
|
// phantoms can only place other arrows if they are the head of the path
|
|
|
|
canPlaceArrows =
|
|
|
|
canPlaceArrows =
|
|
|
|
path.items.indexOf(component.id) == path.items.length - 1
|
|
|
|
path.items.indexOf(player.id) == path.items.length - 1
|
|
|
|
if (canPlaceArrows) {
|
|
|
|
if (canPlaceArrows) {
|
|
|
|
// and if their only action is to shoot the ball
|
|
|
|
// and if their only action is to shoot the ball
|
|
|
|
|
|
|
|
const phantomActions = player.actions
|
|
|
|
// list the actions the phantoms does
|
|
|
|
|
|
|
|
const phantomActions = component.actions
|
|
|
|
|
|
|
|
canPlaceArrows =
|
|
|
|
canPlaceArrows =
|
|
|
|
phantomActions.length == 0 ||
|
|
|
|
phantomActions.length == 0 ||
|
|
|
|
phantomActions.findIndex(
|
|
|
|
phantomActions.findIndex(
|
|
|
|
(c) => c.type != ActionKind.SHOOT,
|
|
|
|
(c) => c.type != ActionKind.SHOOT,
|
|
|
|
) == -1
|
|
|
|
) == -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
|
|
|
canPlaceArrows && (
|
|
|
|
|
|
|
|
<CourtPlayerArrowAction
|
|
|
|
|
|
|
|
key={1}
|
|
|
|
|
|
|
|
player={player}
|
|
|
|
|
|
|
|
isInvalid={previewAction?.isInvalid ?? false}
|
|
|
|
|
|
|
|
setPreviewAction={setPreviewAction}
|
|
|
|
|
|
|
|
playerInfo={info}
|
|
|
|
|
|
|
|
content={content}
|
|
|
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
|
|
|
setContent={setContent}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
(info.ballState === BallState.HOLDS_ORIGIN || info.ballState === BallState.PASSED_ORIGIN) && (
|
|
|
|
|
|
|
|
<BallAction key={2} onDrop={(ballBounds) => {
|
|
|
|
|
|
|
|
doMoveBall(ballBounds, player)
|
|
|
|
|
|
|
|
}}/>
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}, [content, doMoveBall, previewAction?.isInvalid, setContent])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const renderPlayer = useCallback((component: Player | PlayerPhantom) => {
|
|
|
|
|
|
|
|
let info: PlayerInfo
|
|
|
|
|
|
|
|
const isPhantom = component.type == "phantom"
|
|
|
|
|
|
|
|
if (isPhantom) {
|
|
|
|
|
|
|
|
const origin = getOrigin(component, content.components)
|
|
|
|
info = {
|
|
|
|
info = {
|
|
|
|
id: component.id,
|
|
|
|
id: component.id,
|
|
|
|
team: origin.team,
|
|
|
|
team: origin.team,
|
|
|
@ -251,14 +295,7 @@ function EditorView({
|
|
|
|
ballState: component.ballState,
|
|
|
|
ballState: component.ballState,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// a player
|
|
|
|
|
|
|
|
info = component
|
|
|
|
info = component
|
|
|
|
// can place arrows only if the
|
|
|
|
|
|
|
|
canPlaceArrows =
|
|
|
|
|
|
|
|
component.path == null ||
|
|
|
|
|
|
|
|
component.actions.findIndex(
|
|
|
|
|
|
|
|
(p) => p.type != ActionKind.SHOOT,
|
|
|
|
|
|
|
|
) == -1
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
@ -266,165 +303,87 @@ function EditorView({
|
|
|
|
key={component.id}
|
|
|
|
key={component.id}
|
|
|
|
className={isPhantom ? "phantom" : "player"}
|
|
|
|
className={isPhantom ? "phantom" : "player"}
|
|
|
|
playerInfo={info}
|
|
|
|
playerInfo={info}
|
|
|
|
onPositionValidated={(newPos) => {
|
|
|
|
onPositionValidated={(newPos) => validatePlayerPosition(component, info, newPos)}
|
|
|
|
setContent((content) =>
|
|
|
|
onRemove={() => doRemovePlayer(component)}
|
|
|
|
moveComponent(
|
|
|
|
|
|
|
|
newPos,
|
|
|
|
|
|
|
|
component,
|
|
|
|
|
|
|
|
info,
|
|
|
|
|
|
|
|
courtBounds(),
|
|
|
|
|
|
|
|
content,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(content) => {
|
|
|
|
|
|
|
|
if (!isPhantom) insertRackedPlayer(component)
|
|
|
|
|
|
|
|
return removePlayer(component, content)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
onRemove={() => {
|
|
|
|
|
|
|
|
setContent((c) => removePlayer(component, c))
|
|
|
|
|
|
|
|
if (!isPhantom) insertRackedPlayer(component)
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
courtRef={courtRef}
|
|
|
|
availableActions={() => [
|
|
|
|
availableActions={() => renderAvailablePlayerActions(info, component)}
|
|
|
|
canPlaceArrows && (
|
|
|
|
/>
|
|
|
|
<ArrowAction
|
|
|
|
|
|
|
|
key={1}
|
|
|
|
|
|
|
|
onHeadMoved={(headPos) => {
|
|
|
|
|
|
|
|
const arrowHeadPos = middlePos(headPos)
|
|
|
|
|
|
|
|
const targetIdx = getComponentCollided(
|
|
|
|
|
|
|
|
headPos,
|
|
|
|
|
|
|
|
content.components,
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
}, [content.components, doRemovePlayer, renderAvailablePlayerActions, validatePlayerPosition])
|
|
|
|
|
|
|
|
|
|
|
|
setPreviewAction((action) => ({
|
|
|
|
const doDeleteAction = useCallback((
|
|
|
|
...action!,
|
|
|
|
action: Action,
|
|
|
|
segments: [
|
|
|
|
idx: number,
|
|
|
|
{
|
|
|
|
origin: TacticComponent,
|
|
|
|
next: ratioWithinBase(
|
|
|
|
) => {
|
|
|
|
arrowHeadPos,
|
|
|
|
setContent((content) => removeAction(origin, action, idx, content))
|
|
|
|
courtBounds(),
|
|
|
|
}, [setContent])
|
|
|
|
),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
type: getActionKind(
|
|
|
|
|
|
|
|
targetIdx != -1,
|
|
|
|
|
|
|
|
info.ballState,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
onHeadPicked={(headPos) => {
|
|
|
|
|
|
|
|
;(document.activeElement as HTMLElement).blur()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setPreviewAction({
|
|
|
|
const doUpdateAction = useCallback((component: TacticComponent, action: Action, actionIndex: number) => {
|
|
|
|
origin: component.id,
|
|
|
|
setContent((content) =>
|
|
|
|
type: getActionKind(false, info.ballState),
|
|
|
|
updateComponent(
|
|
|
|
target: ratioWithinBase(
|
|
|
|
|
|
|
|
headPos,
|
|
|
|
|
|
|
|
courtBounds(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
segments: [
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
next: ratioWithinBase(
|
|
|
|
...component,
|
|
|
|
middlePos(headPos),
|
|
|
|
actions:
|
|
|
|
courtBounds(),
|
|
|
|
component.actions.toSpliced(
|
|
|
|
|
|
|
|
actionIndex,
|
|
|
|
|
|
|
|
1,
|
|
|
|
|
|
|
|
action,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
onHeadDropped={(headRect) => {
|
|
|
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
|
|
|
let { createdAction, newContent } =
|
|
|
|
|
|
|
|
placeArrow(
|
|
|
|
|
|
|
|
component,
|
|
|
|
|
|
|
|
courtBounds(),
|
|
|
|
|
|
|
|
headRect,
|
|
|
|
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
}, [setContent])
|
|
|
|
|
|
|
|
|
|
|
|
let originNewBallState = component.ballState
|
|
|
|
const renderComponent = useCallback((component: TacticComponent) => {
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
createdAction.type == ActionKind.SHOOT
|
|
|
|
component.type == "player" ||
|
|
|
|
|
|
|
|
component.type == "phantom"
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
const targetIdx =
|
|
|
|
return renderPlayer(component)
|
|
|
|
newContent.components.findIndex(
|
|
|
|
|
|
|
|
(c) =>
|
|
|
|
|
|
|
|
c.id ==
|
|
|
|
|
|
|
|
createdAction.target,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
newContent = dropBallOnComponent(
|
|
|
|
|
|
|
|
targetIdx,
|
|
|
|
|
|
|
|
newContent,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
originNewBallState = BallState.SHOOTED
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (component.type == BALL_TYPE) {
|
|
|
|
newContent = updateComponent(
|
|
|
|
return (
|
|
|
|
{
|
|
|
|
<CourtBall
|
|
|
|
...(newContent.components.find(
|
|
|
|
key="ball"
|
|
|
|
(c) => c.id == component.id,
|
|
|
|
ball={component}
|
|
|
|
)! as Player | PlayerPhantom),
|
|
|
|
onPosValidated={doMoveBall}
|
|
|
|
ballState: originNewBallState,
|
|
|
|
onRemove={() => {
|
|
|
|
},
|
|
|
|
setContent((content) =>
|
|
|
|
newContent,
|
|
|
|
removeBall(content),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return newContent
|
|
|
|
setObjects((objects) => [
|
|
|
|
})
|
|
|
|
...objects,
|
|
|
|
setPreviewAction(null)
|
|
|
|
{key: "ball"},
|
|
|
|
|
|
|
|
])
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
|
|
|
|
info.ballState != BallState.NONE && (
|
|
|
|
|
|
|
|
<BallAction key={2} onDrop={doMoveBall} />
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
]}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(
|
|
|
|
const doDeleteAction = (
|
|
|
|
"unknown tactic component " + component,
|
|
|
|
action: Action,
|
|
|
|
|
|
|
|
idx: number,
|
|
|
|
|
|
|
|
component: TacticComponent,
|
|
|
|
|
|
|
|
) => {
|
|
|
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
|
|
|
content = updateComponent(
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
...component,
|
|
|
|
|
|
|
|
actions: component.actions.toSpliced(idx, 1),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
content,
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
}, [renderPlayer, doMoveBall, setContent])
|
|
|
|
|
|
|
|
|
|
|
|
if (action.target == null) return content
|
|
|
|
const renderActions = useCallback((component: TacticComponent) =>
|
|
|
|
|
|
|
|
component.actions.map((action, i) => {
|
|
|
|
const target = content.components.find(
|
|
|
|
return (
|
|
|
|
(c) => action.target == c.id,
|
|
|
|
<CourtAction
|
|
|
|
)!
|
|
|
|
key={"action-" + component.id + "-" + i}
|
|
|
|
|
|
|
|
action={action}
|
|
|
|
if (target.type == "phantom") {
|
|
|
|
origin={component.id}
|
|
|
|
let path = null
|
|
|
|
courtRef={courtRef}
|
|
|
|
if (component.type == "player") {
|
|
|
|
isInvalid={false}
|
|
|
|
path = component.path
|
|
|
|
onActionDeleted={() => {
|
|
|
|
} else if (component.type == "phantom") {
|
|
|
|
doDeleteAction(action, i, component)
|
|
|
|
path = getOrigin(component, content.components).path
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
onActionChanges={(action) =>
|
|
|
|
|
|
|
|
doUpdateAction(component, action, i)
|
|
|
|
if (
|
|
|
|
|
|
|
|
path == null ||
|
|
|
|
|
|
|
|
path.items.find((c) => c == target.id) == null
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
content = removePlayer(target, content)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}), [doDeleteAction, doUpdateAction])
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div id="main-div">
|
|
|
|
<div id="main-div">
|
|
|
@ -439,52 +398,28 @@ function EditorView({
|
|
|
|
<TitleInput
|
|
|
|
<TitleInput
|
|
|
|
style={titleStyle}
|
|
|
|
style={titleStyle}
|
|
|
|
default_value={name}
|
|
|
|
default_value={name}
|
|
|
|
on_validated={(new_name) => {
|
|
|
|
onValidated={useCallback((new_name) => {
|
|
|
|
onNameChange(new_name).then((success) => {
|
|
|
|
onNameChange(new_name).then((success) => {
|
|
|
|
setTitleStyle(success ? {} : ERROR_STYLE)
|
|
|
|
setTitleStyle(success ? {} : ERROR_STYLE)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
}, [onNameChange])}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="topbar-right"/>
|
|
|
|
<div id="topbar-right"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="edit-div">
|
|
|
|
<div id="edit-div">
|
|
|
|
<div id="racks">
|
|
|
|
<div id="racks">
|
|
|
|
<Rack
|
|
|
|
<PlayerRack id={"allies"} objects={allies} setObjects={setAllies} setComponents={setComponents}
|
|
|
|
id="allies-rack"
|
|
|
|
courtRef={courtRef}/>
|
|
|
|
objects={allies}
|
|
|
|
|
|
|
|
onChange={setAllies}
|
|
|
|
|
|
|
|
canDetach={(div) =>
|
|
|
|
|
|
|
|
overlaps(courtBounds(), div.getBoundingClientRect())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
onElementDetached={(r, e) =>
|
|
|
|
|
|
|
|
setComponents((components) => [
|
|
|
|
|
|
|
|
...components,
|
|
|
|
|
|
|
|
placePlayerAt(
|
|
|
|
|
|
|
|
r.getBoundingClientRect(),
|
|
|
|
|
|
|
|
courtBounds(),
|
|
|
|
|
|
|
|
e,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
render={({ team, key }) => (
|
|
|
|
|
|
|
|
<PlayerPiece
|
|
|
|
|
|
|
|
team={team}
|
|
|
|
|
|
|
|
text={key}
|
|
|
|
|
|
|
|
key={key}
|
|
|
|
|
|
|
|
hasBall={false}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<Rack
|
|
|
|
<Rack
|
|
|
|
id={"objects"}
|
|
|
|
id={"objects"}
|
|
|
|
objects={objects}
|
|
|
|
objects={objects}
|
|
|
|
onChange={setObjects}
|
|
|
|
onChange={setObjects}
|
|
|
|
canDetach={(div) =>
|
|
|
|
canDetach={useCallback((div) =>
|
|
|
|
overlaps(courtBounds(), div.getBoundingClientRect())
|
|
|
|
overlaps(courtBounds(), div.getBoundingClientRect())
|
|
|
|
}
|
|
|
|
, [courtBounds])}
|
|
|
|
onElementDetached={(r, e) =>
|
|
|
|
onElementDetached={useCallback((r, e: RackedCourtObject) =>
|
|
|
|
setContent((content) =>
|
|
|
|
setContent((content) =>
|
|
|
|
placeObjectAt(
|
|
|
|
placeObjectAt(
|
|
|
|
r.getBoundingClientRect(),
|
|
|
|
r.getBoundingClientRect(),
|
|
|
@ -493,18 +428,51 @@ function EditorView({
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
, [courtBounds, setContent])}
|
|
|
|
render={renderCourtObject}
|
|
|
|
render={renderCourtObject}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<PlayerRack id={"opponents"} objects={opponents} setObjects={setOpponents}
|
|
|
|
|
|
|
|
setComponents={setComponents} courtRef={courtRef}/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="court-div">
|
|
|
|
|
|
|
|
<div id="court-div-bounds">
|
|
|
|
|
|
|
|
<BasketCourt
|
|
|
|
|
|
|
|
components={content.components}
|
|
|
|
|
|
|
|
courtImage={<Court courtType={courtType}/>}
|
|
|
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
|
|
|
previewAction={previewAction}
|
|
|
|
|
|
|
|
renderComponent={renderComponent}
|
|
|
|
|
|
|
|
renderActions={renderActions}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface PlayerRackProps {
|
|
|
|
|
|
|
|
id: string
|
|
|
|
|
|
|
|
objects: RackedPlayer[]
|
|
|
|
|
|
|
|
setObjects: (state: RackedPlayer[]) => 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])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Rack
|
|
|
|
<Rack
|
|
|
|
id="opponent-rack"
|
|
|
|
id={id}
|
|
|
|
objects={opponents}
|
|
|
|
objects={objects}
|
|
|
|
onChange={setOpponents}
|
|
|
|
onChange={setObjects}
|
|
|
|
canDetach={(div) =>
|
|
|
|
canDetach={useCallback((div) =>
|
|
|
|
overlaps(courtBounds(), div.getBoundingClientRect())
|
|
|
|
overlaps(courtBounds(), div.getBoundingClientRect())
|
|
|
|
}
|
|
|
|
, [courtBounds])}
|
|
|
|
onElementDetached={(r, e) =>
|
|
|
|
onElementDetached={useCallback((r, e: RackedPlayer) =>
|
|
|
|
setComponents((components) => [
|
|
|
|
setComponents((components) => [
|
|
|
|
...components,
|
|
|
|
...components,
|
|
|
|
placePlayerAt(
|
|
|
|
placePlayerAt(
|
|
|
@ -513,87 +481,138 @@ function EditorView({
|
|
|
|
e,
|
|
|
|
e,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
])
|
|
|
|
])
|
|
|
|
}
|
|
|
|
, [courtBounds, setComponents])}
|
|
|
|
render={({ team, key }) => (
|
|
|
|
render={useCallback(({team, key}: { team: PlayerTeam, key: string }) => (
|
|
|
|
<PlayerPiece
|
|
|
|
<PlayerPiece
|
|
|
|
team={team}
|
|
|
|
team={team}
|
|
|
|
text={key}
|
|
|
|
text={key}
|
|
|
|
key={key}
|
|
|
|
key={key}
|
|
|
|
hasBall={false}
|
|
|
|
hasBall={false}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
), [])}
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="court-div">
|
|
|
|
|
|
|
|
<div id="court-div-bounds">
|
|
|
|
|
|
|
|
<BasketCourt
|
|
|
|
|
|
|
|
components={content.components}
|
|
|
|
|
|
|
|
courtImage={<Court courtType={courtType} />}
|
|
|
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
|
|
|
previewAction={previewAction}
|
|
|
|
|
|
|
|
renderComponent={(component) => {
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
component.type == "player" ||
|
|
|
|
|
|
|
|
component.type == "phantom"
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return renderPlayer(component)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (component.type == BALL_TYPE) {
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<CourtBall
|
|
|
|
|
|
|
|
key="ball"
|
|
|
|
|
|
|
|
ball={component}
|
|
|
|
|
|
|
|
onPosValidated={doMoveBall}
|
|
|
|
|
|
|
|
onRemove={() => {
|
|
|
|
|
|
|
|
setContent((content) =>
|
|
|
|
|
|
|
|
removeBall(content),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
setObjects((objects) => [
|
|
|
|
|
|
|
|
...objects,
|
|
|
|
|
|
|
|
{ key: "ball" },
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new Error(
|
|
|
|
|
|
|
|
"unknown tactic component " + component,
|
|
|
|
interface CourtPlayerArrowActionProps {
|
|
|
|
|
|
|
|
playerInfo: PlayerInfo
|
|
|
|
|
|
|
|
player: Player | PlayerPhantom
|
|
|
|
|
|
|
|
isInvalid: boolean
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content: TacticContent
|
|
|
|
|
|
|
|
setContent: (state: SetStateAction<TacticContent>) => void
|
|
|
|
|
|
|
|
setPreviewAction: (state: SetStateAction<ActionPreview | null>) => void
|
|
|
|
|
|
|
|
courtRef: RefObject<HTMLDivElement>
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function CourtPlayerArrowAction({
|
|
|
|
|
|
|
|
playerInfo,
|
|
|
|
|
|
|
|
player,
|
|
|
|
|
|
|
|
isInvalid,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content,
|
|
|
|
|
|
|
|
setContent,
|
|
|
|
|
|
|
|
setPreviewAction,
|
|
|
|
|
|
|
|
courtRef
|
|
|
|
|
|
|
|
}: CourtPlayerArrowActionProps) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const courtBounds = useCallback(() => courtRef.current!.getBoundingClientRect(), [courtRef])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<ArrowAction
|
|
|
|
|
|
|
|
key={1}
|
|
|
|
|
|
|
|
onHeadMoved={(headPos) => {
|
|
|
|
|
|
|
|
const arrowHeadPos = middlePos(headPos)
|
|
|
|
|
|
|
|
const targetIdx = getComponentCollided(
|
|
|
|
|
|
|
|
headPos,
|
|
|
|
|
|
|
|
content.components,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
const target = content.components[targetIdx]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setPreviewAction((action) => ({
|
|
|
|
|
|
|
|
...action!,
|
|
|
|
|
|
|
|
segments: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
next: ratioWithinBase(
|
|
|
|
|
|
|
|
arrowHeadPos,
|
|
|
|
|
|
|
|
courtBounds(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
type: getActionKind(
|
|
|
|
|
|
|
|
target,
|
|
|
|
|
|
|
|
playerInfo.ballState,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
isInvalid: !overlaps(headPos, courtBounds()) || !isActionValid(player, target, content.components)
|
|
|
|
|
|
|
|
}))
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
renderActions={(component) =>
|
|
|
|
onHeadPicked={(headPos) => {
|
|
|
|
component.actions.map((action, i) => (
|
|
|
|
(document.activeElement as HTMLElement).blur()
|
|
|
|
<CourtAction
|
|
|
|
|
|
|
|
key={"action-" + component.id + "-" + i}
|
|
|
|
setPreviewAction({
|
|
|
|
action={action}
|
|
|
|
origin: playerInfo.id,
|
|
|
|
origin={component.id}
|
|
|
|
type: getActionKind(null, playerInfo.ballState),
|
|
|
|
courtRef={courtRef}
|
|
|
|
target: ratioWithinBase(
|
|
|
|
onActionDeleted={() => {
|
|
|
|
headPos,
|
|
|
|
doDeleteAction(action, i, component)
|
|
|
|
courtBounds(),
|
|
|
|
}}
|
|
|
|
),
|
|
|
|
onActionChanges={(a) =>
|
|
|
|
segments: [
|
|
|
|
setContent((content) =>
|
|
|
|
|
|
|
|
updateComponent(
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
...component,
|
|
|
|
next: ratioWithinBase(
|
|
|
|
actions:
|
|
|
|
middlePos(headPos),
|
|
|
|
component.actions.toSpliced(
|
|
|
|
courtBounds(),
|
|
|
|
i,
|
|
|
|
|
|
|
|
1,
|
|
|
|
|
|
|
|
a,
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
isInvalid: false
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
onHeadDropped={(headRect) => {
|
|
|
|
|
|
|
|
if (isInvalid) {
|
|
|
|
|
|
|
|
setPreviewAction(null)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
|
|
|
let {createdAction, newContent} =
|
|
|
|
|
|
|
|
createAction(
|
|
|
|
|
|
|
|
player,
|
|
|
|
|
|
|
|
courtBounds(),
|
|
|
|
|
|
|
|
headRect,
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
createdAction.type == ActionKind.SHOOT
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
const targetIdx =
|
|
|
|
|
|
|
|
newContent.components.findIndex(
|
|
|
|
|
|
|
|
(c) =>
|
|
|
|
|
|
|
|
c.id ==
|
|
|
|
|
|
|
|
createdAction.target,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
newContent = dropBallOnComponent(
|
|
|
|
|
|
|
|
targetIdx,
|
|
|
|
|
|
|
|
newContent,
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
newContent = updateComponent(
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
...(newContent.components.find(
|
|
|
|
|
|
|
|
(c) => c.id == player.id,
|
|
|
|
|
|
|
|
)! as Player | PlayerPhantom),
|
|
|
|
|
|
|
|
ballState: BallState.PASSED,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
newContent,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return newContent
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
setPreviewAction(null)
|
|
|
|
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -601,7 +620,7 @@ function isBallOnCourt(content: TacticContent) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
content.components.findIndex(
|
|
|
|
content.components.findIndex(
|
|
|
|
(c) =>
|
|
|
|
(c) =>
|
|
|
|
(c.type == "player" && c.ballState == BallState.HOLDS) ||
|
|
|
|
(c.type == "player" && (c.ballState === BallState.HOLDS_ORIGIN || c.ballState === BallState.HOLDS_BY_PASS)) ||
|
|
|
|
c.type == BALL_TYPE,
|
|
|
|
c.type == BALL_TYPE,
|
|
|
|
) != -1
|
|
|
|
) != -1
|
|
|
|
)
|
|
|
|
)
|
|
|
|