LittleJS Medal System
- Achievement/trophy system for games
- Medal class with name, description, icon, and unlock tracking
- Automatic saving to local storage, unless a service like Newgrounds holds the medal (see Medal.isLocal)
- Visual display queue with slide-in notifications
- The Newgrounds plugin extends it with NewgroundsMedal, held on the server while logged in
- Setting debugMedals = true in the game code before medalsInit skips the load and the save, and in the debug build logs the Newgrounds traffic; it is not exported, so only a script tag build can set it
- Source
Classes
Members
(static, constant) medals :Object.<number, Medal>
List of all medals
Type:
- Object.<number, Medal>
- Source
Methods
(static) medalsForEach(callback)
Calls a function for each medal
Parameters:
| Name | Type | Description |
|---|---|---|
callback | MedalCallbackFunction |
- Source
(static) medalsInit(saveName)
Initialize medals with a save name used for storage
- Call this after creating all medals
- Loads which medals are unlocked from the save, and writes the catalog back
- A medal a service like Newgrounds holds is left as it is, see Medal.isLocal
Parameters:
| Name | Type | Description |
|---|---|---|
saveName | string | The localStorage key the medals are kept under, a different one from the game's own readSaveData and writeSaveData, or each would overwrite the other |
- Source
(static) medalsReset()
Reset all medals to locked and persist the cleared catalog
- A medal a service like Newgrounds holds is left alone, the service has it
- Source
Type Definitions
MedalCallbackFunction(medal)
Parameters:
| Name | Type | Description |
|---|---|---|
medal | Medal |
- Source