GitHubLoslegen

Die API-Referenz stammt aus den Go-Doc-Kommentaren im Quellcode und ist auf Englisch verfasst.

package eos

import "github.com/nsgo-dev/game/pkg/online/eos"

Übersicht

Package eos is experimental: its API and documented formats may change in a minor release. See the API stability policy. provides the Go boundary for Epic Online Services. The package keeps the callback contract independent of the native SDK so games can use a fake driver in tests and return ErrUnavailable when the SDK is absent.

Index

Variablen

var (
	// ErrUnavailable is returned by New without a driver, and by a native driver when the EOS shared library cannot be loaded.
	ErrUnavailable = errors.New("eos: unavailable")
	// ErrClosed is reported for a request made after Close.
	ErrClosed = errors.New("eos: closed")
	// ErrUnauthenticated is reported by Login without an exchange code and by a request made before Login succeeds.
	ErrUnauthenticated = errors.New("eos: unauthenticated")
	// ErrInvalidConfig is returned by New when a product, sandbox or deployment ID is empty.
	ErrInvalidConfig = errors.New("eos: invalid config")
	// ErrInvalidArgument is reported for an empty ID or an out-of-range argument.
	ErrInvalidArgument = errors.New("eos: invalid argument")
)

Funktionen

func ExchangeCodeFromArgs(args []string) string

ExchangeCodeFromArgs returns the exchange code the Epic launcher passes as -AUTH_PASSWORD=<code> together with -AUTH_TYPE=exchangecode, or "" when args carry no exchange-code login. Pass os.Args[1:].

Typen

type Config struct {
	ProductID    string
	SandboxID    string
	DeploymentID string
	ExchangeCode string
}

Config identifies an Epic product. ExchangeCode is the code the Epic launcher passes with -AUTH_PASSWORD; ExchangeCodeFromArgs reads it from the command line.

type Driver interface {
	Login(exchangeCode string, done func(Player, error))
	UnlockAchievement(id string, done func(error))
	ProgressAchievement(id string, percent float64, done func(error))
	SubmitScore(board string, score int64, done func(error))
	QueryLeaderboard(board string, friends bool, limit int, done func([]LeaderboardEntry, error))
	SetPresence(details, status string, done func(error))
	Tick()
	Close() error
}

Driver is the native boundary implemented by an EOS SDK adapter. Every operation is asynchronous, as in the EOS SDK: a method starts the request and returns, and the driver calls done exactly once when the request completes, normally from inside Tick, where the EOS SDK dispatches its callbacks, or at once when the request cannot start. Platform calls every method and Tick on the engine goroutine and posts each done result back to its scope, so a driver may also call done from another goroutine.

type LeaderboardEntry struct {
	Rank    int
	UserID  string
	Display string
	Score   int64
}

LeaderboardEntry is one row returned by QueryLeaderboard.

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

Platform owns one EOS connection and its driver. Its methods are safe only on the engine goroutine, matching sound and game services. Every done callback runs on the engine goroutine under the scope given to New, never inside the call that started the request; results that arrive after Close or after the scope is disposed are dropped.

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

New creates a platform around an injected driver and closes it when cx is disposed. Native adapters should return ErrUnavailable when the EOS shared library cannot be loaded; a nil driver yields ErrUnavailable.

func (p *Platform) Close() error

Close shuts down the native driver and signs the player out. It is idempotent.

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

Login authenticates with the configured exchange code. On success Player and SignedIn report the account; on failure they report signed out. done may be nil.

func (p *Platform) Player() Player

Player returns the authenticated player, or zero while signed out. It is a reactive read.

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

ProgressAchievement reports achievement progress in [0,100]; other values yield ErrInvalidArgument. done may be nil.

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

QueryLeaderboard loads up to limit global or friends rows from an EOS leaderboard; limit must be positive. done must not be nil.

func (p *Platform) SetPresence(details, status string, done func(error))

SetPresence publishes rich presence details and status. done may be nil.

func (p *Platform) SignedIn() bool

SignedIn reports whether Login succeeded.

func (p *Platform) SubmitScore(board string, score int64, done func(error))

SubmitScore submits a score to a named EOS leaderboard. done may be nil.

func (p *Platform) Tick()

Tick pumps the native EOS callback queue once. Call it every step of the fixed game loop.

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

UnlockAchievement reports an achievement ID to EOS. done may be nil.

type Player struct {
	ProductUserID string
	DisplayName   string
}

Player is the local Epic account returned by Login.