Remove layer of keypress decoding in scoring display JS.

This commit is contained in:
Patrick Fairbank
2018-08-25 19:41:00 -07:00
parent e9acaf4e99
commit b49a86bdca
4 changed files with 41 additions and 40 deletions

View File

@@ -12,6 +12,7 @@ var handleScore = function(data) {
var score = data.Score.CurrentScore; var score = data.Score.CurrentScore;
$("#autoRuns").text(score.AutoRuns); $("#autoRuns").text(score.AutoRuns);
$("#climbs").text(score.Climbs); $("#climbs").text(score.Climbs);
$("#parks").text(score.Parks);
// Update component visibility. // Update component visibility.
if (!data.AutoCommitted) { if (!data.AutoCommitted) {
@@ -35,27 +36,7 @@ var handleScore = function(data) {
// Handles a keyboard event and sends the appropriate websocket message. // Handles a keyboard event and sends the appropriate websocket message.
var handleKeyPress = function(event) { var handleKeyPress = function(event) {
var key = String.fromCharCode(event.keyCode); websocket.send(String.fromCharCode(event.keyCode));
switch (key) {
case "r":
websocket.send("autoRun");
break;
case "R":
websocket.send("undoAutoRun");
break;
case "c":
websocket.send("climb");
break;
case "C":
websocket.send("undoClimb");
break;
case "\r":
websocket.send("commit");
break;
case "a":
websocket.send("uncommitAuto");
break;
}
}; };
// Handles a websocket message to update the match status. // Handles a websocket message to update the match status.

View File

@@ -43,7 +43,11 @@
<p>Use the following keyboard shortcuts:</p> <p>Use the following keyboard shortcuts:</p>
<div class="row"> <div class="row">
<div class="col-lg-3 col-lg-offset-1 scoring">c/C</div> <div class="col-lg-3 col-lg-offset-1 scoring">c/C</div>
<div class="col-lg-8 scoring-comment">Climbs +/- (ignore Levitate)</div> <div class="col-lg-8 scoring-comment">Climbs +/- (actual; disregard Levitate)</div>
</div>
<div class="row">
<div class="col-lg-3 col-lg-offset-1 scoring">p/P</div>
<div class="col-lg-8 scoring-comment">Parks +/-</div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-3 col-lg-offset-1 scoring">a</div> <div class="col-lg-3 col-lg-offset-1 scoring">a</div>
@@ -58,6 +62,10 @@
<div class="col-lg-4 col-lg-offset-1 scoring-comment">Climbs</div> <div class="col-lg-4 col-lg-offset-1 scoring-comment">Climbs</div>
<div class="col-lg-2 scoring-comment" id="climbs"></div> <div class="col-lg-2 scoring-comment" id="climbs"></div>
</div> </div>
<div class="row">
<div class="col-lg-4 col-lg-offset-1 scoring-comment">Parks</div>
<div class="col-lg-2 scoring-comment" id="parks"></div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -145,35 +145,47 @@ func (web *Web) scoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Re
} }
switch messageType { switch messageType {
case "autoRun": case "r":
if !autoCommitted { if !autoCommitted {
if (*score).CurrentScore.AutoRuns < 3 { if (*score).CurrentScore.AutoRuns < 3 {
(*score).CurrentScore.AutoRuns++ (*score).CurrentScore.AutoRuns++
} }
} }
case "undoAutoRun": case "R":
if !autoCommitted { if !autoCommitted {
if (*score).CurrentScore.AutoRuns > 0 { if (*score).CurrentScore.AutoRuns > 0 {
(*score).CurrentScore.AutoRuns-- (*score).CurrentScore.AutoRuns--
} }
} }
case "climb": case "c":
if autoCommitted { if autoCommitted {
if (*score).CurrentScore.Climbs < 3 { if (*score).CurrentScore.Climbs+(*score).CurrentScore.Parks < 3 {
(*score).CurrentScore.Climbs++ (*score).CurrentScore.Climbs++
} }
} }
case "undoClimb": case "C":
if autoCommitted { if autoCommitted {
if (*score).CurrentScore.Climbs > 0 { if (*score).CurrentScore.Climbs > 0 {
(*score).CurrentScore.Climbs-- (*score).CurrentScore.Climbs--
} }
} }
case "commit": case "p":
if autoCommitted {
if (*score).CurrentScore.Climbs+(*score).CurrentScore.Parks < 3 {
(*score).CurrentScore.Parks++
}
}
case "P":
if autoCommitted {
if (*score).CurrentScore.Parks > 0 {
(*score).CurrentScore.Parks--
}
}
case "\r":
if web.arena.MatchState != field.PreMatch || web.arena.CurrentMatch.Type == "test" { if web.arena.MatchState != field.PreMatch || web.arena.CurrentMatch.Type == "test" {
autoCommitted = true autoCommitted = true
} }
case "uncommitAuto": case "a":
autoCommitted = false autoCommitted = false
case "commitMatch": case "commitMatch":
if web.arena.MatchState != field.PostMatch { if web.arena.MatchState != field.PostMatch {

View File

@@ -47,16 +47,16 @@ func TestScoringDisplayWebsocket(t *testing.T) {
readWebsocketType(t, blueWs, "matchTime") readWebsocketType(t, blueWs, "matchTime")
// Send a match worth of scoring commands in. // Send a match worth of scoring commands in.
redWs.Write("autoRun", nil) redWs.Write("r", nil)
blueWs.Write("autoRun", nil) blueWs.Write("r", nil)
blueWs.Write("autoRun", nil) blueWs.Write("r", nil)
blueWs.Write("autoRun", nil) blueWs.Write("r", nil)
blueWs.Write("autoRun", nil) blueWs.Write("r", nil)
blueWs.Write("undoAutoRun", nil) blueWs.Write("R", nil)
redWs.Write("commit", nil) redWs.Write("\r", nil)
blueWs.Write("commit", nil) blueWs.Write("\r", nil)
redWs.Write("uncommitAuto", nil) redWs.Write("a", nil)
redWs.Write("commit", nil) redWs.Write("\r", nil)
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
readWebsocketType(t, redWs, "score") readWebsocketType(t, redWs, "score")
} }
@@ -67,7 +67,7 @@ func TestScoringDisplayWebsocket(t *testing.T) {
assert.Equal(t, 1, web.arena.RedRealtimeScore.CurrentScore.AutoRuns) assert.Equal(t, 1, web.arena.RedRealtimeScore.CurrentScore.AutoRuns)
assert.Equal(t, 2, web.arena.BlueRealtimeScore.CurrentScore.AutoRuns) assert.Equal(t, 2, web.arena.BlueRealtimeScore.CurrentScore.AutoRuns)
redWs.Write("autoRun", nil) redWs.Write("r", nil)
for i := 0; i < 1; i++ { for i := 0; i < 1; i++ {
readWebsocketType(t, redWs, "score") readWebsocketType(t, redWs, "score")
} }