@ignifx/editor-host 0.15.0 → 0.17.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/editor-lines.js +77 -0
- package/dist/editor-lines.js.map +1 -0
- package/dist/index.d.ts +277 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +636 -82
- package/dist/index.js.map +1 -1
- package/dist/sprite-game-view.js +132 -0
- package/dist/sprite-game-view.js.map +1 -0
- package/package.json +10 -10
- package/skills/editor-host/SKILL.md +25 -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, 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";
|
|
2
|
+
import { Camera, Component, CoreErrorCode, IgnifxError, Light, Phase, RENDERING_SETTINGS_SECTION, 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, instanceComponentAt, instanceEntityAt, 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
|
/**
|
|
@@ -187,8 +187,9 @@ const HostKind = {
|
|
|
187
187
|
* The play controls send `"heartbeat"`, `"playControls"`, `"logRelay"` and `"queryRuntime"`, plus
|
|
188
188
|
* `"screenshot"` when the game has a canvas and `"sendInput"` when it has `app.input`. The scene
|
|
189
189
|
* host sends `"heartbeat"` and whichever of `"gizmos"`, `"screenshot"`, `"viewMode2d"`,
|
|
190
|
-
* `"pick2d"`, `"gameView"`, `"
|
|
191
|
-
*
|
|
190
|
+
* `"pick2d"`, `"gameView"`, `"gameViewOnDemand"`, `"gameViewSize"`, `"gameView2d"`, `"thumbnails"`,
|
|
191
|
+
* `"grid"`, `"tilemapCells"`, `"editorLines"` and `"spriteAnimation"` it supports; every
|
|
192
|
+
* `SceneMethod` not tied to one of them is required of a 0.3 scene host.
|
|
192
193
|
*
|
|
193
194
|
* @public
|
|
194
195
|
*/
|
|
@@ -250,6 +251,24 @@ const HostCapability = {
|
|
|
250
251
|
*/
|
|
251
252
|
gameView: "gameView",
|
|
252
253
|
/**
|
|
254
|
+
* The scene host's `gameViewFrame` renders on demand: it does not wait for an animation frame,
|
|
255
|
+
* which a hidden host (a `visibility: hidden` iframe, a background tab) never gets, so it answers
|
|
256
|
+
* at full rate while hidden. Additive in 0.3; without it, a hidden host answers slowly or not
|
|
257
|
+
* at all.
|
|
258
|
+
*/
|
|
259
|
+
gameViewOnDemand: "gameViewOnDemand",
|
|
260
|
+
/**
|
|
261
|
+
* The scene host's `gameViewFrame` takes `width` and `height`, resizing the view first. Additive
|
|
262
|
+
* in 0.3; without it, send `setGameView` to resize.
|
|
263
|
+
*/
|
|
264
|
+
gameViewSize: "gameViewSize",
|
|
265
|
+
/**
|
|
266
|
+
* The scene host's `gameViewFrame` renders a document whose main camera is a `Camera2D`
|
|
267
|
+
* (`@ignifx/2d`): its sprites through that camera, at the view's size. Additive in 0.3; without
|
|
268
|
+
* it, such a document answers `dataUrl: null`.
|
|
269
|
+
*/
|
|
270
|
+
gameView2d: "gameView2d",
|
|
271
|
+
/**
|
|
253
272
|
* The scene host answers `renderThumbnail`: a model or prefab asset rendered on its own
|
|
254
273
|
* (`RenderViewMethod`). From engine ask E8 (additive in 0.3); without it, the host answers it with
|
|
255
274
|
* `RpcErrorCode.methodNotFound`.
|
|
@@ -261,7 +280,27 @@ const HostCapability = {
|
|
|
261
280
|
* (additive in 0.3); without it, the scene host answers `setGrid` with
|
|
262
281
|
* `RpcErrorCode.methodNotFound`.
|
|
263
282
|
*/
|
|
264
|
-
grid: "grid"
|
|
283
|
+
grid: "grid",
|
|
284
|
+
/**
|
|
285
|
+
* The scene host answers `setTilemapCells`: it writes cells into the open scene's live tilemaps,
|
|
286
|
+
* so a tilemap editor's painting shows without a save. Additive in 0.3; without it, the scene
|
|
287
|
+
* host answers `setTilemapCells` with `RpcErrorCode.methodNotFound`.
|
|
288
|
+
*/
|
|
289
|
+
tilemapCells: "tilemapCells",
|
|
290
|
+
/**
|
|
291
|
+
* The scene host answers `setEditorLines` and `clearEditorLines`: it draws the editor's own line
|
|
292
|
+
* segments (collider outlines, handles) over the view in both view modes, never in a game view or
|
|
293
|
+
* the play view. Additive in 0.3; without it, the scene host answers both with
|
|
294
|
+
* `RpcErrorCode.methodNotFound`.
|
|
295
|
+
*/
|
|
296
|
+
editorLines: "editorLines",
|
|
297
|
+
/**
|
|
298
|
+
* The scene host answers `sampleSpriteAnimation`: one frame of a clip on an entity's
|
|
299
|
+
* `SpriteAnimator` (`@ignifx/2d`), for the editor's sprite animation panel. From engine ask E51
|
|
300
|
+
* (additive in 0.3); without it, the scene host answers `sampleSpriteAnimation` with
|
|
301
|
+
* `RpcErrorCode.methodNotFound`.
|
|
302
|
+
*/
|
|
303
|
+
spriteAnimation: "spriteAnimation"
|
|
265
304
|
};
|
|
266
305
|
/**
|
|
267
306
|
* The longest string, in UTF-16 code units, the editor accepts from a host in `ready` (the engine
|
|
@@ -1107,10 +1146,33 @@ const SceneMethod = {
|
|
|
1107
1146
|
*/
|
|
1108
1147
|
sampleAnimation: "sampleAnimation",
|
|
1109
1148
|
/**
|
|
1149
|
+
* Shows one frame of a clip on an entity's `SpriteAnimator` without playing it (engine ask E51).
|
|
1150
|
+
* Needs `HostCapability.spriteAnimation`. Answers {@link SampleSpriteAnimationResult}. A host from
|
|
1151
|
+
* before it answers `RpcErrorCode.methodNotFound`. Additive in 0.3.
|
|
1152
|
+
*/
|
|
1153
|
+
sampleSpriteAnimation: "sampleSpriteAnimation",
|
|
1154
|
+
/**
|
|
1110
1155
|
* Shows or hides the view's grid and sets its spacing (engine ask E31). Needs
|
|
1111
1156
|
* `HostCapability.grid`. Answers `null`. Additive in 0.3.
|
|
1112
1157
|
*/
|
|
1113
|
-
setGrid: "setGrid"
|
|
1158
|
+
setGrid: "setGrid",
|
|
1159
|
+
/**
|
|
1160
|
+
* Writes cells of a tilemap asset into every live `Tilemap` of the open scene that shows it, so
|
|
1161
|
+
* painting is seen at once, without a save or a reopen. The file on disk is not touched. Needs
|
|
1162
|
+
* `HostCapability.tilemapCells`. Answers {@link SetTilemapCellsResult}. Additive in 0.3.
|
|
1163
|
+
*/
|
|
1164
|
+
setTilemapCells: "setTilemapCells",
|
|
1165
|
+
/**
|
|
1166
|
+
* Draws a set of world-space line segments over the view, such as collider outlines or handles,
|
|
1167
|
+
* replacing the set of the same id. Needs `HostCapability.editorLines`. Answers `null`. Additive
|
|
1168
|
+
* in 0.3.
|
|
1169
|
+
*/
|
|
1170
|
+
setEditorLines: "setEditorLines",
|
|
1171
|
+
/**
|
|
1172
|
+
* Removes one set of lines `setEditorLines` drew, or every set. Needs `HostCapability.editorLines`.
|
|
1173
|
+
* Answers `null`. Additive in 0.3.
|
|
1174
|
+
*/
|
|
1175
|
+
clearEditorLines: "clearEditorLines"
|
|
1114
1176
|
};
|
|
1115
1177
|
/**
|
|
1116
1178
|
* Scene host → editor: the notifications of protocol 0.3. None has an answer.
|
|
@@ -1299,6 +1361,34 @@ const GRID_MIN_SIZE = .001;
|
|
|
1299
1361
|
*/
|
|
1300
1362
|
const GRID_MAX_SIZE = 1e3;
|
|
1301
1363
|
/**
|
|
1364
|
+
* The most numbers the `cells` of one `setTilemapCells` request may hold: a million cells. A request
|
|
1365
|
+
* with more fails with `invalidParams`.
|
|
1366
|
+
*
|
|
1367
|
+
* @public
|
|
1368
|
+
*/
|
|
1369
|
+
const TILEMAP_CELLS_MAX_NUMBERS = 2e6;
|
|
1370
|
+
/** The longest `asset` address and string `layer` of `setTilemapCells`, in UTF-16 code units. */
|
|
1371
|
+
const TILEMAP_CELLS_MAX_NAME_LENGTH = 256;
|
|
1372
|
+
/**
|
|
1373
|
+
* The most numbers the `lines` of one `setEditorLines` request may hold: 100 000 segments.
|
|
1374
|
+
*
|
|
1375
|
+
* @public
|
|
1376
|
+
*/
|
|
1377
|
+
const EDITOR_LINES_MAX_NUMBERS = 6e5;
|
|
1378
|
+
/**
|
|
1379
|
+
* The most line sets the view draws at once; a `setEditorLines` for a new id past it fails with
|
|
1380
|
+
* `invalidParams`.
|
|
1381
|
+
*
|
|
1382
|
+
* @public
|
|
1383
|
+
*/
|
|
1384
|
+
const EDITOR_LINES_MAX_SETS = 64;
|
|
1385
|
+
/**
|
|
1386
|
+
* The longest line set id, in UTF-16 code units.
|
|
1387
|
+
*
|
|
1388
|
+
* @public
|
|
1389
|
+
*/
|
|
1390
|
+
const EDITOR_LINES_MAX_ID_LENGTH = 256;
|
|
1391
|
+
/**
|
|
1302
1392
|
* Tells whether a value is one of an `as const` object's values.
|
|
1303
1393
|
*
|
|
1304
1394
|
* @param names - The object.
|
|
@@ -1628,6 +1718,65 @@ function isSetGridParams(value) {
|
|
|
1628
1718
|
return optionalField(value, "visible", isBoolean) && (size === void 0 || isFiniteNumber(size) && size >= .001 && size <= 1e3);
|
|
1629
1719
|
}
|
|
1630
1720
|
/**
|
|
1721
|
+
* Checks the parameters of `setTilemapCells`.
|
|
1722
|
+
*
|
|
1723
|
+
* @param value - The received `params`.
|
|
1724
|
+
* @returns True for a non-empty `asset` and a layer name or index, each name at most 256 code
|
|
1725
|
+
* units, and an even-length list of at most {@link TILEMAP_CELLS_MAX_NUMBERS} non-negative integers.
|
|
1726
|
+
*
|
|
1727
|
+
* @public
|
|
1728
|
+
*/
|
|
1729
|
+
function isSetTilemapCellsParams(value) {
|
|
1730
|
+
if (!isRecord(value)) return false;
|
|
1731
|
+
const { asset, layer, cells } = value;
|
|
1732
|
+
return isUidString(asset) && asset.length <= TILEMAP_CELLS_MAX_NAME_LENGTH && (isString(layer) && layer.length <= TILEMAP_CELLS_MAX_NAME_LENGTH || isCount(layer)) && Array.isArray(cells) && cells.length % 2 === 0 && cells.length <= 2e6 && cells.every((item) => isCount(item));
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* Checks the result of `setTilemapCells`.
|
|
1736
|
+
*
|
|
1737
|
+
* @param value - The received `result`.
|
|
1738
|
+
* @returns True for two counts.
|
|
1739
|
+
*
|
|
1740
|
+
* @public
|
|
1741
|
+
*/
|
|
1742
|
+
function isSetTilemapCellsResult(value) {
|
|
1743
|
+
return isRecord(value) && isCount(value["tilemaps"]) && isCount(value["changed"]);
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Tells whether a value is a line set id.
|
|
1747
|
+
*
|
|
1748
|
+
* @param value - The value to test.
|
|
1749
|
+
* @returns True for a non-empty string of at most {@link EDITOR_LINES_MAX_ID_LENGTH} code units.
|
|
1750
|
+
*/
|
|
1751
|
+
function isLineSetId(value) {
|
|
1752
|
+
return isUidString(value) && value.length <= 256;
|
|
1753
|
+
}
|
|
1754
|
+
/**
|
|
1755
|
+
* Checks the parameters of `setEditorLines`.
|
|
1756
|
+
*
|
|
1757
|
+
* @param value - The received `params`.
|
|
1758
|
+
* @returns True for an id, a list of finite numbers whose length is a multiple of six and at most
|
|
1759
|
+
* {@link EDITOR_LINES_MAX_NUMBERS}, and an optional colour of three or four numbers from 0 to 1.
|
|
1760
|
+
*
|
|
1761
|
+
* @public
|
|
1762
|
+
*/
|
|
1763
|
+
function isSetEditorLinesParams(value) {
|
|
1764
|
+
if (!isRecord(value)) return false;
|
|
1765
|
+
const { lines, color } = value;
|
|
1766
|
+
return isLineSetId(value["id"]) && isArrayOf(lines, isFiniteNumber) && lines.length % 6 === 0 && lines.length <= 6e5 && (color === void 0 || (isNumberTuple(color, 3) || isNumberTuple(color, 4)) && isArrayOf(color, isFiniteNumber) && color.every((channel) => channel >= 0 && channel <= 1));
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* Checks the parameters of `clearEditorLines`.
|
|
1770
|
+
*
|
|
1771
|
+
* @param value - The received `params`.
|
|
1772
|
+
* @returns True for an object whose `id`, if present, is a line set id.
|
|
1773
|
+
*
|
|
1774
|
+
* @public
|
|
1775
|
+
*/
|
|
1776
|
+
function isClearEditorLinesParams(value) {
|
|
1777
|
+
return isRecord(value) && optionalField(value, "id", isLineSetId);
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1631
1780
|
* Checks one record of `getColliderOutlines`.
|
|
1632
1781
|
*
|
|
1633
1782
|
* @param value - The value to test.
|
|
@@ -1701,6 +1850,32 @@ function isSampleAnimationResult(value) {
|
|
|
1701
1850
|
return isRecord(value) && isBoolean(value["posed"]);
|
|
1702
1851
|
}
|
|
1703
1852
|
/**
|
|
1853
|
+
* Checks the parameters of `sampleSpriteAnimation`.
|
|
1854
|
+
*
|
|
1855
|
+
* @param value - The received `params`.
|
|
1856
|
+
* @returns True for a uid, a clip name within {@link SAMPLE_ANIMATION_MAX_NAME_LENGTH}, and exactly
|
|
1857
|
+
* one of a finite `frame` and a finite `time`.
|
|
1858
|
+
*
|
|
1859
|
+
* @public
|
|
1860
|
+
*/
|
|
1861
|
+
function isSampleSpriteAnimationParams(value) {
|
|
1862
|
+
if (!isRecord(value) || !isUidString(value["entity"]) || !isBoundedName(value["entity"]) || !isBoundedName(value["clip"])) return false;
|
|
1863
|
+
const frame = value["frame"];
|
|
1864
|
+
const time = value["time"];
|
|
1865
|
+
return frame === void 0 ? isFiniteNumber(time) : isFiniteNumber(frame) && time === void 0;
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* Checks the result of `sampleSpriteAnimation`.
|
|
1869
|
+
*
|
|
1870
|
+
* @param value - The received `result`.
|
|
1871
|
+
* @returns True for `{ posed: boolean }`.
|
|
1872
|
+
*
|
|
1873
|
+
* @public
|
|
1874
|
+
*/
|
|
1875
|
+
function isSampleSpriteAnimationResult(value) {
|
|
1876
|
+
return isRecord(value) && isBoolean(value["posed"]);
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1704
1879
|
* Checks the parameters of `sceneOpened`.
|
|
1705
1880
|
*
|
|
1706
1881
|
* @param value - The received `params`.
|
|
@@ -1831,7 +2006,9 @@ function isLogParams(value) {
|
|
|
1831
2006
|
* @remarks
|
|
1832
2007
|
* A host lists `HostCapability.gameView` when it answers the first two and
|
|
1833
2008
|
* `HostCapability.thumbnails` when it answers the third; one that does not answers
|
|
1834
|
-
* `RpcErrorCode.methodNotFound`. Additive in 0.3.
|
|
2009
|
+
* `RpcErrorCode.methodNotFound`. Additive in 0.3. `HostCapability.gameViewOnDemand`,
|
|
2010
|
+
* `HostCapability.gameViewSize` and `HostCapability.gameView2d` mark what a newer host's
|
|
2011
|
+
* `gameViewFrame` does beyond that.
|
|
1835
2012
|
*
|
|
1836
2013
|
* @public
|
|
1837
2014
|
*/
|
|
@@ -1842,6 +2019,10 @@ const RenderViewMethod = {
|
|
|
1842
2019
|
* Renders the open scene through its own main camera, the one the game would use, and answers
|
|
1843
2020
|
* the image: {@link GameViewFrameResult}. Fails with `RpcErrorCode.noScene` while no scene is
|
|
1844
2021
|
* open and `RpcErrorCode.invalidRequest` while the game view is off.
|
|
2022
|
+
*
|
|
2023
|
+
* A host with `HostCapability.gameViewOnDemand` answers without waiting for an animation frame
|
|
2024
|
+
* (a hidden host gets none); one with `HostCapability.gameViewSize` takes the image size in the
|
|
2025
|
+
* request; one with `HostCapability.gameView2d` renders a `Camera2D` document camera too.
|
|
1845
2026
|
*/
|
|
1846
2027
|
gameViewFrame: "gameViewFrame",
|
|
1847
2028
|
/** Renders one model or prefab asset on its own and answers the image: {@link ThumbnailResult}. */
|
|
@@ -1929,12 +2110,12 @@ function isGameViewState(value) {
|
|
|
1929
2110
|
* Checks the parameters of `gameViewFrame`.
|
|
1930
2111
|
*
|
|
1931
2112
|
* @param value - The received `params`.
|
|
1932
|
-
* @returns True for a known format
|
|
2113
|
+
* @returns True for a known format, a quality from 0 to 1 and sizes in range when given.
|
|
1933
2114
|
*
|
|
1934
2115
|
* @public
|
|
1935
2116
|
*/
|
|
1936
2117
|
function isGameViewFrameParams(value) {
|
|
1937
|
-
return isRecord(value) && hasImageFormat(value);
|
|
2118
|
+
return isRecord(value) && hasImageFormat(value) && optionalField(value, "width", (width) => isSide(width, 2048)) && optionalField(value, "height", (height) => isSide(height, 2048));
|
|
1938
2119
|
}
|
|
1939
2120
|
/**
|
|
1940
2121
|
* Checks the result of `gameViewFrame`.
|
|
@@ -3105,6 +3286,67 @@ var PlayStatsReader = class {
|
|
|
3105
3286
|
};
|
|
3106
3287
|
}
|
|
3107
3288
|
};
|
|
3289
|
+
//#endregion
|
|
3290
|
+
//#region src/scene/json.ts
|
|
3291
|
+
/**
|
|
3292
|
+
* The uid of a referenced entity or component.
|
|
3293
|
+
*
|
|
3294
|
+
* @param target - The field's value.
|
|
3295
|
+
* @returns Its uid, or `null` for anything without one.
|
|
3296
|
+
*/
|
|
3297
|
+
function uidOf(target) {
|
|
3298
|
+
const uid = typeof target === "object" && target !== null ? Reflect.get(target, "uid") : null;
|
|
3299
|
+
return typeof uid === "string" ? uid : null;
|
|
3300
|
+
}
|
|
3301
|
+
/**
|
|
3302
|
+
* Narrows JSON to an object. `Array.isArray` does not remove a readonly array from the union, so the
|
|
3303
|
+
* discrimination lives here once.
|
|
3304
|
+
*
|
|
3305
|
+
* @param value - The JSON.
|
|
3306
|
+
* @returns The object, or `null` for anything else.
|
|
3307
|
+
*/
|
|
3308
|
+
function asJsonObject(value) {
|
|
3309
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
3310
|
+
return value;
|
|
3311
|
+
}
|
|
3312
|
+
/**
|
|
3313
|
+
* Narrows JSON to an array.
|
|
3314
|
+
*
|
|
3315
|
+
* @param value - The JSON.
|
|
3316
|
+
* @returns The array, or `null`.
|
|
3317
|
+
*/
|
|
3318
|
+
function asJsonArray(value) {
|
|
3319
|
+
return Array.isArray(value) ? value : null;
|
|
3320
|
+
}
|
|
3321
|
+
/**
|
|
3322
|
+
* Tells whether JSON references an entity or component of a set.
|
|
3323
|
+
*
|
|
3324
|
+
* @param value - The JSON.
|
|
3325
|
+
* @param entities - The entity uids.
|
|
3326
|
+
* @param components - The component uids.
|
|
3327
|
+
* @returns True when a `$entity` or `$component` names one of them, or is an instance path that
|
|
3328
|
+
* starts at one of the entities.
|
|
3329
|
+
*/
|
|
3330
|
+
function pointsInto(value, entities, components) {
|
|
3331
|
+
const array = asJsonArray(value);
|
|
3332
|
+
if (array !== null) return array.some((item) => pointsInto(item, entities, components));
|
|
3333
|
+
const object = asJsonObject(value);
|
|
3334
|
+
if (object === null) return false;
|
|
3335
|
+
const entity = object["$entity"];
|
|
3336
|
+
const component = object["$component"];
|
|
3337
|
+
return typeof entity === "string" && (entities.has(entity) || entities.has(pathHead(entity))) || typeof component === "string" && (components.has(component) || entities.has(pathHead(component))) || Object.values(object).some((item) => pointsInto(item, entities, components));
|
|
3338
|
+
}
|
|
3339
|
+
/**
|
|
3340
|
+
* The first segment of an instance path (`"<instanceRootUid>/<uidInThePrefab>"`), the document
|
|
3341
|
+
* entity the path starts at; a plain uid has none.
|
|
3342
|
+
*
|
|
3343
|
+
* @param uid - A reference's uid or instance path.
|
|
3344
|
+
* @returns The instance root's uid, or `""` for a plain uid.
|
|
3345
|
+
*/
|
|
3346
|
+
function pathHead(uid) {
|
|
3347
|
+
const at = uid.indexOf("/");
|
|
3348
|
+
return at <= 0 ? "" : uid.slice(0, at);
|
|
3349
|
+
}
|
|
3108
3350
|
/**
|
|
3109
3351
|
* Copies a JSON value, so the host's settings never share an object with the editor's message.
|
|
3110
3352
|
*
|
|
@@ -3558,9 +3800,25 @@ var DocumentMirror = class {
|
|
|
3558
3800
|
decoder(built) {
|
|
3559
3801
|
const index = this.index();
|
|
3560
3802
|
const assets = this.#app.assets;
|
|
3803
|
+
const rootOf = (uid) => {
|
|
3804
|
+
const head = pathHead(uid);
|
|
3805
|
+
const root = head === "" ? null : index?.entities.get(head) ?? built?.entity(head) ?? null;
|
|
3806
|
+
return root === null ? null : {
|
|
3807
|
+
root,
|
|
3808
|
+
rest: uid.slice(head.length + 1)
|
|
3809
|
+
};
|
|
3810
|
+
};
|
|
3561
3811
|
return {
|
|
3562
|
-
entity: (uid) =>
|
|
3563
|
-
|
|
3812
|
+
entity: (uid) => {
|
|
3813
|
+
const known = index?.entities.get(uid) ?? built?.entity(uid) ?? null;
|
|
3814
|
+
const path = known === null ? rootOf(uid) : null;
|
|
3815
|
+
return path === null ? known : instanceEntityAt(path.root, path.rest);
|
|
3816
|
+
},
|
|
3817
|
+
component: (uid) => {
|
|
3818
|
+
const known = index?.components.get(uid) ?? built?.component(uid) ?? index?.added.get(uid) ?? null;
|
|
3819
|
+
const path = known === null ? rootOf(uid) : null;
|
|
3820
|
+
return path === null ? known : instanceComponentAt(path.root, path.rest);
|
|
3821
|
+
},
|
|
3564
3822
|
asset: (address, type) => {
|
|
3565
3823
|
const handle = assets.get(address);
|
|
3566
3824
|
return handle !== null && handle.state === "loaded" && (type === null || handle.type === type) ? handle : null;
|
|
@@ -4373,7 +4631,7 @@ function isSpriteLike(component) {
|
|
|
4373
4631
|
* @param component - The component.
|
|
4374
4632
|
* @returns True when it reports its cell size and layer sizes.
|
|
4375
4633
|
*/
|
|
4376
|
-
function isTilemapLike(component) {
|
|
4634
|
+
function isTilemapLike$1(component) {
|
|
4377
4635
|
return typeof Reflect.get(component, "cellSize") === "number" && typeof Reflect.get(component, "layerCount") === "number" && typeof Reflect.get(component, "layerSize") === "function";
|
|
4378
4636
|
}
|
|
4379
4637
|
/**
|
|
@@ -4407,7 +4665,7 @@ function boundsOf2D(app, entities) {
|
|
|
4407
4665
|
});
|
|
4408
4666
|
}
|
|
4409
4667
|
for (const component of tilemap === null ? [] : entity.getComponentsInChildren(tilemap, true)) {
|
|
4410
|
-
const extent = isTilemapLike(component) ? tilemapBox(component) : null;
|
|
4668
|
+
const extent = isTilemapLike$1(component) ? tilemapBox(component) : null;
|
|
4411
4669
|
if (extent !== null) box = union(box, extent);
|
|
4412
4670
|
}
|
|
4413
4671
|
}
|
|
@@ -4471,6 +4729,107 @@ function sceneViewMode(app, scene) {
|
|
|
4471
4729
|
const has3D = app.world.components(Camera).some(inScene);
|
|
4472
4730
|
return has2D && !has3D ? ViewMode.twoD : ViewMode.threeD;
|
|
4473
4731
|
}
|
|
4732
|
+
/** The view a screen-space layer keeps: no camera at all. */
|
|
4733
|
+
const IDENTITY_LAYER_VIEW = {
|
|
4734
|
+
x: 0,
|
|
4735
|
+
y: 0,
|
|
4736
|
+
zoom: 1,
|
|
4737
|
+
rotation: 0
|
|
4738
|
+
};
|
|
4739
|
+
/**
|
|
4740
|
+
* The view of a world layer centred on a point, as `@ignifx/2d`'s sync writes it: Lite's
|
|
4741
|
+
* `positionPx` is the layer pixel at the top-left corner, so the centre is moved back by half the
|
|
4742
|
+
* image, turned by the view's rotation.
|
|
4743
|
+
*
|
|
4744
|
+
* @param shot - What the camera shows.
|
|
4745
|
+
* @param widthPx - The image width.
|
|
4746
|
+
* @param heightPx - The image height.
|
|
4747
|
+
* @param pixelsPerUnit - Layer pixels per metre.
|
|
4748
|
+
* @returns The layer's view.
|
|
4749
|
+
*/
|
|
4750
|
+
function centredLayerView(shot, widthPx, heightPx, pixelsPerUnit) {
|
|
4751
|
+
const zoom = shot.zoom === 0 ? 1 : shot.zoom;
|
|
4752
|
+
const halfWidth = widthPx * .5 / zoom;
|
|
4753
|
+
const halfHeight = heightPx * .5 / zoom;
|
|
4754
|
+
const cos = Math.cos(shot.rotation);
|
|
4755
|
+
const sin = Math.sin(shot.rotation);
|
|
4756
|
+
const centreXPx = shot.centreX * pixelsPerUnit;
|
|
4757
|
+
const centreYPx = -shot.centreY * pixelsPerUnit;
|
|
4758
|
+
return {
|
|
4759
|
+
x: centreXPx - halfWidth * cos - halfHeight * sin,
|
|
4760
|
+
y: centreYPx + halfWidth * sin - halfHeight * cos,
|
|
4761
|
+
zoom,
|
|
4762
|
+
rotation: shot.rotation
|
|
4763
|
+
};
|
|
4764
|
+
}
|
|
4765
|
+
/**
|
|
4766
|
+
* What a `Camera2D` shows in an image of a size: its own `resolve` (orthographic size, pixel-perfect
|
|
4767
|
+
* snapping, bounds) run against that size, else `zoom = heightPx / (2 · size · PPU)` at its
|
|
4768
|
+
* position.
|
|
4769
|
+
*
|
|
4770
|
+
* @remarks
|
|
4771
|
+
* `resolve` stores the size it was given on the camera. The scene view draws through the editor's
|
|
4772
|
+
* own `Camera2D`, so the level's camera keeps those values only until a frame draws through it.
|
|
4773
|
+
*
|
|
4774
|
+
* @param camera - The level's camera.
|
|
4775
|
+
* @param widthPx - The image width.
|
|
4776
|
+
* @param heightPx - The image height.
|
|
4777
|
+
* @param pixelsPerUnit - Layer pixels per metre.
|
|
4778
|
+
* @returns The centre, zoom and rotation.
|
|
4779
|
+
*/
|
|
4780
|
+
function camera2DShot(camera, widthPx, heightPx, pixelsPerUnit) {
|
|
4781
|
+
const matrix = camera.entity.transform.worldMatrix;
|
|
4782
|
+
const worldX = matrix[12] ?? 0;
|
|
4783
|
+
const worldY = matrix[13] ?? 0;
|
|
4784
|
+
const rotation = Math.atan2(matrix[1] ?? 0, matrix[0] ?? 1);
|
|
4785
|
+
const resolve = Reflect.get(camera, "resolve");
|
|
4786
|
+
const centre = Reflect.get(camera, "centre");
|
|
4787
|
+
if (typeof resolve === "function") {
|
|
4788
|
+
Reflect.apply(resolve, camera, [
|
|
4789
|
+
worldX,
|
|
4790
|
+
worldY,
|
|
4791
|
+
widthPx,
|
|
4792
|
+
heightPx,
|
|
4793
|
+
pixelsPerUnit
|
|
4794
|
+
]);
|
|
4795
|
+
const zoom = Reflect.get(camera, "zoom");
|
|
4796
|
+
const x = typeof centre === "object" && centre !== null ? Reflect.get(centre, "x") : void 0;
|
|
4797
|
+
const y = typeof centre === "object" && centre !== null ? Reflect.get(centre, "y") : void 0;
|
|
4798
|
+
if (typeof zoom === "number" && typeof x === "number" && typeof y === "number") return {
|
|
4799
|
+
centreX: x,
|
|
4800
|
+
centreY: y,
|
|
4801
|
+
zoom,
|
|
4802
|
+
rotation
|
|
4803
|
+
};
|
|
4804
|
+
}
|
|
4805
|
+
return {
|
|
4806
|
+
centreX: worldX,
|
|
4807
|
+
centreY: worldY,
|
|
4808
|
+
zoom: zoomForSize(camera.orthographicSize > 0 ? camera.orthographicSize : 1, heightPx, pixelsPerUnit),
|
|
4809
|
+
rotation
|
|
4810
|
+
};
|
|
4811
|
+
}
|
|
4812
|
+
/**
|
|
4813
|
+
* The project's sprite layers, in draw order, from `app.twoD.layers`.
|
|
4814
|
+
*
|
|
4815
|
+
* @param app - The app.
|
|
4816
|
+
* @returns The layers, or `null` when the project has no 2D toolkit.
|
|
4817
|
+
*/
|
|
4818
|
+
function twoDLayersOf(app) {
|
|
4819
|
+
const service = Reflect.get(app, "twoD");
|
|
4820
|
+
if (typeof service !== "object" || service === null) return null;
|
|
4821
|
+
const layers = Reflect.get(service, "layers");
|
|
4822
|
+
if (!Array.isArray(layers)) return null;
|
|
4823
|
+
const out = [];
|
|
4824
|
+
for (const entry of layers) {
|
|
4825
|
+
const layer = typeof entry === "object" && entry !== null ? Reflect.get(entry, "layer") : null;
|
|
4826
|
+
if (typeof layer === "object" && layer !== null) out.push({
|
|
4827
|
+
layer,
|
|
4828
|
+
screenSpace: Reflect.get(Object(entry), "screenSpace") === true
|
|
4829
|
+
});
|
|
4830
|
+
}
|
|
4831
|
+
return out;
|
|
4832
|
+
}
|
|
4474
4833
|
//#endregion
|
|
4475
4834
|
//#region src/scene/editor-camera-2d.ts
|
|
4476
4835
|
/**
|
|
@@ -5083,10 +5442,19 @@ async function encodeCapture(capture, size, format, quality) {
|
|
|
5083
5442
|
targetContext.imageSmoothingQuality = "high";
|
|
5084
5443
|
targetContext.drawImage(source, 0, 0, size.width, size.height);
|
|
5085
5444
|
const type = format === "png" ? "image/png" : "image/jpeg";
|
|
5086
|
-
|
|
5445
|
+
return encodeBlob(await target.convertToBlob(format === "png" ? { type } : {
|
|
5087
5446
|
type,
|
|
5088
5447
|
quality
|
|
5089
|
-
});
|
|
5448
|
+
}), type);
|
|
5449
|
+
}
|
|
5450
|
+
/**
|
|
5451
|
+
* Writes an encoded image as a data URL.
|
|
5452
|
+
*
|
|
5453
|
+
* @param blob - The PNG or JPEG bytes.
|
|
5454
|
+
* @param type - `"image/png"` or `"image/jpeg"`.
|
|
5455
|
+
* @returns The data URL.
|
|
5456
|
+
*/
|
|
5457
|
+
async function encodeBlob(blob, type) {
|
|
5090
5458
|
return `data:${type};base64,${toBase64(new Uint8Array(await blob.arrayBuffer()))}`;
|
|
5091
5459
|
}
|
|
5092
5460
|
/**
|
|
@@ -5122,12 +5490,6 @@ async function takeScreenshot(app, params) {
|
|
|
5122
5490
|
height: size.height
|
|
5123
5491
|
};
|
|
5124
5492
|
}
|
|
5125
|
-
//#endregion
|
|
5126
|
-
//#region src/scene/game-view.ts
|
|
5127
|
-
/**
|
|
5128
|
-
* The Game panel's view (engine ask E8): the open scene through its own main camera, rendered into
|
|
5129
|
-
* a render texture beside the editor camera's frame (`setGameView`, `gameViewFrame`).
|
|
5130
|
-
*/
|
|
5131
5493
|
/** The JPEG quality when the request gives none, as for `screenshot`. */
|
|
5132
5494
|
const DEFAULT_JPEG_QUALITY$1 = .9;
|
|
5133
5495
|
/**
|
|
@@ -5179,32 +5541,67 @@ var GameView = class {
|
|
|
5179
5541
|
};
|
|
5180
5542
|
}
|
|
5181
5543
|
/**
|
|
5182
|
-
* `gameViewFrame`: renders the document camera into the texture
|
|
5183
|
-
* as an image.
|
|
5544
|
+
* `gameViewFrame`: renders the document camera, a `Camera` into the texture or a `Camera2D`
|
|
5545
|
+
* through the sprite pass, and answers it as an image.
|
|
5184
5546
|
*
|
|
5185
5547
|
* @param app - The scene view's app.
|
|
5186
5548
|
* @param mirror - The open document.
|
|
5187
|
-
* @param params - `{ format, quality? }`.
|
|
5549
|
+
* @param params - `{ format, quality?, width?, height? }`.
|
|
5188
5550
|
* @returns The image and the camera's document uid, or no image when the document has no camera.
|
|
5189
5551
|
*/
|
|
5190
5552
|
async frame(app, mirror, params) {
|
|
5191
|
-
if (!isGameViewFrameParams(params)) throw new InvalidParamsError("gameViewFrame takes { format: \"png\" | \"jpeg\", quality? }.");
|
|
5553
|
+
if (!isGameViewFrameParams(params)) throw new InvalidParamsError("gameViewFrame takes { format: \"png\" | \"jpeg\", quality?, width?, height? } with sides from 1 to 2048.");
|
|
5554
|
+
if (!this.#enabled || this.#texture === null) throw new RpcFailure(RpcErrorCode.invalidRequest, "The game view is off; send \"setGameView\" with enabled: true first.");
|
|
5555
|
+
if (params.width !== void 0 || params.height !== void 0) this.set(app, {
|
|
5556
|
+
enabled: true,
|
|
5557
|
+
width: params.width ?? this.#width,
|
|
5558
|
+
height: params.height ?? this.#height
|
|
5559
|
+
});
|
|
5192
5560
|
const texture = this.#texture;
|
|
5193
|
-
if (!this.#enabled || texture === null) throw new RpcFailure(RpcErrorCode.invalidRequest, "The game view is off; send \"setGameView\" with enabled: true first.");
|
|
5194
5561
|
const size = {
|
|
5195
5562
|
width: this.#width,
|
|
5196
5563
|
height: this.#height
|
|
5197
5564
|
};
|
|
5565
|
+
const quality = params.quality ?? DEFAULT_JPEG_QUALITY$1;
|
|
5198
5566
|
const camera = documentCamera(app, mirror);
|
|
5199
|
-
if (camera
|
|
5567
|
+
if (camera !== null) {
|
|
5568
|
+
const uid = (mirror.documentEntityOf(camera.entity) ?? camera.entity).uid;
|
|
5569
|
+
await app.renderer.renderToTexture(camera, texture, { maxWaitMs: 20 });
|
|
5570
|
+
return {
|
|
5571
|
+
dataUrl: await encodeCapture(await texture.readPixels(), size, params.format, quality),
|
|
5572
|
+
...size,
|
|
5573
|
+
camera: uid
|
|
5574
|
+
};
|
|
5575
|
+
}
|
|
5576
|
+
const camera2D = levelCamera2D(app, mirror.scene);
|
|
5577
|
+
const layers = twoDLayersOf(app);
|
|
5578
|
+
const twoD = twoDServiceOf(app);
|
|
5579
|
+
if (camera2D === null || layers === null || twoD === null) return {
|
|
5200
5580
|
dataUrl: null,
|
|
5201
5581
|
...size,
|
|
5202
5582
|
camera: null
|
|
5203
5583
|
};
|
|
5204
|
-
const uid = (mirror.documentEntityOf(
|
|
5205
|
-
await app.renderer.
|
|
5584
|
+
const uid = (mirror.documentEntityOf(camera2D.entity) ?? camera2D.entity).uid;
|
|
5585
|
+
await app.renderer.nextFrame({ maxWaitMs: 20 });
|
|
5586
|
+
const world = centredLayerView(camera2DShot(camera2D, size.width, size.height, twoD.pixelsPerUnit), size.width, size.height, twoD.pixelsPerUnit);
|
|
5587
|
+
const draws = layers.map(({ layer, screenSpace }) => {
|
|
5588
|
+
const view = screenSpace ? IDENTITY_LAYER_VIEW : world;
|
|
5589
|
+
return {
|
|
5590
|
+
layer,
|
|
5591
|
+
x: view.x,
|
|
5592
|
+
y: view.y,
|
|
5593
|
+
zoom: view.zoom,
|
|
5594
|
+
rotation: view.rotation
|
|
5595
|
+
};
|
|
5596
|
+
});
|
|
5597
|
+
const { renderSpriteGameView } = await import("./sprite-game-view.js");
|
|
5598
|
+
const { clearColor } = app.settings.section(RENDERING_SETTINGS_SECTION);
|
|
5599
|
+
const type = params.format === "png" ? "image/png" : "image/jpeg";
|
|
5206
5600
|
return {
|
|
5207
|
-
dataUrl: await
|
|
5601
|
+
dataUrl: await encodeBlob(await renderSpriteGameView(app.lite.engine, draws, {
|
|
5602
|
+
...size,
|
|
5603
|
+
clear: clearColor
|
|
5604
|
+
}, type, quality), type),
|
|
5208
5605
|
...size,
|
|
5209
5606
|
camera: uid
|
|
5210
5607
|
};
|
|
@@ -5367,55 +5764,6 @@ function screenGridPlacement(view, size) {
|
|
|
5367
5764
|
};
|
|
5368
5765
|
}
|
|
5369
5766
|
//#endregion
|
|
5370
|
-
//#region src/scene/json.ts
|
|
5371
|
-
/**
|
|
5372
|
-
* The uid of a referenced entity or component.
|
|
5373
|
-
*
|
|
5374
|
-
* @param target - The field's value.
|
|
5375
|
-
* @returns Its uid, or `null` for anything without one.
|
|
5376
|
-
*/
|
|
5377
|
-
function uidOf(target) {
|
|
5378
|
-
const uid = typeof target === "object" && target !== null ? Reflect.get(target, "uid") : null;
|
|
5379
|
-
return typeof uid === "string" ? uid : null;
|
|
5380
|
-
}
|
|
5381
|
-
/**
|
|
5382
|
-
* Narrows JSON to an object. `Array.isArray` does not remove a readonly array from the union, so the
|
|
5383
|
-
* discrimination lives here once.
|
|
5384
|
-
*
|
|
5385
|
-
* @param value - The JSON.
|
|
5386
|
-
* @returns The object, or `null` for anything else.
|
|
5387
|
-
*/
|
|
5388
|
-
function asJsonObject(value) {
|
|
5389
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
5390
|
-
return value;
|
|
5391
|
-
}
|
|
5392
|
-
/**
|
|
5393
|
-
* Narrows JSON to an array.
|
|
5394
|
-
*
|
|
5395
|
-
* @param value - The JSON.
|
|
5396
|
-
* @returns The array, or `null`.
|
|
5397
|
-
*/
|
|
5398
|
-
function asJsonArray(value) {
|
|
5399
|
-
return Array.isArray(value) ? value : null;
|
|
5400
|
-
}
|
|
5401
|
-
/**
|
|
5402
|
-
* Tells whether JSON references an entity or component of a set.
|
|
5403
|
-
*
|
|
5404
|
-
* @param value - The JSON.
|
|
5405
|
-
* @param entities - The entity uids.
|
|
5406
|
-
* @param components - The component uids.
|
|
5407
|
-
* @returns True when a `$entity` or `$component` names one of them.
|
|
5408
|
-
*/
|
|
5409
|
-
function pointsInto(value, entities, components) {
|
|
5410
|
-
const array = asJsonArray(value);
|
|
5411
|
-
if (array !== null) return array.some((item) => pointsInto(item, entities, components));
|
|
5412
|
-
const object = asJsonObject(value);
|
|
5413
|
-
if (object === null) return false;
|
|
5414
|
-
const entity = object["$entity"];
|
|
5415
|
-
const component = object["$component"];
|
|
5416
|
-
return typeof entity === "string" && entities.has(entity) || typeof component === "string" && components.has(component) || Object.values(object).some((item) => pointsInto(item, entities, components));
|
|
5417
|
-
}
|
|
5418
|
-
//#endregion
|
|
5419
5767
|
//#region src/scene/held-references.ts
|
|
5420
5768
|
/**
|
|
5421
5769
|
* What instance members outside a subtree that is about to be rebuilt hold in it: the reference
|
|
@@ -6371,6 +6719,41 @@ function sampleAnimation(app, mirror, params) {
|
|
|
6371
6719
|
}
|
|
6372
6720
|
}
|
|
6373
6721
|
//#endregion
|
|
6722
|
+
//#region src/scene/sample-sprite-animation.ts
|
|
6723
|
+
/**
|
|
6724
|
+
* `sampleSpriteAnimation`: the scene view shows one frame of a clip on an entity's `SpriteAnimator`
|
|
6725
|
+
* (engine ask E51), through `@ignifx/2d`'s `SpriteAnimator.sample` and `sampleTime`. The host
|
|
6726
|
+
* depends on core only, so it finds the `SpriteAnimator` by its type id and calls them by shape.
|
|
6727
|
+
*/
|
|
6728
|
+
/** The type id `@ignifx/2d` registers its `SpriteAnimator` under. */
|
|
6729
|
+
const SPRITE_ANIMATOR_TYPE_ID = "ignifx/SpriteAnimator";
|
|
6730
|
+
/**
|
|
6731
|
+
* Answers `sampleSpriteAnimation` on the open document.
|
|
6732
|
+
*
|
|
6733
|
+
* @param app - The scene view's app.
|
|
6734
|
+
* @param mirror - The open document.
|
|
6735
|
+
* @param params - The received `params`.
|
|
6736
|
+
* @returns Whether the frame was written.
|
|
6737
|
+
* @throws InvalidParamsError for malformed params, an entity the document lacks or one without a
|
|
6738
|
+
* `SpriteAnimator`, and any `IgnifxError` the engine throws, whose code it carries as `data.code`.
|
|
6739
|
+
*/
|
|
6740
|
+
function sampleSpriteAnimation(app, mirror, params) {
|
|
6741
|
+
if (!isSampleSpriteAnimationParams(params)) throw new InvalidParamsError(`sampleSpriteAnimation takes { entity: uid, clip: string, frame: number } or { entity: uid, clip: string, time: number }, with names of at most ${String(256)} characters.`);
|
|
6742
|
+
const entity = mirror.index()?.entities.get(params.entity);
|
|
6743
|
+
if (entity === void 0) throw new InvalidParamsError(`sampleSpriteAnimation names ${params.entity}, which is not an entity of the open scene.`);
|
|
6744
|
+
const type = componentTypeOf(app, SPRITE_ANIMATOR_TYPE_ID);
|
|
6745
|
+
const animator = type === null ? null : entity.getComponent(type);
|
|
6746
|
+
const byTime = params.frame === void 0;
|
|
6747
|
+
const method = animator === null ? void 0 : Reflect.get(animator, byTime ? "sampleTime" : "sample");
|
|
6748
|
+
if (animator === null || typeof method !== "function") throw new InvalidParamsError(`The entity ${params.entity} has no SpriteAnimator to sample.`);
|
|
6749
|
+
try {
|
|
6750
|
+
return { posed: Reflect.apply(method, animator, [params.clip, params.frame ?? params.time ?? 0]) === true };
|
|
6751
|
+
} catch (error) {
|
|
6752
|
+
if (isIgnifxError(error)) throw new InvalidParamsError(error.message, { code: error.code });
|
|
6753
|
+
throw error;
|
|
6754
|
+
}
|
|
6755
|
+
}
|
|
6756
|
+
//#endregion
|
|
6374
6757
|
//#region src/scene/schemas.ts
|
|
6375
6758
|
/**
|
|
6376
6759
|
* `getSchemas` and `schemasChanged`: every registered component's schema, as the inspector reads
|
|
@@ -6652,7 +7035,7 @@ var ThumbnailRenderer = class {
|
|
|
6652
7035
|
await nextFrame();
|
|
6653
7036
|
const size = params.size ?? 128;
|
|
6654
7037
|
const texture = this.#textureOf(app, size * SUPERSAMPLE);
|
|
6655
|
-
await app.renderer.renderToTexture(camera, texture);
|
|
7038
|
+
await app.renderer.renderToTexture(camera, texture, { maxWaitMs: 20 });
|
|
6656
7039
|
return {
|
|
6657
7040
|
dataUrl: await encodeCapture(await texture.readPixels(), {
|
|
6658
7041
|
width: size,
|
|
@@ -6823,6 +7206,81 @@ function frameCamera(camera, bounds) {
|
|
|
6823
7206
|
camera.far = distance + radius * 1.5;
|
|
6824
7207
|
}
|
|
6825
7208
|
//#endregion
|
|
7209
|
+
//#region src/scene/tilemap-cells.ts
|
|
7210
|
+
/**
|
|
7211
|
+
* `setTilemapCells`: a tilemap editor's painting, written into the open scene's live `Tilemap`s so
|
|
7212
|
+
* it shows at once. The host reaches `Tilemap` by type id and its members by shape, as
|
|
7213
|
+
* `./view-2d.ts` does, so it does not depend on `@ignifx/2d`.
|
|
7214
|
+
*/
|
|
7215
|
+
/**
|
|
7216
|
+
* Turns the file-ordered `[index, tile, …]` pairs of `setTilemapCells` into `Tilemap.setCells`
|
|
7217
|
+
* writes, whose rows count from the bottom.
|
|
7218
|
+
*
|
|
7219
|
+
* @param layers - The document's layers.
|
|
7220
|
+
* @param layer - The layer's name or index.
|
|
7221
|
+
* @param cells - The flat pairs, the index row-major with the top row first.
|
|
7222
|
+
* @returns The writes, or why the request does not fit the document.
|
|
7223
|
+
*/
|
|
7224
|
+
function planTileWrites(layers, layer, cells) {
|
|
7225
|
+
const index = typeof layer === "number" ? layer : layers.findIndex((candidate) => candidate.name === layer);
|
|
7226
|
+
const declared = layers[index];
|
|
7227
|
+
if (declared === void 0) return `The tilemap has no layer ${JSON.stringify(layer)}.`;
|
|
7228
|
+
const { width, height } = declared;
|
|
7229
|
+
const writes = [];
|
|
7230
|
+
for (let at = 0; at + 1 < cells.length; at += 2) {
|
|
7231
|
+
const cell = cells[at] ?? 0;
|
|
7232
|
+
if (cell >= width * height) return `Cell ${String(cell)} is outside layer ${JSON.stringify(declared.name)} (${String(width)}×${String(height)}).`;
|
|
7233
|
+
const row = Math.floor(cell / width);
|
|
7234
|
+
writes.push({
|
|
7235
|
+
layer: index,
|
|
7236
|
+
x: cell % width,
|
|
7237
|
+
y: height - 1 - row,
|
|
7238
|
+
tileId: cells[at + 1] ?? 0
|
|
7239
|
+
});
|
|
7240
|
+
}
|
|
7241
|
+
return writes;
|
|
7242
|
+
}
|
|
7243
|
+
/**
|
|
7244
|
+
* Tells whether a component has the `Tilemap` members the host uses.
|
|
7245
|
+
*
|
|
7246
|
+
* @param component - The component.
|
|
7247
|
+
* @returns True for a `map`, a `definition` and a `setCells` method.
|
|
7248
|
+
*/
|
|
7249
|
+
function isTilemapLike(component) {
|
|
7250
|
+
return Reflect.has(component, "map") && Reflect.has(component, "definition") && typeof Reflect.get(component, "setCells") === "function";
|
|
7251
|
+
}
|
|
7252
|
+
/**
|
|
7253
|
+
* Writes the cells into every `Tilemap` under the roots whose `map` is the asset and has loaded.
|
|
7254
|
+
* Every tilemap's writes are checked before any is made.
|
|
7255
|
+
*
|
|
7256
|
+
* @param app - The scene view's app.
|
|
7257
|
+
* @param roots - The open scene's root entities.
|
|
7258
|
+
* @param params - The request.
|
|
7259
|
+
* @returns How many tilemaps were written and how many cells changed.
|
|
7260
|
+
* @throws InvalidParamsError when the layer or a cell does not fit a tilemap's document.
|
|
7261
|
+
*/
|
|
7262
|
+
function setTilemapCells(app, roots, params) {
|
|
7263
|
+
const type = componentTypeOf(app, TILEMAP_TYPE);
|
|
7264
|
+
if (type === null) return {
|
|
7265
|
+
tilemaps: 0,
|
|
7266
|
+
changed: 0
|
|
7267
|
+
};
|
|
7268
|
+
const planned = [];
|
|
7269
|
+
for (const root of roots) for (const component of root.getComponentsInChildren(type, true)) {
|
|
7270
|
+
const layers = isTilemapLike(component) ? component.definition?.layers : void 0;
|
|
7271
|
+
if (!isTilemapLike(component) || component.map?.address !== params.asset || layers === void 0) continue;
|
|
7272
|
+
const writes = planTileWrites(layers, params.layer, params.cells);
|
|
7273
|
+
if (typeof writes === "string") throw new InvalidParamsError(`setTilemapCells: ${params.asset}: ${writes}`);
|
|
7274
|
+
planned.push([component, writes]);
|
|
7275
|
+
}
|
|
7276
|
+
let changed = 0;
|
|
7277
|
+
for (const [tilemap, writes] of planned) changed += tilemap.setCells(writes);
|
|
7278
|
+
return {
|
|
7279
|
+
tilemaps: planned.length,
|
|
7280
|
+
changed
|
|
7281
|
+
};
|
|
7282
|
+
}
|
|
7283
|
+
//#endregion
|
|
6826
7284
|
//#region src/scene/scene-host.ts
|
|
6827
7285
|
/**
|
|
6828
7286
|
* The scene methods and notifications of protocol 0.3: what the scene view's host does with the
|
|
@@ -6830,6 +7288,13 @@ function frameCamera(camera, bounds) {
|
|
|
6830
7288
|
*/
|
|
6831
7289
|
/** The name of the host's persistent scene instance for its own objects. */
|
|
6832
7290
|
const EDITOR_SCENE_NAME = "editor";
|
|
7291
|
+
/** The colour of an editor line set that names none: a light green, as collider gizmos usually are. */
|
|
7292
|
+
const DEFAULT_LINE_COLOR = {
|
|
7293
|
+
r: .55,
|
|
7294
|
+
g: 1,
|
|
7295
|
+
b: .55,
|
|
7296
|
+
a: 1
|
|
7297
|
+
};
|
|
6833
7298
|
/** The editor camera's priority: above any camera a document can hold. */
|
|
6834
7299
|
const EDITOR_CAMERA_PRIORITY = 1e6;
|
|
6835
7300
|
/**
|
|
@@ -6870,6 +7335,10 @@ var SceneHost = class {
|
|
|
6870
7335
|
visible: true,
|
|
6871
7336
|
size: 1
|
|
6872
7337
|
};
|
|
7338
|
+
/** The editor's line sets, as `setEditorLines` last set them, by id; drawn once `#lines` exists. */
|
|
7339
|
+
#lineSets = /* @__PURE__ */ new Map();
|
|
7340
|
+
/** The line sets' meshes, once a canvas has an overlay (never headless). */
|
|
7341
|
+
#lines = null;
|
|
6873
7342
|
#drag;
|
|
6874
7343
|
#gameView = new GameView();
|
|
6875
7344
|
#thumbnails;
|
|
@@ -6906,6 +7375,7 @@ var SceneHost = class {
|
|
|
6906
7375
|
[SceneMethod.getColliderOutlines, (params) => this.#getColliderOutlines(params)],
|
|
6907
7376
|
[SceneMethod.sampleAnimation, (params) => this.#sampleAnimation(params)]
|
|
6908
7377
|
]);
|
|
7378
|
+
if (has(HostCapability.spriteAnimation)) methods.set(SceneMethod.sampleSpriteAnimation, (params) => this.#sampleSpriteAnimation(params));
|
|
6909
7379
|
if (has(HostCapability.gizmos)) methods.set(SceneMethod.setGizmo, (params) => this.#setGizmo(params));
|
|
6910
7380
|
if (has(HostCapability.screenshot)) methods.set(SceneMethod.screenshot, async (params) => this.#screenshot(params));
|
|
6911
7381
|
if (has(HostCapability.gameView)) {
|
|
@@ -6927,6 +7397,11 @@ var SceneHost = class {
|
|
|
6927
7397
|
return thumbnails.render(params);
|
|
6928
7398
|
});
|
|
6929
7399
|
if (has(HostCapability.grid)) methods.set(SceneMethod.setGrid, (params) => this.#setGrid(params));
|
|
7400
|
+
if (has(HostCapability.tilemapCells)) methods.set(SceneMethod.setTilemapCells, (params) => this.#setTilemapCells(params));
|
|
7401
|
+
if (has(HostCapability.editorLines)) {
|
|
7402
|
+
methods.set(SceneMethod.setEditorLines, (params) => this.#setEditorLines(params));
|
|
7403
|
+
methods.set(SceneMethod.clearEditorLines, (params) => this.#clearEditorLines(params));
|
|
7404
|
+
}
|
|
6930
7405
|
this.methods = new Map([...methods].map(([name, handler]) => [name, async (params) => this.#serial(() => handler(params))]));
|
|
6931
7406
|
}
|
|
6932
7407
|
/**
|
|
@@ -7013,6 +7488,12 @@ var SceneHost = class {
|
|
|
7013
7488
|
const { createEditorGrid } = await import("./grid.js");
|
|
7014
7489
|
this.#grid.view = createEditorGrid(app.lite, overlay);
|
|
7015
7490
|
}
|
|
7491
|
+
if (this.methods.has(SceneMethod.setEditorLines)) {
|
|
7492
|
+
const { createEditorLines } = await import("./editor-lines.js");
|
|
7493
|
+
const lines = createEditorLines(app.lite, overlay);
|
|
7494
|
+
for (const [id, set] of this.#lineSets) lines.set(id, set.lines, set.color);
|
|
7495
|
+
this.#lines = lines;
|
|
7496
|
+
}
|
|
7016
7497
|
const onClick = (click) => {
|
|
7017
7498
|
this.#onClick(click).catch((error) => {
|
|
7018
7499
|
const params = {
|
|
@@ -7150,6 +7631,8 @@ var SceneHost = class {
|
|
|
7150
7631
|
this.#grid.view?.dispose();
|
|
7151
7632
|
this.#grid.view = null;
|
|
7152
7633
|
}
|
|
7634
|
+
this.#lines?.dispose();
|
|
7635
|
+
this.#lines = null;
|
|
7153
7636
|
this.#view?.dispose();
|
|
7154
7637
|
this.#view = null;
|
|
7155
7638
|
this.#gameView.dispose();
|
|
@@ -7369,6 +7852,59 @@ var SceneHost = class {
|
|
|
7369
7852
|
return null;
|
|
7370
7853
|
}
|
|
7371
7854
|
/**
|
|
7855
|
+
* `setTilemapCells`: writes a tilemap editor's cells into the open scene's live tilemaps that
|
|
7856
|
+
* show the asset. The file on disk is the editor's to save.
|
|
7857
|
+
*
|
|
7858
|
+
* @param params - `{ asset, layer, cells }`.
|
|
7859
|
+
* @returns How many tilemaps were written and how many cells changed.
|
|
7860
|
+
*/
|
|
7861
|
+
#setTilemapCells(params) {
|
|
7862
|
+
const mirror = this.#requireMirror(SceneMethod.setTilemapCells);
|
|
7863
|
+
if (!isSetTilemapCellsParams(params)) throw new InvalidParamsError("setTilemapCells takes { asset: string, layer: string | number, cells: [index, tile, …] } of non-negative integers.");
|
|
7864
|
+
this.#requireOpen(SceneMethod.setTilemapCells);
|
|
7865
|
+
return setTilemapCells(this.#requireApp(), mirror.scene?.roots ?? [], params);
|
|
7866
|
+
}
|
|
7867
|
+
/**
|
|
7868
|
+
* `setEditorLines`: draws a set of the editor's world-space lines over the view, replacing the
|
|
7869
|
+
* set of the same id. Kept across scene opens; a page load starts with none.
|
|
7870
|
+
*
|
|
7871
|
+
* @param params - `{ id, lines, color? }`.
|
|
7872
|
+
* @returns `null`.
|
|
7873
|
+
*/
|
|
7874
|
+
#setEditorLines(params) {
|
|
7875
|
+
this.#requireMirror(SceneMethod.setEditorLines);
|
|
7876
|
+
if (!isSetEditorLinesParams(params)) throw new InvalidParamsError("setEditorLines takes { id: string, lines: number[] (six per segment), color?: [r, g, b, a?] from 0 to 1 }.");
|
|
7877
|
+
if (!this.#lineSets.has(params.id) && this.#lineSets.size >= 64) throw new InvalidParamsError(`The view draws at most ${String(64)} line sets; clear one first.`);
|
|
7878
|
+
const [r = 0, g = 0, b = 0, a = 1] = params.color ?? [];
|
|
7879
|
+
const color = params.color === void 0 ? DEFAULT_LINE_COLOR : {
|
|
7880
|
+
r,
|
|
7881
|
+
g,
|
|
7882
|
+
b,
|
|
7883
|
+
a
|
|
7884
|
+
};
|
|
7885
|
+
this.#lineSets.set(params.id, {
|
|
7886
|
+
lines: params.lines,
|
|
7887
|
+
color
|
|
7888
|
+
});
|
|
7889
|
+
this.#lines?.set(params.id, params.lines, color);
|
|
7890
|
+
return null;
|
|
7891
|
+
}
|
|
7892
|
+
/**
|
|
7893
|
+
* `clearEditorLines`: removes one line set, or every set.
|
|
7894
|
+
*
|
|
7895
|
+
* @param params - `{ id? }`.
|
|
7896
|
+
* @returns `null`.
|
|
7897
|
+
*/
|
|
7898
|
+
#clearEditorLines(params) {
|
|
7899
|
+
this.#requireMirror(SceneMethod.clearEditorLines);
|
|
7900
|
+
if (!isClearEditorLinesParams(params)) throw new InvalidParamsError("clearEditorLines takes { id?: string }.");
|
|
7901
|
+
const id = params.id ?? null;
|
|
7902
|
+
if (id === null) this.#lineSets.clear();
|
|
7903
|
+
else this.#lineSets.delete(id);
|
|
7904
|
+
this.#lines?.clear(id);
|
|
7905
|
+
return null;
|
|
7906
|
+
}
|
|
7907
|
+
/**
|
|
7372
7908
|
* Where the grid draws this frame: on the ground under the 3D editor camera, or over the 2D view.
|
|
7373
7909
|
*
|
|
7374
7910
|
* @returns The placement, or `null` while the grid is hidden.
|
|
@@ -7407,6 +7943,17 @@ var SceneHost = class {
|
|
|
7407
7943
|
return sampleAnimation(this.#requireApp(), mirror, params);
|
|
7408
7944
|
}
|
|
7409
7945
|
/**
|
|
7946
|
+
* `sampleSpriteAnimation`: shows one frame of a clip on an entity's `SpriteAnimator`.
|
|
7947
|
+
*
|
|
7948
|
+
* @param params - `{ entity, clip, frame }` or `{ entity, clip, time }`.
|
|
7949
|
+
* @returns `{ posed }`.
|
|
7950
|
+
*/
|
|
7951
|
+
#sampleSpriteAnimation(params) {
|
|
7952
|
+
const mirror = this.#requireMirror(SceneMethod.sampleSpriteAnimation);
|
|
7953
|
+
this.#requireOpen(SceneMethod.sampleSpriteAnimation);
|
|
7954
|
+
return sampleSpriteAnimation(this.#requireApp(), mirror, params);
|
|
7955
|
+
}
|
|
7956
|
+
/**
|
|
7410
7957
|
* `setViewMode`: switches the view between the 3D editor camera and the 2D one. The first switch
|
|
7411
7958
|
* to 2D on a document starts where the level's own `Camera2D` looks, or frames the document.
|
|
7412
7959
|
*
|
|
@@ -7836,12 +8383,19 @@ async function startEditorHost(options) {
|
|
|
7836
8383
|
HostCapability.logRelay,
|
|
7837
8384
|
HostCapability.hotReloadDefaults,
|
|
7838
8385
|
HostCapability.gameView,
|
|
8386
|
+
HostCapability.gameViewOnDemand,
|
|
8387
|
+
HostCapability.gameViewSize,
|
|
8388
|
+
HostCapability.gameView2d,
|
|
7839
8389
|
...canRenderThumbnails(options) ? [HostCapability.thumbnails] : [],
|
|
7840
|
-
HostCapability.grid
|
|
8390
|
+
HostCapability.grid,
|
|
8391
|
+
HostCapability.tilemapCells,
|
|
8392
|
+
HostCapability.editorLines,
|
|
8393
|
+
HostCapability.spriteAnimation
|
|
7841
8394
|
] : [
|
|
7842
8395
|
HostCapability.heartbeat,
|
|
7843
8396
|
HostCapability.logRelay,
|
|
7844
|
-
HostCapability.hotReloadDefaults
|
|
8397
|
+
HostCapability.hotReloadDefaults,
|
|
8398
|
+
HostCapability.spriteAnimation
|
|
7845
8399
|
];
|
|
7846
8400
|
let channel = null;
|
|
7847
8401
|
const scene = new SceneHost({
|
|
@@ -8671,6 +9225,6 @@ function listenForEditorPlayControls(options) {
|
|
|
8671
9225
|
};
|
|
8672
9226
|
}
|
|
8673
9227
|
//#endregion
|
|
8674
|
-
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, GRID_MAX_SIZE, GRID_MIN_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, isSetGridParams, isSetViewModeParams, isSettingsSet, isThumbnailResult, isTransformDraggedParams, isTransformDraggingParams, listenForEditorPlayControls, protocolVersionIsCompatible, startEditorHost, startEditorPlayControls };
|
|
9228
|
+
export { ApplyOpFailureCode, COLLIDER_OUTLINES_MAX_ENTITIES, COLLIDER_OUTLINES_MAX_NUMBERS, DEFAULT_HEARTBEAT_INTERVAL_MS, EDITOR_CONNECT_MESSAGE_TYPE, EDITOR_LINES_MAX_ID_LENGTH, EDITOR_LINES_MAX_NUMBERS, EDITOR_LINES_MAX_SETS, EditorHostErrorCode, GAME_VIEW_DEFAULT_SIZE, GAME_VIEW_MAX_SIZE, GRID_MAX_SIZE, GRID_MIN_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, TILEMAP_CELLS_MAX_NUMBERS, TRANSFORM_DRAGGING_INTERVAL_MS, ViewMode, isAppErrorData, isApplyOpsParams, isApplyOpsResult, isAssetReloadedParams, isClearEditorLinesParams, 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, isSampleSpriteAnimationParams, isSampleSpriteAnimationResult, isSceneFile, isSceneFileAssetRef, isSceneFileComponent, isSceneFileEntity, isSceneFileInstance, isSceneFileOverride, isSceneFileTransform, isSceneIssue, isSceneOp, isSceneOpenedParams, isSchemaSet, isScreenshotParams, isScreenshotResult, isSendInputEvent, isSendInputParams, isSendInputResult, isSetAnimateMaterialsParams, isSetEditorLinesParams, isSetGameViewParams, isSetGizmoParams, isSetGridParams, isSetTilemapCellsParams, isSetTilemapCellsResult, isSetViewModeParams, isSettingsSet, isThumbnailResult, isTransformDraggedParams, isTransformDraggingParams, listenForEditorPlayControls, protocolVersionIsCompatible, startEditorHost, startEditorPlayControls };
|
|
8675
9229
|
|
|
8676
9230
|
//# sourceMappingURL=index.js.map
|