# hui
The hangout's interface kit: one look for every screen, and the shared pieces each object draws through instead of
registering screens of its own.
- Look: warm frosted glass panels, cream ink, an amber accent for the hangout and a phosphor green for anything a
console shows. Headings in Bricolage Grotesque, text in Arimo, keys in JetBrains Mono on raised keycaps, small
retro kickers in Press Start 2P.
- `Hui.prompt(owner, key, verb, object?)` / `Hui.unprompt(owner)`: the one interaction prompt on screen. The most
recent offer wins; withdrawing it brings back the one under it, so prompts never stack or stick.
- `Hui.controls(owner, title, items)` / `Hui.uncontrols(owner)`: the controls bar for whatever the player is doing
(holding the Game Boy, a controller, seated). `items` = `{ { keys = { "Z" }, label = "A" }, ... }`.
- `Hui.toast(kicker, title, body?)`: a card that drops in at the top and leaves by itself.
- Building blocks for screens: `Hui.glass`, `Hui.text`, `Hui.keycap`, `Hui.keys`, `Hui.kicker`, `Hui.bar`,
`Hui.button`, `Hui.T` (tokens).
# emotes
Four gestures a player makes with their own body: **wave**, **cheer** (both arms up), **clap** and **point** (at the screen). Each is a couple of seconds of arm motion made from the body's own rig through `seating.pose`, laid over whatever the body is doing: seated on a `Seat` the legs stay seated; standing still the body holds its stance, and walking off cancels it.
```luau
local Emotes = require("seating.emotes")
Emotes.list() -- { { id = "wave", label = "Wave" }, { id = "cheer", ... }, { id = "clap", ... }, { id = "point", ... } }
Emotes.play("wave") -- the local player's avatar; every peer sees it
Emotes.current(avatar) -- the emote an avatar is making on this peer, or nil
```
Every peer that loads this module plays the gestures it hears: `play` poses the local avatar at once and sends `seating.emote` (the avatar, the emote, the session time it started) to the room. `Seat` requires it, so every peer in a room with a seat runs it. It binds no keys: a HUD calls `play`.
# ConsoleStation
A shared television console: any emulator core in the world (NES, CHIP-8, Neo Geo, ...) running on one
screen that the whole room sees, with two controllers. Put it on an entity at the screen's centre, facing
out of the screen (+Z), whose screen mesh draws the material bound to `texGuid`.
- **Choosing a game.** Near it with empty hands, Interact (E / pad west / touch) opens the cartridge
library (`stations.cartlib`): every built-in cartridge and every cartridge anyone in the session has
uploaded, for the consoles in `consoles`, plus "Upload from your computer".
- **Where it runs.** On the peer that holds the cartridge's bytes (the *runner*): the uploader, or the one
who picked a built-in cart. That peer emulates at full speed, hears the sound, and streams the picture to
everyone else (`stations.framecodec` delta frames, `streamHz` a second within `streamBudget` bytes a
second). It restates what is inserted every few seconds, so a late joiner sees it too.
- **Two players.** A `PadControl` controller sends its buttons here as one word (bit 0-3 right, left,
up, down; 4-7 A, B, C, D; 8 Start; 9 Select/Coin). The runner applies player 1 and 2 to the core
(NES pads, CHIP-8 keypad, Neo Geo `setPad`).
Methods: `padInput(slot, word)` (from a controller on this peer), `insert(entry)`, `eject()`, `cart()`,
`isRunner()`. Fields: `consoles`, `texGuid`, `streamHz`, `streamBudget`, `volume`, `promptRange`,
`seatOffset` (where a player's view sits while holding a controller, in this entity's frame), `status`.
- **The screen's light.** While a picture runs, the picture's drawn colour lights the room on every peer: a
shadowed spot out of the glass (`glowIntensity`, `glowRange`, `glowShadows`), a small point on the tube,
and a broad shadowless fill (`fillIntensity`, `fillBack` metres behind the glass so its falloff from set
to seats is gentle, `fillAngle`, `fillPitch` down toward the floor and seats). All go dark on eject.
# progress
Each player's hangout progression, kept on their own machine (runtime data, survives restarts) and shared
with the room as a small card.
- **Play time:** per console and per game, while you are the one playing (holding the Game Boy, or a
controller on a TV game with a game running).
- **XP and level:** playing earns 10 XP a minute (15 when two people play the TV together), hanging out with
at least one other person earns 2 a minute, milestones add a bonus. Level *n* needs `100 + 60 (n-1)` XP.
- **Milestones:** real things done in the room (first game, co-op on the TV, passing the Game Boy on,
uploading a cartridge, an hour on a console, playing every console, playing from the sofa...).
```lua
local Progress = require("stations.progress")
Progress.playing(consoleId, title, dt, coop) -- each frame you play
Progress.event("upload") -- "upload", "handover", "seated", "watched", "pinned"
Progress.photo() -- a photo taken with the instant camera
Progress.tick(dt) -- once a frame (HangoutHud does it)
Progress.level() -> (level, xpIntoLevel, xpForLevel)
Progress.cards() -> { {peer, name, level, xp, minutes, top, milestones} } -- everyone, you first
Progress.milestones() -> { {id, title, text, done} }
Progress.onToast(fn(title, text)) -- a milestone or level up
```
Channel: `progress.card` (each peer's card, on change and every 15 s; answered on `progress.hello`).
# wallGlide
Walking slides along walls and door frames. The character controller already slides a step along the wall it meets,
but its walk feel brakes the part of the velocity that points away from the direction asked for (at `braking`,
30 m/s², faster than the 20 m/s² `acceleration`), and a wall slide is exactly such a part: brushing a wall at 45°
slowed to about 0.3 m/s and a diagonal into a doorway stopped against the jamb.
`step()` runs once a frame for the local player (from `HangoutHud.update`) and clips the walk on the controller's
input bus (`inputX` / `inputZ`) against the wall the body touches: the part aimed into the wall is dropped, the part
along it kept, so the walk asked for and the walk the wall allows agree and nothing is braked. Risers no taller than
`stepHeight` are left to the controller to step up.
```luau
require("stations.wallGlide").step()
```
# Seat
A place to sit. Put it on an empty entity standing where a sitter's hips go (on the seat surface, back from the front edge), turned so its +Z points the way the sitter faces. The player's body needs the engine's humanoid avatar (any rig with humanoid roles); nothing else is needed on the seat. `room.Sofa` carries three (`seat_1..3`), `room.DeskChair` one (`seat`).
- Near a free seat with empty hands, it offers "Sit" to `stations.focus`; the focus picker chooses by aim between it, the seats beside it and any prop in reach (the nearest when nothing is aimed at), and Interact sits you only when this seat is the target. `room.Bed` carries two on its foot (`bed_seat_1..2`).
- Seated: the body is held on the seat facing its +Z, walking and gravity are off, and the body takes a seated pose made from its own rig (`seating.pose`: thighs forward, shins down, hands in the lap). The camera eases into a view over your shoulder (the engine's `mount` camera on the seat), and back to your walking view when you stand.
- **Stand up**: Interact (with nothing in reach to pick up), Jump, or a push of Move. You stand at `standOffset`, clear of the furniture.
- Pick up a controller or the Game Boy while seated and it plays as usual (its own view and controls take over until you put it down); doing so awards the `seated` progress event once.
- Multiplayer: the sitter's peer sends `seating.hold` (on sitting and every 2 s, so a late joiner hears it) and `seating.free`; every peer poses that body seated on its own copy and refuses the seat to anyone else. Two players sitting at the same instant are settled by who sat first. A seat whose sitter stops being heard for 7 s, or whose body leaves, frees itself.
Fields: `label`, `promptRange` (0.9), `style` (ride | drive), `hipLift` (0.1), `standOffset`, `viewOffset`, `viewPitch`, `facing` (world facing, kept up to date), `status` (who sits, for inspection).
Methods: `seat:occupant()` (the avatar sitting, or nil), `seat:isSeatedLocal()`. Across all seats, `require("seating.seats")`: `isSeatedLocal()`, `localSeat()`, `seatOf(avatar)`, `occupantOf(seatId)`, `all()`.
# seats
What this peer knows about every `Seat` (`seating.Seat`): which seat the local player sits on, the seat each avatar sits on as the room heard it, and which free seat is nearest (the one seat that shows the "Sit" prompt). Seat components keep it up to date; other code reads it.
```luau
local seats = require("seating.seats")
seats.isSeatedLocal() -- is the local player sitting?
seats.localSeat() -- the seat entity they sit on, or nil
seats.seatOf(avatar) -- the seat entity any avatar sits on, or nil
seats.occupantOf(seatId) -- the avatar on a seat, or nil
seats.all() -- every Seat entity this peer runs
```
# hangoutUi
The hangout's own screens, drawn with the `hui` kit: the player card (name, level ring, XP), the menu
(Players in the session, Milestones, Settings with ray-traced lighting and volume) and the controls overlay
(the current context's controls first, then what works anywhere), each with the glyphs of the device in the
player's hands.
`HangoutHud` drives it: `Ui.init()` once, `Ui.tick(dt)` every frame, `Ui.toggleMenu()` / `Ui.toggleHelp()` from
its controls. `Ui.setGraphics(get, set)` is how the graphics component hands the menu its ray-traced toggle.
# cameraCollision
The hangout's follow-camera pull-in, for small furnished rooms. `HangoutHud` calls `step(dt)` every frame after the builtin orbital follow rig has placed the camera at its framing. The rig's own pull-in is switched off at runtime (`cameraRadius = 0`): in 3-4 m rooms its look-ahead sweeps kept finding walls and furniture, and the over-the-head aim lift (`HangoutHud.frameOverHead`) moved the sweep's pivot, which the look-ahead read as motion, so the camera kept snapping to the player's head.
What it does:
- sweeps a 0.12 m sphere from the aim point to the framed camera position, past every player's avatar;
- blocks on architecture whatever its size (any collider under a `*shell*` or a `*door_leaf*`: walls, wall ends, the lintel over a doorway, floors, ceilings, doors) and on large furniture (largest extent >= `bigLong` 1.4 m and second >= `bigWide` 0.6 m: sofa back, bed, bookshelf, wardrobe, fridge); triggers, lamps, plants, the coffee table, side tables, desks, chairs, consoles and pads are looked through;
- never lets the camera rest inside a looked-through prop: it stops in front of the nearest one that would hold it;
- keeps the aim point under a ceiling when the player stands on furniture;
- comes in at once (never a frame through a wall), holds `hold` 0.35 s once clear, then eases out over `outTime` 0.45 s; a gain inside `deadband` is ignored so it does not pump.
API: `step(dt)`, `seeThrough(entityId)`, `forget()` (drop cached verdicts after furniture changes), `enabled` (false hands the camera back to the rig's own pull-in, for comparisons), `last` (ideal/placed distance and blocker of the last frame, for diagnostics). Tunables are fields on the module table.
# cartlib — the session cartridge library
`require("stations.cartlib")` gives every console station one shared list of the cartridges in the room: each core's committed demo carts, the local player's own uploads, and what every other player in the session holds. Players upload ROMs from their computer and anyone in the room can play them; the bytes are copied peer to peer on demand.
Uploaded ROMs are **never** written to `/zero/source`: they live in the uploader's runtime-data library (chunked under the 256 KB value cap, the `retro.host` RomLibrary layout, so a console's own loader lists them too) and in memory. Carts copied from another player live in memory for the session only.
## API
```lua
local Cartlib = require("stations.cartlib")
Cartlib.list(consoleId?) -> { Entry } -- sorted by console, BIOS first, then title
-- Entry = { id, console, title, size, holders = {peerId}, builtin, isBios }
-- id = console .. ":" .. filename .. ":" .. size (stable across peers)
Cartlib.has(id) -> boolean -- bytes available on this peer
Cartlib.bytes(id) -> string? -- committed file, runtime library, or session cache
Cartlib.upload(consoleId?) -> (Entry?, why?) -- yields; system file picker, validate, store, announce
Cartlib.fetch(id, function(ok, why) end) -- copy from a holder peer (<= 8 MB)
Cartlib.onChanged(cb) -> unsubscribe
Cartlib.biosFor(consoleId) -> id? -- a locally held BIOS (e.g. neogeo.zip)
Cartlib.openLoader({ title, consoles = {"gameboy", ...}, onPick = function(entry) end })
Cartlib.closeLoader()
Cartlib.handleCallback(id, data) -> boolean -- forward a UI callback (see below)
Cartlib.tick() -- prune players who left (CartLoader calls it)
```
Extras: `Cartlib.get(id)`, `Cartlib.progress(id)` (0..1 while copying), `Cartlib.consoles()`, `Cartlib.formatSize(n)`, `Cartlib.refresh()` (rescan disk and the runtime library), `Cartlib.isLoaderOpen()`, `Cartlib.isUploading()`.
Consoles come from every installed `emulatorCore` (`retro.host.registry`). Any `.zip` is a Neo Geo set (console `neogeo`); `neogeo.zip` is the Neo Geo BIOS (`isBios = true`, validation skipped). If no core claims `neogeo`, the library still files zips under it. `builtin` entries are the files in each core's `romsDir`, held by everyone.
## Neo Geo system files
The Neo Geo core reads its BIOS from a zip (`neogeo.package` romset): a system ROM (`sp-s2.sp1`, `sp-s3.sp1`, `sp-u2.sp1`, `sp-j2.sp1`, `uni-bios*.rom`, … the romset's `BIOS_NAMES`), `sfix.sfix`, `sm1.sm1`, and optionally `000-lo.lo`. Players don't have to build that zip themselves:
- Loose files (`.sp1 .sfix .sm1 .rom .bin .lo`, renamed copies like `sp-s2 (1).sp1` included; `Cartlib._biosPart(name)` names each one's role) are kept in the player's runtime-data library under `neogeo_bios/`. Once a system ROM, sfix and sm1 are all held, they are packed (stored, uncompressed, `Cartlib._storeZip`) into `neogeo.zip`, which becomes the BIOS entry.
- A zip of system files under any name is the BIOS when it holds all three; otherwise its files join the loose parts.
- `Cartlib.neoSetup()` answers what is here: `{ ready, system, sfix, sm1, lo, missing, games }`.
The picker takes several files at once on the All and Neo Geo tabs.
## Help on the shelf
Every tab opens with an *Adding games* strip: the file types it takes and that uploads stay in the player's library and are shared with the room while they are here. The Neo Geo tab adds a setup card: step 1 *System files* (each file ✓/○, an *Upload system files* button while any is missing) and step 2 *Your game zip*. PLAY on a Neo Geo game without the system files keeps the shelf open, switches to that tab, says what is missing and puts focus on the upload button.
## The loader panel
`openLoader` shows a centred card over a dimmed backdrop: console tabs (All + the consoles you pass), one row per cart (console tag, BIOS tag, title, console, size, who has it, and an action: PLAY when the bytes are here, GET to copy them, COPYING n%, TOO BIG past 8 MB), a close button (Esc) and an **Upload from your computer** button that filters the picker to the current tab's extensions. Everything is a button, so arrows / d-pad / stick move focus, Enter / south press, and touch taps. Picking a cart that is elsewhere copies it first and then calls `onPick`; an upload calls `onPick` with the new entry.
UI callbacks run in play. `openLoader` registers its own callback env, so callbacks reach it when it is opened from a component's code. A component that wants to be sure can forward its own `onCallback(id, data)` to `Cartlib.handleCallback(id, data)` (repeats within the same frame are ignored), or carry the `stations/CartLoader` component, which does that and calls `Cartlib.tick()`.
## Session sync
- `cartlib.announce {v=1, carts={meta...}}` — each peer broadcasts the metadata (never bytes) of what it holds beyond the built-in carts: on load, after any upload or copy, and in answer to a hello.
- `cartlib.hello` — sent on load and when a loader opens; every peer answers with an announce, so a late joiner learns the room.
- Players who leave are dropped from every list (`multiplayer.getPeers()` checked on each `list()` and each `tick()`).
## Transfer protocol
All messages are broadcasts that name their target peer first; other peers ignore them.
1. requester → `cartlib.req (holder, reqId, cartId)`
2. holder → `cartlib.head (requester, reqId, chunkCount, byteLen)` or `cartlib.deny (requester, reqId, why)`
3. holder → `cartlib.chunk (requester, reqId, i, base64)` — 12 000 characters each, paced by a 150 KB/s budget shared by all transfers it serves; the budget halves when `multiplayer.getDiagnostics().refusals` rises and recovers by 10 % every half second.
4. holder → `cartlib.done`; requester → `cartlib.nack (holder, reqId, {missing})` for any gaps (also after 4 s without a chunk), up to 6 times.
5. requester reassembles, checks the decoded length, caches in memory, announces itself as a holder. A holder that does not answer in 6 s, stalls or denies is swapped for the next holder (lowest latency first).
Carts over 8 MB never move (requester and holder both refuse); players upload their own copy.
## Testing hook
`Cartlib._addLocal(name, bytes, consoleHint?, { persist = false, share = false }?)` is the path the picker uses after it reads the file (`persist = false`: session only; `share = false`: kept off the room's list); `Cartlib._addFiles(files, consoleHint?, opts?)` is the same for a picker's whole selection. `_split`, `_assembler`, `_encode`, `_decode`, `_classify` and `_fetchFrom(peer, id, meta, onDone)` are exposed for tests.