Skip to content

Map editor ​

The map editor builds maps for your game: the ground, what stands on it, and the places your rules find by name. It runs in the dev server next to your code, and it saves maps as files in your repository.

Quick start ​

A project made with npm create @v12-engine has the editor already (--no-editor leaves it out). Open the app, pick Map editor in the list of scenes, and start editing.

To add an editor scene to your own app, make one with editorScene and list it with your scenes:

ts
import { editorScene } from '@v12-engine/editor'

export const towerDefenseEditor = editorScene({
	id: 'td-editor',
	name: 'Tower defense map editor',
	game: towerDefenseGame, // the game whose maps it makes (`createGame`)
	play: sceneRef('td-map') // the scene its Play button opens on the map
})

That gives you a full editor for your game. Its code is fetched the first time the scene opens, so your game's page carries none of it until then.

On a page of your own, without the app's scenes, openEditor puts the editor in an element:

ts
const opened = openEditor({ target: '#editor', game: towerDefenseGame, onStart: (world) => startTowerDefense(world) })
// opened.editor once it is there; opened.dispose() to remove it

The layout ​

The 3D scene fills the middle. Along the top are the menus (File, Edit, View, Map, Play, Window, Help), the search field (Ctrl+K), undo and redo, and ▶ Play. Down the left and right edges are rails of icons: click one to open its panel beside the rail, click again to close it. The left rail has Hierarchy, Place, Terrain and Markers; the right rail has Inspector, Look, Map settings, Data and the rest. A strip of tool icons sits inside the scene's left edge (select, move, turn, resize, then the brushes and marker tools), with the picked tool's settings in a slim bar beside it. The drawer along the bottom holds Content, Problems, History, Versions, Timeline, Console and Metrics; it opens over the scene and closes when you click back into the scene. The minimap sits in a bottom corner, and the status line at the bottom right shows the cell under the pointer, the selection, the map size and whether it is saved. Nothing opens until you ask for it; press ? for every key.

What to do first ​

  1. Move the camera and select things
  2. Raise hills and paint the ground
  3. Put down units, buildings and trees
  4. Name a region, point or path for your rules
  5. Add a river, a lake or a waterfall
  6. Change a unit's stats in the Data panel
  7. Set the light, fog and weather
  8. Play the map right in the editor
  9. Save the map into your project
  10. Add a panel of your own

The other pages: Models and animation, Cinematic panel, Objectives, rules and campaign, Metrics and debug views.

Reference ​

Packages and entry points ​

ImportWhat it is
@v12-engine/editoreditorScene, openEditor, defineEditorExtension, MapEditor
@v12-engine/editor/viteThe dev server plugin (editorFiles) that saves files
@v12-engine/editor/styles.cssThe editor's stylesheet
@v12-engine/editor/map-commandThe v12 map command

See Entry points. The client never imports the editor (npm run lint checks it), so a game's page carries only the editor it asks for.

Setup options ​

openEditor, editorScene, <EditorApp> and new EditorClient all take the same options, EditorSetup:

OptionWhat it doesPage
gameThe game whose maps it edits (required)
play, playHereThe scene Play opens; how Play here plays (false for not at all)Play here
palette, kinds, mapAreasWhat can be put down; kinds of thing of your ownPanels
extensions, tools, panels, actionsYour own panels, tools and keysPanels
icons, menus, search, inspector, themesYour own icons, menu lines, search sources, Inspector sections, themesPanels
layoutThe layout it starts withGetting around
startMap, startFileThe map it opens on when nothing was kept; the project file it opensFiles
docs, guideWhere panels' help links point; what Help › The guide opensPanels
filesA file store of your own for a shipped editorFiles

Results and errors ​

An editor operation called from code returns an EditorResult: { ok: true, value } or { ok: false, why }, where why is written for the person using the editor ("There is a prefab gate already"). It says nothing on the status line by itself: call editor.said(result) to show it. A mistake of the calling code (a prefab that was never read) throws an EditorError.