sort ws tags

main
Bel LaPointe 2024-12-15 12:03:21 -07:00
parent 9a74575e6c
commit c1933dc180
2 changed files with 42 additions and 26 deletions

View File

@ -378,6 +378,22 @@ func (games Games) CreateEventAssignmentRotation(ctx context.Context, id string,
return games.createEvent(ctx, id, event)
}
func (words KillWords) Privates() []KillWord {
a := slices.Clone(words.Assignment.Private)
slices.SortFunc(a, func(a, b KillWord) int {
return strings.Compare(a.Word, b.Word)
})
return a
}
func (words KillWords) Publics() []KillWord {
a := slices.Clone(words.Assignment.Public)
slices.SortFunc(a, func(a, b KillWord) int {
return strings.Compare(a.Word, b.Word)
})
return a
}
func (prev AllKillWords) ShuffleAssignees(killer, victim, word string) AllKillWords {
m := prev.withoutAssignees()

View File

@ -156,7 +156,7 @@ type inProgressMsgItem struct {
type inProgressMsgItemTag struct {
K string `json:"k"`
V string `json:"v"`
V int `json:"v,string"`
}
func (ws WS) inProgressMsgItems(ctx context.Context, ugs *UserGameServer, gameState GameState) ([]inProgressMsgItem, error) {
@ -180,44 +180,44 @@ func (ws WS) inProgressMsgItems(ctx context.Context, ugs *UserGameServer, gameSt
}
func (ws WS) inProgressMsgItem(ctx context.Context, ugs *UserGameServer, gameState GameState, uid string) (*inProgressMsgItem, error) {
v := gameState.Players[uid]
if uid == ugs.Session.ID {
if isSelf := uid == ugs.Session.ID; isSelf {
return nil, nil
}
name, err := ws.games.UserName(ctx, uid)
if err != nil {
return nil, err
}
v := gameState.Players[uid]
self := gameState.Players[ugs.Session.ID]
tags := []inProgressMsgItemTag{}
if self := gameState.Players[ugs.Session.ID]; self.KillWords.Assignee == uid {
for _, private := range v.KillWords.Assignment.Private {
tags = append(tags, inProgressMsgItemTag{
K: private.Word,
V: strconv.Itoa(private.Points),
})
}
}
for _, public := range v.KillWords.Assignment.Public {
tags = append(tags, inProgressMsgItemTag{
K: public.Word,
V: strconv.Itoa(public.Points),
})
}
if self := gameState.Players[ugs.Session.ID]; !slices.ContainsFunc(self.Kills, func(a Kill) bool {
return a.Victim == uid
}) {
if hasBeenKilledWithGlobal := slices.ContainsFunc(self.Kills, func(a Kill) bool {
return a.KillWord.Word == self.KillWords.Global.Word && a.Victim == uid
}); !hasBeenKilledWithGlobal {
tags = append(tags, inProgressMsgItemTag{
K: self.KillWords.Global.Word,
V: strconv.Itoa(self.KillWords.Global.Points),
V: self.KillWords.Global.Points,
})
}
for _, public := range v.KillWords.Publics() {
tags = append(tags, inProgressMsgItemTag{
K: public.Word,
V: public.Points,
})
}
if isAssigned := self.KillWords.Assignee == uid; isAssigned {
for _, private := range v.KillWords.Privates() {
tags = append(tags, inProgressMsgItemTag{
K: private.Word,
V: private.Points,
})
}
}
name, err := ws.games.UserName(ctx, uid)
return &inProgressMsgItem{
Name: name,
Title: strconv.Itoa(v.Points()),
Tags: tags,
}, nil
}, err
}