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 {
|
} else if complete := !gameState.Completed.IsZero(); complete {
|
||||||
msg, err = ws.completeMsg(ctx, gameState)
|
msg, err = ws.completeMsg(ctx, gameState)
|
||||||
} else {
|
} else {
|
||||||
msg, err = ws.incompleteMsg(ctx, gameState)
|
msg, err = ws.inProgressMsg(ctx, ugs, gameState)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -87,12 +87,14 @@ func (ws WS) Push(ctx context.Context, ugs *UserGameServer) error {
|
||||||
"",
|
"",
|
||||||
"The game ends when everyone has been assassinated.",
|
"The game ends when everyone has been assassinated.",
|
||||||
}, "<br>")
|
}, "<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) {
|
func (ws WS) unstartedMsg(ctx context.Context, gameState GameState) (msg map[string]any, _ error) {
|
||||||
msg["page"] = "A"
|
msg["page"] = "A"
|
||||||
|
|
||||||
items := []map[string]any{}
|
items := []map[string]any{}
|
||||||
for k := range gameState.Players {
|
for k := range gameState.Players {
|
||||||
name, err := ws.games.UserName(ctx, k)
|
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})
|
items = append(items, map[string]any{"name": name})
|
||||||
}
|
}
|
||||||
msg["items"] = items
|
msg["items"] = items
|
||||||
|
|
||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws WS) completeMsg(ctx context.Context, gameState GameState) (msg map[string]any, _ error) {
|
func (ws WS) completeMsg(ctx context.Context, gameState GameState) (msg map[string]any, _ error) {
|
||||||
msg["page"] = "B"
|
msg["page"] = "B"
|
||||||
msg["event"] = "B"
|
msg["event"] = "B"
|
||||||
|
|
||||||
items := []map[string]any{}
|
items := []map[string]any{}
|
||||||
for k, v := range gameState.Players {
|
for k, v := range gameState.Players {
|
||||||
name, err := ws.games.UserName(ctx, k)
|
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
|
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["page"] = "B"
|
||||||
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 == ws.Session(ctx).ID {
|
if k == ugs.Session.ID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,7 +151,7 @@ func (ws WS) incompleteMsg(ctx context.Context, gameState GameState) (msg map[st
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := []map[string]any{}
|
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 {
|
for _, private := range v.KillWords.Assignment.Private {
|
||||||
tags = append(tags, map[string]any{
|
tags = append(tags, map[string]any{
|
||||||
"k": private.Word,
|
"k": private.Word,
|
||||||
|
|
@ -160,7 +165,7 @@ func (ws WS) incompleteMsg(ctx context.Context, gameState GameState) (msg map[st
|
||||||
"v": public.Points,
|
"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
|
return a.Victim == k
|
||||||
}) {
|
}) {
|
||||||
tags = append(tags, map[string]any{
|
tags = append(tags, map[string]any{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue