0024. Top-down worlds and the gameplay kit
- Status: Accepted 2026-11-29 (Phase 5a; owner decisions 2026-11-29: a world document plus chunk levels, state machines and behaviour trees as data, our own JSON dialogue documents, string tables per language)
- Date: 2026-11-29
- Phase: 5
Context
Section titled “Context”Phase 5a adds the second genre: a top-down open world with NPCs that move and talk, quests and items, in more than one language. As before, gameplay should be data that creators, packs and the AI can write, with code behaviours as the escape hatch (ADR 0018).
Decision
Section titled “Decision”-
Worlds. A new
worlddocument lists a grid of chunks. Each chunk is an ordinary level file, so it works in the level editor, the AI level tools and content packs. A scene withworldinstead oflevelstreams the chunks: those within a radius of the camera are loaded, and far ones unload. Tiles, objects and physics are offset by the chunk’s position. Entities that walk off a chunk keep living until their chunk unloads. -
Navigation. Grid A* over the loaded tiles’ collision, with a path cache and a step budget per tick.
-
NPC behaviour as data. Brain documents (
game/ai/<id>.json, listed inbrains), referenced by aBraincomponent. They are documents rather than inline component data because component data is not schema-checked in production builds (no Zod at runtime, ADR 0016), and documents are validated at build time and reusable.- A state machine: states with enter/exit actions, an activity or a behaviour tree, and transitions on events, conditions, time or the activity finishing.
- A behaviour tree: sequence, selector, parallel, inverter, succeeder, repeat, cooldown, conditions, and leaf
activities (
moveTo,wander,follow,flee,wait,say,dowith any rule actions).
Both are deterministic (fixed step,
GameRng). -
Gameplay kit (
@ludrel/gameplay).- Inventory: item definitions in the manifest, stacks, and pickup and use actions.
- Quests: quest documents with steps, counters and rewards.
- Dialogue: dialogue documents with nodes, lines, choices, conditions on counters, quests and items, and rule actions, plus a built-in dialogue box.
- Localization:
game/locales/<lang>.jsonstring tables. Any text may be written as@key; inline{en, fr}maps still work. The player’s language comes from the browser, asetLanguageaction changes it, and missing keys fall back to the default language.
Saves include inventory, quests and language.
-
Template.
templates/topdown(“Berry Hollow”): a small original adventure (a village, a meadow, a pond and a forest in six chunks; an elder, a villager and a fox; a quest; English and French), with art made in code, a bot that finishes it in a headless test, andpnpm create-game --template topdown.
Alternatives considered
Section titled “Alternatives considered”- One big level streamed in chunks: huge files to edit, diff, merge and send to models.
- State machines only: smaller, but richer NPCs would need code.
- Ink/Yarn dialogue: writer-friendly, but text outside schema validation and another runtime.
- Inline text maps only: no way to hand a translator one file.
Consequences
Section titled “Consequences”- More document kinds (
world,dialogue,quest, locale tables) to validate, document for the AI, and support in packs. - Streaming makes the world partly unloaded at any time: rules and behaviours must not assume every entity exists.
- Content packs can add chunk levels and scenes with worlds, but not yet items, dialogues, quests, brains or string tables (the pack loader does not merge them); a later step.