Skip to content

0022. Visual level editor: data-only canvas, shared level operations

  • Status: Accepted 2026-11-29 (Phase 4a; owner decisions 2026-11-28: Phase 4 split into 4a/4b, the editor draws data only on the web origin)
  • Date: 2026-11-28
  • Phase: 4

Creators need to make and change levels without editing tile arrays, and the AI tools should be able to make the same changes. Game code is untrusted and only runs on the play origin or in the sandbox (ADR 0012, 0020), so the editor cannot use the game’s own runtime on the web origin.

  • @ludrel/level-edit: level operations as plain data (paint, fill, floodFill, ground, place, move, update, remove, resize, layer operations, setLevel). applyLevelOps applies a list all or nothing and returns a new document (layer encodings are kept); describeLevel draws a level as text for models. The ground brush auto-tiles from the game’s legend with the same function the ASCII builder uses (groundTile), and a test checks that painting cell by cell matches the builder.
  • AI tools read_level and edit_level (the MCP server, remote MCP and the assistant get them automatically). edit_level validates the result against the level schema before writing.
  • Editor view (apps/web/app/components/level-editor.tsx): Canvas 2D on the web origin, drawing only data — tileset images and prefab sprites (from Sprite, first frame of SpriteAnimation, prefab extends resolved). Every change is a level operation; the new JSON goes into the file’s editor buffer, so the JSON view, saving, validation, history and merging work as for any file. Undo/redo keeps document snapshots.
  • Play from here: the editor sends goto {scene, at} over the play bridge to its preview; the game calls goToScene(scene, { place }), which moves the named entity (player) there. Only the editor’s preview sends it; the game checks the message. The preview is rebuilt first if files changed since its build. Template games also read ?scene=<id>&at=<x>,<y> in dev.
  • Running the editor inside the play iframe (exact rendering, custom behaviours visible): every edit would cross postMessage and the editor UI would live in untrusted code’s window. Rejected for now (owner decision).
  • Tiled (external editor): no AI path, no history integration, extra install for creators.
  • What the editor shows can differ from the game (particles, code behaviours, parallax); Play from here is the check.
  • Large levels (thousands of tiles across) clone the document on each edit; fine for platformer sizes, to revisit for open-world maps (Phase 5 chunked maps).
  • __PLATFORM__ is exposed in built games’ own (sandboxed) window for end-to-end tests.