-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds selection of currently active board in play.ts #10594
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Chess } from 'chessops/chess'; | ||
public import { Chess } from 'chessops/chess'; | ||
import { INITIAL_FEN, makeFen, parseFen } from 'chessops/fen'; | ||
import { makeSan, parseSan } from 'chessops/san'; | ||
import { NormalMove } from 'chessops/types'; | ||
|
@@ -96,6 +96,7 @@ export default function (token: string) { | |
let liveChessConnection: WebSocket; //Connection Object to LiveChess through websocket | ||
let isLiveChessConnected = false; //Used to track if a board there is a connection to DGT Live Chess | ||
let currentSerialnr = '0'; //Public property to store the current serial number of the DGT Board in case there is more than one | ||
let currentBoard: { serialnr: string; state: string }; //Stores active board object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we have both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currentSerialnr is used in the DGTliveChessConnectionLoop that checks whether it's been assigned a non-null value to determine connection status to the board and in the socket connection's onclose to reset the value back to 0. In line 859 there's a conditional checking a hard coded values from the first boards array index value. It seems like the code was initially designed to use both a variable to hold the serial number and then it also checks hardcoded array values(assuming the user only has one board) in the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was mostly a rhetorical question. Is there a reason why we need to have both? Because otherwise, it should be changed so that only one value is used everywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. I'll change it. I was also thinking about making this work with the regular interface so you don't need two tabs open to use this feature. Sorry for the time between responses, I've been busy with work. |
||
//subscription stores the information about the board being connected, most importantly the serialnr | ||
const subscription = { id: 2, call: 'subscribe', param: { feed: 'eboardevent', id: 1, param: { serialnr: '' } } }; | ||
let lastLegalParam: { board: string; san: string[] }; //This can help prevent duplicate moves from LiveChess being detected as move from the other side, like a duplicate O-O | ||
|
@@ -844,19 +845,21 @@ export default function (token: string) { | |
if (message.response == 'call' && message.id == '1') { | ||
//Get the list of available boards on LiveChess | ||
boards = message.param; | ||
//Selects currently active board | ||
for (let i = 0; i < boards.length; i++) { | ||
if (boards[i].state == "ACTIVE") { | ||
currentBoard = boards[i]; | ||
currentSerialnr = boards[i].serialnr; | ||
} | ||
} | ||
console.table(boards); | ||
if (verbose) console.info(boards[0].serialnr); | ||
//TODO | ||
//we need to be able to handle more than one board | ||
//for now using the first board found | ||
//Update the base subscription message with the serial number | ||
currentSerialnr = boards[0].serialnr; | ||
if (verbose) console.info(currentSerialnr); | ||
subscription.param.param.serialnr = currentSerialnr; | ||
if (verbose) console.info('Websocket onmessage[call]: board serial number updated to: ' + currentSerialnr); | ||
if (verbose) console.info('Webscoket - about to send the following message \n' + JSON.stringify(subscription)); | ||
liveChessConnection.send(JSON.stringify(subscription)); | ||
//Check if the board is properly connected | ||
if (boards[0].state != 'ACTIVE' && boards[0].state != 'INACTIVE') | ||
if (currentBoard.state != 'ACTIVE' && currentBoard.state != 'INACTIVE') | ||
// "NOTRESPONDING" || "DELAYED" | ||
console.error(`Board with serial ${currentSerialnr} is not properly connected. Please fix`); | ||
//Send setup with stating position | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take this out. Must've accidentally added this.