@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.
- package/LICENSE +21 -0
- package/README.md +145 -2
- package/bin/airjam.mjs +66 -0
- package/dist/ai-pack.d.ts +44 -0
- package/dist/ai-pack.js +15 -0
- package/dist/ai-pack.js.map +1 -0
- package/dist/chunk-A4V2N4LX.js +938 -0
- package/dist/chunk-A4V2N4LX.js.map +1 -0
- package/dist/chunk-J5MAU4QZ.js +102 -0
- package/dist/chunk-J5MAU4QZ.js.map +1 -0
- package/dist/chunk-N7AI7HZK.js +529 -0
- package/dist/chunk-N7AI7HZK.js.map +1 -0
- package/dist/development.d.ts +98 -0
- package/dist/development.js +33 -0
- package/dist/development.js.map +1 -0
- package/dist/documentation.d.ts +27 -0
- package/dist/documentation.js +7 -0
- package/dist/documentation.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2184 -0
- package/dist/index.js.map +1 -0
- package/dist/scaffold.d.ts +6 -0
- package/dist/scaffold.js +20 -0
- package/dist/scaffold.js.map +1 -0
- package/package.json +78 -3
- package/runtime/local-network.d.mts +8 -0
- package/runtime/local-network.mjs +9 -0
- package/runtime/vite-config.d.mts +42 -0
- package/runtime/vite-config.mjs +130 -0
- package/runtime/vite-https.d.mts +11 -0
- package/runtime/vite-https.mjs +41 -0
- package/template-assets/bootstrap/.claude/launch.json +12 -0
- package/template-assets/bootstrap/AGENTS.md +248 -0
- package/template-assets/bootstrap/CLAUDE.md +63 -0
- package/template-assets/bootstrap/_gitignore +6 -0
- package/template-assets/bootstrap/skills/airjam-docs-workflow/SKILL.md +49 -0
- package/template-assets/bootstrap/skills/airjam-mcp/SKILL.md +56 -0
- package/template-assets/bootstrap/skills/canvas-2d-gameplay/SKILL.md +47 -0
- package/template-assets/bootstrap/skills/controller-ui/SKILL.md +69 -0
- package/template-assets/bootstrap/skills/debug-and-test/SKILL.md +72 -0
- package/template-assets/bootstrap/skills/game-architecture/SKILL.md +58 -0
- package/template-assets/bootstrap/skills/game-state-and-rendering/SKILL.md +44 -0
- package/template-assets/bootstrap/skills/host-surface/SKILL.md +52 -0
- package/template-assets/bootstrap/skills/index.md +36 -0
- package/template-assets/bootstrap/skills/prefab-authoring/SKILL.md +48 -0
- package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +51 -0
- package/template-assets/documentation/for-agents/controller-ui/page.mdx +60 -0
- package/template-assets/documentation/for-agents/page.mdx +98 -0
- package/template-assets/documentation/for-agents/project-structure/page.mdx +172 -0
- package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +79 -0
- package/template-assets/documentation/getting-started/debugging/page.mdx +165 -0
- package/template-assets/documentation/getting-started/dev-logs/page.mdx +171 -0
- package/template-assets/documentation/getting-started/game-ideas/page.mdx +116 -0
- package/template-assets/documentation/getting-started/introduction/page.mdx +183 -0
- package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +427 -0
- package/template-assets/documentation/getting-started/quick-start/page.mdx +333 -0
- package/template-assets/documentation/how-it-works/architecture/page.mdx +189 -0
- package/template-assets/documentation/how-it-works/host-system/page.mdx +267 -0
- package/template-assets/documentation/manifest.json +430 -0
- package/template-assets/documentation/sdk/hooks/page.mdx +500 -0
- package/template-assets/documentation/sdk/input-system/page.mdx +270 -0
- package/template-assets/documentation/sdk/networked-state/page.mdx +213 -0
- package/template-assets/documentation/sdk/ui-components/page.mdx +227 -0
- package/template-assets/managed/.airjam/ai-pack.json +191 -0
- package/template-assets/managed/docs/airjam/agent-gold-path.md +67 -0
- package/template-assets/managed/docs/airjam/agent-mcp.md +135 -0
- package/template-assets/managed/docs/airjam/canvas-2d-gameplay.md +82 -0
- package/template-assets/managed/docs/airjam/composition-shell-contract.md +87 -0
- package/template-assets/managed/docs/airjam/debug-and-testing.md +86 -0
- package/template-assets/managed/docs/airjam/development-loop.md +51 -0
- package/template-assets/managed/docs/airjam/docs-index.md +58 -0
- package/template-assets/managed/docs/airjam/generated/architecture.md +178 -0
- package/template-assets/managed/docs/airjam/generated/controller-ui.md +61 -0
- package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +164 -0
- package/template-assets/managed/docs/airjam/generated/for-agents.md +99 -0
- package/template-assets/managed/docs/airjam/generated/game-ideas.md +107 -0
- package/template-assets/managed/docs/airjam/generated/host-system.md +251 -0
- package/template-assets/managed/docs/airjam/generated/input-system.md +260 -0
- package/template-assets/managed/docs/airjam/generated/introduction.md +175 -0
- package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +426 -0
- package/template-assets/managed/docs/airjam/generated/networked-state.md +214 -0
- package/template-assets/managed/docs/airjam/generated/project-structure.md +171 -0
- package/template-assets/managed/docs/airjam/generated/quick-start.md +334 -0
- package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +490 -0
- package/template-assets/managed/docs/airjam/generated/state-and-rendering.md +80 -0
- package/template-assets/managed/docs/airjam/generated/ui-components.md +222 -0
- package/template-assets/managed/docs/airjam/generated/unified-dev-logs.md +170 -0
- package/template-assets/managed/docs/airjam/iconography.md +55 -0
- package/template-assets/managed/docs/airjam/prefab-authoring.md +112 -0
- package/template-assets/managed/docs/airjam/preview-controllers.md +126 -0
- package/template-assets/managed/docs/airjam/r3f-3d-scene.md +97 -0
- package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +106 -0
- package/template-assets/managed/docs/airjam/visual-system.md +103 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
<!-- Generated from content/docs/getting-started/introduction/page.mdx. Do not edit directly. -->
|
|
2
|
+
<!-- Canonical public doc: https://airjam.io/docs/getting-started/introduction -->
|
|
3
|
+
|
|
4
|
+
# Introduction
|
|
5
|
+
|
|
6
|
+
Air Jam is an open **AI-native framework for multiplayer games controlled by
|
|
7
|
+
phones**. A computer or TV acts as the host display, smartphones become the
|
|
8
|
+
controllers, and both humans and coding agents build against the same runtime,
|
|
9
|
+
input, state, and release model.
|
|
10
|
+
|
|
11
|
+
## Key Features
|
|
12
|
+
|
|
13
|
+
- **Zero App Download**: Players join by scanning a QR code—no app store required
|
|
14
|
+
- **Instant Multiplayer**: Seamlessly connect up to 8 smartphones as controllers
|
|
15
|
+
- **Developer Friendly**: Built with modern web technologies (React, TypeScript)
|
|
16
|
+
- **AI-Native By Design**: Humans and agents share explicit contracts for runtime, input, logs, and release workflows
|
|
17
|
+
- **Type Safe**: End-to-end type safety with Zod schema validation
|
|
18
|
+
- **Performance Optimized**: Tap-safe button input with fixed tick cadence
|
|
19
|
+
- **Haptic Feedback**: Send vibration patterns to controllers for game events
|
|
20
|
+
|
|
21
|
+
### 1. Install the SDK
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add @air-jam/sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### 2. Wrap Your App
|
|
28
|
+
|
|
29
|
+
```tsx filename="src/app.tsx"
|
|
30
|
+
import { airjam } from "./airjam.config";
|
|
31
|
+
|
|
32
|
+
export const App = () => (
|
|
33
|
+
<Routes>
|
|
34
|
+
<Route
|
|
35
|
+
path="/"
|
|
36
|
+
element={
|
|
37
|
+
<airjam.Host
|
|
38
|
+
onPlayerJoin={(player) => {
|
|
39
|
+
console.log(`${player.label} joined!`);
|
|
40
|
+
}}
|
|
41
|
+
onPlayerLeave={(id) => {
|
|
42
|
+
console.log(`Player ${id} left`);
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
<HostView />
|
|
46
|
+
</airjam.Host>
|
|
47
|
+
}
|
|
48
|
+
/>
|
|
49
|
+
<Route
|
|
50
|
+
path={airjam.paths.controller}
|
|
51
|
+
element={
|
|
52
|
+
<airjam.Controller>
|
|
53
|
+
<ControllerView />
|
|
54
|
+
</airjam.Controller>
|
|
55
|
+
}
|
|
56
|
+
/>
|
|
57
|
+
</Routes>
|
|
58
|
+
);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```tsx filename="src/airjam.config.ts"
|
|
62
|
+
import { createAirJamApp, env } from "@air-jam/sdk";
|
|
63
|
+
import { z } from "zod";
|
|
64
|
+
|
|
65
|
+
const gameInputSchema = z.object({
|
|
66
|
+
direction: z.number().min(-1).max(1),
|
|
67
|
+
action: z.boolean(),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const airjam = createAirJamApp({
|
|
71
|
+
runtime: env.vite(import.meta.env),
|
|
72
|
+
controllerPath: "/controller",
|
|
73
|
+
input: { schema: gameInputSchema },
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 3. Create Your Host View
|
|
78
|
+
|
|
79
|
+
The path below matches the current starter template layout.
|
|
80
|
+
It is a good default, not a required framework filename.
|
|
81
|
+
|
|
82
|
+
```tsx filename="src/host/index.tsx"
|
|
83
|
+
import { useAirJamHost } from "@air-jam/sdk";
|
|
84
|
+
|
|
85
|
+
const HostView = () => {
|
|
86
|
+
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
|
+
// });
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<div className="relative min-h-screen bg-black text-white">
|
|
99
|
+
<header className="absolute top-0 right-0 left-0 z-10 flex items-center justify-between border-b border-white/10 bg-black/70 px-4 py-2 backdrop-blur">
|
|
100
|
+
<span>Room {host.roomId}</span>
|
|
101
|
+
<button
|
|
102
|
+
onClick={
|
|
103
|
+
host.runtimeState === "playing"
|
|
104
|
+
? host.pauseRuntime
|
|
105
|
+
: host.resumeRuntime
|
|
106
|
+
}
|
|
107
|
+
>
|
|
108
|
+
{host.runtimeState === "playing" ? "Pause" : "Resume"}
|
|
109
|
+
</button>
|
|
110
|
+
</header>
|
|
111
|
+
<GameCanvas />
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Mount host ownership once at `<airjam.Host ...>`, then use `useAirJamHost()` only as a consumer hook inside that boundary.
|
|
118
|
+
|
|
119
|
+
### 4. Create Your Controller View
|
|
120
|
+
|
|
121
|
+
The path below also matches the current starter template layout.
|
|
122
|
+
If your project uses a different file shape, keep the same ownership boundary even if the filename changes.
|
|
123
|
+
|
|
124
|
+
```tsx filename="src/controller/index.tsx"
|
|
125
|
+
import {
|
|
126
|
+
useAirJamController,
|
|
127
|
+
useControllerTick,
|
|
128
|
+
useInputWriter,
|
|
129
|
+
} from "@air-jam/sdk";
|
|
130
|
+
import { useRef } from "react";
|
|
131
|
+
|
|
132
|
+
const ControllerView = () => {
|
|
133
|
+
const controller = useAirJamController();
|
|
134
|
+
const writeInput = useInputWriter();
|
|
135
|
+
const directionRef = useRef(0);
|
|
136
|
+
|
|
137
|
+
useControllerTick(
|
|
138
|
+
() => {
|
|
139
|
+
writeInput({
|
|
140
|
+
direction: directionRef.current,
|
|
141
|
+
action: false,
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
enabled:
|
|
146
|
+
controller.connectionStatus === "connected" &&
|
|
147
|
+
controller.runtimeState === "playing",
|
|
148
|
+
intervalMs: 16,
|
|
149
|
+
},
|
|
150
|
+
);
|
|
151
|
+
};
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Canonical Architecture: Three Lanes
|
|
155
|
+
|
|
156
|
+
Use one lane per concern:
|
|
157
|
+
|
|
158
|
+
1. **Input lane**: `useControllerTick` + `useInputWriter` (controller), `getInput` / `useGetInput` (host).
|
|
159
|
+
2. **State lane**: `createAirJamStore` with host-owned actions and `useActions()` dispatch.
|
|
160
|
+
3. **Signal lane**: `sendSignal` / system commands for out-of-band UX and runtime commands.
|
|
161
|
+
|
|
162
|
+
Arcade does not replace this model. Arcade is an Air Jam app around another
|
|
163
|
+
Air Jam app, so the same lane rules still apply in embedded runtime mode.
|
|
164
|
+
|
|
165
|
+
Avoid cross-lane misuse:
|
|
166
|
+
|
|
167
|
+
1. Don’t stream per-frame movement through store actions.
|
|
168
|
+
2. Don’t encode authoritative gameplay state in signals.
|
|
169
|
+
3. Don’t call `state.actions.*`; use `useActions()` only.
|
|
170
|
+
|
|
171
|
+
## Next Steps
|
|
172
|
+
|
|
173
|
+
- [Architecture](./architecture.md) - Understand the system design
|
|
174
|
+
- [Hooks Reference](./sdk-hooks.md) - Complete API documentation
|
|
175
|
+
- [Input System](./input-system.md) - Learn about input behavior and validation
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
<!-- Generated from content/docs/getting-started/migrating-legacy-games/page.mdx. Do not edit directly. -->
|
|
2
|
+
<!-- Canonical public doc: https://airjam.io/docs/getting-started/migrating-legacy-games -->
|
|
3
|
+
|
|
4
|
+
# Migrating Legacy Games
|
|
5
|
+
|
|
6
|
+
This guide is for older Air Jam games that still use the pre-v1 app shape.
|
|
7
|
+
|
|
8
|
+
If you are starting fresh, use [Quick Start](./quick-start.md) instead.
|
|
9
|
+
|
|
10
|
+
If you are using an LLM to help with the migration, copy this guide into the
|
|
11
|
+
conversation first. Codex or Claude are the best fit for this kind of
|
|
12
|
+
repo-wide migration work.
|
|
13
|
+
|
|
14
|
+
## When You Need This Guide
|
|
15
|
+
|
|
16
|
+
You are likely on the old shape if your game still has some of these patterns:
|
|
17
|
+
|
|
18
|
+
- `AirJamProvider` in `App.tsx`
|
|
19
|
+
- flat files like `src/host-view.tsx`, `src/controller-view.tsx`, and `src/store.ts`
|
|
20
|
+
- `HostShell` / `ControllerShell`
|
|
21
|
+
- old store actions like `joinTeam(team, playerId?)`
|
|
22
|
+
- controller code that calls `controller.sendInput(...)` directly in a loop
|
|
23
|
+
|
|
24
|
+
The v1 goal is not “make old code barely compile”.
|
|
25
|
+
|
|
26
|
+
The goal is:
|
|
27
|
+
|
|
28
|
+
1. move to the canonical v1 runtime shape
|
|
29
|
+
2. keep boundaries clean between runtime, replicated state, and game logic
|
|
30
|
+
3. remove old shell/provider assumptions instead of carrying them forward
|
|
31
|
+
|
|
32
|
+
## Prerelease Local Migration Note
|
|
33
|
+
|
|
34
|
+
If you are migrating an old game against a local unreleased Air Jam workspace before packages are published, keep the setup split clean:
|
|
35
|
+
|
|
36
|
+
1. install `@air-jam/sdk` from the local package or a local tarball
|
|
37
|
+
2. do not depend on `@air-jam/server` through a direct `file:` package reference if it still carries monorepo-only `workspace:*` internals
|
|
38
|
+
3. for prerelease local dev, resolve `air-jam-server` from your nearby Air Jam workspace checkout or use tarballs once you are doing package validation
|
|
39
|
+
|
|
40
|
+
This is only a prerelease migration concern. The release goal is published packages or tarball validation, not permanent cross-repo path coupling.
|
|
41
|
+
|
|
42
|
+
## The Target Shape
|
|
43
|
+
|
|
44
|
+
The current canonical app shape looks like this:
|
|
45
|
+
|
|
46
|
+
```text
|
|
47
|
+
src/
|
|
48
|
+
airjam.config.ts
|
|
49
|
+
app.tsx
|
|
50
|
+
routes/
|
|
51
|
+
host-view.tsx
|
|
52
|
+
controller-view.tsx
|
|
53
|
+
game/
|
|
54
|
+
input.ts
|
|
55
|
+
store.ts
|
|
56
|
+
...
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Not every migrated game must match that exact folder tree.
|
|
60
|
+
|
|
61
|
+
What matters is the boundary model:
|
|
62
|
+
|
|
63
|
+
1. `createAirJamApp(...)` defines runtime and input config
|
|
64
|
+
2. `app.tsx` owns route-level `<airjam.Host>` and `<airjam.Controller>` wrappers
|
|
65
|
+
3. host/controller runtime owner hooks mount only in those route entry files
|
|
66
|
+
4. replicated state uses the current `createAirJamStore` action contract
|
|
67
|
+
5. host-local simulation stays separate from replicated store state
|
|
68
|
+
|
|
69
|
+
## Migration Checklist
|
|
70
|
+
|
|
71
|
+
Use this order. Do not jump around randomly.
|
|
72
|
+
|
|
73
|
+
1. Replace `AirJamProvider` bootstrap with `createAirJamApp`
|
|
74
|
+
2. Move host/controller ownership into route wrappers
|
|
75
|
+
3. Migrate replicated store actions to `(ctx, payload)`
|
|
76
|
+
4. Remove `HostShell` / `ControllerShell`
|
|
77
|
+
5. Decide what belongs in replicated store state versus host-local simulation
|
|
78
|
+
6. Modernize controller input only if the game actually has continuous input
|
|
79
|
+
7. Clean up old shell/theme workarounds and dead legacy branches
|
|
80
|
+
8. Re-run local validation before changing game behavior
|
|
81
|
+
|
|
82
|
+
## Step 1: Move Runtime Setup Into `airjam.config.ts`
|
|
83
|
+
|
|
84
|
+
Old shape:
|
|
85
|
+
|
|
86
|
+
```tsx filename="src/App.tsx"
|
|
87
|
+
import { AirJamProvider } from "@air-jam/sdk";
|
|
88
|
+
import { gameInputSchema } from "./types";
|
|
89
|
+
|
|
90
|
+
export function App() {
|
|
91
|
+
return (
|
|
92
|
+
<AirJamProvider
|
|
93
|
+
serverUrl={import.meta.env.VITE_AIR_JAM_SERVER_URL}
|
|
94
|
+
publicHost={import.meta.env.VITE_AIR_JAM_PUBLIC_HOST}
|
|
95
|
+
input={{
|
|
96
|
+
schema: gameInputSchema,
|
|
97
|
+
latch: {
|
|
98
|
+
booleanFields: ["action"],
|
|
99
|
+
},
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
...
|
|
103
|
+
</AirJamProvider>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Target shape:
|
|
109
|
+
|
|
110
|
+
```tsx filename="src/airjam.config.ts"
|
|
111
|
+
import { createAirJamApp, env } from "@air-jam/sdk";
|
|
112
|
+
import { gameInputSchema } from "./game/input";
|
|
113
|
+
|
|
114
|
+
export const airjam = createAirJamApp({
|
|
115
|
+
runtime: env.vite(import.meta.env),
|
|
116
|
+
controllerPath: "/controller",
|
|
117
|
+
input: {
|
|
118
|
+
schema: gameInputSchema,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
This removes runtime wiring noise from your app tree and gives you one canonical config surface.
|
|
124
|
+
|
|
125
|
+
## Step 2: Move Host And Controller Ownership Into `app.tsx`
|
|
126
|
+
|
|
127
|
+
Old shape:
|
|
128
|
+
|
|
129
|
+
```tsx filename="src/App.tsx"
|
|
130
|
+
<Routes>
|
|
131
|
+
<Route path="/" element={<HostView />} />
|
|
132
|
+
<Route path="/controller" element={<ControllerView />} />
|
|
133
|
+
</Routes>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Target shape:
|
|
137
|
+
|
|
138
|
+
```tsx filename="src/app.tsx"
|
|
139
|
+
import { Route, Routes } from "react-router-dom";
|
|
140
|
+
import { airjam } from "./airjam.config";
|
|
141
|
+
|
|
142
|
+
export function App() {
|
|
143
|
+
return (
|
|
144
|
+
<Routes>
|
|
145
|
+
<Route
|
|
146
|
+
path="/"
|
|
147
|
+
element={
|
|
148
|
+
<airjam.Host>
|
|
149
|
+
<HostView />
|
|
150
|
+
</airjam.Host>
|
|
151
|
+
}
|
|
152
|
+
/>
|
|
153
|
+
<Route
|
|
154
|
+
path={airjam.paths.controller}
|
|
155
|
+
element={
|
|
156
|
+
<airjam.Controller>
|
|
157
|
+
<ControllerView />
|
|
158
|
+
</airjam.Controller>
|
|
159
|
+
}
|
|
160
|
+
/>
|
|
161
|
+
</Routes>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
This is the runtime boundary. Keep it explicit.
|
|
167
|
+
|
|
168
|
+
## Step 3: Fix Store Actions First
|
|
169
|
+
|
|
170
|
+
This is the most important migration after bootstrap.
|
|
171
|
+
|
|
172
|
+
Old actions often looked like this:
|
|
173
|
+
|
|
174
|
+
```tsx filename="src/store.ts"
|
|
175
|
+
actions: {
|
|
176
|
+
joinTeam: (team, playerId) => {
|
|
177
|
+
if (!playerId) return;
|
|
178
|
+
...
|
|
179
|
+
},
|
|
180
|
+
setReady: (ready, playerId) => {
|
|
181
|
+
if (!playerId) return;
|
|
182
|
+
...
|
|
183
|
+
},
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The current action model is:
|
|
188
|
+
|
|
189
|
+
The `src/game/stores/game-store.ts` path below is a starter-friendly example.
|
|
190
|
+
If your project already uses a different store module layout, keep the same action contract and ownership rules while migrating.
|
|
191
|
+
|
|
192
|
+
```tsx filename="src/game/stores/game-store.ts"
|
|
193
|
+
actions: {
|
|
194
|
+
joinTeam: ({ actorId, connectedPlayerIds }, { team }) =>
|
|
195
|
+
set((state) => {
|
|
196
|
+
if (!actorId) return state;
|
|
197
|
+
...
|
|
198
|
+
}),
|
|
199
|
+
|
|
200
|
+
setReady: ({ actorId }, { ready }) =>
|
|
201
|
+
set((state) => {
|
|
202
|
+
if (!actorId) return state;
|
|
203
|
+
...
|
|
204
|
+
}),
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Controller-side dispatch should always look like:
|
|
209
|
+
|
|
210
|
+
```tsx filename="src/routes/controller-view.tsx"
|
|
211
|
+
const actions = useGameStore.useActions();
|
|
212
|
+
|
|
213
|
+
actions.joinTeam({ team: "team1" });
|
|
214
|
+
actions.setReady({ ready: true });
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Do not keep trailing `playerId` arguments around.
|
|
218
|
+
|
|
219
|
+
For the full store model, see [Networked State](./networked-state.md).
|
|
220
|
+
|
|
221
|
+
## Step 4: Remove `HostShell` And `ControllerShell`
|
|
222
|
+
|
|
223
|
+
Treat the old shell components as migration targets, not as permanent app structure.
|
|
224
|
+
|
|
225
|
+
Why:
|
|
226
|
+
|
|
227
|
+
1. they hide app-owned layout inside generic wrappers
|
|
228
|
+
2. they can leak presentational concerns into the app
|
|
229
|
+
3. they make theme and layout cleanup harder than it should be
|
|
230
|
+
|
|
231
|
+
Use app-owned layout instead.
|
|
232
|
+
|
|
233
|
+
If you still need a narrow layout helper, use one intentionally, for example `SurfaceViewport` for shared full-screen controller or host UI scaling.
|
|
234
|
+
|
|
235
|
+
Do not rebuild your app around a generic shell.
|
|
236
|
+
|
|
237
|
+
## Step 5: Choose The Right Migration Branch
|
|
238
|
+
|
|
239
|
+
Not every legacy game should be migrated the same way.
|
|
240
|
+
|
|
241
|
+
### Branch A: Flat Legacy App
|
|
242
|
+
|
|
243
|
+
If your app still looks like:
|
|
244
|
+
|
|
245
|
+
```text
|
|
246
|
+
src/
|
|
247
|
+
App.tsx
|
|
248
|
+
host-view.tsx
|
|
249
|
+
controller-view.tsx
|
|
250
|
+
store.ts
|
|
251
|
+
types.ts
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
then do the full cleanup:
|
|
255
|
+
|
|
256
|
+
1. add `src/airjam.config.ts`
|
|
257
|
+
2. rename to `src/app.tsx`
|
|
258
|
+
3. move runtime entry files to `src/routes/`
|
|
259
|
+
4. move input/store/domain files into `src/game/`
|
|
260
|
+
|
|
261
|
+
This is the cleanest migration for older minimal apps.
|
|
262
|
+
|
|
263
|
+
### Branch B: Already Modular Legacy App
|
|
264
|
+
|
|
265
|
+
If your app already has good structure like:
|
|
266
|
+
|
|
267
|
+
```text
|
|
268
|
+
src/
|
|
269
|
+
features/
|
|
270
|
+
store/
|
|
271
|
+
hooks/
|
|
272
|
+
components/
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
then do not force a cosmetic rewrite just to match a template.
|
|
276
|
+
|
|
277
|
+
Instead:
|
|
278
|
+
|
|
279
|
+
1. modernize bootstrap and route ownership
|
|
280
|
+
2. modernize the store action contract
|
|
281
|
+
3. keep healthy feature/domain modules mostly where they are
|
|
282
|
+
|
|
283
|
+
The migration guide is about boundaries, not folder cosplay.
|
|
284
|
+
|
|
285
|
+
### Branch C: Host-Simulation-Heavy App
|
|
286
|
+
|
|
287
|
+
If most of the game logic lives in a host-side hook or engine module, keep that boundary explicit:
|
|
288
|
+
|
|
289
|
+
1. replicated store state owns shared, synchronized state
|
|
290
|
+
2. host-local hook/engine owns timers, refs, physics, media loading, and simulation details
|
|
291
|
+
3. only the minimum necessary state should cross between them
|
|
292
|
+
|
|
293
|
+
This is usually cleaner than trying to stuff the whole game loop into the replicated store.
|
|
294
|
+
|
|
295
|
+
## Step 6: Migrate Input Based On Input Type
|
|
296
|
+
|
|
297
|
+
Do not overgeneralize input migration.
|
|
298
|
+
|
|
299
|
+
### Continuous Input Games
|
|
300
|
+
|
|
301
|
+
If your controller sends directional or analog-style input every frame, prefer:
|
|
302
|
+
|
|
303
|
+
1. local refs/state
|
|
304
|
+
2. `useInputWriter()`
|
|
305
|
+
3. `useControllerTick(...)`
|
|
306
|
+
|
|
307
|
+
Example:
|
|
308
|
+
|
|
309
|
+
```tsx filename="src/routes/controller-view.tsx"
|
|
310
|
+
import {
|
|
311
|
+
useAirJamController,
|
|
312
|
+
useControllerTick,
|
|
313
|
+
useInputWriter,
|
|
314
|
+
} from "@air-jam/sdk";
|
|
315
|
+
import { useRef } from "react";
|
|
316
|
+
|
|
317
|
+
export function ControllerView() {
|
|
318
|
+
const controller = useAirJamController();
|
|
319
|
+
const writeInput = useInputWriter();
|
|
320
|
+
const movementRef = useRef({ x: 0, y: 0 });
|
|
321
|
+
const actionRef = useRef(false);
|
|
322
|
+
|
|
323
|
+
useControllerTick(
|
|
324
|
+
() => {
|
|
325
|
+
writeInput({
|
|
326
|
+
movementX: movementRef.current.x,
|
|
327
|
+
movementY: movementRef.current.y,
|
|
328
|
+
action: actionRef.current,
|
|
329
|
+
});
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
enabled:
|
|
333
|
+
controller.connectionStatus === "connected" &&
|
|
334
|
+
controller.runtimeState === "playing",
|
|
335
|
+
intervalMs: 16,
|
|
336
|
+
},
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Action-Only Or Choice-Driven Games
|
|
342
|
+
|
|
343
|
+
If the controller mainly sends taps, choices, or store actions, do not add per-frame input machinery just because another game needed it.
|
|
344
|
+
|
|
345
|
+
Use the simpler model that matches your game.
|
|
346
|
+
|
|
347
|
+
For more input details, see [Input System](./input-system.md).
|
|
348
|
+
|
|
349
|
+
## Step 7: Clean Up Old `latch` Usage Carefully
|
|
350
|
+
|
|
351
|
+
Older games may still configure input through `latch`.
|
|
352
|
+
|
|
353
|
+
For most games, the right migration is smaller than you think:
|
|
354
|
+
|
|
355
|
+
- move the schema into `airjam.config.ts`
|
|
356
|
+
- remove `latch` entirely
|
|
357
|
+
- keep the default input behavior unless you have a real non-default need
|
|
358
|
+
|
|
359
|
+
Only add `input.behavior` overrides when the defaults are not enough.
|
|
360
|
+
|
|
361
|
+
## Step 8: Remove Legacy Workarounds
|
|
362
|
+
|
|
363
|
+
After bootstrap, shell, and action migration, remove old hacks that only existed because of the old shape.
|
|
364
|
+
|
|
365
|
+
Common examples:
|
|
366
|
+
|
|
367
|
+
1. theme fixes that fight shell-injected classes
|
|
368
|
+
2. old child-mode or shell-mode presentation branches
|
|
369
|
+
3. duplicated route aliases like `/host` unless you truly still need them
|
|
370
|
+
4. stale README instructions that still describe the old app shape
|
|
371
|
+
|
|
372
|
+
This step matters. A migration is not complete if the old assumptions are still quietly shaping the code.
|
|
373
|
+
|
|
374
|
+
## Identity Rules To Recheck
|
|
375
|
+
|
|
376
|
+
During migration, be explicit about identity.
|
|
377
|
+
|
|
378
|
+
You should know:
|
|
379
|
+
|
|
380
|
+
1. what is the Air Jam controller/session identity
|
|
381
|
+
2. what is the in-game avatar or character identity
|
|
382
|
+
3. which store keys use which identity
|
|
383
|
+
|
|
384
|
+
Do not leave this implicit.
|
|
385
|
+
|
|
386
|
+
This becomes especially important when:
|
|
387
|
+
|
|
388
|
+
1. controllers are assigned to in-game characters
|
|
389
|
+
2. bots exist
|
|
390
|
+
3. host simulation uses different IDs than controller presence
|
|
391
|
+
|
|
392
|
+
## Validation Checklist
|
|
393
|
+
|
|
394
|
+
Before calling a migration done, verify:
|
|
395
|
+
|
|
396
|
+
1. host route boots cleanly with `<airjam.Host>`
|
|
397
|
+
2. controller route joins cleanly with `<airjam.Controller>`
|
|
398
|
+
3. store actions no longer rely on trailing `playerId` arguments
|
|
399
|
+
4. no child component mounts a second runtime owner hook
|
|
400
|
+
5. shell-removal cleanup is complete
|
|
401
|
+
6. README and local dev commands match the migrated app shape
|
|
402
|
+
7. `pnpm run typecheck`
|
|
403
|
+
8. `pnpm run build`
|
|
404
|
+
9. the game still behaves correctly in local host/controller play
|
|
405
|
+
|
|
406
|
+
## Recommended Order For Real Migrations
|
|
407
|
+
|
|
408
|
+
When migrating multiple games, do them in this order:
|
|
409
|
+
|
|
410
|
+
1. smallest flat app first
|
|
411
|
+
2. host-simulation-heavy app second
|
|
412
|
+
3. already-modular app third
|
|
413
|
+
|
|
414
|
+
That order usually sharpens the guide fastest:
|
|
415
|
+
|
|
416
|
+
1. first app proves the basic recipe
|
|
417
|
+
2. second app forces the harder boundary decisions
|
|
418
|
+
3. third app benefits from the refined guide and should migrate more cleanly
|
|
419
|
+
|
|
420
|
+
## Related Docs
|
|
421
|
+
|
|
422
|
+
1. [Quick Start](./quick-start.md)
|
|
423
|
+
2. [Debugging and Logs](./debugging-and-logs.md)
|
|
424
|
+
3. [Input System](./input-system.md)
|
|
425
|
+
4. [Networked State](./networked-state.md)
|
|
426
|
+
5. [Hooks](./sdk-hooks.md)
|