# The controller

The few controls every work is played with, and the file that tells Playspace which of your keys they press. The
manifest's part is copied from the page Playspace's publishing agent reads; read it as how a work is wired.

## The Playspace set

Every work on Playspace is played with the same few controls:

| | On a phone | On a computer |
|---|---|---|
| Move | the stick, bottom left | W A S D or the arrows |
| A | the large button, bottom right | Space |
| B | the smaller button, above A | Shift |
| The menu | the pill at the top left | Esc |
| The pointer | a tap (the click) and a drag | the mouse and its click |

Make the work playable with these and nothing more. Playspace draws the stick, A, B and the pill, with your words in
them, and on a computer key caps in the corners; do not draw buttons of your own for them. A work that needs more than the
set (a third button held in play, a second set of directions, typing as the play) is over it: it still publishes,
flagged, with the actions that have no place left out.

## Answer each control one way

Listen to your own keys and your own pointer, and name those keys in `playspace.json`'s `controls` (the control
manifest, below): the player then presses them from the stick, A, B and the pill on a phone, and shows them as key
caps on a computer. That is all the input code a work needs. Do not also answer the same button through
`playspace.input.onIntent`, or it fires twice, and do not call `playspace.layout()` for the set: a layout written by
hand takes the place of the manifest, and the key caps on a computer go with it. The one place a work reads Playspace
for input is a view the drag turns: with `window.playspace` there, take the look from `playspace.camera.onLook` and
leave your own drag reading off, as the three.js starter does (`"pointer": "look"` in the manifest). A view from inside
(first person) made this way gets drag-to-look on a computer, not a captured mouse: the mouse is not locked to it. Where the contract and the cookbook say to declare a
layout or to answer A and B through `onIntent`, that is how Playspace's own agent wires a work it did not write.

Give each action one control. The stick (W A S D and the arrows) is for moving something; an action that is not a
movement (a flipper, a jump, a switch) goes on A or B, not on the stick's directions. Do not give the same action a
touch area of your own as well (a half of the screen that does what A does): on a phone the player already draws A
there, and the work reads as needing more than the set.

## 0.5 The control manifest: the Playspace set

Every work on Playspace is played with the same few controls, on a phone and on a computer:

| | On a phone | On a computer |
|---|---|---|
| Move (`move`) | the stick, bottom left, pressing the work's own move keys | W A S D or the arrows, both pressing the work's own move keys |
| A (`a`) | the large button, bottom right, pressing the work's own key | Space |
| B (`b`) | the smaller button, up and toward the edge | Shift (either) |
| The menu (`esc`) | the pill, top left, the work's word in it | Esc |
| The pointer (`pointer`) | a drag on the work (the mouse held, or the view turning) and a tap (the click) | the mouse and its click, the work's own |

### The file

**The file's version is 3** (`"v": 3`); the code's `playspace.layout({ v: 3, ... })` is a different thing (for `own`,
`avoid`, `select` and a captured look), never written into the file. `playspace.json`'s `"controls"` (`false` stays the creator's opt-out). Only `v` is required; each of `move`, `a`, `b`, `esc` is drawn
only where named:

    { "v": 3,
      "move":    { "keys": ["KeyW", "KeyS", "KeyA", "KeyD"], "alt": ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], "word": "Move" },
      "a":       { "key": "Space", "word": "Jump" },
      "b":       { "key": "ShiftLeft", "word": "Run", "press": "switch" },
      "esc":     { "key": "Escape", "word": "Menu" },
      "pointer": "look",
      "click":   "Use",
      "fixed":   true,
      "extra":   [ { "key": "KeyH", "why": "unneeded" }, { "key": "Enter", "why": "repeat" } ] }

- `move.keys`: the work's own four keys (up, down, left, right); `alt` a second four it also reads; `word` at most 8.
- `a.key`, `b.key`, `esc.key`: the work's own key (a `KeyboardEvent.code`). `a.key` may be `"click"` (the left mouse
  button where the finger aims), `b.key` `"click2"` (the right). `press: "switch"`: one press holds, the next lets go;
  absent, held while the finger is down. Words at most 8 letters, the pill's at most 6 (Menu when none).
