Skip to content

quarter-spiral/sdk-app

Repository files navigation

Quarter Spiral Game Developer SDK

This SDK is the interface between your game and the Quarter Spiral platform. It's platform independent so that you can use the same tools and API no matter if you are developing flash or HTML5 games.

HTML5

Setup

Include this script tag on every page you want to use the SDK from:

<script src="http://sdk-app.herokuapp.com/javascripts/sdk.js" type="text/javascript"></script>

Now initialize the SDK in your JavaScript:

QS.setup().then(function (qs) {
    
})

Inside of that function you now have access to the qs objects which comes with some nifty helpers to make your life easier.

Make sure to call QS.setup only once on every page!

If a player is not logged in when playing the game (e.g. when playing through an embed on a third party website) the SDK will not setup! It will reject the promise. Handle that case like this:

QS.setup().then(function (qs) {
  // success!
}, function(error) {
  // Not setup. Log the reason:
  console.log(error.message)
})

Retrieve information about the player

QS.setup().then(function (qs) {
  qs.retrievePlayerInfo().then(function (player) {
    console.log("Current player:")
    console.log("Name", player.name)
    console.log("Email", player.email)
  }
})

The retrievePlayerInfo call gives you a player object that holds information about the currently logged in player. You can access it's name, email and uuid which is it's unique identifier within the Quarter Spiral universe.

In some cases an email address might not be present. For the time being we return [email protected] in these cases but this will be subject to change.

Manage player data

Quarter Spiral lets you save data for every player that plays your game.

QS.setup().then(function (qs) {
  qs.setPlayerData(
    {tutorialPlayed: true, highScore: 105}
  ).then(function (data) {
    console.log("Player data saved.")
    console.log("Saved data:", data)
  })
})

This call will overwrite all data that was previously stored for this player. If you only want to adjust a single value you can do that:

QS.setup().then(function (qs) {
  qs.setPlayerData('highScore', 120).then(function (data) {
    console.log("Player data saved.")
    console.log("Saved data:", data)
  })
})

Even of you only set a single value you will always get back the full set of stored data for that player in the then phase.

There is also a convenient way to retrieve the current player's data:

QS.setup().then(function (qs) {
  qs.retrievePlayerData().then(function (data) {
    console.log("Player data loaded:", data)
  })
})

Retrieve data for any QS player

You can retrieve information about players with the QS SDK. All you need is a set of one or more UUIDs of one or more players.

Important: retrievePlayerInfo returns a single object with the player information of the currently logged in player when no parameter is passed to it. If you do pass an array or a single UUID to it, though the return value is going to be an object which holds they players' information under the key of their UUID.

QS.setup().then(function (qs) {
  var uuids = [uuid1, uuid2]
  qs.retrievePlayerInfo(uuids).then(function (data) {
    console.log('' + uuid1 + ' has the name: ' + data.uuid1.name);
  });
})

Flash

The Flash SDK is in in a raw state at the moment. Please pay additional caution when using it!

Setup

Import these packages:

import flash.display.LoaderInfo;
import flash.external.ExternalInterface;
import flash.system.Security;

Then make sure to allow communication with QS:

var flashVars:Object = LoaderInfo(this.root.loaderInfo).parameters;

flash.system.Security.allowInsecureDomain(flashVars.qsCanvasHost)
flash.system.Security.allowDomain(flashVars.qsCanvasHost)

Once the QS initialization is done, the SDK will reach out to a special callback. Register it like this:

function qsSetupCallback(qs):void {
  // QS SDK ready!
}
ExternalInterface.addCallback('qsSetupCallback', qsSetupCallback);

Now you got to initialize the QS SDK with:

ExternalInterface.call('QS.setup')

Make sure to call QS.setup only once!

Once that callback was called you have access to the full QS functionality.

If a player is not logged in when playing the game (e.g. when playing through an embed on a third party website) the SDK will not setup! It will instead call an error callback. You can register it like this:

function qsSetupErrorCallback(message):void {
  // QS SDK not ready! Reason can be found in the message variable
}
ExternalInterface.addCallback('qsSetupErrorCallback', qsSetupErrorCallback);

Retrieve information about the player

First register the callback to retrieve the info about the player or errors in case they happen:

function qsPlayerInfoCallback(player):void {
  trace("Player info loaded");
  trace(player.name);
  trace(player.email);
}
ExternalInterface.addCallback('qsPlayerInfoCallback', qsPlayerInfoCallback);

function qsPlayerInfoErrorCallback(message):void {
  //An error has happened!
}
ExternalInterface.addCallback('qsPlayerInfoErrorCallback', qsPlayerInfoErrorCallback);

Then call QS.flash.retrievePlayerInfo to trigger the retrieval of the information:

function qsSetupCallback(qs):void {
  ExternalInterface.call('QS.flash.retrievePlayerInfo')
}
ExternalInterface.addCallback('qsSetupCallback', qsSetupCallback);

ExternalInterface.call('QS.setup')

The retrievePlayerInfo call gives you a player object that holds information about the currently logged in player. You can access it's name, email and uuid which is it's unique identifier within the Quarter Spiral universe.

In some cases an email address might not be present. For the time being we return [email protected] in these cases but this will be subject to change.

Manage player data

Quarter Spiral lets you save data for every player that plays your game.

function qsSetupCallback(qs):void {
  ExternalInterface.call('QS.flash.setPlayerData', {
    highScore: 190,
    tutorialCompleted: true
  })
}
ExternalInterface.addCallback('qsSetupCallback', qsSetupCallback);

ExternalInterface.call('QS.setup')

This call will overwrite all data that was previously stored for this player. If you only want to adjust a single value you can do that:

function qsSetupCallback(qs):void {
  ExternalInterface.call('QS.flash.setPlayerData', 'highScore', 190);
}
ExternalInterface.addCallback('qsSetupCallback', qsSetupCallback);

ExternalInterface.call('QS.setup')

To know if the data could be saved or an error have occurred there are two callbacks you can register:

function qsPlayerDataSetCallback(data):void {
  //Data was saved and the complete data is passed in in the data variable.
  //Please note that even if you only set a single value the data variable always holds the complete data!
}
ExternalInterface.addCallback('qsPlayerDataSetCallback', qsPlayerDataSetCallback);

function qsPlayerDataSetErrorCallback(message):void {
  trace("Problem setting player data:: " + message)
}
ExternalInterface.addCallback('qsPlayerDataSetErrorCallback', qsPlayerDataSetErrorCallback);

There is also a convenient way to retrieve the current player's data:

function qsPlayerDataCallback(data):void {
  trace("Player data loaded!")
}
ExternalInterface.addCallback('qsPlayerDataCallback', qsPlayerDataCallback);

function qsPlayerDataErrorCallback(message):void {
  trace("Problem loading player data: " + message)
}
ExternalInterface.addCallback('qsPlayerDataErrorCallback', qsPlayerDataErrorCallback);

function qsSetupCallback(qs):void {
  ExternalInterface.call('QS.flash.retrievePlayerData')
}
ExternalInterface.call('QS.setup')

About

The SDK to integrate your game to the Quarter Spiral platform

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •