steam

package
v0.4.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnavailable reports that no Steamworks driver is available: New was given a nil scope or driver.
	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 Entry

type Entry struct {
	Rank                 int
	SteamID, PersonaName string
	Score                int64
}

Entry is one leaderboard row.

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

func New(cx *core.Scope, driver Driver) (*Platform, error)

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)
		}
	})
}

func (*Platform) Close

func (p *Platform) Close() error

Close signs the user out and shuts the driver down. Later calls report ErrClosed; closing again does nothing.

func (*Platform) GetStatFloat

func (p *Platform) GetStatFloat(id string, done func(float64, error))

GetStatFloat reads the FLOAT stat id if the underlying driver supports stat reads.

func (*Platform) GetStatInt

func (p *Platform) GetStatInt(id string, done func(int64, error))

GetStatInt reads the INT stat id if the underlying driver supports stat reads.

func (*Platform) IndicateAchievementProgress

func (p *Platform) IndicateAchievementProgress(id string, current, max uint32, done func(error))

IndicateAchievementProgress shows Steam's achievement progress toast if the underlying driver supports it.

func (*Platform) Init

func (p *Platform) Init(done func(Player, error))

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

func (p *Platform) Player() Player

Player returns the signed-in user, or the zero Player before Init succeeds and after Close.

func (*Platform) Scores

func (p *Platform) Scores(board string, friends bool, limit int, done func([]Entry, error))

Scores queries up to limit entries of board, from the global range or, with friends, the player's friends.

func (*Platform) SetPresence

func (p *Platform) SetPresence(key, value string, done func(error))

SetPresence sets the rich presence key to value.

func (*Platform) SetStatFloat

func (p *Platform) SetStatFloat(id string, value float64, done func(error))

SetStatFloat sets the FLOAT stat id. Call StoreStats to commit it to Steam.

func (*Platform) SetStatInt

func (p *Platform) SetStatInt(id string, value int64, done func(error))

SetStatInt sets the INT stat id. Call StoreStats to commit it to Steam.

func (*Platform) SignedIn

func (p *Platform) SignedIn() bool

SignedIn reports whether Init has signed in a Steam user.

func (*Platform) StoreStats

func (p *Platform) StoreStats(done func(error))

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) Unlock

func (p *Platform) Unlock(id string, done func(error))

Unlock sets the achievement id. Call StoreStats to commit it to Steam.

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.

func (*Platform) UploadScore

func (p *Platform) UploadScore(board string, score int64, keepBest bool, done func(error))

UploadScore submits score to board. With keepBest, Steam keeps the player's better score; otherwise it overwrites it.

type Player

type Player struct{ SteamID, PersonaName string }

Player is the signed-in Steam user.

Jump to

Keyboard shortcuts

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