- `pointer`: `"mouse"` (the default: a finger is the mouse, a tap the click), `"look"` (a drag turns the view, a tap
  the click), `"own"` (the work's own touch: none of ours on the work), `"none"`. `click`: the word under the mouse on
  a computer. `capture: true` beside `"pointer": "look"` (0.28.0): on a computer a click takes the mouse and its
  movement turns the view, Esc gives it back, for a view from inside (rule 3); left out, a drag turns the view; a phone
  is the same either way. `fixed: true` for a layout that cannot adapt upright.
- A key in one control only, and not also in `extra` (`why`: `repeat` or `unneeded`); any other field drops the file.

### On a computer

The player presses Space, Shift, Esc and W A S D or the arrows on every work, and our runtime presses the work's own
key for each (Space presses 13th Floor's E, Shift its F); a small picture with no words shows which of those keys the
work uses (a mini keyboard with only them lit, the arrows, the mouse, a text field where the work takes typing),
centred at the stage's bottom for the first 6 s after the work's first picture and 3 s after each resume (runtime
1.44.0), so a HUD of the work's own at the bottom middle is covered only then. How it plays in Info and About says what
each key does; your words still name the phone's controls. The arrows always move (below); every other key the
work reads keeps working (E still opens the door). Only a manifest of the work's own is translated: with none, every
key reaches the work as pressed. What follows from that:

- **Where the work's own key is already Space, a Shift or Esc, it keeps it** and nothing is pressed for it (Racing
  Game's Boost on Shift and Drift on Space stay the browser's own). A then takes Space, else Shift; B Shift, else
  Space; the pill Esc. A key of those three that the work reads for something else (named in `extra`, or heard by the
  check) stays the work's, and its control takes the other key or none. Under a version 3 file Space, Shift and Esc
  press your keys only once the work calls `playspace.start()`: a title screen's "press Space" gets Space. The click on A (`click`) and the right click on B (`click2`) are the mouse's own and take no key.
- **The arrows are always W A S D.** Both press the stick's keys. A work that gives the arrows another meaning (a turn,
  an aim) keeps only the move on a computer; put that meaning on the mouse, A or B, or leave it in `extra`.
- **Held on Shift, tapped on Space.** On Windows five Shift presses in a row open Sticky Keys and take the focus, so
  what is held (run, boost, a modifier) goes on B and what is tapped (jump, use, fire) on A.
- **The letter case under Shift.** Where the work reads Shift itself, a real Shift held makes the browser say "W", not
  "w". A work comparing `event.key` to a lower-case letter then stops moving while the player runs. Where B is not the work's own Shift, the runtime sends W A S D as plain letters while Shift is down.
- **What Esc cannot promise.** With the mouse captured, or in full screen, the browser takes the first Esc and lets
  the mouse go (or leaves full screen); no page hears it. The work hears `pointerlockchange`. Esc is the work's menu
  key except for that first press; a work that pauses on losing the mouse needs nothing more.
- **Typing stays typing.** Nothing is pressed for the player while a field of the work has the focus, or with Ctrl,
  Meta or Alt held; a focused button or link of the work keeps Space (the rest of the set still presses your keys). Space and the arrows do not scroll the page where they have a
  control (a page that scrolls keeps its scroll).

### Which control suits which action

- **The default.** The stick is the move keys, A the most used verb's key, B the second's, a tap the click, a drag the
  mouse, the pill the work's own menu key.
- **The shooter.** A drag turns the view, so fire goes on A as the click (`"a": { "key": "click", "word": "Fire" }`);
  a held A passes its drag on as look, so one thumb fires and aims.
- **Aim at a point** (a finger on the work aims and fires where it rests): no button; the default pointer.
- **Up is jump.** A platformer whose jump is the up key gets Jump on A as well: a stick is poor at jumps.
- **Run on the rim.** A run that only speeds the walk is the stick pushed to its rim; B stays free.
- **A switch.** B as a switch where the computer holds a key while clicking (a painter's remove).
- **Held on B, tapped on A.** One thumb rolls from B onto A to press both; on a computer B is Shift (Sticky Keys,
  above).

### Four worked files

- **Musewalk** (W A S D and the arrows walk, Shift runs, a drag looks, a click travels, Q goes back):
  `{ "v": 3, "move": { "keys": ["KeyW", "KeyS", "KeyA", "KeyD"], "alt": ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"] }, "a": { "key": "ShiftLeft", "word": "Run" }, "esc": { "key": "KeyQ", "word": "Back" }, "pointer": "own" }`
- **13th Floor** (W A S D, a drag to look, E use, F light; on a computer Space presses E and Shift F):
  `{ "v": 3, "move": { "keys": ["KeyW", "KeyS", "KeyA", "KeyD"] }, "a": { "key": "KeyE", "word": "Use" }, "b": { "key": "KeyF", "word": "Light" }, "pointer": "look", "click": "Use" }`
- **Racing Game** (the arrows and W A S D drive, Shift boosts, Space drifts, R resets; C and H are a camera and a
  horn play does not depend on): Reset on the pill (Esc presses R on a computer; Shift and Space are its own).
  `{ "v": 3, "move": { "keys": ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], "alt": ["KeyW", "KeyS", "KeyA", "KeyD"], "word": "Drive" }, "a": { "key": "ShiftLeft", "word": "Boost" }, "b": { "key": "Space", "word": "Drift" }, "esc": { "key": "KeyR", "word": "Reset" }, "extra": [{ "key": "KeyC", "why": "unneeded" }, { "key": "KeyH", "why": "unneeded" }] }`
- **Svelte Snake** (its own swipe turns the snake exactly as its arrows do): nothing of ours.
  `{ "v": 3, "pointer": "own", "extra": [{ "key": "ArrowUp", "why": "repeat" }, { "key": "ArrowDown", "why": "repeat" }, { "key": "ArrowLeft", "why": "repeat" }, { "key": "ArrowRight", "why": "repeat" }] }`
