@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,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
# Networked State
|
|
4
2
|
|
|
5
3
|
`createAirJamStore` is the canonical shared-state lane for Air Jam:
|
|
@@ -10,17 +8,63 @@
|
|
|
10
8
|
|
|
11
9
|
Use this lane for replicated game state, not per-frame input.
|
|
12
10
|
|
|
11
|
+
A store is a plain object from `@air-jam/sdk/core`, so game logic can use it
|
|
12
|
+
without React. Components read it with `useAirJamStore`.
|
|
13
|
+
|
|
14
|
+
## Private per-player state
|
|
15
|
+
|
|
16
|
+
A store can declare one `privateField`: a map keyed by `controllerId`. Use it for
|
|
17
|
+
hidden hands, roles or shopping lists. The host keeps every entry. The room's
|
|
18
|
+
public state broadcast never contains this field; each phone receives only its
|
|
19
|
+
own entry through targeted delivery, including after a reconnect.
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { createAirJamStore } from "@air-jam/sdk/core";
|
|
23
|
+
import { useAirJamPrivateState } from "@air-jam/sdk";
|
|
24
|
+
|
|
25
|
+
type MarketState = {
|
|
26
|
+
round: number;
|
|
27
|
+
secrets: Record<string, { shoppingList: string[] }>;
|
|
28
|
+
actions: {};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const marketStore = createAirJamStore<MarketState, "secrets">(
|
|
32
|
+
() => ({ round: 1, secrets: {}, actions: {} }),
|
|
33
|
+
{ privateField: "secrets" },
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
function ShoppingList() {
|
|
37
|
+
const ownEntry = useAirJamPrivateState(marketStore);
|
|
38
|
+
return <p>{ownEntry?.shoppingList.join(", ") ?? "Waiting for your list"}</p>;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
When supplying an explicit state type, name the private field as the second type
|
|
43
|
+
argument so the hook infers that entry even when the store has other maps.
|
|
44
|
+
Declare this store in the game just like a public store. The hook returns
|
|
45
|
+
`undefined` until this controller's entry arrives, and when the host removes it.
|
|
46
|
+
Host actions update the map normally. Only changed entries are sent; public-only
|
|
47
|
+
changes do not resend private data. Embedded controllers use the same private
|
|
48
|
+
lane through their MessagePort bridge.
|
|
49
|
+
|
|
50
|
+
Agent `projectSnapshot` receives the public fields and a private map containing
|
|
51
|
+
only the requested controller's entry (an empty map without a controller).
|
|
52
|
+
Host-authority `rawStores` and host restore retain the whole map. Keep private
|
|
53
|
+
values out of other public fields and explicitly author any end-of-round reveal.
|
|
54
|
+
Private state derives from the replicated store, so headless runs and replays use
|
|
55
|
+
the same authoritative state; it is not a separate RPC or an encrypted channel.
|
|
56
|
+
|
|
13
57
|
## Canonical Action Model
|
|
14
58
|
|
|
15
59
|
Actions always use this shape on the host:
|
|
16
60
|
|
|
17
|
-
1. First argument: `ctx` (identity and
|
|
61
|
+
1. First argument: `ctx` (identity, role, connected players and game time `now`)
|
|
18
62
|
2. Second argument: `payload` (either `undefined` or one typed plain-object payload)
|
|
19
63
|
|
|
20
|
-
|
|
64
|
+
Dispatch always goes through the store's `actions`:
|
|
21
65
|
|
|
22
|
-
1. `
|
|
23
|
-
2. `
|
|
66
|
+
1. `gameStore.actions.someAction()`
|
|
67
|
+
2. `gameStore.actions.someAction({ ...payload })`
|
|
24
68
|
|
|
25
69
|
No trailing `controllerId` arguments and no multi-argument action payloads.
|
|
26
70
|
No primitive, array, or event-like root payloads.
|
|
@@ -31,7 +75,7 @@ This example uses a starter-friendly `stores/` folder shape.
|
|
|
31
75
|
The important contract is the action model and ownership boundary, not the exact filename.
|
|
32
76
|
|
|
33
77
|
```tsx filename="src/game/stores/game-store.ts"
|
|
34
|
-
import { createAirJamStore } from "@air-jam/sdk";
|
|
78
|
+
import { createAirJamStore, type AirJamActionContext } from "@air-jam/sdk/core";
|
|
35
79
|
|
|
36
80
|
type Team = "team1" | "team2";
|
|
37
81
|
|
|
@@ -40,22 +84,16 @@ interface GameState {
|
|
|
40
84
|
teamAssignments: Record<string, Team>;
|
|
41
85
|
scores: { team1: number; team2: number };
|
|
42
86
|
actions: {
|
|
43
|
-
joinTeam: (
|
|
44
|
-
|
|
45
|
-
payload: { team: Team },
|
|
46
|
-
) => void;
|
|
47
|
-
scorePoint: (
|
|
48
|
-
_ctx: { actorId: string; role: "controller" | "host" },
|
|
49
|
-
payload: { team: Team },
|
|
50
|
-
) => void;
|
|
87
|
+
joinTeam: (ctx: AirJamActionContext, payload: { team: Team }) => void;
|
|
88
|
+
scorePoint: (ctx: AirJamActionContext, payload: { team: Team }) => void;
|
|
51
89
|
setPhase: (
|
|
52
|
-
|
|
90
|
+
ctx: AirJamActionContext,
|
|
53
91
|
payload: { phase: "lobby" | "playing" },
|
|
54
92
|
) => void;
|
|
55
93
|
};
|
|
56
94
|
}
|
|
57
95
|
|
|
58
|
-
export const
|
|
96
|
+
export const gameStore = createAirJamStore<GameState>((set) => ({
|
|
59
97
|
phase: "lobby",
|
|
60
98
|
teamAssignments: {},
|
|
61
99
|
scores: { team1: 0, team2: 0 },
|
|
@@ -79,19 +117,51 @@ export const useGameStore = createAirJamStore<GameState>((set) => ({
|
|
|
79
117
|
}));
|
|
80
118
|
```
|
|
81
119
|
|
|
120
|
+
## Declare the Store
|
|
121
|
+
|
|
122
|
+
The host and controllers sync a store only when the app declares it:
|
|
123
|
+
|
|
124
|
+
```ts filename="src/airjam.config.ts"
|
|
125
|
+
import { defineAirJamGame } from "@air-jam/sdk/core";
|
|
126
|
+
import { gameStore } from "./game/stores/game-store";
|
|
127
|
+
|
|
128
|
+
export const airjam = defineAirJamGame({
|
|
129
|
+
metadata: {
|
|
130
|
+
slug: "space-game",
|
|
131
|
+
name: "Space Game",
|
|
132
|
+
tagline: "Fly together and defend the fleet.",
|
|
133
|
+
category: "arcade",
|
|
134
|
+
minPlayers: 1,
|
|
135
|
+
maxPlayers: 4,
|
|
136
|
+
inputModalities: ["buttons", "touch"],
|
|
137
|
+
supportedSdkRange: "^1.0.0",
|
|
138
|
+
maintainer: { name: "Air Jam" },
|
|
139
|
+
version: 1,
|
|
140
|
+
},
|
|
141
|
+
controllerPath: "/controller",
|
|
142
|
+
stores: [gameStore],
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
A declared store syncs for as long as the host or controller runs, whether or
|
|
147
|
+
not any component is reading it. Reading a store the app does not declare
|
|
148
|
+
throws `AJ_STORE_NOT_DECLARED`.
|
|
149
|
+
|
|
82
150
|
## Use on Controller
|
|
83
151
|
|
|
84
152
|
This controller example matches the starter template surface layout.
|
|
85
153
|
It assumes your app has already mounted `airjam.Controller`.
|
|
86
154
|
|
|
87
155
|
```tsx filename="src/controller/index.tsx"
|
|
88
|
-
import { useAirJamController } from "@air-jam/sdk";
|
|
89
|
-
import {
|
|
156
|
+
import { useAirJamController, useAirJamStore } from "@air-jam/sdk";
|
|
157
|
+
import { gameStore } from "../game/stores/game-store";
|
|
90
158
|
|
|
91
159
|
export const ControllerView = () => {
|
|
92
160
|
const controller = useAirJamController();
|
|
93
|
-
const
|
|
94
|
-
|
|
161
|
+
const teamAssignments = useAirJamStore(
|
|
162
|
+
gameStore,
|
|
163
|
+
(state) => state.teamAssignments,
|
|
164
|
+
);
|
|
95
165
|
|
|
96
166
|
const myTeam = controller.controllerId
|
|
97
167
|
? teamAssignments[controller.controllerId]
|
|
@@ -100,7 +170,7 @@ export const ControllerView = () => {
|
|
|
100
170
|
return (
|
|
101
171
|
<div>
|
|
102
172
|
<p>My team: {myTeam ?? "unassigned"}</p>
|
|
103
|
-
<button onClick={() => actions.joinTeam({ team: "team1" })}>
|
|
173
|
+
<button onClick={() => gameStore.actions.joinTeam({ team: "team1" })}>
|
|
104
174
|
Join Team 1
|
|
105
175
|
</button>
|
|
106
176
|
</div>
|
|
@@ -114,12 +184,12 @@ This host example also matches the starter template surface layout.
|
|
|
114
184
|
It assumes your app has already mounted `airjam.Host`.
|
|
115
185
|
|
|
116
186
|
```tsx filename="src/host/index.tsx"
|
|
117
|
-
import {
|
|
187
|
+
import { useAirJamStore } from "@air-jam/sdk";
|
|
188
|
+
import { gameStore } from "../game/stores/game-store";
|
|
118
189
|
|
|
119
190
|
export const HostView = () => {
|
|
120
|
-
const phase =
|
|
121
|
-
const scores =
|
|
122
|
-
const actions = useGameStore.useActions();
|
|
191
|
+
const phase = useAirJamStore(gameStore, (state) => state.phase);
|
|
192
|
+
const scores = useAirJamStore(gameStore, (state) => state.scores);
|
|
123
193
|
|
|
124
194
|
return (
|
|
125
195
|
<div>
|
|
@@ -127,10 +197,10 @@ export const HostView = () => {
|
|
|
127
197
|
<p>
|
|
128
198
|
{scores.team1} - {scores.team2}
|
|
129
199
|
</p>
|
|
130
|
-
<button onClick={() => actions.setPhase({ phase: "playing" })}>
|
|
200
|
+
<button onClick={() => gameStore.actions.setPhase({ phase: "playing" })}>
|
|
131
201
|
Start
|
|
132
202
|
</button>
|
|
133
|
-
<button onClick={() => actions.scorePoint({ team: "team1" })}>
|
|
203
|
+
<button onClick={() => gameStore.actions.scorePoint({ team: "team1" })}>
|
|
134
204
|
Team 1 +1
|
|
135
205
|
</button>
|
|
136
206
|
</div>
|
|
@@ -141,24 +211,29 @@ export const HostView = () => {
|
|
|
141
211
|
## Action Flow
|
|
142
212
|
|
|
143
213
|
1. Controller calls `actions.someAction()` or `actions.someAction({ ...payload })`.
|
|
144
|
-
2.
|
|
145
|
-
3.
|
|
146
|
-
4. Host
|
|
147
|
-
5. Host
|
|
148
|
-
|
|
214
|
+
2. The phone's session sends a request on the store's channel.
|
|
215
|
+
3. The room stamps it with the phone's seat, which becomes `ctx.actorId`.
|
|
216
|
+
4. Host executes action handler `(ctx, payload)`, updates state and answers.
|
|
217
|
+
5. Host publishes what changed; the room keeps the latest copy and sends each
|
|
218
|
+
phone the change, with only its own private entry.
|
|
219
|
+
6. If the phone's connection drops before the answer arrives, the action
|
|
220
|
+
resolves `unconfirmed`: it may or may not have run, and the state the phone
|
|
221
|
+
mirrors shows which.
|
|
149
222
|
|
|
150
223
|
## Rules
|
|
151
224
|
|
|
152
225
|
1. Keep all networked mutations inside `actions`.
|
|
153
|
-
2. Always dispatch via `
|
|
226
|
+
2. Always dispatch via `store.actions`; do not call `store.getState().actions.*` directly.
|
|
154
227
|
3. Use one payload object per action for stable evolution.
|
|
155
228
|
4. Root payloads must be omitted or plain objects.
|
|
156
229
|
5. `T | undefined` payload unions are not valid roots. If an action has no payload, omit it entirely.
|
|
157
230
|
6. Nested values must stay RPC-serializable.
|
|
158
231
|
7. Use `ctx.actorId` for identity-aware actions (team join, ownership, etc.).
|
|
159
|
-
8. `ctx.actorId` is always the dispatcher identity. If host code dispatches through `
|
|
160
|
-
9.
|
|
161
|
-
10.
|
|
232
|
+
8. `ctx.actorId` is always the dispatcher identity. If host code dispatches through `store.actions`, then `ctx.actorId` is the host.
|
|
233
|
+
9. Read time as `ctx.now`, never `Date.now()`: it is game time, the simulation's when the game declares one, so headless runs and replays see the same time. Store deadlines in it and let the simulation act on them; phones show what the host writes to the store, such as whole seconds left, because they cannot read the host's clock.
|
|
234
|
+
10. If the host intentionally needs to run the same semantic player action as controller `X`, use `store.asPlayer("X")` instead of inventing a target payload for an actor-owned action.
|
|
235
|
+
11. Keep per-frame gameplay input in declared controls, read in simulation steps, not in this store.
|
|
236
|
+
12. For a host-only side effect of an action, such as a sound, use `useHostActionListener(store, listener)`.
|
|
162
237
|
|
|
163
238
|
## Accept And Reject Examples
|
|
164
239
|
|
|
@@ -171,21 +246,24 @@ import {
|
|
|
171
246
|
acceptAirJamAction,
|
|
172
247
|
createAirJamStore,
|
|
173
248
|
rejectAirJamAction,
|
|
174
|
-
} from "@air-jam/sdk";
|
|
249
|
+
} from "@air-jam/sdk/core";
|
|
175
250
|
|
|
176
|
-
export const
|
|
251
|
+
export const gameStore = createAirJamStore((set, get) => ({
|
|
177
252
|
aliveByPlayerId: {} as Record<string, boolean>,
|
|
178
253
|
cooldownMsByPlayerId: {} as Record<string, number>,
|
|
179
254
|
actions: {
|
|
180
|
-
fire: ({ actorId }) =>
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
255
|
+
fire: ({ actorId }) => {
|
|
256
|
+
if (!actorId || get().aliveByPlayerId[actorId] === false)
|
|
257
|
+
return rejectAirJamAction("player_dead", "Dead players cannot fire.");
|
|
258
|
+
const cooldownMs = 4500;
|
|
259
|
+
set((state) => ({
|
|
260
|
+
cooldownMsByPlayerId: {
|
|
261
|
+
...state.cooldownMsByPlayerId,
|
|
262
|
+
[actorId]: cooldownMs,
|
|
263
|
+
},
|
|
264
|
+
}));
|
|
265
|
+
return acceptAirJamAction({ cooldownMs });
|
|
266
|
+
},
|
|
189
267
|
},
|
|
190
268
|
}));
|
|
191
269
|
```
|
|
@@ -204,10 +282,14 @@ The SDK/runtime automatically resolves the correct replicated store domain from
|
|
|
204
282
|
|
|
205
283
|
## API Summary
|
|
206
284
|
|
|
207
|
-
`createAirJamStore<T>(initializer)` returns
|
|
285
|
+
`createAirJamStore<T>(initializer)` from `@air-jam/sdk/core` returns a store to
|
|
286
|
+
declare in `defineAirJamGame({ stores })`. It provides:
|
|
287
|
+
|
|
288
|
+
1. `actions`, dispatching with `() => Promise` or `(payloadObject) => Promise` signatures.
|
|
289
|
+
2. `getState()` and `subscribe()` for logic outside React.
|
|
290
|
+
3. `asPlayer(controllerId)`, a host-only dispatch map for explicit player impersonation of semantic actions.
|
|
208
291
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
3. `asPlayer(controllerId)` host-only dispatch map for explicit player impersonation of semantic actions.
|
|
292
|
+
React reads it with `useAirJamStore(store, selector)` and listens to host-applied
|
|
293
|
+
actions with `useHostActionListener(store, listener)`.
|
|
212
294
|
|
|
213
295
|
`T` must include an `actions` object with host handlers `(ctx, payload) => void`, where `payload` is `undefined` or a plain object.
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Game Settings
|
|
2
|
+
|
|
3
|
+
Declare the numbers, switches and choices a creator tunes while playtesting in
|
|
4
|
+
`airjam.config.ts`. The host owns their values and revision. A live update takes
|
|
5
|
+
effect between simulation steps and is recorded for exact replay. While a
|
|
6
|
+
simulation declared as a loader is still loading, updates are refused, so a
|
|
7
|
+
replay starts from the settings the simulation was created with.
|
|
8
|
+
|
|
9
|
+
## Declare settings in core
|
|
10
|
+
|
|
11
|
+
Keep the declaration in a leaf module so the simulation can import its type
|
|
12
|
+
without importing the game config back again.
|
|
13
|
+
|
|
14
|
+
```ts filename="src/game/contracts/settings.ts"
|
|
15
|
+
import {
|
|
16
|
+
defineAirJamSettings,
|
|
17
|
+
setting,
|
|
18
|
+
type AirJamSettingsValues,
|
|
19
|
+
} from "@air-jam/sdk/core";
|
|
20
|
+
|
|
21
|
+
export const pongSettings = defineAirJamSettings({
|
|
22
|
+
ballSpeed: setting.number({
|
|
23
|
+
default: 360,
|
|
24
|
+
min: 180,
|
|
25
|
+
max: 720,
|
|
26
|
+
step: 10,
|
|
27
|
+
live: true,
|
|
28
|
+
description: "Ball speed in pixels per second.",
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
export type PongSettings = AirJamSettingsValues<typeof pongSettings>;
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Pass it as `defineAirJamGame({ settings: pongSettings, ... })`. Remove the
|
|
35
|
+
module constants it replaces. A lobby choice players make, such as
|
|
36
|
+
`pointsToWin`, remains replicated store state.
|
|
37
|
+
|
|
38
|
+
Keys are lower camel case. `setting.number` requires `default`, `min` and
|
|
39
|
+
`max`, with an optional positive `step`; use `step: 1` for whole numbers.
|
|
40
|
+
Steps are multiples of zero. `setting.boolean` requires a boolean `default`.
|
|
41
|
+
`setting.choice` takes a nonempty string tuple in `options` and a `default`
|
|
42
|
+
from that tuple; its value type is the union of those strings.
|
|
43
|
+
Every kind accepts `description` and `live`, which defaults to false.
|
|
44
|
+
`defineAirJamSettings` validates defaults immediately. The description returned
|
|
45
|
+
by `airjam.inspect_game` includes these descriptors in `declaration.settings`.
|
|
46
|
+
|
|
47
|
+
## Read the current values
|
|
48
|
+
|
|
49
|
+
Use the settings type as the fourth simulation type parameter:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
defineAirJamSimulation<State, Input, Event, PongSettings>({
|
|
53
|
+
stepMs: 1000 / 60,
|
|
54
|
+
create: ({ settings }) => createState(settings.ballSpeed),
|
|
55
|
+
step: (state, { settings, stepMs }) => {
|
|
56
|
+
state.x += (settings.ballSpeed * stepMs) / 1000;
|
|
57
|
+
},
|
|
58
|
+
observe: (state, { settings }) => ({
|
|
59
|
+
x: state.x,
|
|
60
|
+
ballSpeed: settings.ballSpeed,
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Store actions read the same values through
|
|
66
|
+
`AirJamActionContext<PongSettings>.settings`. Host rendering calls
|
|
67
|
+
`useAirJamSettings(pongSettings)` from `@air-jam/sdk`; the hook subscribes to
|
|
68
|
+
the host runtime and returns the typed values. Controllers have no settings
|
|
69
|
+
hook. Copy any value a phone must display into replicated store state.
|
|
70
|
+
|
|
71
|
+
## Set initial values and tune a live room
|
|
72
|
+
|
|
73
|
+
`HostRuntimeOptions.settings` accepts a partial set of initial values and fills
|
|
74
|
+
the rest from defaults. `airjam.start_game_run` accepts the same `settings`
|
|
75
|
+
object when creating a new room, for browser and headless runs. Initial values
|
|
76
|
+
may include non-live settings. They are fixed for the host's lifetime.
|
|
77
|
+
|
|
78
|
+
Open a game session with host authority, then call:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"tool": "airjam.read_game_settings",
|
|
83
|
+
"arguments": { "gameSessionId": "<session id>" }
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The result contains `values` and `revision`, initially zero. Update using that
|
|
88
|
+
revision:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"tool": "airjam.update_game_settings",
|
|
93
|
+
"arguments": {
|
|
94
|
+
"gameSessionId": "<session id>",
|
|
95
|
+
"patch": { "ballSpeed": 700 },
|
|
96
|
+
"expectedRevision": 0
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
A successful update returns the complete values and the next revision. The
|
|
102
|
+
whole patch is validated before any value changes. Both tools have the same
|
|
103
|
+
host authority requirements as semantic host actions. The runtime contract is
|
|
104
|
+
`settings-read` with `{ roomId, runtimeId }`, and `settings-update` with those
|
|
105
|
+
fields plus `patch` and `expectedRevision`.
|
|
106
|
+
|
|
107
|
+
The CLI uses the same operations:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
pnpm exec airjam session settings-read <session-id>
|
|
111
|
+
pnpm exec airjam session settings-update <session-id> --patch '{"ballSpeed":700}' --expected-revision 0
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Both commands print JSON. Use `airjam run start --settings '{"ballSpeed":600}'` with the other required
|
|
115
|
+
run options to start a fresh room at a chosen speed. Attaching a run to an
|
|
116
|
+
existing room does not replace its initial settings.
|
|
117
|
+
|
|
118
|
+
## Errors and replay
|
|
119
|
+
|
|
120
|
+
`AJ_SETTING_UNKNOWN` names an undeclared key. `AJ_SETTING_INVALID` means a
|
|
121
|
+
value violates its type, range, step or choices. `AJ_SETTING_STALE` means
|
|
122
|
+
another update changed the revision; read again before applying a new patch.
|
|
123
|
+
`AJ_SETTING_NOT_LIVE` means the setting requires a new room with that initial
|
|
124
|
+
value. Rejected updates leave all values and the revision unchanged.
|
|
125
|
+
|
|
126
|
+
Input logs use `version: 3`, with resolved initial `settings` and ordered
|
|
127
|
+
`settings` events containing each accepted `patch` and `revision`.
|
|
128
|
+
They share the stream with inputs and actions. `replayAirJamInputLog` creates
|
|
129
|
+
the host with the initial values and applies each update in order before its
|
|
130
|
+
recorded step. Use the same seed and game code to reproduce the final state.
|
|
131
|
+
|
|
132
|
+
## Keeping a value
|
|
133
|
+
|
|
134
|
+
A live change lasts for the current room. To make a chosen value the default for
|
|
135
|
+
future rooms and test runs, keep it in the game's declaration:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
pnpm exec airjam game settings keep --set ballSpeed=400 --json
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Use `--dir <game>` from another directory, and repeat `--set` for several values.
|
|
142
|
+
The command requires the game's own `typescript` dependency and rewrites only
|
|
143
|
+
literal `default:` values in the selected `defineAirJamSettings({...})`, even
|
|
144
|
+
when it is imported from another game module. Imported settings must resolve to
|
|
145
|
+
one `const` directly initialized by `defineAirJamSettings`; named and default
|
|
146
|
+
exports and explicit re-export aliases are resolved to that binding. Mutable or
|
|
147
|
+
ambiguous bindings are refused. The config must export the `defineAirJamGame`
|
|
148
|
+
binding as `airjam`, so an unused game declaration is never selected. Comments
|
|
149
|
+
and formatting stay in
|
|
150
|
+
place; the declaration remains the only source of defaults. Commit the change
|
|
151
|
+
as ordinary game source. Shared or computed defaults, ambiguous declarations,
|
|
152
|
+
unknown keys and values outside their declared type, range, step or options are
|
|
153
|
+
refused before writing. The JSON result names the file and each `{ key, from,
|
|
154
|
+
to }`; equal values write nothing. Studio's Keep operation uses this same
|
|
155
|
+
transform and captures the source change in history.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
# SDK UI Components
|
|
4
2
|
|
|
5
3
|
`@air-jam/sdk` is headless by default. `@air-jam/sdk/ui` provides optional, composable UI primitives you can drop into your own game layout.
|
|
@@ -97,6 +95,8 @@ Use it for:
|
|
|
97
95
|
|
|
98
96
|
### `SurfaceViewport`
|
|
99
97
|
|
|
98
|
+
A game whose `inputModalities` include `'joystick'` always gets a landscape controller; the SDK applies it, so do not set orientation; lay it out with `GamepadLayout` from `@air-jam/sdk/ui`: the stick under the left thumb, the actions under the right in a square the same size, and only short status between them.
|
|
99
|
+
|
|
100
100
|
Own safe-area, orientation, and page-level UI scaling for a game surface.
|
|
101
101
|
It should fill the available screen while scaling the UI system proportionally, rather than letterboxing a fixed contained stage.
|
|
102
102
|
Internally it publishes a local `--airjam-ui-scale` into Tailwind's own spacing, text, radius, and container variables so normal Tailwind utilities keep working.
|
|
@@ -104,7 +104,7 @@ Internally it publishes a local `--airjam-ui-scale` into Tailwind's own spacing,
|
|
|
104
104
|
```tsx
|
|
105
105
|
import { SurfaceViewport } from "@air-jam/sdk/ui";
|
|
106
106
|
|
|
107
|
-
<SurfaceViewport
|
|
107
|
+
<SurfaceViewport className="bg-zinc-950">
|
|
108
108
|
<ControllerView />
|
|
109
109
|
</SurfaceViewport>;
|
|
110
110
|
```
|
|
@@ -162,6 +162,47 @@ Use it for:
|
|
|
162
162
|
|
|
163
163
|
---
|
|
164
164
|
|
|
165
|
+
## Phone Controls
|
|
166
|
+
|
|
167
|
+
`ControlButton`, `AxisButton` and `Stick` bind phone UI to the game's declared
|
|
168
|
+
controls and send them; see [Input System](/docs/sdk/input-system).
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { AxisButton, ControlButton, Stick } from "@air-jam/sdk/ui";
|
|
172
|
+
|
|
173
|
+
<Stick control={shipInput.move} knobClassName="bg-white/30" />
|
|
174
|
+
<AxisButton control={pongInput.direction} value={-1}>Up</AxisButton>
|
|
175
|
+
<ControlButton control={shipInput.fire} className="data-[active=true]:ring-2">
|
|
176
|
+
Fire
|
|
177
|
+
</ControlButton>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Each sets `data-active` while held. `Stick` takes `directions="4-way"`,
|
|
181
|
+
`deadzone`, `knob`, `knobClassName`, and a function child that draws the whole
|
|
182
|
+
stick from `{ value, active }`.
|
|
183
|
+
|
|
184
|
+
### `GamepadLayout`
|
|
185
|
+
|
|
186
|
+
Lays out a sideways controller like a gamepad: `left` and `right` thumb
|
|
187
|
+
squares of the same size, sized from the phone's short side and mirrored about
|
|
188
|
+
the centre, with a compact `center` column between them. `right` holds one
|
|
189
|
+
action, or several as a cluster around the main one. It fills its parent, so
|
|
190
|
+
put a header above it. See [Controller UI](/docs/for-agents/controller-ui#sideways-controllers).
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
import { ControlButton, GamepadLayout, Stick } from "@air-jam/sdk/ui";
|
|
194
|
+
|
|
195
|
+
<GamepadLayout
|
|
196
|
+
left={<Stick control={gameInput.move} className="rounded-full bg-white/10" />}
|
|
197
|
+
center={<span className="text-xs uppercase">Round 1</span>}
|
|
198
|
+
right={
|
|
199
|
+
<ControlButton control={gameInput.action} className="rounded-full">
|
|
200
|
+
Go
|
|
201
|
+
</ControlButton>
|
|
202
|
+
}
|
|
203
|
+
/>;
|
|
204
|
+
```
|
|
205
|
+
|
|
165
206
|
## Base Primitives
|
|
166
207
|
|
|
167
208
|
### `Button`
|
|
@@ -222,6 +263,6 @@ Combine:
|
|
|
222
263
|
|
|
223
264
|
## Anti-Patterns
|
|
224
265
|
|
|
225
|
-
- Do not build gameplay input on
|
|
266
|
+
- Do not build gameplay input on `Button`; bind controls with `ControlButton`, `AxisButton` and `Stick`.
|
|
226
267
|
- Do not rely on UI primitives for room/session lifecycle; lifecycle stays in headless SDK hooks.
|
|
227
268
|
- Do not fork component behavior in each game if composition solves it; prefer small wrappers around canonical primitives.
|