Dopamine Facade - BaryoDev/dopaminejs GitHub Wiki

Dopamine Facade

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.

What init does

  1. Awaits rewardSystem.init().
  2. Draws the loaded player: XP bar, level badge, streak badge.
  3. Returns the four parts. They are also properties on the instance.

What it wires

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

Cleanup

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.

When to skip it

  • You render the progress yourself (React, Vue, a canvas HUD). Use RewardSystem and DataService.
  • You run on a server. The facade needs a DOM.
  • You want a different particle or sound backend.
⚠️ **GitHub.com Fallback** ⚠️