53 lines
2.2 KiB
Go
53 lines
2.2 KiB
Go
package session
|
|
|
|
import (
|
|
"github.com/lixenwraith/chess/internal/client/api"
|
|
"github.com/lixenwraith/chess/internal/client/replay"
|
|
)
|
|
|
|
// Session maintains client state and configuration
|
|
type Session struct {
|
|
APIBaseURL string
|
|
CurrentGame string
|
|
CurrentUser string
|
|
AuthToken string
|
|
Username string
|
|
LastMoveCount int
|
|
GamesCursor string // next page of the "games" listing
|
|
GamesPage []api.GameSummary // the last "games" page, for "replay <index>"
|
|
Client *api.Client
|
|
// Replay is the stored game being stepped through, nil while live. The
|
|
// live game, user, and poll state above are untouched by a replay.
|
|
Replay *replay.State
|
|
// ReadLine reads the next input line (false at end of input); the pager
|
|
// uses it to wait between screens.
|
|
ReadLine func() (string, bool)
|
|
Verbose bool
|
|
// Game state for prompt
|
|
CurrentGameState *api.GameResponse
|
|
PlayerColor string // "w", "b", or ""
|
|
}
|
|
|
|
// Session interface implementation
|
|
func (s *Session) GetAPIBaseURL() string { return s.APIBaseURL }
|
|
func (s *Session) SetAPIBaseURL(url string) { s.APIBaseURL = url }
|
|
func (s *Session) GetCurrentGame() string { return s.CurrentGame }
|
|
func (s *Session) SetCurrentGame(id string) { s.CurrentGame = id }
|
|
func (s *Session) GetCurrentUser() string { return s.CurrentUser }
|
|
func (s *Session) SetCurrentUser(id string) { s.CurrentUser = id }
|
|
func (s *Session) GetAuthToken() string { return s.AuthToken }
|
|
func (s *Session) SetAuthToken(token string) { s.AuthToken = token }
|
|
func (s *Session) GetUsername() string { return s.Username }
|
|
func (s *Session) SetUsername(name string) { s.Username = name }
|
|
func (s *Session) GetLastMoveCount() int { return s.LastMoveCount }
|
|
func (s *Session) SetLastMoveCount(count int) { s.LastMoveCount = count }
|
|
func (s *Session) GetClient() any { return s.Client }
|
|
func (s *Session) IsVerbose() bool { return s.Verbose }
|
|
func (s *Session) SetGameState(game any) {
|
|
if g, ok := game.(*api.GameResponse); ok {
|
|
s.CurrentGameState = g
|
|
}
|
|
}
|
|
func (s *Session) SetPlayerColor(color string) { s.PlayerColor = color }
|
|
func (s *Session) GetPlayerColor() string { return s.PlayerColor }
|