Skip to content

Commit

Permalink
Show next match team on the team sign rear after the match is over.
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed Jun 2, 2024
1 parent 1f9060b commit c864a8f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
6 changes: 4 additions & 2 deletions field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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.
Expand Down
44 changes: 30 additions & 14 deletions field/team_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package field
import (
"fmt"
"github.com/Team254/cheesy-arena/game"
"github.com/Team254/cheesy-arena/model"
"image/color"
"log"
"net"
Expand All @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion field/team_sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}

0 comments on commit c864a8f

Please sign in to comment.