Docs / PLAYER-UX

Player UX Contract — Browser & Gamepad

Source: docs/PLAYER-UX.md

Status: Normative specification (contract). This document is the single source of truth for the player-facing behavior of Game Composer. It defines what a player sees and does, and the interfaces the player consumes from other owners (platform, schema, runtime, SDK). It does not define those other owners' internals.

Playability disclaimer. This document specifies contracts only. Nothing here asserts that any composed game is playable. Playability is a verified property that requires the E2E scenarios in §10 to pass end to end. Until those pass, the player surface MUST be described as contract-ready / unverified, never as "playable" or "working".


1. Scope and non-goals

1.1 In scope

  • The browser player surface: launching a composed game into an emulator core, the launch/status lifecycle, and all user-facing states and errors.
  • Input mapping for keyboard and Standard Gamepad, including resolution, device lifecycle, and remapping UX.
  • Status display requirements for every lifecycle state.
  • Error taxonomy, user-facing message requirements, and recovery semantics.

1.2 Out of scope (owned elsewhere)

  • Emulator core implementation, runtime lifecycle internals, and the runtime→player transport — runtime owner.
  • Launch descriptor schema, its validation rules, and storage — schema/platform owners. This document only lists the fields the player consumes; it does not redefine their schema.
  • CLI, SDK API surface, and desktop shell — CLI/SDK/desktop owners.
  • Test harness, fixtures, and automation implementation — E2E owner (this doc defines required scenarios, not their code).

1.3 Normative language

The key words MUST, MUST NOT, SHOULD, SHOULD NOT, and MAY are to be interpreted as described in RFC 2119.


2. Assumptions

These are inputs to this spec, not decisions made by it. If an owner changes one, this contract must be revised.

  • A1. The player is a web application running in an evergreen browser with WebAssembly and the W3C Gamepad API.
  • A2. A composed game is delivered as a bundle (game data/ROM) plus an emulator core identifier; a runtime (owned elsewhere) exposes an API to boot a core with a bundle and to emit status events and accept input.
  • A3. The host/platform supplies a launch descriptor to the player. The player consumes a defined subset (§5.1); the descriptor's authoritative schema is owned by the schema owner.
  • A4. The baseline gamepad is the Standard Gamepad mapping (Gamepad.mapping === "standard"). Non-standard pads are handled via a best-effort fallback (§6.4).
  • A5. Emulator cores expose a fixed set of logical actions (§6.1); games map core-specific controls onto those actions through an input profile.

3. Roles and surfaces

Role Responsibility Owns
Player (end user) Selects a game, launches it, supplies input, interprets status/errors. —
Player surface Browser UI: library entry, launch orchestration, input capture, status/error rendering. This document
Host / platform Provides launch descriptor, Authorization/session context, library metadata. Schema / platform owners
Runtime Boots core with bundle, emits status events, receives input actions, owns session lifetime. Runtime owner

Boundary rule: The player MUST NOT reach into emulator internals. All cross-boundary interaction MUST go through the descriptor, the status-event stream, and the input-action stream defined here.


4. Player surfaces

The player MUST support both surfaces concurrently:

  1. Browser surface — rendered UI, keyboard input, mouse for menus.
  2. Gamepad surface — Standard Gamepad input to gameplay and, where specified, to menu navigation.

Both surfaces feed the same logical action stream (§6); they MUST NOT create separate input paths. A player MUST be able to complete the full launch→play→exit flow using the keyboard alone, and MUST be able to play (once launched) using a gamepad alone.


5. Launch contract — emulator + game

5.1 Launch descriptor (player-consumable fields)

The player MUST consume at least the following fields from the launch descriptor. Missing or invalid required fields produce E_DESCRIPTOR_INVALID (§8.1).

