mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Fix bug with committing playoff matches after a team substitution.
This commit is contained in:
@@ -44,6 +44,34 @@ func UpdateEliminationSchedule(database *model.Database, startTime time.Time) (b
|
|||||||
return len(winner) > 0, err
|
return len(winner) > 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Updates the alliance, if necessary, to include whoever played in the match, in case there was a substitute.
|
||||||
|
func UpdateAlliance(database *model.Database, matchTeamIds [3]int, allianceId int) error {
|
||||||
|
allianceTeams, err := database.GetTeamsByAlliance(allianceId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, teamId := range matchTeamIds {
|
||||||
|
found := false
|
||||||
|
for _, allianceTeam := range allianceTeams {
|
||||||
|
if teamId == allianceTeam.TeamId {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
newAllianceTeam := model.AllianceTeam{AllianceId: allianceId, PickPosition: len(allianceTeams),
|
||||||
|
TeamId: teamId}
|
||||||
|
allianceTeams = append(allianceTeams, newAllianceTeam)
|
||||||
|
if err := database.CreateAllianceTeam(&newAllianceTeam); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Recursively traverses the elimination bracket downwards, creating matches as necessary. Returns the winner
|
// Recursively traverses the elimination bracket downwards, creating matches as necessary. Returns the winner
|
||||||
// of the given round if known.
|
// of the given round if known.
|
||||||
func buildEliminationMatchSet(database *model.Database, round int, group int,
|
func buildEliminationMatchSet(database *model.Database, round int, group int,
|
||||||
|
|||||||
@@ -376,6 +376,15 @@ func (web *Web) commitMatchScore(match *model.Match, matchResult *model.MatchRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
if match.ShouldUpdateEliminationMatches() {
|
if match.ShouldUpdateEliminationMatches() {
|
||||||
|
if err = tournament.UpdateAlliance(web.arena.Database, [3]int{match.Red1, match.Red2, match.Red3},
|
||||||
|
match.ElimRedAlliance); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = tournament.UpdateAlliance(web.arena.Database, [3]int{match.Blue1, match.Blue2, match.Blue3},
|
||||||
|
match.ElimBlueAlliance); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Generate any subsequent elimination matches.
|
// Generate any subsequent elimination matches.
|
||||||
isTournamentWon, err := tournament.UpdateEliminationSchedule(web.arena.Database,
|
isTournamentWon, err := tournament.UpdateEliminationSchedule(web.arena.Database,
|
||||||
time.Now().Add(time.Second*tournament.ElimMatchSpacingSec))
|
time.Now().Add(time.Second*tournament.ElimMatchSpacingSec))
|
||||||
|
|||||||
@@ -228,6 +228,8 @@ func TestCommitCards(t *testing.T) {
|
|||||||
// Check that a red card in eliminations zeroes out the score.
|
// Check that a red card in eliminations zeroes out the score.
|
||||||
tournament.CreateTestAlliances(web.arena.Database, 2)
|
tournament.CreateTestAlliances(web.arena.Database, 2)
|
||||||
match.Type = "elimination"
|
match.Type = "elimination"
|
||||||
|
match.ElimRedAlliance = 1
|
||||||
|
match.ElimBlueAlliance = 2
|
||||||
web.arena.Database.SaveMatch(match)
|
web.arena.Database.SaveMatch(match)
|
||||||
matchResult = model.BuildTestMatchResult(match.Id, 10)
|
matchResult = model.BuildTestMatchResult(match.Id, 10)
|
||||||
matchResult.MatchType = match.Type
|
matchResult.MatchType = match.Type
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func TestMatchReviewEditExistingResult(t *testing.T) {
|
|||||||
web := setupTestWeb(t)
|
web := setupTestWeb(t)
|
||||||
|
|
||||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 1001,
|
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 1001,
|
||||||
Red2: 1002, Red3: 1003, Blue1: 1004, Blue2: 1005, Blue3: 1006}
|
Red2: 1002, Red3: 1003, Blue1: 1004, Blue2: 1005, Blue3: 1006, ElimRedAlliance: 1, ElimBlueAlliance: 2}
|
||||||
web.arena.Database.CreateMatch(&match)
|
web.arena.Database.CreateMatch(&match)
|
||||||
matchResult := model.BuildTestMatchResult(match.Id, 1)
|
matchResult := model.BuildTestMatchResult(match.Id, 1)
|
||||||
matchResult.MatchType = match.Type
|
matchResult.MatchType = match.Type
|
||||||
@@ -79,7 +79,7 @@ func TestMatchReviewCreateNewResult(t *testing.T) {
|
|||||||
web := setupTestWeb(t)
|
web := setupTestWeb(t)
|
||||||
|
|
||||||
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 1001,
|
match := model.Match{Type: "elimination", DisplayName: "QF4-3", Status: "complete", Winner: "R", Red1: 1001,
|
||||||
Red2: 1002, Red3: 1003, Blue1: 1004, Blue2: 1005, Blue3: 1006}
|
Red2: 1002, Red3: 1003, Blue1: 1004, Blue2: 1005, Blue3: 1006, ElimRedAlliance: 1, ElimBlueAlliance: 2}
|
||||||
web.arena.Database.CreateMatch(&match)
|
web.arena.Database.CreateMatch(&match)
|
||||||
tournament.CreateTestAlliances(web.arena.Database, 2)
|
tournament.CreateTestAlliances(web.arena.Database, 2)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user