mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 14:12:11 +00:00
feat: promote accepted proposals from API
This commit is contained in:
@@ -2,6 +2,7 @@ package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -68,5 +69,34 @@ func PrepareProposal(id string, playlist Playlist, formation MatchFormation, ran
|
||||
if err != nil {
|
||||
return PreparedProposal{}, err
|
||||
}
|
||||
if formation.Selection.Region == "" || len(formation.Selection.Players) == 0 || formation.Selection.Players[0].ProtocolVersion < 1 {
|
||||
return PreparedProposal{}, fmt.Errorf("formed match metadata is incomplete")
|
||||
}
|
||||
proposal.Region = formation.Selection.Region
|
||||
proposal.Protocol = formation.Selection.Players[0].ProtocolVersion
|
||||
for _, player := range formation.Selection.Players {
|
||||
if player.ProtocolVersion != proposal.Protocol {
|
||||
return PreparedProposal{}, fmt.Errorf("formed match has mixed protocols")
|
||||
}
|
||||
}
|
||||
assignProposalSlots(&proposal, formation.Teams)
|
||||
return PreparedProposal{Proposal: proposal, CasualLineup: lineup}, nil
|
||||
}
|
||||
|
||||
func assignProposalSlots(proposal *Proposal, teams Teams) {
|
||||
assign := func(team int, players []Candidate) {
|
||||
ordered := append([]Candidate(nil), players...)
|
||||
sort.Slice(ordered, func(i, j int) bool { return ordered[i].PlayerID < ordered[j].PlayerID })
|
||||
for index, player := range ordered {
|
||||
for participant := range proposal.Participants {
|
||||
if proposal.Participants[participant].PlayerID == player.PlayerID {
|
||||
proposal.Participants[participant].Team = team
|
||||
proposal.Participants[participant].Slot = team*3 + index
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assign(0, teams.Team0)
|
||||
assign(1, teams.Team1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user