Skip to content

Files and projects ​

Where maps are saved, how your game loads them, how to merge them in git, and the panels for your project's files, code and art. The full list of what the editor writes is in the reference.

Save a map to the project ​

  1. Press Ctrl+S. The first time, name the map.
  2. With the dev server running, the map is written to src/games/<game>/maps/<name>.vgmap.json, with <name>.names.ts beside it (its names as types).
  3. Files the map brings (a ground from a picture, test points) go into <name>.files/ beside it. That folder is rewritten at every save, so do not put files there by hand.

A built editor with no dev server keeps maps in the browser. Export (Ctrl+Shift+S) and Import (Ctrl+Shift+O) give a map file, or a .vgmap (a zip with its files).

Load maps in your game ​

Import them. With Vite, take every file of the folder, so a new map is just a new file:

ts
const files = import.meta.glob<MapFile>('./maps/*.vgmap.json', { eager: true, import: 'default' })
export const maps = Object.fromEntries(Object.entries(files).map(([path, file]) => [stemOf(path), parseMap(file)]))

A game whose server runs under Node lists them with mapsFrom, as the starters do. parseMap brings older map formats up to date.

Merge maps in git ​

Map files are written for diffs: one object a line, one row of the ground a line. New ids are spread apart, so two branches rarely clash. For the rest, use the merge driver.

  1. Add to .gitattributes:
*.vgmap.json merge=vgmap
  1. Run once in each clone:
sh
git config merge.vgmap.driver "npm run --silent map merge %O %A %B"

It merges thing by thing and cell by cell, and keeps ours where both sides changed the same thing.

Handle a map changed on disk ​

When a file changed on disk since you opened it (a git pull, another editor), saving does not overwrite it. The editor asks: Load theirs, Save as another file, or Keep mine. Coming back to the window, a change with nothing unsaved is loaded at once.

Get back unsaved or earlier work ​

  • Drafts: while a map has unsaved changes, a draft is kept in the browser every 20 seconds (Settings › Keep a draft). When the editor opens, newer drafts are offered: Take it up or Throw it away.
  • Versions: each save keeps a version in the browser (the last 20). Open File › Versions of this map, press Diff to see what changed, or Restore to take one back as an unsaved change.

Both are this browser's only; a clone of the project has none.

Start from a template ​

  1. Make a map with the size, ground, cliffs, water, players and look you want.
  2. Pick File › Save as a template… and name it. Objects, camps, doodads and paint are left out.
  3. Pick File › New map › From the template … to start a new map from it.

Templates are templates/<name>.vgmap.json in your game's folder.

Take a picture of the map ​

  1. Frame the view.
  2. Pick View › A picture of the view…: 1×, 2× or 4×, PNG or JPEG. Overlays and selection rings are left out.
  3. It goes into the map's files as images/<name>.png. Press Use as the map's preview to make it what map lists and loading screens show.

Bring in models, sounds and pictures ​

  1. Open Assets (File › Assets…, or the Assets button in Content).
  2. Drop files on it. Models are compressed on the way in and go into your game's folder; or drop them on the map's own files to travel with a .vgmap.
  3. Pick a file to see its details: a model to turn, its triangles and bones, Used by (every use, as links), its tags and credit.
  4. Act on it: Look into it, Put it down as scenery, Set up as a unit…, Split into models…, Make lighter levels, Paint the ground with it, Compress, Rename, Delete (the first press says what uses it).

