Screens & windows
Everything that isn't the map: the title screen, windows, minigames and the HUD. Input, the look and settings have their own pages.
Starting the game
src/content/start.ts runs when the game loads, and again on "Return to title". It decides what the player sees first: boot screens (first start only), "press any key", the title screen's entrance, then the menu.
export async function start(game: Game) {
game.maps.preload('heaven/before_god') // the first map: load in the background while the title is up
await game.title.boot() // boot screens, only the first time after launch
await game.title.show() // "press any key" (unlocks sound), then the entrance
for (;;) {
const latest = game.save.latest()
const pick = await game.title.menu({
...(latest ? { continue: 'Continue' } : {}),
new: 'New game',
load: 'Load game',
...(game.extras.anyUnlocked() ? { extras: 'Extras' } : {}),
settings: 'Settings',
...(canQuit ? { quit: 'Quit' } : {}), // desktop app only
})
if (pick === null) return // a save was loaded from the Load window
if (pick === 'continue' && latest) return game.save.load(latest.slot)
if (pick === 'new') return game.save.newGame()
if (pick === 'load') game.windows.open('saves', { mode: 'load' })
if (pick === 'settings') game.windows.open('settings')
if (pick === 'extras') await game.minigames.open('extras')
if (pick === 'quit') quit()
}
}
game.title.menu({ key: label })resolves with the picked key (labels are translated), ornullif the title screen went away meanwhile.src/content/ui/TitleFrame.tsxis the frame every title screen variant shares:<TitleArt />(the variant, behind), the prompt and menu on the right (so short phone screens fit),<TitleSwitcher />bottom left and the version. Place<TitleMenu />anywhere; it fills its box up to 320px wide. The "press any key" text (on black, before the art) adapts to keyboard, gamepad or touch.- Windows open above the title screen (Load, Settings, Extras).
Boot screens
Notices and logos shown when the game starts, before "press any key". Every .tsx file in src/content/boot/ is one screen, found automatically. They play one after another (lowest order first, then by file name): fade in from black, stay, fade to black, next. They never play again on "Return to title".
// src/content/boot/warning.tsx
export default defineBoot({
order: 1,
skippable: false, // true = confirm (Enter, Space, pad A), a click or a tap ends it early
fadeIn: 600, // ms
steps: 5000, // ms on screen
fadeOut: 600, // ms
preload: [picture], // optional: imported files, loaded before the first boot screen
screen: () => <Box sx={{ position: 'absolute', inset: 0, display: 'grid', placeItems: 'center' }}>…</Box>,
})
- Stills:
steps: [1200, 2000]gives the screen astepprop: 0 for 1.2 s, then 1 for 2 s. Draw more as it goes up (step >= 1 && …); seeboot/logo.tsx. skippable: falsecan never be skipped, by any key, button, click or tap. A skipped screen fades out quickly and the next one starts; each screen needs its own press.- The title screen loads in the background meanwhile. No files in the folder = no boot screens. A file starting with
_is a helper, not a screen.
Entrance and menu
After "press any key" the title art plays its entrance; only when that ends do the menu, the switcher and the version appear. The menu buttons then fade in one after another, top to bottom, and cannot be used (click, tap, keys, pad) until the last one is fully in.
// src/content/titles/<id>/index.ts: how long the entrance takes
intro: 1200, // ms, or stills like a boot screen: [1000, 1600]
// src/content/titles/<id>/Screen.tsx
export default function Starlit({ step }: TitleScreenProps) {
return <><Sky />{step >= 1 && <Logo />}</> // step = number of steps once it is over
}
// src/content/ui/TitleFrame.tsx: how the buttons appear
<TitleMenu effect="right" distance={16} duration={350} stagger={110} />
effect:'fade', or'left'/'right'/'top'/'bottom'(fades in while slidingdistancepx from that side).duration= one button,stagger= delay to the next, both ms.- Skipping: confirm, a click or a tap during the entrance jumps to the end: the screen gets its last
step, its CSS animations jump to their final frame, and the menu is fully visible and usable at once. During the menu's fade-in it shows the menu in full. The skipping press never picks a menu item. - Short screens:
<TitleMenu sx={…} buttonSx={…} />style the list and each button.TitleFrame.tsxuses them withSHORT_SCREENfor smaller buttons on a phone held sideways, so 7 buttons fit a 375px-tall screen; a longer menu scrolls. - No
intro= the menu starts appearing right away. The switcher and version fade in with it (titleMenuIninTitleFrame.tsx).
Title screen variants
Like many visual novels, the title screen can change as the story goes on (an ending reached, a secret found). Each variant is a folder in src/content/titles/, found automatically:
// src/content/titles/good_ending/index.ts
export default defineTitle({
name: 'After the storm', // shown in the switcher
order: 2, // switcher order, oldest first
screen: () => import('./Screen'), // the art + entrance, loaded only when needed
preload: [logo], // files from outside this folder
music: 'music/title_2', // optional, from src/content/audio
})
// src/content/titles/good_ending/Screen.tsx: draws behind the menu, animates in when it appears
export default function GoodEnding({ phase }: TitleScreenProps) { … }
// anywhere (event, map, minigame): unlocked for good, across all saves
game.title.unlock('good_ending')
- The first one has
unlocked: true(titles/default). A new unlock becomes the current title at once; unlocking it again later keeps the player's own pick. Unlocks and the pick live in the persistent data, not in save slots. - Entrance: the screen component plays its animation (and its
introsteps, see above) when it mounts: after "press any key" and when the player switches to it. Switching cross-fades the old one out. - Switcher (bottom left, once two are unlocked, not while "press any key" shows): ◀ name 2/3 ▶. Tap the arrows, or Q / R (LB / RB on a pad).
- Preloading: before a variant shows, its code and every image, sound and video in its folder (plus
preloadandmusic) are downloaded and decoded, and fonts are ready. A dark cover shows meanwhile (a spinner after 0.4 s); keys are ignored until it is ready. The other unlocked variants then load in the background, so switching is instant; a switch before that waits on the old screen, never on a blank one. Everything is let go when the game starts. - Keep a variant's pictures and sounds in its own folder (or list them in
preload): anything else loads only when drawn, and can pop in during the entrance. game.title:unlock(id),select(id),current(),unlocked(),isUnlocked(id),lock(id)(testing). The dev panel has a Title screens section to unlock, lock and show each one.
Windows
// src/content/windows/notes/index.tsx → the window 'notes'
import { Button, Typography } from '@mui/material'
import { defineWindow, type WindowProps } from '@/core/define'
import { useLang } from '@/core/lang'
function Notes({ params, close }: WindowProps<{ topic: string }>) {
const t = useLang()
return (
<>
<Typography>{t('Notes about {topic}', { topic: params.topic })}</Typography>
<Button onClick={close}>{t('Close')}</Button>
</>
)
}
export default defineWindow({ title: 'Notes', component: Notes, width: 420, modal: false, closable: true })
game.windows.open('notes', { topic: 'slimes' }) // params typed from WindowProps
game.windows.toggle('inventory'); game.windows.close('notes'); game.windows.closeAll()
game.windows.isOpen('notes')
| Option | |
|---|---|
title | Title bar text (translated) |
width | Minimum width (number = px). The window grows wider if its content needs it, never past the screen. Default 420. |
modal | Dims everything behind and blocks clicks to it |
closable | Shows the × and lets cancel close it (default true) |
transition | How it comes in and goes out, like a boot screen's fades: { in: 180, out: 140, effect: 'slideUp', distance: 24, ease: 'ease' }. Effects: fade (default), scale, slideUp, slideDown, slideLeft, slideRight. Left out: it appears and goes at once (the default). A closing window takes no input while it goes; "Reduce motion" turns every effect into a fade. |
- Windows stack. Opening one that is already open brings it to the front. Click a window to focus it. Every window opens in the middle of the screen and sizes itself to its content (it can't be dragged); content taller than the screen scrolls.
- Keys: cancel (and menu) closes the front window; arrows/D-pad move focus between buttons (by screen position); confirm presses the focused button, or flips the focused switch / checkbox (Enter too, not only Space).
- Use Material UI components inside. Shared helper components go in a folder starting with
_(windows/_shared).
Windows that come with the game: menu (the pause menu), inventory, quests, party, journal, shop, saves, settings, confirm (the question behind game.dialog.ask), textinput (behind game.dialog.prompt and the event command input()) and credits (lists the names in src/content/credits.ts). They're content: change them freely. Extras is a full-screen minigame (src/content/minigames/extras).
Inside every window: Window.tsx
src/content/ui/Window.tsx draws the inside of every window (the ones above too): the title bar, then the window's own component inside <WindowContent>. The frame around it (picture, background) is window / panel in look/index.ts.
// src/content/ui/Window.tsx
import { WindowContent } from '@/core/ui/WindowContent'
export function Window({ id, title, closable, isTop, close, children }: WindowSlotProps) {
return (
<>
<TitleBar … />
<WindowContent sx={{ p: 2, overflowX: 'hidden', overflowY: 'auto' }}>{children}</WindowContent>
{id === 'settings' && ( // a logo in the bottom right corner, Settings only
<Box component="img" src={logo} alt="" sx={{ position: 'absolute', right: 12, bottom: 12, width: 48, pointerEvents: 'none' }} />
)}
</>
)
}
<WindowContent>must stay, once: it is where keys, buttons and focus reach the window (the first control is focused, a controller scrolls it). Itssx(padding, scrolling) is yours. Left out, the game warns in the console (dev only).- The window is
position: relative:position: 'absolute'sits on the window itself. Anything outside<WindowContent>(a footer, a logo) doesn't scroll away. - Props:
id(which window),title(translated; empty while it loads),closable,isTop(the front window),close(),children. Types:WindowSlotPropsin@/core/slots.
Windows the engine opens
The engine opens some content by its folder name. Each may look and work however you like, but keep the name:
- Always:
menu(the ☰ button, Back),confirm(yes / no questions),saves(saving and loading).pnpm gen, the dev server and builds stop with a clear message if one is missing. - Only for a feature you use:
shop(game.shops.open()),crafting,travel(fast travel),gameover,textinput(game.dialog.text()), and thebattleminigame. Without one, using its feature shows an error naming the missing folder.
The list is src/core/required.ts.
Minigames
The battle screen focuses what the player is likely to press: Attack on your turn, your own character when healing, the first enemy when attacking, and Continue when the battle ends.
// src/content/minigames/coin_flip/index.tsx
function CoinFlip({ params, finish }: MinigameProps<{ bet: number }, 'win' | 'lose'>) {
return <Button onClick={() => finish(Math.random() < 0.5 ? 'win' : 'lose')}>Flip</Button>
}
export default defineMinigame({ component: CoinFlip, quitResult: 'lose' }) // cancel quits with 'lose'
const result = await game.minigames.start('coin_flip', { bet: 10 }) // 'win' | 'lose'
- A minigame covers the whole screen and fades in/out.
finish()counts only once. - Without
quitResultthe player must finish it. - Real-time games:
useGameLoop((dt) => …)from@/core/minigame/useGameLoop. It pauses while a window is on top. Keep the game state in refs and draw to a canvas; read input withgame.input.isDown('left'). Seeminigames/dodge. - The battle screen is a minigame too (
minigames/battle). menuButton: falseindefineMinigamehides the pause menu button (☰) while it runs (Extras does).game.minigames.open(id, params)opens one as part of the game's own UI (Extras does): not a step of a scene, so never part of a mid-scene save; a running scene waits under it. It does nothing while another minigame is up.game.minigames.finish(result)ends the running one from outside, as if it calledfinish(result)(for callbacks you pass in its params).- Started from the title screen, it is drawn over the title (the After Stories screen is one).
UI files: src/content/ui
The engine draws its screens through these files: each lays out and styles one part, and the engine keeps the logic (timing, input, saving). Colours and frames are also in the look; these files are for layout, order, icons and extra pieces. Small wrappers from @/core/ui/… carry what the engine needs (keys, scrolling, touch handling): keep them, their sx is yours. Prop types: @/core/slots.
| File | What it lays out | The engine keeps |
|---|---|---|
TextDialog.tsx | The chat box: where its parts sit (more) | <ChatBoxPlace>, <ChatBoxFrame>, <DialogTextArea> |
NameTag.tsx | The speaker's name on the box (gets name, speaker, color, the character's own characterLook) | When it shows (not for narration or full pages) |
ContinueMark.tsx | The ▼ "press to continue" mark | When it shows (once the line has typed out) |
SceneToolbar.tsx | The toolbar's buttons: words or icons, order (more) | What each button does, <SceneToolbarButton>, <SceneToolbarPlace> |
VoiceBar.tsx | The bar showing how long the line's voice still plays (more) | When it shows, the voice's length |
Choice.tsx | A choice's answers, its timer, the toolbar while no line shows (more) | <ChoiceList> (keys, nothing focused at first), <ChoiceButton> |
Log.tsx | The log (backlog): panel, line layout, the line buttons' symbols | <LogList> (scrolling, wheel to close), <LogButton> (◀ ▶ step, confirm presses); the buttons' actions |
ChapterCard.tsx | The full-screen chapter card (fade with shown / fadeMs) | Timing, skipping (click, tap, confirm) |
Toast.tsx | game.toast() messages: where, how they look | How long each stays, how many (config/screen.ts toast) |
Loading.tsx | MapLoading: the fade between maps and the loading screen in it (phase, progress); Loading: the spinner while a window or minigame loads; ReplayCover: the cover while a scene runs again up to where a save was made | When and how long (config/screen.ts timings) |
Timers.tsx | On-screen timers: where, label and digits | <TimerFrame> (data-warning in the warning time), <TimerDigits> (written ten times a second) |
TouchControls.tsx | The joystick and touch buttons: where, sizes, symbols | <Joystick>, <TouchButton> (the touch handling); which buttons (config/input.ts) |
ImageViewer.tsx | The controls over a full-screen picture (gallery): ✕, the dots for variants, caption, hints. Anything clickable must be a button | The picture, zoom, pan, swipe, keys (config/screen.ts imageViewer) |
MovieSkip.tsx | The skip button over a movie | When it shows (after a tap or key, skippable movies only; how long: skip.movieButtonMs in scenes.ts) |
RotateCover.tsx | The "turn your phone sideways" cover | When it shows (config/screen.ts landscapeOnly, phone held upright), on top of everything |
TitleSwitcher.tsx | Switching between unlocked title screens (◀ name ▶; placed by TitleFrame.tsx) | When it shows (two or more unlocked), the tab keys / shoulder buttons |
CrashNotice.tsx | The notice in place of a crashed window, map or event (gets label, message, dev, action: Close or Try again) | Catching and reporting the crash; a plain text notice if this file crashes too |
Window.tsx | Inside every window's frame (more) | <WindowContent> |
Hud.tsx, MenuButton.tsx, TitleFrame.tsx | Over the map (money, minimap, shortcut keys); the ☰ pause menu button; the title screen's frame |
HUD and toasts
src/content/ui/Hud.tsx is drawn over the map. It shows the money and sets up the shortcut keys; every window is reached from the pause menu, so no device needs a key it doesn't have. Edit it freely (your own buttons, bars, a clock):
useAction('inventory', () => game.windows.toggle('inventory'), { layers: ['map', 'windows'] })
useAction('menu', () => game.windows.toggle('menu')) // map only: over a window, menu closes the front one
<ActionHint action="inventory" /> // shows "E", "X", "□"… for the device in use
game.toast(game.t('Saved!')) // a short message at the top
game.toast(game.t('Found a key'), { icon: keyIcon, ms: 4000 })
game.toast(game.t('Legendary!'), { params: { style: 'gold' } }) // your own params, for Toast.tsx
game.toast() shows text as given: translate it yourself with game.t(). (Toasts the engine makes, like "New quest", are translated already.)Where toasts show and how they look: src/content/ui/Toast.tsx. Every toast has a kind and params, so each kind can look different: fill in its entry in byKind, or read the params in byParams. All kinds and their params are listed in ToastKinds (src/core/slots.ts). A game.toast() without a kind is a message.
| Kind | Params | From |
|---|---|---|
message | whatever you pass | game.toast(), small engine notes |
item | item, count | items.add(…, { notify }) |
money | amount | money.add(…, { notify }) |
questNew, questDone | quest | quest start / complete |
achievement, ending, codex | achievement, ending, entry | first unlock |
recipe, place, chapter | recipe, place, chapter | learned, found, begun |
partyJoin, levelUp, skillLearned | character (+ level / skill) | party changes with notify |
relationship | character, change, value | relationships.change(…, { notify }) |
save | result: quickSaved, quickSaveFailed, noQuickSave, loadFailed, storageFull | quick save / load, full storage |
screenshot | where (or null) | F8 |
error | where, message | errors nothing caught |
Timings
Fades and waits are in content/config/screen.ts: timings (map fade, loading-screen delay, minigame fade, title fades, boot skip) and toast (ms, max at once). Stick deadzone, key repeat and the touch joystick size are in content/config/input.ts (feel).
Screenshots
// src/content/config/screen.ts
screenshot: { width: 1920, format: 'png', quality: 0.92, prefix: 'screenshot' }, // width 0 = the size on screen
await game.screenshot() // true when a picture was saved
F8 by default (action screenshot, rebindable in Settings → Controls). Desktop: saved in the Pictures folder, in a folder named after the game. Android: the share sheet opens. Browser: it downloads. Touch controls and toasts are left out of the picture.
When something breaks
Every layer (map, HUD, event, title, each window and minigame) has its own safety net: a crash shows a small notice with Try again or Close instead of a blank screen. Errors nothing caught, and event scripts that throw, are logged and shown as a toast.
// src/content/config/screen.ts
errors: { tellPlayer: true, toastMs: 6000, toastEveryMs: 4000 },
While developing, the toast carries the real message; players of the finished game see “Something went wrong” (or nothing with tellPlayer: false). The last 20 errors are in the dev panel.