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()
  }
}

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>,
})

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} />

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')

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
titleTitle bar text (translated)
widthMinimum width (number = px). The window grows wider if its content needs it, never past the screen. Default 420.
modalDims everything behind and blocks clicks to it
closableShows the × and lets cancel close it (default true)
transitionHow 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 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' }} />
      )}
    </>
  )
}

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:

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'

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.

FileWhat it lays outThe engine keeps
TextDialog.tsxThe chat box: where its parts sit (more)<ChatBoxPlace>, <ChatBoxFrame>, <DialogTextArea>
NameTag.tsxThe 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.tsxThe ▼ "press to continue" markWhen it shows (once the line has typed out)
SceneToolbar.tsxThe toolbar's buttons: words or icons, order (more)What each button does, <SceneToolbarButton>, <SceneToolbarPlace>
VoiceBar.tsxThe bar showing how long the line's voice still plays (more)When it shows, the voice's length
Choice.tsxA choice's answers, its timer, the toolbar while no line shows (more)<ChoiceList> (keys, nothing focused at first), <ChoiceButton>
Log.tsxThe log (backlog): panel, line layout, the line buttons' symbols<LogList> (scrolling, wheel to close), <LogButton> (◀ ▶ step, confirm presses); the buttons' actions
ChapterCard.tsxThe full-screen chapter card (fade with shown / fadeMs)Timing, skipping (click, tap, confirm)
Toast.tsxgame.toast() messages: where, how they lookHow long each stays, how many (config/screen.ts toast)
Loading.tsxMapLoading: 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 madeWhen and how long (config/screen.ts timings)
Timers.tsxOn-screen timers: where, label and digits<TimerFrame> (data-warning in the warning time), <TimerDigits> (written ten times a second)
TouchControls.tsxThe joystick and touch buttons: where, sizes, symbols<Joystick>, <TouchButton> (the touch handling); which buttons (config/input.ts)
ImageViewer.tsxThe controls over a full-screen picture (gallery): ✕, the dots for variants, caption, hints. Anything clickable must be a buttonThe picture, zoom, pan, swipe, keys (config/screen.ts imageViewer)
MovieSkip.tsxThe skip button over a movieWhen it shows (after a tap or key, skippable movies only; how long: skip.movieButtonMs in scenes.ts)
RotateCover.tsxThe "turn your phone sideways" coverWhen it shows (config/screen.ts landscapeOnly, phone held upright), on top of everything
TitleSwitcher.tsxSwitching between unlocked title screens (◀ name ▶; placed by TitleFrame.tsx)When it shows (two or more unlocked), the tab keys / shoulder buttons
CrashNotice.tsxThe 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.tsxInside every window's frame (more)<WindowContent>
Hud.tsx, MenuButton.tsx, TitleFrame.tsxOver 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.

KindParamsFrom
messagewhatever you passgame.toast(), small engine notes
itemitem, countitems.add(…, { notify })
moneyamountmoney.add(…, { notify })
questNew, questDonequestquest start / complete
achievement, ending, codexachievement, ending, entryfirst unlock
recipe, place, chapterrecipe, place, chapterlearned, found, begun
partyJoin, levelUp, skillLearnedcharacter (+ level / skill)party changes with notify
relationshipcharacter, change, valuerelationships.change(…, { notify })
saveresult: quickSaved, quickSaveFailed, noQuickSave, loadFailed, storageFullquick save / load, full storage
screenshotwhere (or null)F8
errorwhere, messageerrors 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.