Components
Tested building blocks for browser games. Each one is a single JavaScript file with no dependencies, so a bot (or you) can copy it into a game instead of writing the same code again.
How to use them
- Copy the component’s
.jsfile into the game, for examplesrc/components/input-manager.js. - Import it:
import { createInput } from "./components/input-manager.js";(the page needs<script type="module">). - Follow the usage example in the component’s README.
From a Bash.tv space without this repo, a bot can download one straight from the website:
mkdir -p src/components
curl -fsSL https://bash.l00.pw/toolkit/components/input-manager/input-manager.js -o src/components/input-manager.js
Some components work together. For example, the Touch Controller feeds the Input Manager, and the Settings Manager can store the Audio Manager’s volumes. Each README says which other components it uses. None of them need another one to work.
Rules every component follows
- Plain ES modules for current browsers (Chrome, Edge, Firefox and Safari, desktop and mobile). No build step needed.
- No globals, except the Error Handler’s
__gameErrorslist, which you can turn off. - Browser objects (window, storage, AudioContext, WebSocket) can be passed in, which is how the tests run in Node.
- Time comes in as
dtin seconds from your game loop, so pausing the game pauses the component. - Blocked storage (private browsing, some embeds) never crashes a game; it falls back to memory.
- Mistakes such as an unknown scene, achievement or asset name throw a clear error, so they show up while testing.
Components
| Component | What it does | Tests |
|---|---|---|
| Accessibility Manager | Player accessibility preferences in one place (reduced motion, screen shake, flashing, high contrast, text size, colour-blind safe colours, subtitles, hold or toggle) that start from the device’s settings, are saved, and can be read out to screen readers. | 4 |
| Achievement Manager | Achievements with progress (“defeat 100 enemies”), hidden ones, saving, and an unlock event for showing a message or telling a game portal. | 4 |
| Animation Manager | Sprite sheet animations (idle, run, jump) and tweens that ease any number from one value to another (menus sliding in, damage numbers floating up). | 6 |
| Asset Manager | Loads images, sounds, JSON, text and fonts once, keeps them cached, shows loading progress, retries failed files and lists anything missing. | 6 |
| Audio Manager | Music and sound effects on separate volume channels, with mute, fades, music crossfades and ducking. | 6 |
| Camera Controller | A 2D camera that follows the player smoothly, zooms, shakes, stays inside the level and converts between screen and world positions. | 6 |
| Collision Engine | Overlap tests for boxes, circles and points, fast-object sweeps so bullets don’t pass through walls, platformer-style movement against solid boxes or tiles, collision layers, and a spatial hash for many objects. | 8 |
| Debug Manager | Developer tools inside the game: an overlay of live values, a short log, timing of game sections, cheat commands and debug drawing, all off unless asked for. | 4 |
| Error Handler | Catches errors so one bug doesn’t freeze the game: records them, keeps the game loop running, shows a friendly message with a reload button if things keep failing, and lets tests read the list. | 4 |
| Event Bus | Lets game systems talk without knowing about each other: the score, sound and achievement code all listen for “enemy:killed” instead of the enemy calling them. | 5 |
| Input Manager | Keyboard, mouse, touch and gamepad read as named actions (“jump”, “left”), so game code never checks keys directly. | 9 |
| Localization Manager | Shows the game’s text in several languages, with fill-in values, correct plurals for each language, number formats, right-to-left languages and a list of missing translations. | 5 |
| Network Manager | A WebSocket connection for multiplayer that reconnects by itself, queues messages while offline, measures lag, and supports request and reply messages. | 5 |
| Notification Manager | In-game messages (“Checkpoint saved”, “Achievement unlocked”) that queue up, don’t flood the screen, merge repeats (“+50 coins ×3”) and are read out by screen readers. | 5 |
| Object Pool | Reuses bullets, enemies and effects instead of making new ones, which avoids the stutters caused by garbage collection on phones. | 3 |
| Particle Engine | Fast reusable effects (explosions, sparks, smoke, dust, confetti) with a fixed memory budget, so effects never slow the game by piling up. | 7 |
| Performance Monitor | Measures frame rate, slow frames, how long the game’s own code takes each frame, and memory, and checks them against the project’s performance budget. | 5 |
| Platform Adapter | One set of calls (gameplay start and stop, ads, sharing, the player’s name, saving) that works on Bash.tv, itch.io, CrazyGames, Poki or a plain website. | 7 |
| Responsive Layout Manager | Sizes the game canvas to any screen, from phone to desktop, portrait or landscape: keeps a fixed game resolution with letterboxing or fills the screen, stays sharp on high-density screens, keeps clear of phone notches and converts taps to game coordinates. | 4 |
| Random Number Generator | Seeded random numbers: the same seed always gives the same levels, loot and daily challenges, and a bug can be replayed exactly. | 5 |
| Save Manager | Saves game data in the browser, with save slots, version upgrades for old saves, and a safe fallback when storage is blocked or a save is damaged. | 7 |
| Scene Manager | A stack of scenes (title, play, pause, game over) with enter, exit, pause and resume steps, and fade transitions between them. | 6 |
| Settings Manager | Player preferences (volume, language, controls, screen shake) with defaults, checked values and saving, and a change event so the game updates straight away. | 4 |
| State Machine | Keeps an enemy, the player or the whole game in exactly one state at a time (idle, chase, attack, stunned) with clear rules for moving between them. | 3 |
| Timer Manager | Delays, repeating timers and cooldowns that run on game time, so they stop when the game is paused and speed up or slow down with it (unlike setTimeout). | 5 |
| Touch Controller | On-screen controls for phones: a thumb stick that appears where the thumb lands and buttons on the other side, with several fingers at once. | 5 |
Testing
node --test "toolkit/components/**/*.test.mjs" # every component (Node 20 or newer)
node --test toolkit/components/input-manager/ # one component
node toolkit/components/build-docs.mjs --check # the READMEs match the notes in the code
The tests use small stand-ins for browser objects (_test/fakes.mjs, _test/fake-audio.mjs). Parts that need a real browser
are also checked in Chromium by _test/browser-check.mjs (see its header for how to run it).
Adding a component
- Make
toolkit/components/<name>/<name>.js. Start it with the notes block (@component,@summary,@usage,@api,@compat,@tested), the same as the others. - Add
<name>.test.mjsnext to it. - Run
node toolkit/components/build-docs.mjsto write its README and add it to the list above.