Field Type Required Player use
sessionId string yes Correlate all status/input events; display in error details.
game.id string yes Identity for library/relaunch.
game.title string yes Displayed in status and errors.
game.version string no Displayed in details.
emulator.coreId string yes Displayed as "engine"; passed to runtime.
emulator.coreVersion string no Displayed in details.
emulator.platform string no Displayed as "system" (e.g. "8-bit").
bundle.url string (URL) yes Source of game data.
bundle.checksum string no Verified before launch when present.
bundle.sizeBytes number no Enables determinate load progress.
inputProfile string no Selects a named binding profile (§6.5).

The player MUST NOT assume fields beyond this table. Additional descriptor fields MUST be ignored for display purposes.

5.2 Launch state machine

The player lifecycle is a finite state machine. Every state transition MUST be driven by either a user action or a status event from the runtime; the player MUST NOT advance state on a timer or guess.

State Entry condition Permitted exits Player obligation on entry
idle Initial load, or "Back to library" → resolving (user selects game) Show game library; no runtime session active.
resolving User selected a game → loading (descriptor valid); → error (invalid/unavailable) Validate descriptor; show "Preparing title".
loading Descriptor valid → ready (core.ready); → error (fetch/init failure); → idle (user cancels) Fetch/verify bundle via runtime; show progress (§7.2); offer Cancel.
ready Runtime reports core ready → running (user Start/Play); → error; → idle (user exits) Show title, engine, controls hint; surface primary "Play" action. MUST NOT auto-start audio (§9).
running User confirmed start → paused (pause); → error (session lost); → terminated (end) Render gameplay surface; hide loading UI; capture input; start audio from the user gesture.
paused Pause requested → running (resume); → loading (restart); → terminated (exit) Show overlay with Resume / Restart / Exit; suspend input to gameplay.
terminated Session ended or exited → idle (back to library); → resolving (relaunch) Show end summary and Relaunch / Library actions.
error Any state on failure → resolving or loading (retry); → idle (back to library) Show error panel (§8); preserve sessionId for retry.

Invariants:

  • The player MUST NOT initiate a second launch for the same sessionId while a launch is in flight (no double-boot).
  • All status events MUST be correlated by sessionId; events for a stale/superseded session MUST be ignored.
  • A transition to error MUST be attributable to a specific error code (§8.1).

5.3 Launch sequence (happy path)

  1. User selects a game in the library → player enters resolving.
  2. Player validates the descriptor (§5.1). On failure → error with E_DESCRIPTOR_INVALID.
  3. Player enters loading and asks the runtime to boot emulator.coreId with bundle.url. Progress is reported via launch.progress events (§7.3).
  4. If bundle.checksum is present, the runtime verifies it before declaring ready; mismatch → E_BUNDLE_CHECKSUM_MISMATCH.
  5. On core.ready, player enters ready and displays title/engine/controls with a primary Play action.
  6. User activates Play (mouse, keyboard, or gamepad Start) → player enters running, renders gameplay, and starts audio from that gesture.
  7. Session proceeds under running/paused until exit → terminated → idle.

5.4 Launch UX requirements

  • The player MUST always show which game and which engine is being launched before gameplay begins.
  • The player MUST offer a Cancel control during resolving and loading that returns to idle without leaving a dangling runtime session.
  • The player MUST NOT present any game as "playable" or "verified" as part of launch; status copy MUST be neutral (e.g. "Ready", "Launching").
  • Retry after a launch failure MUST re-run from the failed step, not from idle, unless the user chose "Back to library".

6. Input mapping contract

6.1 Logical actions

All input — keyboard and gamepad — MUST resolve to this fixed set of logical actions. Games reference actions by name, not by physical key/button.

Action group Actions
Menu navigation MenuUp, MenuDown, MenuLeft, MenuRight, MenuConfirm, MenuBack
D-pad DPadUp, DPadDown, DPadLeft, DPadRight
Face buttons FaceSouth, FaceEast, FaceWest, FaceNorth
Shoulder / trigger ShoulderL, ShoulderR, TriggerL, TriggerR
System Start, Select, SystemPause
Analog AxisLeftX, AxisLeftY, AxisRightX, AxisRightY

