@air-jam/cli 0.0.0-stage → 0.9.3

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.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +145 -2
  3. package/bin/airjam.mjs +66 -0
  4. package/dist/ai-pack.d.ts +44 -0
  5. package/dist/ai-pack.js +15 -0
  6. package/dist/ai-pack.js.map +1 -0
  7. package/dist/chunk-A4V2N4LX.js +938 -0
  8. package/dist/chunk-A4V2N4LX.js.map +1 -0
  9. package/dist/chunk-J5MAU4QZ.js +102 -0
  10. package/dist/chunk-J5MAU4QZ.js.map +1 -0
  11. package/dist/chunk-N7AI7HZK.js +529 -0
  12. package/dist/chunk-N7AI7HZK.js.map +1 -0
  13. package/dist/development.d.ts +98 -0
  14. package/dist/development.js +33 -0
  15. package/dist/development.js.map +1 -0
  16. package/dist/documentation.d.ts +27 -0
  17. package/dist/documentation.js +7 -0
  18. package/dist/documentation.js.map +1 -0
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.js +2184 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/scaffold.d.ts +6 -0
  23. package/dist/scaffold.js +20 -0
  24. package/dist/scaffold.js.map +1 -0
  25. package/package.json +78 -3
  26. package/runtime/local-network.d.mts +8 -0
  27. package/runtime/local-network.mjs +9 -0
  28. package/runtime/vite-config.d.mts +42 -0
  29. package/runtime/vite-config.mjs +130 -0
  30. package/runtime/vite-https.d.mts +11 -0
  31. package/runtime/vite-https.mjs +41 -0
  32. package/template-assets/bootstrap/.claude/launch.json +12 -0
  33. package/template-assets/bootstrap/AGENTS.md +248 -0
  34. package/template-assets/bootstrap/CLAUDE.md +63 -0
  35. package/template-assets/bootstrap/_gitignore +6 -0
  36. package/template-assets/bootstrap/skills/airjam-docs-workflow/SKILL.md +49 -0
  37. package/template-assets/bootstrap/skills/airjam-mcp/SKILL.md +56 -0
  38. package/template-assets/bootstrap/skills/canvas-2d-gameplay/SKILL.md +47 -0
  39. package/template-assets/bootstrap/skills/controller-ui/SKILL.md +69 -0
  40. package/template-assets/bootstrap/skills/debug-and-test/SKILL.md +72 -0
  41. package/template-assets/bootstrap/skills/game-architecture/SKILL.md +58 -0
  42. package/template-assets/bootstrap/skills/game-state-and-rendering/SKILL.md +44 -0
  43. package/template-assets/bootstrap/skills/host-surface/SKILL.md +52 -0
  44. package/template-assets/bootstrap/skills/index.md +36 -0
  45. package/template-assets/bootstrap/skills/prefab-authoring/SKILL.md +48 -0
  46. package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +51 -0
  47. package/template-assets/documentation/for-agents/controller-ui/page.mdx +60 -0
  48. package/template-assets/documentation/for-agents/page.mdx +98 -0
  49. package/template-assets/documentation/for-agents/project-structure/page.mdx +172 -0
  50. package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +79 -0
  51. package/template-assets/documentation/getting-started/debugging/page.mdx +165 -0
  52. package/template-assets/documentation/getting-started/dev-logs/page.mdx +171 -0
  53. package/template-assets/documentation/getting-started/game-ideas/page.mdx +116 -0
  54. package/template-assets/documentation/getting-started/introduction/page.mdx +183 -0
  55. package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +427 -0
  56. package/template-assets/documentation/getting-started/quick-start/page.mdx +333 -0
  57. package/template-assets/documentation/how-it-works/architecture/page.mdx +189 -0
  58. package/template-assets/documentation/how-it-works/host-system/page.mdx +267 -0
  59. package/template-assets/documentation/manifest.json +430 -0
  60. package/template-assets/documentation/sdk/hooks/page.mdx +500 -0
  61. package/template-assets/documentation/sdk/input-system/page.mdx +270 -0
  62. package/template-assets/documentation/sdk/networked-state/page.mdx +213 -0
  63. package/template-assets/documentation/sdk/ui-components/page.mdx +227 -0
  64. package/template-assets/managed/.airjam/ai-pack.json +191 -0
  65. package/template-assets/managed/docs/airjam/agent-gold-path.md +67 -0
  66. package/template-assets/managed/docs/airjam/agent-mcp.md +135 -0
  67. package/template-assets/managed/docs/airjam/canvas-2d-gameplay.md +82 -0
  68. package/template-assets/managed/docs/airjam/composition-shell-contract.md +87 -0
  69. package/template-assets/managed/docs/airjam/debug-and-testing.md +86 -0
  70. package/template-assets/managed/docs/airjam/development-loop.md +51 -0
  71. package/template-assets/managed/docs/airjam/docs-index.md +58 -0
  72. package/template-assets/managed/docs/airjam/generated/architecture.md +178 -0
  73. package/template-assets/managed/docs/airjam/generated/controller-ui.md +61 -0
  74. package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +164 -0
  75. package/template-assets/managed/docs/airjam/generated/for-agents.md +99 -0
  76. package/template-assets/managed/docs/airjam/generated/game-ideas.md +107 -0
  77. package/template-assets/managed/docs/airjam/generated/host-system.md +251 -0
  78. package/template-assets/managed/docs/airjam/generated/input-system.md +260 -0
  79. package/template-assets/managed/docs/airjam/generated/introduction.md +175 -0
  80. package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +426 -0
  81. package/template-assets/managed/docs/airjam/generated/networked-state.md +214 -0
  82. package/template-assets/managed/docs/airjam/generated/project-structure.md +171 -0
  83. package/template-assets/managed/docs/airjam/generated/quick-start.md +334 -0
  84. package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +490 -0
  85. package/template-assets/managed/docs/airjam/generated/state-and-rendering.md +80 -0
  86. package/template-assets/managed/docs/airjam/generated/ui-components.md +222 -0
  87. package/template-assets/managed/docs/airjam/generated/unified-dev-logs.md +170 -0
  88. package/template-assets/managed/docs/airjam/iconography.md +55 -0
  89. package/template-assets/managed/docs/airjam/prefab-authoring.md +112 -0
  90. package/template-assets/managed/docs/airjam/preview-controllers.md +126 -0
  91. package/template-assets/managed/docs/airjam/r3f-3d-scene.md +97 -0
  92. package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +106 -0
  93. package/template-assets/managed/docs/airjam/visual-system.md +103 -0
