Tools, tests & building
The dev panel, hot reload, generated files, tests, the desktop app, and the mistakes that are easy to make.
Dev panel
Press ` (the key left of 1) in a dev build. Along the top: collision overlay toggle, the player's tile and position, the clock. Sections:
| Section | Lets you |
|---|---|
| Collision overlay | Red walls, orange NPC boxes, green triggers, blue interaction areas, yellow objects with ids, cyan player hitbox |
| Maps & spawns, Events, Minigames, Windows | Jump to any map/spawn; start anything |
| Flags, relationships, money, items, quests | Edit values, add/remove, start/advance/reset quests |
| Party, battles | Give XP, heal or hurt, add members; fight any enemy or troop |
| Achievements & journal | Unlock any |
| Time & weather, props | Set the hour, rain/snow; spawn a prop in front of the player |
| Translations | Switch language; copy the texts shown without a translation |
| Title screens | Unlock, lock and show each title screen variant |
| Across all saves | Count / reset read lines, unlocks and achievements |
| Look | Open the look gallery: every colour, text size, button (each variant and colour: normal, focus, disabled), named part and other MUI part from content/look/, with a button to hear each UI sound. See The game's look. |
| System state | What the engine is doing (screens, map, scene) |
Hot reload
- Saving a map, structure,
.tmx, event (.tsor.vn), window or minigame updates the running game. The current map rebuilds with the player standing in the same place. - Characters, props, items, quests and other up-front content reload the page.
- Aseprite and Tiled saves regenerate their
.genfiles on the spot.
Generated files
Never edit these; they're rewritten by the dev server and pnpm gen (also part of pnpm typecheck). They are committed, so a fresh checkout typechecks.
| File | From |
|---|---|
src/generated/registry.gen.ts | The content folders, audio files and migrations, plus plain id lists (ContentIds, QuestStepIds: quest step ids are read from each quest file, so it is rewritten when a quest file changes) |
*.gen.ts + *.gen.png next to .aseprite | Sprites and portraits |
*.gen.ts next to .tmx / .tmj | Tiled maps and structures |
index.gen.ts next to index.vn, name.gen.ts next to name.vn | Dialogue scripts |
docs/assets/*.gen.js | This guide's search and code colours (pnpm guide) |
Script report: pnpm story
pnpm story # the report
pnpm story --voice # also writes the scripts to record (build/voice-script.csv, build/voice-script/<voice>.csv)
pnpm story --number # first numbers every spoken line that has no voice yet
- Lines and words per event and per speaker; per event how many lines have a voice number (voiced) and how many of those are recorded in the default voice language.
- Events that nothing starts: no map, event, item or window names them.
- .vn lines that never run (they come after
end). - Lines not recorded yet: lines with a voice number whose clip is not in the default language's folder.
- Voice numbers used twice in one event by one speaker (those lines would share a clip).
- Voice clips no line plays, sounds in
audio/voicethat are not a clip (wrong folder or name), and per voice language the clips it is missing that the default language has (those lines play the default one). --voice: a spreadsheet of every line with a voice number: event, speaker, number, text, the line written before it (so the actor knows what they answer), the sound file to record, and whether it exists. Also one file per voice inbuild/voice-script/(anna.csv,student_a.csv…) to hand to each actor. See Voices.--number: writes the next free voice number on every spoken line without a voice, then reports as usual. Per event and per speaker, one more than the highest number there (gaps are never filled, nothing is ever renumbered). .vn files getanna(0012): Hi!(padded tovoice.digits), TypeScript events{ voice: 12 }. Plain narration is left alone (number it by hand to voice it). A line whose options are a variable is listed, not changed. Commit first, so you can look at the change.- It reads
say()/narrate()with the text written in place; text built at runtime is missed.
Tests
pnpm test # everything once
pnpm test:watch # re-run on save
pnpm vitest run src/core/managers/party.test.ts # one file
Tests to know:
src/content/maps.test.ts: every map is well formed (spawns, doors, props, sprites, schedules) and structures fit.src/core/**/*.test.ts: the engine (battles, party, shops, saves and migrations, replays, input, tweens, grid…).vite/**: codegen (registry, Tiled, Aseprite, .vn compiler and checker).scripts/**:pnpm lang,pnpm story, this guide.
Tips for writing tests:
- Component tests: put
// @vitest-environment happy-domon top and use@testing-library/react. Alwaysawait act(async () => …): a plainactwith Suspense hangs. - happy-dom has no layout: mock
getBoundingClientRectwhen testing keyboard focus movement. - Manager tests often mock
../registrywith small fake content, and../gameRefwith a fakegame(seebattles.test.ts).
Browser tests
pnpm test # unit tests (fast, no browser)
pnpm test:browser # plays the start of the game in a real headless browser
pnpm test:built # the same idea for the built web game (after pnpm build:web)
pnpm test:browser starts its own dev server (port 5180), then at 1280×720 and at phone landscape 844×390 with touch: passes the title screen, starts a new game, plays the intro with confirm, walks, opens every engine window and checks that it fits the screen, crafts, shows a timer, the game-over screen, an event, fast travel, and saves and loads. Any error in the browser console fails the run. A picture of every step is written to build/browser-test/.
The browser test always runs the normal game with maps, whatever vnOnly says in src/content/config/mode.ts (VN routes and the flowchart are checked too, since they work in either mode). pnpm test:built checks the build as it is: in VN-only mode it checks that the story starts and its lines advance, otherwise that the intro ends and the map is drawn. Rebuild after changing the mode.
| Browser | The Chromium Playwright has downloaded (pnpm exec playwright-core install chromium), or any Chrome with CHROME_PATH=/path/to/chrome. |
| A game already running | GAME_URL=http://localhost:5173/ pnpm test:browser uses it instead of starting a server (dev builds only: the test reads the game through the dev server). |
| Your own checks | Add steps to scripts/browser/smoke.ts: withGame(page, "game.windows.open('shop')") runs code with the real game, check(screen, 'what', ok) records the result. |
Lint, format, types
- Biome lints and formats (TypeScript, CSS, JS, JSON).
pnpm lint/pnpm lint:fix. Markdown is excluded. No Prettier or ESLint. - TypeScript 7 (the fast native version). Two configs:
tsconfig.json(the game) andtsconfig.node.json(vite config, Electron, scripts, codegen, the editor extension). - Editor: install the recommended Biome extension. The project settings format on save and sort imports. For
.vnfiles install the VN extension. - Files in
vite/andscripts/run directly in Node (type stripping): noenum,namespaceor constructor parameter properties there, and imports end in.ts.
Building
pnpm build # all targets below
pnpm build:web # build/web (static files, host anywhere)
pnpm build:linux # Linux AppImage
pnpm build:win # Windows installer + portable .exe (needs wine on Linux)
pnpm build:desktop # Linux + Windows
pnpm build:android # Android debug APK (needs JDK 21 + Android SDK)
pnpm build:android-bundle # Android Play Store bundle (.aab), signed with android/keystore.properties
pnpm build:android --lite # any build + --lite: smaller pictures and sounds for weaker devices (files end in -lite)
pnpm vn:extension # build/vn-extension/*.vsix
The web build uses relative paths, so build/web runs from any folder of any web server. .github/workflows/pages.yml publishes it to GitHub Pages when you run it by hand (GitHub -> Actions -> Pages -> Run workflow; pushing never rebuilds the site): this guide (docs/) at the site's root and the game in demo/ (the live demo). It needs Settings -> Pages -> Source set to "GitHub Actions". For your own game, keep it, change the folder, or delete the file.
The desktop app
- Loads the built game through its own
app://game/address (so sound and files work like on the web). - Saves are files in the user folder (where). Save export/import use native file dialogs. F11 toggles fullscreen. "Quit" shows in the title menu only here.
- One instance at a time; minimum window 640×360; links open in the normal browser.
- Icon:
src/content/assets/icon/icon.png(see Icons). Name, ids and version:src/content/config/app.ts(First steps). - Electron downloads its own binary on first run.
Icons and splash
Every icon is a file in src/content/assets/icon/ (png, webp, jpg or svg). One kind is never made from another: each has its own file.
| File | Used for |
|---|---|
icon.png | Browser tab, desktop window, desktop installers (square, 512×512 is good) |
icon.square.* | Android launcher icon, older phones (48 dp) |
icon.round.* | Android launchers that show round icons (48 dp) |
icon.foreground.* | Android adaptive icon, front layer: 108 dp, the phone cuts it to its own shape, so keep the art inside the middle 66 dp |
icon.background.* | Optional: the adaptive icon's back layer. Without it, the colour iconBackground in app.ts |
icon.monochrome.* | Optional: Android 13 themed icons (one colour, the phone tints it) |
- Android needs each kind at 5 sizes (48 dp = 48, 72, 96, 144, 192 px; 108 dp = 108 … 432 px). Each is scaled down from the biggest file of that kind; an svg is drawn sharp at every size. Icons are only ever made smaller: if every file is too small, the build says which size is needed.
- A hand-made size wins:
icon.round.96.pngis used as it is wherever exactly 96 px are needed. Its real size must match its name. pnpm build:androidmakes them (and skips it when nothing changed). Building from Android Studio instead: runpnpm iconsfirst (also after cloning). The made files inandroid/…/mipmap-*are not committed.- Splash: every start-up screen (Android, the desktop window, the browser page) is one plain colour until the game draws:
splashBackgroundinapp.ts. No picture or icon is shown there; your own boot screens (src/content/boot/) come right after.
In content: import { isElectron, isAndroid, canQuit, quit, setFullscreen } from '@/core/platform' for system-specific features. They fall back gracefully in the browser.
Android
- Capacitor wraps
build/webin an Android app. The native project isandroid/; open it in Android Studio to run it on a device. - Needs JDK 17 to 24 (21 recommended) and the Android SDK with accepted licences. The build finds both in the usual folders, or uses
JAVA_HOME/ANDROID_HOME. - Saves are files in the app's private folder (where). Export opens the share sheet, import the system file picker.
- The Back button (or back gesture) acts like Esc: it closes the front window, and opens the menu on the map. It never closes the app. Change what it does with
backButtoninsrc/content/config/input.ts. - Play Store:
pnpm build:android-bundlemakesbuild/dist/<id>.aab. Signing needsandroid/keystore.properties(never committed):
# make the key once, keep it safe (losing it = no more updates on Play)
keytool -genkey -v -keystore android/release.jks -alias game -keyalg RSA -keysize 2048 -validity 10000
# android/keystore.properties
storeFile=release.jks
storePassword=…
keyAlias=game
keyPassword=…
The web build runs once, even when you build several targets. A target that fails doesn't stop the others; the summary at the end lists it. Installers and the APK end up in build/dist.
Big games
| Target | Limit | What the build does |
|---|---|---|
| Windows | Installer and portable .exe: 2 GB | Over 1.7 GB it makes a .zip of the game folder instead (Steam ships folders anyway). |
| Desktop (all) | none | Pictures, sounds and videos stay as plain files next to app.asar, so an update only changes the files that changed (small Steam patches). |
| Play Store | 500 MB base, 1.5 GB per asset pack, 4 GB in all | Over 450 MB, media files move into install-time asset packs. Play installs them with the app and the game reads them at the same paths. Over 4 GB the build stops (download-later packs aren't supported yet). |
| Android APK | 4 GB | Stops with a message; use the bundle. |
Converted images (art → big games) keep all of these much further away.
What the built game may load (security policy)
Every built game (web, desktop, Android) carries a Content-Security-Policy: the browser inside it refuses to load or run anything the policy does not list. By default that is only the game's own files, so a bug or a bad mod cannot make the game run code from elsewhere. pnpm dev:* has no policy (hot reload needs more freedom).
// src/content/config/security.ts
export default defineSecurity({
contentSecurityPolicy: {
enabled: true,
allow: {
connect: ['https://api.example.com'], // fetch() / WebSocket
images: [], media: [], fonts: [], // files from other sites
styles: [], scripts: [], frames: [],
},
allowEval: false, // true only for a library that needs eval
},
})
- Something from another site does not load in the built game, and the console says "Refused to … because it violates the Content Security Policy": add its address to the matching list.
- Check a build with
pnpm build:webthenpnpm test:built: it opens the built game in a headless browser, plays the start of the game and fails on any console error, including a blocked file. - A PixiJS add-on that builds shaders may need
allowEval: true; the engine itself does not (it loadspixi.js/unsafe-eval, PixiJS's own way to work without eval).
Locked media (encrypted pictures and sounds)
Built games ship their pictures, sounds and videos encrypted, so players can't just open them from the game folder. The game unlocks each file as it loads it; nothing in your content changes. pnpm dev:* never locks anything.
// src/content/config/protect.ts
export default defineProtect({
media: {
enabled: true,
key: 'any text, made up once', // changing it later = every media file changes in the next update
extensions: ['webp', 'png', 'ogg', 'flac', 'webm', /* … */],
skip: ['icon.png'], // stays plain (the browser reads the tab icon itself)
},
})
- It is not real protection. The game has to unlock its own files, so the key is inside the game. Every engine has this limit (Godot, RPG Maker, KiriKiri). It stops casual browsing. Someone who is determined can still get the files out.
- Very small files (under 4 KB) are built into the game's code instead of being separate files, and those are not locked.
- Each file is locked on its own, with the same file names, and the same file always locks to the same bytes. A Steam update still only changes the files that changed.
- Desktop: the app unlocks files while reading them. Web and Android: a service worker (
media-lock.js) does it. On the web the game must be served overhttps://or fromlocalhost, and the browser must allow service workers (some private modes don't). - Check a build with
pnpm build:webthenpnpm test:built: it also checks that a picture, a video and a hard reload all get unlocked files.
Pitfalls
| Symptom | Cause / fix |
|---|---|
| "Maximum update depth exceeded" in a window | A useGameData selector builds a new array/object. Select the existing object and derive in the component. |
| Import cycle / "cannot access before initialization" | An up-front file (character, item, prop, quest…) imports game. Use the game from the hook's context. |
| Circular type errors (TS7022) between maps/events | Hooks are typed => void on purpose; don't annotate them as Promise<void>. Keep save/data.ts free of game imports. |
| A Tiled tileset won't load | Saved as .tsx: export it as .tsj (JSON) or embed it. |
| Text stays English | Not found by the scanner (template string, variable): see Translations. Or a toast without game.t(). |
| A mid-scene save loads differently | Math.random() in the event: use random() from the context. |
| Works in dev, but a file or script is blocked in the built game | The security policy: see what the built game may load. |
| No sound | No key pressed yet (browser rule), or the volume sliders in Settings. |
game.events.start never resolves | Awaited from inside a running event: it's queued after the current one. Use event(id) instead. |
Functions named use… get hook lint errors | Biome treats every useX as a React hook. Pick another name. |