|
|
@ -20,22 +20,19 @@ import { Rack } from "../components/Rack"
|
|
|
|
import {PlayerPiece} from "../components/editor/PlayerPiece"
|
|
|
|
import {PlayerPiece} from "../components/editor/PlayerPiece"
|
|
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
CourtType,
|
|
|
|
CourtType, StepContent, StepInfoNode,
|
|
|
|
Tactic,
|
|
|
|
Tactic,
|
|
|
|
TacticComponent,
|
|
|
|
TacticComponent,
|
|
|
|
TacticContent,
|
|
|
|
|
|
|
|
} from "../model/tactic/Tactic"
|
|
|
|
} from "../model/tactic/Tactic"
|
|
|
|
import { fetchAPI, fetchAPIGet } from "../Fetcher"
|
|
|
|
import { fetchAPI, fetchAPIGet } 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 "../components/editor/CourtAction"
|
|
|
|
import { CourtAction } from "../components/editor/CourtAction"
|
|
|
|
import { ActionPreview, BasketCourt } from "../components/editor/BasketCourt"
|
|
|
|
import { ActionPreview, BasketCourt } from "../components/editor/BasketCourt"
|
|
|
|
import { overlaps } from "../geo/Box"
|
|
|
|
import { overlaps } from "../geo/Box"
|
|
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
dropBallOnComponent,
|
|
|
|
dropBallOnComponent,
|
|
|
|
getComponentCollided,
|
|
|
|
getComponentCollided,
|
|
|
@ -47,21 +44,11 @@ import {
|
|
|
|
removeBall,
|
|
|
|
removeBall,
|
|
|
|
updateComponent,
|
|
|
|
updateComponent,
|
|
|
|
} from "../editor/TacticContentDomains"
|
|
|
|
} from "../editor/TacticContentDomains"
|
|
|
|
import {
|
|
|
|
|
|
|
|
BallState,
|
|
|
|
import {BallState, Player, PlayerInfo, PlayerLike, PlayerTeam,} from "../model/tactic/Player"
|
|
|
|
Player,
|
|
|
|
|
|
|
|
PlayerInfo,
|
|
|
|
|
|
|
|
PlayerLike,
|
|
|
|
|
|
|
|
PlayerTeam,
|
|
|
|
|
|
|
|
} from "../model/tactic/Player"
|
|
|
|
|
|
|
|
import {RackedCourtObject, RackedPlayer} from "../editor/RackedItems"
|
|
|
|
import {RackedCourtObject, RackedPlayer} from "../editor/RackedItems"
|
|
|
|
import CourtPlayer from "../components/editor/CourtPlayer"
|
|
|
|
import CourtPlayer from "../components/editor/CourtPlayer"
|
|
|
|
import {
|
|
|
|
import {createAction, getActionKind, isActionValid, removeAction,} from "../editor/ActionsDomains"
|
|
|
|
createAction,
|
|
|
|
|
|
|
|
getActionKind,
|
|
|
|
|
|
|
|
isActionValid,
|
|
|
|
|
|
|
|
removeAction,
|
|
|
|
|
|
|
|
} from "../editor/ActionsDomains"
|
|
|
|
|
|
|
|
import ArrowAction from "../components/actions/ArrowAction"
|
|
|
|
import ArrowAction from "../components/actions/ArrowAction"
|
|
|
|
import {middlePos, Pos, 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"
|
|
|
@ -75,6 +62,7 @@ import {
|
|
|
|
import { CourtBall } from "../components/editor/CourtBall"
|
|
|
|
import { CourtBall } from "../components/editor/CourtBall"
|
|
|
|
import { useNavigate, useParams } from "react-router-dom"
|
|
|
|
import { useNavigate, useParams } from "react-router-dom"
|
|
|
|
import { DEFAULT_TACTIC_NAME } from "./NewTacticPage.tsx"
|
|
|
|
import { DEFAULT_TACTIC_NAME } from "./NewTacticPage.tsx"
|
|
|
|
|
|
|
|
import StepsTree from "../components/editor/StepsTree"
|
|
|
|
|
|
|
|
|
|
|
|
const ERROR_STYLE: CSSProperties = {
|
|
|
|
const ERROR_STYLE: CSSProperties = {
|
|
|
|
borderColor: "red",
|
|
|
|
borderColor: "red",
|
|
|
@ -85,7 +73,7 @@ const GUEST_MODE_TITLE_STORAGE_KEY = "guest_mode_title"
|
|
|
|
|
|
|
|
|
|
|
|
export interface EditorViewProps {
|
|
|
|
export interface EditorViewProps {
|
|
|
|
tactic: Tactic
|
|
|
|
tactic: Tactic
|
|
|
|
onContentChange: (tactic: TacticContent) => Promise<SaveState>
|
|
|
|
onContentChange: (tactic: StepContent) => Promise<SaveState>
|
|
|
|
onNameChange: (name: string) => Promise<boolean>
|
|
|
|
onNameChange: (name: string) => Promise<boolean>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
interface TacticDto {
|
|
|
|
interface TacticDto {
|
|
|
@ -93,6 +81,7 @@ interface TacticDto {
|
|
|
|
name: string
|
|
|
|
name: string
|
|
|
|
courtType: CourtType
|
|
|
|
courtType: CourtType
|
|
|
|
content: string
|
|
|
|
content: string
|
|
|
|
|
|
|
|
root: StepInfoNode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interface EditorPageProps {
|
|
|
|
interface EditorPageProps {
|
|
|
@ -107,6 +96,7 @@ export default function EditorPage({ guestMode }: EditorPageProps) {
|
|
|
|
courtType: "PLAIN",
|
|
|
|
courtType: "PLAIN",
|
|
|
|
content: '{"components": []}',
|
|
|
|
content: '{"components": []}',
|
|
|
|
name: DEFAULT_TACTIC_NAME,
|
|
|
|
name: DEFAULT_TACTIC_NAME,
|
|
|
|
|
|
|
|
root: {id: 1, children: []}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
return null
|
|
|
@ -120,9 +110,11 @@ export default function EditorPage({ guestMode }: EditorPageProps) {
|
|
|
|
|
|
|
|
|
|
|
|
async function initialize() {
|
|
|
|
async function initialize() {
|
|
|
|
const infoResponsePromise = fetchAPIGet(`tactics/${id}`)
|
|
|
|
const infoResponsePromise = fetchAPIGet(`tactics/${id}`)
|
|
|
|
|
|
|
|
const treeResponsePromise = fetchAPIGet(`tactics/${id}/tree`)
|
|
|
|
const contentResponsePromise = fetchAPIGet(`tactics/${id}/steps/1`)
|
|
|
|
const contentResponsePromise = fetchAPIGet(`tactics/${id}/steps/1`)
|
|
|
|
|
|
|
|
|
|
|
|
const infoResponse = await infoResponsePromise
|
|
|
|
const infoResponse = await infoResponsePromise
|
|
|
|
|
|
|
|
const treeResponse = await treeResponsePromise
|
|
|
|
const contentResponse = await contentResponsePromise
|
|
|
|
const contentResponse = await contentResponsePromise
|
|
|
|
|
|
|
|
|
|
|
|
if (infoResponse.status == 401 || contentResponse.status == 401) {
|
|
|
|
if (infoResponse.status == 401 || contentResponse.status == 401) {
|
|
|
@ -132,8 +124,9 @@ export default function EditorPage({ guestMode }: EditorPageProps) {
|
|
|
|
|
|
|
|
|
|
|
|
const { name, courtType } = await infoResponse.json()
|
|
|
|
const { name, courtType } = await infoResponse.json()
|
|
|
|
const content = await contentResponse.text()
|
|
|
|
const content = await contentResponse.text()
|
|
|
|
|
|
|
|
const { root } = await treeResponse.json()
|
|
|
|
|
|
|
|
|
|
|
|
setTactic({ id, name, courtType, content })
|
|
|
|
setTactic({ id, name, courtType, content, root })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
initialize()
|
|
|
|
initialize()
|
|
|
@ -143,6 +136,7 @@ export default function EditorPage({ guestMode }: EditorPageProps) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Editor
|
|
|
|
<Editor
|
|
|
|
id={id}
|
|
|
|
id={id}
|
|
|
|
|
|
|
|
rootStepNode={tactic.root}
|
|
|
|
courtType={tactic.courtType}
|
|
|
|
courtType={tactic.courtType}
|
|
|
|
content={tactic.content}
|
|
|
|
content={tactic.content}
|
|
|
|
name={tactic.name}
|
|
|
|
name={tactic.name}
|
|
|
@ -161,14 +155,15 @@ export interface EditorProps {
|
|
|
|
id: number
|
|
|
|
id: number
|
|
|
|
name: string
|
|
|
|
name: string
|
|
|
|
content: string
|
|
|
|
content: string
|
|
|
|
courtType: CourtType
|
|
|
|
courtType: CourtType,
|
|
|
|
|
|
|
|
rootStepNode: StepInfoNode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function Editor({ id, name, courtType, content }: EditorProps) {
|
|
|
|
function Editor({ id, name, courtType, content, rootStepNode }: EditorProps) {
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
|
|
|
|
|
|
|
|
const storageContent = localStorage.getItem(GUEST_MODE_CONTENT_STORAGE_KEY)
|
|
|
|
const storageContent = localStorage.getItem(GUEST_MODE_CONTENT_STORAGE_KEY)
|
|
|
|
const editorContent =
|
|
|
|
const stepContent =
|
|
|
|
isInGuestMode && storageContent != null ? storageContent : content
|
|
|
|
isInGuestMode && storageContent != null ? storageContent : content
|
|
|
|
|
|
|
|
|
|
|
|
const storageName = localStorage.getItem(GUEST_MODE_TITLE_STORAGE_KEY)
|
|
|
|
const storageName = localStorage.getItem(GUEST_MODE_TITLE_STORAGE_KEY)
|
|
|
@ -182,9 +177,13 @@ function Editor({ id, name, courtType, content }: EditorProps) {
|
|
|
|
name: editorName,
|
|
|
|
name: editorName,
|
|
|
|
id,
|
|
|
|
id,
|
|
|
|
courtType,
|
|
|
|
courtType,
|
|
|
|
content: JSON.parse(editorContent),
|
|
|
|
currentStepContent: {
|
|
|
|
|
|
|
|
stepId: 1,
|
|
|
|
|
|
|
|
...JSON.parse(stepContent)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
rootStepNode,
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
onContentChange={async (content: TacticContent) => {
|
|
|
|
onContentChange={async (content: StepContent) => {
|
|
|
|
if (isInGuestMode) {
|
|
|
|
if (isInGuestMode) {
|
|
|
|
localStorage.setItem(
|
|
|
|
localStorage.setItem(
|
|
|
|
GUEST_MODE_CONTENT_STORAGE_KEY,
|
|
|
|
GUEST_MODE_CONTENT_STORAGE_KEY,
|
|
|
@ -196,6 +195,7 @@ function Editor({ id, name, courtType, content }: EditorProps) {
|
|
|
|
`tactics/${id}/steps/1`,
|
|
|
|
`tactics/${id}/steps/1`,
|
|
|
|
{ content },
|
|
|
|
{ content },
|
|
|
|
"PUT",
|
|
|
|
"PUT",
|
|
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if (response.status == 401) {
|
|
|
|
if (response.status == 401) {
|
|
|
|
navigate("/login")
|
|
|
|
navigate("/login")
|
|
|
@ -212,20 +212,38 @@ function Editor({ id, name, courtType, content }: EditorProps) {
|
|
|
|
`tactics/${id}/name`,
|
|
|
|
`tactics/${id}/name`,
|
|
|
|
{ name },
|
|
|
|
{ name },
|
|
|
|
"PUT",
|
|
|
|
"PUT",
|
|
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if (response.status == 401) {
|
|
|
|
if (response.status == 401) {
|
|
|
|
navigate("/login")
|
|
|
|
navigate("/login")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return response.ok
|
|
|
|
return response.ok
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
|
|
|
|
onStepSelected={() => {
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
stepsContentsRoot={rootStepNode}
|
|
|
|
|
|
|
|
courtType={courtType}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface EditorViewProps {
|
|
|
|
|
|
|
|
tactic: Tactic
|
|
|
|
|
|
|
|
onContentChange: (tactic: StepContent) => Promise<SaveState>
|
|
|
|
|
|
|
|
onStepSelected: (stepId: number) => void,
|
|
|
|
|
|
|
|
onNameChange: (name: string) => Promise<boolean>
|
|
|
|
|
|
|
|
stepsContentsRoot: StepInfoNode
|
|
|
|
|
|
|
|
courtType: "PLAIN" | "HALF"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function EditorView({
|
|
|
|
function EditorView({
|
|
|
|
tactic: { id, name, content: initialContent, courtType },
|
|
|
|
|
|
|
|
|
|
|
|
tactic: {id, name, currentStepContent: initialContent},
|
|
|
|
onContentChange,
|
|
|
|
onContentChange,
|
|
|
|
onNameChange,
|
|
|
|
onNameChange,
|
|
|
|
|
|
|
|
onStepSelected,
|
|
|
|
|
|
|
|
stepsContentsRoot,
|
|
|
|
|
|
|
|
courtType,
|
|
|
|
}: EditorViewProps) {
|
|
|
|
}: EditorViewProps) {
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
|
|
|
|
|
|
|
@ -251,6 +269,8 @@ function EditorView({
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [isStepsTreeVisible, setStepsTreeVisible] = useState(false)
|
|
|
|
|
|
|
|
|
|
|
|
const courtRef = useRef<HTMLDivElement>(null)
|
|
|
|
const courtRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
|
|
|
|
|
|
const setComponents = (action: SetStateAction<TacticComponent[]>) => {
|
|
|
|
const setComponents = (action: SetStateAction<TacticComponent[]>) => {
|
|
|
@ -532,9 +552,14 @@ function EditorView({
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="topbar-right" />
|
|
|
|
<div id="topbar-right">
|
|
|
|
|
|
|
|
<button onClick={() => setStepsTreeVisible((b) => !b)}>
|
|
|
|
|
|
|
|
STEPS
|
|
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="edit-div">
|
|
|
|
<div id="editor-div">
|
|
|
|
|
|
|
|
<div id="content-div">
|
|
|
|
<div id="racks">
|
|
|
|
<div id="racks">
|
|
|
|
<PlayerRack
|
|
|
|
<PlayerRack
|
|
|
|
id={"allies"}
|
|
|
|
id={"allies"}
|
|
|
@ -592,6 +617,69 @@ function EditorView({
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<EditorStepsTree isVisible={isStepsTreeVisible} root={stepsContentsRoot}/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface EditorStepsTreeProps {
|
|
|
|
|
|
|
|
isVisible: boolean
|
|
|
|
|
|
|
|
root: StepInfoNode
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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: []
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<div id="steps-div" style={{transform: isVisible ? "translateX(0)" : "translateX(100%)"}}>
|
|
|
|
|
|
|
|
<StepsTree root={fakeRoot}/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -659,8 +747,8 @@ interface CourtPlayerArrowActionProps {
|
|
|
|
player: PlayerLike
|
|
|
|
player: PlayerLike
|
|
|
|
isInvalid: boolean
|
|
|
|
isInvalid: boolean
|
|
|
|
|
|
|
|
|
|
|
|
content: TacticContent
|
|
|
|
content: StepContent
|
|
|
|
setContent: (state: SetStateAction<TacticContent>) => void
|
|
|
|
setContent: (state: SetStateAction<StepContent>) => void
|
|
|
|
setPreviewAction: (state: SetStateAction<ActionPreview | null>) => void
|
|
|
|
setPreviewAction: (state: SetStateAction<ActionPreview | null>) => void
|
|
|
|
courtRef: RefObject<HTMLDivElement>
|
|
|
|
courtRef: RefObject<HTMLDivElement>
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -768,7 +856,7 @@ function CourtPlayerArrowAction({
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function isBallOnCourt(content: TacticContent) {
|
|
|
|
function isBallOnCourt(content: StepContent) {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
content.components.findIndex(
|
|
|
|
content.components.findIndex(
|
|
|
|
(c) =>
|
|
|
|
(c) =>
|
|
|
|