Skip to content

DVS-devtools/game-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GameSDK v3.x

Table of Contents

How integrate the SDK on your game

Follow the simply steps explained below, in 5 minute you are ready to test your game with the SDK integrated!

Alt text

Install node and npm

Probably you already have this installed in your PC/Mac but just in case here are the tutorial to setting up in environment for development:

Edit your hosts file

You should add this line to your file hosts ( How to edit my host file? )

   127.0.0.1 local.www.gameasy.com

Clone the repo

git clone https://github.com/docomodigital/game-sdk

Install all dependencies packages

npm install

Copy the game in public > games > myfolder

Put the game in game-sdk/public/game/myfolder where myfolder could have any name you prefer

Run the local server

npm start

Go to http://local.www.gameasy.com:8080 All games currently available in the public > games directory will be show and can be started with the relative Play button

An implementation example

// index.html
// It's better to put the initialization in your index.html as soon as possible
GamifiveSDK.init({ 
lite: true,
menuPosition: 'TOP_LEFT' //'BOTTOM_RIGHT', 'TOP_RIGHT', 'BOTTOM_LEFT'
}); // lite false means without gameover
GamifiveSDK.loadUserData(function(userData) {
    // UserData is null the first time or after a clearUserData() call
    // The userData is associated with userid-gameid combination
    // You can integrate this function with your assets loader
    // for example in construct2 you can send a signal to the loader

    // N.B. getDefaultUserData() implementation it's your implementation responsability
    // and should return a javascript object
    var initialState = userData ? userData : getDefaultsUserData();
    initGame(initialState);
});

GamifiveSDK.onStartSession(function(){
    // this will be called every time a start session is called    
})

// When the user play:
GamifiveSDK.startSession();

// When the user finish to play
GamifiveSDK.endSession( { score: 123456789, level: 1 } );
// This will saves the state on our server and on local
// N.B. The object is just an example. You can structure it however you want
GamifiveSDK.saveUserData({ level1: { score: 123456789, unlocked: true } });

// The more games button is a floating action button that once clicked redirect the user
// to our portal. It's needed to show this button in your pause event
GamifiveSDK.showMoreGamesButton();
GamifiveSDK.showMoreGamesButton('TOP_LEFT')//'BOTTOM_RIGHT', 'TOP_RIGHT', 'BOTTOM_LEFT'

// On exit pause hide the more games button
GamifiveSDK.hideMoreGamesButton();

While testing

Inside index file remove/comment the line below if present:

<script id="gfsdk" src="http://s.motime.com/js/wl/webstore_html5game/gfsdk/dist/gfsdk.min.js"></script>

Our SDK integration calls can be anywhere in the code at the specific event (Game Start, Game Over, Game Pause, etc) The init and the load should be inside the index file but this is up to your code. Here is the list of our calls:

GamifiveSDK.init({ lite: true, menuPosition: 'TOP_LEFT' });
GamifiveSDK.loadUserData(function(resp) {});
GamifiveSDK.hideMoreGamesButton(); 
GamifiveSDK.startSession();
GamifiveSDK.showMoreGamesButton();
GamifiveSDK.saveUserData({ 'score' : score_var, 'level' : level_var });
GamifiveSDK.endSession({ 'score' : score_var, 'level' : level_var });

Before sending

Before sending the package just put this tag in your head

<script id="gfsdk" src="http://s.motime.com/js/wl/webstore_html5game/gfsdk/dist/gfsdk.min.js"></script>

Aliases

These are valid aliases too for game-sdk in window main scope

- GamefiveSDK 
- DocomoSDK
- GamifiveSdk
- GamefiveSdk

API

onLoadUserDataCb

Called when the data, saved with saveUserData, has been loaded from server

Type: Function

Parameters

  • userProgress (Object | null)

init

Initialize the sdk

Parameters

  • initConfig Object
    • initConfig.lite Boolean false if should show the gameover
    • initConfig.moreGamesButtonStyle Object DEPRECATED since v2.5.3: a custom styles to pass to moregames button
    • initConfig.menuPosition String TOP_LEFT, BOTTOM_LEFT, TOP_RIGHT, BOTTOM_RIGHT (optional, default 'BOTTOM_RIGHT')

Returns Promise

getConfig

Returns the whole state!

Returns Object

getLevel

Returns the number of the last level reached by user

Returns Number

showMoreGamesButton

Shows the menu|moregames button. call this function when in pause

Parameters

  • position string? custom position

hideMoreGamesButton

Hides the menu | moregames button call this function when on pause exit

loadUserData

Loads the arbitrary data from our server. Returns somenthing only for retrocompatibility. Since version >=2 must be called with the callback signature

Parameters

  • onLoadUserData
  • onLoadUserDataCb SDK~onLoadUserData The callback that handles the response.

Returns (Object | undefined)

saveUserData

Save an arbitrary object on server and on local

Parameters

clearUserData

Clear the user data saved on local and on server. Use this function only under explicit user input

goToHome

Redirect the browser to the game portal

getAvatar

Get the user avatar if any.

Returns Object avatarObj

Returns String avatarObj.src - the url of the avatar object

Returns String avatarObj.nickname - the name of the user

getNickname

Get the userNickName if any. otherwise undefined

Returns (Object | undefined)

onStartSession

Register a function that will be called on each startSession call

Parameters

startSession

Starts a session. If the init it's still in pending the session will start on init finished

endSession

Ends a session and calculate the session time. This function can be called without params. In this case only the session time is calculated. It can be called also with just the score and in this case the level is implicitly 1 this is useful for games without levels.

Parameters

  • scoreAndLevel Object (optional, default {score:0,level:1})

getVersion

Get the version object

Returns Object version

Returns String version.version - The commit string in semantic version syntax

Returns String version.build - The hash of the commit version refers

isInitialized

Returns if the sdk has been initialized

Returns Boolean

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published