@vgai/engine 0.2.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.
Files changed (147) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +35 -0
  3. package/package.json +55 -0
  4. package/src/adapter/authoring.ts +402 -0
  5. package/src/adapter/colyseus-networking-adapter.ts +72 -0
  6. package/src/adapter/first-party-systems.ts +103 -0
  7. package/src/adapter/game-adapter.ts +151 -0
  8. package/src/adapter/host-context.ts +77 -0
  9. package/src/adapter/index.ts +85 -0
  10. package/src/adapter/ingest/game-contract.ts +59 -0
  11. package/src/adapter/ingest/overlay-applier.ts +207 -0
  12. package/src/adapter/ingest/overlay-apply.ts +124 -0
  13. package/src/adapter/ingest/overlay-file.ts +126 -0
  14. package/src/adapter/ingest/overlay-report.ts +176 -0
  15. package/src/adapter/ingest/scene-capture.ts +307 -0
  16. package/src/adapter/ingest/upstream-pin.ts +52 -0
  17. package/src/adapter/loop-gate-report.ts +54 -0
  18. package/src/adapter/rapier-physics-adapter.ts +56 -0
  19. package/src/adapter/system-adapter.ts +154 -0
  20. package/src/adapter/transform.ts +18 -0
  21. package/src/adapter/vgai-scene-game-adapter.ts +886 -0
  22. package/src/adapter/world-kind.ts +34 -0
  23. package/src/ai/navigation.ts +164 -0
  24. package/src/animation/anim-graph-types.ts +56 -0
  25. package/src/animation/anim-graph.ts +406 -0
  26. package/src/animation/anim-system.ts +28 -0
  27. package/src/animation/blend-node.ts +119 -0
  28. package/src/animation/property-track.ts +178 -0
  29. package/src/animation/schema.ts +204 -0
  30. package/src/assets.ts +80 -0
  31. package/src/audio/ambient.ts +300 -0
  32. package/src/audio/impacts.ts +212 -0
  33. package/src/audio/index.ts +7 -0
  34. package/src/audio/movement.ts +140 -0
  35. package/src/audio/musical.ts +200 -0
  36. package/src/audio/ui-sounds.ts +171 -0
  37. package/src/audio/vehicle.ts +235 -0
  38. package/src/audio/weapons.ts +152 -0
  39. package/src/core/game-loop.ts +127 -0
  40. package/src/core/system-runner.ts +298 -0
  41. package/src/core/types.ts +58 -0
  42. package/src/dev/console-bridge.ts +83 -0
  43. package/src/dev/debug-draw.ts +80 -0
  44. package/src/dev/logger.ts +119 -0
  45. package/src/ecs/component-manager.ts +748 -0
  46. package/src/ecs/game-component.ts +147 -0
  47. package/src/ecs/hmr-swap-report.ts +65 -0
  48. package/src/input/input-manager.ts +439 -0
  49. package/src/input/input-types.ts +19 -0
  50. package/src/input/schema.ts +129 -0
  51. package/src/loader.ts +70 -0
  52. package/src/manifest/index.ts +24 -0
  53. package/src/manifest/load-file.ts +16 -0
  54. package/src/manifest/load.ts +378 -0
  55. package/src/manifest/schema.ts +375 -0
  56. package/src/physics/collision-system.ts +76 -0
  57. package/src/physics/physics-registry.ts +83 -0
  58. package/src/physics/transform-writer.ts +41 -0
  59. package/src/physics/trigger-dispatch.ts +97 -0
  60. package/src/react/game-state.tsx +172 -0
  61. package/src/render/auto-batcher.ts +169 -0
  62. package/src/render/render-batch-system.ts +268 -0
  63. package/src/render/render-features.ts +146 -0
  64. package/src/render/render-settings.ts +72 -0
  65. package/src/runtime/create-runtime.ts +1152 -0
  66. package/src/runtime/frame-selector-cache.ts +81 -0
  67. package/src/runtime/game.ts +1003 -0
  68. package/src/runtime/input-router.ts +213 -0
  69. package/src/runtime/mount-game.ts +269 -0
  70. package/src/runtime/mount-manifest.ts +361 -0
  71. package/src/runtime/scene-ui-bridge.ts +86 -0
  72. package/src/runtime/scene-ui-data.ts +119 -0
  73. package/src/runtime/state-bridge.ts +79 -0
  74. package/src/runtime/types.ts +196 -0
  75. package/src/scene/asset-loaders.ts +195 -0
  76. package/src/scene/asset-paths.ts +123 -0
  77. package/src/scene/asset-registry.ts +67 -0
  78. package/src/scene/collider-dimensions.ts +125 -0
  79. package/src/scene/component-registry.ts +40 -0
  80. package/src/scene/defaults.ts +164 -0
  81. package/src/scene/geometries/index.ts +7 -0
  82. package/src/scene/geometries/terrain.ts +42 -0
  83. package/src/scene/geometry-registry.ts +42 -0
  84. package/src/scene/instance-registry.ts +84 -0
  85. package/src/scene/instancers/grid.ts +38 -0
  86. package/src/scene/instancers/index.ts +7 -0
  87. package/src/scene/light-camera-factory.ts +97 -0
  88. package/src/scene/material-factory.ts +211 -0
  89. package/src/scene/material-registry.ts +73 -0
  90. package/src/scene/materials/index.ts +7 -0
  91. package/src/scene/materials/water.ts +56 -0
  92. package/src/scene/parse.ts +71 -0
  93. package/src/scene/particles-factory.ts +383 -0
  94. package/src/scene/scene-apply.ts +356 -0
  95. package/src/scene/scene-diff-schema.ts +115 -0
  96. package/src/scene/scene-diff-types.ts +29 -0
  97. package/src/scene/scene-loader.ts +1533 -0
  98. package/src/scene/scene-query.ts +63 -0
  99. package/src/scene/scene-types.ts +34 -0
  100. package/src/scene/scene-version.ts +40 -0
  101. package/src/scene/schema/animation.ts +95 -0
  102. package/src/scene/schema/audio.ts +25 -0
  103. package/src/scene/schema/camera.ts +21 -0
  104. package/src/scene/schema/collider.ts +69 -0
  105. package/src/scene/schema/entity-ref.ts +78 -0
  106. package/src/scene/schema/entity.ts +169 -0
  107. package/src/scene/schema/environment.ts +384 -0
  108. package/src/scene/schema/index.ts +95 -0
  109. package/src/scene/schema/instances.ts +35 -0
  110. package/src/scene/schema/joint.ts +26 -0
  111. package/src/scene/schema/light.ts +38 -0
  112. package/src/scene/schema/material.ts +113 -0
  113. package/src/scene/schema/mesh.ts +108 -0
  114. package/src/scene/schema/particles.ts +398 -0
  115. package/src/scene/schema/physics.ts +49 -0
  116. package/src/scene/schema/scene-file.ts +299 -0
  117. package/src/scene/schema/shadow.ts +24 -0
  118. package/src/scene/schema/spline.ts +21 -0
  119. package/src/scene/schema/tuples.ts +21 -0
  120. package/src/scene/schema/ui.ts +602 -0
  121. package/src/scene/user-data.ts +203 -0
  122. package/src/setup/setup-audio.ts +60 -0
  123. package/src/setup/setup-particles.ts +23 -0
  124. package/src/setup/setup-physics.ts +67 -0
  125. package/src/setup/setup-renderer.ts +529 -0
  126. package/src/types-n8ao.d.ts +37 -0
  127. package/src/types-realism-effects.d.ts +61 -0
  128. package/src/world2d/authoring-2d.ts +208 -0
  129. package/src/world2d/capture-to-scene2d.ts +52 -0
  130. package/src/world2d/collision-2d.ts +106 -0
  131. package/src/world2d/components-2d.ts +86 -0
  132. package/src/world2d/index.ts +66 -0
  133. package/src/world2d/ingest-iframe-2d.ts +255 -0
  134. package/src/world2d/ingest2d.ts +131 -0
  135. package/src/world2d/physics2d-registry.ts +49 -0
  136. package/src/world2d/pixi-game-adapter.ts +325 -0
  137. package/src/world2d/pixi-surface.ts +78 -0
  138. package/src/world2d/scene-capture-2d.ts +117 -0
  139. package/src/world2d/scene2d-loader.ts +308 -0
  140. package/src/world2d/schema/entity2d.ts +145 -0
  141. package/src/world2d/schema/physics2d.ts +53 -0
  142. package/src/world2d/schema/sprite.ts +71 -0
  143. package/src/world2d/schema/tilemap.ts +22 -0
  144. package/src/world2d/schema/tuples2d.ts +25 -0
  145. package/src/world2d/system-adapters-2d.ts +49 -0
  146. package/src/world2d/transform-writer-2d.ts +24 -0
  147. package/src/world2d/types.ts +55 -0
