@air-jam/cli 0.9.3 → 1.0.0-beta.1
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/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
|
@@ -3,258 +3,239 @@
|
|
|
3
3
|
|
|
4
4
|
# Input System
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
A game declares the controls each player has. Phones, agents and replays fill
|
|
7
|
+
those controls; the host reads them once per simulation step, with a fixed
|
|
8
|
+
meaning for each kind of control.
|
|
7
9
|
|
|
8
|
-
##
|
|
10
|
+
## Declare Controls
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
```ts
|
|
13
|
+
// src/game/contracts/input.ts
|
|
14
|
+
import {
|
|
15
|
+
button,
|
|
16
|
+
defineAirJamInput,
|
|
17
|
+
stick,
|
|
18
|
+
type AirJamInputValues,
|
|
19
|
+
} from "@air-jam/sdk/core";
|
|
20
|
+
|
|
21
|
+
export const shipInput = defineAirJamInput({
|
|
22
|
+
move: stick(),
|
|
23
|
+
fire: button("pressed"),
|
|
24
|
+
boost: button("held"),
|
|
21
25
|
});
|
|
22
26
|
|
|
23
|
-
type
|
|
24
|
-
|
|
25
|
-
export const airjam = createAirJamApp({
|
|
26
|
-
runtime: env.vite(import.meta.env),
|
|
27
|
-
controllerPath: "/controller",
|
|
28
|
-
input: {
|
|
29
|
-
schema: gameInputSchema,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
27
|
+
export type ShipInput = AirJamInputValues<typeof shipInput>;
|
|
32
28
|
```
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Without any `input.behavior` overrides:
|
|
30
|
+
Declare them once in `src/airjam.config.ts` with `defineAirJamGame` from `@air-jam/sdk/core`:
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
## Optional Behavior Overrides
|
|
45
|
-
|
|
46
|
-
Use `input.behavior` only when your game has specialized needs.
|
|
47
|
-
|
|
48
|
-
```tsx filename="src/airjam.config.ts"
|
|
49
|
-
export const airjam = createAirJamApp({
|
|
50
|
-
runtime: env.vite(import.meta.env),
|
|
51
|
-
controllerPath: "/controller",
|
|
52
|
-
input: {
|
|
53
|
-
schema: gameInputSchema,
|
|
54
|
-
behavior: {
|
|
55
|
-
pulse: ["action", "ability"],
|
|
56
|
-
latest: ["vector"],
|
|
57
|
-
hold: ["menuVector"],
|
|
58
|
-
},
|
|
59
|
-
},
|
|
32
|
+
```ts
|
|
33
|
+
export const airjam = defineAirJamGame({
|
|
34
|
+
// ...
|
|
35
|
+
simulation: shipSimulation,
|
|
36
|
+
input: shipInput,
|
|
60
37
|
});
|
|
61
38
|
```
|
|
62
39
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
input
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
40
|
+
## Control Kinds
|
|
41
|
+
|
|
42
|
+
| Kind | Declared as | A step reads |
|
|
43
|
+
| ------------------------------ | -------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
44
|
+
| Held button | `button("held")` | `true` while the button is down, and for at least one step after a tap shorter than a step |
|
|
45
|
+
| Pressed button | `button("pressed")` | `true` for exactly one step per press |
|
|
46
|
+
| Axis | `axis()` | a number from -1 to 1 |
|
|
47
|
+
| Stick | `stick()` | `{ x, y }`, each from -1 to 1; `y` is down, like screen space |
|
|
48
|
+
| Stick that keeps its direction | `stick({ keepDirection: true })` | the last direction while the stick is centred, as in snake |
|
|
49
|
+
|
|
50
|
+
Presses travel as a counter, so a tap between two network packets or two
|
|
51
|
+
simulation steps is never lost or doubled. Games never debounce or latch input
|
|
52
|
+
themselves.
|
|
53
|
+
|
|
54
|
+
## Read Controls In The Simulation
|
|
55
|
+
|
|
56
|
+
Input reaches a game only in its simulation steps:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
export const shipSimulation = defineAirJamSimulation<Sim, ShipInput>({
|
|
60
|
+
stepMs: 1000 / 60,
|
|
61
|
+
create: () => createSim(),
|
|
62
|
+
step: (sim, { input, players, dtSeconds }) => {
|
|
63
|
+
for (const player of players) {
|
|
64
|
+
const { move, fire, boost } = input(player.id);
|
|
65
|
+
steer(sim, player.id, move, boost, dtSeconds);
|
|
66
|
+
if (fire) shoot(sim, player.id);
|
|
67
|
+
}
|
|
91
68
|
},
|
|
92
|
-
}
|
|
69
|
+
});
|
|
93
70
|
```
|
|
94
71
|
|
|
95
|
-
|
|
72
|
+
`input(playerId)` always returns every control. A player who has sent nothing
|
|
73
|
+
yet reads as released and centred.
|
|
96
74
|
|
|
97
|
-
##
|
|
75
|
+
## Phone Controls
|
|
98
76
|
|
|
99
|
-
|
|
77
|
+
The SDK's phone controls fill the declared controls and send them; a game
|
|
78
|
+
never runs its own send loop.
|
|
100
79
|
|
|
101
80
|
```tsx
|
|
102
|
-
|
|
103
|
-
{
|
|
104
|
-
vector: { x: 0.5, y: -0.3 },
|
|
105
|
-
action: true,
|
|
106
|
-
ability: false,
|
|
107
|
-
timestamp: 1703123456789,
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// ❌ invalid input (returns undefined + warning)
|
|
111
|
-
{
|
|
112
|
-
vector: { x: "bad", y: 0 },
|
|
113
|
-
action: true,
|
|
114
|
-
}
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Benefits:
|
|
118
|
-
|
|
119
|
-
- typed `getInput()` values
|
|
120
|
-
- malformed payloads blocked before gameplay logic
|
|
121
|
-
- clear runtime warnings during development
|
|
81
|
+
import { AxisButton, ControlButton, Stick } from "@air-jam/sdk/ui";
|
|
122
82
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
It assumes your app has already mounted `airjam.Host` above this view.
|
|
128
|
-
|
|
129
|
-
```tsx filename="src/host/index.tsx"
|
|
130
|
-
import { useAirJamHost } from "@air-jam/sdk";
|
|
131
|
-
import { useFrame } from "@react-three/fiber";
|
|
132
|
-
|
|
133
|
-
const HostView = () => {
|
|
134
|
-
const host = useAirJamHost();
|
|
135
|
-
|
|
136
|
-
useFrame(() => {
|
|
137
|
-
host.players.forEach((player) => {
|
|
138
|
-
const input = host.getInput(player.id);
|
|
139
|
-
if (!input) return;
|
|
140
|
-
|
|
141
|
-
movePlayer(player.id, input.vector);
|
|
142
|
-
|
|
143
|
-
if (input.action) {
|
|
144
|
-
playerShoot(player.id);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
return <GameScene />;
|
|
150
|
-
};
|
|
83
|
+
<Stick control={shipInput.move} className="size-48 rounded-full bg-zinc-900" />
|
|
84
|
+
<ControlButton control={shipInput.fire} className="bg-red-500 data-[active=true]:ring-2">
|
|
85
|
+
Fire
|
|
86
|
+
</ControlButton>
|
|
151
87
|
```
|
|
152
88
|
|
|
153
|
-
|
|
89
|
+
1. `ControlButton` binds a button. Each touch, or Space and Enter while it has
|
|
90
|
+
focus, is one press.
|
|
91
|
+
2. `AxisButton` holds an axis at a value while held, such as a paddle's up and
|
|
92
|
+
down buttons. The latest held button wins.
|
|
93
|
+
3. `Stick` reads a drag anywhere inside it. `directions="4-way"` snaps it to a
|
|
94
|
+
pad, `deadzone` keeps small offsets centred, and a function child draws the
|
|
95
|
+
whole stick. It stays correct however the controller surface is rotated.
|
|
154
96
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
```tsx filename="src/game/components/ship.tsx"
|
|
158
|
-
import { useGetInput } from "@air-jam/sdk";
|
|
159
|
-
|
|
160
|
-
const Ship = ({ playerId }: { playerId: string }) => {
|
|
161
|
-
const getInput = useGetInput<typeof gameInputSchema>();
|
|
162
|
-
|
|
163
|
-
useFrame(() => {
|
|
164
|
-
const input = getInput(playerId);
|
|
165
|
-
if (!input) return;
|
|
166
|
-
|
|
167
|
-
shipRef.current.position.x += input.vector.x * SPEED;
|
|
168
|
-
shipRef.current.position.y += input.vector.y * SPEED;
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
return <mesh ref={shipRef}>...</mesh>;
|
|
172
|
-
};
|
|
173
|
-
```
|
|
97
|
+
Every control sets `data-active` while held, so games style the held state
|
|
98
|
+
with their own classes. Controls release when the phone page loses focus.
|
|
174
99
|
|
|
175
|
-
|
|
100
|
+
The controller sends its controls once per display frame when they change, again
|
|
101
|
+
after joining, and on a slow keepalive. Nothing stamps input with a device
|
|
102
|
+
clock.
|
|
176
103
|
|
|
177
|
-
|
|
104
|
+
## Keyboards And Gamepads
|
|
178
105
|
|
|
179
|
-
|
|
180
|
-
|
|
106
|
+
Declare bindings for the controls and every keyboard layout and gamepad plays
|
|
107
|
+
as a local player, with no phone:
|
|
181
108
|
|
|
182
|
-
```
|
|
109
|
+
```ts
|
|
183
110
|
import {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
writeInput({
|
|
198
|
-
direction: directionRef.current,
|
|
199
|
-
action: false,
|
|
200
|
-
});
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
enabled:
|
|
204
|
-
controller.connectionStatus === "connected" &&
|
|
205
|
-
controller.runtimeState === "playing",
|
|
206
|
-
intervalMs: 16,
|
|
207
|
-
},
|
|
208
|
-
);
|
|
209
|
-
};
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### 1. Keep Input and State in Separate Lanes
|
|
213
|
-
|
|
214
|
-
- Input lane: `useInputWriter` + `getInput` / `useGetInput`
|
|
215
|
-
- State lane: `createAirJamStore` + `useActions`
|
|
216
|
-
|
|
217
|
-
Do not send per-frame analog input via store actions.
|
|
218
|
-
|
|
219
|
-
### 2. Keep Quickstart Config Minimal
|
|
220
|
-
|
|
221
|
-
Start with `input: { schema }`. Add `input.behavior` only for non-default needs.
|
|
222
|
-
|
|
223
|
-
### 3. Handle Missing Input Gracefully
|
|
111
|
+
arrows,
|
|
112
|
+
button,
|
|
113
|
+
defineAirJamInput,
|
|
114
|
+
defineAirJamInputBindings,
|
|
115
|
+
stick,
|
|
116
|
+
wasd,
|
|
117
|
+
} from "@air-jam/sdk/core";
|
|
118
|
+
|
|
119
|
+
export const shipInput = defineAirJamInput({
|
|
120
|
+
move: stick(),
|
|
121
|
+
fire: button("pressed"),
|
|
122
|
+
boost: button("held"),
|
|
123
|
+
});
|
|
224
124
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
125
|
+
export const shipInputBindings = defineAirJamInputBindings(shipInput, {
|
|
126
|
+
keyboard: [
|
|
127
|
+
{ move: wasd(), fire: "Space", boost: "ShiftLeft" },
|
|
128
|
+
{ move: arrows(), fire: "Enter", boost: "ShiftRight" },
|
|
129
|
+
],
|
|
130
|
+
gamepad: { move: "leftStick", fire: "south", boost: "rightTrigger" },
|
|
131
|
+
});
|
|
228
132
|
|
|
229
|
-
|
|
133
|
+
// airjam.config.ts
|
|
134
|
+
defineAirJamGame({ input: shipInput, inputBindings: shipInputBindings, ... });
|
|
230
135
|
```
|
|
231
136
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
137
|
+
1. Each keyboard layout is one player; every connected gamepad is one more.
|
|
138
|
+
Keys are `KeyboardEvent.code` values. A button binds one or more keys, an
|
|
139
|
+
axis binds `keyAxis(negative, positive)`, and a stick binds `wasd()`,
|
|
140
|
+
`arrows()` or `keyStick({ up, left, down, right })`. A binding for a
|
|
141
|
+
control that isn't declared, or of the wrong kind, throws when declared.
|
|
142
|
+
2. Gamepad names follow the standard layout: `south`, `east`, `west`,
|
|
143
|
+
`north`, `leftBumper`, `rightBumper`, `leftTrigger`, `rightTrigger`,
|
|
144
|
+
`select`, `start`, stick presses and the d-pad for buttons;
|
|
145
|
+
`leftStickX`/`Y` and `rightStickX`/`Y` for axes; `leftStick`, `rightStick`
|
|
146
|
+
or `dpad` for sticks. Sticks get a small deadzone and stay y down.
|
|
147
|
+
3. A layout's first key, or a gamepad's first button or stick push, opens a
|
|
148
|
+
seat: a preview phone named "Keyboard 1" or "Gamepad 1" that joins like any
|
|
149
|
+
phone. Its own screen answers menus and lobby buttons; the keys or buttons
|
|
150
|
+
drive play. Minimizing that phone keeps it playing; removing it frees the
|
|
151
|
+
seat, and the next key opens a new one.
|
|
152
|
+
4. Keys and gamepads count only while the game page has focus, key repeats
|
|
153
|
+
never press, and losing focus or unplugging a gamepad releases what it
|
|
154
|
+
held. Keys aimed at the page's own buttons and fields stay theirs.
|
|
155
|
+
|
|
156
|
+
Local development's preview phones and Studio provide these seats; a page
|
|
157
|
+
with nobody to provide them leaves keys and gamepads alone. Game code never
|
|
158
|
+
listens to keys or polls gamepads itself.
|
|
159
|
+
|
|
160
|
+
A product framing a game offers its preview workspace's phones as that
|
|
161
|
+
game's seats by passing the game frame to `PreviewControllerWorkspace` as
|
|
162
|
+
`localPlayersGame`; `localPlayers={false}` offers none and closes the seats
|
|
163
|
+
it opened. The Arcade offers them only once a player turns keyboard and
|
|
164
|
+
gamepad players on.
|
|
165
|
+
|
|
166
|
+
A product framing its own phones launches each with
|
|
167
|
+
`createPreviewControllerLaunch` from `@air-jam/sdk/preview`, passing its
|
|
168
|
+
page's origin as `parentOrigin` and, for a seat, its label as `localSeat`. A
|
|
169
|
+
phone takes seat input and close requests only from its direct parent at that
|
|
170
|
+
origin, and answers only there; without `parentOrigin` that is the phone's own
|
|
171
|
+
origin, as the preview workspace launches it.
|
|
172
|
+
|
|
173
|
+
## Agents
|
|
174
|
+
|
|
175
|
+
Agents fill the same controls through leased participant control. They send
|
|
176
|
+
values: a button is `true` or `false`, an axis a number and a stick an
|
|
177
|
+
`{ x, y }`. A button going from `false` to `true` is one press; to press again,
|
|
178
|
+
send `false` and then `true`. The input description agents read comes from the
|
|
179
|
+
declaration.
|
|
180
|
+
|
|
181
|
+
## Input Log And Replays
|
|
182
|
+
|
|
183
|
+
Every host whose game declares a simulation keeps a version 2 input log,
|
|
184
|
+
from construction, in the browser as well as headless. It contains the real
|
|
185
|
+
seed, resolved initial settings, players joining and leaving, room state,
|
|
186
|
+
store actions applied between steps, controls when they change and accepted
|
|
187
|
+
settings updates. Each event carries the step it reached the game before.
|
|
188
|
+
Actions a step causes replay with the simulation and are not logged again.
|
|
189
|
+
`runtime.inputLog()` reads it locally; it throws while the simulation is
|
|
190
|
+
loading or when the game declares none.
|
|
191
|
+
|
|
192
|
+
The recorder retains the start of the match. It freezes before a step would
|
|
193
|
+
exceed 30 minutes of played game time or 16 MiB (the sum of each entry's JSON
|
|
194
|
+
length). A full log ends at the last whole step and excludes pending events.
|
|
195
|
+
`runtime.inputLogFull` reports this without changing the version 2 format.
|
|
196
|
+
Reload the game to start a new recording.
|
|
197
|
+
|
|
198
|
+
Agents use `readHostInputLog(request, observation.identity)` from
|
|
199
|
+
`@air-jam/sdk/runtime-control` through the existing host-agent channel. It
|
|
200
|
+
returns `{ status: "recorded", log, full }`, or `{ status: "not-replayable",
|
|
201
|
+
reason, message }`. Reasons are `no-simulation`, `loading`, `runtime-replaced`
|
|
202
|
+
and `host-unavailable`. A game without a simulation says:
|
|
203
|
+
"This game has no simulation, so its matches cannot be replayed; record a clip instead."
|
|
204
|
+
Reading needs no room grant. The first `input-log-read` request fixes a cut;
|
|
205
|
+
later pages read the same prefix while the match keeps playing.
|
|
206
|
+
|
|
207
|
+
Headless runs keep the log in their evidence. Running
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
airjam session run replay <run-id>
|
|
242
211
|
```
|
|
243
212
|
|
|
244
|
-
|
|
213
|
+
plays it on a fresh copy of the game, with no server or page, and reports
|
|
214
|
+
whether the replay ends where the run ended.
|
|
215
|
+
`replayAirJamInputLog(airjam.createHostRuntime, log)` from
|
|
216
|
+
`@air-jam/sdk/core` remains the run-to-completion form.
|
|
217
|
+
|
|
218
|
+
For playback, `await openAirJamReplay(airjam.createHostRuntime, log)` returns
|
|
219
|
+
`{ runtime, roomId, agent, stop, stepMs, ticks, tick, done, advance }`.
|
|
220
|
+
It stays paused between calls. `advance({ steps: 10 })` runs whole steps;
|
|
221
|
+
`advance({ ms: elapsed * speed })` carries fractions between calls, so a
|
|
222
|
+
caller can drive any speed per animation frame. Both return the current tick
|
|
223
|
+
and clamp at `ticks`. Reaching the end applies events after the final step
|
|
224
|
+
once, including on a recording with zero steps. Call `stop()` when finished.
|
|
245
225
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
226
|
+
There is no backward seek. Open a new replay and advance to the desired tick.
|
|
227
|
+
Each replay needs a fresh load of the same game source, in its own page or
|
|
228
|
+
headless process: game stores are module singletons and cannot share the load
|
|
229
|
+
with the live game or another replay. Exact replay also requires game code to
|
|
230
|
+
draw randomness from the step's seeded `random`.
|
|
249
231
|
|
|
250
|
-
###
|
|
232
|
+
### A Control Does Nothing
|
|
251
233
|
|
|
252
|
-
1.
|
|
253
|
-
2.
|
|
254
|
-
3.
|
|
234
|
+
1. Check the control is declared and passed to `defineAirJamGame({ input })`.
|
|
235
|
+
2. Read it in the simulation step; the host has no other way to read input.
|
|
236
|
+
3. Render phone controls inside `<airjam.Controller>`.
|
|
255
237
|
|
|
256
|
-
###
|
|
238
|
+
### A Tap Fires Twice Or Not At All
|
|
257
239
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
3. Avoid dispatching button presses through store actions
|
|
240
|
+
Use `button("pressed")` for one-shot actions, which then read `true` once per
|
|
241
|
+
press, and `button("held")` for actions that last while held.
|
|
@@ -11,7 +11,7 @@ input, state, and release model.
|
|
|
11
11
|
## Key Features
|
|
12
12
|
|
|
13
13
|
- **Zero App Download**: Players join by scanning a QR code—no app store required
|
|
14
|
-
- **Instant Multiplayer**:
|
|
14
|
+
- **Instant Multiplayer**: Connect smartphones up to the game’s declared player capacity
|
|
15
15
|
- **Developer Friendly**: Built with modern web technologies (React, TypeScript)
|
|
16
16
|
- **AI-Native By Design**: Humans and agents share explicit contracts for runtime, input, logs, and release workflows
|
|
17
17
|
- **Type Safe**: End-to-end type safety with Zod schema validation
|
|
@@ -27,7 +27,10 @@ pnpm add @air-jam/sdk
|
|
|
27
27
|
### 2. Wrap Your App
|
|
28
28
|
|
|
29
29
|
```tsx filename="src/app.tsx"
|
|
30
|
-
import {
|
|
30
|
+
import { createAirJamApp, env } from "@air-jam/sdk";
|
|
31
|
+
import { airjam as game } from "./airjam.config";
|
|
32
|
+
|
|
33
|
+
const airjam = createAirJamApp(game, { runtime: env.vite(import.meta.env) });
|
|
31
34
|
|
|
32
35
|
export const App = () => (
|
|
33
36
|
<Routes>
|
|
@@ -58,19 +61,52 @@ export const App = () => (
|
|
|
58
61
|
);
|
|
59
62
|
```
|
|
60
63
|
|
|
61
|
-
```
|
|
62
|
-
import {
|
|
63
|
-
import {
|
|
64
|
+
```ts filename="src/airjam.config.ts"
|
|
65
|
+
import { defineAirJamGame } from "@air-jam/sdk/core";
|
|
66
|
+
import {
|
|
67
|
+
axis,
|
|
68
|
+
button,
|
|
69
|
+
defineAirJamInput,
|
|
70
|
+
defineAirJamSimulation,
|
|
71
|
+
type AirJamInputValues,
|
|
72
|
+
} from "@air-jam/sdk/core";
|
|
73
|
+
|
|
74
|
+
export const gameInput = defineAirJamInput({
|
|
75
|
+
direction: axis(),
|
|
76
|
+
fire: button("pressed"),
|
|
77
|
+
});
|
|
64
78
|
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
const simulation = defineAirJamSimulation<
|
|
80
|
+
World,
|
|
81
|
+
AirJamInputValues<typeof gameInput>
|
|
82
|
+
>({
|
|
83
|
+
stepMs: 1000 / 60,
|
|
84
|
+
create: () => createWorld(),
|
|
85
|
+
step: (world, { input, players, dtSeconds }) => {
|
|
86
|
+
for (const player of players) {
|
|
87
|
+
const { direction, fire } = input(player.id);
|
|
88
|
+
movePaddle(world, player.id, direction * SPEED * dtSeconds);
|
|
89
|
+
if (fire) fireLaser(world, player.id);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
68
92
|
});
|
|
69
93
|
|
|
70
|
-
export const airjam =
|
|
71
|
-
|
|
94
|
+
export const airjam = defineAirJamGame({
|
|
95
|
+
metadata: {
|
|
96
|
+
slug: "space-game",
|
|
97
|
+
name: "Space Game",
|
|
98
|
+
tagline: "Fly together and defend the fleet.",
|
|
99
|
+
category: "arcade",
|
|
100
|
+
minPlayers: 1,
|
|
101
|
+
maxPlayers: 4,
|
|
102
|
+
inputModalities: ["buttons", "touch"],
|
|
103
|
+
supportedSdkRange: "^1.0.0",
|
|
104
|
+
maintainer: { name: "Air Jam" },
|
|
105
|
+
version: 1,
|
|
106
|
+
},
|
|
72
107
|
controllerPath: "/controller",
|
|
73
|
-
|
|
108
|
+
simulation,
|
|
109
|
+
input: gameInput,
|
|
74
110
|
});
|
|
75
111
|
```
|
|
76
112
|
|
|
@@ -84,15 +120,7 @@ import { useAirJamHost } from "@air-jam/sdk";
|
|
|
84
120
|
|
|
85
121
|
const HostView = () => {
|
|
86
122
|
const host = useAirJamHost();
|
|
87
|
-
|
|
88
|
-
// In your game loop (e.g., useFrame or requestAnimationFrame):
|
|
89
|
-
// host.players.forEach(p => {
|
|
90
|
-
// const input = host.getInput(p.id);
|
|
91
|
-
// if (input) {
|
|
92
|
-
// player.y += input.direction * SPEED;
|
|
93
|
-
// if (input.action) fireLaser(p.id);
|
|
94
|
-
// }
|
|
95
|
-
// });
|
|
123
|
+
// The simulation moves the game; this view draws it with useSimulationFrame.
|
|
96
124
|
|
|
97
125
|
return (
|
|
98
126
|
<div className="relative min-h-screen bg-black text-white">
|
|
@@ -122,41 +150,33 @@ The path below also matches the current starter template layout.
|
|
|
122
150
|
If your project uses a different file shape, keep the same ownership boundary even if the filename changes.
|
|
123
151
|
|
|
124
152
|
```tsx filename="src/controller/index.tsx"
|
|
125
|
-
import {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
action: false,
|
|
142
|
-
});
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
enabled:
|
|
146
|
-
controller.connectionStatus === "connected" &&
|
|
147
|
-
controller.runtimeState === "playing",
|
|
148
|
-
intervalMs: 16,
|
|
149
|
-
},
|
|
150
|
-
);
|
|
151
|
-
};
|
|
153
|
+
import { AxisButton, ControlButton } from "@air-jam/sdk/ui";
|
|
154
|
+
import { gameInput } from "../airjam.config";
|
|
155
|
+
|
|
156
|
+
const ControllerView = () => (
|
|
157
|
+
<div className="grid h-full grid-cols-2 gap-3 p-3">
|
|
158
|
+
<AxisButton control={gameInput.direction} value={-1}>
|
|
159
|
+
Up
|
|
160
|
+
</AxisButton>
|
|
161
|
+
<AxisButton control={gameInput.direction} value={1}>
|
|
162
|
+
Down
|
|
163
|
+
</AxisButton>
|
|
164
|
+
<ControlButton control={gameInput.fire} className="col-span-2">
|
|
165
|
+
Fire
|
|
166
|
+
</ControlButton>
|
|
167
|
+
</div>
|
|
168
|
+
);
|
|
152
169
|
```
|
|
153
170
|
|
|
171
|
+
The SDK's phone controls fill the declared controls and send them; the
|
|
172
|
+
controller runs no send loop.
|
|
173
|
+
|
|
154
174
|
## Canonical Architecture: Three Lanes
|
|
155
175
|
|
|
156
176
|
Use one lane per concern:
|
|
157
177
|
|
|
158
|
-
1. **Input lane**:
|
|
159
|
-
2. **State lane**: `createAirJamStore` with host-owned actions
|
|
178
|
+
1. **Input lane**: controls declared with `defineAirJamInput`, filled by the SDK's phone controls, read in simulation steps with `input(playerId)`.
|
|
179
|
+
2. **State lane**: `createAirJamStore` with host-owned actions, dispatched through `store.actions`.
|
|
160
180
|
3. **Signal lane**: `sendSignal` / system commands for out-of-band UX and runtime commands.
|
|
161
181
|
|
|
162
182
|
Arcade does not replace this model. Arcade is an Air Jam app around another
|
|
@@ -166,10 +186,10 @@ Avoid cross-lane misuse:
|
|
|
166
186
|
|
|
167
187
|
1. Don’t stream per-frame movement through store actions.
|
|
168
188
|
2. Don’t encode authoritative gameplay state in signals.
|
|
169
|
-
3. Don’t call `state.actions.*`;
|
|
189
|
+
3. Don’t call `state.actions.*`; dispatch through `gameStore.actions`.
|
|
170
190
|
|
|
171
191
|
## Next Steps
|
|
172
192
|
|
|
173
193
|
- [Architecture](./architecture.md) - Understand the system design
|
|
174
194
|
- [Hooks Reference](./sdk-hooks.md) - Complete API documentation
|
|
175
|
-
- [Input System](./input-system.md) -
|
|
195
|
+
- [Input System](./input-system.md) - Declare controls and read them each step
|