Graphics, audio, control and accessibility preferences for browser games, with one tested settings store. A schema with defaults, ranges, steps and labels; every saved value checked so a broken save can't crash the game; version upgrades; graphics presets and a first-run quality guess from the device; reduced motion from the system setting; listeners that apply changes instantly (and on startup...
Download skill (.zip) Files on GitHubGame settings system
Settings every web game should have
| Group | Settings |
|---|---|
| Audio | Master, Music, Sound effects (sliders), mute when in background |
| Graphics | Quality preset, resolution scale, particles, frame rate limit, show FPS |
| Controls | Remap (game-control-customization), sensitivity, invert Y, vibration, touch button size |
| Accessibility | Screen shake amount, reduce motion, flashing effects, text size, color filter, subtitles, game speed |
| General | Language (game-localization), “Show tips again”, reset progress (with confirm) |
Skip what doesn’t apply (no invert Y in a puzzle game), but audio and accessibility always apply.
assets/settings.js
import { createSettings, SETTINGS, PRESETS, detectPreset } from "./settings.js";
const settings = createSettings({ key: "my-game:settings", version: 1, schema: SETTINGS });
if (!localStorage.getItem("my-game:settings")) settings.applyPreset("graphics", detectPreset()); // first run guess
settings.on("musicVolume", (v) => audio.setMusicVolume(v)); // runs now with the saved value, then on every change
settings.on("reducedMotion", (v) => (transitions.reducedMotion = v));
settings.on("colorblind", (v) => applyColorFilter(canvas, v)); // game-accessibility-audit
menu items: settings.menuItems("audio", { labels: (s, key) => t("settings." + key) })
settings.reset("graphics"); settings.all(); settings.flush() // flush before the page closes if you need it
- Values outside the schema are refused (
setreturns false); numbers are clamped and snapped to the step. reducedMotiondefaults to the system’s “reduce motion” setting (prefers-reduced-motion).- Add your own entries to the schema; bump
versionand passmigrate(oldData, oldVersion)when renaming keys.
Rules
- Apply instantly. Moving the music slider changes the music while the menu is open. No “Apply” button, no restart.
- Use the settings everywhere: shake amount multiplies screen shake, game speed multiplies dt, text size multiplies fonts. A setting that does nothing is worse than no setting.
- Settings are per device (localStorage). In Bash kits, use
mineif they should follow the player (playing-together). - Sliders show their value or a clear fill; toggles say On/Off, not only a color.
- Settings reachable from the pause menu, not only the title screen.
Tested
Node tests: defaults, the system reduced-motion default, listeners firing on subscribe and change, clamping and steps, refusing bad values and unknown keys, presets, reload keeping values and fixing bad ones, a broken save falling back to defaults, migration, reset by group, generated menu items, and the device preset guess. Used in the UI kit demo (saved across reloads).
Pitfalls
Settings that need a restart, volume sliders that only apply to new sounds, no master volume, accessibility options hidden in a submenu nobody finds, and crashing on an old saved value.