@@ -0,0 +1,402 @@
1
+ /**
2
+ * AuthoringAdapter — the editor's authoring contract. The editor talks to THIS,
3
+ * keyed by opaque string node ids, instead of to a concrete document format.
4
+ *
5
+ * `.vscn` / `SceneEntity` is the private model of ONE implementer
6
+ * (`VgaiSceneAuthoringAdapter`); an ingested game's adapter implements the same
7
+ * providers directly over its live `Object3D` tree. The editor sees only the
8
+ * interface and the advertised `capabilities` — it never branches on which
9
+ * implementer it is talking to.
10
+ *
11
+ * The interface lives in the engine (not the editor) so `MountedGame.authoring`
12
+ * can reference it without the engine depending on the editor; implementers live
13
+ * in `packages/editor/src/authoring/`.
14
+ *
15
+ * **Reserved inspector paths convention:** the property paths `name`, `visible`,
16
+ * and `locked` are reserved — an adapter that supports them exposes them through
17
+ * the ordinary `InspectorProvider.get`/`set` (no separate provider). The shell
18
+ * renders the hierarchy panel's rename field, eye (visibility) toggle, and lock
19
+ * toggle against these three paths, generically, for any adapter that reports
20
+ * them via `InspectorProvider.properties`.
21
+ */
22
+
23
+ import type * as THREE from 'three';
24
+ import type { SceneEntity } from '../scene/scene-types';
25
+ import type { Transform, TransformOwner } from './transform';
26
+
27
+ /** Booleans the editor UI gates affordances on (hide what an adapter can't do). */
28
+ export interface AuthoringCapabilities {
29
+ transform: boolean;
30
+ material: boolean;
31
+ inspectorFields: boolean;
32
+ create: boolean;
33
+ delete: boolean;
34
+ reparent: boolean;
35
+ persist: boolean;
36
+ /**
37
+ * UI layout authoring (anchors/offsets/pivot/flex) — distinct from 3D
38
+ * `transform`. Optional so existing 3D adapters need not declare it. A UI
39
+ * adapter sets this true and implements {@link LayoutProvider}; the 3D gizmo /
40
+ * TransformProvider are NOT the UI manipulation path (spec K7).
41
+ */
42
+ layout?: boolean;
43
+ }
44
+
45
+ /** A node in the authoring hierarchy — format-neutral (not a `SceneEntity`). */
46
+ export interface EditorNode {
47
+ /** STABLE id — survives reload (see ingest structural-path ids). */
48
+ id: string;
49
+ label: string;
50
+ kind: 'mesh' | 'light' | 'camera' | 'group' | 'object' | (string & {});
51
+ parentId: string | null;
52
+ childIds: string[];
53
+ flags: {
54
+ runtimeOnly?: boolean;
55
+ locked?: boolean;
56
+ transformOwner?: TransformOwner;
57
+ /** D8 — member of a RootGroup, not the active one; children may be unloaded. */
58
+ inactiveRoot?: boolean;
59
+ };
60
+ }
61
+
62
+ export interface PropertyDescriptor {
63
+ path: string;
64
+ label: string;
65
+ type: 'string' | 'number' | 'boolean' | 'vec3' | 'color' | 'enum' | 'asset' | 'json';
66
+ readonly?: boolean;
67
+ options?: unknown[];
68
+ /**
69
+ * Optional domain-shaped grouping (T3.4 slice 2, docs/ADAPTER-AUTHORING-
70
+ * DESIGN.md §1.E): properties sharing the same `group` label render
71
+ * together under a titled sub-section in the generic inspector, instead of
72
+ * the flat property grid. Backward-compatible — omitted (or two
73
+ * descriptors with different/no `group`) renders exactly as before this
74
+ * field existed. This is the ONLY authoring-richness addition v1 makes;
75
+ * there is no schema and no new PropertyDescriptor `type` — a custom
76
+ * adapter reports its own domain concepts (health/score/an enum, …) through
77
+ * the SAME provider, merely labeled into a named group.
78
+ */
79
+ group?: string;
80
+ }
81
+
82
+ export interface HierarchyProvider {
83
+ roots(): EditorNode[];
84
+ node(id: string): EditorNode | null;
85
+ /** The live object for raycast/gizmo binding (null for non-object nodes). */
86
+ object3D(id: string): THREE.Object3D | null;
87
+ idForObject3D(o: THREE.Object3D): string | null;
88
+ }
89
+
90
+ export interface SelectionProvider {
91
+ get(): string[];
92
+ set(ids: string[]): void;
93
+ }
94
+
95
+ export interface TransformProvider {
96
+ get(id: string): Transform;
97
+ owner(id: string): TransformOwner;
98
+ /** Pause whatever controller fights the gizmo (physics/script) for editing. */
99
+ beginEdit(id: string): void;
100
+ apply(id: string, t: Transform): void;
101
+ endEdit(id: string): void;
102
+ }
103
+
104
+ export interface InspectorProvider {
105
+ /** Schema-driven — NOT fixed to `SceneEntity`. */
106
+ properties(id: string): PropertyDescriptor[];
107
+ get(id: string, path: string): unknown;
108
+ set(id: string, path: string, value: unknown): void;
109
+ /**
110
+ * Optional — REMOVE a property's authored override entirely (not "set to a
111
+ * value"), letting whatever governs it in its absence take over. The one
112
+ * concrete need today: a longhand CSS override (`style.borderTopLeftRadius`)
113
+ * that a uniform edit of its shorthand (`style.borderRadius`) must clear so
114
+ * the shorthand actually wins, instead of leaving a stale longhand that
115
+ * silently overrides it on reload (spec 27 §5 C2, U2). Adapters with no
116
+ * removable-override concept simply omit it — callers optional-chain.
117
+ */
118
+ remove?(id: string, path: string): void;
119
+ }
120
+
121
+ /**
122
+ * UI layout authoring (K7) — anchors/offsets/pivot/flex props on a UI node. This
123
+ * is the manipulation path for the DOM-overlay UI editor (handles, anchor presets,
124
+ * flex inspector) and is deliberately SEPARATE from {@link TransformProvider}
125
+ * (which is 3D position/quaternion/scale and cannot express flex/anchor layout).
126
+ * The layout shape is format-neutral (a plain object the UI adapter understands).
127
+ */
128
+ export interface LayoutProvider {
129
+ /** The node's current layout object (anchors/offsets/pivot/flex), or null. */
130
+ get(id: string): Record<string, unknown> | null;
131
+ /** Pause whatever drives layout (animation) before a gesture, if needed. */
132
+ beginEdit(id: string): void;
133
+ /** Apply a (partial) layout patch — merged onto the node's layout. */
134
+ apply(id: string, layoutPatch: Record<string, unknown>): void;
135
+ /** Commit the gesture (one undo step). */
136
+ endEdit(id: string): void;
137
+ }
138
+
139
+ export interface StructureProvider {
140
+ create(kind: string, parentId?: string): string;
141
+ /**
142
+ * Remove `id`. May optionally return an awaitable (`Promise<void>`) when the
143
+ * underlying write is asynchronous (e.g. a react-world source-file edit) —
144
+ * `deleteSelection` (`editor-hotkeys.ts`) awaits it per id so a same-file
145
+ * multi-delete's writes land strictly one at a time (see that function's own
146
+ * doc comment for why serialization + deletion order together are what make
147
+ * a per-id loop sound for an adapter whose OID index isn't reindexed between
148
+ * writes). An adapter with a synchronous/in-memory remove (e.g.
149
+ * `UIAuthoringAdapter`) returns `void` — `await`ing it is a harmless no-op.
150
+ */
151
+ remove(id: string): void | Promise<void>;
152
+ duplicate(id: string): string;
153
+ reparent(id: string, newParentId: string | null): void;
154
+ /** Reorder `id` to sit immediately before `beforeSiblingId` among its siblings
155
+ * (`null` = move to the end). Absent ⇒ the shell has no sibling-reorder UI
156
+ * for this adapter. */
157
+ reorder?(id: string, beforeSiblingId: string | null): void;
158
+ /**
159
+ * The kinds `create` accepts for a given parent (`null` parentId = a new
160
+ * root), each with a display label — drives the shell's creation palette.
161
+ * Absent ⇒ the palette shows nothing for this adapter, even though `create`
162
+ * itself may still work when called directly (e.g. programmatically, or by
163
+ * an adapter-specific affordance outside the generic palette).
164
+ */
165
+ creatableKinds?(parentId: string | null): { kind: string; label: string }[];
166
+ /** D3 (spec 27 §6) — wrap `id` in a new container element (default tag
167
+ * adapter-chosen, e.g. a `div`), re-parenting `id` as that container's sole
168
+ * child. Absent ⇒ the shell's context menu shows no Wrap item for this
169
+ * adapter. */
170
+ wrap?(id: string, wrapperTag?: string): void;
171
+ /** D3 (spec 27 §6) — replace `id` with its own children (the inverse of
172
+ * `wrap`). Absent ⇒ the shell's context menu shows no Unwrap item for this
173
+ * adapter. */
174
+ unwrap?(id: string): void;
175
+ /**
176
+ * D4.R2 (spec27 §6 D4 reopen) — remove every id in `ids` as ONE undoable
177
+ * op (a single Ctrl+Z restores the whole batch), instead of the caller
178
+ * looping `remove(id)` per id (which — one `remove` call = one undo push
179
+ * per adapter, by design — produces N separate undo entries: Ctrl+Z then
180
+ * restores them one at a time, asymmetric with the first-party adapter's
181
+ * own single batched multi-delete undo). Absent ⇒ the shell falls back to
182
+ * the per-id `remove` loop (today's N-entry behavior, unchanged) — an
183
+ * honest degrade, not a silent behavior change, for any adapter that
184
+ * hasn't implemented batching. May optionally return an awaitable
185
+ * (`Promise<void>`), same widening `remove` documents above and for the
186
+ * same reason (delete-order-residual fix): `deleteSelection`
187
+ * (`editor-hotkeys.ts`) awaits it so the caller can rely on the whole
188
+ * batch's write having landed before it returns. A synchronous/in-memory
189
+ * implementation (e.g. `UIAuthoringAdapter`'s) returns `void` — awaiting it
190
+ * is a harmless no-op.
191
+ */
192
+ removeMany?(ids: readonly string[]): void | Promise<void>;
193
+ }
194
+
195
+ /**
196
+ * PersistenceProvider — whether and where an adapter's edits persist (design:
197
+ * `docs/PERSISTENCE-PROVIDER-DESIGN.md` §2). The ACTIVE adapter's provider is the
198
+ * ONE place this is decided — the host (editor) never hard-codes a destination or
199
+ * guards on session flags; it asks the provider.
200
+ */
201
+ export interface PersistenceProvider {
202
+ isDirty(): boolean;
203
+ /** Save to the adapter's OWN source of truth (.vscn / overlay file / …). */
204
+ save(): Promise<void>;
205
+ serialize(): unknown;
206
+ /** Migration aid (first-party direction): pull a subtree into `.vscn` entities. */
207
+ captureToVscn?(ids: string[]): SceneEntity[];
208
+ /**
209
+ * Human/agent-readable destination this provider persists to — e.g.
210
+ * `"scenes/main.vscn.json"`, `".vgai/overlays/fps.json"`, or `"ephemeral
211
+ * (discarded on stop)"`. Drives the save-status UI and makes routing
212
+ * inspectable (design §2). Implementers whose destination can change during
213
+ * the session (e.g. the first-party provider tracks the loaded `.vscn` path)
214
+ * should expose this as a live getter rather than a value captured once.
215
+ */
216
+ readonly destination: string;
217
+ /**
218
+ * The reload contract (design §5): apply an external change to this
219
+ * provider's persisted artifact into the RUNNING session (e.g. a file-watcher
220
+ * update to the `.vscn` or the overlay). Absent ⇒ the host must remount to
221
+ * pick up external changes (the honest floor). Implemented (T3.2 slice 3) by
222
+ * the first-party provider (`applyExternalUpdate`) and the ingest overlay
223
+ * provider (`applyOverlay`); absent (correctly) on the ephemeral provider.
224
+ *
225
+ * `rawContent`, when the host has it (the file-watcher SSE payload carries the
226
+ * artifact's exact bytes), is an OPTIONAL second parameter enabling own-echo
227
+ * detection — an event that is exactly what this provider itself last wrote is
228
+ * its own save reflected back, and should be skipped even outside the normal
229
+ * debounce window (see `EditorStore.applyExternalUpdate`'s doc comment). This
230
+ * stays optional/provider-specific — only the first-party provider currently
231
+ * uses it — so other implementers can ignore the parameter entirely.
232
+ */
233
+ applyExternal?(content: unknown, rawContent?: string): void;
234
+ }
235
+
236
+ /** D8 — mutually-exclusive root groups (radio roots): e.g. a "Scenes" group whose
237
+ * members are the game's scene roots, only one of which is loaded/active at a
238
+ * time (unlike ordinary sibling roots, which all coexist). */
239
+ export interface RootGroup {
240
+ id: string; // stable, e.g. 'scenes'
241
+ label: string; // 'Scenes'
242
+ memberRootIds: string[]; // EditorNode ids; each is a hierarchy root
243
+ activeRootId: string | null;
244
+ }
245
+ export interface RootGroupsProvider {
246
+ groups(): RootGroup[];
247
+ activate(groupId: string, rootId: string): Promise<void> | void;
248
+ }
249
+
250
+ /** D8 — data-file → root mapping ("opening a file" = activating its root). */
251
+ export interface FileMapProvider {
252
+ /** project-relative path → node id this adapter maps it to, else null. */
253
+ rootForFile(path: string): string | null;
254
+ }
255
+
256
+ /** D12 — per-layer viewport picking. Coordinates are client (browser) px. */
257
+ export interface PickProvider {
258
+ pick(clientX: number, clientY: number): string | null;
259
+ }
260
+
261
+ /** D4 — storybook stories. */
262
+ export interface StoryRef {
263
+ id: string;
264
+ label: string;
265
+ }
266
+ export interface StoriesProvider {
267
+ storiesFor(nodeId: string): StoryRef[]; // [] = none
268
+ active(nodeId: string): string | null;
269
+ apply(nodeId: string, storyId: string | null): void; // null clears
270
+ /** Render ONLY this node against the story (storybook canvas); null exits. */
271
+ isolate?(nodeId: string | null, storyId?: string): void;
272
+ }
273
+
274
+ /** D6 (S-C) — GameComponent management; config editing stays on InspectorProvider. */
275
+ export interface ComponentsProvider {
276
+ available(nodeId: string): string[];
277
+ list(nodeId: string): { type: string }[];
278
+ add(nodeId: string, type: string): void;
279
+ remove(nodeId: string, type: string): void;
280
+ }
281
+
282
+ /** Asset drop (hierarchy + viewport). */
283
+ export interface AssetDropProvider {
284
+ accepts(nodeId: string, assetPath: string): boolean;
285
+ drop(nodeId: string, assetPath: string): void;
286
+ }
287
+
288
+ /** Plain-object rect shape shared by {@link RectProvider} — the same fields a real
289
+ * `DOMRect` carries (a subset, so a real `DOMRect` satisfies this structurally too).
290
+ * See {@link RectProvider} for the coordinate space (host-relative, not viewport). */
291
+ export interface DOMRectLike {
292
+ x: number;
293
+ y: number;
294
+ width: number;
295
+ height: number;
296
+ }
297
+
298
+ /** Per-node screen geometry — the KEYSTONE omission today (nothing produces rects the
299
+ * ported inspect.ts math consumes). Coordinates are **host-relative** px: relative to
300
+ * the adapter's own mounted world surface (its `position:absolute; inset:0` layer), the
301
+ * same surface the A3 selection overlay is hosted over, so the overlay can draw against
302
+ * these rects directly. (NOT viewport-client — the JSDoc formerly said so in error.) */
303
+ export interface RectProvider {
304
+ /** selectable node id → its current bounding rect, or null if unmounted/offscreen */
305
+ rect(id: string): { x: number; y: number; width: number; height: number } | null;
306
+ /** rects of layout-relevant neighbours, for snap/measure/box-model overlays */
307
+ contextRects?(id: string): {
308
+ parent?: DOMRectLike;
309
+ siblings?: DOMRectLike[];
310
+ paddingBox?: DOMRectLike;
311
+ };
312
+ /**
313
+ * D3 (spec 27 §6) — every currently-empty container this adapter's tree
314
+ * contains right now: no visible children, no text, a collapsed dimension
315
+ * (the `ui-source/inspect.ts:findEmptyContainers` math) — each with a
316
+ * grown-to-tappable placeholder rect and a display name, driving the
317
+ * overlay's dashed empty-container hint. Host-relative, same coordinate
318
+ * space as {@link rect}. Absent ⇒ this adapter has no "empty container"
319
+ * concept (e.g. an adapter with no structural containers at all) — no
320
+ * hints are drawn for it.
321
+ */
322
+ emptyContainers?(): { id: string; rect: DOMRectLike; displayName: string }[];
323
+ }
324
+
325
+ /** Spatial gesture → source/data write, for non-Object3D (DOM) nodes. Distinct from the
326
+ * 3D TransformProvider. begin/apply/end bracket a single undo step; apply is live-preview. */
327
+ export interface BoxEditProvider {
328
+ begin(id: string): void;
329
+ /** patch: any of x,y,width,height,marginTop… paddingLeft… — px deltas or absolutes */
330
+ apply(id: string, patch: Record<string, number>): void;
331
+ end(id: string): void;
332
+ }
333
+
334
+ /** Text-content editing — currently OFF-contract (the react adapter has an `editText(id)`
335
+ * method, react-world-authoring-adapter.ts:728, not reachable via the contract). Bring it
336
+ * on so the overlay's double-click-to-edit-text (D3) is contract-driven. */
337
+ export interface TextProvider {
338
+ /** the element's editable pure-text, or null if the body is dynamic/has child elements */
339
+ get(id: string): string | null;
340
+ set(id: string, text: string): void; // dynamic-guarded by the writer
341
+ }
342
+
343
+ /**
344
+ * D3 (spec 27 §6) — background-color sampling at a viewport point, for the
345
+ * eyedropper's FALLBACK path (browsers with no native `EyeDropper` API). The
346
+ * native API, where available, samples real rendered pixels itself and needs
347
+ * none of this. Distinct from {@link PickProvider} (which returns a node id,
348
+ * not a color) and from `InspectorProvider.get('style.backgroundColor')`
349
+ * (which NORMALIZES to `#rrggbb` and so loses the "transparent" signal a
350
+ * color CHAIN walk needs — see `ui-source/inspect.ts:effectiveColorFromChain`'s
351
+ * doc comment: it walks raw, un-normalized CSS values looking for the first
352
+ * non-transparent one).
353
+ */
354
+ export interface ColorSampleProvider {
355
+ /** Raw (un-normalized) CSS `background-color` values, hit-element FIRST,
356
+ * walking up its ancestor chain — the exact shape
357
+ * `effectiveColorFromChain` consumes. `null` when nothing is hit at the
358
+ * point. Client (viewport) px, matching {@link PickProvider}. */
359
+ backgroundChainAt(clientX: number, clientY: number): string[] | null;
360
+ }
361
+
362
+ export interface AuthoringAdapter {
363
+ readonly capabilities: AuthoringCapabilities;
364
+ readonly hierarchy: HierarchyProvider; // required — minimum is "read the tree"
365
+ readonly selection?: SelectionProvider;
366
+ readonly transforms?: TransformProvider;
367
+ readonly inspector?: InspectorProvider;
368
+ /** UI layout authoring path (K7) — present on UI adapters, absent on 3D adapters. */
369
+ readonly layout?: LayoutProvider;
370
+ readonly structure?: StructureProvider;
371
+ readonly persistence?: PersistenceProvider;
372
+ /** D8 — mutually-exclusive root groups (radio roots). Absent ⇒ no grouped roots. */
373
+ readonly rootGroups?: RootGroupsProvider;
374
+ /** D8 — data-file → root mapping. Absent ⇒ this adapter maps no files to roots. */
375
+ readonly files?: FileMapProvider;
376
+ /** D12 — per-layer viewport picking. Absent ⇒ this adapter is not pickable. */
377
+ readonly pickable?: PickProvider;
378
+ /** T0 (spec 27 §2) — per-node screen geometry for a DOM visual editor's overlay/
379
+ * snap/measure math. Absent ⇒ this adapter produces no rects (no overlay). */
380
+ readonly rects?: RectProvider;
381
+ /** T0 (spec 27 §2) — spatial drag-resize/move → source/data write for non-Object3D
382
+ * (DOM) nodes. Absent ⇒ no box-edit gesture for this adapter. */
383
+ readonly boxEdit?: BoxEditProvider;
384
+ /** T0 (spec 27 §2) — double-click-to-edit-text on the contract (wires the react
385
+ * adapter's existing off-contract `editText`). Absent ⇒ no in-place text edit. */
386
+ readonly text?: TextProvider;
387
+ /** D3 (spec 27 §6) — eyedropper fallback color sampling. Absent ⇒ the
388
+ * canvas eyedropper swatch has no non-native path for this adapter. */
389
+ readonly colorSample?: ColorSampleProvider;
390
+ /** D4 — storybook stories. Absent ⇒ no stories for any node in this adapter. */
391
+ readonly stories?: StoriesProvider;
392
+ /** D6 (S-C) — GameComponent management. Absent ⇒ no component authoring. */
393
+ readonly components?: ComponentsProvider;
394
+ /** Asset drop (hierarchy + viewport). Absent ⇒ this adapter accepts no drops. */
395
+ readonly assetDrop?: AssetDropProvider;
396
+ /** Undo/redo for this adapter's edits (first-party delegates to the store; an
397
+ * ingest adapter keeps its own overlay-backed stack). Absent ⇒ host falls back. */
398
+ undo?(): void;
399
+ redo?(): void;
400
+ /** Change notification → UI refresh. */
401
+ subscribe?(listener: () => void): () => void;
402
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * ColyseusNetworkingAdapter — the first-party `NetworkingAdapter`. This is an
3
+ * INTROSPECTION / coordination boundary, NOT a transport: it lets the editor ask
4
+ * "is this object replicated, who owns it, may I edit it" — and, for the network
5
+ * inspector panel, "am I connected, to which room, how much replication activity
6
+ * is happening" — without owning Colyseus.
7
+ *
8
+ * It is parameterized by accessors over the room state (rather than a fixed schema)
9
+ * so any Colyseus room can supply one: map an `Object3D` to its network id + owner,
10
+ * report the local session and peers, and report connection/room/stats for the
11
+ * inspector. The editor uses `authority`/`editable` to keep remote/server-
12
+ * authoritative objects inspect-only (editing a replicated transform locally is
13
+ * meaningless — the server overwrites it next snapshot).
14
+ */
15
+
16
+ import type * as THREE from 'three';
17
+ import type {
18
+ ConnectionState,
19
+ NetPeer,
20
+ NetworkingAdapter,
21
+ ReplicationStats,
22
+ RoomInfo,
23
+ Unsubscribe,
24
+ } from './system-adapter';
25
+
26
+ export interface ColyseusNetworkingConfig {
27
+ /** The local peer's session id (objects it owns are editable). */
28
+ localSessionId(): string | null;
29
+ /** Peers currently in the room. */
30
+ peers(): NetPeer[];
31
+ /** Network id for an object, or null if it is not replicated (→ local authored). */
32
+ networkId(o: THREE.Object3D): string | null;
33
+ /** Owning peer/session id for a replicated object (null = server-owned). */
34
+ ownerId(o: THREE.Object3D): string | null;
35
+ /** True if the server is authoritative over this object (→ inspect-only). */
36
+ serverAuthoritative?(o: THREE.Object3D): boolean;
37
+ /** Current connection lifecycle state, for the network inspector panel.
38
+ * Optional — defaults to `'disconnected'` for implementers that only need
39
+ * object authority/editability (the pre-inspector config shape). */
40
+ connectionState?(): ConnectionState;
41
+ /** The active room's identity, or `null` when not connected to a room.
42
+ * Optional — defaults to `null`. */
43
+ roomInfo?(): RoomInfo | null;
44
+ /** Replication activity snapshot (entity count + msg rates), for the inspector.
45
+ * Optional — defaults to all-zero stats. */
46
+ replicationStats?(): ReplicationStats;
47
+ /** Subscribe to changes in connection state / room / replication stats.
48
+ * Optional — defaults to a no-op subscription. */
49
+ subscribe?(cb: () => void): Unsubscribe;
50
+ }
51
+
52
+ export function createColyseusNetworkingAdapter(cfg: ColyseusNetworkingConfig): NetworkingAdapter {
53
+ return {
54
+ peers: () => cfg.peers(),
55
+ networkId: (o) => cfg.networkId(o),
56
+ authority: (o) => {
57
+ if (cfg.networkId(o) == null) return 'local'; // not replicated → local authored
58
+ if (cfg.serverAuthoritative?.(o)) return 'server';
59
+ return cfg.ownerId(o) === cfg.localSessionId() ? 'local' : 'remote';
60
+ },
61
+ editable: (o) => {
62
+ if (cfg.networkId(o) == null) return true; // local authored object
63
+ if (cfg.serverAuthoritative?.(o)) return false; // server owns it → inspect-only
64
+ return cfg.ownerId(o) === cfg.localSessionId(); // only your own peer's objects
65
+ },
66
+ getConnectionState: () => cfg.connectionState?.() ?? 'disconnected',
67
+ getRoomInfo: () => cfg.roomInfo?.() ?? null,
68
+ getReplicationStats: () =>
69
+ cfg.replicationStats?.() ?? { entities: 0, msgsInPerSec: 0, msgsOutPerSec: 0 },
70
+ subscribe: (cb) => cfg.subscribe?.(cb) ?? (() => {}),
71
+ };
72
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * First-party implementations of the remaining `SystemAdapters` — input, assets,
3
+ * animation, navigation — each a thin coordination/introspection boundary over the
4
+ * real engine subsystem (the original vision named these as first-class System
5
+ * adapters; physics + networking shipped earlier). The editor speaks only the
6
+ * interfaces; these wrap `InputManager`, the asset loader, `AnimGraph`, and
7
+ * `NavMeshManager` so an external game could supply its own equivalents.
8
+ */
9
+
10
+ import type * as THREE from 'three';
11
+ import type { NavMeshManager } from '../ai/navigation';
12
+ import type { AnimGraph } from '../animation/anim-graph';
13
+ import type { InputManager } from '../input/input-manager';
14
+ import { resolveUrl } from '../loader';
15
+ import type { AudioContext as GameAudio } from '../setup/setup-audio';
16
+ import type {
17
+ AnimationAdapter,
18
+ AssetAdapter,
19
+ AudioAdapter,
20
+ InputAdapter,
21
+ NavigationAdapter,
22
+ NavPoint,
23
+ } from './system-adapter';
24
+
25
+ /** First-party `InputAdapter` over the engine `InputManager`. */
26
+ export function createInputManagerAdapter(input: InputManager): InputAdapter {
27
+ return {
28
+ poll: () => input.poll(),
29
+ actions: () => {
30
+ const out: Record<string, number> = {};
31
+ for (const name of input.actionNames()) out[name] = input.isPressed(name) ? 1 : 0;
32
+ return out;
33
+ },
34
+ };
35
+ }
36
+
37
+ /** First-party `AssetAdapter` — resolves URLs through the engine loader (which
38
+ * applies the project base + downloaded-asset remap). External/ingest games can
39
+ * supply their own to redirect relative paths. */
40
+ export function createVgaiAssetAdapter(): AssetAdapter {
41
+ return { resolve: (url) => resolveUrl(url) };
42
+ }
43
+
44
+ /** First-party `AnimationAdapter` over the runtime's `AnimGraph` map. */
45
+ export function createAnimationAdapter(
46
+ animGraphs: Map<THREE.Object3D, AnimGraph>,
47
+ ): AnimationAdapter {
48
+ const paramsOf = (g: AnimGraph): Record<string, number | boolean> => {
49
+ const out: Record<string, number | boolean> = {};
50
+ for (const name of g.parameterNames()) {
51
+ const v = g.getParameter(name);
52
+ if (v !== undefined) out[name] = v;
53
+ }
54
+ return out;
55
+ };
56
+ return {
57
+ graphs: () =>
58
+ [...animGraphs.entries()].map(([object, g]) => ({
59
+ object,
60
+ state: g.getCurrentState(),
61
+ parameters: paramsOf(g),
62
+ })),
63
+ state: (o) => animGraphs.get(o)?.getCurrentState() ?? null,
64
+ getParameter: (o, name) => animGraphs.get(o)?.getParameter(name),
65
+ setParameter: (o, name, value) => animGraphs.get(o)?.setParameter(name, value),
66
+ };
67
+ }
68
+
69
+ /**
70
+ * First-party `AudioAdapter` over the engine's master-gain bus
71
+ * (`setup-audio.ts`'s `AudioContext.masterGain`) — the seam `Game.play.pause()`
72
+ * (D10, T7.6) calls to silence a first-party world's audio. Restoring after a
73
+ * mute puts the gain back at whatever value it held right before muting (not
74
+ * a hardcoded `1`) — this composes correctly with an independent manual mute
75
+ * (the editor's `MuteButton`, `PlayBar.tsx`): pausing while already
76
+ * user-muted resumes muted, exactly as a user would expect.
77
+ */
78
+ export function createAudioSystemAdapter(audio: GameAudio): AudioAdapter {
79
+ let muted = false;
80
+ let priorGain = audio.masterGain.gain.value;
81
+ return {
82
+ setMuted(next: boolean) {
83
+ if (next === muted) return;
84
+ muted = next;
85
+ if (next) {
86
+ priorGain = audio.masterGain.gain.value;
87
+ audio.masterGain.gain.value = 0;
88
+ } else {
89
+ audio.masterGain.gain.value = priorGain;
90
+ }
91
+ },
92
+ isMuted: () => muted,
93
+ };
94
+ }
95
+
96
+ /** First-party `NavigationAdapter` over the engine `NavMeshManager`. */
97
+ export function createNavigationAdapter(nav: NavMeshManager): NavigationAdapter {
98
+ return {
99
+ hasNavMesh: () => nav.hasNavMesh(),
100
+ findPath: (start: NavPoint, end: NavPoint) => nav.findPath(start, end) as NavPoint[],
101
+ debugMesh: (scene: THREE.Scene) => nav.getDebugMesh(scene) as unknown as THREE.Object3D | null,
102
+ };
103
+ }