Documentation
¶
Overview ¶
Package steam is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.
Package steam defines the engine-facing boundary for Steamworks user stats, achievements, leaderboards and rich presence. Native adapters implement Driver, while tests can use a fake without loading the Steam SDK.
Index ¶
- Variables
- type Driver
- type Entry
- type Platform
- func (p *Platform) Close() error
- func (p *Platform) GetStatFloat(id string, done func(float64, error))
- func (p *Platform) GetStatInt(id string, done func(int64, error))
- func (p *Platform) IndicateAchievementProgress(id string, current, max uint32, done func(error))
- func (p *Platform) Init(done func(Player, error))
- func (p *Platform) Player() Player
- func (p *Platform) Scores(board string, friends bool, limit int, done func([]Entry, error))
- func (p *Platform) SetPresence(key, value string, done func(error))
- func (p *Platform) SetStatFloat(id string, value float64, done func(error))
- func (p *Platform) SetStatInt(id string, value int64, done func(error))
- func (p *Platform) SignedIn() bool
- func (p *Platform) StoreStats(done func(error))
- func (p *Platform) Tick()
- func (p *Platform) Unlock(id string, done func(error))
- func (p *Platform) UpdateAvgRateStat(id string, countThisSession, sessionLength float64, done func(error))
- func (p *Platform) UploadScore(board string, score int64, keepBest bool, done func(error))
- type Player
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnavailable = errors.New("steam: unavailable") // ErrClosed reports a call on a Platform that is nil or has been closed. ErrClosed = errors.New("steam: closed") // ErrUnauthenticated reports that the driver initialized without a signed-in Steam user. ErrUnauthenticated = errors.New("steam: unauthenticated") )
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver interface {
Init(context.Context) (Player, error)
SetAchievement(context.Context, string) error
SetStatInt(context.Context, string, int64) error
SetStatFloat(context.Context, string, float64) error
StoreStats(context.Context) error
UploadScore(context.Context, string, int64, bool) error
QueryScores(context.Context, string, bool, int) ([]Entry, error)
SetRichPresence(context.Context, string, string) error
RunCallbacks()
Shutdown() error
}
Driver is implemented by a Steamworks adapter. Calls are synchronous at the boundary and Platform posts completion callbacks to its core scope.
func NewClientDriver ¶
func NewClientDriver(client *steamworks.Client) Driver
NewClientDriver returns a Driver backed by a shared *steamworks.Client. Because client owns Steamworks initialization, per-frame callback pumping and shutdown, the returned Driver's RunCallbacks and Shutdown are no-ops.
type Platform ¶
type Platform struct {
// contains filtered or unexported fields
}
Platform wraps a Driver for one core scope. Use it from the scope's goroutine; every completion callback runs there through Scope.Post, and none runs once the scope is disposed.
func New ¶
New creates a Steam platform around driver and closes it when cx is disposed. A nil scope or driver returns ErrUnavailable.
Example ¶
New wraps a Steamworks driver for the app's scope, posting each completion callback back to the engine goroutine. The example is compiled but not run: a real driver needs the Steamworks runtime and a running app.
package main
import (
"fmt"
"github.com/nsgo-dev/game/pkg/online/steam"
"github.com/nsgo-dev/nsgo/core"
)
func main() {
var (
cx *core.Scope
driver steam.Driver
)
platform, err := steam.New(cx, driver)
if err != nil {
fmt.Println(err)
return
}
defer platform.Close()
platform.Init(func(player steam.Player, err error) {
if err == nil {
fmt.Println("signed in as", player.PersonaName)
}
})
}
Output:
func (*Platform) Close ¶
Close signs the user out and shuts the driver down. Later calls report ErrClosed; closing again does nothing.
func (*Platform) GetStatFloat ¶
GetStatFloat reads the FLOAT stat id if the underlying driver supports stat reads.
func (*Platform) GetStatInt ¶
GetStatInt reads the INT stat id if the underlying driver supports stat reads.
func (*Platform) IndicateAchievementProgress ¶
IndicateAchievementProgress shows Steam's achievement progress toast if the underlying driver supports it.
func (*Platform) Init ¶
Init initializes the driver and signs the user in. done receives the player, or ErrUnauthenticated when the driver returns no Steam ID, or ErrClosed on a closed Platform.
func (*Platform) Player ¶
Player returns the signed-in user, or the zero Player before Init succeeds and after Close.
func (*Platform) Scores ¶
Scores queries up to limit entries of board, from the global range or, with friends, the player's friends.
func (*Platform) SetPresence ¶
SetPresence sets the rich presence key to value.
func (*Platform) SetStatFloat ¶
SetStatFloat sets the FLOAT stat id. Call StoreStats to commit it to Steam.
func (*Platform) SetStatInt ¶
SetStatInt sets the INT stat id. Call StoreStats to commit it to Steam.
func (*Platform) StoreStats ¶
StoreStats commits the stats and achievements set since the last store.
func (*Platform) Tick ¶
func (p *Platform) Tick()
Tick pumps the driver's Steam callbacks; call it once per fixed step.
func (*Platform) UpdateAvgRateStat ¶
func (p *Platform) UpdateAvgRateStat(id string, countThisSession, sessionLength float64, done func(error))
UpdateAvgRateStat updates an AVGRATE stat with countThisSession over sessionLength seconds if the underlying driver supports it. Call StoreStats to commit it to Steam.