Skip to content

Conversation

@tom-anders
Copy link
Collaborator

@tom-anders tom-anders commented Mar 25, 2025

With this PR, we'd have very basic support for tournaments. However, the game screen is still missing some features, like berserking, displaying rank, etc. That will be a follow-up PR. Same goes for the "podium" screen for finished tournaments.

I did not add widget tests yet, wanted to get feedback on the layout/design first.

tournament_screen.webm

TODO:

  • fix tests
  • fix non started tournament clock display
  • fix bug when non started tournament doesn't refresh when the countdown reaches 0 (it should refresh and start automatically, currently: it doesn't start and the featured game doesn't work)
  • [ ]

@teefoox
Copy link

teefoox commented Mar 25, 2025

The tournament screen is great! Love it.
I think it would be useful to also have the players' recent results (at least the last one) to know if one needs to win one or two games to get the win-streak buff. In an end tournament rush, it can help to make strategic decisions.

@veloce
Copy link
Contributor

veloce commented Mar 28, 2025

Nice work on the UI! Will review asap.

Copy link
Contributor

@veloce veloce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@tom-anders
Copy link
Collaborator Author

Thanks for the review! I added two widgets tests now, let me know if you think there's anything else that should be tested

@tom-anders
Copy link
Collaborator Author

The server already sends a reload event when something notable changes, so I don't think manual refreshing would have any benefit

Then it needs to register app lifecycle onPause/onResume callbacks to force a reload on resume

Done 👍

But here, we need the tournament socket to stay active. If I delete that linked code, moving to the next game works (but it's probably not the solution we want...?)

indeed it is by design we don't want more than one socket connection at a time; how does it work on the website? I don't think the tournament page opens 2 sockets. IIRC the old mobile app also do not open 2 sockets at the same time and still has the featured game.

Ah, I checked with Firefox devtools, the website sends a startWatching to the server, so we need to do the same. I guess that means we can't reuse the TvController anymore, but that's fine

]);
// wait for socket message
await tester.pump(const Duration(milliseconds: 10));
expect(find.byType(PieceWidget), findsNWidgets(32));
Copy link
Collaborator Author

@tom-anders tom-anders Apr 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@veloce FYI: After adding the featured game in the tests as well, this expectation failed as it seems to still find the PieceWidgets from the FeatureGame board. So I replaced it with a check to find the name of our opponent instead to verify that the game screen is shown.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tom-anders you could refine by using find.descendant to check the pieces are descendant of GameScreen.

@tom-anders
Copy link
Collaborator Author

Alright, we're using the tournament websocket now for displaying the featured game, now everything works even when there's a new featured game.

I also made the board look more like in broadcasts:

Screenshot_1743714662

featuredGame: pick('featured').asFeaturedGameOrNull(),
// Sometimes a new FEN comes in via the websocket, but the API reload response
// still has the FEN of the previous move, leading to sync issues.
// So only copy the whole game here if it's a new ID.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this logic, I saw some glitches where moves were taken back due to API and websocket being out of sync

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked how it works on the website? Given the reload mechanism I find it strange indeed to use both this and the websocket.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can check again and/or ask @ornicar, but I think the reload events are not tied to the events of the featured game, but rather to the score/standings changing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's fine like that. You need the reload events to know there is a new game. I assume the server sends the reload socket message when a new featured game starts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, when there's a new featured game, we get it via reload and then send startWatching via the socket to get the updates for each move

}

// Don't bother parsing the whole FEN here, we just need the turn
final turn = featuredGame.fen.endsWith(' b') ? Side.black : Side.white;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@veloce Does chessground have some kind of convenience API for this? I didn't want to waste performance by parsing the whole string here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. That would be more a dartchess thing but for now there is only the Position API which parses the full fen. I don't think performance is an issue here though, so I wouldn't bother.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well for bullet games this might be called pretty often

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fen parsing is cheap enough that even for real games (playing), the FEN is parsed each time the position change (it's a chessground parameter).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright 👍

@veloce
Copy link
Contributor

veloce commented Apr 4, 2025

Sorry it messed the PR commit history...

@veloce
Copy link
Contributor

veloce commented Apr 4, 2025

Will merge soon I think, still some testing and a couple of UI changes.

@veloce veloce merged commit a9c6188 into lichess-org:main Apr 9, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants