@air-jam/cli 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +273 -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/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-J5MAU4QZ.js +102 -0
- package/dist/chunk-J5MAU4QZ.js.map +1 -0
- package/dist/chunk-LH7UO57C.js +23 -0
- package/dist/chunk-LH7UO57C.js.map +1 -0
- package/dist/chunk-N7AI7HZK.js +529 -0
- package/dist/chunk-N7AI7HZK.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-U6V3HEBB.js +939 -0
- 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 +102 -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/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.d.ts +1 -0
- package/dist/index.js +2468 -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 +82 -3
- package/runtime/local-network.d.mts +6 -0
- package/runtime/local-network.mjs +9 -0
- package/runtime/public-assets.mjs +62 -0
- package/runtime/source-fence.mjs +182 -0
- package/runtime/vite-config.d.mts +43 -0
- package/runtime/vite-config.mjs +134 -0
- package/runtime/vite-dev.mjs +18 -0
- package/runtime/vite-https.d.mts +11 -0
- package/runtime/vite-https.mjs +40 -0
- package/template-assets/bootstrap/.claude/launch.json +12 -0
- package/template-assets/bootstrap/AGENTS.md +290 -0
- package/template-assets/bootstrap/CLAUDE.md +55 -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 +100 -0
- package/template-assets/bootstrap/skills/canvas-2d-gameplay/SKILL.md +47 -0
- package/template-assets/bootstrap/skills/controller-ui/SKILL.md +71 -0
- package/template-assets/bootstrap/skills/debug-and-test/SKILL.md +72 -0
- package/template-assets/bootstrap/skills/game-architecture/SKILL.md +102 -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 +58 -0
- package/template-assets/bootstrap/skills/r3f-3d-scene/SKILL.md +61 -0
- package/template-assets/documentation/for-agents/controller-ui/page.mdx +99 -0
- package/template-assets/documentation/for-agents/page.mdx +120 -0
- package/template-assets/documentation/for-agents/project-structure/page.mdx +170 -0
- package/template-assets/documentation/for-agents/state-and-rendering/page.mdx +77 -0
- package/template-assets/documentation/for-agents/supported-agents/page.mdx +18 -0
- package/template-assets/documentation/getting-started/debugging/page.mdx +164 -0
- package/template-assets/documentation/getting-started/dev-logs/page.mdx +169 -0
- package/template-assets/documentation/getting-started/game-ideas/page.mdx +114 -0
- package/template-assets/documentation/getting-started/introduction/page.mdx +200 -0
- package/template-assets/documentation/getting-started/migrating-legacy-games/page.mdx +673 -0
- package/template-assets/documentation/getting-started/quick-start/page.mdx +310 -0
- package/template-assets/documentation/how-it-works/architecture/page.mdx +230 -0
- package/template-assets/documentation/how-it-works/host-system/page.mdx +270 -0
- package/template-assets/documentation/manifest.json +500 -0
- package/template-assets/documentation/sdk/assets-and-theme/page.mdx +185 -0
- package/template-assets/documentation/sdk/hooks/page.mdx +435 -0
- package/template-assets/documentation/sdk/input-system/page.mdx +240 -0
- package/template-assets/documentation/sdk/networked-state/page.mdx +295 -0
- package/template-assets/documentation/sdk/settings/page.mdx +155 -0
- package/template-assets/documentation/sdk/ui-components/page.mdx +268 -0
- package/template-assets/managed/.airjam/ai-pack.json +209 -0
- package/template-assets/managed/docs/airjam/agent-gold-path.md +115 -0
- package/template-assets/managed/docs/airjam/agent-mcp.md +179 -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 +104 -0
- package/template-assets/managed/docs/airjam/development-loop.md +51 -0
- package/template-assets/managed/docs/airjam/docs-index.md +64 -0
- package/template-assets/managed/docs/airjam/generated/architecture.md +223 -0
- package/template-assets/managed/docs/airjam/generated/assets-and-theme.md +188 -0
- package/template-assets/managed/docs/airjam/generated/controller-ui.md +102 -0
- package/template-assets/managed/docs/airjam/generated/debugging-and-logs.md +165 -0
- package/template-assets/managed/docs/airjam/generated/for-agents.md +123 -0
- package/template-assets/managed/docs/airjam/generated/game-ideas.md +107 -0
- package/template-assets/managed/docs/airjam/generated/host-system.md +261 -0
- package/template-assets/managed/docs/airjam/generated/input-system.md +241 -0
- package/template-assets/managed/docs/airjam/generated/introduction.md +195 -0
- package/template-assets/managed/docs/airjam/generated/migrating-legacy-games.md +674 -0
- package/template-assets/managed/docs/airjam/generated/networked-state.md +298 -0
- package/template-assets/managed/docs/airjam/generated/project-structure.md +171 -0
- package/template-assets/managed/docs/airjam/generated/quick-start.md +311 -0
- package/template-assets/managed/docs/airjam/generated/sdk-hooks.md +430 -0
- package/template-assets/managed/docs/airjam/generated/settings.md +158 -0
- package/template-assets/managed/docs/airjam/generated/state-and-rendering.md +80 -0
- package/template-assets/managed/docs/airjam/generated/supported-agents.md +21 -0
- package/template-assets/managed/docs/airjam/generated/ui-components.md +265 -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 +212 -0
- package/template-assets/managed/docs/airjam/preview-controllers.md +129 -0
- package/template-assets/managed/docs/airjam/r3f-3d-scene.md +163 -0
- package/template-assets/managed/docs/airjam/state-lanes-cookbook.md +101 -0
- package/template-assets/managed/docs/airjam/visual-system.md +103 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Preview Controllers
|
|
2
|
+
|
|
3
|
+
Preview controllers are the fast local desktop tryout path for host surfaces.
|
|
4
|
+
|
|
5
|
+
They are useful in local development when you want to:
|
|
6
|
+
|
|
7
|
+
1. verify the controller UI without picking up a phone first
|
|
8
|
+
2. test host + controller interplay on one agent
|
|
9
|
+
3. mix one desktop preview controller with one real phone/browser controller in the same room
|
|
10
|
+
|
|
11
|
+
## Product Position
|
|
12
|
+
|
|
13
|
+
Air Jam is still phone-first.
|
|
14
|
+
|
|
15
|
+
Preview controllers are not the main product interaction. They are an optional
|
|
16
|
+
host-side accessory that speeds up local iteration and public tryout.
|
|
17
|
+
|
|
18
|
+
## Important Rules
|
|
19
|
+
|
|
20
|
+
1. preview controllers use the real controller route
|
|
21
|
+
2. preview controllers join the same room/session model as phone controllers
|
|
22
|
+
3. preview controllers are not a fake simulator or second topology
|
|
23
|
+
4. production should stay explicit opt-in
|
|
24
|
+
|
|
25
|
+
Embedded preview controllers intentionally rebase that controller route onto the
|
|
26
|
+
current host-page origin. The shared/join URL stays canonical for phones and
|
|
27
|
+
external browsers, but the local iframe should stay same-origin with the host so
|
|
28
|
+
browser tooling can interact with it reliably.
|
|
29
|
+
|
|
30
|
+
If a game behaves differently under a preview controller, treat that as a sign
|
|
31
|
+
the game may be relying on an accidental controller-origin assumption.
|
|
32
|
+
|
|
33
|
+
## Default Local Dev Usage
|
|
34
|
+
|
|
35
|
+
Scaffolded host surfaces can mount the shared SDK preview workspace like this:
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import { HostPreviewControllerWorkspace } from "@air-jam/sdk/preview";
|
|
39
|
+
|
|
40
|
+
export const HostView = () => {
|
|
41
|
+
const previewControllersEnabled = import.meta.env.DEV;
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
<GameSurface />
|
|
46
|
+
<HostPreviewControllerWorkspace enabled={previewControllersEnabled} />
|
|
47
|
+
</>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
In the normal local loop:
|
|
53
|
+
|
|
54
|
+
1. open the host page
|
|
55
|
+
2. click `Open controller`
|
|
56
|
+
3. a real controller client opens in the host-local preview workspace
|
|
57
|
+
4. you can still join the same room from a phone or another browser tab
|
|
58
|
+
|
|
59
|
+
For Claude Code or other agent preview surfaces, keep this flow in the same
|
|
60
|
+
visible host preview screen when possible. The point is to let the user see the
|
|
61
|
+
agent operate the host plus preview controllers together. Add more local players
|
|
62
|
+
with more preview-controller windows before reaching for separate OS browser
|
|
63
|
+
tabs.
|
|
64
|
+
|
|
65
|
+
Agents should use real browser click, drag, and release gestures against the
|
|
66
|
+
visible controller UI. They should not synthesize pointer events into controller
|
|
67
|
+
iframes from parent-page eval; that path is brittle around iframe boundaries,
|
|
68
|
+
pointer capture, and React event timing.
|
|
69
|
+
|
|
70
|
+
The preview workspace supports:
|
|
71
|
+
|
|
72
|
+
1. multiple floating controller windows
|
|
73
|
+
2. drag by the title bar
|
|
74
|
+
3. resize from any window edge or corner
|
|
75
|
+
4. minimize and close controls
|
|
76
|
+
5. per-window portrait or landscape rotation from the title bar for games without joystick input
|
|
77
|
+
|
|
78
|
+
6. shared active-opacity control for preview windows through platform settings
|
|
79
|
+
7. a room controller roster with source-aware `Kick` controls for manual local recovery
|
|
80
|
+
8. a `Reset room` escape hatch that creates a fresh empty room and reloads the local host page so gameplay state and controller state both reset cleanly
|
|
81
|
+
|
|
82
|
+
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.
|
|
83
|
+
|
|
84
|
+
`host.players` stays the gameplay-facing list.
|
|
85
|
+
|
|
86
|
+
`host.controllers` is the richer room-session roster. Use it when you need:
|
|
87
|
+
|
|
88
|
+
1. controller source (`phone`, `preview`, `virtual`)
|
|
89
|
+
2. connected versus disconnected session state
|
|
90
|
+
3. resume-lease awareness
|
|
91
|
+
4. manual host recovery controls such as removing a stuck controller
|
|
92
|
+
5. local-dev recovery flows such as resetting the current room
|
|
93
|
+
|
|
94
|
+
## Production Rule
|
|
95
|
+
|
|
96
|
+
Do not mount preview controllers in production by accident.
|
|
97
|
+
|
|
98
|
+
The safe default is:
|
|
99
|
+
|
|
100
|
+
1. enabled in local dev
|
|
101
|
+
2. disabled in production unless the host intentionally opts in
|
|
102
|
+
|
|
103
|
+
That keeps phone controllers as the canonical public interaction while still
|
|
104
|
+
allowing deliberate product experiments later.
|
|
105
|
+
|
|
106
|
+
## Where The API Lives
|
|
107
|
+
|
|
108
|
+
The feature is intentionally not part of the root SDK surface.
|
|
109
|
+
|
|
110
|
+
Use the experimental leaf:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
@air-jam/sdk/preview
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
That leaf currently owns:
|
|
117
|
+
|
|
118
|
+
1. preview launch helpers
|
|
119
|
+
2. preview identity helpers
|
|
120
|
+
3. preview session manager state
|
|
121
|
+
4. shared workspace and floating-window components
|
|
122
|
+
|
|
123
|
+
## What To Avoid
|
|
124
|
+
|
|
125
|
+
1. do not build a second controller transport for previews
|
|
126
|
+
2. do not inject fake controller state directly into gameplay
|
|
127
|
+
3. do not move preview layout/session state into replicated game state
|
|
128
|
+
4. do not assume preview-controller APIs are stable root-SDK contracts
|
|
129
|
+
5. do not use preview controllers as the primary semantic gameplay test path when the game exposes an agent contract
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# R3F 3D Scene
|
|
2
|
+
|
|
3
|
+
This guide exists for Air Jam projects that use React Three Fiber for host-side gameplay.
|
|
4
|
+
|
|
5
|
+
The goal is not just to "make Three.js work".
|
|
6
|
+
|
|
7
|
+
The goal is to keep 3D scenes readable, performant, and authored with stable conventions so LLMs do not create visual chaos.
|
|
8
|
+
|
|
9
|
+
## Dependencies
|
|
10
|
+
|
|
11
|
+
The starter does not include 3D dependencies. Before importing them, add
|
|
12
|
+
`three` and `@react-three/fiber` as runtime dependencies and `@types/three` as a
|
|
13
|
+
development dependency. Choose versions compatible with the project's React
|
|
14
|
+
version.
|
|
15
|
+
|
|
16
|
+
In Studio, call `studio_change_dependency` once per package with
|
|
17
|
+
`action: "add"`, `name`, the chosen `version`, and `dev: true` for `@types/three`.
|
|
18
|
+
This updates the package manifest and lockfile together. Outside Studio, use the
|
|
19
|
+
project's package manager, for example `pnpm add three @react-three/fiber` and
|
|
20
|
+
`pnpm add -D @types/three` in a pnpm project. Install optional libraries such as
|
|
21
|
+
`@react-three/drei` or `@dimforge/rapier3d-compat` only when the game uses them.
|
|
22
|
+
|
|
23
|
+
## Render Layer Rule
|
|
24
|
+
|
|
25
|
+
Treat R3F as the scene and rendering layer.
|
|
26
|
+
|
|
27
|
+
Keep:
|
|
28
|
+
|
|
29
|
+
1. gameplay rules in domain/system modules
|
|
30
|
+
2. orchestration in engine/adapters
|
|
31
|
+
3. scene composition, cameras, lights, and materials in the 3D layer
|
|
32
|
+
|
|
33
|
+
Movement, collisions and physics belong to the game's simulation, which the
|
|
34
|
+
SDK steps on the host at a fixed rate. R3F components only read the latest
|
|
35
|
+
simulation frame and draw it. A match then runs without a screen, so tests,
|
|
36
|
+
model players and replays play the real game.
|
|
37
|
+
|
|
38
|
+
## Object Lifecycle
|
|
39
|
+
|
|
40
|
+
In React, create three.js objects inside an effect, keep them in state and free
|
|
41
|
+
them in its cleanup, never during render into a useRef, useMemo or module
|
|
42
|
+
variable: live edits and StrictMode rerun effects, so an object kept from render
|
|
43
|
+
is freed while still shown and the scene goes empty.
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const material = new THREE.MeshStandardMaterial();
|
|
48
|
+
setMaterial(material);
|
|
49
|
+
return () => material.dispose();
|
|
50
|
+
}, []);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Agent Captures Of The 3D View
|
|
54
|
+
|
|
55
|
+
A WebGL canvas holds its pixels only until the browser presents the frame, so a
|
|
56
|
+
capture taken at any other moment comes out black. Render each frame yourself
|
|
57
|
+
and hand the canvas to the function `useHostAgentCapture` returns right after
|
|
58
|
+
`gl.render`:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
function RenderLoop({
|
|
62
|
+
onRendered,
|
|
63
|
+
}: {
|
|
64
|
+
onRendered: (canvas: HTMLCanvasElement) => void;
|
|
65
|
+
}) {
|
|
66
|
+
useFrame(({ gl, scene, camera }) => {
|
|
67
|
+
gl.render(scene, camera);
|
|
68
|
+
onRendered(gl.domElement);
|
|
69
|
+
}, 1);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Clips draw from that call. A still observation can arrive between frames, so
|
|
75
|
+
keep a 2D copy of the canvas every few frames and let the capture draw the live
|
|
76
|
+
canvas while `onRendered` runs and the copy at any other time. The alternative,
|
|
77
|
+
`preserveDrawingBuffer: true` on the renderer, costs frame time on every frame. Call
|
|
78
|
+
`event.preventDefault()` on the canvas's `webglcontextlost` event so the
|
|
79
|
+
browser can restore a lost context instead of leaving the view blank.
|
|
80
|
+
|
|
81
|
+
## Lighting Baseline
|
|
82
|
+
|
|
83
|
+
Establish one clean baseline lighting setup early.
|
|
84
|
+
|
|
85
|
+
For many stylized scenes, that usually means:
|
|
86
|
+
|
|
87
|
+
1. one main directional light that defines form and shadows
|
|
88
|
+
2. one ambient or hemisphere contribution so shadows are not dead black
|
|
89
|
+
3. one environment or sky source that gives the whole scene a coherent fill
|
|
90
|
+
|
|
91
|
+
Do not keep stacking random lights until the scene looks acceptable.
|
|
92
|
+
|
|
93
|
+
## Shadows
|
|
94
|
+
|
|
95
|
+
Three.js shadows often fail because the shadow camera bounds do not match the actual play area.
|
|
96
|
+
|
|
97
|
+
Rules:
|
|
98
|
+
|
|
99
|
+
1. enable shadows only on lights and meshes that matter
|
|
100
|
+
2. tune the directional light shadow camera to the real gameplay footprint
|
|
101
|
+
3. avoid gigantic catch-all shadow bounds
|
|
102
|
+
4. verify the play area fits inside the shadow frustum during active gameplay
|
|
103
|
+
|
|
104
|
+
If shadows look clipped, low-detail, or unstable, fix the shadow camera first before raising map sizes blindly.
|
|
105
|
+
|
|
106
|
+
## Grounding And Placement
|
|
107
|
+
|
|
108
|
+
Models should have a clear grounding convention.
|
|
109
|
+
|
|
110
|
+
Do not solve floating props with random hand-tuned offsets in every scene.
|
|
111
|
+
|
|
112
|
+
Instead:
|
|
113
|
+
|
|
114
|
+
1. define the ground plane or gameplay floor height
|
|
115
|
+
2. define each prefab's origin and intended contact point
|
|
116
|
+
3. keep reusable placement helpers for grounding and bounds
|
|
117
|
+
|
|
118
|
+
This matters for props, pickups, vehicles, characters, and spawnables.
|
|
119
|
+
|
|
120
|
+
## Physics
|
|
121
|
+
|
|
122
|
+
Rapier is a good default when the game genuinely needs:
|
|
123
|
+
|
|
124
|
+
1. rigid-body motion
|
|
125
|
+
2. stacking or collision response
|
|
126
|
+
3. reliable intersection/cast queries
|
|
127
|
+
4. authored physics interactions that are easier to express with a solver
|
|
128
|
+
|
|
129
|
+
Prefer custom movement/collision when:
|
|
130
|
+
|
|
131
|
+
1. objects move on simple constrained planes
|
|
132
|
+
2. collision is mostly overlap or tile/shape based
|
|
133
|
+
3. the game wants deterministic arcade behavior more than simulation fidelity
|
|
134
|
+
|
|
135
|
+
Do not pay the complexity cost of a full physics engine without clear benefit.
|
|
136
|
+
|
|
137
|
+
Whichever you choose, step it inside the simulation, not in the scene: a solver
|
|
138
|
+
running in R3F components (`@react-three/rapier`'s `<Physics>`) cannot run a
|
|
139
|
+
match without a screen.
|
|
140
|
+
|
|
141
|
+
## Particles And Effects
|
|
142
|
+
|
|
143
|
+
Use particles to reinforce motion, impacts, pickups, or atmosphere.
|
|
144
|
+
|
|
145
|
+
Do not use them as noise.
|
|
146
|
+
|
|
147
|
+
Rules:
|
|
148
|
+
|
|
149
|
+
1. keep them isolated in effect modules or systems
|
|
150
|
+
2. tie them to concrete gameplay events
|
|
151
|
+
3. keep spawn counts and lifetime intentional
|
|
152
|
+
|
|
153
|
+
## Materials, Textures, And Shaders
|
|
154
|
+
|
|
155
|
+
Prefer a coherent material language over random defaults.
|
|
156
|
+
|
|
157
|
+
Use:
|
|
158
|
+
|
|
159
|
+
1. curated textures when they actually improve readability
|
|
160
|
+
2. generated textures when the style is controlled and repeatable
|
|
161
|
+
3. custom shaders when the mechanic or visual identity truly needs them
|
|
162
|
+
|
|
163
|
+
Avoid introducing shader complexity just to make a weak base scene look more advanced.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# State Lanes Cookbook
|
|
2
|
+
|
|
3
|
+
Use this when you are deciding where a fact or effect belongs.
|
|
4
|
+
|
|
5
|
+
Air Jam is easiest to reason about when you keep four lanes separate:
|
|
6
|
+
|
|
7
|
+
1. controller input lane
|
|
8
|
+
2. replicated state lane
|
|
9
|
+
3. host-only runtime lane
|
|
10
|
+
4. signal/result lane
|
|
11
|
+
|
|
12
|
+
## The Short Rule
|
|
13
|
+
|
|
14
|
+
1. If a value comes from a controller every frame, keep it in the input lane.
|
|
15
|
+
2. If multiple surfaces must render the same durable truth, keep it in replicated state.
|
|
16
|
+
3. If only the host runtime needs it locally, keep it in host-only refs or local runtime state.
|
|
17
|
+
4. If you only need to notify, reject, or return a one-shot outcome, use signals or action acknowledgements instead of replicated state.
|
|
18
|
+
|
|
19
|
+
## Worked Example
|
|
20
|
+
|
|
21
|
+
Imagine a slingshot artillery game.
|
|
22
|
+
|
|
23
|
+
### Controller Input Lane
|
|
24
|
+
|
|
25
|
+
Declare controls with `defineAirJamInput`, bind phone UI to them with the SDK's `ControlButton`, `AxisButton` and `Stick`, and read them in the simulation step with `input(playerId)` for:
|
|
26
|
+
|
|
27
|
+
1. drag vector
|
|
28
|
+
2. aim angle
|
|
29
|
+
3. button held state
|
|
30
|
+
4. latest joystick direction
|
|
31
|
+
|
|
32
|
+
These values are transient and per-frame. They should not be replicated store state.
|
|
33
|
+
|
|
34
|
+
## Replicated State Lane
|
|
35
|
+
|
|
36
|
+
Use `createAirJamStore(...)` from `@air-jam/sdk/core` for durable shared truth that host and controllers both render:
|
|
37
|
+
|
|
38
|
+
1. current phase (`lobby`, `playing`, `ended`)
|
|
39
|
+
2. team assignments
|
|
40
|
+
3. score
|
|
41
|
+
4. cooldown timers that controllers display
|
|
42
|
+
5. which players are alive
|
|
43
|
+
|
|
44
|
+
If the controller HUD or another remote surface must render it, it belongs here.
|
|
45
|
+
Declare the store in `defineAirJamGame({ stores: [gameStore] })`; the host and
|
|
46
|
+
controllers sync only declared stores. Components read it with
|
|
47
|
+
`useAirJamStore(gameStore, selector)` and dispatch with `gameStore.actions`.
|
|
48
|
+
|
|
49
|
+
### Host-Only Runtime Lane
|
|
50
|
+
|
|
51
|
+
Use the declared simulation, `gameStore.getState()` and `useHostActionListener(gameStore, ...)` for host concerns such as:
|
|
52
|
+
|
|
53
|
+
1. physics world refs
|
|
54
|
+
2. particle systems
|
|
55
|
+
3. audio handles
|
|
56
|
+
4. canvas draw caches
|
|
57
|
+
5. interpolated render-only positions
|
|
58
|
+
|
|
59
|
+
These are often derived from replicated state or semantic actions, but they are not themselves the shared truth.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
export const simulation = defineAirJamSimulation<World, GameInput>({
|
|
63
|
+
stepMs: 1000 / 60,
|
|
64
|
+
create: ({ random }) => createPhysicsWorld(random),
|
|
65
|
+
step: (world, { dtSeconds }) => {
|
|
66
|
+
world.step(dtSeconds, gameStore.getState().playersAlive);
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The host draws the world with `useSimulationFrame` and reacts to host-applied
|
|
72
|
+
actions with `useHostActionListener(gameStore, ...)`.
|
|
73
|
+
|
|
74
|
+
### Signal And Result Lane
|
|
75
|
+
|
|
76
|
+
Use signals and action acknowledgements for one-shot outcomes:
|
|
77
|
+
|
|
78
|
+
1. haptics
|
|
79
|
+
2. toast notifications
|
|
80
|
+
3. “action rejected because player is dead”
|
|
81
|
+
4. “action accepted and returned a result payload”
|
|
82
|
+
|
|
83
|
+
Do not push these through replicated state just to trigger an effect once.
|
|
84
|
+
|
|
85
|
+
## Anti-Patterns
|
|
86
|
+
|
|
87
|
+
Avoid these:
|
|
88
|
+
|
|
89
|
+
1. storing per-frame joystick movement in replicated state
|
|
90
|
+
2. storing host-only sim refs or particle instances in replicated state
|
|
91
|
+
3. creating fake replicated booleans just to trigger a one-shot sound
|
|
92
|
+
4. driving semantic game actions by browser clicks when the game already has an agent contract
|
|
93
|
+
|
|
94
|
+
## Fast Placement Test
|
|
95
|
+
|
|
96
|
+
Ask these in order:
|
|
97
|
+
|
|
98
|
+
1. Does this change every frame from a controller? Input lane.
|
|
99
|
+
2. Do host and controllers both need to render it later? Replicated state lane.
|
|
100
|
+
3. Does only the host runtime need it to simulate or render locally? Host-only runtime lane.
|
|
101
|
+
4. Is it just a one-shot notification or outcome? Signal/result lane.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Visual System
|
|
2
|
+
|
|
3
|
+
Use this doc when extending the starter template's styling.
|
|
4
|
+
|
|
5
|
+
The goal is not to scatter one-off classes, arbitrary colors, and ad hoc gradients across the tree.
|
|
6
|
+
|
|
7
|
+
The goal is to keep the visual language intentional, reusable, and easy to evolve.
|
|
8
|
+
|
|
9
|
+
## Default Rule
|
|
10
|
+
|
|
11
|
+
When a template already ships a visual system:
|
|
12
|
+
|
|
13
|
+
1. extend the existing theme tokens first
|
|
14
|
+
2. extend the existing semantic utilities second
|
|
15
|
+
3. only then add one-off styling if the case is truly isolated
|
|
16
|
+
|
|
17
|
+
Do not bypass the shipped system casually.
|
|
18
|
+
|
|
19
|
+
## Tailwind Rule
|
|
20
|
+
|
|
21
|
+
For Tailwind CSS-first projects, prefer this order:
|
|
22
|
+
|
|
23
|
+
1. `@theme` for tokens such as colors, shadows, fonts, and reusable design values
|
|
24
|
+
2. `@layer base` for root, body, and element defaults
|
|
25
|
+
3. `@utility` for semantic reusable classes like stage shells, panels, status pills, and touch surfaces
|
|
26
|
+
4. inline utility classes in components for local composition
|
|
27
|
+
|
|
28
|
+
That keeps the styling model clear:
|
|
29
|
+
|
|
30
|
+
1. tokens define the palette and system values
|
|
31
|
+
2. semantic utilities define recurring UI primitives
|
|
32
|
+
3. component markup composes those primitives
|
|
33
|
+
|
|
34
|
+
## What Belongs In Tokens
|
|
35
|
+
|
|
36
|
+
Good token candidates:
|
|
37
|
+
|
|
38
|
+
1. brand or game palette colors
|
|
39
|
+
2. text colors and muted variants
|
|
40
|
+
3. shadows
|
|
41
|
+
4. type families
|
|
42
|
+
5. surface colors
|
|
43
|
+
6. border strengths
|
|
44
|
+
|
|
45
|
+
Bad token candidates:
|
|
46
|
+
|
|
47
|
+
1. one-off page-specific measurements
|
|
48
|
+
2. one component's temporary padding tweak
|
|
49
|
+
3. values that are only used once and have no system meaning
|
|
50
|
+
|
|
51
|
+
## What Belongs In Semantic Utilities
|
|
52
|
+
|
|
53
|
+
Good semantic utility candidates:
|
|
54
|
+
|
|
55
|
+
1. game shell backgrounds
|
|
56
|
+
2. host stage frames
|
|
57
|
+
3. reusable panel surfaces
|
|
58
|
+
4. status pills
|
|
59
|
+
5. touch control shells
|
|
60
|
+
6. overlay containers
|
|
61
|
+
|
|
62
|
+
Bad semantic utility candidates:
|
|
63
|
+
|
|
64
|
+
1. wrappers used by one element only
|
|
65
|
+
2. tiny spacing helpers that are really just local layout
|
|
66
|
+
3. utilities that hide unclear visual intent behind vague names
|
|
67
|
+
|
|
68
|
+
## Component Rule
|
|
69
|
+
|
|
70
|
+
Component files should mostly compose:
|
|
71
|
+
|
|
72
|
+
1. existing theme tokens
|
|
73
|
+
2. existing semantic utilities
|
|
74
|
+
3. local Tailwind classes for layout and spacing
|
|
75
|
+
|
|
76
|
+
Avoid:
|
|
77
|
+
|
|
78
|
+
1. repeating the same arbitrary color values in many components
|
|
79
|
+
2. rebuilding the same panel styling in multiple places
|
|
80
|
+
3. mixing several unrelated visual directions in one template
|
|
81
|
+
|
|
82
|
+
## Host And Controller Guidance
|
|
83
|
+
|
|
84
|
+
When the template has both host and controller surfaces:
|
|
85
|
+
|
|
86
|
+
1. keep one shared design language across both
|
|
87
|
+
2. let the host feel more atmospheric and stage-like
|
|
88
|
+
3. let the controller feel more tactile and action-first
|
|
89
|
+
4. keep gameplay controls simpler than lobby or status surfaces
|
|
90
|
+
|
|
91
|
+
Shared language does not mean identical layout.
|
|
92
|
+
|
|
93
|
+
## Decision Rule
|
|
94
|
+
|
|
95
|
+
Before adding styling, ask:
|
|
96
|
+
|
|
97
|
+
1. is this a token
|
|
98
|
+
2. is this a reusable semantic utility
|
|
99
|
+
3. is this only local composition
|
|
100
|
+
|
|
101
|
+
Put it at the highest level that is still honest.
|
|
102
|
+
|
|
103
|
+
If the answer is not clear, prefer local composition over premature abstraction.
|