Cleaned up the code and added comments.

This commit is contained in:
Patrick Fairbank
2014-09-06 22:25:12 -07:00
parent 247d5d1fee
commit d86a46f12e
35 changed files with 143 additions and 27 deletions

View File

@@ -8,6 +8,7 @@ var blinkInterval;
var currentScreen = "blank";
var websocket;
// Handles a websocket message to change which screen is displayed.
var handleSetAllianceStationDisplay = function(targetScreen) {
currentScreen = targetScreen;
if (allianceStation == "") {
@@ -28,6 +29,7 @@ var handleSetAllianceStationDisplay = function(targetScreen) {
}
};
// Handles a websocket message to update the team to display.
var handleSetMatch = function(data) {
if (allianceStation != "" && data.AllianceStation == "") {
// The client knows better what display this should be; let the server know.
@@ -52,6 +54,7 @@ var handleSetMatch = function(data) {
}
};
// Handles a websocket message to update the team connection status.
var handleStatus = function(data) {
stationStatus = data.AllianceStations[allianceStation];
var blink = false;
@@ -79,6 +82,7 @@ var handleStatus = function(data) {
}
};
// Handles a websocket message to update the match time countdown.
var handleMatchTime = function(data) {
translateMatchTime(data, function(matchState, matchStateText, countdownSec) {
var countdownString = String(countdownSec % 60);
@@ -91,11 +95,13 @@ var handleMatchTime = function(data) {
});
};
// Handles a websocket message to update the match score.
var handleRealtimeScore = function(data) {
$("#redScore").text(data.RedScore);
$("#blueScore").text(data.BlueScore);
};
// Handles a websocket message to show or hide the hot goal indication.
var handleHotGoalLight = function(side) {
if (allianceStation != "" && (side == "left" && allianceStation[1] == "3" ||
side == "right" && allianceStation[1] == "1")) {

View File

@@ -7,6 +7,7 @@ var websocket;
var teamTemplate = Handlebars.compile($("#teamTemplate").html());
var matchResultTemplate = Handlebars.compile($("#matchResultTemplate").html());
// Handles a websocket message to hide the score dialog once the next match is being introduced.
var handleSetAudienceDisplay = function(targetScreen) {
// Hide the final results so that they aren't blocking the current teams when the announcer needs them most.
if (targetScreen == "intro" || targetScreen == "match") {
@@ -14,6 +15,7 @@ var handleSetAudienceDisplay = function(targetScreen) {
}
};
// Handles a websocket message to update the teams for the current match.
var handleSetMatch = function(data) {
$("#matchName").text(data.MatchType + " Match " + data.MatchDisplayName);
$("#red1").html(teamTemplate(formatTeam(data.Red1)));
@@ -24,6 +26,7 @@ var handleSetMatch = function(data) {
$("#blue3").html(teamTemplate(formatTeam(data.Blue3)));
};
// Handles a websocket message to update the match time countdown.
var handleMatchTime = function(data) {
translateMatchTime(data, function(matchState, matchStateText, countdownSec) {
$("#matchState").text(matchStateText);
@@ -31,11 +34,13 @@ var handleMatchTime = function(data) {
});
};
// Handles a websocket message to update the match score.
var handleRealtimeScore = function(data) {
$("#redScore").text(data.RedScore);
$("#blueScore").text(data.BlueScore);
};
// Handles a websocket message to populate the final score data.
var handleSetFinalScore = function(data) {
console.log(data);
$("#scoreMatchName").text(data.MatchType + " Match " + data.MatchDisplayName);

View File

@@ -1,6 +1,6 @@
// Copyright 2014 Team 254. All Rights Reserved.
// Authors: pat@patfairbank.com (Patrick Fairbank)
// nick@team254.com (Nick Eyre)
// Author: pat@patfairbank.com (Patrick Fairbank)
// Author: nick@team254.com (Nick Eyre)
//
// Client-side methods for the audience display.
@@ -9,6 +9,7 @@ var transitionMap;
var currentScreen = "blank";
var allianceSelectionTemplate = Handlebars.compile($("#allianceSelectionTemplate").html());
// Handles a websocket message to change which screen is displayed.
var handleSetAudienceDisplay = function(targetScreen) {
if (targetScreen == currentScreen) {
return;
@@ -26,6 +27,7 @@ var handleSetAudienceDisplay = function(targetScreen) {
currentScreen = targetScreen;
};
// Handles a websocket message to update the teams for the current match.
var handleSetMatch = function(data) {
$("#redTeam1").text(data.Match.Red1)
$("#redTeam2").text(data.Match.Red2)
@@ -36,6 +38,7 @@ var handleSetMatch = function(data) {
$("#matchName").text(data.MatchName + " " + data.Match.DisplayName);
};
// Handles a websocket message to update the match time countdown.
var handleMatchTime = function(data) {
translateMatchTime(data, function(matchState, matchStateText, countdownSec) {
var countdownString = String(countdownSec % 60);
@@ -47,6 +50,7 @@ var handleMatchTime = function(data) {
});
};
// Handles a websocket message to update the match score.
var handleRealtimeScore = function(data) {
$("#redScoreNumber").text(data.RedScore);
$("#redAssist1").attr("data-on", data.RedCycle.Assists >= 1);
@@ -62,6 +66,7 @@ var handleRealtimeScore = function(data) {
$("#blueCatch").attr("data-on", data.BlueCycle.Catch);
};
// Handles a websocket message to populate the final score data.
var handleSetFinalScore = function(data) {
$("#redFinalScore").text(data.RedScore.Score);
$("#redFinalTeam1").text(data.Match.Red1);
@@ -80,6 +85,7 @@ var handleSetFinalScore = function(data) {
$("#finalMatchName").text(data.MatchName + " " + data.Match.DisplayName);
};
// Handles a websocket message to play a sound to signal match start/stop/etc.
var handlePlaySound = function(sound) {
$("audio").each(function(k, v) {
// Stop and reset any sounds that are still playing.
@@ -89,6 +95,7 @@ var handlePlaySound = function(sound) {
$("#" + sound)[0].play();
};
// Handles a websocket message to update the alliance selection screen.
var handleAllianceSelection = function(alliances) {
if (alliances) {
$.each(alliances, function(k, v) {
@@ -98,6 +105,7 @@ var handleAllianceSelection = function(alliances) {
}
};
// Handles a websocket message to populate and/or show/hide a lower third.
var handleLowerThird = function(data) {
if (data.BottomText == "") {
$("#lowerThirdTop").hide();
@@ -314,7 +322,7 @@ var transitionSponsorToScore = function(callback) {
});
};
// Load and Prioritize Sponsor Data
// Loads sponsor slide data and builds the slideshow HTML.
var initializeSponsorDisplay = function() {
$.getJSON("/api/sponsor_slides", function(sponsors) {
@@ -355,7 +363,6 @@ var initializeSponsorDisplay = function() {
});
}
$(function() {
// Set up the websocket back to the server.
websocket = new CheesyWebsocket("/displays/audience/websocket", {

View File

@@ -20,7 +20,7 @@ var CheesyWebsocket = function(path, events) {
}
}
// Insert an event to allow the server to force-reload the client.
// Insert an event to allow the server to force-reload the client for any display.
events.reload = function(event) {
location.reload();
};
@@ -43,4 +43,4 @@ var CheesyWebsocket = function(path, events) {
};
this.connect();
}
};

View File

@@ -6,6 +6,7 @@
var websocket;
// Handles a websocket message to update the team connection status.
var handleStatus = function(data) {
// Update the team status view.
$.each(data.AllianceStations, function(station, stationStatus) {

View File

@@ -6,34 +6,42 @@
var websocket;
var scoreIsReady;
// Sends a websocket message to load a team into an alliance station.
var substituteTeam = function(team, position) {
websocket.send("substituteTeam", { team: parseInt(team), position: position })
};
// Sends a websocket message to toggle the bypass status for an alliance station.
var toggleBypass = function(station) {
websocket.send("toggleBypass", station);
};
// Sends a websocket message to start the match.
var startMatch = function() {
websocket.send("startMatch");
};
// Sends a websocket message to abort the match.
var abortMatch = function() {
websocket.send("abortMatch");
};
// Sends a websocket message to commit the match score and load the next match.
var commitResults = function() {
websocket.send("commitResults");
};
// Sends a websocket message to discard the match score and load the next match.
var discardResults = function() {
websocket.send("discardResults");
};
// Sends a websocket message to change what the audience display is showing.
var setAudienceDisplay = function() {
websocket.send("setAudienceDisplay", $("input[name=audienceDisplay]:checked").val());
};
// Sends a websocket message to change what the alliance station display is showing.
var setAllianceStationDisplay = function() {
websocket.send("setAllianceStationDisplay", $("input[name=allianceStationDisplay]:checked").val());
};
@@ -49,6 +57,7 @@ var confirmCommit = function(isReplay) {
}
};
// Handles a websocket message to update the team connection status.
var handleStatus = function(data) {
// Update the team status view.
$.each(data.AllianceStations, function(station, stationStatus) {
@@ -115,6 +124,7 @@ var handleStatus = function(data) {
}
};
// Handles a websocket message to update the match time countdown.
var handleMatchTime = function(data) {
translateMatchTime(data, function(matchState, matchStateText, countdownSec) {
$("#matchState").text(matchStateText);
@@ -122,11 +132,13 @@ var handleMatchTime = function(data) {
});
};
// Handles a websocket message to update the audience display screen selector.
var handleSetAudienceDisplay = function(data) {
$("input[name=audienceDisplay]:checked").prop("checked", false);
$("input[name=audienceDisplay][value=" + data + "]").prop("checked", true);
};
// Handles a websocket message to signal whether the referee and scorers have committed after the match.
var handleScoringStatus = function(data) {
scoreIsReady = data.RefereeScoreReady && data.RedScoreReady && data.BlueScoreReady;
$("#refereeScoreStatus").attr("data-ready", data.RefereeScoreReady);
@@ -134,6 +146,7 @@ var handleScoringStatus = function(data) {
$("#blueScoreStatus").attr("data-ready", data.BlueScoreReady);
};
// Handles a websocket message to update the alliance station display screen selector.
var handleSetAllianceStationDisplay = function(data) {
$("input[name=allianceStationDisplay]:checked").prop("checked", false);
$("input[name=allianceStationDisplay][value=" + data + "]").prop("checked", true);

View File

@@ -14,10 +14,13 @@ var matchStates = {
};
var matchTiming;
// Handles a websocket message containing the length of each period in the match.
var handleMatchTiming = function(data) {
matchTiming = data;
};
// Converts the raw match state and time into a human-readable state and per-period time. Calls the provided
// callback with the result.
var translateMatchTime = function(data, callback) {
var matchStateText;
switch (matchStates[data.MatchState]) {
@@ -42,6 +45,7 @@ var translateMatchTime = function(data, callback) {
callback(matchStates[data.MatchState], matchStateText, getCountdown(data.MatchState, data.MatchTimeSec));
};
// Returns the per-period countdown for the given match state and overall time into the match.
var getCountdown = function(matchState, matchTimeSec) {
switch (matchStates[matchState]) {
case "PRE_MATCH":

View File

@@ -5,6 +5,7 @@
var websocket;
// Handles a websocket message to update the realtime scoring fields.
var handleScore = function(data) {
// Update autonomous period values.
var score = data.CurrentScore;
@@ -59,6 +60,7 @@ var handleScore = function(data) {
}
};
// Handles a keyboard event and sends the appropriate websocket message.
var handleKeyPress = function(event) {
var key = String.fromCharCode(event.keyCode);
switch(key) {
@@ -110,6 +112,7 @@ var handleKeyPress = function(event) {
}
};
// Sends a websocket message to indicate that the score for this alliance is ready.
var commitMatchScore = function() {
websocket.send("commitMatch");
};