@ignifx/editor-host 0.15.0 → 0.16.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 +242 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +367 -9
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/skills/editor-host/SKILL.md +24 -4
package/dist/index.js
CHANGED
|
@@ -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"`, `"thumbnails"
|
|
191
|
-
* to one of them is required of a
|
|
190
|
+
* `"pick2d"`, `"gameView"`, `"thumbnails"`, `"grid"`, `"tilemapCells"`, `"editorLines"` and
|
|
191
|
+
* `"spriteAnimation"` it supports; every `SceneMethod` not tied to one of them is required of a
|
|
192
|
+
* 0.3 scene host.
|
|
192
193
|
*
|
|
193
194
|
* @public
|
|
194
195
|
*/
|
|
@@ -261,7 +262,27 @@ const HostCapability = {
|
|
|
261
262
|
* (additive in 0.3); without it, the scene host answers `setGrid` with
|
|
262
263
|
* `RpcErrorCode.methodNotFound`.
|
|
263
264
|
*/
|
|
264
|
-
grid: "grid"
|
|
265
|
+
grid: "grid",
|
|
266
|
+
/**
|
|
267
|
+
* The scene host answers `setTilemapCells`: it writes cells into the open scene's live tilemaps,
|
|
268
|
+
* so a tilemap editor's painting shows without a save. Additive in 0.3; without it, the scene
|
|
269
|
+
* host answers `setTilemapCells` with `RpcErrorCode.methodNotFound`.
|
|
270
|
+
*/
|
|
271
|
+
tilemapCells: "tilemapCells",
|
|
272
|
+
/**
|
|
273
|
+
* The scene host answers `setEditorLines` and `clearEditorLines`: it draws the editor's own line
|
|
274
|
+
* segments (collider outlines, handles) over the view in both view modes, never in a game view or
|
|
275
|
+
* the play view. Additive in 0.3; without it, the scene host answers both with
|
|
276
|
+
* `RpcErrorCode.methodNotFound`.
|
|
277
|
+
*/
|
|
278
|
+
editorLines: "editorLines",
|
|
279
|
+
/**
|
|
280
|
+
* The scene host answers `sampleSpriteAnimation`: one frame of a clip on an entity's
|
|
281
|
+
* `SpriteAnimator` (`@ignifx/2d`), for the editor's sprite animation panel. From engine ask E51
|
|
282
|
+
* (additive in 0.3); without it, the scene host answers `sampleSpriteAnimation` with
|
|
283
|
+
* `RpcErrorCode.methodNotFound`.
|
|
284
|
+
*/
|
|
285
|
+
spriteAnimation: "spriteAnimation"
|
|
265
286
|
};
|
|
266
287
|
/**
|
|
267
288
|
* The longest string, in UTF-16 code units, the editor accepts from a host in `ready` (the engine
|
|
@@ -1107,10 +1128,33 @@ const SceneMethod = {
|
|
|
1107
1128
|
*/
|
|
1108
1129
|
sampleAnimation: "sampleAnimation",
|
|
1109
1130
|
/**
|
|
1131
|
+
* Shows one frame of a clip on an entity's `SpriteAnimator` without playing it (engine ask E51).
|
|
1132
|
+
* Needs `HostCapability.spriteAnimation`. Answers {@link SampleSpriteAnimationResult}. A host from
|
|
1133
|
+
* before it answers `RpcErrorCode.methodNotFound`. Additive in 0.3.
|
|
1134
|
+
*/
|
|
1135
|
+
sampleSpriteAnimation: "sampleSpriteAnimation",
|
|
1136
|
+
/**
|
|
1110
1137
|
* Shows or hides the view's grid and sets its spacing (engine ask E31). Needs
|
|
1111
1138
|
* `HostCapability.grid`. Answers `null`. Additive in 0.3.
|
|
1112
1139
|
*/
|
|
1113
|
-
setGrid: "setGrid"
|
|
1140
|
+
setGrid: "setGrid",
|
|
1141
|
+
/**
|
|
1142
|
+
* Writes cells of a tilemap asset into every live `Tilemap` of the open scene that shows it, so
|
|
1143
|
+
* painting is seen at once, without a save or a reopen. The file on disk is not touched. Needs
|
|
1144
|
+
* `HostCapability.tilemapCells`. Answers {@link SetTilemapCellsResult}. Additive in 0.3.
|
|
1145
|
+
*/
|
|
1146
|
+
setTilemapCells: "setTilemapCells",
|
|
1147
|
+
/**
|
|
1148
|
+
* Draws a set of world-space line segments over the view, such as collider outlines or handles,
|
|
1149
|
+
* replacing the set of the same id. Needs `HostCapability.editorLines`. Answers `null`. Additive
|
|
1150
|
+
* in 0.3.
|
|
1151
|
+
*/
|
|
1152
|
+
setEditorLines: "setEditorLines",
|
|
1153
|
+
/**
|
|
1154
|
+
* Removes one set of lines `setEditorLines` drew, or every set. Needs `HostCapability.editorLines`.
|
|
1155
|
+
* Answers `null`. Additive in 0.3.
|
|
1156
|
+
*/
|
|
1157
|
+
clearEditorLines: "clearEditorLines"
|
|
1114
1158
|
};
|
|
1115
1159
|
/**
|
|
1116
1160
|
* Scene host → editor: the notifications of protocol 0.3. None has an answer.
|
|
@@ -1299,6 +1343,32 @@ const GRID_MIN_SIZE = .001;
|
|
|
1299
1343
|
*/
|
|
1300
1344
|
const GRID_MAX_SIZE = 1e3;
|
|
1301
1345
|
/**
|
|
1346
|
+
* The most numbers the `cells` of one `setTilemapCells` request may hold: a million cells. A request
|
|
1347
|
+
* with more fails with `invalidParams`.
|
|
1348
|
+
*
|
|
1349
|
+
* @public
|
|
1350
|
+
*/
|
|
1351
|
+
const TILEMAP_CELLS_MAX_NUMBERS = 2e6;
|
|
1352
|
+
/**
|
|
1353
|
+
* The most numbers the `lines` of one `setEditorLines` request may hold: 100 000 segments.
|
|
1354
|
+
*
|
|
1355
|
+
* @public
|
|
1356
|
+
*/
|
|
1357
|
+
const EDITOR_LINES_MAX_NUMBERS = 6e5;
|
|
1358
|
+
/**
|
|
1359
|
+
* The most line sets the view draws at once; a `setEditorLines` for a new id past it fails with
|
|
1360
|
+
* `invalidParams`.
|
|
1361
|
+
*
|
|
1362
|
+
* @public
|
|
1363
|
+
*/
|
|
1364
|
+
const EDITOR_LINES_MAX_SETS = 64;
|
|
1365
|
+
/**
|
|
1366
|
+
* The longest line set id, in UTF-16 code units.
|
|
1367
|
+
*
|
|
1368
|
+
* @public
|
|
1369
|
+
*/
|
|
1370
|
+
const EDITOR_LINES_MAX_ID_LENGTH = 256;
|
|
1371
|
+
/**
|
|
1302
1372
|
* Tells whether a value is one of an `as const` object's values.
|
|
1303
1373
|
*
|
|
1304
1374
|
* @param names - The object.
|
|
@@ -1628,6 +1698,65 @@ function isSetGridParams(value) {
|
|
|
1628
1698
|
return optionalField(value, "visible", isBoolean) && (size === void 0 || isFiniteNumber(size) && size >= .001 && size <= 1e3);
|
|
1629
1699
|
}
|
|
1630
1700
|
/**
|
|
1701
|
+
* Checks the parameters of `setTilemapCells`.
|
|
1702
|
+
*
|
|
1703
|
+
* @param value - The received `params`.
|
|
1704
|
+
* @returns True for a non-empty `asset`, a layer name or index, and an even-length list of at most
|
|
1705
|
+
* {@link TILEMAP_CELLS_MAX_NUMBERS} non-negative integers.
|
|
1706
|
+
*
|
|
1707
|
+
* @public
|
|
1708
|
+
*/
|
|
1709
|
+
function isSetTilemapCellsParams(value) {
|
|
1710
|
+
if (!isRecord(value)) return false;
|
|
1711
|
+
const { asset, layer, cells } = value;
|
|
1712
|
+
return isUidString(asset) && (isString(layer) || isCount(layer)) && Array.isArray(cells) && cells.length % 2 === 0 && cells.length <= 2e6 && cells.every((item) => isCount(item));
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Checks the result of `setTilemapCells`.
|
|
1716
|
+
*
|
|
1717
|
+
* @param value - The received `result`.
|
|
1718
|
+
* @returns True for two counts.
|
|
1719
|
+
*
|
|
1720
|
+
* @public
|
|
1721
|
+
*/
|
|
1722
|
+
function isSetTilemapCellsResult(value) {
|
|
1723
|
+
return isRecord(value) && isCount(value["tilemaps"]) && isCount(value["changed"]);
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Tells whether a value is a line set id.
|
|
1727
|
+
*
|
|
1728
|
+
* @param value - The value to test.
|
|
1729
|
+
* @returns True for a non-empty string of at most {@link EDITOR_LINES_MAX_ID_LENGTH} code units.
|
|
1730
|
+
*/
|
|
1731
|
+
function isLineSetId(value) {
|
|
1732
|
+
return isUidString(value) && value.length <= 256;
|
|
1733
|
+
}
|
|
1734
|
+
/**
|
|
1735
|
+
* Checks the parameters of `setEditorLines`.
|
|
1736
|
+
*
|
|
1737
|
+
* @param value - The received `params`.
|
|
1738
|
+
* @returns True for an id, a list of finite numbers whose length is a multiple of six and at most
|
|
1739
|
+
* {@link EDITOR_LINES_MAX_NUMBERS}, and an optional colour of three or four numbers from 0 to 1.
|
|
1740
|
+
*
|
|
1741
|
+
* @public
|
|
1742
|
+
*/
|
|
1743
|
+
function isSetEditorLinesParams(value) {
|
|
1744
|
+
if (!isRecord(value)) return false;
|
|
1745
|
+
const { lines, color } = value;
|
|
1746
|
+
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));
|
|
1747
|
+
}
|
|
1748
|
+
/**
|
|
1749
|
+
* Checks the parameters of `clearEditorLines`.
|
|
1750
|
+
*
|
|
1751
|
+
* @param value - The received `params`.
|
|
1752
|
+
* @returns True for an object whose `id`, if present, is a line set id.
|
|
1753
|
+
*
|
|
1754
|
+
* @public
|
|
1755
|
+
*/
|
|
1756
|
+
function isClearEditorLinesParams(value) {
|
|
1757
|
+
return isRecord(value) && optionalField(value, "id", isLineSetId);
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1631
1760
|
* Checks one record of `getColliderOutlines`.
|
|
1632
1761
|
*
|
|
1633
1762
|
* @param value - The value to test.
|
|
@@ -1701,6 +1830,32 @@ function isSampleAnimationResult(value) {
|
|
|
1701
1830
|
return isRecord(value) && isBoolean(value["posed"]);
|
|
1702
1831
|
}
|
|
1703
1832
|
/**
|
|
1833
|
+
* Checks the parameters of `sampleSpriteAnimation`.
|
|
1834
|
+
*
|
|
1835
|
+
* @param value - The received `params`.
|
|
1836
|
+
* @returns True for a uid, a clip name within {@link SAMPLE_ANIMATION_MAX_NAME_LENGTH}, and exactly
|
|
1837
|
+
* one of a finite `frame` and a finite `time`.
|
|
1838
|
+
*
|
|
1839
|
+
* @public
|
|
1840
|
+
*/
|
|
1841
|
+
function isSampleSpriteAnimationParams(value) {
|
|
1842
|
+
if (!isRecord(value) || !isUidString(value["entity"]) || !isBoundedName(value["entity"]) || !isBoundedName(value["clip"])) return false;
|
|
1843
|
+
const frame = value["frame"];
|
|
1844
|
+
const time = value["time"];
|
|
1845
|
+
return frame === void 0 ? isFiniteNumber(time) : isFiniteNumber(frame) && time === void 0;
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Checks the result of `sampleSpriteAnimation`.
|
|
1849
|
+
*
|
|
1850
|
+
* @param value - The received `result`.
|
|
1851
|
+
* @returns True for `{ posed: boolean }`.
|
|
1852
|
+
*
|
|
1853
|
+
* @public
|
|
1854
|
+
*/
|
|
1855
|
+
function isSampleSpriteAnimationResult(value) {
|
|
1856
|
+
return isRecord(value) && isBoolean(value["posed"]);
|
|
1857
|
+
}
|
|
1858
|
+
/**
|
|
1704
1859
|
* Checks the parameters of `sceneOpened`.
|
|
1705
1860
|
*
|
|
1706
1861
|
* @param value - The received `params`.
|
|
@@ -4373,7 +4528,7 @@ function isSpriteLike(component) {
|
|
|
4373
4528
|
* @param component - The component.
|
|
4374
4529
|
* @returns True when it reports its cell size and layer sizes.
|
|
4375
4530
|
*/
|
|
4376
|
-
function isTilemapLike(component) {
|
|
4531
|
+
function isTilemapLike$1(component) {
|
|
4377
4532
|
return typeof Reflect.get(component, "cellSize") === "number" && typeof Reflect.get(component, "layerCount") === "number" && typeof Reflect.get(component, "layerSize") === "function";
|
|
4378
4533
|
}
|
|
4379
4534
|
/**
|
|
@@ -4407,7 +4562,7 @@ function boundsOf2D(app, entities) {
|
|
|
4407
4562
|
});
|
|
4408
4563
|
}
|
|
4409
4564
|
for (const component of tilemap === null ? [] : entity.getComponentsInChildren(tilemap, true)) {
|
|
4410
|
-
const extent = isTilemapLike(component) ? tilemapBox(component) : null;
|
|
4565
|
+
const extent = isTilemapLike$1(component) ? tilemapBox(component) : null;
|
|
4411
4566
|
if (extent !== null) box = union(box, extent);
|
|
4412
4567
|
}
|
|
4413
4568
|
}
|
|
@@ -6371,6 +6526,41 @@ function sampleAnimation(app, mirror, params) {
|
|
|
6371
6526
|
}
|
|
6372
6527
|
}
|
|
6373
6528
|
//#endregion
|
|
6529
|
+
//#region src/scene/sample-sprite-animation.ts
|
|
6530
|
+
/**
|
|
6531
|
+
* `sampleSpriteAnimation`: the scene view shows one frame of a clip on an entity's `SpriteAnimator`
|
|
6532
|
+
* (engine ask E51), through `@ignifx/2d`'s `SpriteAnimator.sample` and `sampleTime`. The host
|
|
6533
|
+
* depends on core only, so it finds the `SpriteAnimator` by its type id and calls them by shape.
|
|
6534
|
+
*/
|
|
6535
|
+
/** The type id `@ignifx/2d` registers its `SpriteAnimator` under. */
|
|
6536
|
+
const SPRITE_ANIMATOR_TYPE_ID = "ignifx/SpriteAnimator";
|
|
6537
|
+
/**
|
|
6538
|
+
* Answers `sampleSpriteAnimation` on the open document.
|
|
6539
|
+
*
|
|
6540
|
+
* @param app - The scene view's app.
|
|
6541
|
+
* @param mirror - The open document.
|
|
6542
|
+
* @param params - The received `params`.
|
|
6543
|
+
* @returns Whether the frame was written.
|
|
6544
|
+
* @throws InvalidParamsError for malformed params, an entity the document lacks or one without a
|
|
6545
|
+
* `SpriteAnimator`, and any `IgnifxError` the engine throws, whose code it carries as `data.code`.
|
|
6546
|
+
*/
|
|
6547
|
+
function sampleSpriteAnimation(app, mirror, params) {
|
|
6548
|
+
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.`);
|
|
6549
|
+
const entity = mirror.index()?.entities.get(params.entity);
|
|
6550
|
+
if (entity === void 0) throw new InvalidParamsError(`sampleSpriteAnimation names ${params.entity}, which is not an entity of the open scene.`);
|
|
6551
|
+
const type = componentTypeOf(app, SPRITE_ANIMATOR_TYPE_ID);
|
|
6552
|
+
const animator = type === null ? null : entity.getComponent(type);
|
|
6553
|
+
const byTime = params.frame === void 0;
|
|
6554
|
+
const method = animator === null ? void 0 : Reflect.get(animator, byTime ? "sampleTime" : "sample");
|
|
6555
|
+
if (animator === null || typeof method !== "function") throw new InvalidParamsError(`The entity ${params.entity} has no SpriteAnimator to sample.`);
|
|
6556
|
+
try {
|
|
6557
|
+
return { posed: Reflect.apply(method, animator, [params.clip, params.frame ?? params.time ?? 0]) === true };
|
|
6558
|
+
} catch (error) {
|
|
6559
|
+
if (isIgnifxError(error)) throw new InvalidParamsError(error.message, { code: error.code });
|
|
6560
|
+
throw error;
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
6563
|
+
//#endregion
|
|
6374
6564
|
//#region src/scene/schemas.ts
|
|
6375
6565
|
/**
|
|
6376
6566
|
* `getSchemas` and `schemasChanged`: every registered component's schema, as the inspector reads
|
|
@@ -6823,6 +7013,81 @@ function frameCamera(camera, bounds) {
|
|
|
6823
7013
|
camera.far = distance + radius * 1.5;
|
|
6824
7014
|
}
|
|
6825
7015
|
//#endregion
|
|
7016
|
+
//#region src/scene/tilemap-cells.ts
|
|
7017
|
+
/**
|
|
7018
|
+
* `setTilemapCells`: a tilemap editor's painting, written into the open scene's live `Tilemap`s so
|
|
7019
|
+
* it shows at once. The host reaches `Tilemap` by type id and its members by shape, as
|
|
7020
|
+
* `./view-2d.ts` does, so it does not depend on `@ignifx/2d`.
|
|
7021
|
+
*/
|
|
7022
|
+
/**
|
|
7023
|
+
* Turns the file-ordered `[index, tile, …]` pairs of `setTilemapCells` into `Tilemap.setCells`
|
|
7024
|
+
* writes, whose rows count from the bottom.
|
|
7025
|
+
*
|
|
7026
|
+
* @param layers - The document's layers.
|
|
7027
|
+
* @param layer - The layer's name or index.
|
|
7028
|
+
* @param cells - The flat pairs, the index row-major with the top row first.
|
|
7029
|
+
* @returns The writes, or why the request does not fit the document.
|
|
7030
|
+
*/
|
|
7031
|
+
function planTileWrites(layers, layer, cells) {
|
|
7032
|
+
const index = typeof layer === "number" ? layer : layers.findIndex((candidate) => candidate.name === layer);
|
|
7033
|
+
const declared = layers[index];
|
|
7034
|
+
if (declared === void 0) return `The tilemap has no layer ${JSON.stringify(layer)}.`;
|
|
7035
|
+
const { width, height } = declared;
|
|
7036
|
+
const writes = [];
|
|
7037
|
+
for (let at = 0; at + 1 < cells.length; at += 2) {
|
|
7038
|
+
const cell = cells[at] ?? 0;
|
|
7039
|
+
if (cell >= width * height) return `Cell ${String(cell)} is outside layer ${JSON.stringify(declared.name)} (${String(width)}×${String(height)}).`;
|
|
7040
|
+
const row = Math.floor(cell / width);
|
|
7041
|
+
writes.push({
|
|
7042
|
+
layer: index,
|
|
7043
|
+
x: cell % width,
|
|
7044
|
+
y: height - 1 - row,
|
|
7045
|
+
tileId: cells[at + 1] ?? 0
|
|
7046
|
+
});
|
|
7047
|
+
}
|
|
7048
|
+
return writes;
|
|
7049
|
+
}
|
|
7050
|
+
/**
|
|
7051
|
+
* Tells whether a component has the `Tilemap` members the host uses.
|
|
7052
|
+
*
|
|
7053
|
+
* @param component - The component.
|
|
7054
|
+
* @returns True for a `map`, a `definition` and a `setCells` method.
|
|
7055
|
+
*/
|
|
7056
|
+
function isTilemapLike(component) {
|
|
7057
|
+
return Reflect.has(component, "map") && Reflect.has(component, "definition") && typeof Reflect.get(component, "setCells") === "function";
|
|
7058
|
+
}
|
|
7059
|
+
/**
|
|
7060
|
+
* Writes the cells into every `Tilemap` under the roots whose `map` is the asset and has loaded.
|
|
7061
|
+
* Every tilemap's writes are checked before any is made.
|
|
7062
|
+
*
|
|
7063
|
+
* @param app - The scene view's app.
|
|
7064
|
+
* @param roots - The open scene's root entities.
|
|
7065
|
+
* @param params - The request.
|
|
7066
|
+
* @returns How many tilemaps were written and how many cells changed.
|
|
7067
|
+
* @throws InvalidParamsError when the layer or a cell does not fit a tilemap's document.
|
|
7068
|
+
*/
|
|
7069
|
+
function setTilemapCells(app, roots, params) {
|
|
7070
|
+
const type = componentTypeOf(app, TILEMAP_TYPE);
|
|
7071
|
+
if (type === null) return {
|
|
7072
|
+
tilemaps: 0,
|
|
7073
|
+
changed: 0
|
|
7074
|
+
};
|
|
7075
|
+
const planned = [];
|
|
7076
|
+
for (const root of roots) for (const component of root.getComponentsInChildren(type, true)) {
|
|
7077
|
+
const layers = isTilemapLike(component) ? component.definition?.layers : void 0;
|
|
7078
|
+
if (!isTilemapLike(component) || component.map?.address !== params.asset || layers === void 0) continue;
|
|
7079
|
+
const writes = planTileWrites(layers, params.layer, params.cells);
|
|
7080
|
+
if (typeof writes === "string") throw new InvalidParamsError(`setTilemapCells: ${params.asset}: ${writes}`);
|
|
7081
|
+
planned.push([component, writes]);
|
|
7082
|
+
}
|
|
7083
|
+
let changed = 0;
|
|
7084
|
+
for (const [tilemap, writes] of planned) changed += tilemap.setCells(writes);
|
|
7085
|
+
return {
|
|
7086
|
+
tilemaps: planned.length,
|
|
7087
|
+
changed
|
|
7088
|
+
};
|
|
7089
|
+
}
|
|
7090
|
+
//#endregion
|
|
6826
7091
|
//#region src/scene/scene-host.ts
|
|
6827
7092
|
/**
|
|
6828
7093
|
* The scene methods and notifications of protocol 0.3: what the scene view's host does with the
|
|
@@ -6830,6 +7095,13 @@ function frameCamera(camera, bounds) {
|
|
|
6830
7095
|
*/
|
|
6831
7096
|
/** The name of the host's persistent scene instance for its own objects. */
|
|
6832
7097
|
const EDITOR_SCENE_NAME = "editor";
|
|
7098
|
+
/** The colour of an editor line set that names none: a light green, as collider gizmos usually are. */
|
|
7099
|
+
const DEFAULT_LINE_COLOR = {
|
|
7100
|
+
r: .55,
|
|
7101
|
+
g: 1,
|
|
7102
|
+
b: .55,
|
|
7103
|
+
a: 1
|
|
7104
|
+
};
|
|
6833
7105
|
/** The editor camera's priority: above any camera a document can hold. */
|
|
6834
7106
|
const EDITOR_CAMERA_PRIORITY = 1e6;
|
|
6835
7107
|
/**
|
|
@@ -6870,6 +7142,10 @@ var SceneHost = class {
|
|
|
6870
7142
|
visible: true,
|
|
6871
7143
|
size: 1
|
|
6872
7144
|
};
|
|
7145
|
+
/** The editor's line sets, as `setEditorLines` last set them, by id; drawn once `#lines` exists. */
|
|
7146
|
+
#lineSets = /* @__PURE__ */ new Map();
|
|
7147
|
+
/** The line sets' meshes, once a canvas has an overlay (never headless). */
|
|
7148
|
+
#lines = null;
|
|
6873
7149
|
#drag;
|
|
6874
7150
|
#gameView = new GameView();
|
|
6875
7151
|
#thumbnails;
|
|
@@ -6906,6 +7182,7 @@ var SceneHost = class {
|
|
|
6906
7182
|
[SceneMethod.getColliderOutlines, (params) => this.#getColliderOutlines(params)],
|
|
6907
7183
|
[SceneMethod.sampleAnimation, (params) => this.#sampleAnimation(params)]
|
|
6908
7184
|
]);
|
|
7185
|
+
if (has(HostCapability.spriteAnimation)) methods.set(SceneMethod.sampleSpriteAnimation, (params) => this.#sampleSpriteAnimation(params));
|
|
6909
7186
|
if (has(HostCapability.gizmos)) methods.set(SceneMethod.setGizmo, (params) => this.#setGizmo(params));
|
|
6910
7187
|
if (has(HostCapability.screenshot)) methods.set(SceneMethod.screenshot, async (params) => this.#screenshot(params));
|
|
6911
7188
|
if (has(HostCapability.gameView)) {
|
|
@@ -6927,6 +7204,11 @@ var SceneHost = class {
|
|
|
6927
7204
|
return thumbnails.render(params);
|
|
6928
7205
|
});
|
|
6929
7206
|
if (has(HostCapability.grid)) methods.set(SceneMethod.setGrid, (params) => this.#setGrid(params));
|
|
7207
|
+
if (has(HostCapability.tilemapCells)) methods.set(SceneMethod.setTilemapCells, (params) => this.#setTilemapCells(params));
|
|
7208
|
+
if (has(HostCapability.editorLines)) {
|
|
7209
|
+
methods.set(SceneMethod.setEditorLines, (params) => this.#setEditorLines(params));
|
|
7210
|
+
methods.set(SceneMethod.clearEditorLines, (params) => this.#clearEditorLines(params));
|
|
7211
|
+
}
|
|
6930
7212
|
this.methods = new Map([...methods].map(([name, handler]) => [name, async (params) => this.#serial(() => handler(params))]));
|
|
6931
7213
|
}
|
|
6932
7214
|
/**
|
|
@@ -7013,6 +7295,12 @@ var SceneHost = class {
|
|
|
7013
7295
|
const { createEditorGrid } = await import("./grid.js");
|
|
7014
7296
|
this.#grid.view = createEditorGrid(app.lite, overlay);
|
|
7015
7297
|
}
|
|
7298
|
+
if (this.methods.has(SceneMethod.setEditorLines)) {
|
|
7299
|
+
const { createEditorLines } = await import("./editor-lines.js");
|
|
7300
|
+
const lines = createEditorLines(app.lite, overlay);
|
|
7301
|
+
for (const [id, set] of this.#lineSets) lines.set(id, set.lines, set.color);
|
|
7302
|
+
this.#lines = lines;
|
|
7303
|
+
}
|
|
7016
7304
|
const onClick = (click) => {
|
|
7017
7305
|
this.#onClick(click).catch((error) => {
|
|
7018
7306
|
const params = {
|
|
@@ -7150,6 +7438,8 @@ var SceneHost = class {
|
|
|
7150
7438
|
this.#grid.view?.dispose();
|
|
7151
7439
|
this.#grid.view = null;
|
|
7152
7440
|
}
|
|
7441
|
+
this.#lines?.dispose();
|
|
7442
|
+
this.#lines = null;
|
|
7153
7443
|
this.#view?.dispose();
|
|
7154
7444
|
this.#view = null;
|
|
7155
7445
|
this.#gameView.dispose();
|
|
@@ -7369,6 +7659,59 @@ var SceneHost = class {
|
|
|
7369
7659
|
return null;
|
|
7370
7660
|
}
|
|
7371
7661
|
/**
|
|
7662
|
+
* `setTilemapCells`: writes a tilemap editor's cells into the open scene's live tilemaps that
|
|
7663
|
+
* show the asset. The file on disk is the editor's to save.
|
|
7664
|
+
*
|
|
7665
|
+
* @param params - `{ asset, layer, cells }`.
|
|
7666
|
+
* @returns How many tilemaps were written and how many cells changed.
|
|
7667
|
+
*/
|
|
7668
|
+
#setTilemapCells(params) {
|
|
7669
|
+
const mirror = this.#requireMirror(SceneMethod.setTilemapCells);
|
|
7670
|
+
if (!isSetTilemapCellsParams(params)) throw new InvalidParamsError("setTilemapCells takes { asset: string, layer: string | number, cells: [index, tile, …] } of non-negative integers.");
|
|
7671
|
+
this.#requireOpen(SceneMethod.setTilemapCells);
|
|
7672
|
+
return setTilemapCells(this.#requireApp(), mirror.scene?.roots ?? [], params);
|
|
7673
|
+
}
|
|
7674
|
+
/**
|
|
7675
|
+
* `setEditorLines`: draws a set of the editor's world-space lines over the view, replacing the
|
|
7676
|
+
* set of the same id. Kept across scene opens; a page load starts with none.
|
|
7677
|
+
*
|
|
7678
|
+
* @param params - `{ id, lines, color? }`.
|
|
7679
|
+
* @returns `null`.
|
|
7680
|
+
*/
|
|
7681
|
+
#setEditorLines(params) {
|
|
7682
|
+
this.#requireMirror(SceneMethod.setEditorLines);
|
|
7683
|
+
if (!isSetEditorLinesParams(params)) throw new InvalidParamsError("setEditorLines takes { id: string, lines: number[] (six per segment), color?: [r, g, b, a?] from 0 to 1 }.");
|
|
7684
|
+
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.`);
|
|
7685
|
+
const [r = 0, g = 0, b = 0, a = 1] = params.color ?? [];
|
|
7686
|
+
const color = params.color === void 0 ? DEFAULT_LINE_COLOR : {
|
|
7687
|
+
r,
|
|
7688
|
+
g,
|
|
7689
|
+
b,
|
|
7690
|
+
a
|
|
7691
|
+
};
|
|
7692
|
+
this.#lineSets.set(params.id, {
|
|
7693
|
+
lines: params.lines,
|
|
7694
|
+
color
|
|
7695
|
+
});
|
|
7696
|
+
this.#lines?.set(params.id, params.lines, color);
|
|
7697
|
+
return null;
|
|
7698
|
+
}
|
|
7699
|
+
/**
|
|
7700
|
+
* `clearEditorLines`: removes one line set, or every set.
|
|
7701
|
+
*
|
|
7702
|
+
* @param params - `{ id? }`.
|
|
7703
|
+
* @returns `null`.
|
|
7704
|
+
*/
|
|
7705
|
+
#clearEditorLines(params) {
|
|
7706
|
+
this.#requireMirror(SceneMethod.clearEditorLines);
|
|
7707
|
+
if (!isClearEditorLinesParams(params)) throw new InvalidParamsError("clearEditorLines takes { id?: string }.");
|
|
7708
|
+
const id = params.id ?? null;
|
|
7709
|
+
if (id === null) this.#lineSets.clear();
|
|
7710
|
+
else this.#lineSets.delete(id);
|
|
7711
|
+
this.#lines?.clear(id);
|
|
7712
|
+
return null;
|
|
7713
|
+
}
|
|
7714
|
+
/**
|
|
7372
7715
|
* Where the grid draws this frame: on the ground under the 3D editor camera, or over the 2D view.
|
|
7373
7716
|
*
|
|
7374
7717
|
* @returns The placement, or `null` while the grid is hidden.
|
|
@@ -7407,6 +7750,17 @@ var SceneHost = class {
|
|
|
7407
7750
|
return sampleAnimation(this.#requireApp(), mirror, params);
|
|
7408
7751
|
}
|
|
7409
7752
|
/**
|
|
7753
|
+
* `sampleSpriteAnimation`: shows one frame of a clip on an entity's `SpriteAnimator`.
|
|
7754
|
+
*
|
|
7755
|
+
* @param params - `{ entity, clip, frame }` or `{ entity, clip, time }`.
|
|
7756
|
+
* @returns `{ posed }`.
|
|
7757
|
+
*/
|
|
7758
|
+
#sampleSpriteAnimation(params) {
|
|
7759
|
+
const mirror = this.#requireMirror(SceneMethod.sampleSpriteAnimation);
|
|
7760
|
+
this.#requireOpen(SceneMethod.sampleSpriteAnimation);
|
|
7761
|
+
return sampleSpriteAnimation(this.#requireApp(), mirror, params);
|
|
7762
|
+
}
|
|
7763
|
+
/**
|
|
7410
7764
|
* `setViewMode`: switches the view between the 3D editor camera and the 2D one. The first switch
|
|
7411
7765
|
* to 2D on a document starts where the level's own `Camera2D` looks, or frames the document.
|
|
7412
7766
|
*
|
|
@@ -7837,11 +8191,15 @@ async function startEditorHost(options) {
|
|
|
7837
8191
|
HostCapability.hotReloadDefaults,
|
|
7838
8192
|
HostCapability.gameView,
|
|
7839
8193
|
...canRenderThumbnails(options) ? [HostCapability.thumbnails] : [],
|
|
7840
|
-
HostCapability.grid
|
|
8194
|
+
HostCapability.grid,
|
|
8195
|
+
HostCapability.tilemapCells,
|
|
8196
|
+
HostCapability.editorLines,
|
|
8197
|
+
HostCapability.spriteAnimation
|
|
7841
8198
|
] : [
|
|
7842
8199
|
HostCapability.heartbeat,
|
|
7843
8200
|
HostCapability.logRelay,
|
|
7844
|
-
HostCapability.hotReloadDefaults
|
|
8201
|
+
HostCapability.hotReloadDefaults,
|
|
8202
|
+
HostCapability.spriteAnimation
|
|
7845
8203
|
];
|
|
7846
8204
|
let channel = null;
|
|
7847
8205
|
const scene = new SceneHost({
|
|
@@ -8671,6 +9029,6 @@ function listenForEditorPlayControls(options) {
|
|
|
8671
9029
|
};
|
|
8672
9030
|
}
|
|
8673
9031
|
//#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 };
|
|
9032
|
+
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
9033
|
|
|
8676
9034
|
//# sourceMappingURL=index.js.map
|