Bash.tv → GitHub → itch.io

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.

Files: debug-manager.js (the component, no dependencies) and debug-manager.test.mjs (4 tests). Copy debug-manager.js into your game, for example to src/components/, and import it as an ES module.

Usage

import { createDebug } from "./debug-manager.js";
const debug = createDebug();                       // on with ?debug in the address, or press the ` key
debug.watch("enemies", () => enemies.length);
debug.watch("player", () => `${player.x | 0}, ${player.y | 0}`);
debug.command("god", () => (player.invincible = !player.invincible), "toggle invincibility");
debug.command("level", (n) => scenes.go("play", { level: +n }), "jump to a level");
function frame(dt) {
  debug.time("update", () => update(dt));
  draw(); debug.draw(ctx);                          // overlay text, drawn last
}
window.__debug = debug;  debug.run("level 3");     // commands from the browser console or a test

API

Engines

Engine Notes
Vanilla / Canvas 2D draw(ctx).
Phaser, PixiJS, Three.js everything except draw() works the same; show debug.lines() in a text object or an HTML <pre> over the canvas.

Tests

Node tests: off by default, ?debug and the toggle key, watches, the log ring, timings, commands with arguments and unknown commands, debug drawing only when on.

Run them with node --test toolkit/components/debug-manager/ (Node 20 or newer, nothing to install).