# Default system screens

## Asset and scenario encryption (desktop version)

Set `build.encrypt` in `liminalia.json` to true ("Encrypt assets and scenario (desktop)" in Studio's project settings), and the desktop version's
assets, scenarios, data, characters, translations, flowchart and the packs included in the export are encrypted (AES-256-CTR), and the app decrypts them when it reads them
(it also handles reading sound and video from the middle). Opening the bundled file (asar) doesn't give usable files as is. The key has to be inside the app,
so someone who puts in the effort can break it (this is true of every engine).
- There's one key per project, saved in `.liminalia/encrypt-key` (the same key for the exports for every OS). Patches (`lim patch`) decrypt the contents with the key inside the app of the previous export
  to compare them, and encrypt the patch with the same key
- The browser and mobile versions aren't encrypted (they're delivered to the player's device, so they can't be fully hidden)
- The export screen shows the current settings for encryption, the save location and save protection (clicking one opens that field in the project settings)

## Font subsetting

Write `{ "files": ["others/fonts/main.otf"], "text": "characters to add" }` in `build.subsetFonts` of `liminalia.json`, and on export the font is subset
to only the characters the game uses (ASCII, kana, and full-width letters, digits and symbols are always kept; characters are collected from scenarios, data, translations, liminalia.json, the source of project plugins,
the text of the engine's system screens, and the packs included in the export (scenarios, data, translations and characters in `packs/<id>/`)). If characters come from elsewhere, such as name input, add them to `text`. The format (ttf, otf, woff, woff2) is kept.

## Including only the assets in use

With `lim build … --only-used`, or `"build": { "onlyUsed": true }` in `liminalia.json` ("Include only the assets in use" in the Studio's export settings),
the export leaves out the assets `lim unused` lists (those whose names appear nowhere in the scripts, data, `cast.json`, `liminalia.json`, the project's plugins
(including ones in folders outside the project or in `node_modules`), the project CSS (`ui.css`) and screen templates (`ui.templates` and `ui/screens/`) with the files next to them,
packs, translations or character models. Drafts and backups elsewhere in the project folder aren't read).
The export log shows how many were left out, their size and their names. Voices (`voice/`) and the assets of the selected theme are never left out. Nor are assets matching a
numbered `@flipbook` pattern (`slash_{nn}.png`), or assets whose name begins or ends with text joined in an expression (`"radio_" + n`). A folder with a command whose asset argument is
an expression (such as `@bg (game.place)`, or `{@se (…)}` inside text), or whose `folder=` is an expression, is kept whole, since the script doesn't say which assets it uses.
The check (asset existence and the plugins' checks) is then run again as if the left-out assets were gone, and any asset that would cause a problem is put back. Names built inside plugin code can't be traced,
so after exporting, run `lim playtest` to the end and check that no asset failed to load.
If you ship updates with `lim patch`, set `build.onlyUsed` rather than passing `--only-used` (the export made for the patch reads only the settings,
so with `--only-used` alone the left-out assets would be added to the patch).

## Steam (desktop version)

- **Cloud saves**: The desktop version keeps saves, read history and settings in a file per key (data earlier versions put in localStorage is moved at the first
  launch). In Steamworks Auto-Cloud, with the default (the OS's standard location), set the root to "WinAppDataRoaming" on Windows and "Mac Application Support" on Mac
  with the subdirectory `<title>/saves`, and on Linux set the root to "LinuxHome" with the subdirectory `.config/<title>/saves`; the pattern is `*.json`.
  If you set `saves.location` to `"portable"`, set the root to "App Install Directory" and the subdirectory to `savedata` on Windows and Linux
  (the default of earlier engine versions on Windows and Linux; a game shipped with Auto-Cloud set up that way keeps the same place by writing `"portable"`)
- **Rich Presence**: Show it with `@presence "Chapter 1: The Hill of Stars"` and clear it with an empty string. When a chapter in `extra.chapters` is reached, its title is shown automatically,
  and it's cleared on returning to the title. In the Rich Presence localization in Steamworks, provide `"#Status"` as `"%status%"`
- **Steam Deck and gamepads**: Text input (`@text-input`) shows Steam's on-screen keyboard when the game is played on Steam Deck or a gamepad is connected
  (entering text confirms it. If the player cancels, they can type in the game's field)
- **Workshop** (`build.steam.workshop`): Loads subscribed items as packs
- **Steam Input** (`build.steam.input`): Binds actions to gamepad buttons and system screen controls
- **DLC**: With `steam` (the DLC's App ID) in `build.store.products`, `@purchase` and `system.purchases` work.
  For the Workshop, Steam Input and DLC settings, see [distribution.md](../distribution.md)

## Crash reports

Exported games keep one uncaught exception, along with the version, the position being played and the environment (the desktop version also keeps it as a file in `logs/` in the save location, and
if the renderer process crashes, records it and reopens the window). The desktop version's `logs/` also keeps uncaught exceptions and rejected Promises in the main process, and failures to write saves
(once per launch), and keeps only the newest 20 `crash-*.log` files. If the renderer process crashes 3 times within a minute, it stops reopening the window and tells the player
(who chooses to restart or quit), and from the next launch on, it displays without the GPU (`gpu.json` in the save location; the GPU is used again when the game's version changes, or when the file is deleted).
If it stops before showing the window, it tells the player and quits. If you write `build.crashReport.url` in `liminalia.json`, the player is asked at the next launch,
and if they answer "Yes," the crash report is sent as a JSON POST (`project`, `message`, `stack`, `at`, `version`, `userAgent`, `date`, plus `kind`, `source`, `step`, `trail`,
`diagnostics`, `build`, `engine`, `platform`, `language` and `screen`, which tell what happened and on which line). The fields, and how to map positions back with source maps (`build.sourcemap`), are in
"Crash records and source maps" in [distribution.md](../distribution.md).

If the project sets `build.analytics.url`, the game asks at its first launch whether it may send play statistics, and Settings gets "Send play statistics"
("Play statistics (optional)" in [distribution.md](../distribution.md)).

## Content warnings, content filtering and editions

- **Content warning** (`ui.contentWarning`: `{ title?, text, button?, always? }`): Shown at startup, before the title. Once the player agrees, it isn't shown again
  (it's shown again when the text changes; with `always`, every time). In the desktop version, "Quit" closes the game
- **Startup splash** (`ui.splash`): After "Click to start," logos and a notice are shown once before the title. If a plugin has `splash`, that's used instead
  ```json
  "splash": {
    "logos": [{ "image": "brand/logo.png", "background": "#ffffff", "time": 2500 }],
    "notice": { "title": "Please read first", "blocks": [{ "label": "01 — FICTION", "text": "This story is fiction.\nIt has no connection to real people or events." }], "time": 6000, "auto": true },
    "skip": true,
    "fade": 600
  }
  ```
  `logos` are the logos shown in order (an image in the image folder, the background color, and how long it's shown), and `notice` is the notice (the heading, and a list of `label` and `text`, where `text` splits lines at line breaks;
  the background color `background`, text color `color`, the time until it moves on automatically `time`, and with `auto: false`, it waits for a press). Pressing (click, Enter, Space) moves on to the next (not with `skip: false`).
  `fade` is the time it takes to fade out at the end, leaving the background color. Change the look with `.lm-splash`, `.lm-splash-logo`, `.lm-splash-notice`, `.lm-splash-block` and `.lm-splash-text` in CSS.
  In Studio, "Startup splash" in "Game settings" lets you edit each item without writing JSON
- **Toning down content** (`ui.contentFilter`: `{ label?, default?, assets? }`): Adds an item to the "Display" tab of Settings. The script
  branches on `system.content_filter`, and `assets` replaces assets (paths from the folder for each kind, like `"bgimage/a.png": "a_safe.png"`).
  When the setting changes, the screen during the game is rebuilt
- **Editions** (`build.variants` and `lim build … --variant name`): For each edition, add `forbid` (stop the export if these are included, so that adult assets don't
  get into an all-ages version) and `exclude` (leave these out), and `contentFilter: true` keeps the content toned down without letting the player change it. The script reads the edition's
  name with `system.variant`. Each edition is exported to its own folder.
  The export screen of the authoring app also lets you choose one under "Edition," below the platforms (shown only for projects with `build.variants`. "Standard" exports without an edition.
  The previous choice is remembered per project. `packages/studio-desktop/src/pages/export.ts`)

## Carrying over from a demo

In `saves.carryFrom` of `liminalia.json`, map the ids of games whose saves can be carried over (such as a demo) to their titles (`{ "my_game_demo": "My Story Demo" }`).
- At the first launch, if this game has no save data yet and save data for that game is found, it asks once whether to carry it over. The browser version reads from the same storage
  (so both must be hosted at the same place), and the desktop version reads from the save location of the app with that title. Save data in an unreadable form (saves.protect) can be carried over too
- "Import saves" in Settings can also load save data exported from that game

## Additional content and fixes (packs)

Put `pack.json` (`id`, `title`, `version`, `requires` (the required version of the base game), `order` (loading order), `extra`) along with
`scenario/`, `data/` and `assets/<kind>/` in `packs/<id>/` in the project folder, and `lim build` includes them in `packs/` of the export. To distribute one later, export it with `lim pack packs/<id>`
and put it in the game's `packs/` (`Resources/packs/` in the desktop version; for example, a Steam DLC depot).
- Packs are loaded at startup; scenarios, data and assets with the same name as the base game's are used first (replacements for fixes). Those with new names are added
- `extra` (CG, replays, music, achievements, glossary, chapters) is added after the base game's lists. The flowchart uses the one with the packs merged in (made by lim pack)
- The script can check whether a pack is installed with `system.packs.<id>` (the value is the version) (`@if (system.packs.dlc1)`)
- Packs whose `requires` doesn't match the base game's version (`version` in `liminalia.json`) aren't loaded. Packs aren't loaded on the dev server
- The desktop version looks in `packs/` in the save location (installed by updates), `Resources/packs/`, items subscribed in the Steam Workshop (`build.steam.workshop`)
  and those included in the export, in that order, and for the same id uses the one found first

## Updates (desktop version)

Write the URL of the manifest made by `lim update-manifest` in `build.update.url` of `liminalia.json`, and the desktop version checks for new packs or a new version of the game at startup (not with `checkOnStartup: false`)
and with "Check for Updates" in the menu (`@check-update` from the script).
- The check at startup runs without making the player wait, and asks on the title screen when no other screen is open. Updates the player declines aren't asked about again at later launches (the menu still asks)
- Packs: If the player answers "Yes," it downloads the pack, checks its sha256, puts it in `packs/<id>/` in the save location and asks whether to restart (restarting, like closing,
  finishes the autosave and saving first)
- The game itself: If the player answers "Yes," it downloads and checks the file for that OS, if there is one; for a Windows installer, it starts the installer and quits the game.
  For a Mac zip or a Linux tar.gz, it extracts and checks it, shows "Replacing the game with the new version and restarting," quits, swaps the files and starts again
  (other files, and installs in places where the files can't be swapped, are opened instead). If there's no file, it opens the download page
- The questions use the standard confirmation dialog (or `screens.confirm`, if the project replaces it; the kinds are `update` and `update-restart`).
  For how to make the manifest and its shape, see [distribution.md](../distribution.md)
