PlayerState.Points()
parent
2a635bc8b5
commit
5587467a2d
|
|
@ -73,6 +73,14 @@ func (games Games) UserName(ctx context.Context, id string) (string, error) {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s PlayerState) Points() int {
|
||||||
|
points := 0
|
||||||
|
for _, kill := range s.Kills {
|
||||||
|
points += kill.KillWord.Points
|
||||||
|
}
|
||||||
|
return points
|
||||||
|
}
|
||||||
|
|
||||||
func (games Games) GameByName(ctx context.Context, uid, name string) (string, error) {
|
func (games Games) GameByName(ctx context.Context, uid, name string) (string, error) {
|
||||||
var result string
|
var result string
|
||||||
err := games.db.Query(ctx, func(rows *sql.Rows) error {
|
err := games.db.Query(ctx, func(rows *sql.Rows) error {
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,20 @@ func (s *S) serveWS(w http.ResponseWriter, r *http.Request) error {
|
||||||
msg["event"] = "A"
|
msg["event"] = "A"
|
||||||
items := []map[string]any{}
|
items := []map[string]any{}
|
||||||
for k, v := range gameState.Players {
|
for k, v := range gameState.Players {
|
||||||
|
if k == s.Session(ctx).ID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name, err := s.games.UserName(ctx, k)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
items = append(items, map[string]any{
|
||||||
|
"name": name,
|
||||||
|
"title": strconv.Itoa(v.Points()),
|
||||||
|
"tags": []map[string]any{
|
||||||
|
map[string]any{"k": "k", "v": "1"},
|
||||||
|
},
|
||||||
|
})
|
||||||
_, _ = k, v
|
_, _ = k, v
|
||||||
}
|
}
|
||||||
slices.SortFunc(items, func(a, b map[string]any) int {
|
slices.SortFunc(items, func(a, b map[string]any) int {
|
||||||
|
|
@ -97,10 +111,8 @@ func (s *S) serveWS(w http.ResponseWriter, r *http.Request) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
points := 0
|
|
||||||
tags := []map[string]any{}
|
tags := []map[string]any{}
|
||||||
for _, kill := range v.Kills {
|
for _, kill := range v.Kills {
|
||||||
points += kill.KillWord.Points
|
|
||||||
tags = append(tags, map[string]any{
|
tags = append(tags, map[string]any{
|
||||||
"k": kill.KillWord.Word,
|
"k": kill.KillWord.Word,
|
||||||
"v": kill.Victim,
|
"v": kill.Victim,
|
||||||
|
|
@ -108,7 +120,7 @@ func (s *S) serveWS(w http.ResponseWriter, r *http.Request) error {
|
||||||
}
|
}
|
||||||
items = append(items, map[string]any{
|
items = append(items, map[string]any{
|
||||||
"name": name,
|
"name": name,
|
||||||
"title": fmt.Sprint(points),
|
"title": fmt.Sprint(v.Points()),
|
||||||
"tags": tags,
|
"tags": tags,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue