Skip to content

Commit

Permalink
Show alliance scores on team sign rear when not showing amplified cou…
Browse files Browse the repository at this point in the history
…ntdown.
  • Loading branch information
patfair committed Jun 2, 2024
1 parent c864a8f commit 467aae1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
22 changes: 15 additions & 7 deletions field/team_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (signs *TeamSigns) Update(arena *Arena) {
countdown := fmt.Sprintf("%02d:%02d", countdownSec/60, countdownSec%60)

// Generate the in-match rear text which is common to a whole alliance.
redInMatchRearText := generateInMatchRearText(countdown, arena.RedRealtimeScore, arena.BlueRealtimeScore)
blueInMatchRearText := generateInMatchRearText(countdown, arena.BlueRealtimeScore, arena.RedRealtimeScore)
redInMatchRearText := generateInMatchRearText(true, countdown, arena.RedRealtimeScore, arena.BlueRealtimeScore)
blueInMatchRearText := generateInMatchRearText(false, countdown, arena.BlueRealtimeScore, arena.RedRealtimeScore)

signs.Red1.update(arena, arena.AllianceStations["R1"], true, countdown, redInMatchRearText)
signs.Red2.update(arena, arena.AllianceStations["R2"], true, countdown, redInMatchRearText)
Expand Down Expand Up @@ -172,14 +172,22 @@ func (sign *TeamSign) update(
}

// Returns the in-match rear text that is common to a whole alliance.
func generateInMatchRearText(countdown string, realtimeScore, opponentRealtimeScore *RealtimeScore) string {
var amplifiedCountdown string
func generateInMatchRearText(isRed bool, countdown string, realtimeScore, opponentRealtimeScore *RealtimeScore) string {
scoreSummary := realtimeScore.CurrentScore.Summarize(&opponentRealtimeScore.CurrentScore)
scoreTotal := scoreSummary.Score
opponentScoreTotal := opponentRealtimeScore.CurrentScore.Summarize(&realtimeScore.CurrentScore).Score
var allianceScores string
if isRed {
allianceScores = fmt.Sprintf("R%03d-B%03d", scoreTotal, opponentScoreTotal)
} else {
allianceScores = fmt.Sprintf("B%03d-R%03d", scoreTotal, opponentScoreTotal)
}
if realtimeScore.AmplifiedTimeRemainingSec > 0 {
amplifiedCountdown = fmt.Sprintf("Amp:%2d", realtimeScore.AmplifiedTimeRemainingSec)
// Replace the total score with the amplified countdown while it's active.
allianceScores = fmt.Sprintf("Amp:%2d", realtimeScore.AmplifiedTimeRemainingSec)
}
scoreSummary := realtimeScore.CurrentScore.Summarize(&opponentRealtimeScore.CurrentScore)
return fmt.Sprintf(
"%s %02d/%02d %6s", countdown, scoreSummary.NumNotes, scoreSummary.NumNotesGoal, amplifiedCountdown,
"%s %02d/%02d %9s", countdown[1:], scoreSummary.NumNotes, scoreSummary.NumNotesGoal, allianceScores,
)
}

Expand Down
10 changes: 7 additions & 3 deletions field/team_sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ import (

func TestTeamSign_GenerateInMatchRearText(t *testing.T) {
realtimeScore1 := &RealtimeScore{AmplifiedTimeRemainingSec: 9}
realtimeScore2 := &RealtimeScore{CurrentScore: game.Score{AmpSpeaker: game.AmpSpeaker{AutoSpeakerNotes: 12}}}
realtimeScore2 := &RealtimeScore{AmplifiedTimeRemainingSec: 15}
realtimeScore3 := &RealtimeScore{CurrentScore: game.Score{AmpSpeaker: game.AmpSpeaker{AutoSpeakerNotes: 12}}}
realtimeScore4 := &RealtimeScore{CurrentScore: game.Score{AmpSpeaker: game.AmpSpeaker{TeleopAmpNotes: 1}}}

assert.Equal(t, "01:23 00/18 Amp: 9", generateInMatchRearText("01:23", realtimeScore1, realtimeScore2))
assert.Equal(t, "1:23 00/18 Amp: 9", generateInMatchRearText(true, "01:23", realtimeScore1, realtimeScore2))
assert.Equal(t, "1:23 00/18 Amp:15", generateInMatchRearText(false, "01:23", realtimeScore2, realtimeScore1))
game.MelodyBonusThresholdWithoutCoop = 23
assert.Equal(t, "34:56 12/23 ", generateInMatchRearText("34:56", realtimeScore2, realtimeScore1))
assert.Equal(t, "4:56 12/23 R060-B001", generateInMatchRearText(true, "34:56", realtimeScore3, realtimeScore4))
assert.Equal(t, "4:56 01/23 B001-R060", generateInMatchRearText(false, "34:56", realtimeScore4, realtimeScore3))
}

func TestTeamSign_Timer(t *testing.T) {
Expand Down

0 comments on commit 467aae1

Please sign in to comment.