@ignifx/editor-host 0.12.0 → 0.14.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/dist/index.d.ts +753 -245
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1488 -230
- package/dist/index.js.map +1 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +1 -0
- package/dist/vite.js.map +1 -1
- package/package.json +10 -10
- package/skills/editor-host/SKILL.md +28 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isEditorOrigin, t as EditorHostErrorCode } from "./error-codes.js";
|
|
2
|
-
import { Camera, Component, CoreErrorCode, IgnifxError, Phase, SCENE_ASSET_TYPE, SCENE_FILE_FORMAT, SCENE_FORMAT_VERSION, Script, Transform, VERSION, addComponentFromRecord, canonicalizeNumber, clamp, createApp, createFrameSample, createRay, createSceneAsset, decodeProps, decodeValue, degToRad, describeRegisteredSchemas, describeSchemas, describeSettings, encodeProps, encodeValue, instantiateScene, isIgnifxError, loadSceneDependencies, parseOverridePath, serializeScene, settingsJsonSchema, toJsonSchema, transformSchema, validateSceneFile } from "@ignifx/core";
|
|
2
|
+
import { Camera, Component, CoreErrorCode, IgnifxError, Light, Phase, SCENE_ASSET_TYPE, SCENE_FILE_FORMAT, SCENE_FORMAT_VERSION, Script, Transform, VERSION, addComponentFromRecord, canonicalizeNumber, clamp, createApp, createFrameSample, createRay, createSceneAsset, decodeProps, decodeValue, degToRad, describeRegisteredSchemas, describeSchemas, describeSettings, encodeProps, encodeValue, instantiateScene, isIgnifxError, loadSceneDependencies, parseOverridePath, serializeEntity, serializeScene, settingsJsonSchema, toJsonSchema, transformSchema, validateSceneFile } from "@ignifx/core";
|
|
3
3
|
import { addToScene, attachPositionGizmoToNode, attachRotationGizmoToNode, attachScaleGizmoToNode, createLines, createPositionGizmo, createRotationGizmo, createScaleGizmo, isGizmoDragging, isGizmoInteracting, isGizmoPickPending, onBeforeRender, setPositionGizmoLocalCoordinates, setRotationGizmoLocalCoordinates, setScaleGizmoLocalCoordinates } from "@babylonjs/lite";
|
|
4
4
|
//#region src/protocol/rpc.ts
|
|
5
5
|
/**
|
|
@@ -40,7 +40,20 @@ const RpcErrorCode = {
|
|
|
40
40
|
*/
|
|
41
41
|
notReady: -32001,
|
|
42
42
|
/** A scene method that needs an open scene was called while none is open (`SceneMethod`). */
|
|
43
|
-
noScene: -32002
|
|
43
|
+
noScene: -32002,
|
|
44
|
+
/**
|
|
45
|
+
* A play method that needs a running game was called while it does not run. `PlayMethod.screenshot`
|
|
46
|
+
* needs the frame loop: it fails before the game starts it, after `stop`, and after `step`.
|
|
47
|
+
* `PlayMethod.queryRuntime` and `PlayMethod.sendInput` need a game that plays or is paused (a
|
|
48
|
+
* stepped game is paused): they fail before the game starts and after `stop`. Additive in 0.3:
|
|
49
|
+
* only a host that answers one of those methods in the play view sends it.
|
|
50
|
+
*/
|
|
51
|
+
notPlaying: -32003,
|
|
52
|
+
/**
|
|
53
|
+
* A play method named an entity uid the game's world does not hold (`PlayMethod.queryRuntime`).
|
|
54
|
+
* Additive in 0.3: only a host that answers `queryRuntime` sends it.
|
|
55
|
+
*/
|
|
56
|
+
unknownEntity: -32004
|
|
44
57
|
};
|
|
45
58
|
/**
|
|
46
59
|
* Narrows to a plain object without an `as` assertion. Shared by this package's guards; not
|
|
@@ -171,9 +184,11 @@ const HostKind = {
|
|
|
171
184
|
* The optional features a host lists in its `ready` result.
|
|
172
185
|
*
|
|
173
186
|
* @remarks
|
|
174
|
-
* The play controls send `
|
|
175
|
-
*
|
|
176
|
-
* `
|
|
187
|
+
* The play controls send `"heartbeat"`, `"playControls"`, `"logRelay"` and `"queryRuntime"`, plus
|
|
188
|
+
* `"screenshot"` when the game has a canvas and `"sendInput"` when it has `app.input`. The scene
|
|
189
|
+
* host sends `"heartbeat"` and whichever of `"gizmos"`, `"screenshot"`, `"viewMode2d"`,
|
|
190
|
+
* `"pick2d"`, `"gameView"` and `"thumbnails"` it supports; every `SceneMethod` not tied to one of
|
|
191
|
+
* them is required of a 0.3 scene host.
|
|
177
192
|
*
|
|
178
193
|
* @public
|
|
179
194
|
*/
|
|
@@ -187,7 +202,11 @@ const HostCapability = {
|
|
|
187
202
|
* `transformDragging` and `transformDragged`.
|
|
188
203
|
*/
|
|
189
204
|
gizmos: "gizmos",
|
|
190
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* The host answers `screenshot`: the scene host captures its view, the play controls the game's
|
|
207
|
+
* canvas. The play controls list it from engine ask E47 (additive in 0.3); without it, the play
|
|
208
|
+
* view answers `screenshot` with `RpcErrorCode.methodNotFound`.
|
|
209
|
+
*/
|
|
191
210
|
screenshot: "screenshot",
|
|
192
211
|
/** The scene host accepts `setViewMode` with `"2d"`: a 2D editor camera and planar gizmos. */
|
|
193
212
|
viewMode2d: "viewMode2d",
|
|
@@ -210,7 +229,32 @@ const HostCapability = {
|
|
|
210
229
|
* overrides). A value the document sets is kept. An editor need not reopen the scene for changed
|
|
211
230
|
* defaults. Additive in 0.3.
|
|
212
231
|
*/
|
|
213
|
-
hotReloadDefaults: "hotReloadDefaults"
|
|
232
|
+
hotReloadDefaults: "hotReloadDefaults",
|
|
233
|
+
/**
|
|
234
|
+
* The play controls answer `queryRuntime`: an entity's live state in the scene format. From engine
|
|
235
|
+
* ask E48 (additive in 0.3); without it, the play view answers `queryRuntime` with
|
|
236
|
+
* `RpcErrorCode.methodNotFound`.
|
|
237
|
+
*/
|
|
238
|
+
queryRuntime: "queryRuntime",
|
|
239
|
+
/**
|
|
240
|
+
* The play controls answer `sendInput`: synthetic key and pointer events queued into the game's
|
|
241
|
+
* own input system (`app.input` from `@ignifx/input`), never into the editor's window. Listed only
|
|
242
|
+
* when the game has `app.input`. From engine ask E49 (additive in 0.3); without it, the play view
|
|
243
|
+
* answers `sendInput` with `RpcErrorCode.methodNotFound`.
|
|
244
|
+
*/
|
|
245
|
+
sendInput: "sendInput",
|
|
246
|
+
/**
|
|
247
|
+
* The scene host answers `setGameView` and `gameViewFrame`: the open scene through its own main
|
|
248
|
+
* camera, rendered beside the editor camera (`RenderViewMethod`). From engine ask E8 (additive in
|
|
249
|
+
* 0.3); without it, the host answers both with `RpcErrorCode.methodNotFound`.
|
|
250
|
+
*/
|
|
251
|
+
gameView: "gameView",
|
|
252
|
+
/**
|
|
253
|
+
* The scene host answers `renderThumbnail`: a model or prefab asset rendered on its own
|
|
254
|
+
* (`RenderViewMethod`). From engine ask E8 (additive in 0.3); without it, the host answers it with
|
|
255
|
+
* `RpcErrorCode.methodNotFound`.
|
|
256
|
+
*/
|
|
257
|
+
thumbnails: "thumbnails"
|
|
214
258
|
};
|
|
215
259
|
/**
|
|
216
260
|
* The longest string, in UTF-16 code units, the editor accepts from a host in `ready` (the engine
|
|
@@ -331,140 +375,6 @@ heartbeat: "heartbeat" };
|
|
|
331
375
|
*/
|
|
332
376
|
const DEFAULT_HEARTBEAT_INTERVAL_MS = 1e3;
|
|
333
377
|
//#endregion
|
|
334
|
-
//#region src/protocol/play.ts
|
|
335
|
-
/**
|
|
336
|
-
* The play view's controls: the methods the editor calls on the project's own game page after the
|
|
337
|
-
* handshake, through `attachEditorPlayControls(app)` from `virtual:ignifx/editor`. Plan §3.6.
|
|
338
|
-
*/
|
|
339
|
-
/**
|
|
340
|
-
* The methods the play view answers after `ready`. `play`, `pause`, `step` and `stop` answer with a
|
|
341
|
-
* {@link PlayState}; `playState` answers with a {@link PlayStateReport}; `playStats` answers with
|
|
342
|
-
* {@link PlayStats}.
|
|
343
|
-
*
|
|
344
|
-
* @remarks
|
|
345
|
-
* A host that answers them lists `HostCapability.playControls` in `ready`. Sent before `ready`, they
|
|
346
|
-
* fail with `RpcErrorCode.notReady`; sent to a host without them, with `RpcErrorCode.methodNotFound`.
|
|
347
|
-
* `playState` and `playStats` are additive 0.3 methods: a host from before one answers it with
|
|
348
|
-
* `RpcErrorCode.methodNotFound`.
|
|
349
|
-
*
|
|
350
|
-
* @public
|
|
351
|
-
*/
|
|
352
|
-
const PlayMethod = {
|
|
353
|
-
/** Clears `app.time.paused` and starts the frame loop if it is stopped. */
|
|
354
|
-
play: "play",
|
|
355
|
-
/** Sets `app.time.paused`; scripts marked `updateWhenPaused` keep running. */
|
|
356
|
-
pause: "pause",
|
|
357
|
-
/** Stops the frame loop, then advances exactly one frame with `app.step()` and leaves the game paused. */
|
|
358
|
-
step: "step",
|
|
359
|
-
/** Stops the frame loop with `app.stop()`. The editor reloads the view to reset the game. */
|
|
360
|
-
stop: "stop",
|
|
361
|
-
/** Reads the game's state without changing it. Takes no parameters. */
|
|
362
|
-
playState: "playState",
|
|
363
|
-
/**
|
|
364
|
-
* Reads the game's frame rate, frame time, entity count and frame count without changing
|
|
365
|
-
* anything. Takes no parameters. The editor polls it; no notification carries it.
|
|
366
|
-
*/
|
|
367
|
-
playStats: "playStats"
|
|
368
|
-
};
|
|
369
|
-
/**
|
|
370
|
-
* The notifications the play view sends after `ready`.
|
|
371
|
-
*
|
|
372
|
-
* @remarks
|
|
373
|
-
* Additive in 0.3: a host from before them sends none, and answers `playState` with
|
|
374
|
-
* `RpcErrorCode.methodNotFound`. `log`, `hostError` and `hotReloaded` came later still: only a host
|
|
375
|
-
* that lists `HostCapability.logRelay` in `ready` sends them.
|
|
376
|
-
*
|
|
377
|
-
* @public
|
|
378
|
-
*/
|
|
379
|
-
const PlayNotification = {
|
|
380
|
-
/**
|
|
381
|
-
* After the game's {@link PlayStateReport.state} changed. A change a `PlayMethod` makes is sent
|
|
382
|
-
* right after that method's answer; one the game makes itself, such as setting
|
|
383
|
-
* `app.time.paused`, within one heartbeat interval.
|
|
384
|
-
*/
|
|
385
|
-
playStateChanged: "playStateChanged",
|
|
386
|
-
/**
|
|
387
|
-
* One line from the game's logger, with the same `LogParams` as the scene view's `log`. Sent by a
|
|
388
|
-
* host that lists `HostCapability.logRelay`; lines logged before the handshake are kept (the
|
|
389
|
-
* newest few hundred) and sent right after `ready`.
|
|
390
|
-
*/
|
|
391
|
-
log: "log",
|
|
392
|
-
/**
|
|
393
|
-
* An error the game's app reported through `app.onError`: the same `HostErrorParams` as the scene
|
|
394
|
-
* view's `hostError`, with `AppErrorData` as its `data`. Sent by a host that lists
|
|
395
|
-
* `HostCapability.logRelay`, kept before the handshake as `log` is.
|
|
396
|
-
*/
|
|
397
|
-
hostError: "hostError",
|
|
398
|
-
/**
|
|
399
|
-
* After every `app.hotReload` operation in the game: the same `HotReloadedParams` as the scene
|
|
400
|
-
* view's `hotReloaded`. Sent by a host that lists `HostCapability.logRelay`.
|
|
401
|
-
*/
|
|
402
|
-
hotReloaded: "hotReloaded"
|
|
403
|
-
};
|
|
404
|
-
/**
|
|
405
|
-
* Whether the game plays, is paused, or is stopped, as {@link PlayStateReport.state} reports it.
|
|
406
|
-
*
|
|
407
|
-
* @public
|
|
408
|
-
*/
|
|
409
|
-
const PlayPhase = {
|
|
410
|
-
/** The frame loop runs (`app.isRunning`) and game time is not paused. */
|
|
411
|
-
playing: "playing",
|
|
412
|
-
/**
|
|
413
|
-
* Game time is paused (`app.time.paused`): after `pause`, or after `step`, which leaves the frame
|
|
414
|
-
* loop stopped on the stepped frame.
|
|
415
|
-
*/
|
|
416
|
-
paused: "paused",
|
|
417
|
-
/** The frame loop does not run: before the game starts it, or after `stop`. */
|
|
418
|
-
stopped: "stopped"
|
|
419
|
-
};
|
|
420
|
-
/**
|
|
421
|
-
* Checks the `result` of a play method's response.
|
|
422
|
-
*
|
|
423
|
-
* @param value - The received `result`.
|
|
424
|
-
* @returns True when `value` has boolean `isRunning` and `isPaused` and a non-negative integer
|
|
425
|
-
* `frameCount`.
|
|
426
|
-
*
|
|
427
|
-
* @public
|
|
428
|
-
*/
|
|
429
|
-
function isPlayState(value) {
|
|
430
|
-
if (!isRecord(value)) return false;
|
|
431
|
-
const frameCount = value["frameCount"];
|
|
432
|
-
return typeof value["isRunning"] === "boolean" && typeof value["isPaused"] === "boolean" && typeof frameCount === "number" && Number.isSafeInteger(frameCount) && frameCount >= 0;
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Checks the `result` of `playState` and the `params` of `playStateChanged`.
|
|
436
|
-
*
|
|
437
|
-
* @param value - The received value.
|
|
438
|
-
* @returns True when `value` has a `state` that is a `PlayPhase`, a non-negative integer
|
|
439
|
-
* `frameCount`, and a non-negative finite `time`.
|
|
440
|
-
*
|
|
441
|
-
* @public
|
|
442
|
-
*/
|
|
443
|
-
function isPlayStateReport(value) {
|
|
444
|
-
if (!isRecord(value)) return false;
|
|
445
|
-
const state = value["state"];
|
|
446
|
-
const frameCount = value["frameCount"];
|
|
447
|
-
const time = value["time"];
|
|
448
|
-
return typeof state === "string" && Object.values(PlayPhase).includes(state) && typeof frameCount === "number" && Number.isSafeInteger(frameCount) && frameCount >= 0 && typeof time === "number" && Number.isFinite(time) && time >= 0;
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* Checks the `result` of `playStats`.
|
|
452
|
-
*
|
|
453
|
-
* @param value - The received `result`.
|
|
454
|
-
* @returns True when `value` has non-negative finite `fps` and `frameTimeMs` and non-negative
|
|
455
|
-
* integer `entityCount` and `frameCount`.
|
|
456
|
-
*
|
|
457
|
-
* @public
|
|
458
|
-
*/
|
|
459
|
-
function isPlayStats(value) {
|
|
460
|
-
if (!isRecord(value)) return false;
|
|
461
|
-
const fps = value["fps"];
|
|
462
|
-
const frameTimeMs = value["frameTimeMs"];
|
|
463
|
-
const entityCount = value["entityCount"];
|
|
464
|
-
const frameCount = value["frameCount"];
|
|
465
|
-
return typeof fps === "number" && Number.isFinite(fps) && fps >= 0 && typeof frameTimeMs === "number" && Number.isFinite(frameTimeMs) && frameTimeMs >= 0 && typeof entityCount === "number" && Number.isSafeInteger(entityCount) && entityCount >= 0 && typeof frameCount === "number" && Number.isSafeInteger(frameCount) && frameCount >= 0;
|
|
466
|
-
}
|
|
467
|
-
//#endregion
|
|
468
378
|
//#region src/protocol/scene-file.ts
|
|
469
379
|
/**
|
|
470
380
|
* The engine's scene file format as it travels on the wire: the same object `@ignifx/core`'s
|
|
@@ -479,7 +389,7 @@ function isPlayStats(value) {
|
|
|
479
389
|
* file with the engine's `validateSceneFile`.
|
|
480
390
|
*/
|
|
481
391
|
/** How deep a JSON value may nest before {@link isJsonValue} refuses it, as a guard against cycles. */
|
|
482
|
-
const MAX_JSON_DEPTH = 256;
|
|
392
|
+
const MAX_JSON_DEPTH$1 = 256;
|
|
483
393
|
/**
|
|
484
394
|
* Tells whether a value is JSON: `null`, a boolean, a string, a finite number, or an array or
|
|
485
395
|
* plain object of JSON values, nested at most 256 levels deep.
|
|
@@ -500,7 +410,7 @@ function isJsonValue(value) {
|
|
|
500
410
|
* @returns True for a JSON value no deeper than the limit.
|
|
501
411
|
*/
|
|
502
412
|
function isJsonValueAt(value, depth) {
|
|
503
|
-
if (depth > MAX_JSON_DEPTH) return false;
|
|
413
|
+
if (depth > MAX_JSON_DEPTH$1) return false;
|
|
504
414
|
if (value === null || typeof value === "string" || typeof value === "boolean") return true;
|
|
505
415
|
if (typeof value === "number") return Number.isFinite(value);
|
|
506
416
|
if (Array.isArray(value)) return value.every((item) => isJsonValueAt(item, depth + 1));
|
|
@@ -647,51 +557,341 @@ function isOverrideOp(value) {
|
|
|
647
557
|
return value === "replace" || value === "remove" || value === "add";
|
|
648
558
|
}
|
|
649
559
|
/**
|
|
650
|
-
* Checks an override patch.
|
|
560
|
+
* Checks an override patch.
|
|
561
|
+
*
|
|
562
|
+
* @param value - The value to test.
|
|
563
|
+
* @returns True for `{ op?, path, value? }` with a known `op` and a JSON `value`.
|
|
564
|
+
*
|
|
565
|
+
* @public
|
|
566
|
+
*/
|
|
567
|
+
function isSceneFileOverride(value) {
|
|
568
|
+
return isRecord(value) && isString(value["path"]) && optionalField(value, "op", isOverrideOp) && optionalField(value, "value", (patch) => isJsonValue(patch));
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Checks an `instance` entry.
|
|
572
|
+
*
|
|
573
|
+
* @param value - The value to test.
|
|
574
|
+
* @returns True for `{ scene, hash?, overrides? }`.
|
|
575
|
+
*
|
|
576
|
+
* @public
|
|
577
|
+
*/
|
|
578
|
+
function isSceneFileInstance(value) {
|
|
579
|
+
return isRecord(value) && isSceneFileAssetRef(value["scene"]) && optionalField(value, "hash", isString) && optionalField(value, "overrides", (overrides) => isArrayOf(overrides, isSceneFileOverride));
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Checks an entity record.
|
|
583
|
+
*
|
|
584
|
+
* @param value - The value to test.
|
|
585
|
+
* @returns True for a record with a uid, a name, a parent, a transform and well-typed optional
|
|
586
|
+
* fields.
|
|
587
|
+
*
|
|
588
|
+
* @public
|
|
589
|
+
*/
|
|
590
|
+
function isSceneFileEntity(value) {
|
|
591
|
+
if (!isRecord(value)) return false;
|
|
592
|
+
const parent = value["parent"];
|
|
593
|
+
return isUidString(value["uid"]) && isString(value["name"]) && (parent === null || isUidString(parent)) && optionalField(value, "active", isBoolean) && optionalField(value, "static", isBoolean) && optionalField(value, "layer", isString) && optionalField(value, "tags", (tags) => isArrayOf(tags, isString)) && isSceneFileTransform(value["transform"]) && optionalField(value, "instance", isSceneFileInstance) && optionalField(value, "components", (components) => isArrayOf(components, isSceneFileComponent));
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Checks a whole scene file's structure.
|
|
597
|
+
*
|
|
598
|
+
* @param value - The value to test.
|
|
599
|
+
* @returns True for a file object whose header fields and entity records have the right types.
|
|
600
|
+
*
|
|
601
|
+
* @public
|
|
602
|
+
*/
|
|
603
|
+
function isSceneFile(value) {
|
|
604
|
+
return isRecord(value) && isString(value["format"]) && Number.isSafeInteger(value["formatVersion"]) && optionalField(value, "engineVersion", isString) && isString(value["name"]) && optionalField(value, "settings", isJsonObject) && isArrayOf(value["entities"], isSceneFileEntity);
|
|
605
|
+
}
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region src/protocol/play.ts
|
|
608
|
+
/**
|
|
609
|
+
* The play view's controls: the methods the editor calls on the project's own game page after the
|
|
610
|
+
* handshake, through `attachEditorPlayControls(app)` from `virtual:ignifx/editor`. Plan §3.6.
|
|
611
|
+
*/
|
|
612
|
+
/**
|
|
613
|
+
* The methods the play view answers after `ready`. `play`, `pause`, `step` and `stop` answer with a
|
|
614
|
+
* {@link PlayState}; `playState` answers with a {@link PlayStateReport}; `playStats` answers with
|
|
615
|
+
* {@link PlayStats}; `screenshot` answers with a `ScreenshotResult`; `queryRuntime` answers with a
|
|
616
|
+
* {@link QueryRuntimeResult}; `sendInput` answers with a {@link SendInputResult}.
|
|
617
|
+
*
|
|
618
|
+
* @remarks
|
|
619
|
+
* A host that answers them lists `HostCapability.playControls` in `ready`. Sent before `ready`, they
|
|
620
|
+
* fail with `RpcErrorCode.notReady`; sent to a host without them, with `RpcErrorCode.methodNotFound`.
|
|
621
|
+
* `playState`, `playStats`, `screenshot`, `queryRuntime` and `sendInput` are additive 0.3 methods:
|
|
622
|
+
* a host from before one answers it with `RpcErrorCode.methodNotFound`. `screenshot`, `queryRuntime`
|
|
623
|
+
* and `sendInput` also need the `HostCapability` of the same name in the play view's `ready`.
|
|
624
|
+
*
|
|
625
|
+
* @public
|
|
626
|
+
*/
|
|
627
|
+
const PlayMethod = {
|
|
628
|
+
/** Clears `app.time.paused` and starts the frame loop if it is stopped. */
|
|
629
|
+
play: "play",
|
|
630
|
+
/** Sets `app.time.paused`; scripts marked `updateWhenPaused` keep running. */
|
|
631
|
+
pause: "pause",
|
|
632
|
+
/** Stops the frame loop, then advances exactly one frame with `app.step()` and leaves the game paused. */
|
|
633
|
+
step: "step",
|
|
634
|
+
/** Stops the frame loop with `app.stop()`. The editor reloads the view to reset the game. */
|
|
635
|
+
stop: "stop",
|
|
636
|
+
/** Reads the game's state without changing it. Takes no parameters. */
|
|
637
|
+
playState: "playState",
|
|
638
|
+
/**
|
|
639
|
+
* Reads the game's frame rate, frame time, entity count and frame count without changing
|
|
640
|
+
* anything. Takes no parameters. The editor polls it; no notification carries it.
|
|
641
|
+
*/
|
|
642
|
+
playStats: "playStats",
|
|
643
|
+
/**
|
|
644
|
+
* Captures the game's canvas as an image, with the scene view's `screenshot` parameters, caps and
|
|
645
|
+
* answer (`ScreenshotParams`, `ScreenshotResult`). Changes nothing: a paused game is captured
|
|
646
|
+
* paused. Needs `HostCapability.screenshot`. Fails with `RpcErrorCode.notPlaying` while the frame
|
|
647
|
+
* loop does not run (before the game starts it, after `stop` or `step`), and with
|
|
648
|
+
* `RpcErrorCode.notReady` before the game's first frame.
|
|
649
|
+
*/
|
|
650
|
+
screenshot: "screenshot",
|
|
651
|
+
/**
|
|
652
|
+
* Reads one entity of the running game as the scene format writes it ({@link QueryRuntimeParams},
|
|
653
|
+
* {@link QueryRuntimeResult}): its live transform, flags and component props, never anything a
|
|
654
|
+
* component does not serialize, and no expressions. Each value is capped and the whole answer kept
|
|
655
|
+
* within {@link QUERY_RUNTIME_MAX_JSON_LENGTH}. Changes nothing. Needs
|
|
656
|
+
* `HostCapability.queryRuntime`. Fails with `RpcErrorCode.notPlaying` while the game is stopped
|
|
657
|
+
* (before it starts, after `stop`; a stepped game is paused and answers), and with
|
|
658
|
+
* `RpcErrorCode.unknownEntity` when no entity of the game has the uid.
|
|
659
|
+
*/
|
|
660
|
+
queryRuntime: "queryRuntime",
|
|
661
|
+
/**
|
|
662
|
+
* Queues synthetic key and pointer events into the game's own input system, as if the game's page
|
|
663
|
+
* had received them ({@link SendInputParams}, {@link SendInputResult}). Nothing reaches the
|
|
664
|
+
* editor's window or the operating system. Needs `HostCapability.sendInput`, which a game lists
|
|
665
|
+
* only when it has `app.input` (`@ignifx/input`). Fails with `RpcErrorCode.notPlaying` while the
|
|
666
|
+
* game is stopped; a paused or stepped game takes the events and resolves them on its next frame,
|
|
667
|
+
* which for a stepped game is the next `step`.
|
|
668
|
+
*/
|
|
669
|
+
sendInput: "sendInput"
|
|
670
|
+
};
|
|
671
|
+
/**
|
|
672
|
+
* The most components a `queryRuntime` answer holds, and the most type ids its `components` filter
|
|
673
|
+
* may name. Components past it are counted in {@link QueryRuntimeResult.omittedComponents}.
|
|
674
|
+
*
|
|
675
|
+
* @public
|
|
676
|
+
*/
|
|
677
|
+
const QUERY_RUNTIME_MAX_COMPONENTS = 64;
|
|
678
|
+
/**
|
|
679
|
+
* The longest a `queryRuntime` answer may be: its `result` as JSON text, in UTF-16 code units
|
|
680
|
+
* (`JSON.stringify(result).length`), 256 Ki. Components that would pass it are left out, in order,
|
|
681
|
+
* and counted in {@link QueryRuntimeResult.omittedComponents}.
|
|
682
|
+
*
|
|
683
|
+
* @public
|
|
684
|
+
*/
|
|
685
|
+
const QUERY_RUNTIME_MAX_JSON_LENGTH = 262144;
|
|
686
|
+
/**
|
|
687
|
+
* In a `queryRuntime` answer, the most keys one object keeps and the longest a key may be; also the
|
|
688
|
+
* longest the entity's `name`, `layer`, each tag and each component `type` may be, and the most
|
|
689
|
+
* tags kept. Keys left out are counted in {@link QueryRuntimeResult.omittedEntries}.
|
|
690
|
+
*
|
|
691
|
+
* @public
|
|
692
|
+
*/
|
|
693
|
+
const QUERY_RUNTIME_MAX_KEYS = 256;
|
|
694
|
+
/**
|
|
695
|
+
* In a `queryRuntime` answer, the longest a prop string may be, `… [clipped]` included: 64 Ki, a
|
|
696
|
+
* quarter of {@link QUERY_RUNTIME_MAX_JSON_LENGTH}, so one long string does not cost its component
|
|
697
|
+
* its place.
|
|
698
|
+
*
|
|
699
|
+
* @public
|
|
700
|
+
*/
|
|
701
|
+
const QUERY_RUNTIME_MAX_STRING_LENGTH = 65536;
|
|
702
|
+
/**
|
|
703
|
+
* The most events one `sendInput` request may carry.
|
|
704
|
+
*
|
|
705
|
+
* @public
|
|
706
|
+
*/
|
|
707
|
+
const SEND_INPUT_MAX_EVENTS = 64;
|
|
708
|
+
/**
|
|
709
|
+
* The notifications the play view sends after `ready`.
|
|
710
|
+
*
|
|
711
|
+
* @remarks
|
|
712
|
+
* Additive in 0.3: a host from before them sends none, and answers `playState` with
|
|
713
|
+
* `RpcErrorCode.methodNotFound`. `log`, `hostError` and `hotReloaded` came later still: only a host
|
|
714
|
+
* that lists `HostCapability.logRelay` in `ready` sends them.
|
|
715
|
+
*
|
|
716
|
+
* @public
|
|
717
|
+
*/
|
|
718
|
+
const PlayNotification = {
|
|
719
|
+
/**
|
|
720
|
+
* After the game's {@link PlayStateReport.state} changed. A change a `PlayMethod` makes is sent
|
|
721
|
+
* right after that method's answer; one the game makes itself, such as setting
|
|
722
|
+
* `app.time.paused`, within one heartbeat interval.
|
|
723
|
+
*/
|
|
724
|
+
playStateChanged: "playStateChanged",
|
|
725
|
+
/**
|
|
726
|
+
* One line from the game's logger, with the same `LogParams` as the scene view's `log`. Sent by a
|
|
727
|
+
* host that lists `HostCapability.logRelay`; lines logged before the handshake are kept (the
|
|
728
|
+
* newest few hundred) and sent right after `ready`.
|
|
729
|
+
*/
|
|
730
|
+
log: "log",
|
|
731
|
+
/**
|
|
732
|
+
* An error the game's app reported through `app.onError`: the same `HostErrorParams` as the scene
|
|
733
|
+
* view's `hostError`, with `AppErrorData` as its `data`. Sent by a host that lists
|
|
734
|
+
* `HostCapability.logRelay`, kept before the handshake as `log` is.
|
|
735
|
+
*/
|
|
736
|
+
hostError: "hostError",
|
|
737
|
+
/**
|
|
738
|
+
* After every `app.hotReload` operation in the game: the same `HotReloadedParams` as the scene
|
|
739
|
+
* view's `hotReloaded`. Sent by a host that lists `HostCapability.logRelay`.
|
|
740
|
+
*/
|
|
741
|
+
hotReloaded: "hotReloaded"
|
|
742
|
+
};
|
|
743
|
+
/**
|
|
744
|
+
* Whether the game plays, is paused, or is stopped, as {@link PlayStateReport.state} reports it.
|
|
745
|
+
*
|
|
746
|
+
* @public
|
|
747
|
+
*/
|
|
748
|
+
const PlayPhase = {
|
|
749
|
+
/** The frame loop runs (`app.isRunning`) and game time is not paused. */
|
|
750
|
+
playing: "playing",
|
|
751
|
+
/**
|
|
752
|
+
* Game time is paused (`app.time.paused`): after `pause`, or after `step`, which leaves the frame
|
|
753
|
+
* loop stopped on the stepped frame.
|
|
754
|
+
*/
|
|
755
|
+
paused: "paused",
|
|
756
|
+
/** The frame loop does not run: before the game starts it, or after `stop`. */
|
|
757
|
+
stopped: "stopped"
|
|
758
|
+
};
|
|
759
|
+
/**
|
|
760
|
+
* Checks the `result` of a play method's response.
|
|
761
|
+
*
|
|
762
|
+
* @param value - The received `result`.
|
|
763
|
+
* @returns True when `value` has boolean `isRunning` and `isPaused` and a non-negative integer
|
|
764
|
+
* `frameCount`.
|
|
765
|
+
*
|
|
766
|
+
* @public
|
|
767
|
+
*/
|
|
768
|
+
function isPlayState(value) {
|
|
769
|
+
if (!isRecord(value)) return false;
|
|
770
|
+
const frameCount = value["frameCount"];
|
|
771
|
+
return typeof value["isRunning"] === "boolean" && typeof value["isPaused"] === "boolean" && typeof frameCount === "number" && Number.isSafeInteger(frameCount) && frameCount >= 0;
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Checks the `result` of `playState` and the `params` of `playStateChanged`.
|
|
775
|
+
*
|
|
776
|
+
* @param value - The received value.
|
|
777
|
+
* @returns True when `value` has a `state` that is a `PlayPhase`, a non-negative integer
|
|
778
|
+
* `frameCount`, and a non-negative finite `time`.
|
|
779
|
+
*
|
|
780
|
+
* @public
|
|
781
|
+
*/
|
|
782
|
+
function isPlayStateReport(value) {
|
|
783
|
+
if (!isRecord(value)) return false;
|
|
784
|
+
const state = value["state"];
|
|
785
|
+
const frameCount = value["frameCount"];
|
|
786
|
+
const time = value["time"];
|
|
787
|
+
return typeof state === "string" && Object.values(PlayPhase).includes(state) && typeof frameCount === "number" && Number.isSafeInteger(frameCount) && frameCount >= 0 && typeof time === "number" && Number.isFinite(time) && time >= 0;
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Checks the `result` of `playStats`.
|
|
791
|
+
*
|
|
792
|
+
* @param value - The received `result`.
|
|
793
|
+
* @returns True when `value` has non-negative finite `fps` and `frameTimeMs` and non-negative
|
|
794
|
+
* integer `entityCount` and `frameCount`.
|
|
795
|
+
*
|
|
796
|
+
* @public
|
|
797
|
+
*/
|
|
798
|
+
function isPlayStats(value) {
|
|
799
|
+
if (!isRecord(value)) return false;
|
|
800
|
+
const fps = value["fps"];
|
|
801
|
+
const frameTimeMs = value["frameTimeMs"];
|
|
802
|
+
const entityCount = value["entityCount"];
|
|
803
|
+
const frameCount = value["frameCount"];
|
|
804
|
+
return typeof fps === "number" && Number.isFinite(fps) && fps >= 0 && typeof frameTimeMs === "number" && Number.isFinite(frameTimeMs) && frameTimeMs >= 0 && typeof entityCount === "number" && Number.isSafeInteger(entityCount) && entityCount >= 0 && typeof frameCount === "number" && Number.isSafeInteger(frameCount) && frameCount >= 0;
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* Checks the `params` of `queryRuntime`.
|
|
808
|
+
*
|
|
809
|
+
* @param value - The received `params`.
|
|
810
|
+
* @returns True for a non-empty `entity` uid and, when present, a `components` list of at most
|
|
811
|
+
* {@link QUERY_RUNTIME_MAX_COMPONENTS} non-empty strings.
|
|
812
|
+
*
|
|
813
|
+
* @public
|
|
814
|
+
*/
|
|
815
|
+
function isQueryRuntimeParams(value) {
|
|
816
|
+
if (!isRecord(value) || !isUidString(value["entity"])) return false;
|
|
817
|
+
const components = value["components"];
|
|
818
|
+
return components === void 0 || Array.isArray(components) && components.length <= 64 && components.every((typeId) => typeof typeId === "string" && typeId.length > 0);
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Checks the `result` of `queryRuntime`.
|
|
822
|
+
*
|
|
823
|
+
* @param value - The received `result`.
|
|
824
|
+
* @returns True for an entity record with at most {@link QUERY_RUNTIME_MAX_COMPONENTS} components,
|
|
825
|
+
* non-negative integer `omittedComponents`, `omittedEntries` and `frameCount`, and a non-negative
|
|
826
|
+
* finite `time`, no longer than {@link QUERY_RUNTIME_MAX_JSON_LENGTH} as JSON.
|
|
827
|
+
*
|
|
828
|
+
* @public
|
|
829
|
+
*/
|
|
830
|
+
function isQueryRuntimeResult(value) {
|
|
831
|
+
if (!isRecord(value)) return false;
|
|
832
|
+
const entity = value["entity"];
|
|
833
|
+
const omitted = value["omittedComponents"];
|
|
834
|
+
const omittedEntries = value["omittedEntries"];
|
|
835
|
+
const frameCount = value["frameCount"];
|
|
836
|
+
const time = value["time"];
|
|
837
|
+
return isSceneFileEntity(entity) && (entity.components ?? []).length <= 64 && typeof omitted === "number" && Number.isSafeInteger(omitted) && omitted >= 0 && typeof omittedEntries === "number" && Number.isSafeInteger(omittedEntries) && omittedEntries >= 0 && typeof frameCount === "number" && Number.isSafeInteger(frameCount) && frameCount >= 0 && typeof time === "number" && Number.isFinite(time) && time >= 0 && JSON.stringify(value).length <= 262144;
|
|
838
|
+
}
|
|
839
|
+
/** A `<Keyboard>` control name as `sendInput` accepts it. */
|
|
840
|
+
const KEY_CONTROL_PATTERN = /^[A-Za-z0-9]{1,64}$/u;
|
|
841
|
+
/**
|
|
842
|
+
* Tells whether a value is a fraction from 0 to 1.
|
|
651
843
|
*
|
|
652
844
|
* @param value - The value to test.
|
|
653
|
-
* @returns True for
|
|
654
|
-
*
|
|
655
|
-
* @public
|
|
845
|
+
* @returns True for a finite number from 0 to 1.
|
|
656
846
|
*/
|
|
657
|
-
function
|
|
658
|
-
return
|
|
847
|
+
function isFraction(value) {
|
|
848
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
|
|
659
849
|
}
|
|
660
850
|
/**
|
|
661
|
-
* Checks
|
|
851
|
+
* Checks one event of a `sendInput` request.
|
|
662
852
|
*
|
|
663
853
|
* @param value - The value to test.
|
|
664
|
-
* @returns True for `
|
|
854
|
+
* @returns True for a key event with a well-formed `control`, or a pointer event with `x` and `y`
|
|
855
|
+
* from 0 to 1 and, when present, an integer `button` from 0 to 4.
|
|
665
856
|
*
|
|
666
857
|
* @public
|
|
667
858
|
*/
|
|
668
|
-
function
|
|
669
|
-
|
|
859
|
+
function isSendInputEvent(value) {
|
|
860
|
+
if (!isRecord(value)) return false;
|
|
861
|
+
const type = value["type"];
|
|
862
|
+
if (type === "keydown" || type === "keyup") {
|
|
863
|
+
const control = value["control"];
|
|
864
|
+
return typeof control === "string" && KEY_CONTROL_PATTERN.test(control);
|
|
865
|
+
}
|
|
866
|
+
if (type !== "pointermove" && type !== "pointerdown" && type !== "pointerup") return false;
|
|
867
|
+
const button = value["button"];
|
|
868
|
+
return isFraction(value["x"]) && isFraction(value["y"]) && (button === void 0 || typeof button === "number" && Number.isInteger(button) && button >= 0 && button <= 4);
|
|
670
869
|
}
|
|
671
870
|
/**
|
|
672
|
-
* Checks
|
|
871
|
+
* Checks the `params` of `sendInput`.
|
|
673
872
|
*
|
|
674
|
-
* @param value - The
|
|
675
|
-
* @returns True for
|
|
676
|
-
* fields.
|
|
873
|
+
* @param value - The received `params`.
|
|
874
|
+
* @returns True for an `events` list of 1 to {@link SEND_INPUT_MAX_EVENTS} well-formed events.
|
|
677
875
|
*
|
|
678
876
|
* @public
|
|
679
877
|
*/
|
|
680
|
-
function
|
|
878
|
+
function isSendInputParams(value) {
|
|
681
879
|
if (!isRecord(value)) return false;
|
|
682
|
-
const
|
|
683
|
-
return
|
|
880
|
+
const events = value["events"];
|
|
881
|
+
return Array.isArray(events) && events.length > 0 && events.length <= 64 && events.every((event) => isSendInputEvent(event));
|
|
684
882
|
}
|
|
685
883
|
/**
|
|
686
|
-
* Checks
|
|
884
|
+
* Checks the `result` of `sendInput`.
|
|
687
885
|
*
|
|
688
|
-
* @param value - The
|
|
689
|
-
* @returns True for
|
|
886
|
+
* @param value - The received `result`.
|
|
887
|
+
* @returns True for an integer `queued` from 0 to {@link SEND_INPUT_MAX_EVENTS}.
|
|
690
888
|
*
|
|
691
889
|
* @public
|
|
692
890
|
*/
|
|
693
|
-
function
|
|
694
|
-
|
|
891
|
+
function isSendInputResult(value) {
|
|
892
|
+
if (!isRecord(value)) return false;
|
|
893
|
+
const queued = value["queued"];
|
|
894
|
+
return typeof queued === "number" && Number.isSafeInteger(queued) && queued >= 0 && queued <= 64;
|
|
695
895
|
}
|
|
696
896
|
//#endregion
|
|
697
897
|
//#region src/protocol/scene-ops.ts
|
|
@@ -1580,6 +1780,163 @@ function isLogParams(value) {
|
|
|
1580
1780
|
return isRecord(value) && isOneOf(LOG_LEVELS, value["level"]) && isHostTextOrNull(value["scope"]) && isHostText(value["message"]) && isFiniteNumber(value["timeMs"]) && optionalField(value, "error", (error) => isRecord(error) && isHostText(error["message"]) && isHostTextOrNull(error["code"]) && isHostTextOrNull(error["stack"]));
|
|
1581
1781
|
}
|
|
1582
1782
|
//#endregion
|
|
1783
|
+
//#region src/protocol/render-views.ts
|
|
1784
|
+
/**
|
|
1785
|
+
* Protocol 0.3, additive (engine ask E8): the scene host's second views, rendered through the
|
|
1786
|
+
* engine's render textures. The Game panel's view is the document's own camera rendered beside the
|
|
1787
|
+
* editor camera (`setGameView`, `gameViewFrame`); a thumbnail is an asset rendered on its own
|
|
1788
|
+
* (`renderThumbnail`). Both answer images in the shape of `screenshot`'s.
|
|
1789
|
+
*/
|
|
1790
|
+
/**
|
|
1791
|
+
* Editor → scene host: the render-view methods, answered after `ready` like every `SceneMethod`.
|
|
1792
|
+
*
|
|
1793
|
+
* @remarks
|
|
1794
|
+
* A host lists `HostCapability.gameView` when it answers the first two and
|
|
1795
|
+
* `HostCapability.thumbnails` when it answers the third; one that does not answers
|
|
1796
|
+
* `RpcErrorCode.methodNotFound`. Additive in 0.3.
|
|
1797
|
+
*
|
|
1798
|
+
* @public
|
|
1799
|
+
*/
|
|
1800
|
+
const RenderViewMethod = {
|
|
1801
|
+
/** Turns the Game panel's view on, off, or to a new size. Answers {@link GameViewState}. */
|
|
1802
|
+
setGameView: "setGameView",
|
|
1803
|
+
/**
|
|
1804
|
+
* Renders the open scene through its own main camera, the one the game would use, and answers
|
|
1805
|
+
* the image: {@link GameViewFrameResult}. Fails with `RpcErrorCode.noScene` while no scene is
|
|
1806
|
+
* open and `RpcErrorCode.invalidRequest` while the game view is off.
|
|
1807
|
+
*/
|
|
1808
|
+
gameViewFrame: "gameViewFrame",
|
|
1809
|
+
/** Renders one model or prefab asset on its own and answers the image: {@link ThumbnailResult}. */
|
|
1810
|
+
renderThumbnail: "renderThumbnail"
|
|
1811
|
+
};
|
|
1812
|
+
/**
|
|
1813
|
+
* The largest width and height, in pixels, of the game view.
|
|
1814
|
+
*
|
|
1815
|
+
* @public
|
|
1816
|
+
*/
|
|
1817
|
+
const GAME_VIEW_MAX_SIZE = 2048;
|
|
1818
|
+
/**
|
|
1819
|
+
* The game view's size until `setGameView` gives one: 640 by 360.
|
|
1820
|
+
*
|
|
1821
|
+
* @public
|
|
1822
|
+
*/
|
|
1823
|
+
const GAME_VIEW_DEFAULT_SIZE = {
|
|
1824
|
+
width: 640,
|
|
1825
|
+
height: 360
|
|
1826
|
+
};
|
|
1827
|
+
/**
|
|
1828
|
+
* The largest side, in pixels, of a thumbnail.
|
|
1829
|
+
*
|
|
1830
|
+
* @public
|
|
1831
|
+
*/
|
|
1832
|
+
const THUMBNAIL_MAX_SIZE = 1024;
|
|
1833
|
+
/**
|
|
1834
|
+
* A thumbnail's side when the request gives none.
|
|
1835
|
+
*
|
|
1836
|
+
* @public
|
|
1837
|
+
*/
|
|
1838
|
+
const THUMBNAIL_DEFAULT_SIZE = 128;
|
|
1839
|
+
/**
|
|
1840
|
+
* Tells whether a value is a whole number from 1 to a maximum.
|
|
1841
|
+
*
|
|
1842
|
+
* @param value - The value to test.
|
|
1843
|
+
* @param max - The largest value allowed.
|
|
1844
|
+
* @returns True for an integer in range.
|
|
1845
|
+
*/
|
|
1846
|
+
function isSide(value, max) {
|
|
1847
|
+
return Number.isSafeInteger(value) && Number(value) >= 1 && Number(value) <= max;
|
|
1848
|
+
}
|
|
1849
|
+
/**
|
|
1850
|
+
* Tells whether a value is an image format and, when present, a quality from 0 to 1.
|
|
1851
|
+
*
|
|
1852
|
+
* @param value - The record to test.
|
|
1853
|
+
* @returns True for a known format and a quality in range when given.
|
|
1854
|
+
*/
|
|
1855
|
+
function hasImageFormat(value) {
|
|
1856
|
+
const format = value["format"];
|
|
1857
|
+
return (format === ScreenshotFormat.png || format === ScreenshotFormat.jpeg) && optionalField(value, "quality", (quality) => isFiniteNumber(quality) && quality >= 0 && quality <= 1);
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Tells whether a value is a PNG or JPEG data URL.
|
|
1861
|
+
*
|
|
1862
|
+
* @param value - The value to test.
|
|
1863
|
+
* @returns True for a `data:image/png;base64,…` or `data:image/jpeg;base64,…` string.
|
|
1864
|
+
*/
|
|
1865
|
+
function isImageDataUrl(value) {
|
|
1866
|
+
return isString(value) && /^data:image\/(?:png|jpeg);base64,/u.test(value);
|
|
1867
|
+
}
|
|
1868
|
+
/**
|
|
1869
|
+
* Checks the parameters of `setGameView`.
|
|
1870
|
+
*
|
|
1871
|
+
* @param value - The received `params`.
|
|
1872
|
+
* @returns True for a boolean `enabled` and sizes in range when given.
|
|
1873
|
+
*
|
|
1874
|
+
* @public
|
|
1875
|
+
*/
|
|
1876
|
+
function isSetGameViewParams(value) {
|
|
1877
|
+
return isRecord(value) && typeof value["enabled"] === "boolean" && optionalField(value, "width", (width) => isSide(width, 2048)) && optionalField(value, "height", (height) => isSide(height, 2048));
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Checks the result of `setGameView`.
|
|
1881
|
+
*
|
|
1882
|
+
* @param value - The received `result`.
|
|
1883
|
+
* @returns True for a boolean `enabled` and sizes in range.
|
|
1884
|
+
*
|
|
1885
|
+
* @public
|
|
1886
|
+
*/
|
|
1887
|
+
function isGameViewState(value) {
|
|
1888
|
+
return isRecord(value) && typeof value["enabled"] === "boolean" && isSide(value["width"], 2048) && isSide(value["height"], 2048);
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Checks the parameters of `gameViewFrame`.
|
|
1892
|
+
*
|
|
1893
|
+
* @param value - The received `params`.
|
|
1894
|
+
* @returns True for a known format and a quality from 0 to 1 when given.
|
|
1895
|
+
*
|
|
1896
|
+
* @public
|
|
1897
|
+
*/
|
|
1898
|
+
function isGameViewFrameParams(value) {
|
|
1899
|
+
return isRecord(value) && hasImageFormat(value);
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* Checks the result of `gameViewFrame`.
|
|
1903
|
+
*
|
|
1904
|
+
* @param value - The received `result`.
|
|
1905
|
+
* @returns True for an image and a camera uid, or `null` for both, and sizes in range.
|
|
1906
|
+
*
|
|
1907
|
+
* @public
|
|
1908
|
+
*/
|
|
1909
|
+
function isGameViewFrameResult(value) {
|
|
1910
|
+
if (!isRecord(value) || !isSide(value["width"], 2048) || !isSide(value["height"], 2048)) return false;
|
|
1911
|
+
const dataUrl = value["dataUrl"];
|
|
1912
|
+
const camera = value["camera"];
|
|
1913
|
+
return dataUrl === null ? camera === null : isImageDataUrl(dataUrl) && isUidString(camera);
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* Checks the parameters of `renderThumbnail`.
|
|
1917
|
+
*
|
|
1918
|
+
* @param value - The received `params`.
|
|
1919
|
+
* @returns True for an address or asset reference, a size in range when given, and a known format.
|
|
1920
|
+
*
|
|
1921
|
+
* @public
|
|
1922
|
+
*/
|
|
1923
|
+
function isRenderThumbnailParams(value) {
|
|
1924
|
+
if (!isRecord(value) || !hasImageFormat(value)) return false;
|
|
1925
|
+
const asset = value["asset"];
|
|
1926
|
+
return (isString(asset) && asset.length > 0 || isSceneFileAssetRef(asset)) && optionalField(value, "size", (size) => isSide(size, 1024));
|
|
1927
|
+
}
|
|
1928
|
+
/**
|
|
1929
|
+
* Checks the result of `renderThumbnail`.
|
|
1930
|
+
*
|
|
1931
|
+
* @param value - The received `result`.
|
|
1932
|
+
* @returns True for an image and sizes in range.
|
|
1933
|
+
*
|
|
1934
|
+
* @public
|
|
1935
|
+
*/
|
|
1936
|
+
function isThumbnailResult(value) {
|
|
1937
|
+
return isRecord(value) && isImageDataUrl(value["dataUrl"]) && isSide(value["width"], 1024) && isSide(value["height"], 1024);
|
|
1938
|
+
}
|
|
1939
|
+
//#endregion
|
|
1583
1940
|
//#region src/protocol/version.ts
|
|
1584
1941
|
/**
|
|
1585
1942
|
* The protocol version this package describes. The editor sends it in `hello` and the host in
|
|
@@ -2362,6 +2719,16 @@ function createEditorView(handles, overlay, canvas) {
|
|
|
2362
2719
|
};
|
|
2363
2720
|
}
|
|
2364
2721
|
/**
|
|
2722
|
+
* The world bounds of every visible mesh an entity draws, without a view: for a thumbnail stage.
|
|
2723
|
+
*
|
|
2724
|
+
* @param handles - The app's Lite engine and render scene (`app.lite`).
|
|
2725
|
+
* @param entity - The entity.
|
|
2726
|
+
* @returns The box, or `null` when nothing under the entity is drawn yet.
|
|
2727
|
+
*/
|
|
2728
|
+
function entityWorldBounds(handles, entity) {
|
|
2729
|
+
return computeWorldBounds(entity.transform.lite, handles.scene);
|
|
2730
|
+
}
|
|
2731
|
+
/**
|
|
2365
2732
|
* A node's parent. Lite types it as a bare world-matrix provider, so it is followed by identity only.
|
|
2366
2733
|
*
|
|
2367
2734
|
* @param node - The node.
|
|
@@ -4606,6 +4973,181 @@ function conjugate(q) {
|
|
|
4606
4973
|
];
|
|
4607
4974
|
}
|
|
4608
4975
|
//#endregion
|
|
4976
|
+
//#region src/scene/screenshot.ts
|
|
4977
|
+
/**
|
|
4978
|
+
* `screenshot`, shared by the scene view and the play view: the parameter check, and a captured
|
|
4979
|
+
* frame scaled to the requested size and written as a PNG or JPEG data URL. Encoding needs a
|
|
4980
|
+
* browser's `OffscreenCanvas`, as the capture needs a GPU.
|
|
4981
|
+
*/
|
|
4982
|
+
/** The JPEG quality when the request gives none. */
|
|
4983
|
+
const DEFAULT_JPEG_QUALITY$2 = .9;
|
|
4984
|
+
/** Bytes encoded per `String.fromCharCode` call, to stay under engines' argument limits. */
|
|
4985
|
+
const BASE64_CHUNK = 32768;
|
|
4986
|
+
/**
|
|
4987
|
+
* Encodes bytes as base64.
|
|
4988
|
+
*
|
|
4989
|
+
* @param bytes - The bytes.
|
|
4990
|
+
* @returns The base64 text.
|
|
4991
|
+
*/
|
|
4992
|
+
function toBase64(bytes) {
|
|
4993
|
+
let binary = "";
|
|
4994
|
+
for (let start = 0; start < bytes.length; start += BASE64_CHUNK) binary += String.fromCharCode(...bytes.subarray(start, start + BASE64_CHUNK));
|
|
4995
|
+
return btoa(binary);
|
|
4996
|
+
}
|
|
4997
|
+
/**
|
|
4998
|
+
* Scales a captured frame to a size and encodes it as a data URL.
|
|
4999
|
+
*
|
|
5000
|
+
* @param capture - The frame, RGBA8 with the top row first.
|
|
5001
|
+
* @param size - The image size.
|
|
5002
|
+
* @param format - `"png"` or `"jpeg"`.
|
|
5003
|
+
* @param quality - The JPEG quality, from 0 to 1; ignored for PNG.
|
|
5004
|
+
* @returns A `data:image/png;base64,…` or `data:image/jpeg;base64,…` URL.
|
|
5005
|
+
* @throws Error when the browser has no 2D canvas context.
|
|
5006
|
+
*/
|
|
5007
|
+
async function encodeCapture(capture, size, format, quality) {
|
|
5008
|
+
const source = new OffscreenCanvas(capture.width, capture.height);
|
|
5009
|
+
const sourceContext = source.getContext("2d");
|
|
5010
|
+
const target = new OffscreenCanvas(size.width, size.height);
|
|
5011
|
+
const targetContext = target.getContext("2d");
|
|
5012
|
+
if (sourceContext === null || targetContext === null) throw new Error("This browser has no 2D canvas to encode the screenshot with.");
|
|
5013
|
+
sourceContext.putImageData(new ImageData(new Uint8ClampedArray(capture.data), capture.width, capture.height), 0, 0);
|
|
5014
|
+
targetContext.imageSmoothingQuality = "high";
|
|
5015
|
+
targetContext.drawImage(source, 0, 0, size.width, size.height);
|
|
5016
|
+
const type = format === "png" ? "image/png" : "image/jpeg";
|
|
5017
|
+
const blob = await target.convertToBlob(format === "png" ? { type } : {
|
|
5018
|
+
type,
|
|
5019
|
+
quality
|
|
5020
|
+
});
|
|
5021
|
+
return `data:${type};base64,${toBase64(new Uint8Array(await blob.arrayBuffer()))}`;
|
|
5022
|
+
}
|
|
5023
|
+
/**
|
|
5024
|
+
* Checks `screenshot`'s parameters.
|
|
5025
|
+
*
|
|
5026
|
+
* @param params - The received `params`.
|
|
5027
|
+
* @returns The parameters.
|
|
5028
|
+
* @throws InvalidParamsError for a side outside 1 to {@link SCREENSHOT_MAX_SIZE}, an unknown format, or
|
|
5029
|
+
* a quality outside 0 to 1.
|
|
5030
|
+
*/
|
|
5031
|
+
function checkScreenshotParams(params) {
|
|
5032
|
+
if (typeof params === "object" && params !== null) for (const side of ["width", "height"]) {
|
|
5033
|
+
const value = Reflect.get(params, side);
|
|
5034
|
+
if (value !== void 0 && (!Number.isSafeInteger(value) || Number(value) < 1 || Number(value) > 2048)) throw new InvalidParamsError(`screenshot takes a width and height from 1 to ${String(SCREENSHOT_MAX_SIZE)} pixels.`);
|
|
5035
|
+
}
|
|
5036
|
+
if (!isScreenshotParams(params)) throw new InvalidParamsError("screenshot takes { width?, height?, format: \"png\" | \"jpeg\", quality? }.");
|
|
5037
|
+
return params;
|
|
5038
|
+
}
|
|
5039
|
+
/**
|
|
5040
|
+
* Captures the app's next presented frame and encodes it as `screenshot` answers.
|
|
5041
|
+
*
|
|
5042
|
+
* @param app - The app whose canvas is captured.
|
|
5043
|
+
* @param params - Checked parameters.
|
|
5044
|
+
* @returns The data URL and its size.
|
|
5045
|
+
* @throws IgnifxError `IGX-0707` when the app's render loop does not run.
|
|
5046
|
+
*/
|
|
5047
|
+
async function takeScreenshot(app, params) {
|
|
5048
|
+
const capture = await app.renderer.captureScreenshot();
|
|
5049
|
+
const size = screenshotSize(params, capture);
|
|
5050
|
+
return {
|
|
5051
|
+
dataUrl: await encodeCapture(capture, size, params.format, params.quality ?? DEFAULT_JPEG_QUALITY$2),
|
|
5052
|
+
width: size.width,
|
|
5053
|
+
height: size.height
|
|
5054
|
+
};
|
|
5055
|
+
}
|
|
5056
|
+
//#endregion
|
|
5057
|
+
//#region src/scene/game-view.ts
|
|
5058
|
+
/**
|
|
5059
|
+
* The Game panel's view (engine ask E8): the open scene through its own main camera, rendered into
|
|
5060
|
+
* a render texture beside the editor camera's frame (`setGameView`, `gameViewFrame`).
|
|
5061
|
+
*/
|
|
5062
|
+
/** The JPEG quality when the request gives none, as for `screenshot`. */
|
|
5063
|
+
const DEFAULT_JPEG_QUALITY$1 = .9;
|
|
5064
|
+
/**
|
|
5065
|
+
* The camera the game would render the open scene through: the enabled document camera with the
|
|
5066
|
+
* highest priority, the first one on a tie, as the engine picks its main camera.
|
|
5067
|
+
*
|
|
5068
|
+
* @param app - The scene view's app.
|
|
5069
|
+
* @param mirror - The open document.
|
|
5070
|
+
* @returns The camera, or `null` when the document has no enabled one.
|
|
5071
|
+
*/
|
|
5072
|
+
function documentCamera(app, mirror) {
|
|
5073
|
+
const scene = mirror.scene;
|
|
5074
|
+
let best = null;
|
|
5075
|
+
for (const camera of app.world.components(Camera)) {
|
|
5076
|
+
if (camera.entity.scene !== scene || !camera.isEnabledInHierarchy) continue;
|
|
5077
|
+
if (best === null || camera.priority > best.priority) best = camera;
|
|
5078
|
+
}
|
|
5079
|
+
return best;
|
|
5080
|
+
}
|
|
5081
|
+
/** The game view's state and texture. */
|
|
5082
|
+
var GameView = class {
|
|
5083
|
+
#enabled = false;
|
|
5084
|
+
#width = GAME_VIEW_DEFAULT_SIZE.width;
|
|
5085
|
+
#height = GAME_VIEW_DEFAULT_SIZE.height;
|
|
5086
|
+
#texture = null;
|
|
5087
|
+
/**
|
|
5088
|
+
* `setGameView`: turns the view on or off, or resizes it. Off frees the texture.
|
|
5089
|
+
*
|
|
5090
|
+
* @param app - The scene view's app.
|
|
5091
|
+
* @param params - `{ enabled, width?, height? }`.
|
|
5092
|
+
* @returns The view as it now is.
|
|
5093
|
+
*/
|
|
5094
|
+
set(app, params) {
|
|
5095
|
+
if (!isSetGameViewParams(params)) throw new InvalidParamsError("setGameView takes { enabled: boolean, width?, height? } with sides from 1 to 2048.");
|
|
5096
|
+
const width = params.width ?? this.#width;
|
|
5097
|
+
const height = params.height ?? this.#height;
|
|
5098
|
+
if (!params.enabled || width !== this.#width || height !== this.#height) {
|
|
5099
|
+
this.#texture?.dispose();
|
|
5100
|
+
this.#texture = null;
|
|
5101
|
+
}
|
|
5102
|
+
this.#enabled = params.enabled;
|
|
5103
|
+
this.#width = width;
|
|
5104
|
+
this.#height = height;
|
|
5105
|
+
if (this.#enabled) this.#texture ??= app.renderer.createRenderTexture(width, height);
|
|
5106
|
+
return {
|
|
5107
|
+
enabled: this.#enabled,
|
|
5108
|
+
width,
|
|
5109
|
+
height
|
|
5110
|
+
};
|
|
5111
|
+
}
|
|
5112
|
+
/**
|
|
5113
|
+
* `gameViewFrame`: renders the document camera into the texture on the next frame and answers it
|
|
5114
|
+
* as an image.
|
|
5115
|
+
*
|
|
5116
|
+
* @param app - The scene view's app.
|
|
5117
|
+
* @param mirror - The open document.
|
|
5118
|
+
* @param params - `{ format, quality? }`.
|
|
5119
|
+
* @returns The image and the camera's document uid, or no image when the document has no camera.
|
|
5120
|
+
*/
|
|
5121
|
+
async frame(app, mirror, params) {
|
|
5122
|
+
if (!isGameViewFrameParams(params)) throw new InvalidParamsError("gameViewFrame takes { format: \"png\" | \"jpeg\", quality? }.");
|
|
5123
|
+
const texture = this.#texture;
|
|
5124
|
+
if (!this.#enabled || texture === null) throw new RpcFailure(RpcErrorCode.invalidRequest, "The game view is off; send \"setGameView\" with enabled: true first.");
|
|
5125
|
+
const size = {
|
|
5126
|
+
width: this.#width,
|
|
5127
|
+
height: this.#height
|
|
5128
|
+
};
|
|
5129
|
+
const camera = documentCamera(app, mirror);
|
|
5130
|
+
if (camera === null) return {
|
|
5131
|
+
dataUrl: null,
|
|
5132
|
+
...size,
|
|
5133
|
+
camera: null
|
|
5134
|
+
};
|
|
5135
|
+
const uid = (mirror.documentEntityOf(camera.entity) ?? camera.entity).uid;
|
|
5136
|
+
await app.renderer.renderToTexture(camera, texture);
|
|
5137
|
+
return {
|
|
5138
|
+
dataUrl: await encodeCapture(await texture.readPixels(), size, params.format, params.quality ?? DEFAULT_JPEG_QUALITY$1),
|
|
5139
|
+
...size,
|
|
5140
|
+
camera: uid
|
|
5141
|
+
};
|
|
5142
|
+
}
|
|
5143
|
+
/** Frees the texture. */
|
|
5144
|
+
dispose() {
|
|
5145
|
+
this.#texture?.dispose();
|
|
5146
|
+
this.#texture = null;
|
|
5147
|
+
this.#enabled = false;
|
|
5148
|
+
}
|
|
5149
|
+
};
|
|
5150
|
+
//#endregion
|
|
4609
5151
|
//#region src/scene/gizmo-drag.ts
|
|
4610
5152
|
/**
|
|
4611
5153
|
* Turns one gizmo drag into the scene view's drag notifications. It needs no GPU: the view calls
|
|
@@ -5707,8 +6249,11 @@ const COMPONENTS_FORMAT = "components";
|
|
|
5707
6249
|
* @remarks
|
|
5708
6250
|
* Each field carries its inspector options (`step`, `hidden`, `readonly`, `group`, an asset's
|
|
5709
6251
|
* `assetType`, a `componentRef`'s `componentType`), and each component its `allowMultiple` and the
|
|
5710
|
-
* `package` that registered it, all optional members of protocol 0.3.
|
|
5711
|
-
*
|
|
6252
|
+
* `package` that registered it, all optional members of protocol 0.3. Each component's title and
|
|
6253
|
+
* summary are its class's own `static title` and `static description`, which every package
|
|
6254
|
+
* declares on its components, so an extension's curated names arrive without the host importing
|
|
6255
|
+
* the extension; core's `describeSchemas()` still overrides core's entries, and a component with
|
|
6256
|
+
* neither is titled from its type id. The host's own classes are left out: they are not the
|
|
5712
6257
|
* document's. `ignifx/Transform` is described with core's `transformSchema()` and carries
|
|
5713
6258
|
* `builtIn`: its fields are each entity's `transform` block, edited with `setTransform`, and it is
|
|
5714
6259
|
* never added or removed. Each component also carries `extends` (engine ask E44): the registered
|
|
@@ -5757,50 +6302,9 @@ function registeredAncestors(registry, type) {
|
|
|
5757
6302
|
const ancestors = registry.describe(type).ancestors;
|
|
5758
6303
|
for (let index = 1; index < ancestors.length; index += 1) {
|
|
5759
6304
|
const ancestor = ancestors[index];
|
|
5760
|
-
if (ancestor !== void 0 && registry.isRegistered(ancestor)) ids.push(registry.requireTypeId(ancestor));
|
|
5761
|
-
}
|
|
5762
|
-
return ids;
|
|
5763
|
-
}
|
|
5764
|
-
//#endregion
|
|
5765
|
-
//#region src/scene/screenshot.ts
|
|
5766
|
-
/** Bytes encoded per `String.fromCharCode` call, to stay under engines' argument limits. */
|
|
5767
|
-
const BASE64_CHUNK = 32768;
|
|
5768
|
-
/**
|
|
5769
|
-
* Encodes bytes as base64.
|
|
5770
|
-
*
|
|
5771
|
-
* @param bytes - The bytes.
|
|
5772
|
-
* @returns The base64 text.
|
|
5773
|
-
*/
|
|
5774
|
-
function toBase64(bytes) {
|
|
5775
|
-
let binary = "";
|
|
5776
|
-
for (let start = 0; start < bytes.length; start += BASE64_CHUNK) binary += String.fromCharCode(...bytes.subarray(start, start + BASE64_CHUNK));
|
|
5777
|
-
return btoa(binary);
|
|
5778
|
-
}
|
|
5779
|
-
/**
|
|
5780
|
-
* Scales a captured frame to a size and encodes it as a data URL.
|
|
5781
|
-
*
|
|
5782
|
-
* @param capture - The frame, RGBA8 with the top row first.
|
|
5783
|
-
* @param size - The image size.
|
|
5784
|
-
* @param format - `"png"` or `"jpeg"`.
|
|
5785
|
-
* @param quality - The JPEG quality, from 0 to 1; ignored for PNG.
|
|
5786
|
-
* @returns A `data:image/png;base64,…` or `data:image/jpeg;base64,…` URL.
|
|
5787
|
-
* @throws Error when the browser has no 2D canvas context.
|
|
5788
|
-
*/
|
|
5789
|
-
async function encodeCapture(capture, size, format, quality) {
|
|
5790
|
-
const source = new OffscreenCanvas(capture.width, capture.height);
|
|
5791
|
-
const sourceContext = source.getContext("2d");
|
|
5792
|
-
const target = new OffscreenCanvas(size.width, size.height);
|
|
5793
|
-
const targetContext = target.getContext("2d");
|
|
5794
|
-
if (sourceContext === null || targetContext === null) throw new Error("This browser has no 2D canvas to encode the screenshot with.");
|
|
5795
|
-
sourceContext.putImageData(new ImageData(new Uint8ClampedArray(capture.data), capture.width, capture.height), 0, 0);
|
|
5796
|
-
targetContext.imageSmoothingQuality = "high";
|
|
5797
|
-
targetContext.drawImage(source, 0, 0, size.width, size.height);
|
|
5798
|
-
const type = format === "png" ? "image/png" : "image/jpeg";
|
|
5799
|
-
const blob = await target.convertToBlob(format === "png" ? { type } : {
|
|
5800
|
-
type,
|
|
5801
|
-
quality
|
|
5802
|
-
});
|
|
5803
|
-
return `data:${type};base64,${toBase64(new Uint8Array(await blob.arrayBuffer()))}`;
|
|
6305
|
+
if (ancestor !== void 0 && registry.isRegistered(ancestor)) ids.push(registry.requireTypeId(ancestor));
|
|
6306
|
+
}
|
|
6307
|
+
return ids;
|
|
5804
6308
|
}
|
|
5805
6309
|
//#endregion
|
|
5806
6310
|
//#region src/scene/settings.ts
|
|
@@ -5877,6 +6381,311 @@ function settingsSet(app) {
|
|
|
5877
6381
|
};
|
|
5878
6382
|
}
|
|
5879
6383
|
//#endregion
|
|
6384
|
+
//#region src/scene/thumbnails.ts
|
|
6385
|
+
/**
|
|
6386
|
+
* `renderThumbnail` (engine ask E8): a model or prefab rendered on its own, in a second app the
|
|
6387
|
+
* host keeps for the purpose, through `app.renderer.renderToTexture`.
|
|
6388
|
+
*
|
|
6389
|
+
* The stage is a separate app on a 1x1 `OffscreenCanvas`, built from the project's own options, so
|
|
6390
|
+
* a thumbnail never shows the open document, never lights it, and is never lit by it. It is
|
|
6391
|
+
* created on the first request and lives until the host is disposed.
|
|
6392
|
+
*/
|
|
6393
|
+
/** The JPEG quality when the request gives none, as for `screenshot`. */
|
|
6394
|
+
const DEFAULT_JPEG_QUALITY = .9;
|
|
6395
|
+
/** The stage camera's vertical field of view, in degrees. */
|
|
6396
|
+
const STAGE_FOV = 35;
|
|
6397
|
+
/** The texture is this many times the image's side, and scaled down when encoded. */
|
|
6398
|
+
const SUPERSAMPLE = 2;
|
|
6399
|
+
/** How many frames a load is given to build its meshes before the thumbnail is taken anyway. */
|
|
6400
|
+
const MAX_SETTLE_FRAMES = 120;
|
|
6401
|
+
/** How many frames in a row the bounds must hold still before the thumbnail is taken. */
|
|
6402
|
+
const STILL_FRAMES = 2;
|
|
6403
|
+
/** The direction from the subject to the camera: in front, above and to the right. */
|
|
6404
|
+
const VIEW_DIRECTION = {
|
|
6405
|
+
x: .55,
|
|
6406
|
+
y: .45,
|
|
6407
|
+
z: -.7
|
|
6408
|
+
};
|
|
6409
|
+
/**
|
|
6410
|
+
* Types the requested asset.
|
|
6411
|
+
*
|
|
6412
|
+
* @param params - Checked parameters.
|
|
6413
|
+
* @returns The address and what it is.
|
|
6414
|
+
* @throws InvalidParamsError for an asset that is neither a model nor a prefab.
|
|
6415
|
+
*/
|
|
6416
|
+
function thumbnailSubject(params) {
|
|
6417
|
+
const asset = params.asset;
|
|
6418
|
+
const address = typeof asset === "string" ? asset : asset.$asset;
|
|
6419
|
+
const type = typeof asset === "string" ? void 0 : asset.type;
|
|
6420
|
+
const lower = address.toLowerCase();
|
|
6421
|
+
if (type === "model" || type === void 0 && (lower.endsWith(".glb") || lower.endsWith(".gltf"))) return {
|
|
6422
|
+
address,
|
|
6423
|
+
kind: "model"
|
|
6424
|
+
};
|
|
6425
|
+
if (type === "scene" || type === "prefab" || type === void 0 && (lower.endsWith(".prefab.json") || lower.endsWith(".scene.json"))) return {
|
|
6426
|
+
address,
|
|
6427
|
+
kind: "prefab"
|
|
6428
|
+
};
|
|
6429
|
+
throw new InvalidParamsError(`renderThumbnail renders models (.glb, .gltf) and prefabs (.prefab.json); ${address} is neither.`);
|
|
6430
|
+
}
|
|
6431
|
+
/**
|
|
6432
|
+
* The one-entity scene file that shows a subject.
|
|
6433
|
+
*
|
|
6434
|
+
* @param address - The asset address.
|
|
6435
|
+
* @param kind - What it is.
|
|
6436
|
+
* @returns The file.
|
|
6437
|
+
*/
|
|
6438
|
+
function thumbnailScene(address, kind) {
|
|
6439
|
+
const transform = {
|
|
6440
|
+
position: [
|
|
6441
|
+
0,
|
|
6442
|
+
0,
|
|
6443
|
+
0
|
|
6444
|
+
],
|
|
6445
|
+
rotation: [
|
|
6446
|
+
0,
|
|
6447
|
+
0,
|
|
6448
|
+
0,
|
|
6449
|
+
1
|
|
6450
|
+
],
|
|
6451
|
+
scale: [
|
|
6452
|
+
1,
|
|
6453
|
+
1,
|
|
6454
|
+
1
|
|
6455
|
+
]
|
|
6456
|
+
};
|
|
6457
|
+
return {
|
|
6458
|
+
format: "ignifx.scene",
|
|
6459
|
+
formatVersion: 1,
|
|
6460
|
+
name: "thumbnail",
|
|
6461
|
+
entities: [kind === "model" ? {
|
|
6462
|
+
uid: "thumbnail-subject",
|
|
6463
|
+
name: "Thumbnail",
|
|
6464
|
+
parent: null,
|
|
6465
|
+
transform,
|
|
6466
|
+
components: [{
|
|
6467
|
+
uid: "thumbnail-model",
|
|
6468
|
+
type: "ignifx/Model",
|
|
6469
|
+
props: { model: {
|
|
6470
|
+
$asset: address,
|
|
6471
|
+
type: "model"
|
|
6472
|
+
} }
|
|
6473
|
+
}]
|
|
6474
|
+
} : {
|
|
6475
|
+
uid: "thumbnail-subject",
|
|
6476
|
+
name: "Thumbnail",
|
|
6477
|
+
parent: null,
|
|
6478
|
+
transform,
|
|
6479
|
+
instance: { scene: { $asset: address } }
|
|
6480
|
+
}]
|
|
6481
|
+
};
|
|
6482
|
+
}
|
|
6483
|
+
/** Renders thumbnails on a stage app of their own. */
|
|
6484
|
+
var ThumbnailRenderer = class {
|
|
6485
|
+
#createApp;
|
|
6486
|
+
#stage = null;
|
|
6487
|
+
#texture = null;
|
|
6488
|
+
#loads = 0;
|
|
6489
|
+
#isDisposed = false;
|
|
6490
|
+
/**
|
|
6491
|
+
* Keeps the factory; nothing is created until the first thumbnail.
|
|
6492
|
+
*
|
|
6493
|
+
* @param createApp - Creates the stage app from the project's options, unstarted.
|
|
6494
|
+
*/
|
|
6495
|
+
constructor(createApp) {
|
|
6496
|
+
this.#createApp = createApp;
|
|
6497
|
+
}
|
|
6498
|
+
/**
|
|
6499
|
+
* `renderThumbnail`: loads the asset alone on the stage, frames it, renders it and encodes it.
|
|
6500
|
+
*
|
|
6501
|
+
* @param params - `{ asset, size?, format, quality? }`.
|
|
6502
|
+
* @returns The image.
|
|
6503
|
+
*/
|
|
6504
|
+
async render(params) {
|
|
6505
|
+
if (!isRenderThumbnailParams(params)) throw new InvalidParamsError("renderThumbnail takes { asset: address | { $asset, type? }, size?: 1 to 1024, format: \"png\" | \"jpeg\", quality? }.");
|
|
6506
|
+
const { address, kind } = thumbnailSubject(params);
|
|
6507
|
+
const { app, camera } = await (this.#stage ??= this.#open());
|
|
6508
|
+
this.#loads += 1;
|
|
6509
|
+
const instance = await app.world.loadSceneFile(thumbnailScene(address, kind), {
|
|
6510
|
+
address: `__ignifx_thumbnail__/${String(this.#loads)}.scene.json`,
|
|
6511
|
+
mode: "single"
|
|
6512
|
+
});
|
|
6513
|
+
try {
|
|
6514
|
+
frameCamera(camera, await settledBounds(app, instance));
|
|
6515
|
+
await nextFrame();
|
|
6516
|
+
const size = params.size ?? 128;
|
|
6517
|
+
const texture = this.#textureOf(app, size * SUPERSAMPLE);
|
|
6518
|
+
await app.renderer.renderToTexture(camera, texture);
|
|
6519
|
+
return {
|
|
6520
|
+
dataUrl: await encodeCapture(await texture.readPixels(), {
|
|
6521
|
+
width: size,
|
|
6522
|
+
height: size
|
|
6523
|
+
}, params.format, params.quality ?? DEFAULT_JPEG_QUALITY),
|
|
6524
|
+
width: size,
|
|
6525
|
+
height: size
|
|
6526
|
+
};
|
|
6527
|
+
} finally {
|
|
6528
|
+
await app.world.unloadScene(instance);
|
|
6529
|
+
}
|
|
6530
|
+
}
|
|
6531
|
+
/** Disposes the stage app, now or once it has been created. */
|
|
6532
|
+
dispose() {
|
|
6533
|
+
this.#isDisposed = true;
|
|
6534
|
+
this.#texture = null;
|
|
6535
|
+
this.#stage?.then((stage) => {
|
|
6536
|
+
stage.app.dispose();
|
|
6537
|
+
}, () => null);
|
|
6538
|
+
}
|
|
6539
|
+
/**
|
|
6540
|
+
* Creates and starts the stage: a persistent scene with the camera and two lights.
|
|
6541
|
+
*
|
|
6542
|
+
* @returns The stage.
|
|
6543
|
+
*/
|
|
6544
|
+
async #open() {
|
|
6545
|
+
const app = await this.#createApp();
|
|
6546
|
+
const scene = app.world.createScene("thumbnail-stage", { persistent: true });
|
|
6547
|
+
const camera = app.world.createEntity("Thumbnail Camera", { scene }).addComponent(Camera, {
|
|
6548
|
+
fov: STAGE_FOV,
|
|
6549
|
+
near: .01,
|
|
6550
|
+
far: 1e3
|
|
6551
|
+
});
|
|
6552
|
+
app.world.createEntity("Thumbnail Sky", { scene }).addComponent(Light, {
|
|
6553
|
+
type: "hemispheric",
|
|
6554
|
+
intensity: .8
|
|
6555
|
+
});
|
|
6556
|
+
const sun = app.world.createEntity("Thumbnail Sun", { scene });
|
|
6557
|
+
sun.transform.localPosition.set(4, 6, -5);
|
|
6558
|
+
sun.transform.lookAt({
|
|
6559
|
+
x: 0,
|
|
6560
|
+
y: 0,
|
|
6561
|
+
z: 0
|
|
6562
|
+
});
|
|
6563
|
+
sun.addComponent(Light, {
|
|
6564
|
+
type: "directional",
|
|
6565
|
+
intensity: 2
|
|
6566
|
+
});
|
|
6567
|
+
await app.start();
|
|
6568
|
+
if (this.#isDisposed) app.dispose();
|
|
6569
|
+
return {
|
|
6570
|
+
app,
|
|
6571
|
+
camera
|
|
6572
|
+
};
|
|
6573
|
+
}
|
|
6574
|
+
/**
|
|
6575
|
+
* The stage's texture at a side, created again when the side changes.
|
|
6576
|
+
*
|
|
6577
|
+
* @param app - The stage app.
|
|
6578
|
+
* @param side - The side in pixels.
|
|
6579
|
+
* @returns The texture.
|
|
6580
|
+
*/
|
|
6581
|
+
#textureOf(app, side) {
|
|
6582
|
+
const current = this.#texture;
|
|
6583
|
+
if (current !== null && current.width === side && !current.isDisposed) return current;
|
|
6584
|
+
current?.dispose();
|
|
6585
|
+
const texture = app.renderer.createRenderTexture(side, side);
|
|
6586
|
+
this.#texture = texture;
|
|
6587
|
+
return texture;
|
|
6588
|
+
}
|
|
6589
|
+
};
|
|
6590
|
+
/**
|
|
6591
|
+
* Waits one animation frame.
|
|
6592
|
+
*
|
|
6593
|
+
* @returns A promise that settles in the next frame callback.
|
|
6594
|
+
*/
|
|
6595
|
+
function nextFrame() {
|
|
6596
|
+
return new Promise((resolve) => {
|
|
6597
|
+
requestAnimationFrame(() => {
|
|
6598
|
+
resolve();
|
|
6599
|
+
});
|
|
6600
|
+
});
|
|
6601
|
+
}
|
|
6602
|
+
/**
|
|
6603
|
+
* Waits until a loaded subject's meshes exist and hold still, then measures them.
|
|
6604
|
+
*
|
|
6605
|
+
* @param app - The stage app.
|
|
6606
|
+
* @param instance - The loaded subject.
|
|
6607
|
+
* @returns Its world bounds; a unit box at the origin when nothing draws.
|
|
6608
|
+
*/
|
|
6609
|
+
async function settledBounds(app, instance) {
|
|
6610
|
+
let last = null;
|
|
6611
|
+
let still = 0;
|
|
6612
|
+
for (let frame = 0; frame < MAX_SETTLE_FRAMES && still < STILL_FRAMES; frame += 1) {
|
|
6613
|
+
await nextFrame();
|
|
6614
|
+
const bounds = unionBounds(app, instance.roots);
|
|
6615
|
+
still = bounds !== null && last !== null && sameBounds(bounds, last) ? still + 1 : 0;
|
|
6616
|
+
last = bounds;
|
|
6617
|
+
}
|
|
6618
|
+
return last ?? {
|
|
6619
|
+
min: {
|
|
6620
|
+
x: -.5,
|
|
6621
|
+
y: -.5,
|
|
6622
|
+
z: -.5
|
|
6623
|
+
},
|
|
6624
|
+
max: {
|
|
6625
|
+
x: .5,
|
|
6626
|
+
y: .5,
|
|
6627
|
+
z: .5
|
|
6628
|
+
}
|
|
6629
|
+
};
|
|
6630
|
+
}
|
|
6631
|
+
/**
|
|
6632
|
+
* The union of entities' world bounds.
|
|
6633
|
+
*
|
|
6634
|
+
* @param app - The stage app.
|
|
6635
|
+
* @param entities - The entities.
|
|
6636
|
+
* @returns The box, or `null` when none draws.
|
|
6637
|
+
*/
|
|
6638
|
+
function unionBounds(app, entities) {
|
|
6639
|
+
let result = null;
|
|
6640
|
+
for (const entity of entities) {
|
|
6641
|
+
const box = entityWorldBounds(app.lite, entity);
|
|
6642
|
+
if (box === null) continue;
|
|
6643
|
+
result = result === null ? box : {
|
|
6644
|
+
min: {
|
|
6645
|
+
x: Math.min(result.min.x, box.min.x),
|
|
6646
|
+
y: Math.min(result.min.y, box.min.y),
|
|
6647
|
+
z: Math.min(result.min.z, box.min.z)
|
|
6648
|
+
},
|
|
6649
|
+
max: {
|
|
6650
|
+
x: Math.max(result.max.x, box.max.x),
|
|
6651
|
+
y: Math.max(result.max.y, box.max.y),
|
|
6652
|
+
z: Math.max(result.max.z, box.max.z)
|
|
6653
|
+
}
|
|
6654
|
+
};
|
|
6655
|
+
}
|
|
6656
|
+
return result;
|
|
6657
|
+
}
|
|
6658
|
+
/**
|
|
6659
|
+
* Tells whether two boxes are equal.
|
|
6660
|
+
*
|
|
6661
|
+
* @param a - One box.
|
|
6662
|
+
* @param b - The other.
|
|
6663
|
+
* @returns True for the same corners.
|
|
6664
|
+
*/
|
|
6665
|
+
function sameBounds(a, b) {
|
|
6666
|
+
return a.min.x === b.min.x && a.min.y === b.min.y && a.min.z === b.min.z && a.max.x === b.max.x && a.max.y === b.max.y && a.max.z === b.max.z;
|
|
6667
|
+
}
|
|
6668
|
+
/**
|
|
6669
|
+
* Places the stage camera so a box fills the view, with its clip planes around it.
|
|
6670
|
+
*
|
|
6671
|
+
* @param camera - The stage camera.
|
|
6672
|
+
* @param bounds - The subject's bounds.
|
|
6673
|
+
*/
|
|
6674
|
+
function frameCamera(camera, bounds) {
|
|
6675
|
+
const center = {
|
|
6676
|
+
x: (bounds.min.x + bounds.max.x) / 2,
|
|
6677
|
+
y: (bounds.min.y + bounds.max.y) / 2,
|
|
6678
|
+
z: (bounds.min.z + bounds.max.z) / 2
|
|
6679
|
+
};
|
|
6680
|
+
const radius = Math.max(Math.hypot(bounds.max.x - center.x, bounds.max.y - center.y, bounds.max.z - center.z), .01);
|
|
6681
|
+
const distance = radius / Math.sin(STAGE_FOV / 2 * Math.PI / 180) * 1.05;
|
|
6682
|
+
const length = Math.hypot(VIEW_DIRECTION.x, VIEW_DIRECTION.y, VIEW_DIRECTION.z);
|
|
6683
|
+
camera.transform.localPosition.set(center.x + VIEW_DIRECTION.x / length * distance, center.y + VIEW_DIRECTION.y / length * distance, center.z + VIEW_DIRECTION.z / length * distance);
|
|
6684
|
+
camera.transform.lookAt(center);
|
|
6685
|
+
camera.near = Math.max(distance - radius * 1.5, distance / 1e3);
|
|
6686
|
+
camera.far = distance + radius * 1.5;
|
|
6687
|
+
}
|
|
6688
|
+
//#endregion
|
|
5880
6689
|
//#region src/scene/scene-host.ts
|
|
5881
6690
|
/**
|
|
5882
6691
|
* The scene methods and notifications of protocol 0.3: what the scene view's host does with the
|
|
@@ -5919,6 +6728,8 @@ var SceneHost = class {
|
|
|
5919
6728
|
snap: null
|
|
5920
6729
|
};
|
|
5921
6730
|
#drag;
|
|
6731
|
+
#gameView = new GameView();
|
|
6732
|
+
#thumbnails;
|
|
5922
6733
|
#started = false;
|
|
5923
6734
|
/** The field defaults seen at start and after each hot reload, from {@link SceneHost.start} on. */
|
|
5924
6735
|
#defaults = null;
|
|
@@ -5954,6 +6765,24 @@ var SceneHost = class {
|
|
|
5954
6765
|
]);
|
|
5955
6766
|
if (has(HostCapability.gizmos)) methods.set(SceneMethod.setGizmo, (params) => this.#setGizmo(params));
|
|
5956
6767
|
if (has(HostCapability.screenshot)) methods.set(SceneMethod.screenshot, async (params) => this.#screenshot(params));
|
|
6768
|
+
if (has(HostCapability.gameView)) {
|
|
6769
|
+
methods.set(RenderViewMethod.setGameView, (params) => {
|
|
6770
|
+
this.#requireMirror(RenderViewMethod.setGameView);
|
|
6771
|
+
return this.#gameView.set(this.#requireApp(), params);
|
|
6772
|
+
});
|
|
6773
|
+
methods.set(RenderViewMethod.gameViewFrame, async (params) => {
|
|
6774
|
+
const mirror = this.#requireMirror(RenderViewMethod.gameViewFrame);
|
|
6775
|
+
this.#requireOpen(RenderViewMethod.gameViewFrame);
|
|
6776
|
+
return this.#gameView.frame(this.#requireApp(), mirror, params);
|
|
6777
|
+
});
|
|
6778
|
+
}
|
|
6779
|
+
const createThumbnailApp = options.createThumbnailApp;
|
|
6780
|
+
this.#thumbnails = has(HostCapability.thumbnails) && createThumbnailApp !== void 0 ? new ThumbnailRenderer(createThumbnailApp) : null;
|
|
6781
|
+
const thumbnails = this.#thumbnails;
|
|
6782
|
+
if (thumbnails !== null) methods.set(RenderViewMethod.renderThumbnail, async (params) => {
|
|
6783
|
+
this.#requireMirror(RenderViewMethod.renderThumbnail);
|
|
6784
|
+
return thumbnails.render(params);
|
|
6785
|
+
});
|
|
5957
6786
|
this.methods = new Map([...methods].map(([name, handler]) => [name, async (params) => this.#serial(() => handler(params))]));
|
|
5958
6787
|
}
|
|
5959
6788
|
/**
|
|
@@ -6161,6 +6990,8 @@ var SceneHost = class {
|
|
|
6161
6990
|
for (const cleanup of this.#cleanups.splice(0)) cleanup();
|
|
6162
6991
|
this.#view?.dispose();
|
|
6163
6992
|
this.#view = null;
|
|
6993
|
+
this.#gameView.dispose();
|
|
6994
|
+
this.#thumbnails?.dispose();
|
|
6164
6995
|
}
|
|
6165
6996
|
/**
|
|
6166
6997
|
* `openScene`: replaces the open document with the editor's file.
|
|
@@ -6319,20 +7150,10 @@ var SceneHost = class {
|
|
|
6319
7150
|
async #screenshot(params) {
|
|
6320
7151
|
const app = this.#requireApp();
|
|
6321
7152
|
this.#requireMirror(SceneMethod.screenshot);
|
|
6322
|
-
|
|
6323
|
-
const value = Reflect.get(params, side);
|
|
6324
|
-
if (value !== void 0 && (!Number.isSafeInteger(value) || Number(value) < 1 || Number(value) > 2048)) throw new InvalidParamsError(`screenshot takes a width and height from 1 to ${String(SCREENSHOT_MAX_SIZE)} pixels.`);
|
|
6325
|
-
}
|
|
6326
|
-
if (!isScreenshotParams(params)) throw new InvalidParamsError("screenshot takes { width?, height?, format: \"png\" | \"jpeg\", quality? }.");
|
|
7153
|
+
const checked = checkScreenshotParams(params);
|
|
6327
7154
|
this.#view?.setVisible(false);
|
|
6328
7155
|
try {
|
|
6329
|
-
|
|
6330
|
-
const size = screenshotSize(params, capture);
|
|
6331
|
-
return {
|
|
6332
|
-
dataUrl: await encodeCapture(capture, size, params.format, params.quality ?? .9),
|
|
6333
|
-
width: size.width,
|
|
6334
|
-
height: size.height
|
|
6335
|
-
};
|
|
7156
|
+
return await takeScreenshot(app, checked);
|
|
6336
7157
|
} finally {
|
|
6337
7158
|
this.#view?.setVisible(true);
|
|
6338
7159
|
}
|
|
@@ -6818,7 +7639,9 @@ async function startEditorHost(options) {
|
|
|
6818
7639
|
HostCapability.viewMode2d,
|
|
6819
7640
|
HostCapability.pick2d,
|
|
6820
7641
|
HostCapability.logRelay,
|
|
6821
|
-
HostCapability.hotReloadDefaults
|
|
7642
|
+
HostCapability.hotReloadDefaults,
|
|
7643
|
+
HostCapability.gameView,
|
|
7644
|
+
...canRenderThumbnails(options) ? [HostCapability.thumbnails] : []
|
|
6822
7645
|
] : [
|
|
6823
7646
|
HostCapability.heartbeat,
|
|
6824
7647
|
HostCapability.logRelay,
|
|
@@ -6829,7 +7652,8 @@ async function startEditorHost(options) {
|
|
|
6829
7652
|
capabilities,
|
|
6830
7653
|
notify: (method, params) => {
|
|
6831
7654
|
channel?.notify(method, params);
|
|
6832
|
-
}
|
|
7655
|
+
},
|
|
7656
|
+
createThumbnailApp: async () => createThumbnailApp(options)
|
|
6833
7657
|
});
|
|
6834
7658
|
const opened = openChannel({
|
|
6835
7659
|
target: resolveMessageTarget(options.messageTarget),
|
|
@@ -6892,6 +7716,34 @@ function hasGpuView(options) {
|
|
|
6892
7716
|
return options.canvas !== void 0 && options.headless !== true;
|
|
6893
7717
|
}
|
|
6894
7718
|
/**
|
|
7719
|
+
* Tells whether the host can build the thumbnail stage app: it has `OffscreenCanvas`, and either
|
|
7720
|
+
* a way to build fresh extensions or no extensions to rebuild.
|
|
7721
|
+
*
|
|
7722
|
+
* @param options - The host options.
|
|
7723
|
+
* @returns True when `renderThumbnail` can be answered.
|
|
7724
|
+
*/
|
|
7725
|
+
function canRenderThumbnails(options) {
|
|
7726
|
+
return typeof OffscreenCanvas !== "undefined" && (options.createExtensions !== void 0 || (options.extensions ?? []).length === 0);
|
|
7727
|
+
}
|
|
7728
|
+
/**
|
|
7729
|
+
* Creates the app thumbnails are rendered in: fresh instances of the project's extensions, its
|
|
7730
|
+
* settings, assets and scripts, on a 1x1 offscreen canvas of its own (the thumbnails draw into
|
|
7731
|
+
* render textures).
|
|
7732
|
+
*
|
|
7733
|
+
* @param options - The host options.
|
|
7734
|
+
* @returns The app, not started.
|
|
7735
|
+
*/
|
|
7736
|
+
async function createThumbnailApp(options) {
|
|
7737
|
+
const app = await createApp({
|
|
7738
|
+
...appOptions(options),
|
|
7739
|
+
extensions: options.createExtensions?.() ?? [],
|
|
7740
|
+
canvas: new OffscreenCanvas(1, 1),
|
|
7741
|
+
headless: false
|
|
7742
|
+
});
|
|
7743
|
+
app.registerComponents(options.scripts ?? []);
|
|
7744
|
+
return app;
|
|
7745
|
+
}
|
|
7746
|
+
/**
|
|
6895
7747
|
* Picks the `createApp` options out of the host options, leaving out the ones that were not given.
|
|
6896
7748
|
*
|
|
6897
7749
|
* @param options - The host options.
|
|
@@ -6908,6 +7760,348 @@ function appOptions(options) {
|
|
|
6908
7760
|
};
|
|
6909
7761
|
}
|
|
6910
7762
|
//#endregion
|
|
7763
|
+
//#region src/play-input.ts
|
|
7764
|
+
/**
|
|
7765
|
+
* The play view's `sendInput` (engine ask E49): synthetic key and pointer events queued into the
|
|
7766
|
+
* game's own `app.input`, the way headless tests drive the engine. The host does not depend on
|
|
7767
|
+
* `@ignifx/input`: it finds `app.input` by name and calls `simulateEvent` by shape, as it reaches
|
|
7768
|
+
* `app.twoD` (`./scene/view-2d.ts`). Nothing here dispatches a DOM event or touches the editor.
|
|
7769
|
+
*/
|
|
7770
|
+
/**
|
|
7771
|
+
* The game's input service, when the project registers `@ignifx/input`.
|
|
7772
|
+
*
|
|
7773
|
+
* @param app - The game's app.
|
|
7774
|
+
* @returns `app.input`, or `null` when it has no `simulateEvent`.
|
|
7775
|
+
*/
|
|
7776
|
+
function inputServiceOf(app) {
|
|
7777
|
+
const service = Reflect.get(app, "input");
|
|
7778
|
+
if (typeof service !== "object" || service === null) return null;
|
|
7779
|
+
const simulateEvent = Reflect.get(service, "simulateEvent");
|
|
7780
|
+
if (typeof simulateEvent !== "function") return null;
|
|
7781
|
+
const resolveControl = Reflect.get(service, "resolveControl");
|
|
7782
|
+
return {
|
|
7783
|
+
simulateEvent: (event) => {
|
|
7784
|
+
Reflect.apply(simulateEvent, service, [event]);
|
|
7785
|
+
},
|
|
7786
|
+
hasControl: (path) => {
|
|
7787
|
+
if (typeof resolveControl !== "function") return true;
|
|
7788
|
+
try {
|
|
7789
|
+
Reflect.apply(resolveControl, service, [path]);
|
|
7790
|
+
return true;
|
|
7791
|
+
} catch {
|
|
7792
|
+
return false;
|
|
7793
|
+
}
|
|
7794
|
+
}
|
|
7795
|
+
};
|
|
7796
|
+
}
|
|
7797
|
+
/**
|
|
7798
|
+
* Splits a `sendInput` event into a key event or a pointer one.
|
|
7799
|
+
*
|
|
7800
|
+
* @param event - The event.
|
|
7801
|
+
* @returns True for `keydown` and `keyup`.
|
|
7802
|
+
*/
|
|
7803
|
+
function isKeyEvent(event) {
|
|
7804
|
+
return event.type === "keydown" || event.type === "keyup";
|
|
7805
|
+
}
|
|
7806
|
+
/**
|
|
7807
|
+
* Measures the game's canvas.
|
|
7808
|
+
*
|
|
7809
|
+
* @param app - The game's app.
|
|
7810
|
+
* @returns Its size and pixel ratio.
|
|
7811
|
+
*/
|
|
7812
|
+
function canvasMetrics(app) {
|
|
7813
|
+
const surface = app.renderer.surface;
|
|
7814
|
+
const width = surface !== null && surface.width > 0 ? surface.width : 1;
|
|
7815
|
+
const height = surface !== null && surface.height > 0 ? surface.height : 1;
|
|
7816
|
+
const clientWidth = surface === null ? void 0 : Reflect.get(surface, "clientWidth");
|
|
7817
|
+
return {
|
|
7818
|
+
width,
|
|
7819
|
+
height,
|
|
7820
|
+
cssPerPixel: typeof clientWidth === "number" && clientWidth > 0 ? clientWidth / width : 1
|
|
7821
|
+
};
|
|
7822
|
+
}
|
|
7823
|
+
/**
|
|
7824
|
+
* Queues `sendInput`'s events into one game's input service. Keeps the last pointer position it
|
|
7825
|
+
* sent, so a move reports the motion since it, as a real pointer does.
|
|
7826
|
+
*/
|
|
7827
|
+
var PlayInput = class {
|
|
7828
|
+
#app;
|
|
7829
|
+
#input;
|
|
7830
|
+
#last = null;
|
|
7831
|
+
/**
|
|
7832
|
+
* Creates the queue for one game.
|
|
7833
|
+
*
|
|
7834
|
+
* @param app - The game's app.
|
|
7835
|
+
* @param input - Its input service.
|
|
7836
|
+
*/
|
|
7837
|
+
constructor(app, input) {
|
|
7838
|
+
this.#app = app;
|
|
7839
|
+
this.#input = input;
|
|
7840
|
+
}
|
|
7841
|
+
/**
|
|
7842
|
+
* `sendInput`: checks every event, then queues them all in order. The game resolves them on its
|
|
7843
|
+
* next frame, as it does events from the page.
|
|
7844
|
+
*
|
|
7845
|
+
* @param params - The received `params`.
|
|
7846
|
+
* @returns How many events were queued.
|
|
7847
|
+
* @throws InvalidParamsError for malformed parameters or a key the game's keyboard does not have;
|
|
7848
|
+
* nothing is queued then. If `simulateEvent` itself throws partway, the events before it stay
|
|
7849
|
+
* queued: the input service has no way to take them back.
|
|
7850
|
+
*/
|
|
7851
|
+
send(params) {
|
|
7852
|
+
if (!isSendInputParams(params)) throw new InvalidParamsError(`sendInput needs 1 to ${String(64)} events: { type: "keydown" | "keyup", control } or { type: "pointermove" | "pointerdown" | "pointerup", x, y (0 to 1), button? (0 to 4) }.`);
|
|
7853
|
+
for (const event of params.events) if (isKeyEvent(event) && !this.#input.hasControl(`<Keyboard>/${event.control}`)) throw new InvalidParamsError(`sendInput: the game's keyboard has no key "${event.control}". Use the <Keyboard> control name, such as w, space or arrowUp.`);
|
|
7854
|
+
const metrics = canvasMetrics(this.#app);
|
|
7855
|
+
for (const event of params.events) this.#input.simulateEvent(this.#simulated(event, metrics));
|
|
7856
|
+
return { queued: params.events.length };
|
|
7857
|
+
}
|
|
7858
|
+
/**
|
|
7859
|
+
* Builds the raw event for one request event.
|
|
7860
|
+
*
|
|
7861
|
+
* @param event - The request's event.
|
|
7862
|
+
* @param metrics - The canvas's size and pixel ratio.
|
|
7863
|
+
* @returns The event `simulateEvent` takes.
|
|
7864
|
+
*/
|
|
7865
|
+
#simulated(event, metrics) {
|
|
7866
|
+
if (isKeyEvent(event)) return {
|
|
7867
|
+
type: event.type,
|
|
7868
|
+
code: event.control
|
|
7869
|
+
};
|
|
7870
|
+
const x = event.x * metrics.width;
|
|
7871
|
+
const y = event.y * metrics.height;
|
|
7872
|
+
const last = this.#last;
|
|
7873
|
+
this.#last = {
|
|
7874
|
+
x,
|
|
7875
|
+
y
|
|
7876
|
+
};
|
|
7877
|
+
const moves = event.type !== "pointerdown" && last !== null;
|
|
7878
|
+
return {
|
|
7879
|
+
type: event.type,
|
|
7880
|
+
x,
|
|
7881
|
+
y,
|
|
7882
|
+
deltaX: moves ? (x - last.x) * metrics.cssPerPixel : 0,
|
|
7883
|
+
deltaY: moves ? (y - last.y) * metrics.cssPerPixel : 0,
|
|
7884
|
+
button: event.button ?? 0
|
|
7885
|
+
};
|
|
7886
|
+
}
|
|
7887
|
+
};
|
|
7888
|
+
//#endregion
|
|
7889
|
+
//#region src/play-query.ts
|
|
7890
|
+
/**
|
|
7891
|
+
* The play view's `queryRuntime` (engine ask E48): one entity of the running game, as the scene
|
|
7892
|
+
* format writes it, read through core's `serializeEntity`, each value capped and the whole answer
|
|
7893
|
+
* kept within `QUERY_RUNTIME_MAX_JSON_LENGTH`.
|
|
7894
|
+
*/
|
|
7895
|
+
/** How deep a capped JSON value may nest; deeper values become `null`, as `isJsonValue` allows 256. */
|
|
7896
|
+
const MAX_JSON_DEPTH = 256;
|
|
7897
|
+
/**
|
|
7898
|
+
* What `"components":[],` and the final counts can add to an answer's JSON beyond the skeleton the
|
|
7899
|
+
* budget measures first: the counts there are written with no more digits than they end with,
|
|
7900
|
+
* except `omittedEntries`, which may grow to a safe integer's 16.
|
|
7901
|
+
*/
|
|
7902
|
+
const COMPONENTS_OVERHEAD = 64;
|
|
7903
|
+
/** Thrown out of a copy once it is sure to pass its budget. */
|
|
7904
|
+
var OverBudget = class extends Error {};
|
|
7905
|
+
/**
|
|
7906
|
+
* Counts, while a component is copied, a lower bound of its JSON length, so a copy that cannot fit
|
|
7907
|
+
* stops early instead of building the whole oversized value.
|
|
7908
|
+
*/
|
|
7909
|
+
var Meter = class {
|
|
7910
|
+
/** How many object keys and list items the caps left out of the copy. */
|
|
7911
|
+
omitted = 0;
|
|
7912
|
+
#used = 0;
|
|
7913
|
+
#limit;
|
|
7914
|
+
/**
|
|
7915
|
+
* Creates the meter.
|
|
7916
|
+
*
|
|
7917
|
+
* @param limit - The JSON length the copy may take.
|
|
7918
|
+
*/
|
|
7919
|
+
constructor(limit) {
|
|
7920
|
+
this.#limit = limit;
|
|
7921
|
+
}
|
|
7922
|
+
/**
|
|
7923
|
+
* Counts part of the copy.
|
|
7924
|
+
*
|
|
7925
|
+
* @param length - At most as many UTF-16 code units as that part takes as JSON.
|
|
7926
|
+
* @throws OverBudget once the count passes the limit.
|
|
7927
|
+
*/
|
|
7928
|
+
charge(length) {
|
|
7929
|
+
this.#used += length;
|
|
7930
|
+
if (this.#used > this.#limit) throw new OverBudget();
|
|
7931
|
+
}
|
|
7932
|
+
};
|
|
7933
|
+
/**
|
|
7934
|
+
* Clips a string to a length, never splitting a surrogate pair.
|
|
7935
|
+
*
|
|
7936
|
+
* @param text - The string.
|
|
7937
|
+
* @param max - The longest it may be.
|
|
7938
|
+
* @returns It, or its start.
|
|
7939
|
+
*/
|
|
7940
|
+
function clipTo(text, max) {
|
|
7941
|
+
if (text.length <= max) return text;
|
|
7942
|
+
const last = text.charCodeAt(max - 1);
|
|
7943
|
+
return text.slice(0, last >= 55296 && last <= 56319 ? max - 1 : max);
|
|
7944
|
+
}
|
|
7945
|
+
/**
|
|
7946
|
+
* Copies a value within the caps of `QueryRuntimeResult.entity`, counting it on the meter.
|
|
7947
|
+
*
|
|
7948
|
+
* @param value - The value, which a custom codec may have made something other than JSON.
|
|
7949
|
+
* @param depth - How deep it sits.
|
|
7950
|
+
* @param meter - The component's budget.
|
|
7951
|
+
* @returns The capped copy; `null` for anything that is not JSON or sits too deep.
|
|
7952
|
+
* @throws OverBudget when the copy cannot fit.
|
|
7953
|
+
*/
|
|
7954
|
+
function capJson(value, depth, meter) {
|
|
7955
|
+
if (typeof value === "string") {
|
|
7956
|
+
const clipped = clipWithMarker(value, QUERY_RUNTIME_MAX_STRING_LENGTH);
|
|
7957
|
+
meter.charge(clipped.length + 2);
|
|
7958
|
+
return clipped;
|
|
7959
|
+
}
|
|
7960
|
+
meter.charge(1);
|
|
7961
|
+
if (typeof value === "boolean" || typeof value === "number" && Number.isFinite(value)) return value;
|
|
7962
|
+
if (typeof value !== "object" || value === null || depth >= MAX_JSON_DEPTH) return null;
|
|
7963
|
+
if (Array.isArray(value)) {
|
|
7964
|
+
meter.omitted += Math.max(0, value.length - HOST_LIST_MAX_LENGTH);
|
|
7965
|
+
return value.slice(0, HOST_LIST_MAX_LENGTH).map((item) => capJson(item, depth + 1, meter));
|
|
7966
|
+
}
|
|
7967
|
+
return capJsonObject(value, depth, meter);
|
|
7968
|
+
}
|
|
7969
|
+
/**
|
|
7970
|
+
* {@link capJson} for an object: its first `QUERY_RUNTIME_MAX_KEYS` keys, each clipped as long.
|
|
7971
|
+
* A key that clips to one already kept is left out, so the first keeps its value. Every key left
|
|
7972
|
+
* out is counted on the meter.
|
|
7973
|
+
*
|
|
7974
|
+
* @param value - The object.
|
|
7975
|
+
* @param depth - How deep it sits.
|
|
7976
|
+
* @param meter - The component's budget.
|
|
7977
|
+
* @returns The capped copy, keys in the same order.
|
|
7978
|
+
* @throws OverBudget when the copy cannot fit.
|
|
7979
|
+
*/
|
|
7980
|
+
function capJsonObject(value, depth, meter) {
|
|
7981
|
+
const out = {};
|
|
7982
|
+
const entries = Object.entries(value);
|
|
7983
|
+
let kept = 0;
|
|
7984
|
+
for (const [index, [key, item]] of entries.entries()) {
|
|
7985
|
+
if (kept === 256) {
|
|
7986
|
+
meter.omitted += entries.length - index;
|
|
7987
|
+
break;
|
|
7988
|
+
}
|
|
7989
|
+
const clipped = clipTo(key, 256);
|
|
7990
|
+
if (Object.hasOwn(out, clipped)) {
|
|
7991
|
+
meter.omitted += 1;
|
|
7992
|
+
continue;
|
|
7993
|
+
}
|
|
7994
|
+
meter.charge(clipped.length + 3);
|
|
7995
|
+
Object.defineProperty(out, clipped, {
|
|
7996
|
+
value: capJson(item, depth + 1, meter),
|
|
7997
|
+
enumerable: true,
|
|
7998
|
+
writable: true,
|
|
7999
|
+
configurable: true
|
|
8000
|
+
});
|
|
8001
|
+
kept += 1;
|
|
8002
|
+
}
|
|
8003
|
+
return out;
|
|
8004
|
+
}
|
|
8005
|
+
/**
|
|
8006
|
+
* Clips a string as the reports do, ending it with {@link CLIPPED_MARKER}.
|
|
8007
|
+
*
|
|
8008
|
+
* @param text - The string.
|
|
8009
|
+
* @param max - The longest it may be, marker included.
|
|
8010
|
+
* @returns It, or its start and the marker.
|
|
8011
|
+
*/
|
|
8012
|
+
function clipWithMarker(text, max) {
|
|
8013
|
+
return text.length <= max ? text : `${clipTo(text, max - 11)}${CLIPPED_MARKER}`;
|
|
8014
|
+
}
|
|
8015
|
+
/**
|
|
8016
|
+
* Copies one component record within the caps, if it fits.
|
|
8017
|
+
*
|
|
8018
|
+
* @param component - The record `serializeEntity` wrote.
|
|
8019
|
+
* @param room - The JSON length still free in the answer.
|
|
8020
|
+
* @returns The capped record and its JSON length, or `null` when it does not fit.
|
|
8021
|
+
*/
|
|
8022
|
+
function fitComponent(component, room) {
|
|
8023
|
+
try {
|
|
8024
|
+
const meter = new Meter(room);
|
|
8025
|
+
const record = {
|
|
8026
|
+
...component,
|
|
8027
|
+
type: clipTo(component.type, 256),
|
|
8028
|
+
...component.props === void 0 ? {} : { props: capJsonObject(component.props, 0, meter) }
|
|
8029
|
+
};
|
|
8030
|
+
const length = JSON.stringify(record).length + 1;
|
|
8031
|
+
return length <= room ? {
|
|
8032
|
+
record,
|
|
8033
|
+
length,
|
|
8034
|
+
omitted: meter.omitted
|
|
8035
|
+
} : null;
|
|
8036
|
+
} catch (error) {
|
|
8037
|
+
if (error instanceof OverBudget) return null;
|
|
8038
|
+
throw error;
|
|
8039
|
+
}
|
|
8040
|
+
}
|
|
8041
|
+
/**
|
|
8042
|
+
* Reads the type ids a `queryRuntime` keeps.
|
|
8043
|
+
*
|
|
8044
|
+
* @param params - The received `params`.
|
|
8045
|
+
* @returns The entity's uid and the type-id filter, or `null` for every component.
|
|
8046
|
+
* @throws InvalidParamsError when the parameters are not a uid and at most 64 type ids.
|
|
8047
|
+
*/
|
|
8048
|
+
function checkQueryRuntimeParams(params) {
|
|
8049
|
+
if (!isQueryRuntimeParams(params)) throw new InvalidParamsError(`queryRuntime needs { entity: uid, components?: typeId[] } with at most ${String(64)} type ids.`);
|
|
8050
|
+
return {
|
|
8051
|
+
uid: params.entity,
|
|
8052
|
+
filter: params.components === void 0 ? null : new Set(params.components)
|
|
8053
|
+
};
|
|
8054
|
+
}
|
|
8055
|
+
/**
|
|
8056
|
+
* `queryRuntime`: one entity of the game as `serializeEntity` writes it from the live world, capped.
|
|
8057
|
+
* Changes nothing.
|
|
8058
|
+
*
|
|
8059
|
+
* @param app - The game's app.
|
|
8060
|
+
* @param params - The received `params`.
|
|
8061
|
+
* @returns The entity record, how many components did not fit, and when it was read.
|
|
8062
|
+
* @throws InvalidParamsError for malformed parameters, and RpcFailure `unknownEntity` when no live
|
|
8063
|
+
* entity of the game has the uid.
|
|
8064
|
+
*/
|
|
8065
|
+
function queryRuntime(app, params) {
|
|
8066
|
+
const { uid, filter } = checkQueryRuntimeParams(params);
|
|
8067
|
+
const entity = app.world.getEntity(uid);
|
|
8068
|
+
if (entity === null || entity.isDestroyed) throw new RpcFailure(RpcErrorCode.unknownEntity, "No entity of the running game has that uid. Entities a script or a prefab spawns get new uids on every run.");
|
|
8069
|
+
const { components, ...fields } = serializeEntity(entity);
|
|
8070
|
+
const matching = (components ?? []).filter((component) => filter?.has(component.type) ?? true);
|
|
8071
|
+
const tagsOmitted = Math.max(0, (fields.tags?.length ?? 0) - 256);
|
|
8072
|
+
const answer = {
|
|
8073
|
+
entity: {
|
|
8074
|
+
...fields,
|
|
8075
|
+
name: clipTo(fields.name, 256),
|
|
8076
|
+
...fields.layer === void 0 ? {} : { layer: clipTo(fields.layer, 256) },
|
|
8077
|
+
...fields.tags === void 0 ? {} : { tags: fields.tags.slice(0, 256).map((tag) => clipTo(tag, 256)) }
|
|
8078
|
+
},
|
|
8079
|
+
omittedComponents: matching.length,
|
|
8080
|
+
omittedEntries: tagsOmitted,
|
|
8081
|
+
frameCount: app.time.frameCount,
|
|
8082
|
+
time: app.time.time
|
|
8083
|
+
};
|
|
8084
|
+
let room = QUERY_RUNTIME_MAX_JSON_LENGTH - JSON.stringify(answer).length - COMPONENTS_OVERHEAD;
|
|
8085
|
+
const kept = [];
|
|
8086
|
+
let omittedEntries = tagsOmitted;
|
|
8087
|
+
for (const component of matching.slice(0, 64)) {
|
|
8088
|
+
const fitted = fitComponent(component, room);
|
|
8089
|
+
if (fitted === null) break;
|
|
8090
|
+
kept.push(fitted.record);
|
|
8091
|
+
room -= fitted.length;
|
|
8092
|
+
omittedEntries += fitted.omitted;
|
|
8093
|
+
}
|
|
8094
|
+
return {
|
|
8095
|
+
...answer,
|
|
8096
|
+
entity: {
|
|
8097
|
+
...answer.entity,
|
|
8098
|
+
...kept.length === 0 ? {} : { components: kept }
|
|
8099
|
+
},
|
|
8100
|
+
omittedComponents: matching.length - kept.length,
|
|
8101
|
+
omittedEntries
|
|
8102
|
+
};
|
|
8103
|
+
}
|
|
8104
|
+
//#endregion
|
|
6911
8105
|
//#region src/play-controls.ts
|
|
6912
8106
|
/**
|
|
6913
8107
|
* The play view's controls: the project's own game page, reached by the editor through the app the
|
|
@@ -6997,6 +8191,53 @@ function stepDelta(app, params) {
|
|
|
6997
8191
|
if (typeof delta !== "number" || !Number.isFinite(delta) || delta <= 0) throw new InvalidParamsError("step needs deltaSeconds to be a positive number of seconds.");
|
|
6998
8192
|
return delta;
|
|
6999
8193
|
}
|
|
8194
|
+
/** How often a capture that waits for its frame checks that the game's loop still runs, in ms. */
|
|
8195
|
+
const CAPTURE_STOP_POLL_MS = 50;
|
|
8196
|
+
/**
|
|
8197
|
+
* The refusal of a `screenshot` while the game's frame loop does not run.
|
|
8198
|
+
*
|
|
8199
|
+
* @returns The failure, with code `notPlaying`.
|
|
8200
|
+
*/
|
|
8201
|
+
function notPlaying() {
|
|
8202
|
+
return new RpcFailure(RpcErrorCode.notPlaying, "The game is not running, so there is no frame to capture. Press Play first; after Step or Stop the game renders no frames.");
|
|
8203
|
+
}
|
|
8204
|
+
/**
|
|
8205
|
+
* Refuses a method that needs a game that plays or is paused, while the game is stopped.
|
|
8206
|
+
*
|
|
8207
|
+
* @param tracker - Reads the game's phase.
|
|
8208
|
+
* @param what - What the method would have done, for the message.
|
|
8209
|
+
* @throws RpcFailure `notPlaying` while the game is stopped: before it starts, or after `stop`.
|
|
8210
|
+
*/
|
|
8211
|
+
function requireStarted(tracker, what) {
|
|
8212
|
+
if (tracker.read().state === PlayPhase.stopped) throw new RpcFailure(RpcErrorCode.notPlaying, `The game is stopped, so there is no running game to ${what}. Press Play first; a paused or stepped game answers.`);
|
|
8213
|
+
}
|
|
8214
|
+
/**
|
|
8215
|
+
* `screenshot`: the game's canvas as an image, as the scene view's `screenshot` answers. Changes
|
|
8216
|
+
* nothing about the game.
|
|
8217
|
+
*
|
|
8218
|
+
* @param app - The game's app.
|
|
8219
|
+
* @param params - The received `params`.
|
|
8220
|
+
* @returns The data URL and its size.
|
|
8221
|
+
* @throws RpcFailure `notPlaying` while the frame loop does not run or when it stops before the
|
|
8222
|
+
* frame arrives, `notReady` before the first frame, and `invalidParams` for parameters the scene
|
|
8223
|
+
* view would refuse.
|
|
8224
|
+
*/
|
|
8225
|
+
async function playScreenshot(app, params) {
|
|
8226
|
+
if (!app.isRunning) throw notPlaying();
|
|
8227
|
+
if (app.time.frameCount === 0) throw new RpcFailure(RpcErrorCode.notReady, "The game has not rendered its first frame yet.");
|
|
8228
|
+
const checked = checkScreenshotParams(params);
|
|
8229
|
+
let poll;
|
|
8230
|
+
const stopped = new Promise((_resolve, reject) => {
|
|
8231
|
+
poll = setInterval(() => {
|
|
8232
|
+
if (!app.isRunning) reject(notPlaying());
|
|
8233
|
+
}, CAPTURE_STOP_POLL_MS);
|
|
8234
|
+
});
|
|
8235
|
+
try {
|
|
8236
|
+
return await Promise.race([takeScreenshot(app, checked), stopped]);
|
|
8237
|
+
} finally {
|
|
8238
|
+
clearInterval(poll);
|
|
8239
|
+
}
|
|
8240
|
+
}
|
|
7000
8241
|
/**
|
|
7001
8242
|
* Builds the play methods for one app.
|
|
7002
8243
|
*
|
|
@@ -7007,7 +8248,7 @@ function stepDelta(app, params) {
|
|
|
7007
8248
|
function playMethods(app, tracker) {
|
|
7008
8249
|
const answer = () => new Reply(playState(app), tracker.report);
|
|
7009
8250
|
const stats = new PlayStatsReader(app);
|
|
7010
|
-
|
|
8251
|
+
const methods = /* @__PURE__ */ new Map([
|
|
7011
8252
|
[PlayMethod.play, async () => {
|
|
7012
8253
|
tracker.isStopped = false;
|
|
7013
8254
|
app.time.paused = false;
|
|
@@ -7033,8 +8274,22 @@ function playMethods(app, tracker) {
|
|
|
7033
8274
|
return answer();
|
|
7034
8275
|
}],
|
|
7035
8276
|
[PlayMethod.playState, () => tracker.read()],
|
|
7036
|
-
[PlayMethod.playStats, () => stats.read()]
|
|
8277
|
+
[PlayMethod.playStats, () => stats.read()],
|
|
8278
|
+
[PlayMethod.queryRuntime, (params) => {
|
|
8279
|
+
requireStarted(tracker, "read");
|
|
8280
|
+
return queryRuntime(app, params);
|
|
8281
|
+
}]
|
|
7037
8282
|
]);
|
|
8283
|
+
if (!app.isHeadless) methods.set(PlayMethod.screenshot, async (params) => playScreenshot(app, params));
|
|
8284
|
+
const input = inputServiceOf(app);
|
|
8285
|
+
if (input !== null) {
|
|
8286
|
+
const queue = new PlayInput(app, input);
|
|
8287
|
+
methods.set(PlayMethod.sendInput, (params) => {
|
|
8288
|
+
requireStarted(tracker, "send input to");
|
|
8289
|
+
return queue.send(params);
|
|
8290
|
+
});
|
|
8291
|
+
}
|
|
8292
|
+
return methods;
|
|
7038
8293
|
}
|
|
7039
8294
|
/**
|
|
7040
8295
|
* The options every play view checks before it opens a channel.
|
|
@@ -7089,7 +8344,10 @@ function openPlayControls(app, options, target, heartbeatIntervalMs, port) {
|
|
|
7089
8344
|
capabilities: [
|
|
7090
8345
|
HostCapability.heartbeat,
|
|
7091
8346
|
HostCapability.playControls,
|
|
7092
|
-
HostCapability.logRelay
|
|
8347
|
+
HostCapability.logRelay,
|
|
8348
|
+
HostCapability.queryRuntime,
|
|
8349
|
+
...app.isHeadless ? [] : [HostCapability.screenshot],
|
|
8350
|
+
...inputServiceOf(app) === null ? [] : [HostCapability.sendInput]
|
|
7093
8351
|
],
|
|
7094
8352
|
hostKind: HostKind.play
|
|
7095
8353
|
},
|
|
@@ -7118,7 +8376,7 @@ function openPlayControls(app, options, target, heartbeatIntervalMs, port) {
|
|
|
7118
8376
|
}
|
|
7119
8377
|
/**
|
|
7120
8378
|
* Lets the editor drive a running game: answers the handshake with `hostKind: "play"`, then `play`,
|
|
7121
|
-
* `pause`, `step`, `stop`, `playState` and `
|
|
8379
|
+
* `pause`, `step`, `stop`, `playState`, `playStats`, `queryRuntime`, (with a canvas) `screenshot` and (with `app.input`) `sendInput`, and sends `playStateChanged` when the game's phase
|
|
7122
8380
|
* changes, and `log`, `hostError` and `hotReloaded` for the game's log lines, `app.onError` reports
|
|
7123
8381
|
* and hot reloads (the newest 256 from before the handshake right after it).
|
|
7124
8382
|
*
|
|
@@ -7217,6 +8475,6 @@ function listenForEditorPlayControls(options) {
|
|
|
7217
8475
|
};
|
|
7218
8476
|
}
|
|
7219
8477
|
//#endregion
|
|
7220
|
-
export { ApplyOpFailureCode, COLLIDER_OUTLINES_MAX_ENTITIES, COLLIDER_OUTLINES_MAX_NUMBERS, DEFAULT_HEARTBEAT_INTERVAL_MS, EDITOR_CONNECT_MESSAGE_TYPE, EditorHostErrorCode, GizmoMode, GizmoSpace, HOST_LIST_MAX_LENGTH, HOST_TEXT_MAX_LENGTH, HandshakeMethod, HostCapability, HostKind, HostNotification, JSON_RPC_VERSION, PROTOCOL_VERSION, PickUnit, PlayMethod, PlayNotification, PlayPhase, RpcErrorCode, SAMPLE_ANIMATION_MAX_NAME_LENGTH, SAMPLE_ANIMATION_MAX_PARAMETERS, SCREENSHOT_MAX_SIZE, SceneMethod, SceneNotification, SceneOpKind, ScreenshotFormat, TRANSFORM_DRAGGING_INTERVAL_MS, ViewMode, isAppErrorData, isApplyOpsParams, isApplyOpsResult, isAssetReloadedParams, isColliderOutlineRecord, isColliderOutlineSet, isEditorConnectMessage, isEditorOrigin, isEntitySelection, isFrameParams, isHostErrorParams, isHotReloadedParams, isIncompatibleProtocolData, isInvalidSceneFileData, isJsonObject, isJsonValue, isLogParams, isOpenSceneParams, isOpenSceneResult, isPickParams, isPickResult, isPlayState, isPlayStateReport, isPlayStats, isProtocolVersion, isReadBackParams, isReadBackResult, isReadyResult, isRpcMessage, isSampleAnimationParams, isSampleAnimationResult, isSceneFile, isSceneFileAssetRef, isSceneFileComponent, isSceneFileEntity, isSceneFileInstance, isSceneFileOverride, isSceneFileTransform, isSceneIssue, isSceneOp, isSceneOpenedParams, isSchemaSet, isScreenshotParams, isScreenshotResult, isSetAnimateMaterialsParams, isSetGizmoParams, isSetViewModeParams, isSettingsSet, isTransformDraggedParams, isTransformDraggingParams, listenForEditorPlayControls, protocolVersionIsCompatible, startEditorHost, startEditorPlayControls };
|
|
8478
|
+
export { ApplyOpFailureCode, COLLIDER_OUTLINES_MAX_ENTITIES, COLLIDER_OUTLINES_MAX_NUMBERS, DEFAULT_HEARTBEAT_INTERVAL_MS, EDITOR_CONNECT_MESSAGE_TYPE, EditorHostErrorCode, GAME_VIEW_DEFAULT_SIZE, GAME_VIEW_MAX_SIZE, GizmoMode, GizmoSpace, HOST_LIST_MAX_LENGTH, HOST_TEXT_MAX_LENGTH, HandshakeMethod, HostCapability, HostKind, HostNotification, JSON_RPC_VERSION, PROTOCOL_VERSION, PickUnit, PlayMethod, PlayNotification, PlayPhase, QUERY_RUNTIME_MAX_COMPONENTS, QUERY_RUNTIME_MAX_JSON_LENGTH, QUERY_RUNTIME_MAX_KEYS, QUERY_RUNTIME_MAX_STRING_LENGTH, RenderViewMethod, RpcErrorCode, SAMPLE_ANIMATION_MAX_NAME_LENGTH, SAMPLE_ANIMATION_MAX_PARAMETERS, SCREENSHOT_MAX_SIZE, SEND_INPUT_MAX_EVENTS, SceneMethod, SceneNotification, SceneOpKind, ScreenshotFormat, THUMBNAIL_DEFAULT_SIZE, THUMBNAIL_MAX_SIZE, TRANSFORM_DRAGGING_INTERVAL_MS, ViewMode, isAppErrorData, isApplyOpsParams, isApplyOpsResult, isAssetReloadedParams, isColliderOutlineRecord, isColliderOutlineSet, isEditorConnectMessage, isEditorOrigin, isEntitySelection, isFrameParams, isGameViewFrameParams, isGameViewFrameResult, isGameViewState, isHostErrorParams, isHotReloadedParams, isIncompatibleProtocolData, isInvalidSceneFileData, isJsonObject, isJsonValue, isLogParams, isOpenSceneParams, isOpenSceneResult, isPickParams, isPickResult, isPlayState, isPlayStateReport, isPlayStats, isProtocolVersion, isQueryRuntimeParams, isQueryRuntimeResult, isReadBackParams, isReadBackResult, isReadyResult, isRenderThumbnailParams, isRpcMessage, isSampleAnimationParams, isSampleAnimationResult, isSceneFile, isSceneFileAssetRef, isSceneFileComponent, isSceneFileEntity, isSceneFileInstance, isSceneFileOverride, isSceneFileTransform, isSceneIssue, isSceneOp, isSceneOpenedParams, isSchemaSet, isScreenshotParams, isScreenshotResult, isSendInputEvent, isSendInputParams, isSendInputResult, isSetAnimateMaterialsParams, isSetGameViewParams, isSetGizmoParams, isSetViewModeParams, isSettingsSet, isThumbnailResult, isTransformDraggedParams, isTransformDraggingParams, listenForEditorPlayControls, protocolVersionIsCompatible, startEditorHost, startEditorPlayControls };
|
|
7221
8479
|
|
|
7222
8480
|
//# sourceMappingURL=index.js.map
|