Documentation
¶
Overview ¶
Package profile keeps what goes with a person from PC to PC: playtime, achievements and settings. It lives in %APPDATA%\Seaglass\Profile, a folder Syncer syncs between PCs and backs up.
Every PC writes only its own file per person, <owner>\<pc>.json, and reads the others: two PCs never write the same file, so syncing never makes conflict copies, and nothing is lost when PCs play offline at the same time. A person's playtime is the sum of their files, their last play and achievements the newest and the union, and their settings those saved last. The owner is the Syncer account playing on this PC, or Shared when there's none.
Index ¶
- Constants
- func ValidOwner(id string) bool
- func ValidPC(id string) bool
- type File
- type Game
- type Merged
- type Store
- func (s *Store) AddAchievements(key, title string, unlocked map[string]int64)
- func (s *Store) AddPlaytime(key, title string, secs int64)
- func (s *Store) Dir() string
- func (s *Store) Flush() error
- func (s *Store) Fresh() bool
- func (s *Store) Healthy() bool
- func (s *Store) Merged() Merged
- func (s *Store) Owner() string
- func (s *Store) Played(key, title string, t int64)
- func (s *Store) Seed(games map[string]Game, settings json.RawMessage)
- func (s *Store) SetOwner(owner string) (bool, error)
- func (s *Store) SetSettings(v json.RawMessage, t int64)
- func (s *Store) SettingsAt() int64
- type Total
Constants ¶
Shared owns what was played while no Syncer account was in use.
Variables ¶
This section is empty.
Functions ¶
func ValidOwner ¶
ValidOwner reports whether id can name an owner's folder.
Types ¶
type File ¶
type File struct {
Version int `json:"version"`
PC string `json:"pc"` // the PC's name, for people reading the file
Updated int64 `json:"updated"`
Games map[string]*Game `json:"games"`
Settings json.RawMessage `json:"settings,omitempty"`
SettingsAt int64 `json:"settingsAt,omitempty"` // when those settings were saved (0: never)
}
File is one PC's file for one owner.
type Game ¶
type Game struct {
Title string `json:"title,omitempty"` // for people reading the file
Playtime int64 `json:"playtime,omitempty"` // seconds played on this PC
LastPlayed int64 `json:"lastPlayed,omitempty"` // unix seconds
Achievements map[string]int64 `json:"achievements,omitempty"`
}
Game is one game in one PC's file.
type Merged ¶
type Merged struct {
Games map[string]Total
Settings json.RawMessage // the newest settings
SettingsAt int64
SettingsPC string // the PC that saved them
}
Merged is everything an owner has, over all their PCs.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is this PC's side of the profile. Safe for concurrent use.
func Open ¶
Open opens the profile in dir for this PC, owned by Shared until SetOwner says otherwise.
func (*Store) AddAchievements ¶
AddAchievements records unlocked achievements (id → unlock time, 0 when unknown).
func (*Store) AddPlaytime ¶
AddPlaytime records seconds played on this PC.
func (*Store) Fresh ¶
Fresh reports whether this PC has no file yet for any owner: nothing has been recorded on it, so what the library knows can be carried over.
func (*Store) Healthy ¶
Healthy reports whether this PC's file could be read (or didn't exist yet). When it couldn't, totals shouldn't replace anything.
func (*Store) Merged ¶
Merged sums up the owner's files from every PC. Files other PCs wrote are only read again when they changed.
func (*Store) Seed ¶
func (s *Store) Seed(games map[string]Game, settings json.RawMessage)
Seed carries over what this PC knew before the profile existed. It only does something while this PC has no file yet.
func (*Store) SetOwner ¶
SetOwner changes whose profile this PC adds to. What this PC recorded while no account was in use goes to the first account it gets (usually the person the PC belongs to). It reports whether the owner changed.
func (*Store) SetSettings ¶
func (s *Store) SetSettings(v json.RawMessage, t int64)
SetSettings records this PC's settings, saved at t. The newest settings of all the owner's PCs are the ones that count.
func (*Store) SettingsAt ¶
SettingsAt is when this PC's settings were saved, on this PC or on the PC they were taken from.