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

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:

  1. sign.v.L.png (this version, in the player's language)
  2. sign.v.png (this version: a variant always beats a language, so a censored picture stays censored in every language)
  3. sign.L.png (the player's language)
  4. 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:

WhatEvery build / languagesThe "cn" version / its languages
Pictures anywhere (items, portraits, UI, CGs, previews; png, jpg, webp, avif, gif, svg)icon.png, icon.ja.pngicon.cn.png, icon.cn.ja.png
Backgrounds and insets (backgrounds/, insets/)bus_inside.svg, bus_inside.ja.svgbus_inside.cn.svg, bus_inside.cn.ja.svg
Gallery pictures (and their thumbnails)gallery/pond/image.png, image.ja.pngimage.cn.png, image.cn.ja.png (the thumbnail is made from the cn picture)
Sounds, music, ambient (audio/)sfx/smoke.ogg, sfx/smoke.ja.oggsfx/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.oggmusic/ja/town.cn.ogg
Voice lines (the language is the folder)voice/ja/park/anna_0012.oggvoice/ja/park/anna_0012.cn.ogg
System voicesystem_voice/anna/saved.oggsystem_voice/anna/saved.cn.ogg
Videos, movies, video backgroundsmovies/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.pngsky.cn.png, sky.cn.ja.png
Aseprite, whole file (portraits, sprites, layered CGs and backgrounds)jack.asepritejack.cn.aseprite (its own language layers as usual)
Aseprite, one layer or groupEyes, Eyes.jaEyes.cn, Eyes.cn.ja (in the same file)
Spine exportsanna.atlas + anna.json + pagesanna.cn.atlas + anna.cn.json + its pages (or only a page: anna.cn.png)
Tiled maps and tileset imagestown.tmx, tilesets/countryside.pngtown.cn.tmx (a different layout), countryside.cn.png (other tiles, same layout)
Fonts (fonts/)pixel.woff2pixel.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 importhelpers.tshelpers.cn.ts
Textthe scriptsvariants/cn/strings.ts rewords lines, then every language translates the new line (below)

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

Things to know