mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Enforce that pre-match scoring is set validly before starting a match.
This commit is contained in:
@@ -58,6 +58,7 @@ func TestAllianceStationDisplayWebsocket(t *testing.T) {
|
||||
web.arena.AllianceStations["B1"].Bypass = true
|
||||
web.arena.AllianceStations["B2"].Bypass = true
|
||||
web.arena.AllianceStations["B3"].Bypass = true
|
||||
web.arena.BypassPreMatchScore = true
|
||||
web.arena.StartMatch()
|
||||
web.arena.Update()
|
||||
messages := readWebsocketMultiple(t, ws, 3)
|
||||
|
||||
@@ -45,6 +45,7 @@ func TestAnnouncerDisplayWebsocket(t *testing.T) {
|
||||
web.arena.AllianceStations["B1"].Bypass = true
|
||||
web.arena.AllianceStations["B2"].Bypass = true
|
||||
web.arena.AllianceStations["B3"].Bypass = true
|
||||
web.arena.BypassPreMatchScore = true
|
||||
web.arena.StartMatch()
|
||||
web.arena.Update()
|
||||
messages := readWebsocketMultiple(t, ws, 2)
|
||||
|
||||
@@ -55,6 +55,7 @@ func TestAudienceDisplayWebsocket(t *testing.T) {
|
||||
web.arena.AllianceStations["B1"].Bypass = true
|
||||
web.arena.AllianceStations["B2"].Bypass = true
|
||||
web.arena.AllianceStations["B3"].Bypass = true
|
||||
web.arena.BypassPreMatchScore = true
|
||||
web.arena.StartMatch()
|
||||
web.arena.Update()
|
||||
web.arena.Update()
|
||||
|
||||
@@ -207,6 +207,8 @@ func (web *Web) matchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request
|
||||
continue
|
||||
}
|
||||
web.arena.AllianceStations[station].Bypass = !web.arena.AllianceStations[station].Bypass
|
||||
case "toggleBypassPreMatchScore":
|
||||
web.arena.BypassPreMatchScore = !web.arena.BypassPreMatchScore
|
||||
case "startMatch":
|
||||
args := struct {
|
||||
MuteMatchSounds bool
|
||||
|
||||
@@ -294,6 +294,7 @@ func TestMatchPlayWebsocketCommands(t *testing.T) {
|
||||
web.arena.AllianceStations["B1"].Bypass = true
|
||||
web.arena.AllianceStations["B2"].Bypass = true
|
||||
web.arena.AllianceStations["B3"].Bypass = true
|
||||
web.arena.BypassPreMatchScore = true
|
||||
ws.Write("startMatch", nil)
|
||||
readWebsocketType(t, ws, "arenaStatus")
|
||||
assert.Equal(t, field.StartMatch, web.arena.MatchState)
|
||||
@@ -353,6 +354,7 @@ func TestMatchPlayWebsocketNotifications(t *testing.T) {
|
||||
web.arena.AllianceStations["B1"].Bypass = true
|
||||
web.arena.AllianceStations["B2"].Bypass = true
|
||||
web.arena.AllianceStations["B3"].Bypass = true
|
||||
web.arena.BypassPreMatchScore = true
|
||||
assert.Nil(t, web.arena.StartMatch())
|
||||
web.arena.Update()
|
||||
messages := readWebsocketMultiple(t, ws, 4)
|
||||
@@ -367,7 +369,7 @@ func TestMatchPlayWebsocketNotifications(t *testing.T) {
|
||||
messages = readWebsocketMultiple(t, ws, 2)
|
||||
statusReceived, matchTime := getStatusMatchTime(t, messages)
|
||||
assert.Equal(t, true, statusReceived)
|
||||
assert.Equal(t, 3, matchTime.MatchState)
|
||||
assert.Equal(t, field.AutoPeriod, matchTime.MatchState)
|
||||
assert.Equal(t, 3, matchTime.MatchTimeSec)
|
||||
web.arena.ScoringStatusNotifier.Notify()
|
||||
readWebsocketType(t, ws, "scoringStatus")
|
||||
@@ -377,7 +379,7 @@ func TestMatchPlayWebsocketNotifications(t *testing.T) {
|
||||
web.arena.Update()
|
||||
err = mapstructure.Decode(readWebsocketType(t, ws, "matchTime"), &matchTime)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, matchTime.MatchState)
|
||||
assert.Equal(t, field.AutoPeriod, matchTime.MatchState)
|
||||
assert.Equal(t, 1, matchTime.MatchTimeSec)
|
||||
web.arena.MatchStartTime = time.Now().Add(-2*time.Second + 10*time.Millisecond) // Not crossed yet
|
||||
web.arena.Update()
|
||||
@@ -385,7 +387,7 @@ func TestMatchPlayWebsocketNotifications(t *testing.T) {
|
||||
web.arena.Update()
|
||||
err = mapstructure.Decode(readWebsocketType(t, ws, "matchTime"), &matchTime)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 3, matchTime.MatchState)
|
||||
assert.Equal(t, field.AutoPeriod, matchTime.MatchState)
|
||||
assert.Equal(t, 2, matchTime.MatchTimeSec)
|
||||
|
||||
// Check across a match state boundary.
|
||||
@@ -394,7 +396,7 @@ func TestMatchPlayWebsocketNotifications(t *testing.T) {
|
||||
web.arena.Update()
|
||||
statusReceived, matchTime = readWebsocketStatusMatchTime(t, ws)
|
||||
assert.Equal(t, true, statusReceived)
|
||||
assert.Equal(t, 4, matchTime.MatchState)
|
||||
assert.Equal(t, field.PausePeriod, matchTime.MatchState)
|
||||
assert.Equal(t, game.MatchTiming.WarmupDurationSec+game.MatchTiming.AutoDurationSec, matchTime.MatchTimeSec)
|
||||
}
|
||||
|
||||
|
||||
@@ -140,19 +140,19 @@ func (web *Web) scoringPanelWebsocketHandler(w http.ResponseWriter, r *http.Requ
|
||||
web.arena.ScoringStatusNotifier.Notify()
|
||||
} else if number, err := strconv.Atoi(command); err == nil && number >= 1 && number <= 9 {
|
||||
// Handle per-robot scoring fields.
|
||||
if number <= 3 {
|
||||
if number <= 3 && web.arena.MatchState == field.PreMatch {
|
||||
index := number - 1
|
||||
score.RobotStartLevels[index]++
|
||||
if score.RobotStartLevels[index] == 4 {
|
||||
score.RobotStartLevels[index] = 0
|
||||
}
|
||||
scoreChanged = true
|
||||
} else if number <= 6 && web.arena.MatchState != field.PreMatch {
|
||||
} else if number > 3 && number <= 6 && web.arena.MatchState != field.PreMatch {
|
||||
index := number - 4
|
||||
score.SandstormBonuses[index] =
|
||||
!score.SandstormBonuses[index]
|
||||
scoreChanged = true
|
||||
} else if web.arena.MatchState != field.PreMatch {
|
||||
} else if number > 6 && web.arena.MatchState != field.PreMatch {
|
||||
index := number - 7
|
||||
score.RobotEndLevels[index]++
|
||||
if score.RobotEndLevels[index] == 4 {
|
||||
|
||||
Reference in New Issue
Block a user