From c864a8f0e2a52885bf56ab99b9bb0f0f6bb9990d Mon Sep 17 00:00:00 2001 From: Patrick Fairbank Date: Sun, 2 Jun 2024 16:38:26 -0700 Subject: [PATCH] Show next match team on the team sign rear after the match is over. --- field/arena.go | 6 ++++-- field/team_sign.go | 44 ++++++++++++++++++++++++++++------------- field/team_sign_test.go | 12 ++++++++++- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/field/arena.go b/field/arena.go index b9a1b150..a04f1dc7 100644 --- a/field/arena.go +++ b/field/arena.go @@ -773,8 +773,9 @@ func (arena *Arena) preLoadNextMatch() { } var teams [6]*model.Team - for i, teamId := range []int{nextMatch.Red1, nextMatch.Red2, nextMatch.Red3, nextMatch.Blue1, nextMatch.Blue2, - nextMatch.Blue3} { + for i, teamId := range []int{ + nextMatch.Red1, nextMatch.Red2, nextMatch.Red3, nextMatch.Blue1, nextMatch.Blue2, nextMatch.Blue3, + } { if teamId == 0 { continue } @@ -783,6 +784,7 @@ func (arena *Arena) preLoadNextMatch() { } } arena.setupNetwork(teams, true) + arena.TeamSigns.SetNextMatchTeams(nextMatch) } // Asynchronously reconfigures the networking hardware for the new set of teams. diff --git a/field/team_sign.go b/field/team_sign.go index e8bc3dcc..82045090 100644 --- a/field/team_sign.go +++ b/field/team_sign.go @@ -8,6 +8,7 @@ package field import ( "fmt" "github.com/Team254/cheesy-arena/game" + "github.com/Team254/cheesy-arena/model" "image/color" "log" "net" @@ -29,17 +30,18 @@ type TeamSigns struct { // Represents a team number or timer sign. type TeamSign struct { - isTimer bool - address byte - frontText string - frontColor color.RGBA - rearText string - lastFrontText string - lastFrontColor color.RGBA - lastRearText string - udpConn net.Conn - packetData [128]byte - packetIndex int + isTimer bool + address byte + nextMatchTeamId int + frontText string + frontColor color.RGBA + rearText string + lastFrontText string + lastFrontColor color.RGBA + lastRearText string + udpConn net.Conn + packetData [128]byte + packetIndex int } const ( @@ -107,6 +109,16 @@ func (signs *TeamSigns) Update(arena *Arena) { signs.BlueTimer.update(arena, nil, false, countdown, blueInMatchRearText) } +// Sets the team numbers for the next match on all signs. +func (signs *TeamSigns) SetNextMatchTeams(match *model.Match) { + signs.Red1.nextMatchTeamId = match.Red1 + signs.Red2.nextMatchTeamId = match.Red2 + signs.Red3.nextMatchTeamId = match.Red3 + signs.Blue1.nextMatchTeamId = match.Blue1 + signs.Blue2.nextMatchTeamId = match.Blue2 + signs.Blue3.nextMatchTeamId = match.Blue3 +} + // Sets the IP address of the sign. func (sign *TeamSign) SetAddress(ipAddress string) { if sign.udpConn != nil { @@ -149,7 +161,7 @@ func (sign *TeamSign) update( sign.frontText, sign.frontColor = generateTimerText(arena.FieldReset, countdown) sign.rearText = inMatchRearText } else { - sign.frontText, sign.frontColor, sign.rearText = generateTeamNumberTexts( + sign.frontText, sign.frontColor, sign.rearText = sign.generateTeamNumberTexts( arena, allianceStation, isRed, inMatchRearText, ) } @@ -186,7 +198,7 @@ func generateTimerText(fieldReset bool, countdown string) (string, color.RGBA) { } // Returns the front text, front color, and rear text to display on the sign for the given alliance station. -func generateTeamNumberTexts( +func (sign *TeamSign) generateTeamNumberTexts( arena *Arena, allianceStation *AllianceStation, isRed bool, inMatchRearText string, ) (string, color.RGBA, string) { if allianceStation.Team == nil { @@ -232,7 +244,11 @@ func generateTeamNumberTexts( } var rearText string - if len(message) > 0 { + if arena.MatchState == PostMatch && sign.nextMatchTeamId > 0 && sign.nextMatchTeamId != allianceStation.Team.Id { + // Show the next match team number on the rear display before the score is committed so that queueing teams know + // where to go. + rearText = fmt.Sprintf("Next Team Up: %d", sign.nextMatchTeamId) + } else if len(message) > 0 { rearText = fmt.Sprintf("%-5d %14s", allianceStation.Team.Id, message) } else { rearText = inMatchRearText diff --git a/field/team_sign_test.go b/field/team_sign_test.go index 60e8cafd..a1d27639 100644 --- a/field/team_sign_test.go +++ b/field/team_sign_test.go @@ -68,7 +68,7 @@ func TestTeamSign_TeamNumber(t *testing.T) { assert.Equal(t, 46, sign.packetIndex) assertSign := func(isRed bool, expectedFrontText string, expectedFrontColor color.RGBA, expectedRearText string) { - frontText, frontColor, rearText := generateTeamNumberTexts(arena, allianceStation, isRed, "Rear Text") + frontText, frontColor, rearText := sign.generateTeamNumberTexts(arena, allianceStation, isRed, "Rear Text") assert.Equal(t, expectedFrontText, frontText) assert.Equal(t, expectedFrontColor, frontColor) assert.Equal(t, expectedRearText, rearText) @@ -114,4 +114,14 @@ func TestTeamSign_TeamNumber(t *testing.T) { assertSign(false, " 254", orangeColor, "254 E-STOP") arena.MatchState = PostMatch assertSign(false, " 254", orangeColor, "254 E-STOP") + + // Test preloading the team for the next match. + sign.nextMatchTeamId = 1503 + assertSign(false, " 254", orangeColor, "Next Team Up: 1503") + allianceStation.Bypass = false + allianceStation.EStop = false + allianceStation.Ethernet = false + arena.MatchState = PreMatch + arena.assignTeam(1503, "R1") + assertSign(false, " 1503", blueColor, "1503 Connect PC") }