Function Signature
Parameters
Configuration object for the achievement engine
Returns
An achievement engine instance with methods for unlocking achievements, tracking progress, and subscribing to state changes.
Example
Behavior
Initialization
WhencreateAchievements is called, it:
- Loads persisted state from storage (unlocked achievements, progress, collected items)
- Verifies integrity of stored data using hash validation
- If tampering is detected, fires
onTamperDetectedand resets to clean state - Returns a ready-to-use engine instance
Integrity Protection
The engine automatically protects against data tampering:- Each storage write includes a hash of the data
- On read, the hash is verified against the stored data
- If verification fails,
onTamperDetectedis called and the data is discarded - All storage keys are wiped together to maintain consistency
Storage Keys
The engine uses three storage keys (with optional prefix fromlocalStorageAdapter):
unlocked- Set of unlocked achievement IDsprogress- Progress values for achievements withmaxProgressitems- Collected items for achievements usingcollectItem()
:hash key for integrity verification.
See Also
- AchievementEngine - Methods available on the returned engine
- defineAchievements - Helper for defining achievements with type inference
- StorageAdapter - Custom storage backends
- HashAdapter - Custom hash functions
