lecodes-cli 0.19.0 → 0.20.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/README.md +1 -0
- package/dist/index.js +1069 -396
- package/package.json +14 -13
- package/runtime/scene-harness.json +1 -1
- package/runtime/sdk-types.json +1 -1
- package/runtime/web/assets/Roboto-Variable-DHm9jpd-.woff2 +0 -0
- package/runtime/web/assets/__vite-browser-external-BIHI7g3E.js +1 -0
- package/runtime/web/assets/basis-C64VHDVD.js +1 -0
- package/runtime/web/assets/basis_transcoder-VXdx5NbI.wasm +0 -0
- package/runtime/web/assets/createViewerLite-BvHobVhp.js +852 -0
- package/runtime/web/assets/draco-BiISTFcR.js +118 -0
- package/runtime/web/assets/draco_decoder-DsQ12WqX.wasm +0 -0
- package/runtime/web/assets/index-CfNCCBjN.js +2 -0
- package/runtime/web/assets/mapViewImpl-B2JcES8l.js +810 -0
- package/runtime/web/assets/maplibre-gl-worker-CJfwIrte.js +8 -0
- package/runtime/web/assets/neutral_ibl128-D-lzdkLN.ktx +0 -0
- package/runtime/web/assets/worker-Caf-yYEI.js +2 -0
- package/runtime/web/embed.html +32 -0
- package/runtime/web/embed.js +171 -0
- package/src/api.ts +302 -0
- package/src/browserAuth.ts +87 -0
- package/src/cmgenTool.ts +104 -0
- package/src/commands/app.ts +896 -0
- package/src/commands/appAndroid.ts +603 -0
- package/src/commands/appDesktop.ts +339 -0
- package/src/commands/appDesktopMac.ts +470 -0
- package/src/commands/appIcon.ts +187 -0
- package/src/commands/appShared.ts +542 -0
- package/src/commands/appTemplates.ts +907 -0
- package/src/commands/appTemplatesAndroid.ts +599 -0
- package/src/commands/appTemplatesGradlew.ts +9 -0
- package/src/commands/assets.ts +28 -0
- package/src/commands/clone.ts +60 -0
- package/src/commands/compile.ts +253 -0
- package/src/commands/create.ts +59 -0
- package/src/commands/design.ts +863 -0
- package/src/commands/designTemplates.ts +11 -0
- package/src/commands/desktop.ts +127 -0
- package/src/commands/dev.ts +236 -0
- package/src/commands/diff.ts +59 -0
- package/src/commands/init.ts +191 -0
- package/src/commands/install.ts +198 -0
- package/src/commands/lightmap.ts +290 -0
- package/src/commands/link.ts +147 -0
- package/src/commands/login.ts +24 -0
- package/src/commands/navmesh.ts +225 -0
- package/src/commands/pn.ts +305 -0
- package/src/commands/projectTemplates.ts +130 -0
- package/src/commands/pull.ts +109 -0
- package/src/commands/push.ts +173 -0
- package/src/commands/render.ts +416 -0
- package/src/commands/scene.ts +148 -0
- package/src/commands/shaders.ts +157 -0
- package/src/commands/status.ts +29 -0
- package/src/commands/test.ts +371 -0
- package/src/commands/thumbs.ts +178 -0
- package/src/commands/types.ts +87 -0
- package/src/commands/update.ts +190 -0
- package/src/compile/assetIcons.ts +214 -0
- package/src/compile/collect.ts +46 -0
- package/src/compile/collectLocal.ts +37 -0
- package/src/compile/designCompile.ts +104 -0
- package/src/compile/fonts.ts +156 -0
- package/src/compile/headlessBundle.ts +129 -0
- package/src/compile/nativeStack.ts +21 -0
- package/src/compile/projectCompile.ts +109 -0
- package/src/compile/sceneCompile.ts +113 -0
- package/src/compile/screenEntry.ts +127 -0
- package/src/compile/shaders.ts +245 -0
- package/src/config.ts +42 -0
- package/src/designMeta.ts +35 -0
- package/src/desktopRenderer.ts +545 -0
- package/src/desktopScript.ts +276 -0
- package/src/dev/clientTemplates.ts +160 -0
- package/src/dev/devServer.ts +333 -0
- package/src/dev/webRunner.ts +22 -0
- package/src/dev/wsServer.ts +144 -0
- package/src/distRoot.ts +20 -0
- package/src/ignore.ts +163 -0
- package/src/index.ts +494 -0
- package/src/lecodes-3d-editor.d.ts +41 -0
- package/src/lecodes-assets.d.ts +7 -0
- package/src/lecodes-design.d.ts +191 -0
- package/src/lecodes-renderer.d.ts +131 -0
- package/src/localFiles.ts +144 -0
- package/src/manifest.ts +46 -0
- package/src/matcTool.ts +137 -0
- package/src/peers.ts +40 -0
- package/src/project.ts +61 -0
- package/src/projectEnv.ts +94 -0
- package/src/qrcode-terminal.d.ts +9 -0
- package/src/releases.ts +125 -0
- package/src/serverDiff.ts +78 -0
- package/src/textDiff.ts +103 -0
- package/src/types.ts +0 -0
- package/src/util.ts +146 -0
- package/runtime/sdk/animate/animate.ts +0 -238
- package/runtime/sdk/animate/bezier.ts +0 -138
- package/runtime/sdk/animate/easings.ts +0 -126
- package/runtime/sdk/canvas/Canvas.ts +0 -305
- package/runtime/sdk/compile/aspectMacro.ts +0 -86
- package/runtime/sdk/compile/assetIconMacro.ts +0 -384
- package/runtime/sdk/compile/assetMacro.ts +0 -146
- package/runtime/sdk/compile/assetName.ts +0 -50
- package/runtime/sdk/compile/bundler.ts +0 -287
- package/runtime/sdk/compile/compileProject.ts +0 -129
- package/runtime/sdk/compile/detectEntry.ts +0 -128
- package/runtime/sdk/compile/fontMacro.ts +0 -459
- package/runtime/sdk/compile/fontRegistry.ts +0 -78
- package/runtime/sdk/compile/header.ts +0 -67
- package/runtime/sdk/compile/index.ts +0 -100
- package/runtime/sdk/compile/libraryImports.ts +0 -52
- package/runtime/sdk/compile/liteMaterial.ts +0 -247
- package/runtime/sdk/compile/sceneEditor.ts +0 -88
- package/runtime/sdk/compile/serverSplit.ts +0 -233
- package/runtime/sdk/compile/serverTypes.ts +0 -227
- package/runtime/sdk/compile/sfnt.ts +0 -98
- package/runtime/sdk/compile/shaderSchema.ts +0 -202
- package/runtime/sdk/compile/shaderTargets.ts +0 -81
- package/runtime/sdk/compile/sourcemap.ts +0 -25
- package/runtime/sdk/core/Aspect.ts +0 -568
- package/runtime/sdk/core/InspectorUI.ts +0 -212
- package/runtime/sdk/core/StateMachine.ts +0 -308
- package/runtime/sdk/core/color.ts +0 -66
- package/runtime/sdk/core/compWrite.ts +0 -42
- package/runtime/sdk/core/events.ts +0 -38
- package/runtime/sdk/core/fields.ts +0 -120
- package/runtime/sdk/core/registry.ts +0 -23
- package/runtime/sdk/core/signals.ts +0 -277
- package/runtime/sdk/core/time.ts +0 -84
- package/runtime/sdk/g2/Camera2D.ts +0 -40
- package/runtime/sdk/g2/CharacterController2D.ts +0 -276
- package/runtime/sdk/g2/Node2D.ts +0 -267
- package/runtime/sdk/g2/OneWay2D.ts +0 -66
- package/runtime/sdk/g2/Physics2D.ts +0 -346
- package/runtime/sdk/g2/Scene2D.ts +0 -209
- package/runtime/sdk/g2/Shape2D.ts +0 -259
- package/runtime/sdk/g2/Sprite.ts +0 -89
- package/runtime/sdk/g2/SpriteAnimation.ts +0 -171
- package/runtime/sdk/g2/SpriteSheet.ts +0 -166
- package/runtime/sdk/g2/Texture2D.ts +0 -47
- package/runtime/sdk/g2/Tilemap.ts +0 -41
- package/runtime/sdk/g2/Tileset.ts +0 -71
- package/runtime/sdk/g2/Trigger2D.ts +0 -77
- package/runtime/sdk/g2/autotile.ts +0 -433
- package/runtime/sdk/g2/cells.ts +0 -91
- package/runtime/sdk/g2/defineScene2d.ts +0 -381
- package/runtime/sdk/g2/groups2d.ts +0 -106
- package/runtime/sdk/g2/loop.ts +0 -50
- package/runtime/sdk/g2/scenarios2d.ts +0 -69
- package/runtime/sdk/g2/touch.ts +0 -83
- package/runtime/sdk/gl/Camera.ts +0 -160
- package/runtime/sdk/gl/CameraPlace.ts +0 -52
- package/runtime/sdk/gl/CharacterController.ts +0 -238
- package/runtime/sdk/gl/Gearbox.ts +0 -212
- package/runtime/sdk/gl/Geometry.ts +0 -279
- package/runtime/sdk/gl/IK.ts +0 -193
- package/runtime/sdk/gl/InstancedMesh.ts +0 -132
- package/runtime/sdk/gl/Light.ts +0 -107
- package/runtime/sdk/gl/Lightmap.ts +0 -256
- package/runtime/sdk/gl/Material.ts +0 -260
- package/runtime/sdk/gl/Mesh.ts +0 -83
- package/runtime/sdk/gl/Model.ts +0 -124
- package/runtime/sdk/gl/NavAgent.ts +0 -337
- package/runtime/sdk/gl/NavMesh.ts +0 -397
- package/runtime/sdk/gl/Node.ts +0 -350
- package/runtime/sdk/gl/Noise.ts +0 -30
- package/runtime/sdk/gl/Particles.ts +0 -676
- package/runtime/sdk/gl/Physics.ts +0 -222
- package/runtime/sdk/gl/Plane.ts +0 -53
- package/runtime/sdk/gl/Ragdoll.ts +0 -270
- package/runtime/sdk/gl/Ray.ts +0 -16
- package/runtime/sdk/gl/Scene.ts +0 -486
- package/runtime/sdk/gl/Shape.ts +0 -409
- package/runtime/sdk/gl/Terrain.ts +0 -1092
- package/runtime/sdk/gl/Texture.ts +0 -63
- package/runtime/sdk/gl/Trigger.ts +0 -45
- package/runtime/sdk/gl/Vehicle.ts +0 -473
- package/runtime/sdk/gl/Wheel.ts +0 -240
- package/runtime/sdk/gl/animation/AnimationClip.ts +0 -204
- package/runtime/sdk/gl/animation/Animator.ts +0 -120
- package/runtime/sdk/gl/animation/Layer.ts +0 -31
- package/runtime/sdk/gl/animation/Loop.ts +0 -30
- package/runtime/sdk/gl/animation/Playback.ts +0 -44
- package/runtime/sdk/gl/animation/core.ts +0 -336
- package/runtime/sdk/gl/controls.ts +0 -95
- package/runtime/sdk/gl/physicsEvents.ts +0 -20
- package/runtime/sdk/gl/scenarios.ts +0 -291
- package/runtime/sdk/gl/state.ts +0 -6
- package/runtime/sdk/gl/terrainMesh.ts +0 -219
- package/runtime/sdk/gl/touch.ts +0 -68
- package/runtime/sdk/inject.ts +0 -197
- package/runtime/sdk/math/Mathf.ts +0 -118
- package/runtime/sdk/math/mat4.ts +0 -278
- package/runtime/sdk/math/quat.ts +0 -232
- package/runtime/sdk/math/vec.ts +0 -255
- package/runtime/sdk/net/codec.ts +0 -119
- package/runtime/sdk/net/core.ts +0 -384
- package/runtime/sdk/net/index.ts +0 -181
- package/runtime/sdk/net/replication.ts +0 -622
- package/runtime/sdk/plugins/camera.ts +0 -81
- package/runtime/sdk/plugins/geolocation.ts +0 -123
- package/runtime/sdk/plugins/oauth.ts +0 -61
- package/runtime/sdk/plugins/permission.ts +0 -7
- package/runtime/sdk/plugins/push.ts +0 -132
- package/runtime/sdk/plugins/qr.ts +0 -73
- package/runtime/sdk/plugins/service.ts +0 -47
- package/runtime/sdk/runtime/app.ts +0 -101
- package/runtime/sdk/runtime/appEvents.ts +0 -54
- package/runtime/sdk/runtime/channel.ts +0 -61
- package/runtime/sdk/runtime/clipboard.ts +0 -20
- package/runtime/sdk/runtime/datetime.ts +0 -329
- package/runtime/sdk/runtime/device.ts +0 -293
- package/runtime/sdk/runtime/fetch.ts +0 -77
- package/runtime/sdk/runtime/files.ts +0 -23
- package/runtime/sdk/runtime/input.ts +0 -175
- package/runtime/sdk/runtime/media.ts +0 -111
- package/runtime/sdk/runtime/misc.ts +0 -16
- package/runtime/sdk/runtime/net.ts +0 -36
- package/runtime/sdk/runtime/rpc.ts +0 -218
- package/runtime/sdk/runtime/service.ts +0 -83
- package/runtime/sdk/runtime/share.ts +0 -9
- package/runtime/sdk/runtime/storage.ts +0 -13
- package/runtime/sdk/runtime/touch.ts +0 -76
- package/runtime/sdk/scene/defineScene.ts +0 -1353
- package/runtime/sdk/scene/editorPlugins.ts +0 -110
- package/runtime/sdk/scene/gizmos.ts +0 -148
- package/runtime/sdk/scene/grammar.ts +0 -120
- package/runtime/sdk/scene/material.ts +0 -188
- package/runtime/sdk/server/auth/appConfig.ts +0 -12
- package/runtime/sdk/server/auth/global.ts +0 -80
- package/runtime/sdk/server/auth/host.ts +0 -318
- package/runtime/sdk/server/auth/models.ts +0 -83
- package/runtime/sdk/server/auth/types.ts +0 -50
- package/runtime/sdk/server/channel.ts +0 -56
- package/runtime/sdk/server/context.ts +0 -36
- package/runtime/sdk/server/db/defineDb.ts +0 -237
- package/runtime/sdk/server/db/fields.ts +0 -132
- package/runtime/sdk/server/db/httpTransport.ts +0 -93
- package/runtime/sdk/server/db/index.ts +0 -7
- package/runtime/sdk/server/db/marci/query.ts +0 -412
- package/runtime/sdk/server/db/types.ts +0 -202
- package/runtime/sdk/server/errors.ts +0 -12
- package/runtime/sdk/server/host.ts +0 -74
- package/runtime/sdk/server/inject.ts +0 -13
- package/runtime/sdk/server/runtime.ts +0 -133
- package/runtime/sdk/server/validate.ts +0 -87
- package/runtime/sdk/ui/NativeView.ts +0 -142
- package/runtime/sdk/ui/UI.ts +0 -39
- package/runtime/sdk/ui/UIBottomSheet.ts +0 -139
- package/runtime/sdk/ui/UIButton.ts +0 -101
- package/runtime/sdk/ui/UIContainer.ts +0 -60
- package/runtime/sdk/ui/UIImage.ts +0 -83
- package/runtime/sdk/ui/UIInput.ts +0 -185
- package/runtime/sdk/ui/UIModal.ts +0 -139
- package/runtime/sdk/ui/UINode.ts +0 -830
- package/runtime/sdk/ui/UIPager.ts +0 -362
- package/runtime/sdk/ui/UIPopover.ts +0 -100
- package/runtime/sdk/ui/UIScreen.ts +0 -123
- package/runtime/sdk/ui/UIScrollable.ts +0 -87
- package/runtime/sdk/ui/UISpacer.ts +0 -14
- package/runtime/sdk/ui/UITabs.ts +0 -236
- package/runtime/sdk/ui/UIText.ts +0 -51
- package/runtime/sdk/ui/UIVideo.ts +0 -88
- package/runtime/sdk/ui/UIVirtualizedList.ts +0 -241
- package/runtime/sdk/ui/UIWidget.ts +0 -127
- package/runtime/sdk/ui/fonts.ts +0 -13
- package/runtime/sdk/ui/presentable.ts +0 -117
- package/runtime/sdk/ui/router.ts +0 -132
- package/runtime/sdk/ui/theme.ts +0 -84
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
// Platform info + the host resize event. The resize listener registers with the host lazily on the
|
|
2
|
-
// first subscription (no top-level side effect, so tree-shaking can drop this entirely if unused).
|
|
3
|
-
|
|
4
|
-
import { Quat } from "../math/quat"
|
|
5
|
-
import { Vec3 } from "../math/vec"
|
|
6
|
-
import { appEventsOn, appEventsOff } from "./appEvents"
|
|
7
|
-
|
|
8
|
-
type ResizeCallback = (width: number, height: number) => void
|
|
9
|
-
|
|
10
|
-
type HdrChangeCallback = (headroom: number) => void
|
|
11
|
-
|
|
12
|
-
type DeviceEventMap = {
|
|
13
|
-
resize: ResizeCallback
|
|
14
|
-
/** Connectivity came back (best-effort, navigator.onLine semantics). */
|
|
15
|
-
online: () => void
|
|
16
|
-
/** Connectivity was lost. */
|
|
17
|
-
offline: () => void
|
|
18
|
-
/** The headroom the 3D engine renders to moved (`device.hdr.headroom`): the display ramped up to
|
|
19
|
-
* its peak after launch, brightness changed, the window went to another screen. */
|
|
20
|
-
hdrchange: HdrChangeCallback
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const resizeListeners: ResizeCallback[] = []
|
|
24
|
-
let resizeRegistered = false
|
|
25
|
-
|
|
26
|
-
const onResize = (width: number, height: number): void => {
|
|
27
|
-
for (const cb of resizeListeners.slice()) cb(width, height)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// --- device.hdr state ---
|
|
31
|
-
// The 3D bridge is a free global that a 2D-only bundle never defines — reach it defensively. Hosts
|
|
32
|
-
// without the methods are SDR by definition; the look setters are remembered so the getters read
|
|
33
|
-
// back what the app asked for.
|
|
34
|
-
const gl = (): typeof _creator | undefined => (typeof _creator !== "undefined" ? _creator : undefined)
|
|
35
|
-
let hdrStrengthLocal = 0.35
|
|
36
|
-
let hdrPaperWhiteLocal = 1
|
|
37
|
-
// `hdrchange` is a poll: the engine quantises the headroom to half-stops, so a change is rare and
|
|
38
|
-
// a 4 Hz timer (only while someone listens) is cheaper than a per-frame bridge call.
|
|
39
|
-
const hdrListeners: HdrChangeCallback[] = []
|
|
40
|
-
let hdrPollTimer: ReturnType<typeof setInterval> | undefined
|
|
41
|
-
let hdrLastHeadroom = 1
|
|
42
|
-
const pollHdr = (): void => {
|
|
43
|
-
const h = device.hdr.headroom
|
|
44
|
-
if (h === hdrLastHeadroom) return
|
|
45
|
-
hdrLastHeadroom = h
|
|
46
|
-
for (const cb of hdrListeners.slice()) cb(h)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Semantic haptic styles for `device.vibrate`. Impact styles (`light`/`medium`/`heavy`/`soft`/
|
|
50
|
-
* `rigid`) are a physical "tap" of varying weight; notification styles (`success`/`warning`/`error`)
|
|
51
|
-
* cue an outcome; `selection` is a light tick for a value change. Chosen to map 1:1 onto iOS
|
|
52
|
-
* `UIFeedbackGenerator` and, on Android, `HapticFeedbackConstants` / `VibrationEffect` — so the same
|
|
53
|
-
* call feels native everywhere, rather than a duration that only web/Android can honor. */
|
|
54
|
-
export type HapticStyle =
|
|
55
|
-
| "light" | "medium" | "heavy" | "soft" | "rigid"
|
|
56
|
-
| "success" | "warning" | "error"
|
|
57
|
-
| "selection"
|
|
58
|
-
|
|
59
|
-
/** Options for `device.motion.start`. */
|
|
60
|
-
export interface MotionOptions {
|
|
61
|
-
/** Sensor update interval in seconds (default 1/60). The sensor fuses at ≥ this rate in the
|
|
62
|
-
* background; you poll the freshest sample each frame, so this is a floor, not a sync. */
|
|
63
|
-
interval?: number
|
|
64
|
-
/** Frame the readables are delivered in. "world" (default): engine Y-up, screen-oriented — drops
|
|
65
|
-
* straight into `camera.quaternion` / any node. "device": the raw sensor frame, no conversion. */
|
|
66
|
-
frame?: "world" | "device"
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// --- device.motion state (pull-per-frame model) ---
|
|
70
|
-
let motionEnabled = false
|
|
71
|
-
let motionFrame: "world" | "device" = "world"
|
|
72
|
-
let motionYawOffset = 0 // radians about world up, captured by recenter()
|
|
73
|
-
|
|
74
|
-
// Calibration constants — VERIFY ON A PHYSICAL DEVICE (the simulator reports no motion).
|
|
75
|
-
// • CM_TO_WORLD: Core Motion's reference frame is Z-up; the engine world is Y-up. If a level horizon
|
|
76
|
-
// reads tilted ~90°, this is the term to check.
|
|
77
|
-
// • ORIENTATION_ROLL: roll about the view axis so camera-up tracks screen-up, indexed by the native
|
|
78
|
-
// interface-orientation code [portrait, landscapeLeft, landscapeRight, upsideDown]. If landscape is
|
|
79
|
-
// upside-down or rolled the wrong way, flip the ±π/2 signs.
|
|
80
|
-
// If the whole panorama turns the wrong way (look right → view goes left), conjugate `raw` below.
|
|
81
|
-
const CM_TO_WORLD = Quat.fromAxisAngle([1, 0, 0], -Math.PI / 2)
|
|
82
|
-
const ORIENTATION_ROLL = [0, Math.PI / 2, -Math.PI / 2, Math.PI]
|
|
83
|
-
|
|
84
|
-
// Device attitude → engine world frame, with the interface-orientation roll folded in (yaw NOT yet
|
|
85
|
-
// recentered). Shared by `attitude` (which adds the recenter) and `gravity` (which is yaw-invariant).
|
|
86
|
-
const orientedAttitude = (s: ArrayLike<number>): Quat => {
|
|
87
|
-
const raw = new Quat(s[0], s[1], s[2], s[3])
|
|
88
|
-
const roll = Quat.fromAxisAngle([0, 0, 1], ORIENTATION_ROLL[s[7]] ?? 0)
|
|
89
|
-
return CM_TO_WORLD.mul(raw).mul(roll)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export const device = {
|
|
93
|
-
/** Which INPUT MODEL the app is running under — the thing to branch on when a build needs
|
|
94
|
-
* mouse-look instead of on-screen sticks. It is not the OS name: a Mac reports `"desktop"`,
|
|
95
|
-
* like Windows and Linux do (the OS/version detail is host-side, not here). */
|
|
96
|
-
get platform(): "web" | "android" | "ios" | "desktop" | string {
|
|
97
|
-
return _creatorUtils.platform
|
|
98
|
-
},
|
|
99
|
-
get language(): string {
|
|
100
|
-
return _creatorUtils.language
|
|
101
|
-
},
|
|
102
|
-
/** Display device-pixel ratio (physical px per logical/CSS px): 1 on standard displays, 2–3 on
|
|
103
|
-
* retina / iOS. Bake a Canvas at this ratio for crisp output without hardcoding, e.g.
|
|
104
|
-
* `new Canvas(w, h, { pixelRatio: device.pixelRatio })`. NOTE: the web 2D/GL surface currently
|
|
105
|
-
* renders at logical resolution, so on web this only helps UI canvases / is forward-looking for
|
|
106
|
-
* 2D; on iOS (physical surface) it makes 2D canvases crisp. Falls back to 1 if the host omits it. */
|
|
107
|
-
get pixelRatio(): number {
|
|
108
|
-
return _creatorUtils.pixelRatio || 1
|
|
109
|
-
},
|
|
110
|
-
/** Current display width in logical px — the same value the "resize" event delivers, but readable at
|
|
111
|
-
* any time (not only inside the listener). 0 until the host has reported a size. */
|
|
112
|
-
get width(): number {
|
|
113
|
-
return _creatorUI.getDisplaySize?.()?.[0] ?? 0
|
|
114
|
-
},
|
|
115
|
-
/** Current display height in logical px — the same value the "resize" event delivers, readable at any
|
|
116
|
-
* time. 0 until the host has reported a size. */
|
|
117
|
-
get height(): number {
|
|
118
|
-
return _creatorUI.getDisplaySize?.()?.[1] ?? 0
|
|
119
|
-
},
|
|
120
|
-
/** Opt into the precise-touch system where the platform supports it. OFF by default. When on, fast
|
|
121
|
-
* strokes are sampled at the touch digitizer's full rate (iOS coalesced touches, ≈120–240 Hz) instead
|
|
122
|
-
* of once per display frame (~60 Hz), so a pointer-heavy app (drawing, handwriting, dragging) gets more
|
|
123
|
-
* points and smoother lines. Leave it off for tap/button UIs. No-op on hosts without a coalesced-input
|
|
124
|
-
* concept (web already coalesces pointermove; headless). */
|
|
125
|
-
setPreciseTouch(enabled: boolean): void {
|
|
126
|
-
_creatorUtils.setPreciseTouch?.(enabled)
|
|
127
|
-
},
|
|
128
|
-
/** Fire a one-shot haptic of the given semantic `style` (default `"medium"`) — a physical tap on
|
|
129
|
-
* supported hardware (iOS Taptic Engine, Android vibrator). Chosen by meaning, not duration, so it
|
|
130
|
-
* feels native on each platform; see {@link HapticStyle}. Host-gated: a silent no-op where there's
|
|
131
|
-
* no haptic hardware (iPad, older iPhones, web, headless). */
|
|
132
|
-
vibrate(style: HapticStyle = "medium"): void {
|
|
133
|
-
_creatorUtils.vibrate?.(style)
|
|
134
|
-
},
|
|
135
|
-
/** Device-orientation sensor (gyro + accelerometer, fused) for tilt/steering and magic-window /
|
|
136
|
-
* 360° panoramas. Poll `attitude` / `gravity` inside setLoop; they return the freshest fused
|
|
137
|
-
* sample, so the sensor rate need not match your frame rate. Host-gated: a no-op with no sensor. */
|
|
138
|
-
motion: {
|
|
139
|
-
/** Whether this device has the motion sensors at all (no gyro → false; iPad/older, web, headless). */
|
|
140
|
-
get available(): boolean {
|
|
141
|
-
return _creatorUtils.motionAvailable?.() ?? false
|
|
142
|
-
},
|
|
143
|
-
/** Whether updates are currently running (start succeeded and stop hasn't been called). */
|
|
144
|
-
get enabled(): boolean {
|
|
145
|
-
return motionEnabled
|
|
146
|
-
},
|
|
147
|
-
/** Begin sensor updates. Resolves to whether it actually started (false = no sensor / denied).
|
|
148
|
-
* Async so a web host can await its permission prompt; native resolves immediately. */
|
|
149
|
-
async start(options: MotionOptions = {}): Promise<boolean> {
|
|
150
|
-
motionFrame = options.frame ?? "world"
|
|
151
|
-
motionEnabled = !!(await (_creatorUtils.motionStart?.(options.interval ?? 1 / 60) ?? false))
|
|
152
|
-
return motionEnabled
|
|
153
|
-
},
|
|
154
|
-
/** Stop sensor updates and release the sensor (battery). */
|
|
155
|
-
stop(): void {
|
|
156
|
-
_creatorUtils.motionStop?.()
|
|
157
|
-
motionEnabled = false
|
|
158
|
-
},
|
|
159
|
-
/** Capture the current heading as "forward" — a yaw-only recenter (pitch/roll stay gravity-
|
|
160
|
-
* referenced, so the horizon stays level). No-op in the "device" frame. */
|
|
161
|
-
recenter(): void {
|
|
162
|
-
const s = _creatorUtils.getMotionSample?.()
|
|
163
|
-
if (!s || motionFrame === "device") { motionYawOffset = 0; return }
|
|
164
|
-
const f = orientedAttitude(s).rotateVec3([0, 0, -1]) // world-space camera forward
|
|
165
|
-
motionYawOffset = Math.atan2(-f.x, -f.z) // heading about world up
|
|
166
|
-
},
|
|
167
|
-
/** The device's current orientation as a `Quat`. In the "world" frame (default) it's engine Y-up
|
|
168
|
-
* and screen-oriented, so `camera.quaternion = device.motion.attitude` is a complete magic-window
|
|
169
|
-
* / panorama camera. `Quat.identity` until the first sample arrives / when not running. */
|
|
170
|
-
get attitude(): Quat {
|
|
171
|
-
const s = _creatorUtils.getMotionSample?.()
|
|
172
|
-
if (!s) return Quat.identity
|
|
173
|
-
if (motionFrame === "device") return new Quat(s[0], s[1], s[2], s[3])
|
|
174
|
-
const q = orientedAttitude(s)
|
|
175
|
-
return Quat.fromAxisAngle([0, 1, 0], -motionYawOffset).mul(q) // yaw recenter (world-frame)
|
|
176
|
-
},
|
|
177
|
-
/** Gravity direction for tilt controls. In the "world" frame it's SCREEN space (x → right, y →
|
|
178
|
-
* down, matching clientX/clientY), orientation-aware — a 2D game reads `gravity.x / gravity.y`.
|
|
179
|
-
* `(0,0,0)` when not running. */
|
|
180
|
-
get gravity(): Vec3 {
|
|
181
|
-
const s = _creatorUtils.getMotionSample?.()
|
|
182
|
-
if (!s) return new Vec3(0, 0, 0)
|
|
183
|
-
if (motionFrame === "device") return new Vec3(s[4], s[5], s[6])
|
|
184
|
-
// Re-express the raw device-frame gravity in screen space: undo the interface roll (about the
|
|
185
|
-
// screen normal), then flip Y to screen-down. Uses the unambiguous CMDeviceMotion.gravity, so
|
|
186
|
-
// it stays correct regardless of the attitude-quaternion convention above.
|
|
187
|
-
const unroll = Quat.fromAxisAngle([0, 0, 1], -(ORIENTATION_ROLL[s[7]] ?? 0))
|
|
188
|
-
const g = new Vec3(s[4], s[5], s[6]).rotate(unroll)
|
|
189
|
-
return new Vec3(g.x, -g.y, g.z)
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
/** The display's extended dynamic range — HDR. On a screen with headroom above SDR white (Apple's
|
|
193
|
-
* XDR panels; the macOS host today) the 3D surface is float and the engine renders past 1.0:
|
|
194
|
-
* 1.0 is the white of the UI and of a diffuse white surface, and the sun, emissives and speculars
|
|
195
|
-
* climb up to `headroom` times that. Everywhere else it is SDR: `available` false, `headroom` 1,
|
|
196
|
-
* the look setters remembered but invisible.
|
|
197
|
-
*
|
|
198
|
-
* Branch content on `available`, not on `headroom` — the live value ramps up from 1 over the
|
|
199
|
-
* first seconds after launch and follows the brightness keys. Particle `emissive` is the thing
|
|
200
|
-
* to raise: it is in post-exposure units (1 = white on screen) and everything above that clips on
|
|
201
|
-
* SDR, so an HDR display is the only place a fireball peaking at 8 reads as one. */
|
|
202
|
-
hdr: {
|
|
203
|
-
/** Whether the surface can show anything above SDR white at all (`maxHeadroom > 1`). */
|
|
204
|
-
get available(): boolean {
|
|
205
|
-
return device.hdr.maxHeadroom > 1
|
|
206
|
-
},
|
|
207
|
-
/** The peak the display can reach, as a multiple of SDR white (a 1600-nit XDR panel reports up
|
|
208
|
-
* to 16). Constant for the surface; 1 on SDR. */
|
|
209
|
-
get maxHeadroom(): number {
|
|
210
|
-
const v = gl()?.getDisplayMaxHeadroom?.() ?? 1
|
|
211
|
-
return v > 1 ? v : 1
|
|
212
|
-
},
|
|
213
|
-
/** The headroom the engine renders to right now — the screen's current peak as a multiple of SDR
|
|
214
|
-
* white, quantised to half-stops. Moves with brightness and the screen under the window
|
|
215
|
-
* (`hdrchange` event); never below 1. */
|
|
216
|
-
get headroom(): number {
|
|
217
|
-
const v = gl()?.getDisplayHeadroom?.() ?? 1
|
|
218
|
-
return v > 1 ? v : 1
|
|
219
|
-
},
|
|
220
|
-
/** How much of the picture reaches for the headroom, 0..1 (default 0.35). 0 touches only what
|
|
221
|
-
* SDR clipped — faithful to the SDR grade, but a mostly-mid-tone frame then looks flat next to
|
|
222
|
-
* the one bright spot; 1 lifts nearly everything above black toward the peak. A sunlit exterior
|
|
223
|
-
* takes 1, a dim interior wants less. A host may pin it (`LECODES_HDR_STRENGTH`). */
|
|
224
|
-
get strength(): number {
|
|
225
|
-
return gl()?.getHdrStrength?.() ?? hdrStrengthLocal
|
|
226
|
-
},
|
|
227
|
-
set strength(v: number) {
|
|
228
|
-
const s = Number.isFinite(v) ? Math.min(1, Math.max(0, v)) : 0.35
|
|
229
|
-
hdrStrengthLocal = s
|
|
230
|
-
gl()?.setHdrStrength?.(s)
|
|
231
|
-
},
|
|
232
|
-
/** Where white lands, as a multiple of SDR white, 1..8 (default 1) — the "HDR brightness" of a
|
|
233
|
-
* console game's calibration screen, where paper white sits at ~200 nits against SDR's ~100.
|
|
234
|
-
* It scales the WHOLE picture: at 1 a white wall is as bright as the UI's white, at 2 it is
|
|
235
|
-
* twice that, and highlights still climb above it (the engine keeps `headroom / paperWhite` for
|
|
236
|
-
* them, clamped at the peak). `strength` decides how much of the picture reaches for the
|
|
237
|
-
* peak; this decides where the picture starts. 1.5–2 is the console norm; a game that wants to
|
|
238
|
-
* read as "HDR on" rather than "SDR with a brighter sun" wants this over `strength`. A host may
|
|
239
|
-
* pin it (`LECODES_HDR_PAPER_WHITE`). */
|
|
240
|
-
get paperWhite(): number {
|
|
241
|
-
return gl()?.getHdrPaperWhite?.() ?? hdrPaperWhiteLocal
|
|
242
|
-
},
|
|
243
|
-
set paperWhite(v: number) {
|
|
244
|
-
const p = Number.isFinite(v) ? Math.min(8, Math.max(1, v)) : 1
|
|
245
|
-
hdrPaperWhiteLocal = p
|
|
246
|
-
gl()?.setHdrPaperWhite?.(p)
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
/** Current connectivity — best-effort navigator.onLine semantics: `false` only when the platform
|
|
250
|
-
* is sure there's no network. `true` on hosts that don't track it. Change events: `"online"` /
|
|
251
|
-
* `"offline"`. */
|
|
252
|
-
get online(): boolean {
|
|
253
|
-
return _creatorUtils.isOnline?.() ?? true
|
|
254
|
-
},
|
|
255
|
-
addEventListener<E extends keyof DeviceEventMap>(channel: E, callback: DeviceEventMap[E]): void {
|
|
256
|
-
if (channel === "online" || channel === "offline") {
|
|
257
|
-
appEventsOn(channel, callback as () => void)
|
|
258
|
-
return
|
|
259
|
-
}
|
|
260
|
-
if (channel === "hdrchange") {
|
|
261
|
-
hdrListeners.push(callback as HdrChangeCallback)
|
|
262
|
-
if (hdrPollTimer === undefined) {
|
|
263
|
-
hdrLastHeadroom = device.hdr.headroom
|
|
264
|
-
hdrPollTimer = setInterval(pollHdr, 250)
|
|
265
|
-
}
|
|
266
|
-
return
|
|
267
|
-
}
|
|
268
|
-
if (channel !== "resize") return
|
|
269
|
-
resizeListeners.push(callback as ResizeCallback)
|
|
270
|
-
if (!resizeRegistered) {
|
|
271
|
-
resizeRegistered = true
|
|
272
|
-
_creatorUI.registerResizeEvent(onResize)
|
|
273
|
-
}
|
|
274
|
-
},
|
|
275
|
-
removeEventListener<E extends keyof DeviceEventMap>(channel: E, callback: DeviceEventMap[E]): void {
|
|
276
|
-
if (channel === "online" || channel === "offline") {
|
|
277
|
-
appEventsOff(channel, callback as () => void)
|
|
278
|
-
return
|
|
279
|
-
}
|
|
280
|
-
if (channel === "hdrchange") {
|
|
281
|
-
const i = hdrListeners.indexOf(callback as HdrChangeCallback)
|
|
282
|
-
if (i >= 0) hdrListeners.splice(i, 1)
|
|
283
|
-
if (hdrListeners.length === 0 && hdrPollTimer !== undefined) {
|
|
284
|
-
clearInterval(hdrPollTimer)
|
|
285
|
-
hdrPollTimer = undefined
|
|
286
|
-
}
|
|
287
|
-
return
|
|
288
|
-
}
|
|
289
|
-
if (channel !== "resize") return
|
|
290
|
-
const i = resizeListeners.indexOf(callback as ResizeCallback)
|
|
291
|
-
if (i >= 0) resizeListeners.splice(i, 1)
|
|
292
|
-
},
|
|
293
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// HTTP via the host. `fetch` is async (host streams the body), `fetchLocal` reads a preloaded asset
|
|
2
|
-
// synchronously. Ported from worker/src/fetch.ts over the same _creatorUtils bridge.
|
|
3
|
-
|
|
4
|
-
export type FetchOptions = {
|
|
5
|
-
body?: any
|
|
6
|
-
method?: string
|
|
7
|
-
headers?: Record<string, string>
|
|
8
|
-
useOnce?: boolean
|
|
9
|
-
onProgress?: (progress: { loaded: number, total?: number }) => void
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface FetchResponse {
|
|
13
|
-
readonly status: number
|
|
14
|
-
json<T = any>(): T
|
|
15
|
-
text(): string
|
|
16
|
-
dispose(): void
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
class FetchResponseImpl implements FetchResponse {
|
|
20
|
-
readonly status: number
|
|
21
|
-
private readonly _id: number
|
|
22
|
-
constructor(id: number, status: number) {
|
|
23
|
-
this._id = id
|
|
24
|
-
this.status = status
|
|
25
|
-
}
|
|
26
|
-
json<T = any>(): T {
|
|
27
|
-
return _creatorUtils.fetchToJson(this._id)
|
|
28
|
-
}
|
|
29
|
-
text(): string {
|
|
30
|
-
return _creatorUtils.fetchToText(this._id)
|
|
31
|
-
}
|
|
32
|
-
dispose(): void {
|
|
33
|
-
_creatorUtils.disposeFetch(this._id)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const fetch = (url: string, options: FetchOptions = {}): Promise<FetchResponse> =>
|
|
38
|
-
new Promise<FetchResponse>((resolve, reject) => {
|
|
39
|
-
_creatorUtils.fetch(url, options, (systemId, statusCode) => {
|
|
40
|
-
resolve(new FetchResponseImpl(systemId, statusCode))
|
|
41
|
-
}, reject)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
export const fetchLocal = (path: string): FetchResponse =>
|
|
45
|
-
new FetchResponseImpl(_creatorUtils.fetchLocal(path), 200)
|
|
46
|
-
|
|
47
|
-
/** A handle to a picked / fetched file (see openFilePicker). */
|
|
48
|
-
export class File {
|
|
49
|
-
/** @internal host buffer handle. `_`-prefixed because hosts read it off the raw object —
|
|
50
|
-
* same key `FetchResponse` carries, so both are accepted anywhere a buffer is expected
|
|
51
|
-
* (FormData entries, `UIImage` src, `Texture.load`, `share`). */
|
|
52
|
-
readonly _id: number
|
|
53
|
-
readonly name: string
|
|
54
|
-
readonly size: number
|
|
55
|
-
constructor(systemId: number, name: string, size: number) {
|
|
56
|
-
this._id = systemId
|
|
57
|
-
this.name = name
|
|
58
|
-
this.size = size
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
type FormDataValue = string | number | boolean | File | FetchResponse
|
|
63
|
-
|
|
64
|
-
export class FormData {
|
|
65
|
-
// Host-facing: hosts walk `_entries` and treat any object value carrying `_id` as binary
|
|
66
|
-
// (the buffer id), everything else as a text field. See viewer-lite utils/fetch.ts,
|
|
67
|
-
// creator-pkg creatorUtilsHandler.cpp, iOS Fetch.swift buildMultipartBody.
|
|
68
|
-
private _entries: [string, FormDataValue, filename?: string][] = []
|
|
69
|
-
|
|
70
|
-
append(name: string, value: FormDataValue, filename?: string): void {
|
|
71
|
-
this._entries.push([ name, value, filename ?? (typeof value === "object" ? (value as any).name : undefined) ])
|
|
72
|
-
}
|
|
73
|
-
delete(name: string): void {
|
|
74
|
-
const index = this._entries.findIndex((i) => i[0] === name)
|
|
75
|
-
if (index >= 0) this._entries.splice(index, 1)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Native file picker. Ported from worker/src/utils/openFilePicker.ts; resolves to File handle(s)
|
|
2
|
-
// (see runtime/fetch.ts) that can be appended to a FormData and uploaded.
|
|
3
|
-
|
|
4
|
-
import { File } from "./fetch"
|
|
5
|
-
|
|
6
|
-
type OpenFilePickerOptions = { accept?: string }
|
|
7
|
-
|
|
8
|
-
export function openFilePicker(options?: OpenFilePickerOptions & { multiple?: false }): Promise<File | null>
|
|
9
|
-
export function openFilePicker(options: OpenFilePickerOptions & { multiple: true }): Promise<File[]>
|
|
10
|
-
export function openFilePicker(
|
|
11
|
-
options: OpenFilePickerOptions & { multiple?: boolean } = {},
|
|
12
|
-
): Promise<File | File[] | null> {
|
|
13
|
-
return new Promise((resolve, reject) => {
|
|
14
|
-
_creatorUtils.openFilePicker((resp) => {
|
|
15
|
-
if (!resp || resp.length === 0) {
|
|
16
|
-
resolve(options.multiple ? [] : null)
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
if (options.multiple) resolve(resp.map((i: any) => new File(i[0], i[1], i[2])))
|
|
20
|
-
else resolve(new File(resp[0][0], resp[0][1], resp[0][2]))
|
|
21
|
-
}, reject, !!options.multiple, options.accept)
|
|
22
|
-
})
|
|
23
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
// Keyboard / mouse / gamepad input behind one `Input` global (docs/input-plan.md).
|
|
2
|
-
//
|
|
3
|
-
// Two kinds of signal, two shapes of API:
|
|
4
|
-
// - BUTTONS — anything that goes down and up: keyboard keys, mouse buttons, gamepad buttons. One
|
|
5
|
-
// code vocabulary ('KeyW', 'MouseLeft', 'GamepadSouth'), one held-poll (`Input.key`) and one
|
|
6
|
-
// event pair (`Input.on('keydown' | 'keyup')`). A mouse button IS a key.
|
|
7
|
-
// - CONTINUOUS — mouse motion/wheel, sticks, triggers: polled every frame (`Input.mouse.delta`,
|
|
8
|
-
// `Input.gamepad(0).axis('leftX')`), never events.
|
|
9
|
-
// Bindings ("jump = Space | GamepadSouth") are app code: compare `e.code`, OR a few `Input.key`s.
|
|
10
|
-
// Hosts report physical state only (`_creatorUtils.inputKey/inputRead/registerInputEvent`).
|
|
11
|
-
|
|
12
|
-
/** Continuous channel ids — the `_creatorUtils.inputRead` contract (bridges.d.ts). */
|
|
13
|
-
export const InputChannel = {
|
|
14
|
-
MouseX: 0, MouseY: 1, MouseDX: 2, MouseDY: 3, WheelX: 4, WheelY: 5, PointerLocked: 6,
|
|
15
|
-
GamepadCount: 7,
|
|
16
|
-
GamepadBase: 16, GamepadStride: 16,
|
|
17
|
-
PadConnected: 0, PadLeftX: 1, PadLeftY: 2, PadRightX: 3, PadRightY: 4, PadLeftTrigger: 5, PadRightTrigger: 6,
|
|
18
|
-
} as const
|
|
19
|
-
|
|
20
|
-
export type InputEventName = "keydown" | "keyup" | "gamepadconnected" | "gamepaddisconnected"
|
|
21
|
-
|
|
22
|
-
/** `keydown` / `keyup` payload. `code` is the same string `Input.key()` takes. */
|
|
23
|
-
export interface InputKeyEvent {
|
|
24
|
-
readonly type: "keydown" | "keyup"
|
|
25
|
-
/** Button code: KeyboardEvent.code ('KeyW', 'Space'), 'MouseLeft|Right|Middle|Back|Forward', or
|
|
26
|
-
* 'GamepadSouth|East|West|North|L1|R1|L2|R2|Select|Start|L3|R3|Up|Down|Left|Right'. */
|
|
27
|
-
readonly code: string
|
|
28
|
-
/** Which device: 'keyboard' | 'mouse' | 'gamepad'. */
|
|
29
|
-
readonly source: "keyboard" | "mouse" | "gamepad"
|
|
30
|
-
/** Pad index (0..3) for gamepad buttons, undefined otherwise. */
|
|
31
|
-
readonly gamepad?: number
|
|
32
|
-
/** OS auto-repeat keydown (key still held) — ignore for one-shot actions. */
|
|
33
|
-
readonly repeat: boolean
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface InputGamepadEvent {
|
|
37
|
-
readonly type: "gamepadconnected" | "gamepaddisconnected"
|
|
38
|
-
readonly gamepad: number
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type Listener<E> = (e: E) => void
|
|
42
|
-
type InputEventMap = {
|
|
43
|
-
keydown: InputKeyEvent
|
|
44
|
-
keyup: InputKeyEvent
|
|
45
|
-
gamepadconnected: InputGamepadEvent
|
|
46
|
-
gamepaddisconnected: InputGamepadEvent
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const listeners: { [K in InputEventName]?: Listener<InputEventMap[K]>[] } = {}
|
|
50
|
-
let hostListenerInstalled = false
|
|
51
|
-
|
|
52
|
-
const sourceOf = (code: string): InputKeyEvent["source"] =>
|
|
53
|
-
code.startsWith("Mouse") ? "mouse" : code.startsWith("Gamepad") ? "gamepad" : "keyboard"
|
|
54
|
-
|
|
55
|
-
const emit = <K extends InputEventName>(name: K, e: InputEventMap[K]) => {
|
|
56
|
-
const list = listeners[name]
|
|
57
|
-
if (!list || list.length === 0) return
|
|
58
|
-
for (const fn of [...list]) fn(e as any)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// One fan-out for the host channel and the test/host `_emit` seam.
|
|
62
|
-
const deliver = (kind: number, code: string, gamepad: number, repeat: number) => {
|
|
63
|
-
if (kind === 0 || kind === 1) {
|
|
64
|
-
const src = sourceOf(code)
|
|
65
|
-
emit(kind === 0 ? "keydown" : "keyup", {
|
|
66
|
-
type: kind === 0 ? "keydown" : "keyup", code, source: src,
|
|
67
|
-
gamepad: src === "gamepad" && gamepad >= 0 ? gamepad : undefined, repeat: repeat !== 0,
|
|
68
|
-
})
|
|
69
|
-
} else if (kind === 2 || kind === 3) {
|
|
70
|
-
emit(kind === 2 ? "gamepadconnected" : "gamepaddisconnected",
|
|
71
|
-
{ type: kind === 2 ? "gamepadconnected" : "gamepaddisconnected", gamepad })
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Lazily claim the host's single listener slot (never at module scope — chisel drops top-level
|
|
76
|
-
// side effects, and a host without the channel simply never fires).
|
|
77
|
-
const ensureHostListener = () => {
|
|
78
|
-
if (hostListenerInstalled) return
|
|
79
|
-
hostListenerInstalled = true
|
|
80
|
-
_creatorUtils.registerInputEvent?.(deliver)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const read = (channel: number): number => _creatorUtils.inputRead?.(channel) ?? 0
|
|
84
|
-
|
|
85
|
-
/** Mouse state — polled. Position is the cursor inside the viewport in logical px; `delta` is the
|
|
86
|
-
* motion during the previous frame (raw where the OS offers it) and keeps counting while locked —
|
|
87
|
-
* that's FPS look. Hosts without a mouse report zeros. */
|
|
88
|
-
export const mouse = {
|
|
89
|
-
get position(): { x: number, y: number } { return { x: read(InputChannel.MouseX), y: read(InputChannel.MouseY) } },
|
|
90
|
-
get delta(): { x: number, y: number } { return { x: read(InputChannel.MouseDX), y: read(InputChannel.MouseDY) } },
|
|
91
|
-
/** Wheel notches during the previous frame (+y = wheel toward you / scroll down). */
|
|
92
|
-
get wheel(): { x: number, y: number } { return { x: read(InputChannel.WheelX), y: read(InputChannel.WheelY) } },
|
|
93
|
-
/** Pointer lock: cursor hidden + confined, `delta` keeps flowing. Web grants it only from a user
|
|
94
|
-
* gesture (call it in a 'keydown' handler for MouseLeft); hosts drop it on focus loss and
|
|
95
|
-
* re-acquire on focus. Escape does NOT unlock by itself on native hosts — call `unlock()`. */
|
|
96
|
-
get locked(): boolean { return read(InputChannel.PointerLocked) !== 0 },
|
|
97
|
-
lock(): boolean { return _creatorUtils.inputSetPointerLock?.(true) ?? false },
|
|
98
|
-
unlock(): void { _creatorUtils.inputSetPointerLock?.(false) },
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export type GamepadAxisName = "leftX" | "leftY" | "rightX" | "rightY" | "leftTrigger" | "rightTrigger"
|
|
102
|
-
const PAD_AXIS: Record<GamepadAxisName, number> = {
|
|
103
|
-
leftX: InputChannel.PadLeftX, leftY: InputChannel.PadLeftY, rightX: InputChannel.PadRightX,
|
|
104
|
-
rightY: InputChannel.PadRightY, leftTrigger: InputChannel.PadLeftTrigger, rightTrigger: InputChannel.PadRightTrigger,
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface GamepadState {
|
|
108
|
-
readonly index: number
|
|
109
|
-
readonly connected: boolean
|
|
110
|
-
/** Stick axes −1..1 (+Y = down, like the web Gamepad API), triggers 0..1. `deadzone` (default
|
|
111
|
-
* 0.15) zeroes small stick drift — pass 0 for the raw value. */
|
|
112
|
-
axis(name: GamepadAxisName, deadzone?: number): number
|
|
113
|
-
/** Held? Same as `Input.key(code, index)`. */
|
|
114
|
-
button(code: string): boolean
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const padCache: GamepadState[] = []
|
|
118
|
-
const gamepadAt = (index: number): GamepadState => {
|
|
119
|
-
let g = padCache[index]
|
|
120
|
-
if (!g) {
|
|
121
|
-
const base = InputChannel.GamepadBase + InputChannel.GamepadStride * index
|
|
122
|
-
g = padCache[index] = {
|
|
123
|
-
index,
|
|
124
|
-
get connected() { return read(base + InputChannel.PadConnected) !== 0 },
|
|
125
|
-
axis(name, deadzone = 0.15) {
|
|
126
|
-
const v = read(base + PAD_AXIS[name])
|
|
127
|
-
return deadzone > 0 && Math.abs(v) < deadzone ? 0 : v
|
|
128
|
-
},
|
|
129
|
-
button(code) { return _creatorUtils.inputKey(code, index) },
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return g
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export const Input = {
|
|
136
|
-
/**
|
|
137
|
-
* Is a button held? `code` is the physical key (`KeyboardEvent.code`: 'ArrowRight', 'KeyW',
|
|
138
|
-
* 'Space'), a mouse button ('MouseLeft', 'MouseRight', 'MouseMiddle') or a gamepad button
|
|
139
|
-
* ('GamepadSouth' = A/Cross, 'GamepadR2' = right trigger as a button …). Poll inside setLoop for
|
|
140
|
-
* frame-independent movement. `gamepad` scopes a Gamepad* code to one pad; omitted = any pad.
|
|
141
|
-
*/
|
|
142
|
-
key(code: string, gamepad?: number): boolean {
|
|
143
|
-
return _creatorUtils.inputKey(code, gamepad)
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
/** Listen for a discrete input moment. `keydown`/`keyup` cover EVERY button — keyboard, mouse,
|
|
147
|
-
* gamepad — filter on `e.code`. Use these for one-shot actions (jump, shoot, charge-release);
|
|
148
|
-
* `Input.key` for continuous ones (walk). */
|
|
149
|
-
on<K extends InputEventName>(name: K, listener: Listener<InputEventMap[K]>): void {
|
|
150
|
-
ensureHostListener()
|
|
151
|
-
const list = (listeners[name] ??= []) as Listener<InputEventMap[K]>[]
|
|
152
|
-
if (!list.includes(listener)) list.push(listener)
|
|
153
|
-
},
|
|
154
|
-
off<K extends InputEventName>(name: K, listener: Listener<InputEventMap[K]>): void {
|
|
155
|
-
const list = listeners[name] as Listener<InputEventMap[K]>[] | undefined
|
|
156
|
-
if (!list) return
|
|
157
|
-
const i = list.indexOf(listener)
|
|
158
|
-
if (i >= 0) list.splice(i, 1)
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
mouse,
|
|
162
|
-
|
|
163
|
-
/** Gamepad `index` (0..3). Always returns an object — check `.connected`. */
|
|
164
|
-
gamepad(index = 0): GamepadState { return gamepadAt(index) },
|
|
165
|
-
/** Indices of the currently connected gamepads. */
|
|
166
|
-
gamepads(): number[] {
|
|
167
|
-
const out: number[] = []
|
|
168
|
-
const n = read(InputChannel.GamepadCount)
|
|
169
|
-
for (let i = 0; i < 4 && out.length < n; i++) if (gamepadAt(i).connected) out.push(i)
|
|
170
|
-
return out
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
/** @internal — hosts/tests: deliver an event exactly as the host listener would. */
|
|
174
|
-
_emit(kind: number, code: string, gamepad: number, repeat: number): void { deliver(kind, code, gamepad, repeat) },
|
|
175
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// Audio / video playback over the host. Ported from worker/src/MediaPlayer.ts, with the listener
|
|
2
|
-
// boilerplate folded into the shared Emitter. VideoPlayer.texture (a 3D Texture) is wired in Phase 4
|
|
3
|
-
// when the Texture type exists — see gl/.
|
|
4
|
-
//
|
|
5
|
-
// The host no longer routes end-of-playback events back by id through a Registry: each player hands
|
|
6
|
-
// the host a `_finished` callback at creation time. The host holds the JS closure directly — valid
|
|
7
|
-
// on every backend (web JS, Android quickjs, iOS JavaScriptCore) — and invokes it when a play-through
|
|
8
|
-
// completes, so there is no id table to keep in sync.
|
|
9
|
-
|
|
10
|
-
import { Emitter } from "../core/events"
|
|
11
|
-
import { Texture } from "../gl/Texture"
|
|
12
|
-
|
|
13
|
-
type MediaEvents = {
|
|
14
|
-
/** Fired at each loop boundary while `loop` is true. */
|
|
15
|
-
loopReached: () => void
|
|
16
|
-
/** Fired once when playback reaches the end while `loop` is false. */
|
|
17
|
-
completed: () => void
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
abstract class MediaPlayer extends Emitter<MediaEvents> {
|
|
21
|
-
protected _id = -1
|
|
22
|
-
protected _src = ""
|
|
23
|
-
private _playing = false
|
|
24
|
-
private _loop = false
|
|
25
|
-
private _volume = 1
|
|
26
|
-
private _disposed = false
|
|
27
|
-
|
|
28
|
-
// Every host-touching operation runs through this so a disposed player can never address a freed
|
|
29
|
-
// (and possibly reused) host slot.
|
|
30
|
-
private _assertAlive(): void {
|
|
31
|
-
if (this._disposed) throw new Error("MediaPlayer has been disposed")
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
play(): void { this.playing = true }
|
|
35
|
-
pause(): void { this.playing = false }
|
|
36
|
-
|
|
37
|
-
get playing(): boolean { return this._playing }
|
|
38
|
-
set playing(value: boolean) {
|
|
39
|
-
this._assertAlive()
|
|
40
|
-
this._playing = value
|
|
41
|
-
_creatorUtils.updateMediaPlayerPlaying(this._id, value)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
get volume(): number { return this._volume }
|
|
45
|
-
set volume(value: number) {
|
|
46
|
-
this._assertAlive()
|
|
47
|
-
this._volume = value
|
|
48
|
-
_creatorUtils.updateMediaPlayerVolume(this._id, value)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get loop(): boolean { return this._loop }
|
|
52
|
-
set loop(value: boolean) {
|
|
53
|
-
this._assertAlive()
|
|
54
|
-
this._loop = value
|
|
55
|
-
_creatorUtils.updateMediaPlayerLoop(this._id, value)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Current playback position, in seconds. Settable to seek. */
|
|
59
|
-
get time(): number { this._assertAlive(); return _creatorUtils.getMediaPlayerTime(this._id) }
|
|
60
|
-
set time(value: number) { this._assertAlive(); _creatorUtils.setMediaPlayerTime(this._id, value) }
|
|
61
|
-
|
|
62
|
-
/** Total media length in seconds (0 until metadata has loaded). */
|
|
63
|
-
get duration(): number { this._assertAlive(); return _creatorUtils.getMediaPlayerDuration(this._id) }
|
|
64
|
-
|
|
65
|
-
/** True once {@link dispose} has been called; the player is unusable afterwards. */
|
|
66
|
-
get disposed(): boolean { return this._disposed }
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Release the underlying host media resource (decoder, network, buffers) immediately and detach
|
|
70
|
-
* all listeners. Idempotent. Any further use of the player throws.
|
|
71
|
-
*/
|
|
72
|
-
dispose(): void {
|
|
73
|
-
if (this._disposed) return
|
|
74
|
-
this._disposed = true
|
|
75
|
-
this._playing = false
|
|
76
|
-
this.clearListeners()
|
|
77
|
-
_creatorUtils.removeMediaPlayer(this._id)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** @internal — the host calls this when a play-through finishes. */
|
|
81
|
-
protected _finished(): void {
|
|
82
|
-
if (this._disposed) return
|
|
83
|
-
if (this._loop) {
|
|
84
|
-
this.dispatch("loopReached")
|
|
85
|
-
} else {
|
|
86
|
-
this._playing = false
|
|
87
|
-
this.dispatch("completed")
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export class AudioPlayer extends MediaPlayer {
|
|
93
|
-
constructor(src?: string) {
|
|
94
|
-
super()
|
|
95
|
-
this._src = src ?? ""
|
|
96
|
-
this._id = _creatorUtils.createAudioPlayer(this._src, () => this._finished())
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export class VideoPlayer extends MediaPlayer {
|
|
101
|
-
constructor(src?: string) {
|
|
102
|
-
super()
|
|
103
|
-
this._src = src ?? ""
|
|
104
|
-
this._id = _creatorUtils.createVideoPlayer(this._src, () => this._finished())
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** A 3D Texture that samples this video (e.g. for a Material.video()). */
|
|
108
|
-
get texture(): Texture {
|
|
109
|
-
return new Texture(0, 0, _creator.createMediaPlayerTexture(this._id))
|
|
110
|
-
}
|
|
111
|
-
}
|