SMKS
SMKS

Reputation: 179

Cloud storage for web client library?

I want to use cloud storage for my game for 3 platforms. So you can play on the web, then continue on your mobile for example.

I am looking at the API documentation, and I can only see support for getting snapshots. I want to create a new snapshot and then save it. It shows how to do this for mobiles but not web?

Surely the service doesn't limit you in this way. It would destroy the user experience.

Thanks, Shaun.

Upvotes: 2

Views: 116

Answers (3)

Clayton Wilkinson
Clayton Wilkinson

Reputation: 4572

Unfortunately as you know there is no API to write a Saved Game using the web API. If you want to support web and mobile game saving, you'll have to implement it yourself. An easy way to do that is to use the Application Data Folder for Google Drive. This allows your application to store data in a hidden directory on the player's drive account. This API is also available on Android (https://developers.google.com/drive/android/appfolder) and even iOS (https://developers.google.com/drive/ios/).

What you miss out on by not using the Play Game Services is primarily some caching logic on the client and the user interface for selecting the snapshot. If you eliminate the caching logic, you also eliminate the need for complex conflict resolution (assuming you use a 'last write wins' approach)

At a high level the steps would be:

  1. Create a new application on the Google API console for the platforms you want to support.

  2. Implement login in your game (this would be the same as if you are using Saved Games via Play Game Services.

  3. Use the specific client Id for the correct platform to access the app data for your application.
  4. Implement a UI to select an existing snapshot or create a new one.

Upvotes: 1

Abhishek
Abhishek

Reputation: 1261

As I understand your question, there are the following scenarios possible in your example

  1. Player playing on mobile, saved the game, accessed the game next time on mobile
  2. Player playing on mobile, saved the game, accessed the game next time on Web
  3. Player playing on Web, saved the game, accessed the game next time on mobile
  4. Player playing on Web, saved the game, accessed the game next time on Web

I am assuming your game has complex logic requiring client-server implementation. And given the discussion above, I am assuming you want to save the game in Google Play Game Services (as opposed to your own web Server). In this case, for scenario 1 and 3 above, you will retrieve the Snapshot as demonstrated in the answer by eduyano earlier.

  Snapshots.OpenSnapshotResult open = Games.Snapshots.open(
        mGoogleApiClient, name, create).await();

if (!open.getStatus().isSuccess()) {
    throw new RuntimeException("or whatever");
}

Snapshot snapshot = open.getSnapshot();
snapshot.getSnapshotContents().writeBytes(mySaveGame);

However, for scenario 2 and 4 above, you will need to use the REST API services for 'Play Games Services for Web'.

So first you will have to make the HTTP request to get the Player ID GET https://www.googleapis.com/games/v1/players/playerId

Subsequently, you will need to know the Snapshot IDs saved against this Player. So make another HTTP request GET https://www.googleapis.com/games/v1/players/playerId/snapshots

For the Snapshot ID retrieved, make the HTTP request to retrieve the relevant Snapshot. It will need authorisation. At this point a JSON object corresponding to the saved Snapshot will be returned.

I hope this helps... And I am assuming you will know how to load the snapshot once the JSON object is returned. Feel free to ask for further clarification.

More details at https://developers.google.com/games/services/web/api/snapshots

Upvotes: 0

eduyayo
eduyayo

Reputation: 2038

Here, you create the savegame by name if not exists:

    Snapshots.OpenSnapshotResult open = Games.Snapshots.open(
            mGoogleApiClient, name, create).await();

    if (!open.getStatus().isSuccess()) {
        throw new RuntimeException("or whatever");
    }

    Snapshot snapshot = open.getSnapshot();
    snapshot.getSnapshotContents().writeBytes(mySaveGame);

create is a boolean telling you want to create a new one when it does not exist.

name is the savegame name.

mySaveGame is my binary blob to be stored.

Upvotes: 0

Related Questions