Files
chess/internal/client/session/session.go
T
lixen 35ed475904
test / test (push) Canceled after 0s
test / e2e (push) Canceled after 0s
v0.14.0 web replay UI, My games, CLI replay
2026-10-19 16:03:11 -04:00

50 lines
2.0 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
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 }