Update scoring panel for 2020.

This commit is contained in:
Patrick Fairbank
2020-03-21 23:32:28 -07:00
parent fd84cdcd73
commit 93cbce7aa1
6 changed files with 318 additions and 414 deletions

View File

@@ -190,7 +190,7 @@ func (score *Score) CellCountingStage(teleopStarted bool) Stage {
} }
// Returns true if the preconditions are satisfied for the given Stage to be activated. // Returns true if the preconditions are satisfied for the given Stage to be activated.
func (score *Score) stageAtCapacity(stage Stage, teleopStarted bool) bool { func (score *Score) StageAtCapacity(stage Stage, teleopStarted bool) bool {
if stage > Stage1 && !score.stageActivated(stage-1, teleopStarted) { if stage > Stage1 && !score.stageActivated(stage-1, teleopStarted) {
return false return false
} }
@@ -202,7 +202,7 @@ func (score *Score) stageAtCapacity(stage Stage, teleopStarted bool) bool {
// Returns true if the given Stage has been activated. // Returns true if the given Stage has been activated.
func (score *Score) stageActivated(stage Stage, teleopStarted bool) bool { func (score *Score) stageActivated(stage Stage, teleopStarted bool) bool {
if score.stageAtCapacity(stage, teleopStarted) { if score.StageAtCapacity(stage, teleopStarted) {
switch stage { switch stage {
case Stage1: case Stage1:
return teleopStarted return teleopStarted

View File

@@ -12,27 +12,45 @@ body {
background-color: #222; background-color: #222;
} }
.container { .container {
padding-top: 2vw;
width: 100%; width: 100%;
height: 100%; height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: flex-start;
align-items: center; align-items: center;
} }
#alliance {
width: 90%;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
border-radius: 25px;
border: 1px solid #333;
}
#alliance[data-alliance="red"] {
background-color: #322;
}
#alliance[data-alliance="blue"] {
background-color: #223;
}
#matchName { #matchName {
font-size: 2vw; font-size: 2vw;
} }
#robots { .scoring-section {
margin-bottom: 0.5vw; margin-bottom: 0.5vw;
display: flex; display: flex;
font-size: 1.5vw; font-size: 1.5vw;
color: #ccc; color: #ccc;
} }
#robotHeader { .scoring-header>div{
margin-right: 1vw; height: 2.5vw;
margin: 0.4vw 1vw 0.4vw 0.2vw;
color: #666; color: #666;
} }
.robot-field { .robot-field {
min-width: 12vw; width: 17vw;
height: 2.5vw; height: 2.5vw;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
@@ -42,180 +60,91 @@ body {
.team { .team {
display: flex; display: flex;
justify-content: center; justify-content: center;
font-weight: bold;
} }
.robot-start-level[data-value="0"] { .boolean[data-value="false"] {
background-color: #633;
}
.robot-start-level[data-value="1"] {
background-color: #236;
}
.robot-start-level[data-value="2"] {
background-color: #263;
}
.robot-start-level[data-value="3"] {
background-color: #850;
}
.sandstorm-bonus[data-value="false"] {
background-color: #333; background-color: #333;
} }
.sandstorm-bonus[data-value="true"] { .boolean[data-value="true"] {
background-color: #263; background-color: #263;
} }
.robot-end-level[data-value="0"] { .endgame-status[data-value="0"] {
background-color: #333; background-color: #333;
} }
.robot-end-level[data-value="1"] { .endgame-status[data-value="1"] {
background-color: #236; background-color: #236;
} }
.robot-end-level[data-value="2"] { .endgame-status[data-value="2"] {
background-color: #224d4d;
}
.robot-end-level[data-value="3"] {
background-color: #263; background-color: #263;
} }
.robot-shortcut { .control-panel[data-value="disabled"] {
width: 2vw; background-color: #333;
}
.control-panel[data-value="false"] {
background-color: #236;
}
.control-panel[data-value="true"] {
background-color: #263;
}
.shortcut {
margin: 0 0.2vw; margin: 0 0.2vw;
font-size: 1vw; font-size: 1vw;
align-self: flex-start; align-self: flex-start;
} }
.team { #elements {
font-weight: bold;
}
#scoringElements {
width: 100%; width: 100%;
height: 100%; display: flex;
justify-content: space-evenly;
align-items: center;
}
.goal-header {
height: 5vw;
margin: 0.4vw 0vw;
color: #666;
display: flex;
flex-direction: column;
justify-content: center;
}
.goal-period {
text-align: center;
color: #666;
}
.goal {
width: 13vw;
height: 5vw;
margin: 0.4vw 3vw;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
}
.rocket {
display: flex;
align-items: flex-end;
}
.rocket-outline {
display: flex;
align-items: flex-end;
padding: 5vw 2vw 1vw 2vw;
border: 1px solid #222;
border-radius: 40% 40% 0% 0%;
}
.alliance-color[data-alliance="red"] {
background-color: #633;
}
.alliance-color[data-alliance="blue"] {
background-color: #236;
}
.outer-rocket {
height: 26vw;
margin: 0.2vw;
}
.inner-rocket {
margin: 0.2vw;
}
#centerColumn {
display: flex;
flex-direction: column;
align-items: center; align-items: center;
} }
#cargoShipContainer { .number-button {
display: flex; width: 4vw;
flex-direction: column; height: 4vw;
align-items: center;
}
#cargoShip {
display: flex;
flex-direction: column;
align-items: center;
padding: 1vw;
border: 1px solid #222;
border-radius: 10%;
}
.cargo-ship-side {
width: 25vw;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center;
border: 1px solid #666;
border-radius: 0.5vw;
font-size: 3vw;
} }
.cargo-ship-front { .plus {
display: flex; background: #263;
} }
.bay { .minus {
position: relative; background: #633;
width: 7vw;
height: 7vw;
margin: 0.2vw;
border: 1px solid #222;
background-color: #666;
border-radius: 10%;
}
.bay[data-value="0"] .hatch-panel {
display: none;
}
.bay[data-value="1"] .hatch-panel {
display: flex;
}
.bay[data-value="2"] .hatch-panel {
display: flex;
}
.bay[data-value="3"] .hatch-panel {
display: none;
}
.bay[data-value="0"] .cargo {
display: none;
}
.bay[data-value="1"] .cargo {
display: none;
}
.bay[data-value="2"] .cargo {
display: flex;
}
.bay[data-value="3"] .cargo {
display: flex;
}
.shortcut {
position: absolute;
left: 0.3vw;
top: -0.1vw;
font-size: 1.2vw;
color: #fff
}
.hatch-panel {
width: 6vw;
height: 6vw;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: none;
margin: auto auto;
border: 1vw solid #c80;
border-radius: 50%;
}
.cargo {
width: 3vw;
height: 3vw;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: none;
margin: auto auto;
background-color: #c50;
border-radius: 50%;
} }
#instructions { #instructions {
margin-top: 0.3vw; margin-top: 0.3vw;
} }
#preMatchMessage, #postMatchMessage { #postMatchMessage {
height: 100%; height: 5vw;
display: none; display: none;
align-items: center; align-items: center;
font-size: 1.5vw; font-size: 1.5vw;
color: #c90; color: #c90;
} }
#commitMatchScore { #commitMatchScore {
height: 100%; height: 5vw;
display: none; display: none;
align-items: center; align-items: center;
} }

