Skip to content

Commit

Permalink
Merge branch '2024_NMRC_Crescendo' of https://github.com/cpapplefamil…
Browse files Browse the repository at this point in the history
…y/cheesy-arena into 2024_NMRC_Crescendo
  • Loading branch information
cpapplefamily committed Jul 26, 2024
2 parents fb967a7 + a28190f commit 610c737
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 11 deletions.
10 changes: 10 additions & 0 deletions field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,8 @@ func (arena *Arena) getAssignedAllianceStation(teamId int) string {
}
var redAmplifiedTimePostWindow_ons = false
var blueAmplifiedTimePostWindow_ons = false
var redAmplifiedTimeRemaining_ons = false
var blueAmplifiedTimeRemaining_ons = false
// Updates the score given new input information from the field PLC, and actuates PLC outputs accordingly.
func (arena *Arena) handlePlcInputOutput() {
if !arena.Plc.IsEnabled() {
Expand Down Expand Up @@ -1011,9 +1013,13 @@ func (arena *Arena) handlePlcInputOutput() {
redCoopAmpLight := redAmpSpeaker.CoopActivated
if redAmplifiedTimeRemaining > 0 {
redAmplifiedTimePostWindow_ons = false
redAmplifiedTimeRemaining_ons = false
redLowAmpLight = int(redAmplifiedTimeRemaining*2)%2 == 0
redHighAmpLight = !redLowAmpLight
arena.RealtimeScoreNotifier.Notify()
}else if !redAmplifiedTimeRemaining_ons{
arena.RealtimeScoreNotifier.Notify()
redAmplifiedTimeRemaining_ons = true
}
if !redAmplifiedTimePostWindow && !redAmplifiedTimePostWindow_ons{
arena.RealtimeScoreNotifier.Notify()
Expand All @@ -1025,9 +1031,13 @@ func (arena *Arena) handlePlcInputOutput() {
blueCoopAmpLight := blueAmpSpeaker.CoopActivated
if blueAmplifiedTimeRemaining > 0 {
blueAmplifiedTimePostWindow_ons = false
blueAmplifiedTimeRemaining_ons = false
blueLowAmpLight = int(blueAmplifiedTimeRemaining*4)%2 == 0
blueHighAmpLight = !blueLowAmpLight
arena.RealtimeScoreNotifier.Notify()
}else if !blueAmplifiedTimeRemaining_ons{
arena.RealtimeScoreNotifier.Notify()
blueAmplifiedTimeRemaining_ons = true
}
if !blueAmplifiedTimePostWindow && !blueAmplifiedTimePostWindow_ons{
arena.RealtimeScoreNotifier.Notify()
Expand Down
25 changes: 22 additions & 3 deletions static/css/field_monitor_display.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ body {
.position-row[data-ds="true"][data-preMatch="false"] {
display: none;
}
#matchData[data-ds="false"]{
display: none;
}
#matchData[data-ds="true"][data-preMatch="true"]{
display: none;
}
#matchData{
position: absolute;
top: 2%;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
font-size: 5vw;
}
#matchStatusRow{
display: flex;
}
#matchStatusRow[data-ds="true"][data-preMatch="false"] {
display: none;
}
#matchStatusRow {
height: 6%;
display: flex;
Expand All @@ -36,9 +58,6 @@ body {
font-size: 1.5vw;
text-transform: uppercase;
}
#matchStatusRow[data-ds="true"][data-preMatch="false"] {
display: none;
}
#eventStatusRow {
height: 7%;
display: flex;
Expand Down
6 changes: 6 additions & 0 deletions static/css/referee_panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ h3 {
flex-direction: column;
align-items: center;
}
#cards[data-hr="false"] {
display: none;
}
.alliance-cards {
padding: 0.5vw 1vw;
display: flex;
Expand Down Expand Up @@ -175,6 +178,9 @@ h3 {
flex-direction: row;
justify-content: center;
}
#controlButtons[data-hr="false"] {
display: none;
}
.control-button {
width: 20vw;
height: 4vw;
Expand Down
24 changes: 24 additions & 0 deletions static/js/field_monitor_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ var handleMatchTime = function(data) {
translateMatchTime(data, function(matchState, matchStateText, countdownSec) {
$("#matchState").text(matchStateText);
$("#matchTime").text(countdownSec);
$("#matchTimeAllianceStation").text(countdownSec);
if (matchStateText === "PRE-MATCH" | matchStateText === "POST-MATCH") {
$(".ds-dependent").attr("data-preMatch", "true");
} else {
Expand All @@ -156,16 +157,38 @@ var handleMatchTime = function(data) {
});
};

// Handles a websocket message to play a sound to signal match start/stop/etc.
const handlePlaySound = function(sound) {
$("audio").each(function(k, v) {
// Stop and reset any sounds that are still playing.
v.pause();
v.currentTime = 0;
});
$("#sound-" + sound)[0].play();
};

// Handles a websocket message to update the match score.
var handleRealtimeScore = function(data,reversed) {

if (reversed === "true") {
$("#rightScore").text(data.Red.ScoreSummary.Score);
$("#leftScore").text(data.Blue.ScoreSummary.Score);

$("#rightScoreAllianceDisplay").text(data.Blue.ScoreSummary.Score);
$("#leftScoreAllianceDisplay").text(data.Red.ScoreSummary.Score);
$(`#noteNumerator`).text(data.Blue.ScoreSummary.NumNotes);
$(`#noteDenominator`).text(data.Blue.ScoreSummary.NumNotesGoal);
$(`#amplifiedTimeRemaining`).text(data.Blue.AmplifiedTimeRemainingSec);

} else {
$("#rightScore").text(data.Blue.ScoreSummary.Score);
$("#leftScore").text(data.Red.ScoreSummary.Score);

$("#rightScoreAllianceDisplay").text(data.Red.ScoreSummary.Score);
$("#leftScoreAllianceDisplay").text(data.Blue.ScoreSummary.Score);
$(`#noteNumerator`).text(data.Red.ScoreSummary.NumNotes);
$(`#noteDenominator`).text(data.Red.ScoreSummary.NumNotesGoal);
$(`#amplifiedTimeRemaining`).text(data.Red.AmplifiedTimeRemainingSec);
}
};

Expand Down Expand Up @@ -234,5 +257,6 @@ $(function() {
matchTiming: function(event) { handleMatchTiming(event.data); },
matchTime: function(event) { handleMatchTime(event.data); },
realtimeScore: function(event) { handleRealtimeScore(event.data,reversed); },
playSound: function(event) { handlePlaySound(event.data); },
});
});
4 changes: 4 additions & 0 deletions static/js/referee_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ const hashObject = function(object) {
}

$(function() {
// Read the configuration for this display from the URL query string.
var urlParams = new URLSearchParams(window.location.search);
$(".headRef-dependent").attr("data-hr", urlParams.get("hr"));

// Set up the websocket back to the server.
websocket = new CheesyWebsocket("/panels/referee/websocket", {
matchLoad: function(event) { handleMatchLoad(event.data); },
Expand Down
3 changes: 2 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
<li class="nav-item dropdown">
<a href="#" class="nav-link" data-bs-toggle="dropdown" role="button">Panel</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="/panels/referee">Referee</a>
<a class="dropdown-item" href="/panels/referee">Head Referee</a>
<a class="dropdown-item" href="/panels/referee?hr=false">Referee</a>
<div class="dropdown-divider"></div>
<div class="dropdown-header">Scoring</div>
<a class="dropdown-item" href="/panels/scoring/red">Red</a>
Expand Down
23 changes: 23 additions & 0 deletions templates/field_monitor_display.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,26 @@
<div id="earlyLateMessage" class="text-center ds-dependent" style="width: 38%;"></div>
<div id="rightScore" class="right-score ds-dependent text-center fta-dependent reversible-right " style="width: 8%;"></div>
</div>
<div id="matchData" class="ds-dependent">
<div>Match Time</div>
<div id="matchTimeAllianceStation"></div>
Melody
<div id="melody">
<span id="noteNumerator"></span>
<span class="note-splitter">/</span>
<span id="noteDenominator"></span>
</div>
<div>Amplified Time</div>
<div id="amplifiedTimeRemaining"></div>
Score
<div id="Score">
<span id="rightScoreAllianceDisplay" class="left-score ds-dependent text-center reversible-right"></span>
<span class="note-splitter">:</span>
<span id="leftScoreAllianceDisplay" class="right-score ds-dependent text-center reversible-right"></span>
</div>
</div>
</body>

<script src="/static/js/lib/jquery.min.js"></script>
<script src="/static/js/lib/jquery.json-2.4.min.js"></script>
<script src="/static/js/lib/jquery.websocket-0.0.1.js"></script>
Expand All @@ -41,6 +60,10 @@
<script src="/static/js/lib/bootstrap.bundle.min.js"></script>
<script src="/static/js/match_timing.js"></script>
<script src="/static/js/field_monitor_display.js"></script>
{{range $sound := .MatchSounds}}
<audio id="sound-{{$sound.Name}}" src="/static/audio/{{$sound.Name}}.{{$sound.FileExtension}}" preload="auto">
</audio>
{{end}}
</html>

{{define "row"}}
Expand Down
4 changes: 2 additions & 2 deletions templates/referee_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{define "body"}}
<div id="matchName"></div>
<div id="refereePanel">
<div id="cards">
<div id="cards" class="headRef-dependent">
<h3>Red/Yellow Cards</h3>
<div class="alliance-cards" id="redCards">
{{range $i := seq 3}}
Expand All @@ -35,7 +35,7 @@ <h3>Fouls</h3>
</div>
</div>
<p>Note: Team and rule assignment are optional.</p>
<div id="controlButtons">
<div id="controlButtons" class="headRef-dependent">
<div class="control-button" id="resetButton" onclick="signalReset();">Signal Reset</div>
<div class="control-button" id="commitButton" onclick="commitMatch();">Commit Match</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions web/alliance_station_display.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package web

import (
"github.com/Team254/cheesy-arena/game"
"github.com/Team254/cheesy-arena/model"
"github.com/Team254/cheesy-arena/websocket"
"net/http"
Expand All @@ -25,7 +26,8 @@ func (web *Web) allianceStationDisplayHandler(w http.ResponseWriter, r *http.Req

data := struct {
*model.EventSettings
}{web.arena.EventSettings}
MatchSounds []*game.MatchSound
}{web.arena.EventSettings, game.MatchSounds}
err = template.ExecuteTemplate(w, "alliance_station_display.html", data)
if err != nil {
handleWebErr(w, err)
Expand All @@ -51,6 +53,6 @@ func (web *Web) allianceStationDisplayWebsocketHandler(w http.ResponseWriter, r

// Subscribe the websocket to the notifiers whose messages will be passed on to the client.
ws.HandleNotifiers(display.Notifier, web.arena.MatchTimingNotifier, web.arena.AllianceStationDisplayModeNotifier,
web.arena.ArenaStatusNotifier, web.arena.MatchLoadNotifier, web.arena.MatchTimeNotifier,
web.arena.ArenaStatusNotifier, web.arena.MatchLoadNotifier, web.arena.PlaySoundNotifier,web.arena.MatchTimeNotifier,
web.arena.RealtimeScoreNotifier, web.arena.ReloadDisplaysNotifier)
}
8 changes: 5 additions & 3 deletions web/field_monitor_display.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
package web

import (
"github.com/Team254/cheesy-arena/game"
"github.com/Team254/cheesy-arena/model"
"github.com/Team254/cheesy-arena/websocket"
"github.com/mitchellh/mapstructure"
"io"
"log"
"net/http"
"net/http"
)

// Renders the field monitor display.
Expand All @@ -31,7 +32,8 @@ func (web *Web) fieldMonitorDisplayHandler(w http.ResponseWriter, r *http.Reques
}
data := struct {
*model.EventSettings
}{web.arena.EventSettings}
MatchSounds []*game.MatchSound
}{web.arena.EventSettings, game.MatchSounds}
err = template.ExecuteTemplate(w, "field_monitor_display.html", data)
if err != nil {
handleWebErr(w, err)
Expand Down Expand Up @@ -62,7 +64,7 @@ func (web *Web) fieldMonitorDisplayWebsocketHandler(w http.ResponseWriter, r *ht

// Subscribe the websocket to the notifiers whose messages will be passed on to the client, in a separate goroutine.
go ws.HandleNotifiers(web.arena.MatchTimingNotifier, display.Notifier, web.arena.ArenaStatusNotifier,
web.arena.EventStatusNotifier, web.arena.RealtimeScoreNotifier, web.arena.MatchTimeNotifier,
web.arena.EventStatusNotifier, web.arena.RealtimeScoreNotifier, web.arena.PlaySoundNotifier, web.arena.MatchTimeNotifier,
web.arena.MatchLoadNotifier, web.arena.ReloadDisplaysNotifier)

// Loop, waiting for commands and responding to them, until the client closes the connection.
Expand Down

0 comments on commit 610c737

Please sign in to comment.