capacitor-google-game-services
v2.0.0
Published
An android only capacitor plugin for Googles Play game services.
Downloads
2
Readme
capacitor-google-game-services
An android only capacitor plugin for Googles Play game services.
Credits to Google Play game services - Android Samples and OpenForge
Supported Versions
- Capacitor v6
- Google Play Game Services SDK v2:17.0.0
Install
npm install capacitor-google-game-services
npx cap sync
Using the plugin
You will first need to setup your app project with Google Play Game Services. Please follow the steps from their documentation here. If you are using additional features such as saved games, achievements, leaderboards, or translations; there are additional steps to conduct here.
Once all the steps are done, you just need to import the plugin.
import { GoogleGameServices } from "capacitor-google-game-services";
const isAuthenticated = await GoogleGameServices.isAuthenticated();
console.log("User is authenticated: ", isAuthenticated);
API
signIn()
signIn() => Promise<{ isAuthenticated: boolean; }>
Attempts to sign in and returns isAuthenticated as true if succeeded. Sign in is automatically attempted upon plugin load. This is only needed if the automatic sign in failed or was logged out.
Returns: Promise<{ isAuthenticated: boolean; }>
isAuthenticated()
isAuthenticated() => Promise<{ isAuthenticated: boolean; }>
Returns if the player is authenticated with Google Play Games.
Returns: Promise<{ isAuthenticated: boolean; }>
showSavedGamesUI()
showSavedGamesUI() => Promise<any>
Attempts to display Google's default saved games screen, returning the saved game object if selected or saving a new game object if player clicked add.
Returns: Promise<any>
saveGame(...)
saveGame(options: { title: string; data: string; }) => Promise<any>
Uses Google Play Game services snapshot feature to save a JSON Object as bytes.
| Param | Type | Description |
| ------------- | --------------------------------------------- | ------------------------------------------------------------------------ |
| options
| { title: string; data: string; } | The title (key) and data (can be json object) to save to the game object |
Returns: Promise<any>
loadGame()
loadGame() => Promise<{ title: string; data: string; }>
Loads the last selected game with the 'savenameTemp' snapshot.
Returns: Promise<{ title: string; data: string; }>
getCurrentPlayer()
getCurrentPlayer() => Promise<{ player: Player; }>
Returns a player object of the currently signed in player
Returns: Promise<{ player: Player; }>
Interfaces
Player
| Prop | Type |
| ------------------ | ------------------- |
| displayName
| string |
| iconImageUrl
| string |