profile

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

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

View Source
const Shared = "shared"

Shared owns what was played while no Syncer account was in use.

Variables

This section is empty.

Functions

func ValidOwner

func ValidOwner(id string) bool

ValidOwner reports whether id can name an owner's folder.

func ValidPC

func ValidPC(id string) bool

ValidPC reports whether id can name a PC's file.

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

func Open(dir, pc, pcName string) (*Store, error)

Open opens the profile in dir for this PC, owned by Shared until SetOwner says otherwise.

func (*Store) AddAchievements

func (s *Store) AddAchievements(key, title string, unlocked map[string]int64)

AddAchievements records unlocked achievements (id → unlock time, 0 when unknown).

func (*Store) AddPlaytime

func (s *Store) AddPlaytime(key, title string, secs int64)

AddPlaytime records seconds played on this PC.

func (*Store) Dir

func (s *Store) Dir() string

Dir is the profile folder.

func (*Store) Flush

func (s *Store) Flush() error

Flush writes this PC's file now.

func (*Store) Fresh

func (s *Store) Fresh() bool

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

func (s *Store) Healthy() bool

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

func (s *Store) Merged() Merged

Merged sums up the owner's files from every PC. Files other PCs wrote are only read again when they changed.

func (*Store) Owner

func (s *Store) Owner() string

Owner is whose profile this PC adds to.

func (*Store) Played

func (s *Store) Played(key, title string, t int64)

Played records that a game was started now (or at t).

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

func (s *Store) SetOwner(owner string) (bool, error)

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

func (s *Store) SettingsAt() int64

SettingsAt is when this PC's settings were saved, on this PC or on the PC they were taken from.

type Total

type Total struct {
	Playtime     int64
	LastPlayed   int64
	Achievements map[string]int64 // id → unlock time (0 when unknown)
}

Total is one game summed over an owner's PCs.

Jump to

Keyboard shortcuts

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