Kroniki Engine
A visual novel and RPG engine: how it works and how to add content to it. React + Material UI for screens, PixiJS for the map, zustand for state. Runs as a desktop app (Electron), an Android app and in the browser, with keyboard, gamepad and touch.
pnpm lang
First steps after cloning
The game's name, ids and version are in one file, src/content/config/app.ts. Everything else (browser tab, desktop window, save folder, storage keys, save and backup formats, installers, the Android app) is filled in from it, so nothing outside src/content needs editing:
// src/content/config/app.ts
export default {
id: 'mygame', // save folder, storage keys, build files
appId: 'com.mystudio.mygame', // store id (Android, installers)
name: 'My Game', // what players see
description: 'A small adventure',
version: '1.0.0', // title screen, saves
build: 1, // goes up with every release (Android needs it)
saveFormat: 'mygame-save', // only saves with this format load
backupFormat: 'mygame-backup',
iconBackground: '#0d1117', // behind the Android adaptive icon
splashBackground: '#000000', // every start-up screen until the game draws
} satisfies AppConfig
- Set
id,appIdand the two formats before your first release. Changing them later starts the game without the players' saves, and stores and Android treat a newappIdas a different app. id: letters, digits,-and_.appId: dot-separated parts that each start with a letter.namemay have spaces and capitals. Installer file names keep only letters, digits, spaces and. _ - ( )("Jack's Game" → "Jacks Game"); the window and the game show the real name.- Also give the title screen its name:
nameinsrc/content/titles/default/index.ts(and its translations insrc/content/lang/), and the title screens'alttext. - The icons are files in
src/content/assets/icon/: one per kind (tab and desktop, Android square, round, adaptive): see Icons and splash.
The art and sound files are stored with Git LFS, and the game doesn't build without them (the sprites' generated files are missing). With Git LFS installed, git clone gets them by itself. Without it, pnpm setup:lfs (optional) downloads Git LFS into tools/git-lfs for this repository only; then run tools/git-lfs/git-lfs pull once to fetch the files the clone left as placeholders.
Setup and commands
source ~/.nvm/nvm.sh && nvm use 24 # node is only on the PATH after this
pnpm install
pnpm dev:browser # dev server (reachable from other machines too)
pnpm dev:electron # the desktop app in dev mode
pnpm test # all tests (vitest)
pnpm typecheck # code generation + TypeScript (src and tools)
pnpm lint # Biome; pnpm lint:fix fixes what it can
pnpm gen # regenerate everything generated (registry, Tiled, Aseprite, .vn)
pnpm lang # translation status (pnpm lang --write adds missing keys)
pnpm icons # Android launcher icons from src/content/assets/icon (builds do it too)
pnpm build # everything: web, Linux, Windows, Android (installers in build/dist)
pnpm build:web # build/web (add --lite for the lite build)
pnpm build:linux # one target; also build:win, build:android (see Tools → Building)
pnpm setup:lfs # optional: Git LFS just for this repo (if it isn't installed), then tools/git-lfs/git-lfs pull
pnpm vn:extension # editor extension for .vn files (build/vn-extension/*.vsix)
pnpm guide # refresh this guide's search and code colours
Open the game at the address the dev server prints. Press ` for the dev panel.
How content works
All game content lives in src/content. The engine lives in src/core and you normally don't need to touch it.
- Make a folder with an
index.ts(or.tsx) in the right place, e.g.src/content/items/potion/index.ts. - Export a definition with the matching helper:
export default defineItem({ … }). The helpers check your fields and give autocomplete. - Use its id anywhere:
game.items.add('potion'). The id is the folder name. It's typed: a typo is a TypeScript error.
A code generator (vite/registry.ts) scans the folders and writes src/generated/registry.gen.ts. It runs on its own while the dev server is up, and in pnpm typecheck / pnpm gen. You never edit generated files.
define…() helpers do the same job as satisfies Type.Names and groups
- Folder names: lowercase letters, digits and
_, starting with a letter (sudden_encounter_4). - Folders starting with
_are helpers, not entries (shared components, utilities). - Maps, events, windows, structures and props can be grouped: a folder without
index.tsis a group.events/anna/hello/index.tsbecomes the id'anna/hello'. Up to 3 group levels. - Inside an entry, subfolders (art, helpers) are never scanned for more entries.
Loaded up front vs. on demand
Maps, events, windows, minigames and structures load when first used (each is its own code chunk). Characters, props, items, quests, shops, enemies, skills, troops, achievements, journal entries, gallery pictures and title screens load at start, because the engine needs their data right away.
game (@/core/game): that creates an import loop. Use the game passed into their hooks instead (use: ({ game }) => …).Project layout
| Folder (src/content/…) | What | Id example | Page |
|---|---|---|---|
maps/<group>/<name>/ | Places you walk around in | 'countryside/town' | Maps |
structures/<name>/ | Small Tiled maps stamped into maps | 'house' | Maps |
props/<name>/ | Chests, barrels, trees… | 'chest' | Maps |
characters/<name>/ | Name, portraits, map sprite, stats | 'anna' | Characters |
events/<group>/<name>/ | Visual-novel scenes (index.ts or index.vn; or one file, <name>.vn) | 'jack/hello' | Events |
items/<name>/ | Inventory items | 'apple' | Gameplay |
quests/<name>/ | Quests with steps | 'jacks_letter' | Gameplay |
shops/<name>/ | What a shop sells and buys | 'anna' | Gameplay |
enemies/<name>/, skills/<name>/, troops/<name>/ | Battles | 'slime', 'fire', 'wolf_pack' | Gameplay |
achievements/, codex/, gallery/ | Achievements, journal entries, CG pictures | 'builder' | Gameplay |
movies/ | Videos that unlock in Extras → Movies | 'opening' | Events |
windows/<name>/ | Inventory, shop, settings… | 'inventory' | Screens |
minigames/<name>/ | Full-screen games (also the battle screen) | 'dodge' | Screens |
titles/<name>/ | Title screen variants, unlocked as the story goes on | 'starlit' | Screens |
boot/<name>.tsx | Notices and logos shown once when the game starts | Screens | |
lang/<code>/ | Translations | 'pl' | Translations |
audio/** | Sound files, any depth | 'music/town' | Audio |
backgrounds/** | Scene backgrounds: a picture (or video) per id, or a folder with an .aseprite and index.ts for one with variants | 'school/classroom' | Backgrounds |
fonts/ | Your font files, named in index.ts: choices in Settings, or fallbacks (emoji) | 'pixel' | Fonts |
save/ | Saved data shape, new game, migrations; persistent.ts: your data kept across all saves | Saves | |
tilesets/, sprites/, assets/ | Shared art | Art |
Files at the top of src/content: lists other content refers to by id, and files that grow as the game grows:
| File | What |
|---|---|
start.ts | What happens when the game starts (boot screens, title screen, main menu) |
settings.ts | The game's own settings next to the engine's (Settings) |
flags.ts | Story flags and their start values |
chapters.ts | Chapters, how they are announced |
stats.ts, statuses.ts, battle.ts | Party stats, elements, levels; statuses (poison, sleep, haste…); battle music, backgrounds, formulas and losing |
scenes.ts | How scenes behave: line styles, moves, transitions, voices, reading comfort, the chat box layout and side image, the toolbar, the framed picture (inset), Back, the music room |
travel.ts, recipes.ts | Fast-travel places; crafting recipes |
weather.ts, ambient.ts, terrain.ts, music.ts, emotes.ts | Weather kinds and their sounds; footsteps per ground; music loop points; emote balloons |
credits.ts | The names listed by the credits window |
look/ (a folder) | How the whole UI looks, sounds and behaves: colours, text, frames, buttons, named parts, UI sounds, MUI defaults. See The game's look. |
src/content/config/: settings you pick once and rarely touch again:
| File | What |
|---|---|
app.ts | The game's name, ids, version, save formats, icon and splash colours (First steps) |
mode.ts | Visual novel only, or the game with maps |
newgameplus.ts, difficulty.ts, gameover.ts | New Game+; difficulty levels; what losing does |
input.ts | Actions and their keys / buttons, touch buttons |
player.ts, money.ts, clock.ts, timers.ts | Player speed, size, sprite; currency; day / night colours and calendar; on-screen timers |
screen.ts | Screen ratios, landscape only on phones, map zoom, scene (stage) sizes, minimap, toasts, timings |
flowchart.ts | The flowchart's sizes, lines and wording (VN mode) |
media.ts, protect.ts, security.ts | How pictures and sounds are converted in builds (see Big games); the media lock; the built game's Content-Security-Policy |
src/content/ui/: how the engine's screens are laid out (the chat box, choices, windows, toasts, the log…). See UI files.
The game object
Content talks to the engine through one object. Everything on it is typed by your content.
import { game } from '@/core/game' // or the `game` handed to hooks
game.maps.go('countryside/forest', { spawn: 'from_town' })
await game.events.start('jack/hello')
const result = await game.minigames.start('rock_paper_scissors')
game.windows.open('inventory')
game.items.add('apple', 2, { notify: true })
game.flags.set('met_anna', true)
game.quests.start('jacks_letter')
game.toast(game.t('Saved!'))
| Part | Does |
|---|---|
maps, structures, props, clock | The world |
events, minigames, windows, title | Scenes and screens |
flags, items, money, shops, quests, party, battles, relationships, achievements, codex, extras | Gameplay |
characters | Names that change |
state, save, session, dialog | Saved data, leaving the game, asking a question |
audio, input, lang, t, toast | Audio, input, translations |
The screen stack
Screens stack as map → event → minigame → windows, with toasts on top. Only the top one gets input: while a window is open, the map doesn't move. Windows stack among themselves: opening one that is already open brings it to the front.
Conventions
- Code style is enforced by Biome (single quotes, no semicolons, 2 spaces, 100 columns). The editor formats on save with the recommended Biome extension.
- State lives in a few grouped zustand stores (with immer). Content reads it through
game.*and React hooks likeuseFlag,useInventory,useGameData. - Things that change every frame (movement, tweens, typing text) are written straight to the screen, not through React state.
- Hooks that may be async are typed as returning
voidon purpose (the engine awaits them). This avoids circular types between maps and events that refer to each other.