Make a map and load it in code
The editor saves a map as src/maps/<name>.vgmap.json, with a names file beside it. Your code reads it with parseMap and finds things on it by name.
ts
// in src/maps.ts
import { type GameMap, parseMap, type World } from '@v12-engine/engine'
import type { FieldPoints } from './maps/field.names'
// every map of the folder, by its name: a new map is a new file and nothing else
const files = import.meta.glob('./maps/*.vgmap.json', { eager: true, import: 'default' }) as Record<string, unknown>
export const maps: Record<string, GameMap> = Object.fromEntries(
Object.entries(files).map(([path, file]) => {
const map = parseMap(file)
return [map.name, map]
})
)
export function mapNamed(name = 'field'): GameMap {
const map = maps[name]
if (!map) throw new Error(`There is no map "${name}"`)
return structuredClone(map)
}
// the names the rules may ask for, from the names file beside the map: a typo does not compile
export const point = (world: World, name: FieldPoints) => world.map.point(name)ts
// in src/rules.ts: the maps the game ships, and the names used
export const rules: Rules = { id: 'my-game', name: 'My game', units: [], maps: Object.values(maps), victory: null }
export function onStart(world: World, { map }: { map?: GameMap }): void {
const road = world.map.path('road')
const entry = world.map.point('entry')
for (const player of map?.players ?? []) if (player.start) world.spawn('scout', player.id, player.start)
}Done: every map file in src/maps/ is a map of the game, and point(world, 'entrry') fails to compile.
The rules never hold coordinates: they ask the map for regions, points and paths by name. The names file (<name>.names.ts) types them: FieldNames, FieldPoints, FieldRegions, FieldPaths, FieldCamps, FieldLights, FieldFx, FieldIds.
In the editor
- Click File › New map (or New map from a generator).
- Shape it with the Terrain, Place and Markers panels.
- Press Ctrl+S to save into
src/maps/, and Play here to try it. - Check the Problems panel for anything the game would refuse (
MapEditorDef.check). - Click Export for a
.vgmapto hand around.
Carve a road or a river
Draw a path with the path tool. In the Markers panel, tick Carves its bed and set width, depth, ground, banks, and water for a river (MapPath.profile). The ground re-carves as you drag its points.
See Maps for what a map holds, and Maps and tools for your team.