|
|
|
@ -1,23 +1,34 @@
|
|
|
|
|
import {CSSProperties, Dispatch, SetStateAction, useCallback, useMemo, useRef, useState,} from "react"
|
|
|
|
|
import {
|
|
|
|
|
CSSProperties,
|
|
|
|
|
Dispatch,
|
|
|
|
|
SetStateAction,
|
|
|
|
|
useCallback,
|
|
|
|
|
useMemo,
|
|
|
|
|
useRef,
|
|
|
|
|
useState,
|
|
|
|
|
} from "react"
|
|
|
|
|
import "../style/editor.css"
|
|
|
|
|
import TitleInput from "../components/TitleInput"
|
|
|
|
|
import PlainCourt from "../assets/court/full_court.svg?react"
|
|
|
|
|
import HalfCourt from "../assets/court/half_court.svg?react"
|
|
|
|
|
|
|
|
|
|
import {BallPiece} from "../components/editor/BallPiece"
|
|
|
|
|
import { BallPiece } from "../components/editor/BallPiece"
|
|
|
|
|
|
|
|
|
|
import {Rack} from "../components/Rack"
|
|
|
|
|
import {PlayerPiece} from "../components/editor/PlayerPiece"
|
|
|
|
|
import { Rack } from "../components/Rack"
|
|
|
|
|
import { PlayerPiece } from "../components/editor/PlayerPiece"
|
|
|
|
|
|
|
|
|
|
import {Tactic, TacticComponent, TacticContent} from "../model/tactic/Tactic"
|
|
|
|
|
import {fetchAPI} from "../Fetcher"
|
|
|
|
|
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"
|
|
|
|
|
import {BasketCourt} from "../components/editor/BasketCourt"
|
|
|
|
|
import {overlaps} from "../geo/Box"
|
|
|
|
|
import { BALL_TYPE } from "../model/tactic/CourtObjects"
|
|
|
|
|
import { CourtAction } from "./editor/CourtAction"
|
|
|
|
|
import { ActionPreview, BasketCourt } from "../components/editor/BasketCourt"
|
|
|
|
|
import { overlaps } from "../geo/Box"
|
|
|
|
|
import {
|
|
|
|
|
dropBallOnComponent,
|
|
|
|
|
getComponentCollided,
|
|
|
|
@ -26,19 +37,30 @@ import {
|
|
|
|
|
placeBallAt,
|
|
|
|
|
placeObjectAt,
|
|
|
|
|
placePlayerAt,
|
|
|
|
|
removeBall, updateComponent,
|
|
|
|
|
removeBall,
|
|
|
|
|
updateComponent,
|
|
|
|
|
} from "../editor/TacticContentDomains"
|
|
|
|
|
import {BallState, Player, PlayerInfo, PlayerPhantom, PlayerTeam,} from "../model/tactic/Player"
|
|
|
|
|
import {RackedCourtObject} from "../editor/RackedItems"
|
|
|
|
|
import {
|
|
|
|
|
BallState,
|
|
|
|
|
Player,
|
|
|
|
|
PlayerInfo,
|
|
|
|
|
PlayerPhantom,
|
|
|
|
|
PlayerTeam,
|
|
|
|
|
} from "../model/tactic/Player"
|
|
|
|
|
import { RackedCourtObject } from "../editor/RackedItems"
|
|
|
|
|
import CourtPlayer from "../components/editor/CourtPlayer"
|
|
|
|
|
import {getActionKind, placeArrow, repositionActionsRelatedTo,} from "../editor/ActionsDomains"
|
|
|
|
|
import { getActionKind, placeArrow } from "../editor/ActionsDomains"
|
|
|
|
|
import ArrowAction from "../components/actions/ArrowAction"
|
|
|
|
|
import {middlePos, ratioWithinBase} from "../geo/Pos"
|
|
|
|
|
import {Action, ActionKind} from "../model/tactic/Action"
|
|
|
|
|
import { middlePos, ratioWithinBase } from "../geo/Pos"
|
|
|
|
|
import { Action, ActionKind } from "../model/tactic/Action"
|
|
|
|
|
import BallAction from "../components/actions/BallAction"
|
|
|
|
|
import {getOrigin, removePlayer, truncatePlayerPath,} from "../editor/PlayerDomains"
|
|
|
|
|
import {CourtBall} from "../components/editor/CourtBall"
|
|
|
|
|
import {BASE} from "../Constants"
|
|
|
|
|
import {
|
|
|
|
|
getOrigin,
|
|
|
|
|
removePlayer,
|
|
|
|
|
truncatePlayerPath,
|
|
|
|
|
} from "../editor/PlayerDomains"
|
|
|
|
|
import { CourtBall } from "../components/editor/CourtBall"
|
|
|
|
|
import { BASE } from "../Constants"
|
|
|
|
|
|
|
|
|
|
const ERROR_STYLE: CSSProperties = {
|
|
|
|
|
borderColor: "red",
|
|
|
|
@ -61,7 +83,7 @@ export interface EditorProps {
|
|
|
|
|
courtType: "PLAIN" | "HALF"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function Editor({id, name, courtType, content}: EditorProps) {
|
|
|
|
|
export default function Editor({ id, name, courtType, content }: EditorProps) {
|
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
|
|
|
|
|
|
const storage_content = localStorage.getItem(GUEST_MODE_CONTENT_STORAGE_KEY)
|
|
|
|
@ -87,7 +109,7 @@ export default function Editor({id, name, courtType, content}: EditorProps) {
|
|
|
|
|
)
|
|
|
|
|
return SaveStates.Guest
|
|
|
|
|
}
|
|
|
|
|
return fetchAPI(`tactic/${id}/save`, {content}).then((r) =>
|
|
|
|
|
return fetchAPI(`tactic/${id}/save`, { content }).then((r) =>
|
|
|
|
|
r.ok ? SaveStates.Ok : SaveStates.Err,
|
|
|
|
|
)
|
|
|
|
|
}}
|
|
|
|
@ -96,7 +118,7 @@ export default function Editor({id, name, courtType, content}: EditorProps) {
|
|
|
|
|
localStorage.setItem(GUEST_MODE_TITLE_STORAGE_KEY, name)
|
|
|
|
|
return true //simulate that the name has been changed
|
|
|
|
|
}
|
|
|
|
|
return fetchAPI(`tactic/${id}/edit/name`, {name}).then(
|
|
|
|
|
return fetchAPI(`tactic/${id}/edit/name`, { name }).then(
|
|
|
|
|
(r) => r.ok,
|
|
|
|
|
)
|
|
|
|
|
}}
|
|
|
|
@ -106,11 +128,11 @@ export default function Editor({id, name, courtType, content}: EditorProps) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function EditorView({
|
|
|
|
|
tactic: {id, name, content: initialContent},
|
|
|
|
|
onContentChange,
|
|
|
|
|
onNameChange,
|
|
|
|
|
courtType,
|
|
|
|
|
}: EditorViewProps) {
|
|
|
|
|
tactic: { id, name, content: initialContent },
|
|
|
|
|
onContentChange,
|
|
|
|
|
onNameChange,
|
|
|
|
|
courtType,
|
|
|
|
|
}: EditorViewProps) {
|
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
|
|
|
|
|
|
const [titleStyle, setTitleStyle] = useState<CSSProperties>({})
|
|
|
|
@ -130,27 +152,24 @@ function EditorView({
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const [allies, setAllies] = useState(
|
|
|
|
|
() => getRackPlayers(PlayerTeam.Allies, content.components),
|
|
|
|
|
const [allies, setAllies] = useState(() =>
|
|
|
|
|
getRackPlayers(PlayerTeam.Allies, content.components),
|
|
|
|
|
)
|
|
|
|
|
const [opponents, setOpponents] = useState(
|
|
|
|
|
() => getRackPlayers(PlayerTeam.Opponents, content.components),
|
|
|
|
|
const [opponents, setOpponents] = useState(() =>
|
|
|
|
|
getRackPlayers(PlayerTeam.Opponents, content.components),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const [objects, setObjects] = useState<RackedCourtObject[]>(
|
|
|
|
|
() => isBallOnCourt(content) ? [] : [{key: "ball"}],
|
|
|
|
|
const [objects, setObjects] = useState<RackedCourtObject[]>(() =>
|
|
|
|
|
isBallOnCourt(content) ? [] : [{ key: "ball" }],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const [previewAction, setPreviewAction] = useState<Action | null>(null)
|
|
|
|
|
const [previewAction, setPreviewAction] = useState<ActionPreview | null>(
|
|
|
|
|
null,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const courtRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
|
|
|
|
const setActions = (action: SetStateAction<Action[]>) => {
|
|
|
|
|
setContent((c) => ({
|
|
|
|
|
...c,
|
|
|
|
|
actions: typeof action == "function" ? action(c.actions) : action,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
const actionsReRenderHooks = []
|
|
|
|
|
|
|
|
|
|
const setComponents = (action: SetStateAction<TacticComponent[]>) => {
|
|
|
|
|
setContent((c) => ({
|
|
|
|
@ -170,7 +189,7 @@ function EditorView({
|
|
|
|
|
setter = setAllies
|
|
|
|
|
}
|
|
|
|
|
if (player.ballState == BallState.HOLDS) {
|
|
|
|
|
setObjects([{key: "ball"}])
|
|
|
|
|
setObjects([{ key: "ball" }])
|
|
|
|
|
}
|
|
|
|
|
setter((players) => [
|
|
|
|
|
...players,
|
|
|
|
@ -184,14 +203,14 @@ function EditorView({
|
|
|
|
|
|
|
|
|
|
const doMoveBall = (newBounds: DOMRect) => {
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
const {newContent, removed} = placeBallAt(
|
|
|
|
|
const { newContent, removed } = placeBallAt(
|
|
|
|
|
newBounds,
|
|
|
|
|
courtBounds(),
|
|
|
|
|
content,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if (removed) {
|
|
|
|
|
setObjects((objects) => [...objects, {key: "ball"}])
|
|
|
|
|
setObjects((objects) => [...objects, { key: "ball" }])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newContent
|
|
|
|
@ -209,13 +228,18 @@ function EditorView({
|
|
|
|
|
const origin = getOrigin(component, content.components)
|
|
|
|
|
const path = origin.path!
|
|
|
|
|
// phantoms can only place other arrows if they are the head of the path
|
|
|
|
|
canPlaceArrows = path.items.indexOf(component.id) == path.items.length - 1
|
|
|
|
|
canPlaceArrows =
|
|
|
|
|
path.items.indexOf(component.id) == path.items.length - 1
|
|
|
|
|
if (canPlaceArrows) {
|
|
|
|
|
// and if their only action is to shoot the ball
|
|
|
|
|
|
|
|
|
|
// list the actions the phantoms does
|
|
|
|
|
const phantomArrows = content.actions.filter(c => c.fromId == component.id)
|
|
|
|
|
canPlaceArrows = phantomArrows.length == 0 || phantomArrows.findIndex(c => c.type != ActionKind.SHOOT) == -1
|
|
|
|
|
const phantomActions = component.actions
|
|
|
|
|
canPlaceArrows =
|
|
|
|
|
phantomActions.length == 0 ||
|
|
|
|
|
phantomActions.findIndex(
|
|
|
|
|
(c) => c.type != ActionKind.SHOOT,
|
|
|
|
|
) == -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info = {
|
|
|
|
@ -230,7 +254,11 @@ function EditorView({
|
|
|
|
|
// a player
|
|
|
|
|
info = component
|
|
|
|
|
// can place arrows only if the
|
|
|
|
|
canPlaceArrows = component.path == null || content.actions.findIndex(p => p.fromId == component.id && p.type != ActionKind.SHOOT) == -1
|
|
|
|
|
canPlaceArrows =
|
|
|
|
|
component.path == null ||
|
|
|
|
|
component.actions.findIndex(
|
|
|
|
|
(p) => p.type != ActionKind.SHOOT,
|
|
|
|
|
) == -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
@ -238,11 +266,6 @@ function EditorView({
|
|
|
|
|
key={component.id}
|
|
|
|
|
className={isPhantom ? "phantom" : "player"}
|
|
|
|
|
playerInfo={info}
|
|
|
|
|
onMoves={() =>
|
|
|
|
|
setActions((actions) =>
|
|
|
|
|
repositionActionsRelatedTo(info.id, courtBounds(), actions),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
onPositionValidated={(newPos) => {
|
|
|
|
|
setContent((content) =>
|
|
|
|
|
moveComponent(
|
|
|
|
@ -264,13 +287,16 @@ function EditorView({
|
|
|
|
|
if (!isPhantom) insertRackedPlayer(component)
|
|
|
|
|
}}
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
availableActions={(pieceRef) => [
|
|
|
|
|
availableActions={() => [
|
|
|
|
|
canPlaceArrows && (
|
|
|
|
|
<ArrowAction
|
|
|
|
|
key={1}
|
|
|
|
|
onHeadMoved={(headPos) => {
|
|
|
|
|
const arrowHeadPos = middlePos(headPos)
|
|
|
|
|
const targetIdx = getComponentCollided(headPos, content.components)
|
|
|
|
|
const targetIdx = getComponentCollided(
|
|
|
|
|
headPos,
|
|
|
|
|
content.components,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
setPreviewAction((action) => ({
|
|
|
|
|
...action!,
|
|
|
|
@ -282,20 +308,20 @@ function EditorView({
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
type: getActionKind(targetIdx != -1, info.ballState),
|
|
|
|
|
type: getActionKind(
|
|
|
|
|
targetIdx != -1,
|
|
|
|
|
info.ballState,
|
|
|
|
|
),
|
|
|
|
|
}))
|
|
|
|
|
}}
|
|
|
|
|
onHeadPicked={(headPos) => {
|
|
|
|
|
(document.activeElement as HTMLElement).blur()
|
|
|
|
|
;(document.activeElement as HTMLElement).blur()
|
|
|
|
|
|
|
|
|
|
setPreviewAction({
|
|
|
|
|
origin: component.id,
|
|
|
|
|
type: getActionKind(false, info.ballState),
|
|
|
|
|
fromId: info.id,
|
|
|
|
|
toId: null,
|
|
|
|
|
moveFrom: ratioWithinBase(
|
|
|
|
|
middlePos(
|
|
|
|
|
pieceRef.getBoundingClientRect(),
|
|
|
|
|
),
|
|
|
|
|
target: ratioWithinBase(
|
|
|
|
|
headPos,
|
|
|
|
|
courtBounds(),
|
|
|
|
|
),
|
|
|
|
|
segments: [
|
|
|
|
@ -310,25 +336,41 @@ function EditorView({
|
|
|
|
|
}}
|
|
|
|
|
onHeadDropped={(headRect) => {
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
let {createdAction, newContent} = placeArrow(
|
|
|
|
|
component,
|
|
|
|
|
courtBounds(),
|
|
|
|
|
headRect,
|
|
|
|
|
content,
|
|
|
|
|
)
|
|
|
|
|
let { createdAction, newContent } =
|
|
|
|
|
placeArrow(
|
|
|
|
|
component,
|
|
|
|
|
courtBounds(),
|
|
|
|
|
headRect,
|
|
|
|
|
content,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let originNewBallState = component.ballState
|
|
|
|
|
|
|
|
|
|
if (createdAction.type == ActionKind.SHOOT) {
|
|
|
|
|
const targetIdx = newContent.components.findIndex(c => c.id == createdAction.toId)
|
|
|
|
|
newContent = dropBallOnComponent(targetIdx, newContent)
|
|
|
|
|
if (
|
|
|
|
|
createdAction.type == ActionKind.SHOOT
|
|
|
|
|
) {
|
|
|
|
|
const targetIdx =
|
|
|
|
|
newContent.components.findIndex(
|
|
|
|
|
(c) =>
|
|
|
|
|
c.id ==
|
|
|
|
|
createdAction.target,
|
|
|
|
|
)
|
|
|
|
|
newContent = dropBallOnComponent(
|
|
|
|
|
targetIdx,
|
|
|
|
|
newContent,
|
|
|
|
|
)
|
|
|
|
|
originNewBallState = BallState.SHOOTED
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newContent = updateComponent({
|
|
|
|
|
...(newContent.components.find(c => c.id == component.id)! as Player | PlayerPhantom),
|
|
|
|
|
ballState: originNewBallState
|
|
|
|
|
}, newContent)
|
|
|
|
|
newContent = updateComponent(
|
|
|
|
|
{
|
|
|
|
|
...(newContent.components.find(
|
|
|
|
|
(c) => c.id == component.id,
|
|
|
|
|
)! as Player | PlayerPhantom),
|
|
|
|
|
ballState: originNewBallState,
|
|
|
|
|
},
|
|
|
|
|
newContent,
|
|
|
|
|
)
|
|
|
|
|
return newContent
|
|
|
|
|
})
|
|
|
|
|
setPreviewAction(null)
|
|
|
|
@ -336,16 +378,54 @@ function EditorView({
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
info.ballState != BallState.NONE && (
|
|
|
|
|
<BallAction
|
|
|
|
|
key={2}
|
|
|
|
|
onDrop={doMoveBall}
|
|
|
|
|
/>
|
|
|
|
|
<BallAction key={2} onDrop={doMoveBall} />
|
|
|
|
|
),
|
|
|
|
|
]}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const doDeleteAction = (
|
|
|
|
|
action: Action,
|
|
|
|
|
idx: number,
|
|
|
|
|
component: TacticComponent,
|
|
|
|
|
) => {
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
content = updateComponent(
|
|
|
|
|
{
|
|
|
|
|
...component,
|
|
|
|
|
actions: component.actions.toSpliced(idx, 1),
|
|
|
|
|
},
|
|
|
|
|
content,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if (action.target == null) return content
|
|
|
|
|
|
|
|
|
|
const target = content.components.find(
|
|
|
|
|
(c) => action.target == c.id,
|
|
|
|
|
)!
|
|
|
|
|
|
|
|
|
|
if (target.type == "phantom") {
|
|
|
|
|
let path = null
|
|
|
|
|
if (component.type == "player") {
|
|
|
|
|
path = component.path
|
|
|
|
|
} else if (component.type == "phantom") {
|
|
|
|
|
path = getOrigin(component, content.components).path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
path == null ||
|
|
|
|
|
path.items.find((c) => c == target.id) == null
|
|
|
|
|
) {
|
|
|
|
|
return content
|
|
|
|
|
}
|
|
|
|
|
content = removePlayer(target, content)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return content
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div id="main-div">
|
|
|
|
|
<div id="topbar-div">
|
|
|
|
@ -353,7 +433,7 @@ function EditorView({
|
|
|
|
|
Home
|
|
|
|
|
</button>
|
|
|
|
|
<div id="topbar-left">
|
|
|
|
|
<SavingState state={saveState}/>
|
|
|
|
|
<SavingState state={saveState} />
|
|
|
|
|
</div>
|
|
|
|
|
<div id="title-input-div">
|
|
|
|
|
<TitleInput
|
|
|
|
@ -366,7 +446,7 @@ function EditorView({
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="topbar-right"/>
|
|
|
|
|
<div id="topbar-right" />
|
|
|
|
|
</div>
|
|
|
|
|
<div id="edit-div">
|
|
|
|
|
<div id="racks">
|
|
|
|
@ -387,7 +467,7 @@ function EditorView({
|
|
|
|
|
),
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
render={({team, key}) => (
|
|
|
|
|
render={({ team, key }) => (
|
|
|
|
|
<PlayerPiece
|
|
|
|
|
team={team}
|
|
|
|
|
text={key}
|
|
|
|
@ -434,7 +514,7 @@ function EditorView({
|
|
|
|
|
),
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
render={({team, key}) => (
|
|
|
|
|
render={({ team, key }) => (
|
|
|
|
|
<PlayerPiece
|
|
|
|
|
team={team}
|
|
|
|
|
text={key}
|
|
|
|
@ -448,8 +528,7 @@ function EditorView({
|
|
|
|
|
<div id="court-div-bounds">
|
|
|
|
|
<BasketCourt
|
|
|
|
|
components={content.components}
|
|
|
|
|
actions={content.actions}
|
|
|
|
|
courtImage={<Court courtType={courtType}/>}
|
|
|
|
|
courtImage={<Court courtType={courtType} />}
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
previewAction={previewAction}
|
|
|
|
|
renderComponent={(component) => {
|
|
|
|
@ -465,20 +544,14 @@ function EditorView({
|
|
|
|
|
key="ball"
|
|
|
|
|
ball={component}
|
|
|
|
|
onPosValidated={doMoveBall}
|
|
|
|
|
onMoves={() =>
|
|
|
|
|
setActions((actions) =>
|
|
|
|
|
repositionActionsRelatedTo(
|
|
|
|
|
component.id,
|
|
|
|
|
courtBounds(),
|
|
|
|
|
actions,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
onRemove={() => {
|
|
|
|
|
setContent((content) =>
|
|
|
|
|
removeBall(content),
|
|
|
|
|
)
|
|
|
|
|
setObjects(objects => [...objects, {key: "ball"}])
|
|
|
|
|
setObjects((objects) => [
|
|
|
|
|
...objects,
|
|
|
|
|
{ key: "ball" },
|
|
|
|
|
])
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
@ -487,60 +560,35 @@ function EditorView({
|
|
|
|
|
"unknown tactic component " + component,
|
|
|
|
|
)
|
|
|
|
|
}}
|
|
|
|
|
renderAction={(action, i) => (
|
|
|
|
|
<CourtAction
|
|
|
|
|
key={i}
|
|
|
|
|
action={action}
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
onActionDeleted={() => {
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
content = {
|
|
|
|
|
...content,
|
|
|
|
|
actions:
|
|
|
|
|
content.actions.toSpliced(
|
|
|
|
|
i,
|
|
|
|
|
1,
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (action.toId == null)
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
const target =
|
|
|
|
|
content.components.find(
|
|
|
|
|
(c) => action.toId == c.id,
|
|
|
|
|
)!
|
|
|
|
|
|
|
|
|
|
if (target.type == "phantom") {
|
|
|
|
|
const origin = getOrigin(
|
|
|
|
|
target,
|
|
|
|
|
content.components,
|
|
|
|
|
)
|
|
|
|
|
if (origin.id != action.fromId) {
|
|
|
|
|
return content
|
|
|
|
|
}
|
|
|
|
|
content = truncatePlayerPath(
|
|
|
|
|
origin,
|
|
|
|
|
target,
|
|
|
|
|
renderActions={(component) =>
|
|
|
|
|
component.actions.map((action, i) => (
|
|
|
|
|
<CourtAction
|
|
|
|
|
key={"action-" + component.id + "-" + i}
|
|
|
|
|
action={action}
|
|
|
|
|
origin={component.id}
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
onActionDeleted={() => {
|
|
|
|
|
doDeleteAction(action, i, component)
|
|
|
|
|
}}
|
|
|
|
|
onActionChanges={(a) =>
|
|
|
|
|
setContent((content) =>
|
|
|
|
|
updateComponent(
|
|
|
|
|
{
|
|
|
|
|
...component,
|
|
|
|
|
actions:
|
|
|
|
|
component.actions.toSpliced(
|
|
|
|
|
i,
|
|
|
|
|
1,
|
|
|
|
|
a,
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
content,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return content
|
|
|
|
|
})
|
|
|
|
|
}}
|
|
|
|
|
onActionChanges={(a) =>
|
|
|
|
|
setContent((content) => ({
|
|
|
|
|
...content,
|
|
|
|
|
actions: content.actions.toSpliced(
|
|
|
|
|
i,
|
|
|
|
|
1,
|
|
|
|
|
a,
|
|
|
|
|
),
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
@ -552,25 +600,27 @@ function EditorView({
|
|
|
|
|
function isBallOnCourt(content: TacticContent) {
|
|
|
|
|
return (
|
|
|
|
|
content.components.findIndex(
|
|
|
|
|
(c) => (c.type == "player" && c.ballState == BallState.HOLDS) || c.type == BALL_TYPE,
|
|
|
|
|
(c) =>
|
|
|
|
|
(c.type == "player" && c.ballState == BallState.HOLDS) ||
|
|
|
|
|
c.type == BALL_TYPE,
|
|
|
|
|
) != -1
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderCourtObject(courtObject: RackedCourtObject) {
|
|
|
|
|
if (courtObject.key == "ball") {
|
|
|
|
|
return <BallPiece/>
|
|
|
|
|
return <BallPiece />
|
|
|
|
|
}
|
|
|
|
|
throw new Error("unknown racked court object " + courtObject.key)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Court({courtType}: { courtType: string }) {
|
|
|
|
|
function Court({ courtType }: { courtType: string }) {
|
|
|
|
|
return (
|
|
|
|
|
<div id="court-image-div">
|
|
|
|
|
{courtType == "PLAIN" ? (
|
|
|
|
|
<PlainCourt id="court-image"/>
|
|
|
|
|
<PlainCourt id="court-image" />
|
|
|
|
|
) : (
|
|
|
|
|
<HalfCourt id="court-image"/>
|
|
|
|
|
<HalfCourt id="court-image" />
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|