What are Achievements?
Achievements are individual accomplishments that players can unlock in your application. Each achievement is defined using theAchievementDef type and includes metadata like the ID, label, description, and optional behavior modifiers.
Achievement Definition
Achievements are defined using thedefineAchievements helper function, which provides full type inference:
The
as const assertion enables TypeScript to infer the exact achievement IDs as literal types, providing better type safety throughout your application.Core Properties
Every achievement definition includes these required properties:A unique identifier for the achievement. This is used to reference the achievement in all engine methods.
The display name of the achievement shown to users.
A description explaining how to unlock the achievement or what it represents.
When provided, enables progress tracking for this achievement. The achievement auto-unlocks when progress reaches this value. See Progress Tracking for details.
Hidden Achievements
You can control the visibility of achievements before they are unlocked using two optional properties:The hidden Property
When hidden is set to true, the achievement’s ID, label, and description are all concealed until the player unlocks it:
If
true, the ID, label, and description are hidden until the achievement is unlocked.The hint Property
When hint is set to true, only the description is hidden. The ID and label remain visible, providing a clue about the achievement’s existence:
If
true, only the description is hidden until unlocked. The ID and label remain visible.Type Definition
The full TypeScript type definition from the source code:Using Defined Achievements
Once you’ve defined your achievements, pass them tocreateAchievements() to create the engine:
Retrieving Definitions at Runtime
You can retrieve an achievement’s definition at any time usinggetDefinition():
The
getDefinition() method returns undefined if no achievement exists with the provided ID.