Documentation
¶
Overview ¶
Package gameservices provides a thin, provider-neutral API for platform game services: local player authentication, achievements, leaderboards, and native Game Center / Play Games UI overlays.
Operations run asynchronously and invoke their callbacks on the engine goroutine via core.Scope.Post so frames are never blocked and callbacks can safely update reactive signals. Check cx.Env().CanUseGameServices() to adapt UI on platforms without a native game service backend (Windows, Linux, the web, watchOS and mini programs), where calls answer ErrUnsupported.
Index ¶
- Constants
- Variables
- func Authenticate(cx *core.Scope, done func(Player, error))
- func LoadScores(cx *core.Scope, leaderboardID string, scope PlayerScope, timeScope TimeScope, ...)
- func ReportAchievement(cx *core.Scope, id string, percent float64, done func(error))
- func ShowAchievements(cx *core.Scope)
- func ShowLeaderboard(cx *core.Scope, leaderboardID string)
- func SubmitScore(cx *core.Scope, leaderboardID string, score int64, done func(error))
- type Achievement
- type Player
- type PlayerScope
- type ScoreEntry
- type TimeScope
Constants ¶
const ( AllTime = driver.GameTimeAllTime Week = driver.GameTimeWeek Today = driver.GameTimeToday )
Leaderboard time scopes.
const ( Global = driver.GamePlayersGlobal Friends = driver.GamePlayersFriends )
Leaderboard player scopes.
Variables ¶
var ( // ErrUnsupported is returned when the platform has no native game service // backend (core.Env.CanUseGameServices is false). ErrUnsupported = driver.ErrGameServicesUnsupported // reached or is not enabled in the current environment. ErrUnavailable = driver.ErrGameServicesUnavailable // ErrUnauthenticated is returned when an operation requires a signed-in // player and none is authenticated. ErrUnauthenticated = driver.ErrGameServicesUnauthenticated // ErrCancelled is returned when the user dismisses or cancels sign-in. ErrCancelled = driver.ErrGameServicesCancelled )
Sentinel errors returned by package gameservices.
Functions ¶
func Authenticate ¶
Authenticate signs the local player into the platform game service (such as Game Center on Apple platforms or Play Games Services on Android) and calls done on the engine goroutine with the authenticated Player or an error.
func LoadScores ¶
func LoadScores(cx *core.Scope, leaderboardID string, scope PlayerScope, timeScope TimeScope, limit int, done func([]ScoreEntry, error))
LoadScores loads up to limit ranked entries from leaderboardID filtered by scope and timeScope, and calls done on the engine goroutine with the entries or an error. Non-positive limits default to 25 and values above 100 are clamped to 100.
func ReportAchievement ¶
ReportAchievement reports completion progress for achievement id, clamping percent to the range 0..100 (100 unlocks the achievement), and calls done on the engine goroutine once the platform accepts or rejects the update.
func ShowAchievements ¶
ShowAchievements presents the platform's native achievements UI overlay when supported and authenticated; it does nothing where unsupported.
func ShowLeaderboard ¶
ShowLeaderboard presents the platform's native leaderboard UI overlay for leaderboardID when supported and authenticated; it does nothing when unsupported or when leaderboardID is empty.
Types ¶
type Achievement ¶
type Achievement = driver.GameAchievement
Achievement describes an achievement's reported completion progress (0..100).
type Player ¶
type Player = driver.GamePlayer
Player identifies the local player signed into the platform game service.
type PlayerScope ¶
type PlayerScope = driver.GamePlayerScope
PlayerScope selects which players LoadScores includes: Global or Friends.
type ScoreEntry ¶
type ScoreEntry = driver.GameScoreEntry
ScoreEntry is one ranked leaderboard row returned by LoadScores.
type TimeScope ¶
type TimeScope = driver.GameTimeScope
TimeScope selects the time window for LoadScores: AllTime, Week or Today.