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

75 lines
2.1 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;
var alliance;
2015-05-30 23:58:42 -07:00
// Handles a websocket message to update the realtime scoring fields.
var handleRealtimeScore = function(data) {
var realtimeScore;
if (alliance === "red") {
realtimeScore = data.Red.RealtimeScore;
} else {
realtimeScore = data.Blue.RealtimeScore;
}
2014-07-29 17:07:30 -07:00
// Update autonomous period values.
var score = realtimeScore.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 (!realtimeScore.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 (!realtimeScore.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) {
2018-09-03 12:51:52 -07:00
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() {
alliance = window.location.href.split("/").slice(-1)[0];
2014-07-29 17:07:30 -07:00
// Set up the websocket back to the server.
websocket = new CheesyWebsocket("/panels/scoring/" + alliance + "/websocket", {
matchTime: function(event) { handleMatchTime(event.data); },
realtimeScore: function(event) { handleRealtimeScore(event.data); }
2014-07-29 17:07:30 -07:00
});
$(document).keypress(handleKeyPress);
});