Expose MaiaChess clock state for electronic chessboards#312
Open
Tortue95 wants to merge 1 commit into
Open
Conversation
|
Someone is attempting to deploy a commit to the Maia Platform Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expose MaiaChess clock state for electronic chessboards
Why this PR
Our goal is to provide an experience that feels as close as possible to a real over-the-board chess game.
To support that, this PR adds a small integration point on the MaiaChess side so external applications, such as ChessConnect, can synchronize a physical chess clock when the game is played on an electronic chessboard.
Today, ChessConnect can already track the MaiaChess board and send moves to a connected board. However, the clock times cannot currently be retrieved in a reliable way.
One possible solution would be to read the displayed clock values directly from the DOM, but that approach is fragile. The HTML elements that display the MaiaChess clocks do not have explicit names or attributes indicating which div represents which clock, or which player it belongs to. An integration would therefore have to infer that information from the visual structure of the page, which is complex, and unreliable over time: a layout or CSS class change could break the integration without any functional change to the clock itself.
This PR therefore exposes an explicit clock state from MaiaChess, instead of requiring external integrations to guess that state from the rendered HTML.
What this PR adds
This PR exposes the current MaiaChess clock state through a neutral global object:
This object contains the information needed to drive an external clock:
Details
turnColorindicates whose turn it is, even when no clock is running.activeColoronly indicates the color whose clock should be counting down.activeColorisnullfor games without a time limit.activeColoris alsonulluntil the game has actually started.remainingAtMsallows consumers to recalculate the current remaining time without requiring continuous React updates.lifecycleallows an external integration to distinguish between a game that has not started, a game in progress, and a finished game.resultallows the final game state to be propagated correctly to a clock or connected device.A big thank you to the maintainers!
I am fully aware that this modification has no direct utility for the MaiaChess website when used as a standalone platform. However, it opens the door to wonderful possibilities for the over-the-board (OTB) chess community.
I wanted to warmly thank you for the time you will spend reviewing this PR and, more generally, for all your work on this project.
To keep the application clean and avoid any bloat, I made sure this integration is as lightweight and non-intrusive as possible. If you would like me to adjust anything to align perfectly with your standards, please don't hesitate to let me know!