sort ws tags
parent
9a74575e6c
commit
c1933dc180
|
|
@ -378,6 +378,22 @@ func (games Games) CreateEventAssignmentRotation(ctx context.Context, id string,
|
||||||
return games.createEvent(ctx, id, event)
|
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 {
|
func (prev AllKillWords) ShuffleAssignees(killer, victim, word string) AllKillWords {
|
||||||
m := prev.withoutAssignees()
|
m := prev.withoutAssignees()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ type inProgressMsgItem struct {
|
||||||
|
|
||||||
type inProgressMsgItemTag struct {
|
type inProgressMsgItemTag struct {
|
||||||
K string `json:"k"`
|
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) {
|
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) {
|
func (ws WS) inProgressMsgItem(ctx context.Context, ugs *UserGameServer, gameState GameState, uid string) (*inProgressMsgItem, error) {
|
||||||
v := gameState.Players[uid]
|
if isSelf := uid == ugs.Session.ID; isSelf {
|
||||||
|
|
||||||
if uid == ugs.Session.ID {
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
name, err := ws.games.UserName(ctx, uid)
|
v := gameState.Players[uid]
|
||||||
if err != nil {
|
self := gameState.Players[ugs.Session.ID]
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
tags := []inProgressMsgItemTag{}
|
tags := []inProgressMsgItemTag{}
|
||||||
if self := gameState.Players[ugs.Session.ID]; self.KillWords.Assignee == uid {
|
|
||||||
for _, private := range v.KillWords.Assignment.Private {
|
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: 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{
|
tags = append(tags, inProgressMsgItemTag{
|
||||||
K: private.Word,
|
K: private.Word,
|
||||||
V: strconv.Itoa(private.Points),
|
V: 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
|
|
||||||
}) {
|
|
||||||
tags = append(tags, inProgressMsgItemTag{
|
|
||||||
K: self.KillWords.Global.Word,
|
|
||||||
V: strconv.Itoa(self.KillWords.Global.Points),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
name, err := ws.games.UserName(ctx, uid)
|
||||||
return &inProgressMsgItem{
|
return &inProgressMsgItem{
|
||||||
Name: name,
|
Name: name,
|
||||||
Title: strconv.Itoa(v.Points()),
|
Title: strconv.Itoa(v.Points()),
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
}, nil
|
}, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue