# Default system screens

## Screens

The game screen is drawn at the size of `screen` in `liminalia.json` (1280×720 by default; it's scaled down or up to fit the player's window). Coordinates of backgrounds, sprites, `@image` and so on are in `screen` coordinates.

- **Text and window size**: The px values of the message window, choices, system screens and `ui` are set for a base size (1280×720 for landscape, 720×1280 for portrait). If `screen` differs from the base, they're scaled by the same ratio (1920×1080 is 1.5 times and looks the same as 1280×720. 1024×768 is 0.8 times, and the extra height leaves more room for the layout on screen)
- **Portrait games** (a `screen` taller than it is wide): The game screen gets the class `lm-portrait`, and the default layout changes (`packages/web/src/system/portrait.css`). Values you write in `ui` are applied as they are
  - Message window: 24px margins on the left and right, 64px at the bottom (for the quick menu), at least 250px tall. Text 28px, names 24px. The margins of sound novel mode (NVL) are narrower too
  - Choices: 600px wide, 26px text. Even if `ui.choice.width` is wider than the game screen, they fit inside the game screen and the text wraps
  - Title: The title and buttons are larger, and the buttons are 400px wide. Even with a horizontal layout, they wrap if they don't fit
  - Save, Load: 8 slots in one column. The image is cropped to the slot's height. Thumbnails are made in the game screen's aspect ratio (256px on the long side)
  - Settings: Item names go above the controls. Log: The speaker goes above the text. Menu: Stays in 2 columns, with a height that's easy to tap. Extras: Images in 3 columns, in the game screen's aspect ratio
  - Standing positions: If `frame` in `cast.json` has the standing positions, sprites are placed as written. If not, the centers of left / center / right are placed at 30%, 50% and 70% of the width, at the bottom of the screen (`auto` divides the width equally by the number of characters, as before). The tool for adding standing positions uses the same ratios for the initial position and size, with sprites up to about 70% of the screen height
  - Camera: `@camera` moves are kept within the range where the edges of the background don't show (portrait is narrower, so moving the same amount as in landscape would show the edges. When `@bg-place` places a background larger than the screen, this limit doesn't apply). Shake amounts for `@quake` and so on are as written
  - Transition effects (`method` of `@bg`, rules) adapt to the size of the game screen, so you write them the same way
- **Background focus** (`ui.backgroundFocus`): The position kept when a background is cropped. Background file name → `object-position` value, where `"*"` means everything else (`{ "*": "62% 50%", "hill_night.webp": "30% 50%" }`). Without it, the center is kept. It applies only when cropping happens (backgrounds whose aspect ratio differs from the game screen's, or when placed in a frame with a different aspect ratio). It also applies to the title background (`ui.title.background`) and thumbnails, but thumbnails of 1280×720 games aren't cropped, so they don't change
- **Portrait template**: `lim new --size 720x1280` (also "720×1280 (portrait, for phones)" in New Project in the desktop app) makes the sample sprites about 70% of the screen height, aligned to the bottom, and writes a focus for the sample background

- **Save, Load**: Save slots with a thumbnail and the beginning of the text. They also show the chapter name and play time (not in save data made by earlier versions).
  The chapter name is decided in this order: the project plugin's `slotChapter` → `ui.chapterNames` (`"file#label"` or `"file"` → name; looked up by the current label first, then the file) → the number and title in `chapters` in `liminalia.json` →
  the title of the last extras chapter (`extra.chapters`) reached in this playthrough → the file name. Play time counts from "New Game" or
  from the play time of the loaded save (only during the game; not on the title, in replays or while in the background).
  Quick saves are listed on the "Q" tab of the Load screen, newest first. Used slots have "Memo" (adds a one-line memo),
  "Lock" (the slot can't be overwritten, deleted or used as a move destination), "Copy" and "Move" (click, then choose the destination slot, on other pages too; only Move carries the lock along) and "Delete"
- **Autosave**: Listed on the first tab of the Load screen ("A"), newest first (not shown on the Save screen; the only button is "Delete"). There are `ui.autosave.slots` slots (3 by default), and
  once they're full, the oldest is replaced. An autosave that would resume from the same place as the newest one overwrites that slot (so going to the background many times on the same page doesn't use up the slots).
  It saves at `@autosave` (resuming from the command after it), and when quitting or going to the background (switching tabs, going back to the home screen on a phone, closing the window in the desktop version.
  At a click wait or a choice, it saves that point; in the middle of an effect, it resumes from the start of the last page or choice shown. It doesn't save on the title, in replays or in Studio's preview), and
  at the times set in `ui.autosave.on` (when choices are shown (on by default; turn it off with `choice: false`), at the start of a chapter (`chapter: true`; the first page where the chapter in `chapters` changes, and
  the start of an extras chapter), and every set number of pages read (`pages`). These resume from the start of the page, and the text in the list is that page's. It doesn't save at a choice returned to by rollback,
  or in a playthrough started partway for development).
  The Android app keeps save data in the app's files and, when going to the background, waits until the autosave is saved (the mobile version section of the README).
  The iOS app also asks to keep running in the background when going to the background, until the autosave is in the app's files (up to 2 seconds; see "Where saves are kept" below).
  When the screen's process in a mobile app dies (for example, when it's stopped to free memory while in the background), the game doesn't stay on a black screen; it reloads
  and continues from the autosave made when going to the background (after "Tap to start." If it had already come back from the background, it starts as usual. If it dies 3 times in a minute, it doesn't reload).
  If the project replaces the system screens, handle it with `system.resumeLeft()`
  `@autoload` continues from the newest autosave. Turn off autosaving when quitting and going to the background with `ui.autosave.leave: false`
  (when the project replaces the Load screen, it's off unless you write it. A project's Load screen can list autosaves with `system.autoSlots()`)
- **Log (backlog)**: The speaker (in the character's name color) and the text, including ruby (small reading aids above characters), styling and line breaks. Each character's text look and the font the player chose also apply. Pages with voice can be replayed with the play button.
  Chosen options are kept too ("Choice" in the speaker column, and the chosen text in the accent color; also when `default` is chosen because time ran out. Options with `call=true`,
  image buttons without text and clickable areas aren't kept). To not keep them, use `ui.backlogChoices: false`
  For the newest 100 pages, "Go back" returns to that page (asks first; progress after it is lost. After loading, up to the newest 20 pages kept in the save)
- **Settings (config)**: The "Text" tab has "Text speed," "Auto delay," "Skip" (Read only / All), "Skip speed" (Fast / Fastest. Fast moves on at a speed where each page can be seen; Fastest by default), auto and skip after choices
  (Stop / Keep going; Stop by default. A skip started with "Next choice" or "Next unread" doesn't keep going), "Choice time limits" (when off,
  `@choice timeout=` doesn't time out either and no remaining-time bar appears, for people who can't read when rushed; on by default), "Language" (when the game has several languages) and
  a preview of the text speed. The "Display" tab has "Text box opacity" (the opacity of the message window's background color and image; the text isn't faded), "Text size" (80–200%. Applies to the text, choices, name box, backlog and system screens. Above 100%, system screens are laid out more tightly, Save and Load become one column that scrolls inside, and Settings scrolls as a whole. Title buttons go up to 1.5 times. If the project sets `ui.screen.textScale: "message"`, only the text and choices),
  "Font" (Default / Serif / Sans / Rounded / UD. UD is a font designed for readability; if it isn't available, Sans), "Screen shake" (Full / Reduced. When Reduced, @quake (including its decaying shake) and @chara-shake don't shake),
  "Flashing lights" (Full / Reduced. When Reduced, @flash puts a faint veil over the screen once instead of flashing. Screen shake and Flashing lights are set separately and are kept when resetting to defaults), "Read text color" (Off / On. If not set, it follows the game's `ui.text.readColor`;
  On adds a default color even if the game doesn't set one), "Line spacing" (Normal / Wide / Wider; 1.25 and 1.5 times the game's line height), "Text outline" (Default / None / Shadow / Outline; Default keeps the game's shadow and outline) and, where fullscreen can be switched, "Display" (Window / Fullscreen; in the desktop version, kept for the next launch).
  The "Sound" tab has "Master volume" (applied to all BGM, sound effects, voice and video) and "Mute" (also toggled with the M key and R3 on a gamepad, with a notice), "Music volume," "Sound volume," "Voice volume," a voice volume for each speaker heard so far (characters whose voice hasn't been heard yet
  aren't shown. If the game sets `ui.settings.voiceSpeakers` to `all`, the speakers in cast.json are listed from the start; with `masked`, they're listed but the names of characters not heard yet are hidden as "???"), whether to stop the voice when advancing ("On advance"), and whether to lower the BGM while a voice plays ("BGM during voice"; lowered by default).
  The "Display" tab also has "Read aloud" (once a page is fully shown, the device's voice reads the speaker and text. Characters with ruby are read by their ruby (ruby made only of "・", which marks emphasis dots, reads the base characters),
  and lines with voice aren't read. Auto advances after reading. It also reads choices and screen buttons selected with keys or a gamepad), "High contrast" (makes the message window opaque black and the text white, and gives choices and system screens sharp edges. If the OS is set to increase contrast,
  it starts on), "Window size" in the desktop version ("Default," plus the sizes from 0.5 to 2 times the game size that fit on the current display), "Confirmation messages"
  (when off, skips the confirmations for returning to the title, quitting, loading, overwriting and jumping. Deleting saves, importing, carrying over and sending reports are still confirmed),
  "Hide the idle mouse cursor" (during the game, hides it after 3 seconds without movement), "Color vision" (Protan, Deutan, Tritan. A color matrix that shifts color differences that are hard to tell apart
  to ones that are easier, applied to the whole game screen, including the text and screen buttons) and "Sound captions" (`ui.captions` and `@se caption=`).
  The "Controls" tab changes key bindings (click "Change" for an action, then press a key. These are layered on top of the project's `ui.keys` and the defaults) and swaps gamepad
  buttons (click "Change" for a role, then press a button. The role that button had moves to the button that had this role before). The text is built from one element per character, so screen readers are given the continuous text of the page, once it's fully shown, in a hidden place (aria-live)
  (dialogue is passed as written, such as ソウ「おはよう」; dialogue without brackets becomes "ソウ：…", or "Sou: …" in English. The text of `@describe` and of `alt=` on images comes before the text;
  chapter 7 of [format.md](../design/format.md)). Chapter cards and chapter ends (`@chapter-card`, `@chapter-end`) pass their number and title to screen readers and text-to-speech when they appear (not while skipping). System screens open as dialogs (`role="dialog"`, `aria-modal`, named by their heading), focus moves into the screen,
  and Tab cycles only within the screen. When the screen closes, focus goes back to where it was before it opened.
  Project CSS can match its own parts with `--window-opacity`, `--text-scale` (text and choices), `--lm-text-scale` (name box, backlog, system screens), `--player-font`, and the game screen classes `lm-high-contrast`, `lm-text-large` (text size above 100%) and `lm-touch` (a touch device or a portrait game; it also has `--lm-touch`, the factor that makes text larger, and `--lm-touch-target`, the smallest size of something to tap).
  At the bottom are "Export saves" and "Import saves" (saves, read history, settings and system variables in one .json file. For backups and for moving to another
  computer or browser. Files from another game aren't imported)
- **Extras**: CG ("Gallery"; only the unlocked variants, advanced by clicking), replays ("Scenes"; a replay plays and returns to Extras when it ends. You can't save during a replay),
  "Music," "Achievements" (achievements that count show "current / goal") and "Endings" (`extra.endings: true`; the same list as the "Endings" tab of the flowchart.
  Only endings reached show their name and the scene title, and if there's a record of reaching one, pressing it reads again from there). Under the heading is the completion ("Completion": the completion rate, and the counts of read text, CGs, replays, endings and achievements).
  If there are two or more `group`s (without them, chapter numbers or titles from `chapter`), CGs are split into tabs, with the number and share of unlocked ones in each group ("4 / 5 (80%)").
  The large view opens as a screen of its own (the tabs and the list behind it can't be pressed), with the title and `description` below. Click, Enter, Space and A on a gamepad show the next variant
  (closing after the last one), ← → and left and right on the D-pad the previous and next CG, ↑ ↓ and up and down on the D-pad the previous and next variant, and the wheel goes back and forward (through the variants, then on to the next CG).
  The wheel while holding Ctrl (a pinch on a trackpad), a finger pinch, + and -, and RT and LT on a gamepad zoom in (up to 4 times; 0 and X on a gamepad reset it),
  and while zoomed in, dragging, the wheel and the right stick move the image. Swiping sideways with a finger shows the previous or next CG. Esc, right-click and B on a gamepad close it
  The lists are in `extra` of `liminalia.json` (extras in chapter 10 of [format.md](../design/format.md)). Plugins can also read the completion with `system.completion()`
- **Music room** (`extra.music`: an array of `{ file, title?, artist?, description? }`. Only tracks played at least once with `@bgm` can be chosen): The player area at the bottom has the current track,
  artist, description, a seek bar, play and pause, previous and next track, repeat ("Repeat all," "Repeat one," "No repeat") and "Shuffle." "Repeat all" and "No repeat" play each
  track without repeating it and move on to the next track the player has heard when one ends ("No repeat" stops after the last track). "Repeat one" repeats at the loop points embedded in the track
- **Glossary** (`extra.glossary`: an array of `{ id, term, reading?, aliases?, description, group?, link? }`): When a `term` or one of its `aliases` appears in the text,
  it's unlocked with a notice, and the word gets a dotted underline in the text (clicking it shows the description without advancing the text. `link: false` only unlocks it, without the underline.
  There's no underline where characters and their positions don't line up, such as grouped digits in vertical writing). `@glossary-unlock id` also unlocks a term. Terms are listed in "Glossary" in Extras, sorted by reading
- **Codex** (`data/codex.json`; "Codex" in chapter 10 of [format.md](../design/format.md)): Listed in the menu and in Extras. Category tabs, a list of entries (marked "New" until read), an image and text in paragraphs, and related entries.
  During play, it shows what this playthrough has unlocked; in Extras, the record shared across all saves. When a new entry is unlocked, a notice appears at the edge of the screen
- **Investigation** (`@investigate`, `data/investigation.json`): A screen where the player clicks spots on the background to investigate them. Viewpoint tabs, marks on investigated spots, a description on mouse over, and "Finish" (`finish: "button"`)
- **Chapter select** (`extra.chapters`: an array of `{ id, title, target, synopsis?, thumb? }`): A chapter is unlocked the first time the first page of its `target` is reached,
  and that point is recorded. From "Chapters" in Extras, the player can see the title, synopsis and image, and read again from that chapter (asks first)
- **Flowchart** (available when `extra.flowchart` is `true` or `{ "titles": { "file#label": "title" } }`; opened from the title and the menu):
  It builds the connections between scenes from the script (the project doesn't need to write anything). Scenes are split at the start, at choice targets and where routes merge; linear stretches and
  jump targets of custom commands (such as investigation spots) are merged into the scene they came from. Only read scenes show a title (the first text, or `titles`); unread scenes are hidden.
  The first time a scene is reached, that point is recorded (shared across all saves), and the player can read again from there (asks first). At the top are the read rate (the share of text pages read) and
  the number of endings, and the "Endings" tab lists the endings (the wording of the kind in ending= of @title-screen and the name in title=, or "Ending n").
  In multilingual projects, scene titles (the first text and the speaker name) and choice text are shown with the translations in the translation files (the text lines and choices in `lang/<language>.json`)
  (`titles` are translated as text of the project settings. `flow.json` in exports from earlier versions, which has nothing to look up translations from, stays in the original language)

Read history, settings and system variables (including the records of unlocked extras) are saved once, shared across all saves.

**Where saves are kept**: The browser version uses IndexedDB (the `saves` store of the `liminalia` database, with keys `liminalia:<game id>:<name>`),
the mobile apps use the app's files (one file per key: `saves/` in the app's files on Android, and `liminalia-saves/` in Application Support on iOS,
because WKWebView's IndexedDB can be cleared when the device runs low on space and so on), and the desktop version uses files in the save location.
What earlier versions of the Android app put in SharedPreferences and of the iOS app put in IndexedDB is moved once, at the first launch (the originals aren't deleted).
Saves in the phone apps are included in the device's backup and carry over to a new device (iCloud backup on iOS; on Android, backup to the Google account and
device-to-device transfer. On Android, only `saves/`, where saves are kept, is included so it stays under the 25 MB limit). There's no cloud save for using two devices at the same time (Steam has Auto-Cloud; see "Steam" below).
When the app can't write (not enough space and so on), it shows "Could not save". Saves, read history, settings and variables shared across all saves (including unlocked extras and the records of the flowchart and chapters)
all go in the same place. localStorage (about 5MB, which a few dozen save slots with thumbnails fill up) isn't used.
- At startup, it loads everything for the game (and for the games in `saves.carryFrom`), then answers from a copy in memory, and writes what's saved to IndexedDB in the background
- Data that earlier versions put in localStorage is moved to IndexedDB when found at startup, and removed from localStorage
- If the page closes before writing finishes (what was saved while in the background, and writes not finished when closing), it's also put in `liminalia-journal` in localStorage,
  and applied at the next startup. If the same game is open in other tabs, they tell each other what was saved
- On the first save, it asks the browser not to delete the data (`navigator.storage.persist()`; Firefox asks the player). Safari may delete the data of pages not added to the home screen
  after 7 days without use (if the request isn't granted). Keep important save data with "Export saves" in Settings
- Where IndexedDB isn't available (such as browsers that block site data), it uses localStorage as before
- If writing to IndexedDB fails (not enough space and so on), it shows "Could not save". The desktop version shows the same when it can't write a file
  (on Windows, antivirus or sync software holding the file, not enough space, a location that can't be written to and so on). When the file is held (EPERM, EBUSY),
  it waits a little and tries again before giving up, and leaves the reason in `logs/` in the save location. Before closing and before restarting, it waits for writes to finish
- Tools for screenshots and automated checks can see the contents with `window.__liminalia.saves` (`entries`, `set`, `remove`, `clear`) and `flushSaves()`
Read status is recorded with a key for the file and page (made from the page's speaker and text, plus the speaker and text of the page before it). Even if editing the script shifts lines
or labels are renamed, read status stays put, and newly added pages stay unread (read-only skip doesn't skip them). The page right after an added or rewritten page
also becomes unread again, because the page before it changed. Read status that earlier versions recorded by line position is moved to keys using the current script's lines when that file is loaded
(lines that had already shifted because the game was updated before the move can't be recovered).
If `saves.protect` in liminalia.json is true, everything is saved in an unreadable form, and anything rewritten is treated as missing.
If there's an `afterLoad` (`file#label`), right after loading, the game calls it and then returns (with `@return`) to the loaded page
(for recalculating `temp.` values, which aren't in saves, and so on). Save data includes the version of the game that made it (`version` in `liminalia.json`), which expressions read as
`save.version` (for a loaded playthrough, the version of that save data; for a new playthrough, the current version; empty for save data from before versions were included).
When an update changes the names or meanings of variables, convert save data from earlier versions in `afterLoad` ("Save versions" in [format.md](../design/format.md)).
Save data keeps a marker for the page (the line, and a key made from the text or choice text) along with the page position. Even if updating the game shifts script lines,
loading finds the page with the same text and resumes there (if not found, the page nearest the original line; both are reported with the diagnostic `save-relocated`).
Saves made inside `@call` or a macro adjust their return points the same way (returning to the command after the call; "Save versions" in [format.md](../design/format.md)).
