What it does
A world document holds everything a role-playing game is made of, as data: a story with a premise, a villain and acts; regions placed on the map with a biome and an act, each with an optional town and dungeon; heroes with classes, stats and skills; non-player characters with roles, wants, fears, secrets and lines; monsters with elements, Break shields and drops; items, skills, quests of ordered steps, and the rules the game is played by. It is intent rather than tiles, so it stays small and plays the same everywhere.
cleanWorld is total: anything world-shaped goes in and a valid world comes out. Unknown names fall to a default,
lists are capped, dangling references are cut, duplicate ids get suffixes, text is trimmed to length and stats are held
to safe ranges, and cleaning a clean world changes nothing. worldPlayable lists what stops a world being played. That
makes it safe to play content from an editor, a generator or an agent without checking it by hand.
worldMaps builds the maps from the seeds. The overworld lays the regions out as roughened cells filled by biome
rules, with town and dungeon entrances, roads and a start. Each town is one of its layouts, with buildings, a shop, an
inn and a spot for every character who lives there, all reachable. Each dungeon floor comes from the level generator, with rooms, stairs
and roaming monsters, and the boss and a chest on the last floor. The functions are pure and light on imports, so a
design tool draws the same maps the game plays.
Features
- One document — story, regions, towns, dungeons, heroes, characters, monsters, items, skills, quests and rules in plain JSON.
- A total cleaner —
cleanWorldturns anything world-shaped into a valid world, and leaves a clean one unchanged. - A playability check —
worldPlayablenames what is missing: regions, a start, heroes or monsters. - A generated overworld — regions as roughened cells by biome, with entrances, roads and a start.
- Town templates — six layouts,
village,harbor,fort,city,shrineandcrossroads, with buildings, doors and spots that are all reachable. - Dungeon floors — from the level generator, with rooms, stairs, roaming monsters, a boss and a chest, seen top-down or in first person.
- Built-in vocabularies — eight biomes, ten dungeon themes, four hero classes, an element wheel of fire, ice, lightning and earth, and item kinds, effects and quest step kinds.
- Caps as options — by default eight regions, six heroes, 40 non-player characters, 32 monsters, 48 items and three acts, and every cap can be changed.
- Tile tables — terrain for the overworld, towns and dungeons, each with a name, a colour, whether it can be walked and whether encounters happen there.
Good for
- Data-driven role-playing games, played at once with
rpg. - Your own RPG screens built on the document and its maps, with
party,questsandturn-battlefor the rules. - Design tools and editors that preview a world as it is written.
- Content from a generator or an agent, cleaned before it is played.
- Settings of your own: a moon biome, a bard, a light-and-dark wheel or five acts, added through options.
- Procedural worlds where the same seeds must always give the same maps.
Make it yours
cleanWorld takes WorldOptions: limits, biomes, dungeonThemes, townLayouts, npcRoles, questShapes,
difficulties, itemKinds (a kind that names an equipment slot is worn there), itemEffects, skillEffects,
classes with their level-1 stats, elements and stepKinds. Every list replaces the built-in one, so spread the
default to extend it. worldMaps takes MapOptions: a biome rule per biome, extra terrain, a town layout rule per
layout drawn with a small builder, the overworld's cols and aspect, and the dungeon floors' size, room size, extra
connections and number of roaming monsters.
Two different uses: the default world, a three-act story over a handful of grassland, forest and mountain regions with the four built-in hero classes; and a world of its own in five acts with the region cap raised to twelve, a moon biome laid on a regolith terrain of its own, a bard class and a light-and-dark element wheel.
A quick look
Anything world-shaped cleaned, checked and turned into maps:
import { cleanWorld, worldPlayable, worldMaps } from '@phaser-ae/rpg-world';
const world = cleanWorld(json); // anything world-shaped in, a valid world out
worldPlayable(world); // [] when it can be played, else what is missing
const maps = worldMaps(world); // the overworld, every town, every dungeon floor
const id = maps.overworld.tiles[r * maps.overworld.cols + c]; // maps.terrain[id]: name, colour, walkable
Works with
rpg— plays a world as it is.party,questsandturn-battle— the rules for a game that builds its own screens on the document.levelgen— makes the dungeon floors; use it alone for dungeons with no world around them.procgen— the noise behind the overworld.tiles-2d— for maps drawn by hand instead.
Good to know
- Maps are generated from seeds, not authored: a town is one of its templates and a dungeon floor comes from the level generator.
- The overworld is one map of regions; there is no travel between continents and no interiors beyond towns and dungeons.
- Stats are held to fixed ranges, 1 to 9999 health, 0 to 999 for most and 0 to 99 for speed and luck, whatever the limits say.
- A biome or town layout with no map rule builds as grassland or a village.






