|
|
|
@ -14,19 +14,24 @@ 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 {
|
|
|
|
|
CourtType, StepContent, StepInfoNode,
|
|
|
|
|
Tactic,
|
|
|
|
|
CourtType,
|
|
|
|
|
StepContent,
|
|
|
|
|
StepInfoNode,
|
|
|
|
|
TacticComponent,
|
|
|
|
|
TacticInfo,
|
|
|
|
|
} from "../model/tactic/Tactic"
|
|
|
|
|
import { fetchAPI, fetchAPIGet } 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 "../components/editor/CourtAction"
|
|
|
|
@ -45,13 +50,25 @@ import {
|
|
|
|
|
updateComponent,
|
|
|
|
|
} from "../editor/TacticContentDomains"
|
|
|
|
|
|
|
|
|
|
import {BallState, Player, PlayerInfo, PlayerLike, PlayerTeam,} from "../model/tactic/Player"
|
|
|
|
|
import {RackedCourtObject, RackedPlayer} from "../editor/RackedItems"
|
|
|
|
|
import {
|
|
|
|
|
BallState,
|
|
|
|
|
Player,
|
|
|
|
|
PlayerInfo,
|
|
|
|
|
PlayerLike,
|
|
|
|
|
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 { middlePos, Pos, ratioWithinBase } from "../geo/Pos"
|
|
|
|
|
import { Action, ActionKind } from "../model/tactic/Action"
|
|
|
|
|
import BallAction from "../components/actions/BallAction"
|
|
|
|
|
import {
|
|
|
|
|
changePlayerBallState,
|
|
|
|
@ -63,6 +80,7 @@ import { CourtBall } from "../components/editor/CourtBall"
|
|
|
|
|
import { useNavigate, useParams } from "react-router-dom"
|
|
|
|
|
import { DEFAULT_TACTIC_NAME } from "./NewTacticPage.tsx"
|
|
|
|
|
import StepsTree from "../components/editor/StepsTree"
|
|
|
|
|
import { addStepNode, removeStepNode } from "../editor/StepsDomain"
|
|
|
|
|
|
|
|
|
|
const ERROR_STYLE: CSSProperties = {
|
|
|
|
|
borderColor: "red",
|
|
|
|
@ -72,15 +90,16 @@ const GUEST_MODE_CONTENT_STORAGE_KEY = "guest_mode_content"
|
|
|
|
|
const GUEST_MODE_TITLE_STORAGE_KEY = "guest_mode_title"
|
|
|
|
|
|
|
|
|
|
export interface EditorViewProps {
|
|
|
|
|
tactic: Tactic
|
|
|
|
|
tactic: TacticInfo
|
|
|
|
|
onContentChange: (tactic: StepContent) => Promise<SaveState>
|
|
|
|
|
onNameChange: (name: string) => Promise<boolean>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface TacticDto {
|
|
|
|
|
id: number
|
|
|
|
|
name: string
|
|
|
|
|
courtType: CourtType
|
|
|
|
|
content: string
|
|
|
|
|
content: { components: TacticComponent[] }
|
|
|
|
|
root: StepInfoNode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -94,9 +113,9 @@ export default function EditorPage({ guestMode }: EditorPageProps) {
|
|
|
|
|
return {
|
|
|
|
|
id: -1,
|
|
|
|
|
courtType: "PLAIN",
|
|
|
|
|
content: '{"components": []}',
|
|
|
|
|
content: { components: [] },
|
|
|
|
|
name: DEFAULT_TACTIC_NAME,
|
|
|
|
|
root: {id: 1, children: []}
|
|
|
|
|
root: { id: 1, children: [] },
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
@ -117,13 +136,17 @@ export default function EditorPage({ guestMode }: EditorPageProps) {
|
|
|
|
|
const treeResponse = await treeResponsePromise
|
|
|
|
|
const contentResponse = await contentResponsePromise
|
|
|
|
|
|
|
|
|
|
if (infoResponse.status == 401 || contentResponse.status == 401) {
|
|
|
|
|
if (
|
|
|
|
|
infoResponse.status == 401 ||
|
|
|
|
|
treeResponse.status == 401 ||
|
|
|
|
|
contentResponse.status == 401
|
|
|
|
|
) {
|
|
|
|
|
navigation("/login")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { name, courtType } = await infoResponse.json()
|
|
|
|
|
const content = await contentResponse.text()
|
|
|
|
|
const content = await contentResponse.json()
|
|
|
|
|
const { root } = await treeResponse.json()
|
|
|
|
|
|
|
|
|
|
setTactic({ id, name, courtType, content, root })
|
|
|
|
@ -136,10 +159,11 @@ export default function EditorPage({ guestMode }: EditorPageProps) {
|
|
|
|
|
return (
|
|
|
|
|
<Editor
|
|
|
|
|
id={id}
|
|
|
|
|
rootStepNode={tactic.root}
|
|
|
|
|
initialStepsNode={tactic.root}
|
|
|
|
|
courtType={tactic.courtType}
|
|
|
|
|
content={tactic.content}
|
|
|
|
|
name={tactic.name}
|
|
|
|
|
initialStepContent={tactic.content}
|
|
|
|
|
initialName={tactic.name}
|
|
|
|
|
initialStepId={1}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
@ -153,23 +177,63 @@ function EditorLoadingScreen() {
|
|
|
|
|
|
|
|
|
|
export interface EditorProps {
|
|
|
|
|
id: number
|
|
|
|
|
name: string
|
|
|
|
|
content: string
|
|
|
|
|
courtType: CourtType,
|
|
|
|
|
rootStepNode: StepInfoNode
|
|
|
|
|
initialName: string
|
|
|
|
|
courtType: "PLAIN" | "HALF"
|
|
|
|
|
initialStepContent: StepContent
|
|
|
|
|
initialStepId: number
|
|
|
|
|
initialStepsNode: StepInfoNode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Editor({ id, name, courtType, content, rootStepNode }: EditorProps) {
|
|
|
|
|
function Editor({
|
|
|
|
|
id,
|
|
|
|
|
initialName,
|
|
|
|
|
courtType,
|
|
|
|
|
initialStepContent,
|
|
|
|
|
initialStepId,
|
|
|
|
|
initialStepsNode,
|
|
|
|
|
}: EditorProps) {
|
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
|
|
|
|
|
const storageContent = localStorage.getItem(GUEST_MODE_CONTENT_STORAGE_KEY)
|
|
|
|
|
const stepContent =
|
|
|
|
|
isInGuestMode && storageContent != null ? storageContent : content
|
|
|
|
|
const stepInitialContent = {
|
|
|
|
|
...(isInGuestMode && storageContent != null
|
|
|
|
|
? JSON.parse(storageContent)
|
|
|
|
|
: initialStepContent),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const storageName = localStorage.getItem(GUEST_MODE_TITLE_STORAGE_KEY)
|
|
|
|
|
const editorName = isInGuestMode && storageName != null ? storageName : name
|
|
|
|
|
const storage_name = localStorage.getItem(GUEST_MODE_TITLE_STORAGE_KEY)
|
|
|
|
|
const editorName =
|
|
|
|
|
isInGuestMode && storage_name != null ? storage_name : initialName
|
|
|
|
|
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
const [stepId, setStepId] = useState(initialStepId)
|
|
|
|
|
const [stepContent, setStepContent, saveState] = useContentState(
|
|
|
|
|
stepInitialContent,
|
|
|
|
|
isInGuestMode ? SaveStates.Guest : SaveStates.Ok,
|
|
|
|
|
useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
debounceAsync(async (content: StepContent) => {
|
|
|
|
|
if (isInGuestMode) {
|
|
|
|
|
localStorage.setItem(
|
|
|
|
|
GUEST_MODE_CONTENT_STORAGE_KEY,
|
|
|
|
|
JSON.stringify(content),
|
|
|
|
|
)
|
|
|
|
|
return SaveStates.Guest
|
|
|
|
|
}
|
|
|
|
|
const response = await fetchAPI(
|
|
|
|
|
`tactics/${id}/steps/${stepId}`,
|
|
|
|
|
{
|
|
|
|
|
content: {
|
|
|
|
|
components: content.components,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"PUT",
|
|
|
|
|
)
|
|
|
|
|
return response.ok ? SaveStates.Ok : SaveStates.Err
|
|
|
|
|
}, 250),
|
|
|
|
|
[id, isInGuestMode, stepId],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<EditorView
|
|
|
|
@ -177,12 +241,13 @@ function Editor({ id, name, courtType, content, rootStepNode }: EditorProps) {
|
|
|
|
|
name: editorName,
|
|
|
|
|
id,
|
|
|
|
|
courtType,
|
|
|
|
|
currentStepContent: {
|
|
|
|
|
stepId: 1,
|
|
|
|
|
...JSON.parse(stepContent)
|
|
|
|
|
},
|
|
|
|
|
rootStepNode,
|
|
|
|
|
rootStepNode: initialStepsNode,
|
|
|
|
|
}}
|
|
|
|
|
currentStepContent={stepContent}
|
|
|
|
|
currentStepId={stepId}
|
|
|
|
|
setCurrentStepContent={(content) => setStepContent(content, true)}
|
|
|
|
|
courtType={courtType}
|
|
|
|
|
saveState={saveState}
|
|
|
|
|
onContentChange={async (content: StepContent) => {
|
|
|
|
|
if (isInGuestMode) {
|
|
|
|
|
localStorage.setItem(
|
|
|
|
@ -195,7 +260,6 @@ function Editor({ id, name, courtType, content, rootStepNode }: EditorProps) {
|
|
|
|
|
`tactics/${id}/steps/1`,
|
|
|
|
|
{ content },
|
|
|
|
|
"PUT",
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
if (response.status == 401) {
|
|
|
|
|
navigate("/login")
|
|
|
|
@ -212,47 +276,70 @@ function Editor({ id, name, courtType, content, rootStepNode }: EditorProps) {
|
|
|
|
|
`tactics/${id}/name`,
|
|
|
|
|
{ name },
|
|
|
|
|
"PUT",
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
if (response.status == 401) {
|
|
|
|
|
navigate("/login")
|
|
|
|
|
}
|
|
|
|
|
return response.ok
|
|
|
|
|
}}
|
|
|
|
|
onStepSelected={() => {
|
|
|
|
|
selectStep={async (step) => {
|
|
|
|
|
const response = await fetchAPIGet(
|
|
|
|
|
`tactics/${id}/steps/${step}`,
|
|
|
|
|
)
|
|
|
|
|
if (!response.ok) return null
|
|
|
|
|
setStepContent(
|
|
|
|
|
{ stepId: step, ...(await response.json()) },
|
|
|
|
|
false,
|
|
|
|
|
)
|
|
|
|
|
}}
|
|
|
|
|
onAddStep={async (parent) => {
|
|
|
|
|
const response = await fetchAPI(`tactics/${id}/steps`, {
|
|
|
|
|
parentId: parent.id,
|
|
|
|
|
})
|
|
|
|
|
if (!response.ok) return null
|
|
|
|
|
const { stepId } = await response.json()
|
|
|
|
|
return { id: stepId, children: [] }
|
|
|
|
|
}}
|
|
|
|
|
onRemoveStep={async (step) => {
|
|
|
|
|
const response = await fetchAPI(
|
|
|
|
|
`tactics/${id}/steps/${step.id}`,
|
|
|
|
|
{},
|
|
|
|
|
"DELETE",
|
|
|
|
|
)
|
|
|
|
|
return response.ok
|
|
|
|
|
}}
|
|
|
|
|
stepsContentsRoot={rootStepNode}
|
|
|
|
|
courtType={courtType}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface EditorViewProps {
|
|
|
|
|
tactic: Tactic
|
|
|
|
|
onContentChange: (tactic: StepContent) => Promise<SaveState>
|
|
|
|
|
onStepSelected: (stepId: number) => void,
|
|
|
|
|
tactic: TacticInfo
|
|
|
|
|
currentStepContent: StepContent
|
|
|
|
|
currentStepId: number
|
|
|
|
|
saveState: SaveState
|
|
|
|
|
setCurrentStepContent: Dispatch<SetStateAction<StepContent>>
|
|
|
|
|
|
|
|
|
|
selectStep: (stepId: number) => void
|
|
|
|
|
onNameChange: (name: string) => Promise<boolean>
|
|
|
|
|
stepsContentsRoot: StepInfoNode
|
|
|
|
|
onRemoveStep: (step: StepInfoNode) => Promise<boolean>
|
|
|
|
|
onAddStep: (parent: StepInfoNode) => Promise<StepInfoNode | null>
|
|
|
|
|
courtType: "PLAIN" | "HALF"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function EditorView({
|
|
|
|
|
|
|
|
|
|
tactic: {id, name, currentStepContent: initialContent},
|
|
|
|
|
onContentChange,
|
|
|
|
|
onNameChange,
|
|
|
|
|
onStepSelected,
|
|
|
|
|
stepsContentsRoot,
|
|
|
|
|
courtType,
|
|
|
|
|
}: EditorViewProps) {
|
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
|
|
|
|
|
|
tactic: { name, rootStepNode: initialStepsNode },
|
|
|
|
|
setCurrentStepContent: setContent,
|
|
|
|
|
currentStepContent: content,
|
|
|
|
|
saveState,
|
|
|
|
|
onNameChange,
|
|
|
|
|
selectStep,
|
|
|
|
|
onRemoveStep,
|
|
|
|
|
onAddStep,
|
|
|
|
|
courtType,
|
|
|
|
|
}: EditorViewProps) {
|
|
|
|
|
const [titleStyle, setTitleStyle] = useState<CSSProperties>({})
|
|
|
|
|
const [content, setContent, saveState] = useContentState(
|
|
|
|
|
initialContent,
|
|
|
|
|
isInGuestMode ? SaveStates.Guest : SaveStates.Ok,
|
|
|
|
|
useMemo(() => debounceAsync(onContentChange), [onContentChange]),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const [rootStepsNode, setRootStepsNode] = useState(initialStepsNode)
|
|
|
|
|
|
|
|
|
|
const [allies, setAllies] = useState(() =>
|
|
|
|
|
getRackPlayers(PlayerTeam.Allies, content.components),
|
|
|
|
@ -262,7 +349,7 @@ function EditorView({
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const [objects, setObjects] = useState<RackedCourtObject[]>(() =>
|
|
|
|
|
isBallOnCourt(content) ? [] : [{key: "ball"}],
|
|
|
|
|
isBallOnCourt(content) ? [] : [{ key: "ball" }],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const [previewAction, setPreviewAction] = useState<ActionPreview | null>(
|
|
|
|
@ -287,7 +374,7 @@ function EditorView({
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setObjects(isBallOnCourt(content) ? [] : [{key: "ball"}])
|
|
|
|
|
setObjects(isBallOnCourt(content) ? [] : [{ key: "ball" }])
|
|
|
|
|
}, [setObjects, content])
|
|
|
|
|
|
|
|
|
|
const insertRackedPlayer = (player: Player) => {
|
|
|
|
@ -300,7 +387,7 @@ function EditorView({
|
|
|
|
|
setter = setAllies
|
|
|
|
|
}
|
|
|
|
|
if (player.ballState == BallState.HOLDS_BY_PASS) {
|
|
|
|
|
setObjects([{key: "ball"}])
|
|
|
|
|
setObjects([{ key: "ball" }])
|
|
|
|
|
}
|
|
|
|
|
setter((players) => [
|
|
|
|
|
...players,
|
|
|
|
@ -499,7 +586,7 @@ function EditorView({
|
|
|
|
|
setContent((content) => removeBall(content))
|
|
|
|
|
setObjects((objects) => [
|
|
|
|
|
...objects,
|
|
|
|
|
{key: "ball"},
|
|
|
|
|
{ key: "ball" },
|
|
|
|
|
])
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
@ -536,7 +623,7 @@ function EditorView({
|
|
|
|
|
<div id="main-div">
|
|
|
|
|
<div id="topbar-div">
|
|
|
|
|
<div id="topbar-left">
|
|
|
|
|
<SavingState state={saveState}/>
|
|
|
|
|
<SavingState state={saveState} />
|
|
|
|
|
</div>
|
|
|
|
|
<div id="title-input-div">
|
|
|
|
|
<TitleInput
|
|
|
|
@ -608,7 +695,7 @@ function EditorView({
|
|
|
|
|
<div id="court-div-bounds">
|
|
|
|
|
<BasketCourt
|
|
|
|
|
components={content.components}
|
|
|
|
|
courtImage={<Court courtType={courtType}/>}
|
|
|
|
|
courtImage={<Court courtType={courtType} />}
|
|
|
|
|
courtRef={courtRef}
|
|
|
|
|
previewAction={previewAction}
|
|
|
|
|
renderComponent={renderComponent}
|
|
|
|
@ -617,7 +704,39 @@ function EditorView({
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<EditorStepsTree isVisible={isStepsTreeVisible} root={stepsContentsRoot}/>
|
|
|
|
|
<EditorStepsTree
|
|
|
|
|
isVisible={isStepsTreeVisible}
|
|
|
|
|
root={rootStepsNode}
|
|
|
|
|
onAddChildren={useCallback(
|
|
|
|
|
async (parent) => {
|
|
|
|
|
const addedNode = await onAddStep(parent)
|
|
|
|
|
if (addedNode == null) {
|
|
|
|
|
console.error(
|
|
|
|
|
"could not add step : onAddStep returned null node",
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
setRootStepsNode((root) =>
|
|
|
|
|
addStepNode(root, parent, addedNode),
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
[onAddStep],
|
|
|
|
|
)}
|
|
|
|
|
onRemoveNode={useCallback(
|
|
|
|
|
async (removed) => {
|
|
|
|
|
const isOk = await onRemoveStep(removed)
|
|
|
|
|
if (isOk)
|
|
|
|
|
setRootStepsNode(
|
|
|
|
|
(root) => removeStepNode(root, removed)!,
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
[onRemoveStep],
|
|
|
|
|
)}
|
|
|
|
|
onStepSelected={useCallback(
|
|
|
|
|
(node) => selectStep(node.id),
|
|
|
|
|
[selectStep],
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
@ -626,60 +745,30 @@ function EditorView({
|
|
|
|
|
interface EditorStepsTreeProps {
|
|
|
|
|
isVisible: boolean
|
|
|
|
|
root: StepInfoNode
|
|
|
|
|
onAddChildren: (parent: StepInfoNode) => void
|
|
|
|
|
onRemoveNode: (node: StepInfoNode) => void
|
|
|
|
|
onStepSelected: (node: StepInfoNode) => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function EditorStepsTree({isVisible, root}: EditorStepsTreeProps) {
|
|
|
|
|
const fakeRoot: StepInfoNode = {
|
|
|
|
|
id: 0,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
children: []
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
|
|
|
|
children: [{
|
|
|
|
|
id: 4,
|
|
|
|
|
children: []
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 5,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
id: 6,
|
|
|
|
|
children: []
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 7,
|
|
|
|
|
children: []
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 8,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
id: 9,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
id: 10,
|
|
|
|
|
children: []
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
function EditorStepsTree({
|
|
|
|
|
isVisible,
|
|
|
|
|
root,
|
|
|
|
|
onAddChildren,
|
|
|
|
|
onRemoveNode,
|
|
|
|
|
onStepSelected,
|
|
|
|
|
}: EditorStepsTreeProps) {
|
|
|
|
|
return (
|
|
|
|
|
<div id="steps-div" style={{transform: isVisible ? "translateX(0)" : "translateX(100%)"}}>
|
|
|
|
|
<StepsTree root={fakeRoot}/>
|
|
|
|
|
<div
|
|
|
|
|
id="steps-div"
|
|
|
|
|
style={{
|
|
|
|
|
transform: isVisible ? "translateX(0)" : "translateX(100%)",
|
|
|
|
|
}}>
|
|
|
|
|
<StepsTree
|
|
|
|
|
root={root}
|
|
|
|
|
onStepSelected={onStepSelected}
|
|
|
|
|
onAddChildren={onAddChildren}
|
|
|
|
|
onRemoveNode={onRemoveNode}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
@ -695,12 +784,12 @@ interface PlayerRackProps {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function PlayerRack({
|
|
|
|
|
id,
|
|
|
|
|
objects,
|
|
|
|
|
setObjects,
|
|
|
|
|
courtRef,
|
|
|
|
|
setComponents,
|
|
|
|
|
}: PlayerRackProps) {
|
|
|
|
|
id,
|
|
|
|
|
objects,
|
|
|
|
|
setObjects,
|
|
|
|
|
courtRef,
|
|
|
|
|
setComponents,
|
|
|
|
|
}: PlayerRackProps) {
|
|
|
|
|
const courtBounds = useCallback(
|
|
|
|
|
() => courtRef.current!.getBoundingClientRect(),
|
|
|
|
|
[courtRef],
|
|
|
|
@ -728,7 +817,7 @@ function PlayerRack({
|
|
|
|
|
[courtBounds, setComponents],
|
|
|
|
|
)}
|
|
|
|
|
render={useCallback(
|
|
|
|
|
({team, key}: { team: PlayerTeam; key: string }) => (
|
|
|
|
|
({ team, key }: { team: PlayerTeam; key: string }) => (
|
|
|
|
|
<PlayerPiece
|
|
|
|
|
team={team}
|
|
|
|
|
text={key}
|
|
|
|
@ -754,15 +843,15 @@ interface CourtPlayerArrowActionProps {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CourtPlayerArrowAction({
|
|
|
|
|
playerInfo,
|
|
|
|
|
player,
|
|
|
|
|
isInvalid,
|
|
|
|
|
|
|
|
|
|
content,
|
|
|
|
|
setContent,
|
|
|
|
|
setPreviewAction,
|
|
|
|
|
courtRef,
|
|
|
|
|
}: CourtPlayerArrowActionProps) {
|
|
|
|
|
playerInfo,
|
|
|
|
|
player,
|
|
|
|
|
isInvalid,
|
|
|
|
|
|
|
|
|
|
content,
|
|
|
|
|
setContent,
|
|
|
|
|
setPreviewAction,
|
|
|
|
|
courtRef,
|
|
|
|
|
}: CourtPlayerArrowActionProps) {
|
|
|
|
|
const courtBounds = useCallback(
|
|
|
|
|
() => courtRef.current!.getBoundingClientRect(),
|
|
|
|
|
[courtRef],
|
|
|
|
@ -817,7 +906,7 @@ function CourtPlayerArrowAction({
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
let {createdAction, newContent} = createAction(
|
|
|
|
|
let { createdAction, newContent } = createAction(
|
|
|
|
|
player,
|
|
|
|
|
courtBounds(),
|
|
|
|
|
headRect,
|
|
|
|
@ -870,18 +959,18 @@ function isBallOnCourt(content: StepContent) {
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
)
|
|
|
|
@ -904,19 +993,23 @@ function useContentState<S>(
|
|
|
|
|
initialContent: S,
|
|
|
|
|
initialSaveState: SaveState,
|
|
|
|
|
saveStateCallback: (s: S) => Promise<SaveState>,
|
|
|
|
|
): [S, Dispatch<SetStateAction<S>>, SaveState] {
|
|
|
|
|
): [
|
|
|
|
|
S,
|
|
|
|
|
(newState: SetStateAction<S>, callSaveCallback: boolean) => void,
|
|
|
|
|
SaveState,
|
|
|
|
|
] {
|
|
|
|
|
const [content, setContent] = useState(initialContent)
|
|
|
|
|
const [savingState, setSavingState] = useState(initialSaveState)
|
|
|
|
|
|
|
|
|
|
const setContentSynced = useCallback(
|
|
|
|
|
(newState: SetStateAction<S>) => {
|
|
|
|
|
(newState: SetStateAction<S>, callSaveCallback: boolean) => {
|
|
|
|
|
setContent((content) => {
|
|
|
|
|
const state =
|
|
|
|
|
typeof newState === "function"
|
|
|
|
|
? (newState as (state: S) => S)(content)
|
|
|
|
|
: newState
|
|
|
|
|
|
|
|
|
|
if (state !== content) {
|
|
|
|
|
if (state !== content && callSaveCallback) {
|
|
|
|
|
setSavingState(SaveStates.Saving)
|
|
|
|
|
saveStateCallback(state)
|
|
|
|
|
.then(setSavingState)
|
|
|
|
|