Skip to content

1. The project ​

Goal: a project that runs, with a scout on a field, and the first map saved from the editor.

Make it ​

sh
npm create @v12-engine my-campaign
cd my-campaign
npm install
npm run dev

Pick the empty starter. Say yes to the map editor, the tests and the shared art (@v12-engine/assets); the campaign is drawn with it. Open the page, click Play, select the scout and right-click the ground.

Look around ​

my-campaign/
  src/
    rules.ts        the game (createGame): what there is, its map, what happens as a game starts
    game.ts         the game whole: its look given, fetched as the page first plays it
    view.ts         how it looks
    main.ts         the page: the start screen and its scenes
    editor.ts       the map editor as a scene
  tests/
    rules.test.ts   the rules tested with no page
  server.ts         a server of the game
  vite.config.ts    the dev server, the editor's plugin, the shared art

The game is one object, game, exported from src/game.ts. The page, server, editor and tests take it. As the campaign grows it moves into src/campaign/, and game.ts becomes one line:

ts
// src/game.ts, by chapter 3: the campaign's game (src/campaign/game.ts), `createGame(campaign)` with its maps,
// `startMission` as its start and its view
export { campaignGame as game } from './campaign/game'

Rules import only the engine, so the same game runs in a page, on a server and in a test. See Project layout.

Save the first map ​

  1. Open the map editor (the start screen's button, or /?editor).
  2. Paint some ground and place a tree or two from Content.
  3. Press Ctrl+S. It writes src/maps/field.vgmap.json and field.names.ts beside it.
  4. Pass the file to game.maps in rules.ts, as its comment says.

Rules find things on a map by name (a unit hall, a point camp, a region ford). The names file types them, so a misspelled name doesn't compile.

Play here

The editor's Play here plays the map you're editing with your rules: the fastest way to try a mission.

Next: 2. Units, a building, a hero.