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.

Status: early development. The engine works and the demo shows what it can do, but APIs, content folders and save formats may still change between versions. Great for trying it out and for small projects, but expect some updates to your game when you upgrade.
Play the demo: see what a game made with Kroniki Engine looks and feels like, right in your browser. No install needed.

First steps after cloning

Start your own game with pnpm setup:project. It asks which kind of game it is (a visual novel, or a game with maps), then removes the demo game from src/content and leaves a tiny starter: the player on an empty map (maps/start) and an empty common route for VN mode. The engine's own screens and scenes stay. Nothing is changed until you pick: Ctrl+C or an empty answer exits. If it finds a symbolic link where it deletes files, it stops before asking and changes nothing (the repository never has any, and deleting through one could reach files outside it): start again from a fresh clone. It runs once (undo with git checkout -- src/content && git clean -fd src/content). Keep the demo instead if you want to learn from it first.

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

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:project      # start your own game: pick VN or maps, remove the demo (asks first)
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.

  1. Make a folder with an index.ts (or .tsx) in the right place, e.g. src/content/items/potion/index.ts.
  2. Export a definition with the matching helper: export default defineItem({ … }). The helpers check your fields and give autocomplete.
  3. 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.

Data is written as TypeScript, not JSON, so you get autocomplete and checks everywhere. The define…() helpers do the same job as satisfies Type.

Names and groups

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.

Files that load up front must not import game (@/core/game): that creates an import loop. Use the game passed into their hooks instead (use: ({ game }) => …).

Project layout

Folder (src/content/…)WhatId examplePage
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>.tsxNotices and logos shown once when the game startsScreens
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 savesSaves
tilesets/, sprites/, assets/Shared artArt

Files at the top of src/content: lists other content refers to by id, and files that grow as the game grows:

FileWhat
start.tsWhat happens when the game starts (boot screens, title screen, main menu)
settings.tsThe game's own settings next to the engine's (Settings)
flags.tsStory flags and their start values
chapters.tsChapters, how they are announced
stats.ts, statuses.ts, battle.tsParty stats, elements, levels; statuses (poison, sleep, haste…); battle music, backgrounds, formulas and losing
scenes.tsHow 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.tsFast-travel places; crafting recipes
weather.ts, ambient.ts, terrain.ts, music.ts, emotes.tsWeather kinds and their sounds; footsteps per ground; music loop points; emote balloons
credits.tsThe 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:

FileWhat
app.tsThe game's name, ids, version, save formats, icon and splash colours (First steps)
mode.tsVisual novel only, or the game with maps
newgameplus.ts, difficulty.ts, gameover.tsNew Game+; difficulty levels; what losing does
input.tsActions and their keys / buttons, touch buttons
player.ts, money.ts, clock.ts, timers.tsPlayer speed, size, sprite; currency; day / night colours and calendar; on-screen timers
screen.tsScreen ratios, landscape only on phones, map zoom, scene (stage) sizes, minimap, toasts, timings
flowchart.tsThe flowchart's sizes, lines and wording (VN mode)
media.ts, protect.ts, security.tsHow 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!'))
PartDoes
maps, structures, props, clockThe world
events, minigames, windows, titleScenes and screens
flags, items, money, shops, quests, party, battles, relationships, achievements, codex, extrasGameplay
charactersNames that change
state, save, session, dialogSaved data, leaving the game, asking a question
audio, input, lang, t, toastAudio, 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