Filter by Unused, Large (over 15k triangles, 80 bones or 3 MB), Tagged or New. Drag any file onto a field that takes its kind (a doodad's model, a sound, a texture). Compress shrinks a model or picture in place and says the sizes before and after; it uses sharp where the project has it (npm install -D sharp).

Browse the project and its code ​

  • Project (left rail): every scene (open it here or in the game), every map with its picture, the cinematics, the campaign, and facts about the project: its packages, scripts, servers and layers. Each has </> to open its code.
  • Code (left rail): your game's code and data files, read only, with the definitions found in each. Search narrows to files and definitions; the button at the file's name opens it in your code editor. New with code writes a stub (see Data panel).

Work on maps from the command line ​

npm run map works on map files without a browser:

sh
npm run map check                                   # every map of the repository; exits 1 on an error, for CI
npm run map -- picture apps/example/src/games/melee/maps/test.vgmap.json test.png --scale 4
npm run map -- picture apps/example/src/games/melee/maps --all   # a picture beside every map of a folder
npm run map -- diff before.vgmap.json after.vgmap.json changes.png
npm run map -- diff before.vgmap.json after.vgmap.json --text   # in words, for a review
npm run map -- run scripts/widen.ts apps/example/src/games/melee/maps/test.vgmap.json   # your script, given the MapEditor
npm run map -- generate melee bay --generator bay --seed 7 --size 192 --players 4 --symmetry both

picture draws the map from above (north at the top, as the minimap). diff marks changed ground magenta, added things green and removed things red. run hands your script a MapEditor and saves the map and its names when it ends:

ts
import type { MapScript } from '../apps/example/scripts/mapCommand'

const widen: MapScript = (editor) => {
	const road = editor.map.paths.find((path) => path.name === 'road')!
	editor.markers.setPath(road.id, { width: road.width + 1 })
}
export default widen

Edit maps from a script or test ​

MapEditor is everything the editor does to a map, without drawing:

ts
const editor = new MapEditor(createMap({ width: 64, depth: 64, game: 'td' }), createRegistry(towerDefense))
editor.markers.addPath([{ x: 4, z: 32 }, { x: 60, z: 32 }], 'road', 3)
editor.markers.addPoint({ x: 4, z: 32 }, 0, 'entry')
editor.markers.addRegion({ kind: 'rect', x: 60, z: 32, width: 4, depth: 6 }, 'gate')
await writeFile('field.vgmap.json', mapText(editor.map))

With the editor open, opened.editor.doc is its MapEditor.

Free browser storage ​

Open File › Storage in this browser… (or search "storage"). It shows how much the page keeps of what the browser allows, every IndexedDB database with its records, the Cache Storage and localStorage. Click a delete button once to arm it and again to delete.

In code ​

ts
editor.mapFiles.openFile('road')
editor.versions.diff(version)
await editor.versions.restore(version)
await editor.templates.save('island')
await editor.viewPicture.save('loading', { scale: 2 })
editor.openAssets('models/tower.glb')
await editor.project.compressAsset(folder, path)
editor.overview.openMap('road')
editor.code.show('ai/rush.ts', 12)

Reference ​

The dev server plugin ​

editorFiles in your vite.config saves the editor's files. A project laid out differently says so:

ts
editorFiles({ games: 'games', public: 'static' })
editorFiles({ gameFolder: () => 'src/game' }) // a project that is one game
OptionWhat it is
games, gameFolderWhere each game's folder is
publicThe shared public folder
code, scaffoldWhere code is, and where New with code may write
runScripts the Run panel may start
idsfalse to stop writing <game>.ids.ts
scenarios, sources, modulesScenarios, sources, and where the engine is loaded from

With every change to a game's data.json, looks.json, fx.json, sounds.json or cinematics/, the plugin writes <game>.ids.ts: one defineIds list and type for each of UNIT, ABILITY, ITEM, UPGRADE, RESOURCE, SPEAKER, CINEMATIC, FX and SOUND, so UNIT.footman is checked by the compiler. Do not edit it. gameIdsSource(game, sources) and gameIds(sources) make the same.

Files a panel edits go through editor.files (read, readJson, write, list, watch, unsaved, save, discard). With the dev server they are project files (/__editor/game-files), data only (.json, .txt, .csv, .tsv, .md, .yaml, .toml, .xml); code is refused. Without one, they are kept in the browser. A shipped editor gives its own store (EditorOptions.files, an EditorFiles); projectFiles(game) and browserFiles(game) are the two built in. The Code panel reads GET __editor/code?game=td and refuses any path outside the game's folder.

What the editor keeps ​

Nothing is migrated: a record that no longer reads as its shape says starts again from the editor's default, and a file is refused with what is wrong.

In the project (written by the dev server):

FileWhat it is
maps/<name>.vgmap.jsonA map (GameMap). Its editor field (hidden, locked, groups, views, prefab instances) is ignored by the game (withoutEditor)
maps/<name>.names.tsThe map's names, as constants and types
maps/<name>.files/Files the map brings (MapPack), tests/<point>.save.json, replays/<date>.json
templates/<name>.vgmap.jsonA template (mapTemplate)
prefabs/<name>.prefab.jsonA prefab: { name, version, contents }; version counts its changes
cinematics/<id>.jsonA cinematic (CinematicDef), read by readCinematic
looks.json, fx.json, quality.json, hud.json, floats.json, pings.json, cellLayers.jsonHow the game looks, laid over its view
sounds.jsonHow each sound plays (SoundDef)
data.jsonDefinitions changed in the Data panel; null is a field taken out
assets.jsonTags and credits of the game's files
campaign.jsonThe campaign (CampaignFile)
languages/<id>.jsonA language's words (MessagesFile)
<game>.ids.tsThe game's ids, as types

In the browser (localStorage, behind the app's storagePrefix, v12 by default):

NameWhat it is
editor-prefsThe editor's settings (EditorPrefs)
editor-keysYour keys (KeptBindings)
editor-layout:<id>The layout for next time (KeptLayout)
editor-layouts:<id>Layouts saved by name
editor-search-recentWhat was found last (at most 30)
editor-recent-mapsOpen Recent, by game (at most 10)
editor-recent-tilesTiles painted with last, by game (at most 8)
editor-content:<game>Content's favourites, recent items, picture size and view
editor-folds:<game>Folds left open or closed
editor-panel:<game>:<panel>A panel's state (panel.state)
editor-shared:<game>Shared values kept with keep
editor-files:<game>:<path>A game's file, where there is no dev server
editor-tour-seenWhether the tour was seen

Maps opened without a project, drafts and versions are in IndexedDB. Model pictures are cached by model and file. In code: storageUsage, listDatabases, listRecords, readRecord, deleteRecords, deleteDatabase, listCaches, deleteCache, listLocalStorage, deleteLocalStorage; versions: saveMapVersion, loadMapVersions, mapVersionText, deleteMapVersion, MAP_VERSIONS.

Other APIs ​

AreaAPI
Draftseditor.drafts, editor.mapFiles.takeDraft(draft, take), keepDraft(), keepDrafts(); EditorPrefs.draftEvery
Versionseditor.versions: entries(), list(), keep(), read, diff, restore, remove; mapChanges(before, after)
Templateseditor.templates: list(), names(), save, read, open, remove; templatePath(name)
Pictureseditor.viewPicture: take({ scale, type }), save(name, options), usePreview(picture), sizeAt(scale)
MergemergeMaps; new ids spread apart (MapEditor ids: 'apart', or 'inRow' for scripts)
ConflictsA page of its own answers with shell.resolveConflict (EditorOptions.shell)
Assetseditor.assetIndex (AssetIndex: usesOf, orphans, codeUses), createAssetStage, assetDrop(kinds, set), ASSET_DRAG_TYPE
Project paneleditor.overview: load(), facts(), maps(), scenes(), playScene(id), editScene(id), openMap(name), openCode(place); editor.project.facts()
Code paneleditor.code: load(), files(), show(path, line?), definitions(), search(query), openInEditor(path?, line?)
Pictures of mapsmapPicture, encodePng

A map says its format and its game; it is not opened in another game's editor.