ra-google-play-service
v0.0.1
Published
Expose Google Play Game Service API
Readme
ra-google-play-service
Expose Google Play Game Service API
Install
npm install ra-google-play-service
npx cap syncAPI
signIn()signOut()isSignedIn()getPlayerInfo()showLeaderboard(...)showAllLeaderboards()submitScore(...)showAchievements()unlockAchievement(...)incrementAchievement(...)revealAchievement(...)saveGameData(...)loadGameData(...)showSavedGames(...)addListener('signInStatusChanged', ...)removeAllListeners()- Interfaces
signIn()
signIn() => Promise<SignInResult>Sign in the user to Google Play Games Services
Returns: Promise<SignInResult>
signOut()
signOut() => Promise<void>Sign out the user from Google Play Games Services
isSignedIn()
isSignedIn() => Promise<{ isSignedIn: boolean; }>Check if user is signed in to Google Play Games Services
Returns: Promise<{ isSignedIn: boolean; }>
getPlayerInfo()
getPlayerInfo() => Promise<PlayerInfo>Get the currently signed in player information
Returns: Promise<PlayerInfo>
showLeaderboard(...)
showLeaderboard(options: LeaderboardOptions) => Promise<void>Show the leaderboard UI for a specific leaderboard
| Param | Type | Description |
| ------------- | ----------------------------------------------------------------- | --------------------------------- |
| options | LeaderboardOptions | Options containing leaderboard ID |
showAllLeaderboards()
showAllLeaderboards() => Promise<void>Show all leaderboards UI
submitScore(...)
submitScore(options: SubmitScoreOptions) => Promise<void>Submit a score to a leaderboard
| Param | Type | Description |
| ------------- | ----------------------------------------------------------------- | ------------------------------------------- |
| options | SubmitScoreOptions | Options containing leaderboard ID and score |
showAchievements()
showAchievements() => Promise<void>Show the achievements UI
unlockAchievement(...)
unlockAchievement(options: AchievementOptions) => Promise<void>Unlock an achievement
| Param | Type | Description |
| ------------- | ----------------------------------------------------------------- | --------------------------------- |
| options | AchievementOptions | Options containing achievement ID |
incrementAchievement(...)
incrementAchievement(options: IncrementAchievementOptions) => Promise<void>Increment an achievement with the specified amount
| Param | Type | Description |
| ------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------------ |
| options | IncrementAchievementOptions | Options containing achievement ID and increment amount |
revealAchievement(...)
revealAchievement(options: AchievementOptions) => Promise<void>Reveal a hidden achievement
| Param | Type | Description |
| ------------- | ----------------------------------------------------------------- | --------------------------------- |
| options | AchievementOptions | Options containing achievement ID |
saveGameData(...)
saveGameData(options: SaveGameOptions) => Promise<SaveResult>Save game data to the cloud
| Param | Type | Description |
| ------------- | ----------------------------------------------------------- | -------------------------------------------- |
| options | SaveGameOptions | Options containing save data and description |
Returns: Promise<SaveResult>
loadGameData(...)
loadGameData(options: LoadGameOptions) => Promise<LoadGameResult>Load saved game data from the cloud
| Param | Type | Description |
| ------------- | ----------------------------------------------------------- | ------------------------------ |
| options | LoadGameOptions | Options for loading saved game |
Returns: Promise<LoadGameResult>
showSavedGames(...)
showSavedGames(options: ShowSavedGamesOptions) => Promise<LoadGameResult>Show the saved games UI
| Param | Type | Description |
| ------------- | ----------------------------------------------------------------------- | ---------------------------------- |
| options | ShowSavedGamesOptions | Options for showing saved games UI |
Returns: Promise<LoadGameResult>
addListener('signInStatusChanged', ...)
addListener(eventName: 'signInStatusChanged', listenerFunc: (result: SignInResult) => void) => Promise<PluginListenerHandle>Add listener for sign-in state changes
| Param | Type | Description |
| ------------------ | -------------------------------------------------------------------------- | ------------------- |
| eventName | 'signInStatusChanged' | Event to listen for |
| listenerFunc | (result: SignInResult) => void | Callback function |
Returns: Promise<PluginListenerHandle>
removeAllListeners()
removeAllListeners() => Promise<void>Remove all listeners for this plugin
Interfaces
SignInResult
| Prop | Type | Description |
| ----------------- | -------------------- | ---------------------------------------------- |
| isSignedIn | boolean | Whether the user is signed in |
| playerId | string | Player ID if signed in |
| displayName | string | Player display name if signed in |
| imageUrl | string | URL to the player's profile image if signed in |
| error | string | Error message if sign in failed |
PlayerInfo
| Prop | Type | Description |
| ----------------- | ------------------- | --------------------------------- |
| playerId | string | Player ID |
| displayName | string | Player display name |
| imageUrl | string | URL to the player's profile image |
LeaderboardOptions
| Prop | Type | Description |
| ------------------- | ------------------- | ------------------------------------------------ |
| leaderboardId | string | Leaderboard ID as defined in Google Play Console |
SubmitScoreOptions
| Prop | Type | Description |
| ----------- | ------------------- | ---------------------------------- |
| score | number | Score to submit to the leaderboard |
AchievementOptions
| Prop | Type | Description |
| ------------------- | ------------------- | ------------------------------------------------ |
| achievementId | string | Achievement ID as defined in Google Play Console |
IncrementAchievementOptions
| Prop | Type | Description |
| ----------- | ------------------- | -------------------------------------- |
| steps | number | Amount to increment the achievement by |
SaveResult
| Prop | Type | Description |
| ------------- | -------------------- | ---------------------------- |
| success | boolean | Whether save was successful |
| saveId | string | Save ID of the saved game |
| error | string | Error message if save failed |
SaveGameOptions
| Prop | Type | Description |
| ----------------- | ------------------- | ----------------------------------------------- |
| saveId | string | Unique identifier for the save |
| data | string | Save data as string (will be encoded as needed) |
| description | string | Human readable description of the save |
LoadGameResult
| Prop | Type | Description |
| --------------------------- | -------------------- | ------------------------------------ |
| success | boolean | Whether data was successfully loaded |
| saveId | string | Save ID that was loaded |
| data | string | The loaded save data |
| description | string | Description of the save |
| lastModifiedTimestamp | number | Last modified timestamp |
| error | string | Error message if load failed |
LoadGameOptions
| Prop | Type | Description |
| ------------ | ------------------- | -------------------------------------- |
| saveId | string | Unique identifier for the save to load |
ShowSavedGamesOptions
| Prop | Type | Description |
| -------------------- | -------------------- | ----------------------------------- |
| title | string | Title to show in the saved games UI |
| allowAddButton | boolean | Whether to allow creating new saves |
| allowDelete | boolean | Whether to allow deleting saves |
| maxSavedGames | number | Maximum number of saves to show |
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
