2014-07-29 17:07:30 -07:00
|
|
|
// Copyright 2014 Team 254. All Rights Reserved.
|
|
|
|
|
// Author: pat@patfairbank.com (Patrick Fairbank)
|
|
|
|
|
//
|
|
|
|
|
// Client-side logic for the scoring interface.
|
|
|
|
|
|
|
|
|
|
var websocket;
|
2015-05-31 12:40:24 -07:00
|
|
|
var scoreCommitted = false;
|
2015-05-30 23:58:42 -07:00
|
|
|
|
2014-09-06 22:25:12 -07:00
|
|
|
// Handles a websocket message to update the realtime scoring fields.
|
2014-07-29 17:07:30 -07:00
|
|
|
var handleScore = function(data) {
|
|
|
|
|
// Update autonomous period values.
|
2016-10-16 16:00:09 -07:00
|
|
|
var score = data.Score.CurrentScore;
|
2018-05-17 21:02:59 -07:00
|
|
|
$("#autoRuns").text(score.AutoRuns);
|
|
|
|
|
$("#climbs").text(score.Climbs);
|
2018-08-25 19:41:00 -07:00
|
|
|
$("#parks").text(score.Parks);
|
2014-07-29 17:07:30 -07:00
|
|
|
|
|
|
|
|
// Update component visibility.
|
|
|
|
|
if (!data.AutoCommitted) {
|
2017-07-15 13:53:00 -07:00
|
|
|
$("#autoScoring").fadeTo(0, 1);
|
|
|
|
|
$("#teleopScoring").hide();
|
2014-07-29 17:07:30 -07:00
|
|
|
$("#waitingMessage").hide();
|
2015-05-31 12:40:24 -07:00
|
|
|
scoreCommitted = false;
|
2016-10-16 16:00:09 -07:00
|
|
|
} else if (!data.Score.TeleopCommitted) {
|
2017-07-15 13:53:00 -07:00
|
|
|
$("#autoScoring").fadeTo(0, 0.25);
|
|
|
|
|
$("#teleopScoring").show();
|
2014-07-29 17:07:30 -07:00
|
|
|
$("#waitingMessage").hide();
|
2015-05-31 12:40:24 -07:00
|
|
|
scoreCommitted = false;
|
2014-07-29 17:07:30 -07:00
|
|
|
} else {
|
2017-07-15 13:53:00 -07:00
|
|
|
$("#autoScoring").hide();
|
|
|
|
|
$("#teleopScoring").hide();
|
2014-07-29 17:07:30 -07:00
|
|
|
$("#commitMatchScore").hide();
|
|
|
|
|
$("#waitingMessage").show();
|
2015-05-31 12:40:24 -07:00
|
|
|
scoreCommitted = true;
|
2014-07-29 17:07:30 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-06 22:25:12 -07:00
|
|
|
// Handles a keyboard event and sends the appropriate websocket message.
|
2014-07-29 17:07:30 -07:00
|
|
|
var handleKeyPress = function(event) {
|
2018-08-25 19:41:00 -07:00
|
|
|
websocket.send(String.fromCharCode(event.keyCode));
|
2014-07-29 17:07:30 -07:00
|
|
|
};
|
|
|
|
|
|
2015-05-31 12:40:24 -07:00
|
|
|
// Handles a websocket message to update the match status.
|
|
|
|
|
var handleMatchTime = function(data) {
|
|
|
|
|
if (matchStates[data.MatchState] == "POST_MATCH" && !scoreCommitted) {
|
|
|
|
|
$("#commitMatchScore").show();
|
|
|
|
|
} else {
|
|
|
|
|
$("#commitMatchScore").hide();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-06 22:25:12 -07:00
|
|
|
// Sends a websocket message to indicate that the score for this alliance is ready.
|
2014-07-29 17:07:30 -07:00
|
|
|
var commitMatchScore = function() {
|
|
|
|
|
websocket.send("commitMatch");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
|
// Set up the websocket back to the server.
|
|
|
|
|
websocket = new CheesyWebsocket("/displays/scoring/" + alliance + "/websocket", {
|
2015-05-31 12:40:24 -07:00
|
|
|
score: function(event) { handleScore(event.data); },
|
|
|
|
|
matchTime: function(event) { handleMatchTime(event.data); }
|
2014-07-29 17:07:30 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(document).keypress(handleKeyPress);
|
|
|
|
|
});
|