Skip to content

Project layout ​

Every starter puts the same things in the same files, so the page, the server, the editor and tests all find them.

my-game/
├── index.html
├── server.ts              a server of the game (startServer)
├── vite.config.ts         the editor's plugin: Save writes maps into src/maps
├── src/
│   ├── rules.ts           the game, engine only: createGame, units, maps, start
│   ├── game.ts            the game with its look attached
│   ├── view.ts            the look (GameView), fetched when the page first plays
│   ├── main.ts            the page: startApp with appScenes
│   ├── editor.ts          the map editor's scene
│   └── maps/              map files the editor saves
└── tests/rules.test.ts    the rules tested with no page

Where to change what ​

To changeEdit
Units, abilities, what happenssrc/rules.ts (How do I…)
How things look and soundsrc/view.ts
The start screen, menus, scenessrc/main.ts (Add a scene)
Mapsthe editor (/?editor), saved in src/maps/
The editor's panels and toolssrc/editor.ts (Make an editor panel)
The serverserver.ts (Run a server and join it)

Why rules and look are apart ​

src/rules.ts imports only @v12-engine/engine. That's what lets the server and tests run your game without a browser. src/game.ts attaches the look with game.view(() => import('./view')), so only a page ever fetches it:

ts
// src/game.ts
import { game } from './rules'

game.view(() => import('./view'))

export { game, UNIT, type Unit } from './rules'

A worker that reads the game (the random-map preview, src/generate.worker.ts) imports src/rules.ts so it doesn't pull in the client. See Rules and their look.

The page ​

src/main.ts builds the app's scenes and starts it. appScenes gives you the start screen, the game, a random map, settings, the editor and a server seat. The address opens straight into one: /?editor, /?server, /?find-game.

ts
const scenes = appScenes({ game, editor, server: true, credits: { sections } })
const app = startApp({ target: '#game', game, scenes, start: sceneAsked(scenes, 'home'), groundWorker, navigationWorker })

groundWorker and navigationWorker move ground textures and navigation builds off the drawing thread (Making a game).

Every file changes live ​

Save while npm run dev runs: unit types, abilities, looks and maps update in the running game. Systems, hooks, components and resources reload the page. See What reloads as you save.