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

424 lines
16 KiB
JavaScript
Raw Normal View History

2014-08-02 19:43:45 -07:00
// Copyright 2014 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
// Author: nick@team254.com (Nick Eyre)
2014-08-02 19:43:45 -07:00
//
// Client-side methods for the audience display.
2014-08-04 00:52:46 -07:00
var websocket;
2014-08-02 19:43:45 -07:00
var transitionMap;
var currentScreen = "blank";
var allianceSelectionTemplate = Handlebars.compile($("#allianceSelectionTemplate").html());
2014-08-02 19:43:45 -07:00
// Handles a websocket message to change which screen is displayed.
2014-08-02 19:43:45 -07:00
var handleSetAudienceDisplay = function(targetScreen) {
if (targetScreen == currentScreen) {
return;
}
transitions = transitionMap[currentScreen][targetScreen];
if (transitions == null) {
// There is no direct transition defined; need to go to the blank screen first.
transitions = function() {
transitionMap[currentScreen]["blank"](transitionMap["blank"][targetScreen]);
};
}
transitions();
currentScreen = targetScreen;
};
// Handles a websocket message to update the teams for the current match.
2014-08-02 19:43:45 -07:00
var handleSetMatch = function(data) {
$("#redTeam1").text(data.Match.Red1)
$("#redTeam2").text(data.Match.Red2)
$("#redTeam3").text(data.Match.Red3)
$("#blueTeam1").text(data.Match.Blue1)
$("#blueTeam2").text(data.Match.Blue2)
$("#blueTeam3").text(data.Match.Blue3)
$("#matchName").text(data.MatchName + " " + data.Match.DisplayName);
};
// Handles a websocket message to update the match time countdown.
2014-08-02 19:43:45 -07:00
var handleMatchTime = function(data) {
translateMatchTime(data, function(matchState, matchStateText, countdownSec) {
var countdownString = String(countdownSec % 60);
if (countdownString.length == 1) {
countdownString = "0" + countdownString;
}
countdownString = Math.floor(countdownSec / 60) + ":" + countdownString;
$("#matchTime").text(countdownString);
});
};
// Handles a websocket message to update the match score.
2014-08-02 19:43:45 -07:00
var handleRealtimeScore = function(data) {
$("#redScoreNumber").text(data.RedScoreFields.Score);
$("#redTower").text(data.RedScoreFields.TowerStrength);
$("#blueScoreNumber").text(data.BlueScoreFields.Score);
$("#blueTower").text(data.BlueScoreFields.TowerStrength);
for (var i = 0; i < 5; i++) {
$("#redDefense" + (i + 1)).attr("value", data.RedScoreFields.DefensesStrength[i]);
$("#blueDefense" + (i + 1)).attr("value", data.BlueScoreFields.DefensesStrength[i]);
}
2014-08-02 19:43:45 -07:00
};
// Handles a websocket message to populate the final score data.
2014-08-02 19:43:45 -07:00
var handleSetFinalScore = function(data) {
$("#redFinalScore").text(data.RedScore.Score);
$("#redFinalTeam1").text(data.Match.Red1);
$("#redFinalTeam2").text(data.Match.Red2);
$("#redFinalTeam3").text(data.Match.Red3);
$("#redFinalAuto").text(data.RedScore.AutoPoints);
2016-08-13 01:04:54 -07:00
$("#redFinalTeleop").text(data.RedScore.TeleopPoints);
2014-08-02 19:43:45 -07:00
$("#redFinalFoul").text(data.RedScore.FoulPoints);
2016-08-13 01:04:54 -07:00
$("#redFinalBreached").html(data.RedScore.Breached ? "&#x2714;" : "&#x2718;");
$("#redFinalBreached").attr("data-checked", data.RedScore.Breached);
$("#redFinalCaptured").html(data.RedScore.Captured ? "&#x2714;" : "&#x2718;");
$("#redFinalCaptured").attr("data-checked", data.RedScore.Captured);
2014-08-02 19:43:45 -07:00
$("#blueFinalScore").text(data.BlueScore.Score);
$("#blueFinalTeam1").text(data.Match.Blue1);
$("#blueFinalTeam2").text(data.Match.Blue2);
$("#blueFinalTeam3").text(data.Match.Blue3);
$("#blueFinalAuto").text(data.BlueScore.AutoPoints);
2016-08-13 01:04:54 -07:00
$("#blueFinalTeleop").text(data.BlueScore.TeleopPoints);
2014-08-02 19:43:45 -07:00
$("#blueFinalFoul").text(data.BlueScore.FoulPoints);
2016-08-13 01:04:54 -07:00
$("#blueFinalBreached").html(data.BlueScore.Breached ? "&#x2714;" : "&#x2718;");
$("#blueFinalBreached").attr("data-checked", data.BlueScore.Breached);
$("#blueFinalCaptured").html(data.BlueScore.Captured ? "&#x2714;" : "&#x2718;");
$("#blueFinalCaptured").attr("data-checked", data.BlueScore.Captured);
2014-08-02 19:43:45 -07:00
$("#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.
v.pause();
v.currentTime = 0;
});
$("#" + sound)[0].play();
};
// Handles a websocket message to update the alliance selection screen.
var handleAllianceSelection = function(alliances) {
if (alliances) {
$.each(alliances, function(k, v) {
v.Index = k + 1;
});
$("#allianceSelection").html(allianceSelectionTemplate(alliances));
}
};
// Handles a websocket message to populate and/or show/hide a lower third.
2014-08-15 20:13:02 -07:00
var handleLowerThird = function(data) {
if (data.BottomText == "") {
$("#lowerThirdTop").hide();
$("#lowerThirdBottom").hide();
$("#lowerThirdSingle").text(data.TopText);
$("#lowerThirdSingle").show();
} else {
$("#lowerThirdSingle").hide();
$("#lowerThirdTop").text(data.TopText);
$("#lowerThirdBottom").text(data.BottomText);
$("#lowerThirdTop").show();
$("#lowerThirdBottom").show();
}
};
2014-08-02 19:43:45 -07:00
var transitionBlankToIntro = function(callback) {
$("#centering").transition({queue: false, bottom: "0px"}, 500, "ease", function() {
$(".teams").transition({queue: false, width: "75px"}, 100, "linear", function() {
$(".score").transition({queue: false, width: "120px"}, 500, "ease", function() {
$("#eventMatchInfo").show();
var height = -$("#eventMatchInfo").height();
$("#eventMatchInfo").transition({queue: false, bottom: height + "px"}, 500, "ease", callback);
});
});
});
};
var transitionIntroToInMatch = function(callback) {
2016-08-12 19:05:45 -07:00
$("#logo").transition({queue: false, top: "35px"}, 500, "ease");
$(".score").transition({queue: false, width: "260px"}, 500, "ease", function() {
2014-08-02 19:43:45 -07:00
$(".score-number").transition({queue: false, opacity: 1}, 750, "ease");
$(".score-fields").transition({queue: false, opacity: 1}, 750, "ease");
2014-08-02 19:43:45 -07:00
$("#matchTime").transition({queue: false, opacity: 1}, 750, "ease", callback);
});
};
var transitionIntroToBlank = function(callback) {
$("#eventMatchInfo").transition({queue: false, bottom: "0px"}, 500, "ease", function() {
$("#eventMatchInfo").hide();
$(".score").transition({queue: false, width: "0px"}, 500, "ease");
$(".teams").transition({queue: false, width: "40px"}, 500, "ease", function() {
$("#centering").transition({queue: false, bottom: "-340px"}, 1000, "ease", callback);
});
});
};
var transitionBlankToInMatch = function(callback) {
$("#centering").transition({queue: false, bottom: "0px"}, 500, "ease", function() {
$(".teams").transition({queue: false, width: "75px"}, 100, "linear", function() {
2016-08-12 19:05:45 -07:00
$("#logo").transition({queue: false, top: "35px"}, 500, "ease");
$(".score").transition({queue: false, width: "260px"}, 500, "ease", function() {
2014-08-02 19:43:45 -07:00
$("#eventMatchInfo").show();
$(".score-number").transition({queue: false, opacity: 1}, 750, "ease");
$(".score-fields").transition({queue: false, opacity: 1}, 750, "ease");
2014-08-02 19:43:45 -07:00
$("#matchTime").transition({queue: false, opacity: 1}, 750, "ease", callback);
var height = -$("#eventMatchInfo").height();
$("#eventMatchInfo").transition({queue: false, bottom: height + "px"}, 500, "ease", callback);
});
});
});
}
var transitionInMatchToIntro = function(callback) {
$(".score-number").transition({queue: false, opacity: 0}, 300, "linear");
$(".score-fields").transition({queue: false, opacity: 0}, 300, "linear");
2014-08-02 19:43:45 -07:00
$("#matchTime").transition({queue: false, opacity: 0}, 300, "linear", function() {
2016-08-12 19:05:45 -07:00
$("#logo").transition({queue: false, top: "50px"}, 500, "ease");
2014-08-02 19:43:45 -07:00
$(".score").transition({queue: false, width: "120px"}, 500, "ease");
$(".teams").transition({queue: false, width: "75px"}, 500, "ease", callback);
});
};
var transitionInMatchToBlank = function(callback) {
$("#eventMatchInfo").transition({queue: false, bottom: "0px"}, 500, "ease");
$("#matchTime").transition({queue: false, opacity: 0}, 300, "linear");
$(".score-fields").transition({queue: false, opacity: 0}, 300, "linear");
2015-08-20 23:09:03 -07:00
$(".score-number").transition({queue: false, opacity: 0}, 300, "linear", function() {
2014-08-02 19:43:45 -07:00
$("#eventMatchInfo").hide();
2016-08-12 19:05:45 -07:00
$("#logo").transition({queue: false, top: "50px"}, 500, "ease");
2014-08-02 19:43:45 -07:00
$(".score").transition({queue: false, width: "0px"}, 500, "ease");
$(".teams").transition({queue: false, width: "40px"}, 500, "ease", function() {
$("#centering").transition({queue: false, bottom: "-340px"}, 1000, "ease", callback);
});
});
};
var transitionBlankToLogo = function(callback) {
$(".blindsCenter.blank").css({rotateY: "0deg"});
$(".blindsCenter.full").css({rotateY: "-180deg"});
2014-08-02 19:43:45 -07:00
$(".blinds.right").transition({queue: false, right: 0}, 1000, "ease");
$(".blinds.left").transition({queue: false, left: 0}, 1000, "ease", function() {
$(".blinds.left").addClass("full");
$(".blinds.right").hide();
setTimeout(function() {
$(".blindsCenter.blank").transition({queue: false, rotateY: "180deg"}, 500, "ease");
$(".blindsCenter.full").transition({queue: false, rotateY: "0deg"}, 500, "ease", callback);
2014-08-02 19:43:45 -07:00
}, 200);
});
};
var transitionLogoToBlank = function(callback) {
$(".blindsCenter.blank").transition({queue: false, rotateY: "360deg"}, 500, "ease");
$(".blindsCenter.full").transition({queue: false, rotateY: "180deg"}, 500, "ease", function() {
2014-08-02 19:43:45 -07:00
setTimeout(function() {
$(".blinds.left").removeClass("full");
$(".blinds.right").show();
$(".blinds.right").transition({queue: false, right: "-50%"}, 1000, "ease");
$(".blinds.left").transition({queue: false, left: "-50%"}, 1000, "ease", callback);
}, 200);
});
};
var transitionLogoToScore = function(callback) {
2014-08-24 15:32:43 -07:00
$(".blindsCenter.full").transition({queue: false, top: "-350px"}, 625, "ease");
$("#finalScore").show();
$("#finalScore").transition({queue: false, opacity: 1}, 1000, "ease", callback);
2014-08-02 19:43:45 -07:00
};
var transitionBlankToScore = function(callback) {
transitionBlankToLogo(function() {
2014-08-24 15:32:43 -07:00
setTimeout(function() { transitionLogoToScore(callback); }, 50);
2014-08-02 19:43:45 -07:00
});
};
var transitionScoreToLogo = function(callback) {
2014-08-24 15:32:43 -07:00
$("#finalScore").transition({queue: false, opacity: 0}, 500, "ease", function(){
2014-08-02 19:43:45 -07:00
$("#finalScore").hide();
});
2014-08-24 15:32:43 -07:00
$(".blindsCenter.full").transition({queue: false, top: 0}, 625, "ease", callback);
2014-08-02 19:43:45 -07:00
};
var transitionScoreToBlank = function(callback) {
transitionScoreToLogo(function() {
transitionLogoToBlank(callback);
});
2015-10-01 20:56:07 -07:00
};
2014-08-02 19:43:45 -07:00
var transitionBlankToAllianceSelection = function(callback) {
2015-09-11 14:06:00 -07:00
$('#allianceSelectionCentering').css("right","-60em").show();
$('#allianceSelectionCentering').transition({queue: false, right: "3em"}, 500, "ease", callback);
};
var transitionAllianceSelectionToBlank = function(callback) {
2015-09-11 14:06:00 -07:00
$('#allianceSelectionCentering').transition({queue: false, right: "-60em"}, 500, "ease", callback);
};
2014-08-15 20:13:02 -07:00
var transitionBlankToLowerThird = function(callback) {
$("#lowerThird").show();
$("#lowerThird").transition({queue: false, left: "150px"}, 750, "ease", callback);
};
var transitionLowerThirdToBlank = function(callback) {
$("#lowerThird").transition({queue: false, left: "-1000px"}, 1000, "ease", function() {
$("#lowerThird").hide();
if (callback) {
callback();
}
});
};
var transitionBlankToSponsor = function(callback) {
$(".blindsCenter.blank").css({rotateY: "90deg"});
$(".blinds.right").transition({queue: false, right: 0}, 1000, "ease");
$(".blinds.left").transition({queue: false, left: 0}, 1000, "ease", function() {
$(".blinds.left").addClass("full");
$(".blinds.right").hide();
setTimeout(function() {
$("#sponsor").show();
$("#sponsor").transition({queue: false, opacity: 1}, 1000, "ease", callback);
}, 200);
});
};
var transitionSponsorToBlank = function(callback) {
$("#sponsor").transition({queue: false, opacity: 0}, 1000, "ease", function() {
setTimeout(function() {
$(".blinds.left").removeClass("full");
$(".blinds.right").show();
$(".blinds.right").transition({queue: false, right: "-50%"}, 1000, "ease");
$(".blinds.left").transition({queue: false, left: "-50%"}, 1000, "ease", callback);
$("#sponsor").hide();
}, 200);
});
};
var transitionLogoToSponsor = function(callback) {
$(".blindsCenter.full").transition({queue: false, rotateY: "90deg"}, 750, "ease", function () {
$("#sponsor").show();
$("#sponsor").transition({queue: false, opacity: 1}, 1000, "ease", callback);
});
};
var transitionSponsorToLogo = function(callback) {
$("#sponsor").transition({queue: false, opacity: 0}, 1000, "ease", function() {
$(".blindsCenter.full").transition({queue: false, rotateY: "0deg"}, 750, "ease", callback);
$("#sponsor").hide();
});
};
var transitionScoreToSponsor = function(callback) {
transitionScoreToLogo(function() {
transitionLogoToSponsor(callback);
});
};
var transitionSponsorToScore = function(callback) {
transitionSponsorToLogo(function() {
transitionLogoToScore(callback);
});
};
// Loads sponsor slide data and builds the slideshow HTML.
var initializeSponsorDisplay = function() {
2014-08-25 20:55:58 -07:00
$.getJSON("/api/sponsor_slides", function(sponsors) {
2014-08-25 20:55:58 -07:00
// Populate Tiles
$.each(sponsors, function(index){
2014-08-25 20:55:58 -07:00
var active = 'active';
if(index)
active = '';
if(sponsors[index]['Image'].length)
2014-09-04 22:04:21 -07:00
$('#sponsorContainer').append('<div class="item '+active+'" data-interval="'+sponsors[index]["DisplayTimeSec"]*1000+'"><img src="/static/img/sponsors/'+sponsors[index]['Image']+'" /><h1>'+sponsors[index]['Subtitle']+'</h1></div>');
2014-08-25 20:55:58 -07:00
else
2014-09-04 22:04:21 -07:00
$('#sponsorContainer').append('<div class="item '+active+'" data-interval="'+sponsors[index]["DisplayTimeSec"]*1000+'"><h2>'+sponsors[index]['Line1']+'<br />'+sponsors[index]['Line2']+'</h2><h1>'+sponsors[index]['Subtitle']+'</h1></div>');
});
2014-08-25 20:18:37 -07:00
2014-08-25 20:55:58 -07:00
// Start Carousel
var t;
var start = $('.carousel#sponsor').find('.active').attr('data-interval');
t = setTimeout("$('.carousel#sponsor').carousel({interval: 1000});", start-1000);
2014-08-25 20:55:58 -07:00
$('.carousel#sponsor').on('slid.bs.carousel', function () {
clearTimeout(t);
var duration = $(this).find('.active').attr('data-interval');
2014-08-25 20:18:37 -07:00
2014-08-25 20:55:58 -07:00
$('.carousel#sponsor').carousel('pause');
t = setTimeout("$('.carousel#sponsor').carousel();", duration-1000);
})
$('.carousel-control.right').on('click', function(){
clearTimeout(t);
});
$('.carousel-control.left').on('click', function(){
clearTimeout(t);
});
});
}
2014-08-02 19:43:45 -07:00
$(function() {
// Set up the websocket back to the server.
websocket = new CheesyWebsocket("/displays/audience/websocket", {
setAudienceDisplay: function(event) { handleSetAudienceDisplay(event.data); },
setMatch: function(event) { handleSetMatch(event.data); },
matchTiming: function(event) { handleMatchTiming(event.data); },
matchTime: function(event) { handleMatchTime(event.data); },
realtimeScore: function(event) { handleRealtimeScore(event.data); },
setFinalScore: function(event) { handleSetFinalScore(event.data); },
playSound: function(event) { handlePlaySound(event.data); },
2014-08-15 20:13:02 -07:00
allianceSelection: function(event) { handleAllianceSelection(event.data); },
lowerThird: function(event) { handleLowerThird(event.data); }
2014-08-02 19:43:45 -07:00
});
initializeSponsorDisplay();
2014-08-02 19:43:45 -07:00
// Map how to transition from one screen to another. Missing links between screens indicate that first we
// must transition to the blank screen and then to the target screen.
transitionMap = {
blank: {
intro: transitionBlankToIntro,
match: transitionBlankToInMatch,
score: transitionBlankToScore,
logo: transitionBlankToLogo,
sponsor: transitionBlankToSponsor,
2014-08-15 20:13:02 -07:00
allianceSelection: transitionBlankToAllianceSelection,
lowerThird: transitionBlankToLowerThird
2014-08-02 19:43:45 -07:00
},
intro: {
blank: transitionIntroToBlank,
match: transitionIntroToInMatch
},
match: {
blank: transitionInMatchToBlank,
intro: transitionInMatchToIntro
},
score: {
blank: transitionScoreToBlank,
logo: transitionScoreToLogo,
sponsor: transitionScoreToSponsor
2014-08-02 19:43:45 -07:00
},
logo: {
blank: transitionLogoToBlank,
score: transitionLogoToScore,
sponsor: transitionLogoToSponsor
},
sponsor: {
blank: transitionSponsorToBlank,
logo: transitionSponsorToLogo,
score: transitionSponsorToScore
},
allianceSelection: {
blank: transitionAllianceSelectionToBlank
2014-08-15 20:13:02 -07:00
},
lowerThird: {
blank: transitionLowerThirdToBlank
2014-08-02 19:43:45 -07:00
}
}
});