refactor out ws.unstartedMsg
parent
c6da3d17a1
commit
3a83fe7c17
|
|
@ -66,18 +66,7 @@ func (ws WS) Push(ctx context.Context, ugs *UserGameServer) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := map[string]any{
|
var 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>"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if gameState.Started {
|
if gameState.Started {
|
||||||
msg["page"] = "B"
|
msg["page"] = "B"
|
||||||
if gameState.Completed.IsZero() {
|
if gameState.Completed.IsZero() {
|
||||||
|
|
@ -153,18 +142,35 @@ func (ws WS) Push(ctx context.Context, ugs *UserGameServer) error {
|
||||||
msg["items"] = items
|
msg["items"] = items
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
msg["page"] = "A"
|
msg, err = ws.unstartedMsg(ctx, gameState)
|
||||||
items := []map[string]any{}
|
}
|
||||||
for k := range gameState.Players {
|
if err != nil {
|
||||||
name, err := ws.games.UserName(ctx, k)
|
return err
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
items = append(items, map[string]any{"name": name})
|
|
||||||
}
|
|
||||||
msg["items"] = items
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
msgB, _ := json.Marshal(msg)
|
||||||
return ws.c.Write(ctx, 1, msgB)
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue