refactors
parent
e8817f9e74
commit
8d0ded9ee9
|
|
@ -72,7 +72,7 @@ func (ws WS) Push(ctx context.Context, ugs *UserGameServer) error {
|
|||
} else if complete := !gameState.Completed.IsZero(); complete {
|
||||
msg, err = ws.completeMsg(ctx, gameState)
|
||||
} else {
|
||||
msg, err = ws.incompleteMsg(ctx, gameState)
|
||||
msg, err = ws.inProgressMsg(ctx, ugs, gameState)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -87,12 +87,14 @@ func (ws WS) Push(ctx context.Context, ugs *UserGameServer) error {
|
|||
"",
|
||||
"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)
|
||||
|
|
@ -102,12 +104,14 @@ func (ws WS) unstartedMsg(ctx context.Context, gameState GameState) (msg map[str
|
|||
items = append(items, map[string]any{"name": name})
|
||||
}
|
||||
msg["items"] = items
|
||||
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
func (ws WS) completeMsg(ctx context.Context, gameState GameState) (msg map[string]any, _ error) {
|
||||
msg["page"] = "B"
|
||||
msg["event"] = "B"
|
||||
|
||||
items := []map[string]any{}
|
||||
for k, v := range gameState.Players {
|
||||
name, err := ws.games.UserName(ctx, k)
|
||||
|
|
@ -131,12 +135,13 @@ func (ws WS) completeMsg(ctx context.Context, gameState GameState) (msg map[stri
|
|||
return msg, nil
|
||||
}
|
||||
|
||||
func (ws WS) incompleteMsg(ctx context.Context, gameState GameState) (msg map[string]any, _ error) {
|
||||
func (ws WS) inProgressMsg(ctx context.Context, ugs *UserGameServer, gameState GameState) (msg map[string]any, _ error) {
|
||||
msg["page"] = "B"
|
||||
msg["event"] = "A"
|
||||
|
||||
items := []map[string]any{}
|
||||
for k, v := range gameState.Players {
|
||||
if k == ws.Session(ctx).ID {
|
||||
if k == ugs.Session.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -146,7 +151,7 @@ func (ws WS) incompleteMsg(ctx context.Context, gameState GameState) (msg map[st
|
|||
}
|
||||
|
||||
tags := []map[string]any{}
|
||||
if self := gameState.Players[ws.Session(ctx).ID]; self.KillWords.Assignee == k {
|
||||
if self := gameState.Players[ugs.Session.ID]; self.KillWords.Assignee == k {
|
||||
for _, private := range v.KillWords.Assignment.Private {
|
||||
tags = append(tags, map[string]any{
|
||||
"k": private.Word,
|
||||
|
|
@ -160,7 +165,7 @@ func (ws WS) incompleteMsg(ctx context.Context, gameState GameState) (msg map[st
|
|||
"v": public.Points,
|
||||
})
|
||||
}
|
||||
if self := gameState.Players[ws.Session(ctx).ID]; !slices.ContainsFunc(self.Kills, func(a Kill) bool {
|
||||
if self := gameState.Players[ugs.Session.ID]; !slices.ContainsFunc(self.Kills, func(a Kill) bool {
|
||||
return a.Victim == k
|
||||
}) {
|
||||
tags = append(tags, map[string]any{
|
||||
|
|
|
|||
Loading…
Reference in New Issue