@air-jam/cli 0.9.3 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -0
- package/dist/auth-profile.d.ts +5 -0
- package/dist/auth-profile.js +7 -0
- package/dist/auth-profile.js.map +1 -0
- package/dist/auth-sessions.d.ts +5 -0
- package/dist/auth-sessions.js +7 -0
- package/dist/auth-sessions.js.map +1 -0
- package/dist/chunk-7D4AYBAV.js +64 -0
- package/dist/chunk-7D4AYBAV.js.map +1 -0
- package/dist/chunk-LH7UO57C.js +23 -0
- package/dist/chunk-LH7UO57C.js.map +1 -0
- package/dist/chunk-PKTLVQXZ.js +82 -0
- package/dist/chunk-PKTLVQXZ.js.map +1 -0
- package/dist/chunk-SQE4NPZP.js +31 -0
- package/dist/chunk-SQE4NPZP.js.map +1 -0
- package/dist/{chunk-A4V2N4LX.js → chunk-U6V3HEBB.js} +6 -5
- package/dist/chunk-U6V3HEBB.js.map +1 -0
- package/dist/chunk-VEHNFPEO.js +224 -0
- package/dist/chunk-VEHNFPEO.js.map +1 -0
- package/dist/development.d.ts +4 -0
- package/dist/development.js +1 -1
- package/dist/game-analytics.d.ts +5 -0
- package/dist/game-analytics.js +7 -0
- package/dist/game-analytics.js.map +1 -0
- package/dist/game-app-id.d.ts +5 -0
- package/dist/game-app-id.js +7 -0
- package/dist/game-app-id.js.map +1 -0
- package/dist/game-media.d.ts +5 -0
- package/dist/game-media.js +7 -0
- package/dist/game-media.js.map +1 -0
- package/dist/index.js +688 -404
- package/dist/index.js.map +1 -1
- package/dist/scaffold.d.ts +8 -1
- package/dist/scaffold.js +6 -1
- package/dist/scaffold.js.map +1 -1
- package/package.json +8 -4
- package/runtime/local-network.d.mts +4 -6
- package/runtime/public-assets.mjs +62 -0
- package/runtime/source-fence.mjs +182 -0
- package/runtime/vite-config.d.mts +2 -1
- package/runtime/vite-config.mjs +6 -2
- package/runtime/vite-dev.mjs +18 -0
- package/runtime/vite-https.mjs +2 -3
- package/template-assets/bootstrap/AGENTS.md +56 -14
- package/template-assets/bootstrap/CLAUDE.md +0 -8
- package/template-assets/bootstrap/skills/airjam-mcp/SKILL.md +44 -0
- package/template-assets/bootstrap/skills/controller-ui/SKILL.md +2 -0
- package/template-assets/bootstrap/skills/game-architecture/SKILL.md +47 -3
- package/template-assets/bootstrap/skills/index.md +1 -1
- package/template-assets/bootstrap/skills/prefab-authoring/SKILL.md +10 -0
- package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +10 -0
- package/template-assets/documentation/for-agents/controller-ui/page.mdx +41 -2
- package/template-assets/documentation/for-agents/page.mdx +24 -2
- package/template-assets/documentation/for-agents/project-structure/page.mdx +0 -2
- package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +0 -2
- package/template-assets/documentation/for-agents/supported-agents/page.mdx +18 -0
- package/template-assets/documentation/getting-started/debugging/page.mdx +7 -8
- package/template-assets/documentation/getting-started/dev-logs/page.mdx +0 -2
- package/template-assets/documentation/getting-started/game-ideas/page.mdx +1 -3
- package/template-assets/documentation/getting-started/introduction/page.mdx +71 -54
- package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +308 -62
- package/template-assets/documentation/getting-started/quick-start/page.mdx +56 -79
- package/template-assets/documentation/how-it-works/architecture/page.mdx +91 -50
- package/template-assets/documentation/how-it-works/host-system/page.mdx +112 -109
- package/template-assets/documentation/manifest.json +112 -42
- package/template-assets/documentation/sdk/assets-and-theme/page.mdx +185 -0
- package/template-assets/documentation/sdk/hooks/page.mdx +106 -171
- package/template-assets/documentation/sdk/input-system/page.mdx +201 -231
- package/template-assets/documentation/sdk/networked-state/page.mdx +134 -52
- package/template-assets/documentation/sdk/settings/page.mdx +155 -0
- package/template-assets/documentation/sdk/ui-components/page.mdx +45 -4
- package/template-assets/managed/.airjam/ai-pack.json +61 -43
- package/template-assets/managed/docs/airjam/agent-gold-path.md +55 -7
- package/template-assets/managed/docs/airjam/agent-mcp.md +44 -0
- package/template-assets/managed/docs/airjam/debug-and-testing.md +18 -0
- package/template-assets/managed/docs/airjam/docs-index.md +18 -12
- package/template-assets/managed/docs/airjam/generated/architecture.md +91 -46
- package/template-assets/managed/docs/airjam/generated/assets-and-theme.md +188 -0
- package/template-assets/managed/docs/airjam/generated/controller-ui.md +41 -0
- package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +7 -6
- package/template-assets/managed/docs/airjam/generated/for-agents.md +24 -0
- package/template-assets/managed/docs/airjam/generated/game-ideas.md +1 -1
- package/template-assets/managed/docs/airjam/generated/host-system.md +112 -102
- package/template-assets/managed/docs/airjam/generated/input-system.md +199 -218
- package/template-assets/managed/docs/airjam/generated/introduction.md +71 -51
- package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +308 -60
- package/template-assets/managed/docs/airjam/generated/networked-state.md +134 -50
- package/template-assets/managed/docs/airjam/generated/quick-start.md +56 -79
- package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +106 -166
- package/template-assets/managed/docs/airjam/generated/settings.md +158 -0
- package/template-assets/managed/docs/airjam/generated/supported-agents.md +21 -0
- package/template-assets/managed/docs/airjam/generated/ui-components.md +45 -2
- package/template-assets/managed/docs/airjam/prefab-authoring.md +100 -0
- package/template-assets/managed/docs/airjam/preview-controllers.md +4 -1
- package/template-assets/managed/docs/airjam/r3f-3d-scene.md +66 -0
- package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +15 -20
- package/dist/chunk-A4V2N4LX.js.map +0 -1
|
@@ -1,270 +1,240 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
# Input System
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
A game declares the controls each player has. Phones, agents and replays fill
|
|
4
|
+
those controls; the host reads them once per simulation step, with a fixed
|
|
5
|
+
meaning for each kind of control.
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
## Declare Controls
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
```ts
|
|
10
|
+
// src/game/contracts/input.ts
|
|
11
|
+
import {
|
|
12
|
+
button,
|
|
13
|
+
defineAirJamInput,
|
|
14
|
+
stick,
|
|
15
|
+
type AirJamInputValues,
|
|
16
|
+
} from "@air-jam/sdk/core";
|
|
17
|
+
|
|
18
|
+
export const shipInput = defineAirJamInput({
|
|
19
|
+
move: stick(),
|
|
20
|
+
fire: button("pressed"),
|
|
21
|
+
boost: button("held"),
|
|
25
22
|
});
|
|
26
23
|
|
|
27
|
-
type
|
|
28
|
-
|
|
29
|
-
export const airjam = createAirJamApp({
|
|
30
|
-
runtime: env.vite(import.meta.env),
|
|
31
|
-
controllerPath: "/controller",
|
|
32
|
-
input: {
|
|
33
|
-
schema: gameInputSchema,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
24
|
+
export type ShipInput = AirJamInputValues<typeof shipInput>;
|
|
36
25
|
```
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Without any `input.behavior` overrides:
|
|
41
|
-
|
|
42
|
-
- booleans use `pulse` (tap-safe consume-on-read)
|
|
43
|
-
- vectors use `latest` (continuous current value)
|
|
44
|
-
- all other fields use `latest`
|
|
45
|
-
|
|
46
|
-
This default is the canonical path for most games.
|
|
47
|
-
|
|
48
|
-
## Optional Behavior Overrides
|
|
49
|
-
|
|
50
|
-
Use `input.behavior` only when your game has specialized needs.
|
|
27
|
+
Declare them once in `src/airjam.config.ts` with `defineAirJamGame` from `@air-jam/sdk/core`:
|
|
51
28
|
|
|
52
|
-
```
|
|
53
|
-
export const airjam =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
input:
|
|
57
|
-
schema: gameInputSchema,
|
|
58
|
-
behavior: {
|
|
59
|
-
pulse: ["action", "ability"],
|
|
60
|
-
latest: ["vector"],
|
|
61
|
-
hold: ["menuVector"],
|
|
62
|
-
},
|
|
63
|
-
},
|
|
29
|
+
```ts
|
|
30
|
+
export const airjam = defineAirJamGame({
|
|
31
|
+
// ...
|
|
32
|
+
simulation: shipSimulation,
|
|
33
|
+
input: shipInput,
|
|
64
34
|
});
|
|
65
35
|
```
|
|
66
36
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
input
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
37
|
+
## Control Kinds
|
|
38
|
+
|
|
39
|
+
| Kind | Declared as | A step reads |
|
|
40
|
+
| ------------------------------ | -------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
41
|
+
| Held button | `button("held")` | `true` while the button is down, and for at least one step after a tap shorter than a step |
|
|
42
|
+
| Pressed button | `button("pressed")` | `true` for exactly one step per press |
|
|
43
|
+
| Axis | `axis()` | a number from -1 to 1 |
|
|
44
|
+
| Stick | `stick()` | `{ x, y }`, each from -1 to 1; `y` is down, like screen space |
|
|
45
|
+
| Stick that keeps its direction | `stick({ keepDirection: true })` | the last direction while the stick is centred, as in snake |
|
|
46
|
+
|
|
47
|
+
Presses travel as a counter, so a tap between two network packets or two
|
|
48
|
+
simulation steps is never lost or doubled. Games never debounce or latch input
|
|
49
|
+
themselves.
|
|
50
|
+
|
|
51
|
+
## Read Controls In The Simulation
|
|
52
|
+
|
|
53
|
+
Input reaches a game only in its simulation steps:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
export const shipSimulation = defineAirJamSimulation<Sim, ShipInput>({
|
|
57
|
+
stepMs: 1000 / 60,
|
|
58
|
+
create: () => createSim(),
|
|
59
|
+
step: (sim, { input, players, dtSeconds }) => {
|
|
60
|
+
for (const player of players) {
|
|
61
|
+
const { move, fire, boost } = input(player.id);
|
|
62
|
+
steer(sim, player.id, move, boost, dtSeconds);
|
|
63
|
+
if (fire) shoot(sim, player.id);
|
|
64
|
+
}
|
|
83
65
|
},
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
New config:
|
|
88
|
-
|
|
89
|
-
```tsx
|
|
90
|
-
input: {
|
|
91
|
-
schema: gameInputSchema,
|
|
92
|
-
behavior: {
|
|
93
|
-
pulse: ["action"],
|
|
94
|
-
latest: ["vector"],
|
|
95
|
-
},
|
|
96
|
-
}
|
|
66
|
+
});
|
|
97
67
|
```
|
|
98
68
|
|
|
99
|
-
|
|
69
|
+
`input(playerId)` always returns every control. A player who has sent nothing
|
|
70
|
+
yet reads as released and centred.
|
|
100
71
|
|
|
101
|
-
##
|
|
72
|
+
## Phone Controls
|
|
102
73
|
|
|
103
|
-
|
|
74
|
+
The SDK's phone controls fill the declared controls and send them; a game
|
|
75
|
+
never runs its own send loop.
|
|
104
76
|
|
|
105
77
|
```tsx
|
|
106
|
-
|
|
107
|
-
{
|
|
108
|
-
vector: { x: 0.5, y: -0.3 },
|
|
109
|
-
action: true,
|
|
110
|
-
ability: false,
|
|
111
|
-
timestamp: 1703123456789,
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// ❌ invalid input (returns undefined + warning)
|
|
115
|
-
{
|
|
116
|
-
vector: { x: "bad", y: 0 },
|
|
117
|
-
action: true,
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
Benefits:
|
|
122
|
-
|
|
123
|
-
- typed `getInput()` values
|
|
124
|
-
- malformed payloads blocked before gameplay logic
|
|
125
|
-
- clear runtime warnings during development
|
|
78
|
+
import { AxisButton, ControlButton, Stick } from "@air-jam/sdk/ui";
|
|
126
79
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
This example uses the starter host surface path.
|
|
132
|
-
Treat it as a recommended default, not a required filename.
|
|
133
|
-
It assumes your app has already mounted `airjam.Host` above this view.
|
|
134
|
-
|
|
135
|
-
```tsx filename="src/host/index.tsx"
|
|
136
|
-
import { useAirJamHost } from "@air-jam/sdk";
|
|
137
|
-
import { useFrame } from "@react-three/fiber";
|
|
138
|
-
|
|
139
|
-
const HostView = () => {
|
|
140
|
-
const host = useAirJamHost();
|
|
141
|
-
|
|
142
|
-
useFrame(() => {
|
|
143
|
-
host.players.forEach((player) => {
|
|
144
|
-
const input = host.getInput(player.id);
|
|
145
|
-
if (!input) return;
|
|
146
|
-
|
|
147
|
-
movePlayer(player.id, input.vector);
|
|
148
|
-
|
|
149
|
-
if (input.action) {
|
|
150
|
-
playerShoot(player.id);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
return <GameScene />;
|
|
156
|
-
};
|
|
80
|
+
<Stick control={shipInput.move} className="size-48 rounded-full bg-zinc-900" />
|
|
81
|
+
<ControlButton control={shipInput.fire} className="bg-red-500 data-[active=true]:ring-2">
|
|
82
|
+
Fire
|
|
83
|
+
</ControlButton>
|
|
157
84
|
```
|
|
158
85
|
|
|
159
|
-
|
|
86
|
+
1. `ControlButton` binds a button. Each touch, or Space and Enter while it has
|
|
87
|
+
focus, is one press.
|
|
88
|
+
2. `AxisButton` holds an axis at a value while held, such as a paddle's up and
|
|
89
|
+
down buttons. The latest held button wins.
|
|
90
|
+
3. `Stick` reads a drag anywhere inside it. `directions="4-way"` snaps it to a
|
|
91
|
+
pad, `deadzone` keeps small offsets centred, and a function child draws the
|
|
92
|
+
whole stick. It stays correct however the controller surface is rotated.
|
|
160
93
|
|
|
161
|
-
|
|
94
|
+
Every control sets `data-active` while held, so games style the held state
|
|
95
|
+
with their own classes. Controls release when the phone page loses focus.
|
|
162
96
|
|
|
163
|
-
|
|
164
|
-
|
|
97
|
+
The controller sends its controls once per display frame when they change, again
|
|
98
|
+
after joining, and on a slow keepalive. Nothing stamps input with a device
|
|
99
|
+
clock.
|
|
165
100
|
|
|
166
|
-
|
|
167
|
-
const getInput = useGetInput<typeof gameInputSchema>();
|
|
101
|
+
## Keyboards And Gamepads
|
|
168
102
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (!input) return;
|
|
103
|
+
Declare bindings for the controls and every keyboard layout and gamepad plays
|
|
104
|
+
as a local player, with no phone:
|
|
172
105
|
|
|
173
|
-
|
|
174
|
-
shipRef.current.position.y += input.vector.y * SPEED;
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
return <mesh ref={shipRef}>...</mesh>;
|
|
178
|
-
};
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
## Controller Cadence
|
|
182
|
-
|
|
183
|
-
Use `useInputWriter()` with `useControllerTick()` for fixed-cadence publishing:
|
|
184
|
-
|
|
185
|
-
This example uses the starter controller surface path.
|
|
186
|
-
It assumes your app has already mounted `airjam.Controller` above this view.
|
|
187
|
-
|
|
188
|
-
```tsx filename="src/controller/index.tsx"
|
|
106
|
+
```ts
|
|
189
107
|
import {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
writeInput({
|
|
204
|
-
direction: directionRef.current,
|
|
205
|
-
action: false,
|
|
206
|
-
});
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
enabled:
|
|
210
|
-
controller.connectionStatus === "connected" &&
|
|
211
|
-
controller.runtimeState === "playing",
|
|
212
|
-
intervalMs: 16,
|
|
213
|
-
},
|
|
214
|
-
);
|
|
215
|
-
};
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
## Best Practices
|
|
219
|
-
|
|
220
|
-
### 1. Keep Input and State in Separate Lanes
|
|
221
|
-
|
|
222
|
-
- Input lane: `useInputWriter` + `getInput` / `useGetInput`
|
|
223
|
-
- State lane: `createAirJamStore` + `useActions`
|
|
224
|
-
|
|
225
|
-
Do not send per-frame analog input via store actions.
|
|
226
|
-
|
|
227
|
-
### 2. Keep Quickstart Config Minimal
|
|
228
|
-
|
|
229
|
-
Start with `input: { schema }`. Add `input.behavior` only for non-default needs.
|
|
230
|
-
|
|
231
|
-
### 3. Handle Missing Input Gracefully
|
|
232
|
-
|
|
233
|
-
```tsx filename="src/components/Player.tsx"
|
|
234
|
-
const input = getInput(playerId);
|
|
235
|
-
if (!input) return;
|
|
236
|
-
|
|
237
|
-
movePlayer(input.vector);
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### 4. Include Timestamps for Advanced Physics
|
|
108
|
+
arrows,
|
|
109
|
+
button,
|
|
110
|
+
defineAirJamInput,
|
|
111
|
+
defineAirJamInputBindings,
|
|
112
|
+
stick,
|
|
113
|
+
wasd,
|
|
114
|
+
} from "@air-jam/sdk/core";
|
|
115
|
+
|
|
116
|
+
export const shipInput = defineAirJamInput({
|
|
117
|
+
move: stick(),
|
|
118
|
+
fire: button("pressed"),
|
|
119
|
+
boost: button("held"),
|
|
120
|
+
});
|
|
241
121
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
122
|
+
export const shipInputBindings = defineAirJamInputBindings(shipInput, {
|
|
123
|
+
keyboard: [
|
|
124
|
+
{ move: wasd(), fire: "Space", boost: "ShiftLeft" },
|
|
125
|
+
{ move: arrows(), fire: "Enter", boost: "ShiftRight" },
|
|
126
|
+
],
|
|
127
|
+
gamepad: { move: "leftStick", fire: "south", boost: "rightTrigger" },
|
|
247
128
|
});
|
|
248
129
|
|
|
249
|
-
|
|
130
|
+
// airjam.config.ts
|
|
131
|
+
defineAirJamGame({ input: shipInput, inputBindings: shipInputBindings, ... });
|
|
250
132
|
```
|
|
251
133
|
|
|
252
|
-
|
|
134
|
+
1. Each keyboard layout is one player; every connected gamepad is one more.
|
|
135
|
+
Keys are `KeyboardEvent.code` values. A button binds one or more keys, an
|
|
136
|
+
axis binds `keyAxis(negative, positive)`, and a stick binds `wasd()`,
|
|
137
|
+
`arrows()` or `keyStick({ up, left, down, right })`. A binding for a
|
|
138
|
+
control that isn't declared, or of the wrong kind, throws when declared.
|
|
139
|
+
2. Gamepad names follow the standard layout: `south`, `east`, `west`,
|
|
140
|
+
`north`, `leftBumper`, `rightBumper`, `leftTrigger`, `rightTrigger`,
|
|
141
|
+
`select`, `start`, stick presses and the d-pad for buttons;
|
|
142
|
+
`leftStickX`/`Y` and `rightStickX`/`Y` for axes; `leftStick`, `rightStick`
|
|
143
|
+
or `dpad` for sticks. Sticks get a small deadzone and stay y down.
|
|
144
|
+
3. A layout's first key, or a gamepad's first button or stick push, opens a
|
|
145
|
+
seat: a preview phone named "Keyboard 1" or "Gamepad 1" that joins like any
|
|
146
|
+
phone. Its own screen answers menus and lobby buttons; the keys or buttons
|
|
147
|
+
drive play. Minimizing that phone keeps it playing; removing it frees the
|
|
148
|
+
seat, and the next key opens a new one.
|
|
149
|
+
4. Keys and gamepads count only while the game page has focus, key repeats
|
|
150
|
+
never press, and losing focus or unplugging a gamepad releases what it
|
|
151
|
+
held. Keys aimed at the page's own buttons and fields stay theirs.
|
|
152
|
+
|
|
153
|
+
Local development's preview phones and Studio provide these seats; a page
|
|
154
|
+
with nobody to provide them leaves keys and gamepads alone. Game code never
|
|
155
|
+
listens to keys or polls gamepads itself.
|
|
156
|
+
|
|
157
|
+
A product framing a game offers its preview workspace's phones as that
|
|
158
|
+
game's seats by passing the game frame to `PreviewControllerWorkspace` as
|
|
159
|
+
`localPlayersGame`; `localPlayers={false}` offers none and closes the seats
|
|
160
|
+
it opened. The Arcade offers them only once a player turns keyboard and
|
|
161
|
+
gamepad players on.
|
|
162
|
+
|
|
163
|
+
A product framing its own phones launches each with
|
|
164
|
+
`createPreviewControllerLaunch` from `@air-jam/sdk/preview`, passing its
|
|
165
|
+
page's origin as `parentOrigin` and, for a seat, its label as `localSeat`. A
|
|
166
|
+
phone takes seat input and close requests only from its direct parent at that
|
|
167
|
+
origin, and answers only there; without `parentOrigin` that is the phone's own
|
|
168
|
+
origin, as the preview workspace launches it.
|
|
169
|
+
|
|
170
|
+
## Agents
|
|
171
|
+
|
|
172
|
+
Agents fill the same controls through leased participant control. They send
|
|
173
|
+
values: a button is `true` or `false`, an axis a number and a stick an
|
|
174
|
+
`{ x, y }`. A button going from `false` to `true` is one press; to press again,
|
|
175
|
+
send `false` and then `true`. The input description agents read comes from the
|
|
176
|
+
declaration.
|
|
177
|
+
|
|
178
|
+
## Input Log And Replays
|
|
179
|
+
|
|
180
|
+
Every host whose game declares a simulation keeps a version 2 input log,
|
|
181
|
+
from construction, in the browser as well as headless. It contains the real
|
|
182
|
+
seed, resolved initial settings, players joining and leaving, room state,
|
|
183
|
+
store actions applied between steps, controls when they change and accepted
|
|
184
|
+
settings updates. Each event carries the step it reached the game before.
|
|
185
|
+
Actions a step causes replay with the simulation and are not logged again.
|
|
186
|
+
`runtime.inputLog()` reads it locally; it throws while the simulation is
|
|
187
|
+
loading or when the game declares none.
|
|
188
|
+
|
|
189
|
+
The recorder retains the start of the match. It freezes before a step would
|
|
190
|
+
exceed 30 minutes of played game time or 16 MiB (the sum of each entry's JSON
|
|
191
|
+
length). A full log ends at the last whole step and excludes pending events.
|
|
192
|
+
`runtime.inputLogFull` reports this without changing the version 2 format.
|
|
193
|
+
Reload the game to start a new recording.
|
|
194
|
+
|
|
195
|
+
Agents use `readHostInputLog(request, observation.identity)` from
|
|
196
|
+
`@air-jam/sdk/runtime-control` through the existing host-agent channel. It
|
|
197
|
+
returns `{ status: "recorded", log, full }`, or `{ status: "not-replayable",
|
|
198
|
+
reason, message }`. Reasons are `no-simulation`, `loading`, `runtime-replaced`
|
|
199
|
+
and `host-unavailable`. A game without a simulation says:
|
|
200
|
+
"This game has no simulation, so its matches cannot be replayed; record a clip instead."
|
|
201
|
+
Reading needs no room grant. The first `input-log-read` request fixes a cut;
|
|
202
|
+
later pages read the same prefix while the match keeps playing.
|
|
203
|
+
|
|
204
|
+
Headless runs keep the log in their evidence. Running
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
airjam session run replay <run-id>
|
|
208
|
+
```
|
|
253
209
|
|
|
254
|
-
|
|
210
|
+
plays it on a fresh copy of the game, with no server or page, and reports
|
|
211
|
+
whether the replay ends where the run ended.
|
|
212
|
+
`replayAirJamInputLog(airjam.createHostRuntime, log)` from
|
|
213
|
+
`@air-jam/sdk/core` remains the run-to-completion form.
|
|
214
|
+
|
|
215
|
+
For playback, `await openAirJamReplay(airjam.createHostRuntime, log)` returns
|
|
216
|
+
`{ runtime, roomId, agent, stop, stepMs, ticks, tick, done, advance }`.
|
|
217
|
+
It stays paused between calls. `advance({ steps: 10 })` runs whole steps;
|
|
218
|
+
`advance({ ms: elapsed * speed })` carries fractions between calls, so a
|
|
219
|
+
caller can drive any speed per animation frame. Both return the current tick
|
|
220
|
+
and clamp at `ticks`. Reaching the end applies events after the final step
|
|
221
|
+
once, including on a recording with zero steps. Call `stop()` when finished.
|
|
222
|
+
|
|
223
|
+
There is no backward seek. Open a new replay and advance to the desired tick.
|
|
224
|
+
Each replay needs a fresh load of the same game source, in its own page or
|
|
225
|
+
headless process: game stores are module singletons and cannot share the load
|
|
226
|
+
with the live game or another replay. Exact replay also requires game code to
|
|
227
|
+
draw randomness from the step's seeded `random`.
|
|
255
228
|
|
|
256
|
-
|
|
257
|
-
2. Verify room code matches on host and controller
|
|
258
|
-
3. Check schema warnings in console (`[InputManager] Invalid input ...`)
|
|
229
|
+
## Common Issues
|
|
259
230
|
|
|
260
|
-
###
|
|
231
|
+
### A Control Does Nothing
|
|
261
232
|
|
|
262
|
-
1.
|
|
263
|
-
2.
|
|
264
|
-
3.
|
|
233
|
+
1. Check the control is declared and passed to `defineAirJamGame({ input })`.
|
|
234
|
+
2. Read it in the simulation step; the host has no other way to read input.
|
|
235
|
+
3. Render phone controls inside `<airjam.Controller>`.
|
|
265
236
|
|
|
266
|
-
###
|
|
237
|
+
### A Tap Fires Twice Or Not At All
|
|
267
238
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
3. Avoid dispatching button presses through store actions
|
|
239
|
+
Use `button("pressed")` for one-shot actions, which then read `true` once per
|
|
240
|
+
press, and `button("held")` for actions that last while held.
|