mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
65 lines
1.9 KiB
JavaScript
65 lines
1.9 KiB
JavaScript
// 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;
|
|
|
|
// Handles a websocket message to update the realtime scoring fields.
|
|
var handleScore = function(data) {
|
|
// Update autonomous period values.
|
|
var score = data.Score.CurrentScore;
|
|
$("#autoRuns").text(score.AutoRuns);
|
|
$("#climbs").text(score.Climbs);
|
|
$("#parks").text(score.Parks);
|
|
|
|
// Update component visibility.
|
|
if (!data.AutoCommitted) {
|
|
$("#autoScoring").fadeTo(0, 1);
|
|
$("#teleopScoring").hide();
|
|
$("#waitingMessage").hide();
|
|
scoreCommitted = false;
|
|
} else if (!data.Score.TeleopCommitted) {
|
|
$("#autoScoring").fadeTo(0, 0.25);
|
|
$("#teleopScoring").show();
|
|
$("#waitingMessage").hide();
|
|
scoreCommitted = false;
|
|
} else {
|
|
$("#autoScoring").hide();
|
|
$("#teleopScoring").hide();
|
|
$("#commitMatchScore").hide();
|
|
$("#waitingMessage").show();
|
|
scoreCommitted = true;
|
|
}
|
|
};
|
|
|
|
// Handles a keyboard event and sends the appropriate websocket message.
|
|
var handleKeyPress = function(event) {
|
|
websocket.send(String.fromCharCode(event.keyCode));
|
|
};
|
|
|
|
// 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.
|
|
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); }
|
|
});
|
|
|
|
$(document).keypress(handleKeyPress);
|
|
});
|