Content variants
One game, several versions of some of its content, picked when the game is built: an all-ages and an adult version, or a version for a region with its own rules (cigarettes drawn as lollipops). The other versions' files are left out of the build, not just hidden.
Groups and values
// src/content/config/variants.ts
export default defineVariants({
rating: { values: ['allages', 'adult'], default: 'allages' },
region: { values: ['global', 'cn'], default: 'global' },
})
A build uses one value per group: its default, or the one you name.
pnpm build:web --variant rating=adult --variant region=cn // any build command takes --variant
GAME_VARIANTS="region=cn" pnpm dev // try a version while you work
- Values are lowercase, different across all groups, and never the name of a language folder (both use the
.<name>part of file names). - Keep the file's shape (
group: { values: [...], default: '...' }): the build reads it as text. A misspelt--variantstops the build.
Files, and files per language
A file named <name>.<value>.<ext> next to <name>.<ext> replaces it in the builds with that value, everywhere it is used. Language versions combine with it: <name>.<value>.<lang>.<ext> is that version in one language. For a player of language L in a build with value v the game uses the first that exists:
sign.v.L.png(this version, in the player's language)sign.v.png(this version: a variant always beats a language, so a censored picture stays censored in every language)sign.L.png(the player's language)sign.png
The demo has one: src/content/backgrounds/bus_inside.cn.svg (try GAME_VARIANTS="region=cn" pnpm dev). Every file type, with the "cn" value and Japanese:
| What | Every build / languages | The "cn" version / its languages |
|---|---|---|
| Pictures anywhere (items, portraits, UI, CGs, previews; png, jpg, webp, avif, gif, svg) | icon.png, icon.ja.png | icon.cn.png, icon.cn.ja.png |
Backgrounds and insets (backgrounds/, insets/) | bus_inside.svg, bus_inside.ja.svg | bus_inside.cn.svg, bus_inside.cn.ja.svg |
| Gallery pictures (and their thumbnails) | gallery/pond/image.png, image.ja.png | image.cn.png, image.cn.ja.png (the thumbnail is made from the cn picture) |
Sounds, music, ambient (audio/) | sfx/smoke.ogg, sfx/smoke.ja.ogg | sfx/smoke.cn.ogg, sfx/smoke.cn.ja.ogg (needs smoke.ja.ogg next to it: the build says so) |
Music per voice language (audio/music/ja/) | music/ja/town.ogg | music/ja/town.cn.ogg |
| Voice lines (the language is the folder) | voice/ja/park/anna_0012.ogg | voice/ja/park/anna_0012.cn.ogg |
| System voice | system_voice/anna/saved.ogg | system_voice/anna/saved.cn.ogg |
| Videos, movies, video backgrounds | movies/op/op.webm, op.ja.webm, or movies/op/ja/op.webm (voice language) | op.cn.webm, op.cn.ja.webm, movies/op/ja/op.cn.webm |
Title screen files (titles/<name>/) | titles/starlit/sky.png, sky.ja.png | sky.cn.png, sky.cn.ja.png |
| Aseprite, whole file (portraits, sprites, layered CGs and backgrounds) | jack.aseprite | jack.cn.aseprite (its own language layers as usual) |
| Aseprite, one layer or group | Eyes, Eyes.ja | Eyes.cn, Eyes.cn.ja (in the same file) |
| Spine exports | anna.atlas + anna.json + pages | anna.cn.atlas + anna.cn.json + its pages (or only a page: anna.cn.png) |
| Tiled maps and tileset images | town.tmx, tilesets/countryside.png | town.cn.tmx (a different layout), countryside.cn.png (other tiles, same layout) |
Fonts (fonts/) | pixel.woff2 | pixel.cn.woff2 |
Scenes (.vn or a folder) | events/park.vn, events/day/ | events/park.cn.vn, events/day.cn/ (text is translated as usual: no language files) |
| Any other content code or file you import | helpers.ts | helpers.cn.ts |
| Text | the scripts | variants/cn/strings.ts rewords lines, then every language translates the new line (below) |
- A file of a value is never content of its own:
smoke.cn.oggis not a sound id,park.adult.vnnot an event,sky.cn.pngnot an extra title screen file. - The other values' files are not in the build at all (not even as language versions or thumbnails); the plain file is not either when the build has its version.
- An Aseprite layer of a value takes the place, name and visibility of the layer it replaces, like a language layer.
Scenes
src/content/events/park.vn // every other build
src/content/events/park.adult.vn // the "adult" build plays this one as the event "park"
src/content/events/day.adult/ // a whole folder works the same for events/day/
A scene only one version has: make park.vn the version for the others (it can be a single line), and park.adult.vn the real one. Inside a scene, small differences:
if variant('adult'): // .vn
anna: …
if (game.variants.is('adult')) … // .ts
game.variants.get('region') // 'global' | 'cn'
Text
// src/content/variants/cn/strings.ts: how the "cn" version words some lines
export default defineVariantStrings({
'Thanks. Now I need a nap.': tx('Thanks. Now I need a lollipop.'),
})
The key is the line as the scripts write it; the new wording is then translated like any other line (pnpm lang lists it). Only the build's own values' files are bundled.
Extras and progress only one version has
export default defineGallery({ only: 'adult', title: 'At night', image })
only works on gallery pictures, movies, endings, achievements, journal entries and replayable events. In the other builds the entry is an empty stand-in: its pictures are not in the build, it is not listed in Extras, and it does not count towards "Found 42%". Write only at the top level of the definition (the build reads it as text).
Saves
A save records the version that made it. Loading one made by another version asks first ("Some scenes and pictures may be different or missing"), then loads it.
Nothing of another version leaks
A build never contains anything of a version it was not made for: not a variant scene's text, and not what only that scene uses, even when it sits in a public folder.
events/park.adult.vn cg secret · sfx sfx/moan · anna(3): A line only the adult park has.
gallery/secret/ used by no other scene → not in the all-ages build (picture, thumbnail, title)
gallery/pond_memory/ also shown by other scenes → in every build (as it must be)
audio/sfx/moan.ogg → not in the all-ages build (with moan.ja.ogg)
audio/voice/en/park/anna_0003.ogg only the adult line's clip → not in the all-ages build
lang/ja/index.ts the adult line's translation → taken out of the all-ages build
- What counts as only that version's: anything named for a value the build lacks (
park.adult.vn,day.adult/,variants/adult/,only: 'adult'folders), and the gallery pictures, movies, endings, achievements, journal entries, backgrounds, insets, sounds and voice clips that only those use. A gallery picture left out takes its folder's text with it (its title). - "Used" means named in any other content file: a scene, a map, an item, a route,
scenes.ts(the music room). If another scene uses the same CG, it ships: keeping that apart is up to you. - Lines only that version has are taken out of every language file, and so are the reworded lines of
variants/<value>/strings.ts. - The build checks itself: if a file, module or line of another version would still be in it, the build stops and lists what. Ids made up at runtime (
cg('secret_' + n)) can't be followed: write ids out in full in variant scenes.
Things to know
- Voice clips are followed for
.vnscenes by their voice numbers. In a.tsscene, name such a clip in full:say('anna', '…', { voice: 'park/anna_0012' })(a plain number there can't be followed, and the clip would ship). - Patches dropped next to an installed game (KiriKiri style), add-ons and mods are not built yet (dev-notes/later.md).