mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Remove game-specific scoring
This commit is contained in:
63
static/js/match_play.js
Normal file → Executable file
63
static/js/match_play.js
Normal file → Executable file
@@ -5,7 +5,6 @@
|
||||
|
||||
var websocket;
|
||||
var currentMatchId;
|
||||
var scoreIsReady;
|
||||
var lowBatteryThreshold = 8;
|
||||
|
||||
// Sends a websocket message to load a team into an alliance station.
|
||||
@@ -59,11 +58,22 @@ var startTimeout = function() {
|
||||
websocket.send("startTimeout", durationSec);
|
||||
};
|
||||
|
||||
// Sends a websocket message to update the realtime score
|
||||
var updateRealtimeScore = function() {
|
||||
websocket.send("updateRealtimeScore", {
|
||||
blueAuto: parseInt($("#blueAutoScore").val()),
|
||||
redAuto: parseInt($("#redAutoScore").val()),
|
||||
blueTeleop: parseInt($("#blueTeleopScore").val()),
|
||||
redTeleop: parseInt($("#redTeleopScore").val()),
|
||||
blueEndgame: parseInt($("#blueEndgameScore").val()),
|
||||
redEndgame: parseInt($("#redEndgameScore").val())
|
||||
})
|
||||
};
|
||||
|
||||
var confirmCommit = function(isReplay) {
|
||||
if (isReplay || !scoreIsReady) {
|
||||
if (isReplay) {
|
||||
// Show the appropriate message(s) in the confirmation dialog.
|
||||
$("#confirmCommitReplay").css("display", isReplay ? "block" : "none");
|
||||
$("#confirmCommitNotReady").css("display", scoreIsReady ? "none" : "block");
|
||||
$("#confirmCommitResults").modal("show");
|
||||
} else {
|
||||
commitResults();
|
||||
@@ -140,6 +150,18 @@ var handleArenaStatus = function(data) {
|
||||
$("#discardResults").prop("disabled", true);
|
||||
$("#editResults").prop("disabled", true);
|
||||
$("#startTimeout").prop("disabled", false);
|
||||
$("#blueAutoScore").val("0");
|
||||
$("#redAutoScore").val("0");
|
||||
$("#blueTeleopScore").val("0");
|
||||
$("#redTeleopScore").val("0");
|
||||
$("#blueEndgameScore").val("0");
|
||||
$("#redEndgameScore").val("0");
|
||||
$("#blueAutoScore").prop("disabled", true);
|
||||
$("#redAutoScore").prop("disabled", true);
|
||||
$("#blueTeleopScore").prop("disabled", true);
|
||||
$("#redTeleopScore").prop("disabled", true);
|
||||
$("#blueEndgameScore").prop("disabled", true);
|
||||
$("#redEndgameScore").prop("disabled", true);
|
||||
break;
|
||||
case "START_MATCH":
|
||||
case "WARMUP_PERIOD":
|
||||
@@ -152,6 +174,12 @@ var handleArenaStatus = function(data) {
|
||||
$("#discardResults").prop("disabled", true);
|
||||
$("#editResults").prop("disabled", true);
|
||||
$("#startTimeout").prop("disabled", true);
|
||||
$("#blueAutoScore").prop("disabled", false);
|
||||
$("#redAutoScore").prop("disabled", false);
|
||||
$("#blueTeleopScore").prop("disabled", false);
|
||||
$("#redTeleopScore").prop("disabled", false);
|
||||
$("#blueEndgameScore").prop("disabled", false);
|
||||
$("#redEndgameScore").prop("disabled", false);
|
||||
break;
|
||||
case "POST_MATCH":
|
||||
$("#startMatch").prop("disabled", true);
|
||||
@@ -160,6 +188,12 @@ var handleArenaStatus = function(data) {
|
||||
$("#discardResults").prop("disabled", false);
|
||||
$("#editResults").prop("disabled", false);
|
||||
$("#startTimeout").prop("disabled", true);
|
||||
$("#blueAutoScore").prop("disabled", false);
|
||||
$("#redAutoScore").prop("disabled", false);
|
||||
$("#blueTeleopScore").prop("disabled", false);
|
||||
$("#redTeleopScore").prop("disabled", false);
|
||||
$("#blueEndgameScore").prop("disabled", false);
|
||||
$("#redEndgameScore").prop("disabled", false);
|
||||
break;
|
||||
case "TIMEOUT_ACTIVE":
|
||||
$("#startMatch").prop("disabled", true);
|
||||
@@ -168,6 +202,12 @@ var handleArenaStatus = function(data) {
|
||||
$("#discardResults").prop("disabled", true);
|
||||
$("#editResults").prop("disabled", true);
|
||||
$("#startTimeout").prop("disabled", true);
|
||||
$("#blueAutoScore").prop("disabled", false);
|
||||
$("#redAutoScore").prop("disabled", false);
|
||||
$("#blueTeleopScore").prop("disabled", false);
|
||||
$("#redTeleopScore").prop("disabled", false);
|
||||
$("#blueEndgameScore").prop("disabled", false);
|
||||
$("#redEndgameScore").prop("disabled", false);
|
||||
break;
|
||||
case "POST_TIMEOUT":
|
||||
$("#startMatch").prop("disabled", true);
|
||||
@@ -176,6 +216,12 @@ var handleArenaStatus = function(data) {
|
||||
$("#discardResults").prop("disabled", true);
|
||||
$("#editResults").prop("disabled", true);
|
||||
$("#startTimeout").prop("disabled", true);
|
||||
$("#blueAutoScore").prop("disabled", false);
|
||||
$("#redAutoScore").prop("disabled", false);
|
||||
$("#blueTeleopScore").prop("disabled", false);
|
||||
$("#redTeleopScore").prop("disabled", false);
|
||||
$("#blueEndgameScore").prop("disabled", false);
|
||||
$("#redEndgameScore").prop("disabled", false);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -212,16 +258,6 @@ var handleAudienceDisplayMode = function(data) {
|
||||
$("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);
|
||||
$("#redScoreStatus").text("Red Scoring " + data.NumRedScoringPanelsReady + "/" + data.NumRedScoringPanels);
|
||||
$("#redScoreStatus").attr("data-ready", data.RedScoreReady);
|
||||
$("#blueScoreStatus").text("Blue Scoring " + data.NumBlueScoringPanelsReady + "/" + data.NumBlueScoringPanels);
|
||||
$("#blueScoreStatus").attr("data-ready", data.BlueScoreReady);
|
||||
};
|
||||
|
||||
// Handles a websocket message to update the alliance station display screen selector.
|
||||
var handleAllianceStationDisplayMode = function(data) {
|
||||
$("input[name=allianceStationDisplay]:checked").prop("checked", false);
|
||||
@@ -251,6 +287,5 @@ $(function() {
|
||||
matchTime: function(event) { handleMatchTime(event.data); },
|
||||
matchTiming: function(event) { handleMatchTiming(event.data); },
|
||||
realtimeScore: function(event) { handleRealtimeScore(event.data); },
|
||||
scoringStatus: function(event) { handleScoringStatus(event.data); },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,14 +13,10 @@ $("form").submit(function() {
|
||||
|
||||
var redScoreJson = JSON.stringify(allianceResults["red"].score);
|
||||
var blueScoreJson = JSON.stringify(allianceResults["blue"].score);
|
||||
var redCardsJson = JSON.stringify(allianceResults["red"].cards);
|
||||
var blueCardsJson = JSON.stringify(allianceResults["blue"].cards);
|
||||
|
||||
// Inject the JSON data into the form as hidden inputs.
|
||||
$("<input />").attr("type", "hidden").attr("name", "redScoreJson").attr("value", redScoreJson).appendTo("form");
|
||||
$("<input />").attr("type", "hidden").attr("name", "blueScoreJson").attr("value", blueScoreJson).appendTo("form");
|
||||
$("<input />").attr("type", "hidden").attr("name", "redCardsJson").attr("value", redCardsJson).appendTo("form");
|
||||
$("<input />").attr("type", "hidden").attr("name", "blueCardsJson").attr("value", blueCardsJson).appendTo("form");
|
||||
|
||||
return true;
|
||||
});
|
||||
@@ -31,41 +27,9 @@ var renderResults = function(alliance) {
|
||||
var scoreContent = scoreTemplate(result);
|
||||
$("#" + alliance + "Score").html(scoreContent);
|
||||
|
||||
// Set the values of the form fields from the JSON results data.
|
||||
for (var i = 0; i < 4; i++) {
|
||||
var i1 = i + 1;
|
||||
|
||||
if (i < 2) {
|
||||
getInputElement(alliance, "AutoCellsBottom" + i1).val(result.score.AutoCellsBottom[i]);
|
||||
getInputElement(alliance, "AutoCellsOuter" + i1).val(result.score.AutoCellsOuter[i]);
|
||||
getInputElement(alliance, "AutoCellsInner" + i1).val(result.score.AutoCellsInner[i]);
|
||||
}
|
||||
|
||||
if (i < 3) {
|
||||
getInputElement(alliance, "ExitedInitiationLine" + i1).prop("checked", result.score.ExitedInitiationLine[i]);
|
||||
getInputElement(alliance, "EndgameStatuses" + i1, result.score.EndgameStatuses[i]).prop("checked", true);
|
||||
}
|
||||
|
||||
getInputElement(alliance, "TeleopCellsBottom" + i1).val(result.score.TeleopCellsBottom[i]);
|
||||
getInputElement(alliance, "TeleopCellsOuter" + i1).val(result.score.TeleopCellsOuter[i]);
|
||||
getInputElement(alliance, "TeleopCellsInner" + i1).val(result.score.TeleopCellsInner[i]);
|
||||
}
|
||||
getInputElement(alliance, "ControlPanelStatus", result.score.ControlPanelStatus).prop("checked", true);
|
||||
getInputElement(alliance, "RungIsLevel").prop("checked", result.score.RungIsLevel);
|
||||
|
||||
if (result.score.Fouls != null) {
|
||||
$.each(result.score.Fouls, function(k, v) {
|
||||
getInputElement(alliance, "Foul" + k + "Team", v.TeamId).prop("checked", true);
|
||||
getSelectElement(alliance, "Foul" + k + "RuleId").val(v.RuleId);
|
||||
getInputElement(alliance, "Foul" + k + "Time").val(v.TimeInMatchSec);
|
||||
});
|
||||
}
|
||||
|
||||
if (result.cards != null) {
|
||||
$.each(result.cards, function(k, v) {
|
||||
getInputElement(alliance, "Team" + k + "Card", v).prop("checked", true);
|
||||
});
|
||||
}
|
||||
getInputElement(alliance, "AutoPoints").val(result.score.AutoPoints);
|
||||
getInputElement(alliance, "TeleopPoints").val(result.score.TeleopPoints);
|
||||
getInputElement(alliance, "EndgamePoints").val(result.score.EndgamePoints);
|
||||
};
|
||||
|
||||
// Converts the current form values back into JSON structures and caches them.
|
||||
@@ -76,63 +40,9 @@ var updateResults = function(alliance) {
|
||||
formData[v.name] = v.value;
|
||||
});
|
||||
|
||||
result.score.ExitedInitiationLine = [];
|
||||
result.score.AutoCellsBottom = [];
|
||||
result.score.AutoCellsOuter = [];
|
||||
result.score.AutoCellsInner = [];
|
||||
result.score.TeleopCellsBottom = [];
|
||||
result.score.TeleopCellsOuter = [];
|
||||
result.score.TeleopCellsInner = [];
|
||||
result.score.EndgameStatuses = [];
|
||||
for (var i = 0; i < 4; i++) {
|
||||
var i1 = i + 1;
|
||||
|
||||
if (i < 2) {
|
||||
result.score.AutoCellsBottom[i] = parseInt(formData[alliance + "AutoCellsBottom" + i1]);
|
||||
result.score.AutoCellsOuter[i] = parseInt(formData[alliance + "AutoCellsOuter" + i1]);
|
||||
result.score.AutoCellsInner[i] = parseInt(formData[alliance + "AutoCellsInner" + i1]);
|
||||
}
|
||||
|
||||
if (i < 3) {
|
||||
result.score.ExitedInitiationLine[i] = formData[alliance + "ExitedInitiationLine" + i1] === "on";
|
||||
result.score.EndgameStatuses[i] = parseInt(formData[alliance + "EndgameStatuses" + i1]);
|
||||
}
|
||||
|
||||
result.score.TeleopCellsBottom[i] = parseInt(formData[alliance + "TeleopCellsBottom" + i1]);
|
||||
result.score.TeleopCellsOuter[i] = parseInt(formData[alliance + "TeleopCellsOuter" + i1]);
|
||||
result.score.TeleopCellsInner[i] = parseInt(formData[alliance + "TeleopCellsInner" + i1]);
|
||||
}
|
||||
result.score.ControlPanelStatus = parseInt(formData[alliance + "ControlPanelStatus"]);
|
||||
result.score.RungIsLevel = formData[alliance + "RungIsLevel"] === "on";
|
||||
|
||||
result.score.Fouls = [];
|
||||
for (var i = 0; formData[alliance + "Foul" + i + "Time"]; i++) {
|
||||
var prefix = alliance + "Foul" + i;
|
||||
var foul = {TeamId: parseInt(formData[prefix + "Team"]), RuleId: parseInt(formData[prefix + "RuleId"]),
|
||||
TimeInMatchSec: parseFloat(formData[prefix + "Time"])};
|
||||
result.score.Fouls.push(foul);
|
||||
}
|
||||
|
||||
result.cards = {};
|
||||
$.each([result.team1, result.team2, result.team3], function(i, team) {
|
||||
result.cards[team] = formData[alliance + "Team" + team + "Card"];
|
||||
});
|
||||
};
|
||||
|
||||
// Appends a blank foul to the end of the list.
|
||||
var addFoul = function(alliance) {
|
||||
updateResults(alliance);
|
||||
var result = allianceResults[alliance];
|
||||
result.score.Fouls.push({TeamId: 0, Rule: "", TimeInMatchSec: 0});
|
||||
renderResults(alliance);
|
||||
};
|
||||
|
||||
// Removes the given foul from the list.
|
||||
var deleteFoul = function(alliance, index) {
|
||||
updateResults(alliance);
|
||||
var result = allianceResults[alliance];
|
||||
result.score.Fouls.splice(index, 1);
|
||||
renderResults(alliance);
|
||||
result.score.AutoPoints = parseInt(formData[alliance + "AutoPoints"]);
|
||||
result.score.TeleopPoints = parseInt(formData[alliance + "TeleopPoints"]);
|
||||
result.score.EndgamePoints = parseInt(formData[alliance + "EndgamePoints"]);
|
||||
};
|
||||
|
||||
// Returns the form input element having the given parameters.
|
||||
@@ -143,9 +53,3 @@ var getInputElement = function(alliance, name, value) {
|
||||
}
|
||||
return $(selector);
|
||||
};
|
||||
|
||||
// Returns the form select element having the given parameters.
|
||||
var getSelectElement = function(alliance, name) {
|
||||
var selector = "select[name=" + alliance + name + "]";
|
||||
return $(selector);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user