Dopamine Facade - BaryoDev/dopaminejs GitHub Wiki
The default export wires DataService, RewardSystem, GameUI, ParticleSystem and SoundManager together. It exists for v1 compatibility and for the quickest start. New code that wants control uses the named exports.
import Dopamine from 'dopaminejs';
import 'dopaminejs/style.css';
const dopamine = new Dopamine({
data: { prefix: 'myapp_' },
rewards: { achievements: { /* ... */ } },
sound: { volume: 0.6 },
particles: { maxParticles: 2000 }
});
const { rewardSystem, gameUI, particleSystem, soundManager } = await dopamine.init();Each config key is passed to the matching class: Storage, Reward System, Sound, Particles.
The constructor creates DOM. Use it in the browser only.
- Awaits
rewardSystem.init(). - Draws the loaded player: XP bar, level badge, streak badge.
- Returns the four parts. They are also properties on the instance.
| Reward event | UI |
|---|---|
xp_gained |
updates the XP bar |
level_up |
updates the level badge, shows the level up overlay |
achievement_unlocked |
shows the achievement popup |
streak_updated |
updates the streak badge |
new_high_score |
shows New High Score: <score>! as a legendary notification and plays the success sound |
dopamine.destroy();Removes the listeners and destroys the UI, the particle canvas and the audio context. The reward system stays usable, so progress can still be recorded after the UI is gone.
- You render the progress yourself (React, Vue, a canvas HUD). Use
RewardSystemandDataService. - You run on a server. The facade needs a DOM.
- You want a different particle or sound backend.