SystemPause is a player-owned action mapped to the pause overlay and MUST NOT be forwarded to the emulator as gameplay input.

6.2 Keyboard default map

These defaults MUST apply when no user binding or profile binding exists.

Action Default key(s)
MenuUp / MenuDown / MenuLeft / MenuRight Arrow keys; W/A/S/D
MenuConfirm Enter / Space
MenuBack Escape
DPad* Arrow keys
FaceSouth Z
FaceEast X
FaceWest A
FaceNorth S
ShoulderL / ShoulderR Q / E
TriggerL / TriggerR 1 / 2
Start Enter
Select Shift
SystemPause Escape / P

Reserved host shortcuts (e.g. browser-level keys) MUST NOT be rebindable; the player MUST ignore attempts to bind them and surface a non-blocking notice.

6.3 Gamepad default map (Standard Gamepad)

Button indices follow the Standard Gamepad layout (buttons[0..16], axes[0..3]).

Action Standard Gamepad source
DPadUp/Down/Left/Right buttons[12]/[13]/[14]/[15]
FaceSouth/East/West/North buttons[0]/[1]/[2]/[3]
ShoulderL/R buttons[4]/[5]
TriggerL/R buttons[6]/[7]
Select / Start buttons[8]/[9]
SystemPause buttons[9] (Start) held long-press, or buttons[10] (L3) — configurable
AxisLeftX/Y axes[0]/[1]
AxisRightX/Y axes[2]/[3]
MenuConfirm FaceSouth (buttons[0])
MenuBack FaceEast (buttons[1])

6.4 Mapping resolution

Resolution order, highest precedence first:

  1. Explicit user binding (from remapping UI, §6.5).
  2. Input-profile binding (from inputProfile in the descriptor).
  3. Default binding (§6.2, §6.3).

Additional resolution rules:

  • Deadzone / digital threshold: Analog axes MUST apply a deadzone (recommended 0.25) and MUST produce digital D-pad events only past a threshold (recommended 0.5) with hysteresis to prevent chatter.
  • Dual sources: Keyboard and gamepad MAY both be active simultaneously. Both MUST feed one action stream; a single logical action MUST NOT be double-fired for one physical event. The most recently used device MUST drive the displayed control hints.
  • Focus loss: On window.blur or visibilitychange to hidden, the player MUST clear all held inputs (release every pressed action) to avoid stuck inputs, and SHOULD enter paused if running.
  • Device lifecycle:
    • On first gamepad connection, the player MUST auto-select it as the active player pad and announce it non-blockingly.
    • On disconnect, held inputs MUST be cleared and a status notice emitted (§7.3); gameplay MUST NOT crash.
    • On reconnect, bindings MUST be restored by device id/index where possible.
    • Multiple connected pads: only the active player pad drives gameplay by default; additional pads MUST be ignored unless a future multi-player profile is defined.
  • Non-standard pads: If mapping !== "standard", the player SHOULD fall back to a raw button-index best-effort map and MUST show a notice that the pad may not map correctly. This is a warning, not an error (§8.1).

6.5 Remapping (optional but contractual)

If a remapping UI is provided, it MUST:

  • Let the user rebind any non-reserved action for keyboard and for the active gamepad.
  • Detect and reject conflicting bindings with an explicit E_BINDING_CONFLICT notice (§8.1).
  • Persist bindings keyed by inputProfile (or a local profile id) and offer Reset to defaults.
  • Apply immediately to the action stream without requiring a page reload.

7. Status display contract

7.1 Status model

The runtime/host MUST supply, and the player MUST consume and render, the following status fields:

Field Type Meaning
sessionId string Correlation id; must match the descriptor.
state enum One of the states in §5.2.
title string Game title for display.
engine string Core name/id for display.
progress number | null 0..1 for determinate loading; null for indeterminate.
message string (optional) Human-readable detail for the current state.
error error object (optional) Present only in error state (§8.4).

