You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add locally stored achievements to your web application and encourage users to continue using and learning.
Installation
npm install gamaas --save
Usage
Most functions in this project are chain-able and allow you to append a . and the next function you wish to call.
Quickstart
To get started quickly, run the below command to run the application in a Webpack'd server.
npm run start
Now point your browser to http://localhost:8090/, open your browser's console, and access the gamaas object directly as it is attached to the window.
Getting started
.init(configOnject: Object): Gamaas
This method is used when setting up your achievements. It accepts an object with specific properties to setup GAMaaS.
Parameters
Param
Required
Type
Description
configOnject
Yes
Object
An object with specific properties to setup GAMaaS
Returns
Return
Type
gamaas
Object
Example
importgamaasfrom'gamaas';gamaas.init({achievements: {// One to many achievementsuniqueAchievementId : {title : "Achievement Title",// The title of your achievementworth : 5,// Number of points the achievement is worthrequired : 5,// Amount of progress required to achieve the achievementexceedRequired : false// Whether or not the achievement progress can exceed what is required},
...
},store : {when : "always",// Whether to store the progress upon every action or when you call .store()dataKey : "achievements"// Namespace for where to save your achievement progress within localStorage}});
.on(event: string, callback: Function): Gamaas
The .on() method requires two parameters, event and callback. The event can be one of four different types which include progress, regress, reset or award. .on() is not required for GAMaaS to function. When any of the events occur, their associated callback function is called. The parameter passed to the callback function is a single object containing the id of the achievement affected along with the event that fired.
The .progress() method is used when incrementing the progress (by 1) of the achievement. In this way if an achievement's progress is currently 1 and you .progress() the achievement, it will then be 2. if exceedRequired is specified and is truthy, then .progress() will not allow the progress to exceed the value specified in the required property of the achievement.
Parameters
Param
Required
Type
Description
id
Yes
string
The id of the achievement you wish to progress.
awarded
No
Boolean
Whether or not you want to award the achievement when the progress meets its requirements. Defaults to true.
The .regress() method is used when decrementing the progress (by 1) of the achievement. In this way if an achievement's progress is currently 3 and you .regress() the achievement, it will then be 2. Achievements can not be reduced below 0.
Parameters
Param
Required
Type
Description
id
Yes
string
The id of the achievement you wish to regress.
awarded
No
Boolean
Whether or not you want to un-award the achievement when the progress is below or equal to its requirements. Defaults to true.
Whether or not you want to un-award the achievement when the achievement is rest. Defaults to true.
Returns
Return
Type
gamaas
Object
.store(): Gamaas
Stores the progress of the achievements to localStorage. This is called automatically when you progress, regress, award or reset achievements when the store.when config value is set to always when you .init() GAMaaS.