@air-jam/sdk 0.1.4 → 0.9.0
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 +627 -57
- package/dist/agent-tooling-BSMGBix9.d.cts +123 -0
- package/dist/agent-tooling-BSMGBix9.d.ts +123 -0
- package/dist/agent-tooling.cjs +83 -0
- package/dist/agent-tooling.cjs.map +1 -0
- package/dist/agent-tooling.d.cts +2 -0
- package/dist/agent-tooling.d.ts +2 -0
- package/dist/agent-tooling.js +17 -0
- package/dist/agent-tooling.js.map +1 -0
- package/dist/arcade/bridge/controller.cjs +749 -0
- package/dist/arcade/bridge/controller.cjs.map +1 -0
- package/dist/arcade/bridge/controller.d.cts +85 -0
- package/dist/arcade/bridge/controller.d.ts +85 -0
- package/dist/arcade/bridge/controller.js +33 -0
- package/dist/arcade/bridge/controller.js.map +1 -0
- package/dist/arcade/bridge/host.cjs +421 -0
- package/dist/arcade/bridge/host.cjs.map +1 -0
- package/dist/arcade/bridge/host.d.cts +73 -0
- package/dist/arcade/bridge/host.d.ts +73 -0
- package/dist/arcade/bridge/host.js +25 -0
- package/dist/arcade/bridge/host.js.map +1 -0
- package/dist/arcade/bridge/iframe.cjs +453 -0
- package/dist/arcade/bridge/iframe.cjs.map +1 -0
- package/dist/arcade/bridge/iframe.d.cts +80 -0
- package/dist/arcade/bridge/iframe.d.ts +80 -0
- package/dist/arcade/bridge/iframe.js +28 -0
- package/dist/arcade/bridge/iframe.js.map +1 -0
- package/dist/arcade/bridge.cjs +1067 -0
- package/dist/arcade/bridge.cjs.map +1 -0
- package/dist/arcade/bridge.d.cts +11 -0
- package/dist/arcade/bridge.d.ts +11 -0
- package/dist/arcade/bridge.js +76 -0
- package/dist/arcade/bridge.js.map +1 -0
- package/dist/arcade/host.cjs +488 -0
- package/dist/arcade/host.cjs.map +1 -0
- package/dist/arcade/host.d.cts +19 -0
- package/dist/arcade/host.d.ts +19 -0
- package/dist/arcade/host.js +13 -0
- package/dist/arcade/host.js.map +1 -0
- package/dist/arcade/surface.cjs +113 -0
- package/dist/arcade/surface.cjs.map +1 -0
- package/dist/arcade/surface.d.cts +14 -0
- package/dist/arcade/surface.d.ts +14 -0
- package/dist/arcade/surface.js +27 -0
- package/dist/arcade/surface.js.map +1 -0
- package/dist/arcade/url.cjs +363 -0
- package/dist/arcade/url.cjs.map +1 -0
- package/dist/arcade/url.d.cts +68 -0
- package/dist/arcade/url.d.ts +68 -0
- package/dist/arcade/url.js +28 -0
- package/dist/arcade/url.js.map +1 -0
- package/dist/arcade-runtime-url-BW-MUAOY.d.cts +28 -0
- package/dist/arcade-runtime-url-l8qj01Pg.d.ts +28 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.cts +16 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.ts +16 -0
- package/dist/arcade.cjs +1565 -0
- package/dist/arcade.cjs.map +1 -0
- package/dist/arcade.d.cts +18 -0
- package/dist/arcade.d.ts +18 -0
- package/dist/arcade.js +122 -0
- package/dist/arcade.js.map +1 -0
- package/dist/capabilities.cjs +39 -0
- package/dist/capabilities.cjs.map +1 -0
- package/dist/capabilities.d.cts +31 -0
- package/dist/capabilities.d.ts +31 -0
- package/dist/capabilities.js +12 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/chunk-2432OL7L.js +193 -0
- package/dist/chunk-2432OL7L.js.map +1 -0
- package/dist/chunk-2J65FXEP.js +41 -0
- package/dist/chunk-2J65FXEP.js.map +1 -0
- package/dist/chunk-32NYL7XI.js +539 -0
- package/dist/chunk-32NYL7XI.js.map +1 -0
- package/dist/chunk-3USU7GY2.js +54 -0
- package/dist/chunk-3USU7GY2.js.map +1 -0
- package/dist/chunk-BE6Z4SIT.js +65 -0
- package/dist/chunk-BE6Z4SIT.js.map +1 -0
- package/dist/chunk-CQUG24WX.js +249 -0
- package/dist/chunk-CQUG24WX.js.map +1 -0
- package/dist/chunk-D3X4MN4U.js +288 -0
- package/dist/chunk-D3X4MN4U.js.map +1 -0
- package/dist/chunk-EVZJA6RN.js +140 -0
- package/dist/chunk-EVZJA6RN.js.map +1 -0
- package/dist/chunk-HFWRZVZ3.js +1438 -0
- package/dist/chunk-HFWRZVZ3.js.map +1 -0
- package/dist/chunk-IKKDONQL.js +1 -0
- package/dist/chunk-IKKDONQL.js.map +1 -0
- package/dist/chunk-JTF47B56.js +1 -0
- package/dist/chunk-JTF47B56.js.map +1 -0
- package/dist/chunk-LIXPF4P6.js +22 -0
- package/dist/chunk-LIXPF4P6.js.map +1 -0
- package/dist/chunk-MKBASO6X.js +216 -0
- package/dist/chunk-MKBASO6X.js.map +1 -0
- package/dist/chunk-MPDMJIX5.js +1 -0
- package/dist/chunk-MPDMJIX5.js.map +1 -0
- package/dist/chunk-NCL6WJCL.js +91 -0
- package/dist/chunk-NCL6WJCL.js.map +1 -0
- package/dist/chunk-NU5W6VAV.js +126 -0
- package/dist/chunk-NU5W6VAV.js.map +1 -0
- package/dist/chunk-TGRTEWYV.js +195 -0
- package/dist/chunk-TGRTEWYV.js.map +1 -0
- package/dist/chunk-VDRNNGHX.js +184 -0
- package/dist/chunk-VDRNNGHX.js.map +1 -0
- package/dist/chunk-VN5LDWVN.js +32 -0
- package/dist/chunk-VN5LDWVN.js.map +1 -0
- package/dist/chunk-W2VK36RO.js +11 -0
- package/dist/chunk-W2VK36RO.js.map +1 -0
- package/dist/chunk-X24K52DG.js +12 -0
- package/dist/chunk-X24K52DG.js.map +1 -0
- package/dist/chunk-XLUWV45V.js +25 -0
- package/dist/chunk-XLUWV45V.js.map +1 -0
- package/dist/chunk-Y4RAPKKB.js +238 -0
- package/dist/chunk-Y4RAPKKB.js.map +1 -0
- package/dist/chunk-YXHH3MQT.js +230 -0
- package/dist/chunk-YXHH3MQT.js.map +1 -0
- package/dist/chunk-ZLPL2R3R.js +183 -0
- package/dist/chunk-ZLPL2R3R.js.map +1 -0
- package/dist/chunk-ZTQ5SP4H.js +9 -0
- package/dist/chunk-ZTQ5SP4H.js.map +1 -0
- package/dist/controller-Bod8YYr1.d.cts +172 -0
- package/dist/controller-DxVchfiA.d.ts +172 -0
- package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
- package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
- package/dist/handshake-CC_LrK5g.d.cts +31 -0
- package/dist/handshake-CC_LrK5g.d.ts +31 -0
- package/dist/host-8hmq_Sgc.d.cts +109 -0
- package/dist/host-Cw-N6e-5.d.ts +109 -0
- package/dist/index.cjs +8507 -3523
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +676 -1070
- package/dist/index.d.ts +676 -1070
- package/dist/index.js +4890 -3196
- package/dist/index.js.map +1 -1
- package/dist/metadata.cjs +114 -0
- package/dist/metadata.cjs.map +1 -0
- package/dist/metadata.d.cts +95 -0
- package/dist/metadata.d.ts +95 -0
- package/dist/metadata.js +83 -0
- package/dist/metadata.js.map +1 -0
- package/dist/notices-CnGaaS8B.d.ts +38 -0
- package/dist/notices-NyDM5Mtz.d.cts +38 -0
- package/dist/platform-machine.cjs +425 -0
- package/dist/platform-machine.cjs.map +1 -0
- package/dist/platform-machine.d.cts +1183 -0
- package/dist/platform-machine.d.ts +1183 -0
- package/dist/platform-machine.js +309 -0
- package/dist/platform-machine.js.map +1 -0
- package/dist/platform-settings-cuor3i11.d.cts +48 -0
- package/dist/platform-settings-cuor3i11.d.ts +48 -0
- package/dist/prefabs.cjs +36 -0
- package/dist/prefabs.cjs.map +1 -0
- package/dist/prefabs.d.cts +49 -0
- package/dist/prefabs.d.ts +49 -0
- package/dist/prefabs.js +8 -0
- package/dist/prefabs.js.map +1 -0
- package/dist/preview.cjs +2609 -0
- package/dist/preview.cjs.map +1 -0
- package/dist/preview.d.cts +155 -0
- package/dist/preview.d.ts +155 -0
- package/dist/preview.js +1671 -0
- package/dist/preview.js.map +1 -0
- package/dist/protocol.cjs +621 -54
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +76 -240
- package/dist/protocol.d.ts +76 -240
- package/dist/protocol.js +100 -2
- package/dist/protocol.js.map +1 -1
- package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
- package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
- package/dist/release.cjs +143 -0
- package/dist/release.cjs.map +1 -0
- package/dist/release.d.cts +64 -0
- package/dist/release.d.ts +64 -0
- package/dist/release.js +43 -0
- package/dist/release.js.map +1 -0
- package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
- package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
- package/dist/sync-B6QsNrXz.d.cts +125 -0
- package/dist/sync-B6QsNrXz.d.ts +125 -0
- package/dist/ui.cjs +2827 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +320 -0
- package/dist/ui.d.ts +320 -0
- package/dist/ui.js +1718 -0
- package/dist/ui.js.map +1 -0
- package/dist/url-policy-C89zxgw9.d.cts +9 -0
- package/dist/url-policy-C89zxgw9.d.ts +9 -0
- package/package.json +149 -11
- package/src/agent/agent-action.ts +304 -0
- package/src/agent/agent-contract.ts +180 -0
- package/src/agent-tooling.ts +20 -0
- package/src/arcade/bridge/controller.ts +15 -0
- package/src/arcade/bridge/host.ts +12 -0
- package/src/arcade/bridge/iframe.ts +61 -0
- package/src/arcade/bridge.ts +3 -0
- package/src/arcade/host.ts +1 -0
- package/src/arcade/surface.ts +4 -0
- package/src/arcade/url.ts +60 -0
- package/src/arcade.ts +4 -0
- package/src/audio/audio-manager.ts +162 -171
- package/src/audio/hooks.tsx +218 -97
- package/src/audio/index.ts +1 -1
- package/src/audio/music.tsx +139 -0
- package/src/capabilities/manifest.ts +71 -0
- package/src/capabilities.ts +12 -0
- package/src/components/connection-status-pill.tsx +55 -0
- package/src/components/controller-player-name-field.tsx +119 -0
- package/src/components/controller-primary-action.tsx +58 -0
- package/src/components/host-mute-button.tsx +49 -0
- package/src/components/join-qr-overlay.tsx +133 -0
- package/src/components/join-url-action-buttons.tsx +95 -0
- package/src/components/join-url-controls.tsx +58 -0
- package/src/components/join-url-field.tsx +52 -0
- package/src/components/lifecycle-action-group.tsx +129 -0
- package/src/components/player-avatar-strip.tsx +65 -0
- package/src/components/player-avatar.tsx +42 -13
- package/src/components/room-qr-code.tsx +125 -0
- package/src/components/runtime-shell-header.tsx +37 -0
- package/src/components/shell-classes.ts +19 -0
- package/src/components/surface-orientation-layout.ts +60 -0
- package/src/components/surface-viewport-layout.ts +268 -0
- package/src/components/surface-viewport.tsx +314 -0
- package/src/components/ui/button.tsx +4 -6
- package/src/components/ui/slider.tsx +1 -1
- package/src/components/volume-controls.tsx +65 -6
- package/src/context/air-jam-context.tsx +209 -161
- package/src/context/index.ts +2 -2
- package/src/context/session-providers.tsx +77 -0
- package/src/context/session-scope.ts +64 -0
- package/src/context/socket-manager.ts +6 -24
- package/src/contracts/v2/bridge.ts +261 -0
- package/src/contracts/v2/handshake.ts +40 -0
- package/src/contracts/v2/index.ts +2 -0
- package/src/dev/browser-log-sink.ts +912 -0
- package/src/diagnostics.ts +128 -0
- package/src/events.ts +7 -34
- package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
- package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
- package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
- package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
- package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
- package/src/hooks/use-air-jam-controller.ts +155 -475
- package/src/hooks/use-air-jam-host.ts +156 -485
- package/src/hooks/use-connection-status.ts +8 -0
- package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
- package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
- package/src/hooks/use-controller-shell-status.ts +40 -0
- package/src/hooks/use-controller-tick.ts +65 -0
- package/src/hooks/use-controller-toasts.ts +116 -0
- package/src/hooks/use-get-input.ts +8 -5
- package/src/hooks/use-host-arcade-restore.ts +30 -0
- package/src/hooks/use-host-join-controls.ts +152 -0
- package/src/hooks/use-host-tick.ts +171 -0
- package/src/hooks/use-input-writer.ts +83 -0
- package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
- package/src/hooks/use-players.ts +12 -0
- package/src/hooks/use-room.ts +22 -0
- package/src/hooks/use-send-signal.ts +6 -2
- package/src/index.ts +205 -31
- package/src/internal/input-manager.ts +195 -215
- package/src/lifecycle/index.ts +9 -0
- package/src/lifecycle/standard-match-phase.ts +32 -0
- package/src/metadata/manifest.ts +152 -0
- package/src/metadata.ts +12 -0
- package/src/platform-machine.ts +475 -0
- package/src/prefabs/types.ts +82 -0
- package/src/prefabs.ts +12 -0
- package/src/preview/host-workspace.tsx +59 -0
- package/src/preview/identity.ts +66 -0
- package/src/preview/layout.ts +223 -0
- package/src/preview/manager.ts +577 -0
- package/src/preview/messages.ts +26 -0
- package/src/preview/ownership.ts +81 -0
- package/src/preview/url.ts +117 -0
- package/src/preview/window.tsx +490 -0
- package/src/preview/workspace.tsx +678 -0
- package/src/preview.ts +42 -0
- package/src/protocol/arcade-platform-actions.ts +29 -0
- package/src/protocol/controller.ts +187 -0
- package/src/protocol/core.ts +23 -0
- package/src/protocol/dev-log-events.ts +222 -0
- package/src/protocol/errors.ts +21 -0
- package/src/protocol/host-grant.ts +185 -0
- package/src/protocol/host.ts +138 -0
- package/src/protocol/notices.ts +43 -0
- package/src/protocol/signals.ts +38 -0
- package/src/protocol/socket-events.ts +154 -0
- package/src/protocol/sync.ts +121 -0
- package/src/protocol/url-policy.ts +63 -0
- package/src/protocol.ts +12 -386
- package/src/qrcode.d.ts +16 -0
- package/src/release.ts +99 -0
- package/src/runtime/air-jam-config.ts +287 -0
- package/src/runtime/air-jam-error-boundary.tsx +672 -0
- package/src/runtime/arcade-bridge-request-surface.ts +15 -0
- package/src/runtime/arcade-runtime-url.ts +95 -0
- package/src/runtime/arcade-surface-identity.ts +16 -0
- package/src/runtime/contracts/control.ts +68 -0
- package/src/runtime/contracts/inspection.ts +165 -0
- package/src/runtime/contracts/observability.ts +94 -0
- package/src/runtime/controller-bridge.ts +451 -0
- package/src/runtime/controller-identity.ts +132 -0
- package/src/runtime/controller-presentation.ts +24 -0
- package/src/runtime/controller-realtime-client.ts +591 -0
- package/src/runtime/create-air-jam-app.tsx +260 -0
- package/src/runtime/dev-runtime-events.ts +36 -0
- package/src/runtime/embedded-runtime-adapters.ts +68 -0
- package/src/runtime/host-bridge.ts +388 -0
- package/src/runtime/host-realtime-client.ts +550 -0
- package/src/runtime/iframe-bridge.ts +135 -0
- package/src/runtime/realtime-client.ts +20 -0
- package/src/runtime/router-basename.ts +25 -0
- package/src/runtime/runtime-owner-contexts.tsx +4 -0
- package/src/runtime/runtime-session-params.ts +169 -0
- package/src/runtime/sdk-version.ts +6 -0
- package/src/runtime/session-runtimes.tsx +188 -0
- package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
- package/src/runtime-control.ts +10 -0
- package/src/runtime-inspection.ts +14 -0
- package/src/runtime-observability.ts +9 -0
- package/src/settings/platform-settings-bridge.ts +336 -0
- package/src/settings/platform-settings-runtime.tsx +387 -0
- package/src/settings/platform-settings.ts +288 -0
- package/src/state/connection-store.ts +80 -12
- package/src/store/air-jam-store-domain-constants.ts +4 -0
- package/src/store/create-air-jam-store.ts +1094 -227
- package/src/styles.css +4 -38
- package/src/ui.ts +29 -0
- package/src/utils/is-rpc-serializable.ts +56 -0
- package/src/utils/player-avatar-url.ts +48 -0
- package/src/utils/url-builder.ts +7 -0
- package/dist/.tsbuildinfo +0 -1
- package/dist/chunk-B5DURUWT.js +0 -80
- package/dist/chunk-B5DURUWT.js.map +0 -1
- package/src/AirJamClient.ts +0 -224
- package/src/audio/volume-store.ts +0 -124
- package/src/components/controller-shell.tsx +0 -346
- package/src/components/host-shell.tsx +0 -520
- package/src/components/qr-scanner-dialog.tsx +0 -373
- package/src/components/ui/alert.tsx +0 -66
- package/src/components/ui/avatar.tsx +0 -46
- package/src/components/ui/badge.tsx +0 -47
- package/src/components/ui/card.tsx +0 -92
- package/src/components/ui/dialog.tsx +0 -122
- package/src/components/ui/tabs.tsx +0 -64
- package/src/hooks/use-air-jam-shell.ts +0 -379
- package/src/hooks/use-fullscreen.ts +0 -108
|
@@ -1,51 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module InputManager
|
|
3
|
-
* @description Internal
|
|
3
|
+
* @description Internal input runtime used by host hooks.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* 2. **Validation** - Validates input against a Zod schema (optional)
|
|
10
|
-
* 3. **Latching** - Ensures rapid button presses and stick flicks are never missed
|
|
11
|
-
*
|
|
12
|
-
* ## What is Latching?
|
|
13
|
-
*
|
|
14
|
-
* Game loops typically run at 60fps, but network events may arrive between frames.
|
|
15
|
-
* Without latching, a quick button tap might be missed if it starts and ends between
|
|
16
|
-
* two consecutive `getInput()` calls.
|
|
17
|
-
*
|
|
18
|
-
* **Latching solves this by:**
|
|
19
|
-
* - Boolean fields: Keeping `true` values until consumed
|
|
20
|
-
* - Vector fields: Keeping non-zero values for one frame after release
|
|
21
|
-
*
|
|
22
|
-
* ## Example: Without Latching (Bug)
|
|
23
|
-
* ```
|
|
24
|
-
* Frame 1: getInput() → action: false
|
|
25
|
-
* [Network: action: true arrives, then action: false arrives]
|
|
26
|
-
* Frame 2: getInput() → action: false ← Tap missed!
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* ## Example: With Latching (Fixed)
|
|
30
|
-
* ```
|
|
31
|
-
* Frame 1: getInput() → action: false
|
|
32
|
-
* [Network: action: true arrives, then action: false arrives]
|
|
33
|
-
* Frame 2: getInput() → action: true ← Tap captured!
|
|
34
|
-
* Frame 3: getInput() → action: false ← Consumed, resets
|
|
35
|
-
* ```
|
|
5
|
+
* Public API terms:
|
|
6
|
+
* - `pulse`: consume-on-read, tap-safe behavior (default for booleans)
|
|
7
|
+
* - `hold`: keep last active vector until a new active value arrives
|
|
8
|
+
* - `latest`: read current value as-is (default for vectors and other fields)
|
|
36
9
|
*
|
|
37
10
|
* @internal This class is not exported publicly. Use hooks to access input.
|
|
38
11
|
*/
|
|
39
12
|
import type { z } from "zod";
|
|
40
13
|
import type { ControllerInputEvent } from "../protocol";
|
|
41
14
|
|
|
42
|
-
|
|
43
|
-
|
|
15
|
+
type InputFieldBehavior = "pulse" | "hold" | "latest";
|
|
16
|
+
|
|
17
|
+
interface VectorValue {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
}
|
|
44
21
|
|
|
45
22
|
/**
|
|
46
|
-
* Configuration for input handling with optional validation and
|
|
23
|
+
* Configuration for input handling with optional validation and per-field behavior.
|
|
47
24
|
*
|
|
48
|
-
* Provided to `
|
|
25
|
+
* Provided to `HostSessionProvider` to enable typed and behavior-aware input reads.
|
|
49
26
|
*
|
|
50
27
|
* @template TSchema - Zod schema type for input validation
|
|
51
28
|
*
|
|
@@ -59,13 +36,14 @@ let lastInputManagerLogTime = 0;
|
|
|
59
36
|
* };
|
|
60
37
|
* ```
|
|
61
38
|
*
|
|
62
|
-
* @example With
|
|
39
|
+
* @example With custom behavior overrides
|
|
63
40
|
* ```ts
|
|
64
41
|
* const config: InputConfig = {
|
|
65
42
|
* schema: gameInputSchema,
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
43
|
+
* behavior: {
|
|
44
|
+
* pulse: ["action", "ability"], // consume-on-read
|
|
45
|
+
* latest: ["aim"], // read latest value
|
|
46
|
+
* hold: ["menuVector"], // keep last non-zero vector
|
|
69
47
|
* },
|
|
70
48
|
* };
|
|
71
49
|
* ```
|
|
@@ -90,57 +68,45 @@ export interface InputConfig<TSchema extends z.ZodSchema = z.ZodSchema> {
|
|
|
90
68
|
* ```
|
|
91
69
|
*/
|
|
92
70
|
schema?: TSchema;
|
|
93
|
-
|
|
94
|
-
* Latching configuration to ensure rapid taps and flicks are never missed.
|
|
95
|
-
*
|
|
96
|
-
* Latching "holds" boolean true values and non-zero vectors until the next
|
|
97
|
-
* `getInput()` call, preventing missed inputs between game frames.
|
|
98
|
-
*/
|
|
99
|
-
latch?: {
|
|
71
|
+
behavior?: {
|
|
100
72
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* When a boolean field is latched:
|
|
104
|
-
* - If it becomes `true`, it stays `true` until consumed by `getInput()`
|
|
105
|
-
* - After consumption, it resets to the actual current value
|
|
106
|
-
*
|
|
107
|
-
* Use for: buttons, triggers, action inputs
|
|
73
|
+
* Consume-on-read behavior. Useful for tap-safe buttons and one-shot vectors.
|
|
108
74
|
*
|
|
109
|
-
*
|
|
75
|
+
* Defaults: booleans use `pulse` even without explicit config.
|
|
110
76
|
*/
|
|
111
|
-
|
|
77
|
+
pulse?: string[];
|
|
112
78
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
*
|
|
119
|
-
* Use for: joysticks, d-pads, directional inputs
|
|
79
|
+
* Sticky behavior. For vectors, keeps the last non-zero direction until
|
|
80
|
+
* another non-zero direction arrives.
|
|
81
|
+
*/
|
|
82
|
+
hold?: string[];
|
|
83
|
+
/**
|
|
84
|
+
* Stateless behavior. Returns the latest raw value.
|
|
120
85
|
*
|
|
121
|
-
*
|
|
86
|
+
* Defaults: vectors and non-boolean fields use `latest`.
|
|
122
87
|
*/
|
|
123
|
-
|
|
88
|
+
latest?: string[];
|
|
124
89
|
};
|
|
125
90
|
}
|
|
126
91
|
|
|
127
92
|
/**
|
|
128
|
-
* Internal state
|
|
93
|
+
* Internal behavior state per controller.
|
|
129
94
|
* @internal
|
|
130
95
|
*/
|
|
131
|
-
interface
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
latched: TInput;
|
|
136
|
-
/** Hash of raw input to detect changes */
|
|
137
|
-
lastRawHash?: string;
|
|
96
|
+
interface ControllerBehaviorState {
|
|
97
|
+
pulseBooleans: Set<string>;
|
|
98
|
+
pulseVectors: Map<string, VectorValue>;
|
|
99
|
+
holdVectors: Map<string, VectorValue>;
|
|
138
100
|
}
|
|
139
101
|
|
|
140
102
|
/**
|
|
141
|
-
* Internal class that manages input buffering, validation, and
|
|
103
|
+
* Internal class that manages input buffering, validation, and behavior semantics.
|
|
104
|
+
*
|
|
105
|
+
* **Single input lane:** one `InputManager` per `HostSessionProvider`, fed only by `server:input`.
|
|
106
|
+
* Multiple `createAirJamStore` domains in the same room (e.g. `arcade.surface` + embedded game)
|
|
107
|
+
* do not duplicate or fork input — gameplay still reads controller input through this manager only.
|
|
142
108
|
*
|
|
143
|
-
* Created automatically by `
|
|
109
|
+
* Created automatically by `HostSessionProvider` when input configuration is provided.
|
|
144
110
|
* Access input via `useGetInput()` or `useAirJamHost().getInput()`.
|
|
145
111
|
*
|
|
146
112
|
* @template TSchema - Zod schema type for input validation
|
|
@@ -149,10 +115,10 @@ interface LatchState<TInput = Record<string, unknown>> {
|
|
|
149
115
|
*
|
|
150
116
|
* @example How it's used internally
|
|
151
117
|
* ```ts
|
|
152
|
-
* // In
|
|
118
|
+
* // In HostSessionProvider
|
|
153
119
|
* const inputManager = new InputManager({
|
|
154
120
|
* schema: gameInputSchema,
|
|
155
|
-
*
|
|
121
|
+
* behavior: { pulse: ["action"] },
|
|
156
122
|
* });
|
|
157
123
|
*
|
|
158
124
|
* // In useAirJamHost (socket handler)
|
|
@@ -166,11 +132,13 @@ interface LatchState<TInput = Record<string, unknown>> {
|
|
|
166
132
|
*/
|
|
167
133
|
export class InputManager<TSchema extends z.ZodSchema = z.ZodSchema> {
|
|
168
134
|
private inputBuffer = new Map<string, Record<string, unknown>>();
|
|
169
|
-
private
|
|
135
|
+
private behaviorState = new Map<string, ControllerBehaviorState>();
|
|
136
|
+
private behaviorOverrides = new Map<string, InputFieldBehavior>();
|
|
170
137
|
private config: InputConfig<TSchema>;
|
|
171
138
|
|
|
172
139
|
constructor(config: InputConfig<TSchema> = {}) {
|
|
173
140
|
this.config = config;
|
|
141
|
+
this.behaviorOverrides = this.createBehaviorOverrides(config.behavior);
|
|
174
142
|
}
|
|
175
143
|
|
|
176
144
|
/**
|
|
@@ -178,39 +146,15 @@ export class InputManager<TSchema extends z.ZodSchema = z.ZodSchema> {
|
|
|
178
146
|
* Should be called when 'server:input' event is received.
|
|
179
147
|
*/
|
|
180
148
|
handleInput(payload: ControllerInputEvent): void {
|
|
181
|
-
//
|
|
182
|
-
// 1. The server already routes input correctly to the right host
|
|
183
|
-
// 2. Multiple host instances might share the same InputManager instance
|
|
184
|
-
// 3. The roomId check was causing false rejections when hosts re-register
|
|
185
|
-
|
|
186
|
-
// Store raw input as-is (arbitrary structure)
|
|
149
|
+
// The server already routes by room; keep host runtime hot path minimal.
|
|
187
150
|
this.inputBuffer.set(payload.controllerId, payload.input);
|
|
188
|
-
|
|
189
|
-
// Throttled logging - only log active input, once per second max
|
|
190
|
-
const now = Date.now();
|
|
191
|
-
const input = payload?.input;
|
|
192
|
-
const hasActiveInput =
|
|
193
|
-
input &&
|
|
194
|
-
(input.action === true ||
|
|
195
|
-
(typeof input.vector === "object" &&
|
|
196
|
-
input.vector !== null &&
|
|
197
|
-
(Math.abs((input.vector as { x?: number; y?: number }).x ?? 0) >
|
|
198
|
-
0.01 ||
|
|
199
|
-
Math.abs((input.vector as { x?: number; y?: number }).y ?? 0) >
|
|
200
|
-
0.01)));
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
hasActiveInput &&
|
|
204
|
-
(!lastInputManagerLogTime || now - lastInputManagerLogTime > 1000)
|
|
205
|
-
) {
|
|
206
|
-
lastInputManagerLogTime = now;
|
|
207
|
-
}
|
|
151
|
+
this.captureTransientBehaviors(payload.controllerId, payload.input);
|
|
208
152
|
}
|
|
209
153
|
|
|
210
154
|
/**
|
|
211
155
|
* Gets input for a specific controller.
|
|
212
156
|
* Returns validated and typed input if schema is provided, otherwise raw Record.
|
|
213
|
-
*
|
|
157
|
+
* Applies configured input behavior semantics.
|
|
214
158
|
*/
|
|
215
159
|
getInput(controllerId: string): z.infer<TSchema> | undefined {
|
|
216
160
|
const rawInput = this.inputBuffer.get(controllerId);
|
|
@@ -234,15 +178,10 @@ export class InputManager<TSchema extends z.ZodSchema = z.ZodSchema> {
|
|
|
234
178
|
validatedInput = result.data as Record<string, unknown>;
|
|
235
179
|
}
|
|
236
180
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
validatedInput as Record<string, unknown>,
|
|
242
|
-
) as z.infer<TSchema>;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return validatedInput as z.infer<TSchema>;
|
|
181
|
+
return this.applyBehaviors(
|
|
182
|
+
controllerId,
|
|
183
|
+
validatedInput as Record<string, unknown>,
|
|
184
|
+
) as z.infer<TSchema>;
|
|
246
185
|
}
|
|
247
186
|
|
|
248
187
|
/**
|
|
@@ -250,127 +189,168 @@ export class InputManager<TSchema extends z.ZodSchema = z.ZodSchema> {
|
|
|
250
189
|
*/
|
|
251
190
|
clearInput(controllerId: string): void {
|
|
252
191
|
this.inputBuffer.delete(controllerId);
|
|
253
|
-
this.
|
|
192
|
+
this.behaviorState.delete(controllerId);
|
|
254
193
|
}
|
|
255
194
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
rawInput: TInput,
|
|
262
|
-
): TInput | undefined {
|
|
263
|
-
const { booleanFields = [], vectorFields = [] } = this.config.latch!;
|
|
264
|
-
const state = this.latchState.get(controllerId);
|
|
265
|
-
|
|
266
|
-
// Simple hash to detect if raw input changed
|
|
267
|
-
const rawHash = JSON.stringify(rawInput);
|
|
268
|
-
const rawChanged = rawHash !== state?.lastRawHash;
|
|
269
|
-
|
|
270
|
-
// If raw hasn't changed and we have previous state, we already consumed
|
|
271
|
-
// Return raw (reset behavior - like old popInput did)
|
|
272
|
-
if (!rawChanged && state) {
|
|
273
|
-
// Reset latched to raw for next frame (consume behavior)
|
|
274
|
-
const resetLatched = { ...rawInput } as TInput;
|
|
275
|
-
const resetLatchedRecord = resetLatched as Record<string, unknown>;
|
|
276
|
-
const actualRawRecord = rawInput as Record<string, unknown>;
|
|
277
|
-
|
|
278
|
-
// Reset boolean fields to raw
|
|
279
|
-
for (const field of booleanFields) {
|
|
280
|
-
const rawValue = actualRawRecord[field];
|
|
281
|
-
resetLatchedRecord[field] = rawValue ?? false;
|
|
282
|
-
}
|
|
195
|
+
private getBehaviorState(controllerId: string): ControllerBehaviorState {
|
|
196
|
+
const existing = this.behaviorState.get(controllerId);
|
|
197
|
+
if (existing) {
|
|
198
|
+
return existing;
|
|
199
|
+
}
|
|
283
200
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
201
|
+
const created: ControllerBehaviorState = {
|
|
202
|
+
pulseBooleans: new Set<string>(),
|
|
203
|
+
pulseVectors: new Map<string, VectorValue>(),
|
|
204
|
+
holdVectors: new Map<string, VectorValue>(),
|
|
205
|
+
};
|
|
206
|
+
this.behaviorState.set(controllerId, created);
|
|
207
|
+
return created;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private createBehaviorOverrides(
|
|
211
|
+
behavior: InputConfig<TSchema>["behavior"],
|
|
212
|
+
): Map<string, InputFieldBehavior> {
|
|
213
|
+
const overrides = new Map<string, InputFieldBehavior>();
|
|
214
|
+
|
|
215
|
+
const assign = (fields: string[] | undefined, mode: InputFieldBehavior) => {
|
|
216
|
+
for (const field of fields ?? []) {
|
|
217
|
+
const existing = overrides.get(field);
|
|
218
|
+
if (existing && existing !== mode) {
|
|
219
|
+
throw new Error(
|
|
220
|
+
`[InputManager] Field "${field}" is configured for both "${existing}" and "${mode}".`,
|
|
221
|
+
);
|
|
300
222
|
}
|
|
223
|
+
overrides.set(field, mode);
|
|
301
224
|
}
|
|
225
|
+
};
|
|
302
226
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
latched: resetLatched,
|
|
307
|
-
lastRawHash: rawHash,
|
|
308
|
-
});
|
|
227
|
+
assign(behavior?.pulse, "pulse");
|
|
228
|
+
assign(behavior?.hold, "hold");
|
|
229
|
+
assign(behavior?.latest, "latest");
|
|
309
230
|
|
|
310
|
-
|
|
231
|
+
return overrides;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private resolveFieldBehavior(
|
|
235
|
+
field: string,
|
|
236
|
+
value: unknown,
|
|
237
|
+
): InputFieldBehavior {
|
|
238
|
+
const override = this.behaviorOverrides.get(field);
|
|
239
|
+
if (override) {
|
|
240
|
+
return override;
|
|
241
|
+
}
|
|
242
|
+
if (typeof value === "boolean") {
|
|
243
|
+
return "pulse";
|
|
311
244
|
}
|
|
245
|
+
if (this.isVectorValue(value)) {
|
|
246
|
+
return "latest";
|
|
247
|
+
}
|
|
248
|
+
return "latest";
|
|
249
|
+
}
|
|
312
250
|
|
|
313
|
-
|
|
314
|
-
|
|
251
|
+
private isVectorValue(value: unknown): value is VectorValue {
|
|
252
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
const vector = value as { x?: unknown; y?: unknown };
|
|
256
|
+
return typeof vector.x === "number" && typeof vector.y === "number";
|
|
257
|
+
}
|
|
315
258
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
259
|
+
private isActiveVector(vector: VectorValue): boolean {
|
|
260
|
+
return vector.x !== 0 || vector.y !== 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private captureTransientBehaviors(
|
|
264
|
+
controllerId: string,
|
|
265
|
+
rawInput: Record<string, unknown>,
|
|
266
|
+
): void {
|
|
267
|
+
const state = this.getBehaviorState(controllerId);
|
|
320
268
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const rawValue = actualRawRecord[field];
|
|
324
|
-
const prevValue = prevLatchedRecord[field];
|
|
269
|
+
for (const [field, value] of Object.entries(rawInput)) {
|
|
270
|
+
const behavior = this.resolveFieldBehavior(field, value);
|
|
325
271
|
|
|
326
|
-
if (
|
|
327
|
-
|
|
328
|
-
|
|
272
|
+
if (behavior === "pulse") {
|
|
273
|
+
if (typeof value === "boolean") {
|
|
274
|
+
if (value) {
|
|
275
|
+
state.pulseBooleans.add(field);
|
|
276
|
+
}
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (this.isVectorValue(value) && this.isActiveVector(value)) {
|
|
280
|
+
state.pulseVectors.set(field, value);
|
|
281
|
+
}
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (behavior === "hold" && this.isVectorValue(value)) {
|
|
286
|
+
if (this.isActiveVector(value)) {
|
|
287
|
+
state.holdVectors.set(field, value);
|
|
288
|
+
}
|
|
329
289
|
}
|
|
330
290
|
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private applyBehaviors<TInput extends Record<string, unknown>>(
|
|
294
|
+
controllerId: string,
|
|
295
|
+
validatedInput: TInput,
|
|
296
|
+
): TInput {
|
|
297
|
+
const state = this.getBehaviorState(controllerId);
|
|
298
|
+
const output = { ...validatedInput } as Record<string, unknown>;
|
|
299
|
+
const processedFields = new Set<string>();
|
|
300
|
+
|
|
301
|
+
for (const [field, value] of Object.entries(validatedInput)) {
|
|
302
|
+
processedFields.add(field);
|
|
303
|
+
const behavior = this.resolveFieldBehavior(field, value);
|
|
304
|
+
|
|
305
|
+
if (behavior === "latest") {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (behavior === "pulse") {
|
|
310
|
+
if (typeof value === "boolean") {
|
|
311
|
+
const pending = state.pulseBooleans.has(field);
|
|
312
|
+
output[field] = value === true || pending;
|
|
313
|
+
state.pulseBooleans.delete(field);
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
331
316
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
if (
|
|
338
|
-
rawValue &&
|
|
339
|
-
typeof rawValue === "object" &&
|
|
340
|
-
!Array.isArray(rawValue)
|
|
341
|
-
) {
|
|
342
|
-
const rawVec = rawValue as { x?: unknown; y?: unknown };
|
|
343
|
-
const prevVec = prevValue as { x?: unknown; y?: unknown } | undefined;
|
|
344
|
-
|
|
345
|
-
if (typeof rawVec.x === "number" && typeof rawVec.y === "number") {
|
|
346
|
-
const isRawActive = rawVec.x !== 0 || rawVec.y !== 0;
|
|
347
|
-
const isPrevActive =
|
|
348
|
-
prevVec &&
|
|
349
|
-
typeof prevVec.x === "number" &&
|
|
350
|
-
typeof prevVec.y === "number" &&
|
|
351
|
-
(prevVec.x !== 0 || prevVec.y !== 0);
|
|
352
|
-
|
|
353
|
-
if (isRawActive) {
|
|
354
|
-
// Currently active - use current value
|
|
355
|
-
latchedRecord[field] = rawVec;
|
|
356
|
-
} else if (isPrevActive) {
|
|
357
|
-
// Just released but was active - keep previous value (flick)
|
|
358
|
-
latchedRecord[field] = prevVec;
|
|
359
|
-
} else {
|
|
360
|
-
// Not active - use zero
|
|
361
|
-
latchedRecord[field] = { x: 0, y: 0 };
|
|
317
|
+
if (this.isVectorValue(value)) {
|
|
318
|
+
const pending = state.pulseVectors.get(field);
|
|
319
|
+
if (pending) {
|
|
320
|
+
output[field] = this.isActiveVector(value) ? value : pending;
|
|
321
|
+
state.pulseVectors.delete(field);
|
|
362
322
|
}
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// hold
|
|
330
|
+
if (this.isVectorValue(value)) {
|
|
331
|
+
if (this.isActiveVector(value)) {
|
|
332
|
+
state.holdVectors.set(field, value);
|
|
333
|
+
output[field] = value;
|
|
334
|
+
} else {
|
|
335
|
+
output[field] = state.holdVectors.get(field) ?? { x: 0, y: 0 };
|
|
363
336
|
}
|
|
364
337
|
}
|
|
365
338
|
}
|
|
366
339
|
|
|
367
|
-
//
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
340
|
+
// Include pending pulse values for optional fields not present in current payload.
|
|
341
|
+
for (const field of Array.from(state.pulseBooleans)) {
|
|
342
|
+
if (!processedFields.has(field)) {
|
|
343
|
+
output[field] = true;
|
|
344
|
+
state.pulseBooleans.delete(field);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
for (const [field, vector] of Array.from(state.pulseVectors.entries())) {
|
|
348
|
+
if (!processedFields.has(field)) {
|
|
349
|
+
output[field] = vector;
|
|
350
|
+
state.pulseVectors.delete(field);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
373
353
|
|
|
374
|
-
return
|
|
354
|
+
return output as TInput;
|
|
375
355
|
}
|
|
376
356
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const standardMatchPhases = [
|
|
2
|
+
"lobby",
|
|
3
|
+
"countdown",
|
|
4
|
+
"playing",
|
|
5
|
+
"ended",
|
|
6
|
+
] as const;
|
|
7
|
+
|
|
8
|
+
export type StandardMatchPhase = (typeof standardMatchPhases)[number];
|
|
9
|
+
export type ShellMatchPhase = Exclude<StandardMatchPhase, "countdown">;
|
|
10
|
+
|
|
11
|
+
export const isStandardMatchPhase = (
|
|
12
|
+
value: string,
|
|
13
|
+
): value is StandardMatchPhase => {
|
|
14
|
+
return (standardMatchPhases as readonly string[]).includes(value);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const isActiveMatchPhase = (phase: StandardMatchPhase): boolean => {
|
|
18
|
+
return phase === "countdown" || phase === "playing";
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const isEndedMatchPhase = (phase: StandardMatchPhase): boolean => {
|
|
22
|
+
return phase === "ended";
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const toShellMatchPhase = (
|
|
26
|
+
phase: StandardMatchPhase,
|
|
27
|
+
): ShellMatchPhase => {
|
|
28
|
+
if (phase === "countdown") {
|
|
29
|
+
return "playing";
|
|
30
|
+
}
|
|
31
|
+
return phase;
|
|
32
|
+
};
|