The player MUST treat status as authoritative input and MUST NOT synthesize state locally except for purely local UI (e.g. showing the library on idle).

7.2 Display requirements per state

State Required display elements
idle Game library; no active-session artifacts.
resolving "Preparing title" message; non-blocking spinner.
loading "Loading title"; determinate progress bar if progress != null, otherwise indeterminate bar; visible Cancel.
ready Title, engine, controls hint, primary Play action.
running Gameplay surface front and center; minimal HUD (title, pause hint); no loading/resolving UI.
paused Dimmed gameplay with overlay: Resume, Restart, Exit.
terminated End summary and Relaunch / Library actions.
error Error panel with code-based message, details, and recovery actions (§8).

7.3 Status event contract

The runtime MUST emit the following events on the player-facing channel, each carrying at least sessionId and state:

Event When Required payload
launch.requested Player asks runtime to boot core sessionId, core id, bundle url
launch.progress Bundle load advances sessionId, progress
core.ready Core booted, ready to start sessionId, title, engine
session.started User confirmed start sessionId
session.paused / session.resumed Pause toggled sessionId
session.ended Session terminated sessionId, reason
error.raised Any failure sessionId, error object (§8.4)
input.device.changed Gamepad connected/disconnected/remapped sessionId?, device id/index, change type

Ordering guarantees the player MAY rely on: core.ready always precedes session.started; error.raised is terminal for the current attempt until a retry is issued; events for a superseded sessionId MUST be ignored by the player.

7.4 Display rules

  • State changes MUST be reflected in the UI within one animation frame, or at most 100 ms, of receiving the corresponding event.
  • Progress updates MUST NOT block rendering of other UI.
  • A politely-announced live region (e.g. aria-live="polite") MUST mirror state changes for assistive technology (§9).
  • The player MUST NOT display raw runtime diagnostics in primary status copy; diagnostics belong in expandable details.

8. Error contract

8.1 Error taxonomy

Every error surfaced to the player MUST carry one of these codes. The player MUST map each code to the specified user-facing intent and recovery actions.

Code Cause User-facing intent (copy, not exact text) Recovery Retryable
E_DESCRIPTOR_INVALID Missing/invalid required descriptor field "This game can't be launched because its information is incomplete." Back to library; contact support No
E_BUNDLE_FETCH_FAILED Network/HTTP failure fetching bundle "Couldn't download the game. Check your connection." Retry; Back to library Yes
E_BUNDLE_CHECKSUM_MISMATCH Bundle integrity check failed "The game data didn't pass verification." Retry download once; then support Yes (bounded)
E_CORE_UNAVAILABLE Core missing/incompatible "The engine needed for this game isn't available." Back to library; support No
E_CORE_INIT_FAILED Core failed during initialization "The engine failed to start." Retry; Back to library Yes
E_WASM_UNSUPPORTED Browser lacks WebAssembly/required API "This browser can't run the emulator. Try an up-to-date browser." Back to library; guidance link No
E_SESSION_LOST Runtime/session crashed mid-play "The session was interrupted." Relaunch; Library Yes
E_BINDING_CONFLICT Duplicate input binding (remapping) "That control is already assigned." Rebind; Reset to defaults No (local)
E_UNKNOWN Unclassified runtime/other failure "Something went wrong." Retry; Library Yes
  • A missing gamepad is not an error: it is a warning/informational notice, because keyboard remains available. This MUST NOT block launch or play.

8.2 User-facing message requirements

  • Messages MUST be human-readable, state what happened in plain language, and offer a concrete next step.
  • Raw stack traces, internal URLs, and opaque identifiers MUST NOT appear in primary copy. An expandable Details section MAY include code, sessionId, and timestamp.
  • The error panel MUST expose at least one recovery action appropriate to the code (§8.1).
  • Error copy MUST NOT claim the game is or was "playable"; it MUST describe only the failed operation.

