games: a ladder you climb against the clock
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"pete/internal/games/cards"
|
||||
"pete/internal/games/hangman"
|
||||
"pete/internal/games/klondike"
|
||||
"pete/internal/games/trivia"
|
||||
"pete/internal/storage"
|
||||
)
|
||||
|
||||
@@ -189,6 +190,9 @@ type tableView struct {
|
||||
Solitaire *solitaireView `json:"solitaire,omitempty"`
|
||||
SolEvents []solEventView `json:"sol_events,omitempty"`
|
||||
|
||||
Trivia *triviaView `json:"trivia,omitempty"`
|
||||
TrivEvents []trivia.Event `json:"triv_events,omitempty"`
|
||||
|
||||
Rake float64 `json:"rake_pct"`
|
||||
}
|
||||
|
||||
@@ -239,6 +243,16 @@ func (s *Server) table(user string) (tableView, error) {
|
||||
}
|
||||
sv := viewSolitaire(g)
|
||||
v.Solitaire = &sv
|
||||
case gameTrivia:
|
||||
var g trivia.State
|
||||
if err := json.Unmarshal(live.State, &g); err != nil {
|
||||
return s.dropUnreadable(user, v, err)
|
||||
}
|
||||
// The clock does not stop for a reload: Left is measured from the AskedAt
|
||||
// the server stamped, so a player who refreshes to buy themselves a fresh
|
||||
// twenty seconds finds the countdown exactly where they left it.
|
||||
tv := viewTrivia(g, time.Now())
|
||||
v.Trivia = &tv
|
||||
default:
|
||||
return s.dropUnreadable(user, v, fmt.Errorf("unknown game %q", live.Game))
|
||||
}
|
||||
@@ -494,6 +508,7 @@ const (
|
||||
gameBlackjack = "blackjack"
|
||||
gameHangman = "hangman"
|
||||
gameSolitaire = "solitaire"
|
||||
gameTrivia = "trivia"
|
||||
)
|
||||
|
||||
// finished is what commit needs to know about a game it's writing back: enough
|
||||
|
||||
Reference in New Issue
Block a user