View File

@@ -29,31 +29,44 @@ var handleRealtimeScore = function(data) {
realtimeScore = data.Blue; realtimeScore = data.Blue;
} }
var score = realtimeScore.Score; var score = realtimeScore.Score;
var summary = realtimeScore.ScoreSummary;
for (var i = 0; i < 3; i++) { for (var i = 0; i < 3; i++) {
var i1 = i + 1; var i1 = i + 1;
$("#robotStartLevel" + i1 + ">.value").text(getRobotStartLevelText(score.RobotStartLevels[i])); $("#exitedInitiationLine" + i1 + ">.value").text(score.ExitedInitiationLine[i] ? "Yes" : "No");
$("#robotStartLevel" + i1).attr("data-value", score.RobotStartLevels[i]); $("#exitedInitiationLine" + i1).attr("data-value", score.ExitedInitiationLine[i]);
$("#sandstormBonus" + i1 + ">.value").text(score.SandstormBonuses[i] ? "Yes" : "No"); $("#endgameStatus" + i1 + ">.value").text(getEndgameStatusText(score.EndgameStatuses[i]));
$("#sandstormBonus" + i1).attr("data-value", score.SandstormBonuses[i]); $("#endgameStatus" + i1).attr("data-value", score.EndgameStatuses[i]);
$("#robotEndLevel" + i1 + ">.value").text(getRobotEndLevelText(score.RobotEndLevels[i])); setGoalValue($("#autoCellsInner"), score.AutoCellsInner);
$("#robotEndLevel" + i1).attr("data-value", score.RobotEndLevels[i]); setGoalValue($("#autoCellsOuter"), score.AutoCellsOuter);
getBay("rocketNearLeft", i).attr("data-value", score.RocketNearLeftBays[i]); setGoalValue($("#autoCellsBottom"), score.AutoCellsBottom);
getBay("rocketNearRight", i).attr("data-value", score.RocketNearRightBays[i]); setGoalValue($("#teleopCellsInner"), score.TeleopCellsInner);
getBay("rocketFarLeft", i).attr("data-value", score.RocketFarLeftBays[i]); setGoalValue($("#teleopCellsOuter"), score.TeleopCellsOuter);
getBay("rocketFarRight", i).attr("data-value", score.RocketFarRightBays[i]); setGoalValue($("#teleopCellsBottom"), score.TeleopCellsBottom);
}
for (var i = 0; i < 8; i++) {
getBay("cargoShip", i).attr("data-value", score.CargoBays[i]);
} }
if (matchStates[data.MatchState] === "PRE_MATCH") { if (score.ControlPanelStatus >= 1) {
if (realtimeScore.IsPreMatchScoreReady) { $("#rotationControl>.value").text("Yes");
$("#preMatchMessage").hide(); $("#rotationControl").attr("data-value", true);
} else { } else if (summary.StagePowerCellsRemaining[1] === 0) {
$("#preMatchMessage").css("display", "flex"); $("#rotationControl>.value").text("Unlocked");
} $("#rotationControl").attr("data-value", false);
} else {
$("#rotationControl>.value").text("Disabled (" + summary.StagePowerCellsRemaining[1] + " left)");
$("#rotationControl").attr("data-value", "disabled");
} }
if (score.ControlPanelStatus === 2) {
$("#positionControl>.value").text("Yes");
$("#positionControl").attr("data-value", true);
} else if (summary.StagePowerCellsRemaining[2] === 0) {
$("#positionControl>.value").text("Unlocked");
$("#positionControl").attr("data-value", false);
} else {
$("#positionControl>.value").text("Disabled (" + summary.StagePowerCellsRemaining[2] + " left)");
$("#positionControl").attr("data-value", "disabled");
}
$("#rungIsLevel>.value").text(score.RungIsLevel ? "Yes" : "No");
$("#rungIsLevel").attr("data-value", score.RungIsLevel);
}; };
// Handles a websocket message to update the match status. // Handles a websocket message to update the match status.
@@ -93,42 +106,30 @@ var commitMatchScore = function() {
$("#commitMatchScore").hide(); $("#commitMatchScore").hide();
}; };
// Returns the display text corresponding to the given integer start level value. // Returns the display text corresponding to the given integer endgame status value.
var getRobotStartLevelText = function(level) { var getEndgameStatusText = function(level) {
switch (level) { switch (level) {
case 1: case 1:
return "1"; return "Park";
case 2: case 2:
return "2"; return "Hang";
case 3:
return "No-Show";
default: default:
return " "; return "None";
} }
}; };
// Returns the display text corresponding to the given integer end level value. // Updates the power cell count for a goal, given the element and score values.
var getRobotEndLevelText = function(level) { var setGoalValue = function(element, powerCells) {
switch (level) { var total = 0;
case 1: $.each(powerCells, function(k, v) {
return "1"; total += v;
case 2: });
return "2"; element.text(total);
case 3:
return "3";
default:
return "Not On";
}
}; };
// Returns the bay element matching the given parameters.
var getBay = function(type, index) {
return $("#bay" + bayMappings[type][index]);
}
$(function() { $(function() {
alliance = window.location.href.split("/").slice(-1)[0]; alliance = window.location.href.split("/").slice(-1)[0];
$(".alliance-color").attr("data-alliance", alliance); $("#alliance").attr("data-alliance", alliance);
// Set up the websocket back to the server. // Set up the websocket back to the server.
websocket = new CheesyWebsocket("/panels/scoring/" + alliance + "/websocket", { websocket = new CheesyWebsocket("/panels/scoring/" + alliance + "/websocket", {

View File

@@ -7,74 +7,85 @@
{{define "title"}}Scoring Panel{{end}} {{define "title"}}Scoring Panel{{end}}
{{define "body"}} {{define "body"}}
<div id="matchName">&nbsp;</div> <div id="matchName">&nbsp;</div>
<div id="robots"> <div id="alliance">
<div id="robotHeader"> <div class="scoring-section">
<div class="robot-field">&nbsp;</div> <div class="scoring-header">
<div class="robot-field">Start Hab Level</div> <div>&nbsp;</div>
<div class="robot-field">Sandstorm Bonus?</div> <div>Exited Initiation Line?</div>
<div class="robot-field">End Hab Level</div> <div>Endgame Status</div>
</div>
{{range $i := seq 3}}
<div>
<div id="team{{$i}}" class="team robot-field"></div>
<div id="exitedInitiationLine{{$i}}" class="boolean robot-field" onclick="handleClick('{{$i}}');">
<div class="shortcut">{{$i}}</div>
<div class="value"></div>
<div class="shortcut"></div>
</div>
<div id="endgameStatus{{$i}}" class="endgame-status robot-field" onclick="handleClick('{{add $i 3}}');">
<div class="shortcut">{{add $i 3}}</div>
<div class="value"></div>
<div class="shortcut"></div>
</div>
</div>
{{end}}
</div> </div>
{{range $i := seq 3}} {{if eq .EventSettings.PlcAddress ""}}
<div> <div id="elements">
<div id="team{{$i}}" class="team robot-field"></div> <div class="scoring-section">
<div id="robotStartLevel{{$i}}" class="robot-start-level robot-field" onclick="handleClick('{{$i}}');"> <div>
<div class="robot-shortcut">{{$i}}</div> <div>&nbsp;</div>
<div class="value"></div> <div class="goal-header">Inner</div>
<div class="robot-shortcut"></div> <div class="goal-header">Outer</div>
<div class="goal-header">Lower</div>
</div>
<div>
<div class="goal-period">Auto</div>
{{template "goal" dict "period" "auto" "level" "Inner" "plus" "W" "minus" "Q"}}
{{template "goal" dict "period" "auto" "level" "Outer" "plus" "S" "minus" "A"}}
{{template "goal" dict "period" "auto" "level" "Bottom" "plus" "X" "minus" "Z"}}
</div>
<div>
<div class="goal-period">Teleop</div>
{{template "goal" dict "period" "teleop" "level" "Inner" "plus" "R" "minus" "E"}}
{{template "goal" dict "period" "teleop" "level" "Outer" "plus" "F" "minus" "D"}}
{{template "goal" dict "period" "teleop" "level" "Bottom" "plus" "V" "minus" "C"}}
</div>
</div> </div>
<div id="sandstormBonus{{$i}}" class="sandstorm-bonus robot-field" onclick="handleClick('{{add $i 3}}');"> <div class="scoring-section">
<div class="robot-shortcut">{{add $i 3}}</div> <div class="scoring-header">
<div class="value"></div> <div>Rotation Control</div>
<div class="robot-shortcut"></div> <div>Position Control</div>
</div> <div>Rung Is Level</div>
<div id="robotEndLevel{{$i}}" class="robot-end-level robot-field" onclick="handleClick('{{add $i 6}}');"> </div>
<div class="robot-shortcut">{{add $i 6}}</div> <div>
<div class="value"></div> <div id="rotationControl" class="control-panel robot-field" onclick="handleClick('O');">
<div class="robot-shortcut"></div> <div class="shortcut">O</div>
<div class="value"></div>
<div class="shortcut"></div>
</div>
<div id="positionControl" class="control-panel robot-field" onclick="handleClick('P');">
<div class="shortcut">P</div>
<div class="value"></div>
<div class="shortcut"></div>
</div>
<div id="rungIsLevel" class="boolean robot-field" onclick="handleClick('L');">
<div class="shortcut">L</div>
<div class="value"></div>
<div class="shortcut"></div>
</div>
</div>
</div> </div>
</div> </div>
{{end}} {{end}}
</div> </div>
<div id="scoringElements"> <div id="instructions">Click or use the labeled keyboard shortcuts to toggle each element</div>
<div class="rocket"> <div id="commitMatchScore">
<div class="rocket-outline alliance-color"> <button type="button" class="btn btn-info" onclick="commitMatchScore();">
<div class="outer-rocket">{{template "rocketHalf" dict "startBayId" 0 "vars" $}}</div> Commit Final Match Score
<div class="inner-rocket">{{template "rocketHalf" dict "startBayId" 3 "vars" $}}</div> </button>
</div>
</div>
<div id="centerColumn">
<div id="cargoShipContainer">
<div id="cargoShip" class="alliance-color">
<div class="cargo-ship-side">
{{template "bay" dict "id" 6 "vars" $}}{{template "bay" dict "id" 13 "vars" $}}
</div>
<div class="cargo-ship-side">
{{template "bay" dict "id" 7 "vars" $}}{{template "bay" dict "id" 12 "vars" $}}
</div>
<div class="cargo-ship-side">
{{template "bay" dict "id" 8 "vars" $}}{{template "bay" dict "id" 11 "vars" $}}
</div>
<div class="cargo-ship-front">
{{template "bay" dict "id" 9 "vars" $}}{{template "bay" dict "id" 10 "vars" $}}
</div>
</div>
</div>
<div id="instructions">Click or use the labeled keyboard shortcuts to toggle each element</div>
<div id="preMatchMessage">Set pre-match state of robots and cargo ship</div>
<div id="commitMatchScore">
<button type="button" class="btn btn-success" onclick="commitMatchScore();">
Commit Final Match Score
</button>
</div>
<div id="postMatchMessage">Waiting for the next match...</div>
</div>
<div class="rocket">
<div class="rocket-outline alliance-color">
<div class="inner-rocket">{{template "rocketHalf" dict "startBayId" 14 "vars" $}}</div>
<div class="outer-rocket">{{template "rocketHalf" dict "startBayId" 17 "vars" $}}</div>
</div>
</div>
</div> </div>
<div id="postMatchMessage">Waiting for the next match...</div>
{{end}} {{end}}
{{define "head"}} {{define "head"}}
<link href="/static/css/scoring_panel.css" rel="stylesheet"> <link href="/static/css/scoring_panel.css" rel="stylesheet">
@@ -82,27 +93,15 @@
{{define "script"}} {{define "script"}}
<script src="/static/js/match_timing.js"></script> <script src="/static/js/match_timing.js"></script>
<script src="/static/js/scoring_panel.js"></script> <script src="/static/js/scoring_panel.js"></script>
<script>
var bayMappings = {"cargoShip": [], "rocketNearLeft": [], "rocketNearRight": [], "rocketFarLeft": [],
"rocketFarRight": []};
{{range $mapping := .BayMappings}}
{{if eq $.Alliance "red"}}
bayMappings["{{$mapping.RedElement}}"][{{$mapping.RedIndex}}] = {{$mapping.BayId}};
{{else}}
bayMappings["{{$mapping.BlueElement}}"][{{$mapping.BlueIndex}}] = {{$mapping.BayId}};
{{end}}
{{end}}
</script>
{{end}} {{end}}
{{define "rocketHalf"}} {{define "goal"}}
{{template "bay" dict "id" .startBayId "vars" .vars}} <div class="goal">
{{template "bay" dict "id" (add .startBayId 1) "vars" .vars}} <div class="number-button minus" onclick="handleClick('{{.minus}}');">
{{template "bay" dict "id" (add .startBayId 2) "vars" .vars}} <div class="shortcut">{{.minus}}</div>-<div class="shortcut" style="opacity: 0;">{{.minus}}</div>
{{end}}
{{define "bay"}}
<div id="bay{{.id}}" class="bay" onclick="handleClick('{{(index .vars.BayMappings .id).Shortcut}}');">
<div class="shortcut">{{(index .vars.BayMappings .id).Shortcut}}</div>
<div class="hatch-panel"></div>
<div class="cargo"></div>
</div> </div>
<div id="{{.period}}Cells{{.level}}"></div>
<div class="number-button plus" onclick="handleClick('{{.plus}}');">
<div class="shortcut">{{.plus}}</div>+<div class="shortcut" style="opacity: 0;">{{.plus}}</div>
</div>
</div>
{{end}} {{end}}

View File

@@ -8,6 +8,7 @@ package web
import ( import (
"fmt" "fmt"
"github.com/Team254/cheesy-arena/field" "github.com/Team254/cheesy-arena/field"
"github.com/Team254/cheesy-arena/game"
"github.com/Team254/cheesy-arena/model" "github.com/Team254/cheesy-arena/model"
"github.com/Team254/cheesy-arena/websocket" "github.com/Team254/cheesy-arena/websocket"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@@ -15,41 +16,9 @@ import (
"log" "log"
"net/http" "net/http"
"strconv" "strconv"
"strings"
) )
// Maps a numbered bay on the scoring panel to the field that it represents in the Score model.
type bayMapping struct {
BayId int
Shortcut string
RedElement string
RedIndex int
BlueElement string
BlueIndex int
}
var bayMappings = []*bayMapping{
{0, "q", "rocketNearRight", 2, "rocketFarRight", 2},
{1, "a", "rocketNearRight", 1, "rocketFarRight", 1},
{2, "z", "rocketNearRight", 0, "rocketFarRight", 0},
{3, "w", "rocketNearLeft", 2, "rocketFarLeft", 2},
{4, "s", "rocketNearLeft", 1, "rocketFarLeft", 1},
{5, "x", "rocketNearLeft", 0, "rocketFarLeft", 0},
{6, "e", "cargoShip", 0, "cargoShip", 7},
{7, "d", "cargoShip", 1, "cargoShip", 6},
{8, "c", "cargoShip", 2, "cargoShip", 5},
{9, "v", "cargoShip", 3, "cargoShip", 4},
{10, "b", "cargoShip", 4, "cargoShip", 3},
{11, "n", "cargoShip", 5, "cargoShip", 2},
{12, "j", "cargoShip", 6, "cargoShip", 1},
{13, "i", "cargoShip", 7, "cargoShip", 0},
{14, "o", "rocketFarRight", 2, "rocketNearRight", 2},
{15, "k", "rocketFarRight", 1, "rocketNearRight", 1},
{16, "m", "rocketFarRight", 0, "rocketNearRight", 0},
{17, "p", "rocketFarLeft", 2, "rocketNearLeft", 2},
{18, "l", "rocketFarLeft", 1, "rocketNearLeft", 1},
{19, ",", "rocketFarLeft", 0, "rocketNearLeft", 0},
}
// Renders the scoring interface which enables input of scores in real-time. // Renders the scoring interface which enables input of scores in real-time.
func (web *Web) scoringPanelHandler(w http.ResponseWriter, r *http.Request) { func (web *Web) scoringPanelHandler(w http.ResponseWriter, r *http.Request) {
if !web.userIsAdmin(w, r) { if !web.userIsAdmin(w, r) {
@@ -70,9 +39,8 @@ func (web *Web) scoringPanelHandler(w http.ResponseWriter, r *http.Request) {
} }
data := struct { data := struct {
*model.EventSettings *model.EventSettings
Alliance string Alliance string
BayMappings []*bayMapping }{web.arena.EventSettings, alliance}
}{web.arena.EventSettings, alliance, bayMappings}
err = template.ExecuteTemplate(w, "base_no_navbar", data) err = template.ExecuteTemplate(w, "base_no_navbar", data)
if err != nil { if err != nil {
handleWebErr(w, err) handleWebErr(w, err)
@@ -92,15 +60,13 @@ func (web *Web) scoringPanelWebsocketHandler(w http.ResponseWriter, r *http.Requ
handleWebErr(w, fmt.Errorf("Invalid alliance '%s'.", alliance)) handleWebErr(w, fmt.Errorf("Invalid alliance '%s'.", alliance))
return return
} }
// TODO(pat): Update for 2020.
/* var realtimeScore **field.RealtimeScore
var realtimeScore **field.RealtimeScore if alliance == "red" {
if alliance == "red" { realtimeScore = &web.arena.RedRealtimeScore
realtimeScore = &web.arena.RedRealtimeScore } else {
} else { realtimeScore = &web.arena.BlueRealtimeScore
realtimeScore = &web.arena.BlueRealtimeScore }
}
*/
ws, err := websocket.NewWebsocket(w, r) ws, err := websocket.NewWebsocket(w, r)
if err != nil { if err != nil {
@@ -129,8 +95,7 @@ func (web *Web) scoringPanelWebsocketHandler(w http.ResponseWriter, r *http.Requ
return return
} }
// TODO(pat): Update for 2020. score := &(*realtimeScore).CurrentScore
//score := &(*realtimeScore).CurrentScore
scoreChanged := false scoreChanged := false
if command == "commitMatch" { if command == "commitMatch" {
@@ -141,62 +106,99 @@ func (web *Web) scoringPanelWebsocketHandler(w http.ResponseWriter, r *http.Requ
} }
web.arena.ScoringPanelRegistry.SetScoreCommitted(alliance, ws) web.arena.ScoringPanelRegistry.SetScoreCommitted(alliance, ws)
web.arena.ScoringStatusNotifier.Notify() web.arena.ScoringStatusNotifier.Notify()
} else if number, err := strconv.Atoi(command); err == nil && number >= 1 && number <= 9 { } else if number, err := strconv.Atoi(command); err == nil && number >= 1 && number <= 6 {
// TODO(pat): Update for 2020. // Handle per-robot scoring fields.
/* if number <= 3 {
// Handle per-robot scoring fields. index := number - 1
if number <= 3 && web.arena.MatchState == field.PreMatch { score.ExitedInitiationLine[index] = !score.ExitedInitiationLine[index]
index := number - 1 scoreChanged = true
score.RobotStartLevels[index]++ } else {
if score.RobotStartLevels[index] == 4 { index := number - 4
score.RobotStartLevels[index] = 0 score.EndgameStatuses[index]++
} if score.EndgameStatuses[index] == 3 {
scoreChanged = true score.EndgameStatuses[index] = 0
} else if number > 3 && number <= 6 && web.arena.MatchState != field.PreMatch {
index := number - 4
score.SandstormBonuses[index] =
!score.SandstormBonuses[index]
scoreChanged = true
} else if number > 6 && web.arena.MatchState != field.PreMatch {
index := number - 7
score.RobotEndLevels[index]++
if score.RobotEndLevels[index] == 4 {
score.RobotEndLevels[index] = 0
}
scoreChanged = true
}
*/
} else {
// Handle cargo bays.
var bayMapping *bayMapping
for _, mapping := range bayMappings {
if mapping.Shortcut == command {
bayMapping = mapping
break
} }
scoreChanged = true
} }
if bayMapping != nil { } else {
// TODO(pat): Update for 2020. switch strings.ToUpper(command) {
/* case "Q":
element := bayMapping.RedElement if decrementGoal(score.AutoCellsInner[:],
index := bayMapping.RedIndex score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
if alliance == "blue" { scoreChanged = true
element = bayMapping.BlueElement }
index = bayMapping.BlueIndex case "A":
} if decrementGoal(score.AutoCellsOuter[:],
switch element { score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
case "cargoShip": scoreChanged = true
scoreChanged = web.toggleCargoShipBay(&score.CargoBays[index], index) }
case "rocketNearLeft": case "Z":
scoreChanged = web.toggleRocketBay(&score.RocketNearLeftBays[index]) if decrementGoal(score.AutoCellsBottom[:],
case "rocketNearRight": score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
scoreChanged = web.toggleRocketBay(&score.RocketNearRightBays[index]) scoreChanged = true
case "rocketFarLeft": }
scoreChanged = web.toggleRocketBay(&score.RocketFarLeftBays[index]) case "W":
case "rocketFarRight": if incrementGoal(score.AutoCellsInner[:],
scoreChanged = web.toggleRocketBay(&score.RocketFarRightBays[index]) score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
} scoreChanged = true
*/ }
case "S":
if incrementGoal(score.AutoCellsOuter[:],
score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
scoreChanged = true
}
case "X":
if incrementGoal(score.AutoCellsBottom[:],
score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
scoreChanged = true
}
case "E":
if decrementGoal(score.TeleopCellsInner[:],
score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
scoreChanged = true
}
case "D":
if decrementGoal(score.TeleopCellsOuter[:],
score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
scoreChanged = true
}
case "C":
if decrementGoal(score.TeleopCellsBottom[:],
score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
scoreChanged = true
}
case "R":
if incrementGoal(score.TeleopCellsInner[:],
score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
scoreChanged = true
}
case "F":
if incrementGoal(score.TeleopCellsOuter[:],
score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
scoreChanged = true
}
case "V":
if incrementGoal(score.TeleopCellsBottom[:],
score.CellCountingStage(web.arena.MatchState >= field.TeleopPeriod)) {
scoreChanged = true
}
case "O":
if score.ControlPanelStatus >= game.ControlPanelRotation {
score.ControlPanelStatus = game.ControlPanelNone
} else if score.StageAtCapacity(game.Stage2, true) {
score.ControlPanelStatus = game.ControlPanelRotation
}
scoreChanged = true
case "P":
if score.ControlPanelStatus == game.ControlPanelPosition {
score.ControlPanelStatus = game.ControlPanelRotation
} else if score.StageAtCapacity(game.Stage3, true) {
score.ControlPanelStatus = game.ControlPanelPosition
}
scoreChanged = true
case "L":
score.RungIsLevel = !score.RungIsLevel
scoreChanged = true
} }
} }
@@ -206,48 +208,20 @@ func (web *Web) scoringPanelWebsocketHandler(w http.ResponseWriter, r *http.Requ
} }
} }
// TODO(pat): Update for 2020. // Increments the power cell count for the given goal, if the preconditions are met.
/* func incrementGoal(goal []int, currentStage game.Stage) bool {
// Advances the given cargo ship bay through the states applicable to the current status of the field. if int(currentStage) < len(goal) {
func (web *Web) toggleCargoShipBay(bay *game.BayStatus, index int) bool { goal[currentStage]++
if (index == 3 || index == 4) && web.arena.MatchState == field.PreMatch { return true
// Only the side bays can be preloaded. }
return false return false
} }
if web.arena.MatchState == field.PreMatch { // Decrements the power cell count for the given goal, if the preconditions are met.
*bay++ func decrementGoal(goal []int, currentStage game.Stage) bool {
if *bay == game.BayHatchCargo { if int(currentStage) < len(goal) && goal[currentStage] > 0 {
// Skip the hatch+cargo state pre-match as it is invalid. goal[currentStage]--
*bay = game.BayCargo
} else if *bay > game.BayCargo {
*bay = game.BayEmpty
}
} else {
if *bay == game.BayCargo {
// If the bay was pre-loaded with cargo, go immediately to hatch+cargo during first toggle.
*bay = game.BayHatchCargo
} else {
*bay++
if *bay == game.BayCargo {
// Skip the cargo-only state during the match as it can't stay in on its own.
*bay = game.BayEmpty
}
}
}
return true
}
// Advances the given rocket bay through the states applicable to the current status of the field.
func (web *Web) toggleRocketBay(bay *game.BayStatus) bool {
if web.arena.MatchState != field.PreMatch {
*bay++
if *bay == game.BayCargo {
// Skip the cargo-only state as it's not applicable to rocket bays.
*bay = game.BayEmpty
}
return true return true
} }
return false return false
} }
*/

View File

@@ -189,6 +189,7 @@ func (web *Web) newHandler() http.Handler {
// Writes the given error out as plain text with a status code of 500. // Writes the given error out as plain text with a status code of 500.
func handleWebErr(w http.ResponseWriter, err error) { func handleWebErr(w http.ResponseWriter, err error) {
log.Printf("HTTP request error: %v", err)
http.Error(w, "Internal server error: "+err.Error(), 500) http.Error(w, "Internal server error: "+err.Error(), 500)
} }