Files
cheesy-arena-lite/static/js/scoring_display.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

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;
var scoreCommitted = false;
2015-05-30 23:58:42 -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.
var score = data.Score.CurrentScore;
2018-05-17 21:02:59 -07:00
$("#autoRuns").text(score.AutoRuns);
$("#climbs").text(score.Climbs);
$("#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();
scoreCommitted = false;
} 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();
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();
scoreCommitted = true;
2014-07-29 17:07:30 -07:00
}
};
// Handles a keyboard event and sends the appropriate websocket message.
2014-07-29 17:07:30 -07:00
var handleKeyPress = function(event) {
websocket.send(String.fromCharCode(event.keyCode));
2014-07-29 17:07:30 -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();
}
};
// 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", {
score: function(event) { handleScore(event.data); },
matchTime: function(event) { handleMatchTime(event.data); }
2014-07-29 17:07:30 -07:00
});
$(document).keypress(handleKeyPress);
});