}
courtRef={courtDivContentRef}
setActions={(actions) =>
setContent((content) => ({
...content,
- players: content.players,
actions: actions(content.actions),
}))
}
@@ -515,8 +517,8 @@ function EditorView({
}
setContent((content) => ({
...content,
- players: toSplicedPlayers(
- content.players,
+ components: replaceOrInsert(
+ content.components,
player,
true,
),
@@ -533,10 +535,11 @@ function EditorView({
}
function isBallOnCourt(content: TacticContent) {
- if (content.players.findIndex((p) => p.hasBall) != -1) {
- return true
- }
- return content.objects.findIndex((o) => o.type == "ball") != -1
+ return (
+ content.components.findIndex(
+ (c) => (c.type == "player" && c.hasBall) || c.type == BALL_TYPE,
+ ) != -1
+ )
}
function renderCourtObject(courtObject: RackedCourtObject) {
@@ -558,12 +561,18 @@ function Court({ courtType }: { courtType: string }) {
)
}
-function getRackPlayers(team: PlayerTeam, players: Player[]): RackedPlayer[] {
+
+function getRackPlayers(
+ team: PlayerTeam,
+ components: TacticComponent[],
+): RackedPlayer[] {
return ["1", "2", "3", "4", "5"]
.filter(
(role) =>
- players.findIndex((p) => p.team == team && p.role == role) ==
- -1,
+ components.findIndex(
+ (c) =>
+ c.type == "player" && c.team == team && c.role == role,
+ ) == -1,
)
.map((key) => ({ team, key }))
}
@@ -611,14 +620,11 @@ function useContentState
(
return [content, setContentSynced, savingState]
}
-function toSplicedPlayers(
- players: Player[],
- player: Player,
+function replaceOrInsert(
+ array: A[],
+ it: A,
replace: boolean,
-): Player[] {
- const idx = players.findIndex(
- (p) => p.team === player.team && p.role === player.role,
- )
-
- return players.toSpliced(idx, 1, ...(replace ? [player] : []))
+): A[] {
+ const idx = array.findIndex((i) => i.id == it.id)
+ return array.toSpliced(idx, 1, ...(replace ? [it] : []))
}
diff --git a/front/views/editor/CourtAction.tsx b/front/views/editor/CourtAction.tsx
index de33224..cef1e86 100644
--- a/front/views/editor/CourtAction.tsx
+++ b/front/views/editor/CourtAction.tsx
@@ -46,7 +46,7 @@ export function CourtAction({
}}
wavy={action.type == ActionKind.DRIBBLE}
//TODO place those magic values in constants
- endRadius={action.toPlayerId ? 26 : 17}
+ endRadius={action.toId ? 26 : 17}
startRadius={0}
onDeleteRequested={onActionDeleted}
style={{
diff --git a/front/views/template/Header.tsx b/front/views/template/Header.tsx
index 5c8cbcd..8555133 100644
--- a/front/views/template/Header.tsx
+++ b/front/views/template/Header.tsx
@@ -17,7 +17,7 @@ export function Header({ username }: { username: string }) {
location.pathname = BASE + "/"
}}>
IQ
- Ball
+ CourtObjects