8.3 Recovery semantics

  • Retry MUST re-run the launch pipeline from the failed step, preserving sessionId and prior successful artifacts where safe (e.g. a verified bundle need not be re-fetched).
  • Bounded auto-retry: only E_BUNDLE_FETCH_FAILED MAY auto-retry, at most 3 attempts with exponential backoff; after exhaustion, stop and require user action. The player MUST NOT silently retry forever.
  • Back to library MUST tear down any partial runtime session before returning to idle.
  • All recovery actions MUST be reachable by keyboard and, where applicable, gamepad.

8.4 Error event contract

The error object carried by error.raised and by state === "error" MUST contain:

Field Type Required
code enum from §8.1 yes
message string (developer-facing detail) yes
sessionId string yes
retryable boolean yes
details object (raw diagnostics, optional) no

The player MUST select user-facing copy from code, never display message directly as primary copy.


9. Accessibility & edge cases

  • Keyboard-only: Every menu, launch, pause, error, and remapping flow MUST be fully operable with the keyboard alone.
  • Focus management: On entering ready, paused, terminated, or error, focus MUST move to the primary action; focus MUST NOT be trapped where escape is expected.
  • Reduced motion: Spinners/progress animations MUST respect prefers-reduced-motion.
  • Contrast: Status text, progress, and error copy MUST meet WCAG AA contrast against their backgrounds.
  • Live region: State changes MUST be announced via aria-live="polite" (§7.4).
  • Audio autoplay: The player MUST NOT start audio before a user gesture. Audio context MUST be resumed on the running transition triggered by the user's Start/Play activation.
  • No gamepad: Launch and keyboard play MUST proceed with an informational notice; gamepad absence MUST NOT be an error (§8.1).
  • Tab visibility: Hiding the tab MUST clear held inputs and SHOULD pause running sessions (§6.4).

10. Verification & E2E gating

This section is the gate for any playability statement. Contract-level checks (static review, unit tests of state transitions, message mapping) are necessary but not sufficient. A playability claim requires the E2E scenarios below to pass against a real browser and a real emulator core.

10.1 Required E2E scenarios

# Scenario Pass condition
1 Cold launch from library to running All states in §5.2 observed in order; gameplay surface rendered.
2 Keyboard input reaches emulator A key-driven action produces an observable change in the running game.
3 Gamepad connect → map → input Connection notice shown; a gamepad action produces an observable change in-game.
4 Pause / resume / restart / exit Overlay actions produce correct state transitions; no dangling session.
5 Every error code in §8.1 Correct message intent, details, and recovery action; retry is bounded.
6 Gamepad disconnect / reconnect Held inputs cleared; no crash; bindings restored.
7 Blur / visibility change Held inputs cleared; running session paused; no stuck input after refocus.

10.2 Claims policy

  • Before all scenarios in §10.1 pass: the player surface MUST be referred to as "contract-ready / unverified". No documentation, UI copy, commit message, or report from any owner may claim the game is playable.
  • After they pass: a playability claim MUST be scoped to the exact game/core/browser matrix that was exercised, and MUST cite the E2E run (commit, date, environment).
  • This document's own status ("contract-ready") is independent of E2E results.

10.3 Acceptance checklist (contract conformance)


11. Open questions / cross-owner dependencies

These need confirmation from other owners; they do not block this contract but may refine it.

  1. Schema owner: Confirm the exact descriptor field names/types in §5.1 match the canonical schema; reconcile any differences.
  2. Runtime owner: Confirm event names and payloads in §7.3 and the error object in §8.4; confirm the input-action channel accepts the logical actions in §6.1.
  3. Platform owner: Confirm where the player obtains the descriptor (host injection vs. fetch) and how sessionId is minted.
  4. E2E owner: Confirm the scenarios in §10.1 are automatable with the chosen harness; flag any that need a seeded fixture or a real core build.
  5. SDK/Desktop owners: Confirm the browser player is the canonical play surface for those integrations, or note where their UX diverges (this doc then needs a companion).

Back to all docs