store

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package store provides persistent storage for saved games.

Index

Constants

View Source
const (
	StatusNew        GameStatus = "new"
	StatusInProgress GameStatus = "in_progress"
	StatusCompleted  GameStatus = "completed"
	StatusAbandoned  GameStatus = "abandoned"

	RunKindNormal RunKind = "normal"
	RunKindDaily  RunKind = "daily"
	RunKindWeekly RunKind = "weekly"
	RunKindSeeded RunKind = "seeded"
)

Variables

This section is empty.

Functions

func CanonicalGameID added in v1.8.0

func CanonicalGameID(gameType string) string

func CanonicalModeID added in v1.8.0

func CanonicalModeID(mode string) string

func RunDateForName added in v1.8.0

func RunDateForName(name string) *time.Time

func SeedTextForName added in v1.8.0

func SeedTextForName(name string) string

func WeeklyIdentityForName added in v1.8.0

func WeeklyIdentityForName(name string) (year, week, index int, ok bool)

Types

type CategoryStat added in v1.5.0

type CategoryStat struct {
	GameType       string
	TotalAttempts  int
	TotalVictories int
	TotalAbandoned int
	TimesDaily     int
	DailyVictories int
	PreferredMode  string
}

CategoryStat holds aggregate statistics for a single game category.

type GameRecord

type GameRecord struct {
	ID           int64
	Name         string
	GameID       string
	GameType     string
	ModeID       string
	Mode         string
	InitialState string
	SaveState    string
	Status       GameStatus
	RunKind      RunKind
	RunDate      *time.Time
	WeekYear     int
	WeekNumber   int
	WeekIndex    int
	SeedText     string
	CreatedAt    time.Time
	UpdatedAt    time.Time
	CompletedAt  *time.Time
}

type GameStatus

type GameStatus string

type ModeStat added in v1.5.0

type ModeStat struct {
	GameType       string
	Mode           string
	Victories      int
	DailyVictories int
	WeeklyBonusXP  int
}

ModeStat holds per-mode victory counts for XP computation.

type RunKind added in v1.8.0

type RunKind string

func RunKindForName added in v1.8.0

func RunKindForName(name string) RunKind

type Store

type Store struct {
	// contains filtered or unexported fields
}

func Open

func Open(dbPath string) (*Store, error)

Open creates the directory if needed, opens the database, creates the table, and enables WAL mode.

func (*Store) Close

func (s *Store) Close() error

func (*Store) CreateGame

func (s *Store) CreateGame(rec *GameRecord) error

CreateGame inserts a new game record and sets rec.ID.

func (*Store) GetCategoryStats added in v1.5.0

func (s *Store) GetCategoryStats() ([]CategoryStat, error)

GetCategoryStats returns aggregate stats per game category from the category_stats view.

func (*Store) GetCompletedWeeklyGauntlets added in v1.8.0

func (s *Store) GetCompletedWeeklyGauntlets() (int, error)

GetCompletedWeeklyGauntlets returns the number of ISO weeks whose highest completed weekly index is 99.

func (*Store) GetCurrentWeeklyHighestCompletedIndex added in v1.8.0

func (s *Store) GetCurrentWeeklyHighestCompletedIndex(year, week int) (int, error)

GetCurrentWeeklyHighestCompletedIndex returns the highest completed weekly index for the provided ISO week-year.

func (*Store) GetDailyGame added in v1.3.0

func (s *Store) GetDailyGame(name string) (*GameRecord, error)

GetDailyGame looks up a daily game by name, including abandoned ones. Daily puzzles should always be resumable regardless of status. Returns nil, nil if no matching game is found.

func (*Store) GetDailyStreakDates added in v1.5.0

func (s *Store) GetDailyStreakDates() ([]time.Time, error)

GetDailyStreakDates returns distinct completion dates for daily games, ordered most recent first. Dates are in local time with time set to midnight.

func (*Store) GetDeterministicGame added in v1.8.0

func (s *Store) GetDeterministicGame(name string) (*GameRecord, error)

GetDeterministicGame looks up an exact deterministic game name, including abandoned rows.

func (*Store) GetGameByName

func (s *Store) GetGameByName(name string) (*GameRecord, error)

GetGameByName looks up a single non-abandoned game by its unique name. Returns nil, nil if no matching game is found.

func (*Store) GetModeStats added in v1.5.0

func (s *Store) GetModeStats() ([]ModeStat, error)

GetModeStats returns per-mode victory counts from the mode_stats view.

func (*Store) GetWeeklyGame added in v1.8.0

func (s *Store) GetWeeklyGame(year, weekNumber, index int) (*GameRecord, error)

GetWeeklyGame looks up a weekly game by canonical week and index.

func (*Store) ListAllGames

func (s *Store) ListAllGames() ([]GameRecord, error)

ListAllGames returns all games (including abandoned) ordered by most recently updated.

func (*Store) ListGames

func (s *Store) ListGames() ([]GameRecord, error)

ListGames returns all non-abandoned games ordered by most recently updated.

func (*Store) ListWeeklyGames added in v1.8.0

func (s *Store) ListWeeklyGames(year, weekNumber int) ([]GameRecord, error)

ListWeeklyGames returns all records matching the canonical weekly prefix for the provided ISO week-year, including abandoned rows.

func (*Store) NameExists

func (s *Store) NameExists(name string) (bool, error)

NameExists checks whether a game with the given name already exists.

func (*Store) UpdateSaveState

func (s *Store) UpdateSaveState(id int64, saveState string) error

UpdateSaveState updates save_state and updated_at for the given game.

func (*Store) UpdateStatus

func (s *Store) UpdateStatus(id int64, status GameStatus) error

UpdateStatus updates the status (and completed_at if completed) for the given game.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL