1
1
import React , { useEffect , useRef , useState } from 'react'
2
2
import { useAppContext } from '../../../app-context'
3
3
import { TournamentGameElement } from './tournament-game'
4
- import Tournament , { TournamentGame } from '../../../playback/Tournament'
4
+ import Tournament , { TournamentGame , TournamentState } from '../../../playback/Tournament'
5
5
import { Space } from 'react-zoomable-ui'
6
6
7
7
export const TournamentRenderer : React . FC = ( ) => {
8
8
const appContext = useAppContext ( )
9
9
10
10
const spaceRef = useRef < Space | null > ( null )
11
11
12
+ const tournament = appContext . state . tournament
13
+ const tournamentState = appContext . state . tournamentState
14
+
12
15
return (
13
16
< div className = "w-full h-screen relative" >
14
17
< Space ref = { spaceRef } treatTwoFingerTrackPadGesturesLikeTouch = { false } >
15
- { appContext . state . tournament && spaceRef . current ? (
18
+ { tournament && spaceRef . current ? (
16
19
< TournamentTree
17
- tournament = { appContext . state . tournament }
18
- minRound = { appContext . state . tournamentMinRound }
20
+ tournament = { tournament }
21
+ tournamentState = { tournamentState }
19
22
spaceRef = { spaceRef . current }
20
23
/>
21
24
) : (
@@ -28,7 +31,7 @@ export const TournamentRenderer: React.FC = () => {
28
31
29
32
interface TournamentTreeProps {
30
33
tournament : Tournament
31
- minRound : number
34
+ tournamentState : TournamentState
32
35
spaceRef : Space
33
36
}
34
37
@@ -45,18 +48,21 @@ const TournamentTree: React.FC<TournamentTreeProps> = (props) => {
45
48
// resizeObserver.observe(leafRef.current)
46
49
// }, [])
47
50
48
- const brackets : [ TournamentGame , string ] [ ] = props . tournament . losersBracketRoot
49
- ? [
50
- [ props . tournament . winnersBracketRoot , 'Winners Bracket' ] ,
51
- [ props . tournament . losersBracketRoot , 'Losers Bracket' ]
52
- ]
53
- : [ [ props . tournament . winnersBracketRoot , '' ] ]
51
+ const brackets : [ TournamentGame , string ] [ ] = [
52
+ [ props . tournament . winnersBracketRoot , props . tournament . losersBracketRoot ? 'Winners Bracket' : '' ]
53
+ ]
54
+ if ( props . tournament . losersBracketRoot && props . tournamentState . showLosers )
55
+ brackets . push ( [ props . tournament . losersBracketRoot , 'Losers Bracket' ] )
54
56
55
57
return (
56
- < div className = "flex flex-row items-center justify-center w-full h-screen" >
58
+ < div className = "flex flex-row gap-10 items-center justify-center w-full h-screen" >
57
59
{ brackets . map ( ( [ rootGame , bracketTitle ] ) => (
58
60
< div className = "flex flex-col justify-center w-max mx-2" key = { bracketTitle } >
59
- < TournamentGameWrapper game = { rootGame } minRound = { props . minRound } spaceRef = { props . spaceRef } />
61
+ < TournamentGameWrapper
62
+ game = { rootGame }
63
+ tournamentState = { props . tournamentState }
64
+ spaceRef = { props . spaceRef }
65
+ />
60
66
{ bracketTitle && (
61
67
< div className = "text-white pt-2 text-center border-t border-white" > { bracketTitle } </ div >
62
68
) }
@@ -68,7 +74,7 @@ const TournamentTree: React.FC<TournamentTreeProps> = (props) => {
68
74
69
75
interface TournamentGameWrapperProps {
70
76
game : TournamentGame
71
- minRound : number
77
+ tournamentState : TournamentState
72
78
spaceRef : Space
73
79
}
74
80
@@ -116,9 +122,17 @@ const TournamentGameWrapper: React.FC<TournamentGameWrapperProps> = (props) => {
116
122
117
123
setLines ( { left, right, down } )
118
124
} , 2 )
119
- } , [ wrapperRef . current , childWrapper1Ref . current , childWrapper2Ref . current , props . minRound ] )
120
-
121
- if ( props . game . round < props . minRound ) {
125
+ } , [ wrapperRef . current , childWrapper1Ref . current , childWrapper2Ref . current , props . tournamentState ] )
126
+
127
+ const [ dependA , dependB ] = props . game . dependsOn
128
+ let round = Math . abs ( props . game . round )
129
+ let minRound = props . tournamentState . minRoundWinners
130
+ let maxRound = props . tournamentState . maxRoundWinners
131
+ if ( Math . sign ( props . game . round ) < 0 ) {
132
+ minRound = props . tournamentState . minRoundLosers
133
+ maxRound = props . tournamentState . maxRoundLosers
134
+ }
135
+ if ( round < minRound ) {
122
136
props . game . viewed = true
123
137
}
124
138
@@ -127,28 +141,28 @@ const TournamentGameWrapper: React.FC<TournamentGameWrapperProps> = (props) => {
127
141
< div
128
142
className = "flex flex-col flex-grow basis-0 " /*ref={round === 1 && index === 0 ? leafRef : undefined}*/
129
143
>
130
- { props . game . round >= props . minRound && (
144
+ { round >= minRound && round <= maxRound && (
131
145
< div className = "mx-auto relative" ref = { wrapperRef } >
132
146
< TournamentGameElement game = { props . game } />
133
- { props . game . round > props . minRound && < GameChildrenLines lines = { lines } /> }
147
+ { round > minRound && < GameChildrenLines lines = { lines } /> }
134
148
</ div >
135
149
) }
136
150
</ div >
137
151
< div className = "flex flex-row" >
138
- { props . game . dependsOn [ 0 ] && (
152
+ { dependA && Math . sign ( dependA . round ) == Math . sign ( props . game . round ) && (
139
153
< div className = "mx-auto" ref = { childWrapper1Ref } >
140
154
< TournamentGameWrapper
141
- game = { props . game . dependsOn [ 0 ] }
142
- minRound = { props . minRound }
155
+ game = { dependA }
156
+ tournamentState = { props . tournamentState }
143
157
spaceRef = { props . spaceRef }
144
158
/>
145
159
</ div >
146
160
) }
147
- { props . game . dependsOn [ 1 ] && (
161
+ { dependB && Math . sign ( dependB . round ) == Math . sign ( props . game . round ) && (
148
162
< div className = "mx-auto" ref = { childWrapper2Ref } >
149
163
< TournamentGameWrapper
150
- game = { props . game . dependsOn [ 1 ] }
151
- minRound = { props . minRound }
164
+ game = { dependB }
165
+ tournamentState = { props . tournamentState }
152
166
spaceRef = { props . spaceRef }
153
167
/>
154
168
</ div >
@@ -188,7 +202,7 @@ const GameChildrenLines: React.FC<{ lines: { left: number | undefined; right: nu
188
202
< div
189
203
className = { commonClasses }
190
204
style = { {
191
- left : ' 50%' ,
205
+ left : `calc( 50% - ${ lineWidthValue / 2 } px)` ,
192
206
background : lineColor ,
193
207
width : lineWidth ,
194
208
height : `${ lines . down / 2 } px` ,
@@ -201,7 +215,7 @@ const GameChildrenLines: React.FC<{ lines: { left: number | undefined; right: nu
201
215
className = { commonClasses }
202
216
style = { {
203
217
flexDirection : 'row-reverse' ,
204
- left : `calc(50% - ${ lines . left } px)` ,
218
+ left : `calc(50% - ${ lines . left } px + ${ lineWidthValue / 2 } px )` ,
205
219
top : `calc(100% - ${ lines . down * 0.5 } px)` ,
206
220
width : `${ lines . left } px` ,
207
221
height : lines . down
@@ -215,7 +229,7 @@ const GameChildrenLines: React.FC<{ lines: { left: number | undefined; right: nu
215
229
< div
216
230
className = { commonClasses }
217
231
style = { {
218
- left : ' 50%' ,
232
+ left : `calc( 50% - ${ lineWidthValue / 2 } px)` ,
219
233
top : `calc(100% - ${ lines . down * 0.5 } px)` ,
220
234
width : `${ lines . right } px` ,
221
235
height : lines . down
0 commit comments