@@ -0,0 +1,107 @@
1
+ <!-- Generated from content/docs/getting-started/game-ideas/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/getting-started/game-ideas -->
3
+
4
+ # Game Ideas for Air Jam
5
+
6
+ A collection of game concepts that leverage Air Jam's unique architecture: **High-Frequency Input Streams** (Socket.IO) + **Reliable Shared State** (AirJam Store).
7
+
8
+ ---
9
+
10
+ ### Neon Tanks
11
+
12
+ - Top-down arena shooter (4-8 players)
13
+ - Dual stick controls: movement + turret aiming
14
+ - Tap to fire
15
+ - **Key Feature:** Demonstrates dual stick capability on touchscreen
16
+
17
+ ### Super Sumo Balls
18
+
19
+ - Rolling balls on tilting platform
20
+ - Use phone gyroscope/accelerometer to tilt
21
+ - Haptic feedback on collisions
22
+ - **Key Feature:** Phone sensors + haptic signals
23
+
24
+ ---
25
+
26
+ ### The Traitor (Among Us style)
27
+
28
+ - 8 players: 6 crew, 2 traitors
29
+ - Hidden roles shown only on phone
30
+ - Task minigames on controller
31
+ - Voting UI on phone
32
+ - **Key Feature:** Secret information per player (killer app for phone controllers)
33
+
34
+ ### Sketchy Business (Pictionary style)
35
+
36
+ - Draw prompts on phone canvas
37
+ - Drawings appear on TV
38
+ - **Key Feature:** Touchscreen as natural drawing pad
39
+
40
+ ### Quiz Show Royale
41
+
42
+ - Fastest finger first trivia
43
+ - Personalized feedback (green/red + vibration)
44
+ - **Key Feature:** Input timestamping for speed
45
+
46
+ ---
47
+
48
+ ### Starship Bridge Simulator
49
+
50
+ - 4 players with different roles
51
+ - Each player gets different UI on phone
52
+ - Asymmetrical gameplay
53
+ - **Key Feature:** Different React components per controller
54
+
55
+ ### Ghost Hunter
56
+
57
+ - 1 vs 3 asymmetrical gameplay
58
+ - Ghost sees minimap on phone only
59
+ - Hunters use joysticks on TV
60
+ - **Key Feature:** Private screen advantage
61
+
62
+ ---
63
+
64
+ ### Poker Night / Blackjack
65
+
66
+ - Private cards on phone
67
+ - Betting UI on phone
68
+ - Public table on TV
69
+ - **Key Feature:** Hidden information per player
70
+
71
+ ### Artillery Wars (Worms style)
72
+
73
+ - Turn-based tank battle
74
+ - Aiming interface on phone (angle/power sliders)
75
+ - Weapon selection on phone
76
+ - **Key Feature:** Complex menus on touchscreen
77
+
78
+ ---
79
+
80
+ ### The Crowd Pixel (r/place style)
81
+
82
+ - 50+ players
83
+ - Each controls a pixel/cursor
84
+ - Collaborative painting
85
+ - **Key Feature:** Tests scalability
86
+
87
+ ### Minority Report UI
88
+
89
+ - Phone as trackpad
90
+ - Gesture controls
91
+ - **Key Feature:** Phone as input device
92
+
93
+ ---
94
+
95
+ ## Key Mechanics Enabled
96
+
97
+ ```
98
+ | Mechanic | Example | Technical Feature |
99
+ |-------------------|-------------------|-----------------------------------------|
100
+ | Secret Roles | Mafia / Traitor | `useSharedState` (filter by `playerId`) |
101
+ | Private Inventory | RPG / Poker | Shared Store + React UI on Phone |
102
+ | Motion Steering | Racing / Rolling | Device Accelerometer → Input Stream |
103
+ | Fastest Finger | Quiz Show | Input Latching (Timestamps) |
104
+ | Physical Feedback | Fighting / Action | `host.sendSignal("HAPTIC")` |
105
+ | Drawing | Pictionary | Canvas API + Data Packet |
106
+ | Asymmetry | Ghost Hunter | Different Views per Role |
107
+ ```
@@ -0,0 +1,251 @@
1
+ <!-- Generated from content/docs/how-it-works/host-system/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/how-it-works/host-system -->
3
+
4
+ # Host System
5
+
6
+ The Air Jam host system manages game sessions and input routing. This page explains how hosts work in different modes and how input flows through the system.
7
+
8
+ ### Standalone Host
9
+
10
+ The simplest mode—your game connects directly to the Air Jam server.
11
+
12
+ **Usage:**
13
+
14
+ ```tsx filename="src/components/HostView.tsx"
15
+ import { useAirJamHost } from "@air-jam/sdk";
16
+ import { airjam } from "../airjam.config";
17
+
18
+ const HostShell = () => (
19
+ <airjam.Host
20
+ onPlayerJoin={(player) => spawnPlayer(player)}
21
+ onPlayerLeave={(id) => removePlayer(id)}
22
+ >
23
+ <HostView />
24
+ </airjam.Host>
25
+ );
26
+
27
+ const HostView = () => {
28
+ const host = useAirJamHost();
29
+
30
+ // Host receives all input directly
31
+ useFrame(() => {
32
+ host.players.forEach((p) => {
33
+ const input = host.getInput(p.id);
34
+ processInput(p.id, input);
35
+ });
36
+ });
37
+
38
+ return <GameCanvas />;
39
+ };
40
+ ```
41
+
42
+ ### Arcade Mode (Outer App + Embedded Game)
43
+
44
+ In arcade mode, the platform runs the outer Arcade app and your game runs as an embedded Air Jam host inside an iframe.
45
+
46
+ The important rule is:
47
+
48
+ 1. Arcade owns platform surface state
49
+ 2. your game owns gameplay state
50
+ 3. the server owns room membership, focus routing, and runtime invariants
51
+
52
+ ## Server-Authoritative Focus System
53
+
54
+ The server maintains authoritative control over which host receives controller inputs through a **focus** state:
55
+
56
+ ### Why Server-Authoritative?
57
+
58
+ 1. **Security** - Prevents rogue games from stealing input
59
+ 2. **Reliability** - Single source of truth for focus state
60
+ 3. **Consistency** - All controllers route to same host
61
+
62
+ This focus system does not replace the normal Air Jam model. It only decides which host currently receives controller input. Your game still uses the normal input lane, replicated state lane, and signal lane.
63
+
64
+ ### 1. Arcade Launch
65
+
66
+ ```
67
+ [Platform] [Server] [Controller]
68
+ │ │ │
69
+ │ host:createRoom │ │
70
+ │ { maxPlayers: 8 } │ │
71
+ │ ───────────────────────────▶│ │
72
+ │ │ │
73
+ │ ack: { ok, roomId: "ABCD" } │ │
74
+ │ ◀───────────────────────────│ │
75
+ │ │ │
76
+ │ Display QR Code │ │
77
+ │ with room code │ Scan QR Code │
78
+ │ │ ◀──────────────────────────│
79
+ │ │ │
80
+ │ │ controller:join │
81
+ │ │ ◀──────────────────────────│
82
+ │ │ │
83
+ │ server:controllerJoined │ server:welcome │
84
+ │ ◀───────────────────────────│ ──────────────────────────▶│
85
+ ```
86
+
87
+ ### 2. Game Launch
88
+
89
+ ```
90
+ [Arcade] [Server] [Your Game] [Controller]
91
+ │ │ │ │
92
+ │ system:launchGame │ │ │
93
+ │ ───────────────────▶│ │ │
94
+ │ │ │ │
95
+ │ ack: { launchCapability } │ │ │
96
+ │ ◀────────────────── │ │ │
97
+ │ │ │ │
98
+ │ Load iframe ───────────────────────────────▶│ │
99
+ │ │ │ │
100
+ │ │ host:joinAsChild │ │
101
+ │ │◀───────────────────── │ │
102
+ │ │ │ │
103
+ │ │ Focus → GAME │ │
104
+ │ │ │ │
105
+ │ │ Redirect controller │ │
106
+ │ │ ─────────────────────────────────────────▶│
107
+ │ │ │ │
108
+ │ │ │ Load game UI │
109
+ ```
110
+
111
+ ### 3. Active Gameplay
112
+
113
+ With focus set to `GAME`, all controller input routes to your game:
114
+
115
+ ```tsx
116
+ // Your game receives input normally inside the mounted host runtime.
117
+ const host = useAirJamHost();
118
+
119
+ useFrame(() => {
120
+ host.players.forEach((player) => {
121
+ const input = host.getInput(player.id);
122
+ // Process gameplay...
123
+ });
124
+ });
125
+ ```
126
+
127
+ ### 4. Game Exit
128
+
129
+ ```
130
+ [Your Game] [Server] [Arcade] [Controller]
131
+ │ │ │ │
132
+ │ host:exit │ │ │
133
+ │ ───────────────────▶│ │ │
134
+ │ │ │ │
135
+ │ │ Focus → SYSTEM │ │
136
+ │ │ │ │
137
+ │ │ server:gameEnded │ │
138
+ │ │ ─────────────────────▶│ │
139
+ │ │ │ │
140
+ │ Destroy iframe ◀────────────── │ │
141
+ │ │ │ │
142
+ │ │ Restore arcade UI │ │
143
+ │ │ ─────────────────────────────────────────▶│
144
+ ```
145
+
146
+ ### Standalone Mode
147
+
148
+ ```tsx
149
+ <airjam.Host roomId="GAME">
150
+ <HostView />
151
+ </airjam.Host>;
152
+
153
+ // Inside HostView:
154
+ const host = useAirJamHost();
155
+ // host.roomId contains the room code
156
+ // host.joinUrl contains full URL for QR code
157
+ ```
158
+
159
+ Production bootstrap remains automatic here:
160
+
161
+ 1. local dev: no auth ceremony
162
+ 2. static deploy: SDK bootstraps with your `appId`
163
+ 3. optional signed mode: SDK fetches a host grant from `hostGrantEndpoint` before bootstrap
164
+
165
+ Game code does not change between those modes.
166
+
167
+ ### Embedded Game Mode (Arcade)
168
+
169
+ ```tsx
170
+ // SDK auto-detects embedded runtime context from platform-injected params.
171
+ // Game code should not parse those params directly.
172
+ const host = useAirJamHost();
173
+
174
+ // Embedded close/lifecycle handling is owned by the arcade platform adapter.
175
+ // Game hosts should keep gameplay logic in host callbacks/input loops only.
176
+ ```
177
+
178
+ ### Player Lifecycle
179
+
180
+ ```tsx
181
+ const HostShell = () => (
182
+ <airjam.Host
183
+ onPlayerJoin={(player) => {
184
+ // player.id - Unique identifier
185
+ // player.label - Display name ("Player 1", etc.)
186
+ // player.color - Assigned color ("#FF5733")
187
+ // player.nickname - Optional custom name
188
+ spawnPlayerEntity(player);
189
+ announceJoin(player.label);
190
+ }}
191
+ onPlayerLeave={(controllerId) => {
192
+ removePlayerEntity(controllerId);
193
+ }}
194
+ >
195
+ <HostView />
196
+ </airjam.Host>
197
+ );
198
+ ```
199
+
200
+ ### Accessing Players
201
+
202
+ ```tsx
203
+ // Current player list
204
+ host.players.forEach((player) => {
205
+ console.log(player.label, player.color);
206
+ });
207
+
208
+ // Player count
209
+ const playerCount = host.players.length;
210
+
211
+ // Find specific player
212
+ const player = host.players.find((p) => p.id === targetId);
213
+ ```
214
+
215
+ ## Controller Presentation State
216
+
217
+ Use `sendState` for lightweight controller presentation metadata, not
218
+ authoritative gameplay sync. Networked stores should own the real multiplayer
219
+ state; this path is for controller-facing hints such as orientation, pause/play
220
+ status, and short messages.
221
+
222
+ ```tsx
223
+ // Update controller presentation
224
+ host.sendState({
225
+ runtimeState: "playing", // "playing" | "paused"
226
+ orientation: "landscape", // "portrait" | "landscape"
227
+ message: "Round 3 - Fight!",
228
+ });
229
+
230
+ // Controllers receive via onState callback
231
+ // or controller.runtimeState / controller.controllerOrientation / controller.stateMessage
232
+ ```
233
+
234
+ ## Error Handling
235
+
236
+ ```tsx
237
+ const host = useAirJamHost();
238
+
239
+ // Check connection
240
+ if (host.connectionStatus === "disconnected") {
241
+ showReconnectUI();
242
+ }
243
+
244
+ // Check for errors
245
+ if (host.lastError) {
246
+ showError(host.lastError);
247
+ }
248
+
249
+ // Force reconnection
250
+ host.reconnect();
251
+ ```
@@ -0,0 +1,260 @@
1
+ <!-- Generated from content/docs/sdk/input-system/page.mdx. Do not edit directly. -->
2
+ <!-- Canonical public doc: https://airjam.io/docs/sdk/input-system -->
3
+
4
+ # Input System
5
+
6
+ The Air Jam input system provides type-safe, validated controller input with clear behavior semantics.
7
+
8
+ ## Configuration
9
+
10
+ Configure input in your canonical Air Jam app setup:
11
+
12
+ ```tsx filename="src/airjam.config.ts"
13
+ import { createAirJamApp, env } from "@air-jam/sdk";
14
+ import { z } from "zod";
15
+
16
+ const gameInputSchema = z.object({
17
+ vector: z.object({ x: z.number(), y: z.number() }),
18
+ action: z.boolean(),
19
+ ability: z.boolean(),
20
+ timestamp: z.number(),
21
+ });
22
+
23
+ type GameInput = z.infer<typeof gameInputSchema>;
24
+
25
+ export const airjam = createAirJamApp({
26
+ runtime: env.vite(import.meta.env),
27
+ controllerPath: "/controller",
28
+ input: {
29
+ schema: gameInputSchema,
30
+ },
31
+ });
32
+ ```
33
+
34
+ ## Default Behavior (No Extra Config)
35
+
36
+ Without any `input.behavior` overrides:
37
+
38
+ - booleans use `pulse` (tap-safe consume-on-read)
39
+ - vectors use `latest` (continuous current value)
40
+ - all other fields use `latest`
41
+
42
+ This default is the canonical path for most games.
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
+ },
60
+ });
61
+ ```
62
+
63
+ Behavior modes:
64
+
65
+ - `pulse`: consume-on-read, ideal for one-shot actions (jump/fire/confirm)
66
+ - `latest`: current value only, ideal for movement sticks
67
+ - `hold`: vectors keep last non-zero direction until next non-zero value
68
+
69
+ ## Migration From `latch`
70
+
71
+ Old config:
72
+
73
+ ```tsx
74
+ input: {
75
+ schema: gameInputSchema,
76
+ latch: {
77
+ booleanFields: ["action"],
78
+ vectorFields: ["vector"],
79
+ },
80
+ }
81
+ ```
82
+
83
+ New config:
84
+
85
+ ```tsx
86
+ input: {
87
+ schema: gameInputSchema,
88
+ behavior: {
89
+ pulse: ["action"],
90
+ latest: ["vector"],
91
+ },
92
+ }
93
+ ```
94
+
95
+ For most games, remove the override entirely and keep `input: { schema }`.
96
+
97
+ ## Schema Validation
98
+
99
+ When you provide a Zod schema, incoming input is validated before your game reads it.
100
+
101
+ ```tsx
102
+ // ✅ valid input
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
122
+
123
+ ### Main Host Loop
124
+
125
+ This example uses the starter host surface path.
126
+ Treat it as a recommended default, not a required filename.
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
+ };
151
+ ```
152
+
153
+ ### Performance-Critical Components
154
+
155
+ Use `useGetInput()` to avoid store-driven re-renders:
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
+ ```
174
+
175
+ ## Controller Cadence
176
+
177
+ Use `useInputWriter()` with `useControllerTick()` for fixed-cadence publishing:
178
+
179
+ This example uses the starter controller surface path.
180
+ It assumes your app has already mounted `airjam.Controller` above this view.
181
+
182
+ ```tsx filename="src/controller/index.tsx"
183
+ import {
184
+ useAirJamController,
185
+ useControllerTick,
186
+ useInputWriter,
187
+ } from "@air-jam/sdk";
188
+ import { useRef } from "react";
189
+
190
+ const ControllerView = () => {
191
+ const controller = useAirJamController();
192
+ const writeInput = useInputWriter();
193
+ const directionRef = useRef(0);
194
+
195
+ useControllerTick(
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
224
+
225
+ ```tsx filename="src/components/Player.tsx"
226
+ const input = getInput(playerId);
227
+ if (!input) return;
228
+
229
+ movePlayer(input.vector);
230
+ ```
231
+
232
+ ### 4. Include Timestamps for Advanced Physics
233
+
234
+ ```tsx filename="src/game/types.ts"
235
+ const inputSchema = z.object({
236
+ vector: z.object({ x: z.number(), y: z.number() }),
237
+ action: z.boolean(),
238
+ timestamp: z.number(),
239
+ });
240
+
241
+ const inputAge = Date.now() - input.timestamp;
242
+ ```
243
+
244
+ ### Input Not Received
245
+
246
+ 1. Check host connection status (`connected`)
247
+ 2. Verify room code matches on host and controller
248
+ 3. Check schema warnings in console (`[InputManager] Invalid input ...`)
249
+
250
+ ### Input Feels Laggy
251
+
252
+ 1. Use `useGetInput()` inside game objects
253
+ 2. Verify your controller tick cadence (typically `16ms`)
254
+ 3. Check network latency (include timestamps in schema)
255
+
256
+ ### Buttons Feel Unreliable
257
+
258
+ 1. Confirm the field is boolean in your schema
259
+ 2. Keep default behavior (`pulse`) for action buttons
260
+ 3. Avoid dispatching button presses through store actions