refactor out ws.unstartedMsg

main
Bel LaPointe 2024-12-15 11:28:42 -07:00
parent c6da3d17a1
commit 3a83fe7c17
1 changed files with 28 additions and 22 deletions

View File

@ -66,18 +66,7 @@ func (ws WS) Push(ctx context.Context, ugs *UserGameServer) error {
return err
}
msg := map[string]any{
"help": strings.Join([]string{
"CARD ASSASSINS (Mobile Ed.)",
"",
"1. Get any target to say any of his or her kill words.",
"2. Click the word to collect points.",
"3. Review new kill words.",
"",
"The game ends when everyone has been assassinated.",
}, "<br>"),
}
var msg map[string]any
if gameState.Started {
msg["page"] = "B"
if gameState.Completed.IsZero() {
@ -153,18 +142,35 @@ func (ws WS) Push(ctx context.Context, ugs *UserGameServer) error {
msg["items"] = items
}
} else {
msg["page"] = "A"
items := []map[string]any{}
for k := range gameState.Players {
name, err := ws.games.UserName(ctx, k)
if err != nil {
return err
}
items = append(items, map[string]any{"name": name})
}
msg["items"] = items
msg, err = ws.unstartedMsg(ctx, gameState)
}
if err != nil {
return err
}
msg["help"] = strings.Join([]string{
"CARD ASSASSINS (Mobile Ed.)",
"",
"1. Get any target to say any of his or her kill words.",
"2. Click the word to collect points.",
"3. Review new kill words.",
"",
"The game ends when everyone has been assassinated.",
}, "<br>")
msgB, _ := json.Marshal(msg)
return ws.c.Write(ctx, 1, msgB)
}
func (ws WS) unstartedMsg(ctx context.Context, gameState GameState) (msg map[string]any, _ error) {
msg["page"] = "A"
items := []map[string]any{}
for k := range gameState.Players {
name, err := ws.games.UserName(ctx, k)
if err != nil {
return nil, err
}
items = append(items, map[string]any{"name": name})
}
msg["items"] = items
return msg, nil
}