Medals

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

Classes

Medal

Members

(static, constant) medals :Object.<number, Medal>

List of all medals

Type:
  • Object.<number, Medal>

Methods

(static) medalsForEach(callback)

Calls a function for each medal

Parameters:
NameTypeDescription
callbackMedalCallbackFunction

(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:
NameTypeDescription
saveNamestring

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

(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

Type Definitions

MedalCallbackFunction(medal)

Parameters:
NameTypeDescription
medalMedal