diff --git a/eslint.config.mjs b/eslint.config.mjs index 2d949c0..979c22a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -25,6 +25,7 @@ export default [ 'jsdoc/require-param': 'off', 'jsdoc/require-param-type': 'off', 'jsdoc/require-returns': 'off', + 'jsdoc/require-returns-type': 'off', 'no-use-before-define': 'off' } }, diff --git a/src/asset.ts b/src/asset.ts index cf0e55d..dd90e4b 100644 --- a/src/asset.ts +++ b/src/asset.ts @@ -9,14 +9,14 @@ import { globals as api } from './globals'; */ export type AssetObserver = Observer & { /** - * The history of changes made to the observer. + * The API asset associated with this observer. */ - history: ObserverHistory; + apiAsset: Asset; /** - * The API asset associated with this observer. + * The history of changes made to the observer. */ - apiAsset: Asset; + history: ObserverHistory; }; /** @@ -359,13 +359,13 @@ class Asset extends Events { /** * Constructor * - * @param {object} data - The asset data + * @param data - The asset data */ constructor(data: any = {}) { super(); // allow duplicate values in data.frameKeys of sprite asset - let options = null; + let options = {}; if (data.type === 'sprite') { options = { pathsWithDuplicates: ['data.frameKeys'] @@ -381,7 +381,7 @@ class Asset extends Events { path: [] }, data); - this._observer = new Observer(data, options || {}) as AssetObserver; + this._observer = new Observer(data, options) as AssetObserver; this._observer.apiAsset = this; this._observer.addEmitter(this); @@ -407,7 +407,7 @@ class Asset extends Events { this._history = {}; } - _initializeHistory() { + initializeHistory() { if (this._observer.history) return; this._history = new ObserverHistory({ @@ -419,7 +419,7 @@ class Asset extends Events { this._observer.history = this._history as ObserverHistory; } - _resetThumbnailUrls() { + private _resetThumbnailUrls() { const type = this.get('type') || ''; if (!type.startsWith('texture')) return; @@ -436,7 +436,7 @@ class Asset extends Events { } } - _onSet(path: string, value: any) { + private _onSet(path: string, value: any) { if (this._suspendOnSet || !path.startsWith('file') || path.endsWith('.url') || !this.get('file')) { return; } @@ -461,8 +461,8 @@ class Asset extends Events { /** * Checks if path exists. See the {@link Asset} overview for a full list of properties. * - * @param {string} path - The path - * @returns {boolean} True if path exists + * @param path - The path + * @returns True if path exists */ has(path: string) { return this._observer.has(path); @@ -471,8 +471,8 @@ class Asset extends Events { /** * Gets value at path. See the {@link Asset} overview for a full list of properties. * - * @param {string} path - The path - * @returns {any} The value + * @param path - The path + * @returns The value */ get(path: string) { return this._observer.get(path); @@ -481,9 +481,9 @@ class Asset extends Events { /** * Sets value at path. See the {@link Asset} overview for a full list of properties. * - * @param {string} path - The path - * @param {any} value - The value - * @returns {boolean} Whether the value was set + * @param path - The path + * @param value - The value + * @returns Whether the value was set */ set(path: string, value: any) { return this._observer.set(path, value); @@ -492,8 +492,8 @@ class Asset extends Events { /** * Unsets value at path. See the {@link Asset} overview for a full list of properties. * - * @param {string} path - The path - * @returns {boolean} Whether the value was unset + * @param path - The path + * @returns Whether the value was unset */ unset(path: string) { return this._observer.unset(path); @@ -503,10 +503,10 @@ class Asset extends Events { * Inserts value in array at path, at specified index. See the {@link Asset} overview for a * full list of properties. * - * @param {string} path - The path - * @param {any} value - The value - * @param {number} index - The index (if undefined the value will be inserted in the end) - * @returns {boolean} Whether the value was inserted + * @param path - The path + * @param value - The value + * @param index - The index (if undefined the value will be inserted in the end) + * @returns Whether the value was inserted */ insert(path: any, value: any, index: any) { return this._observer.insert(path, value, index); @@ -515,9 +515,9 @@ class Asset extends Events { /** * Remove value from array at path. See the {@link Asset} overview for a full list of properties. * - * @param {string} path - The path - * @param {any} value - The value - * @returns {boolean} Whether the value was removed + * @param path - The path + * @param value - The value + * @returns Whether the value was removed */ removeValue(path: any, value: any) { return this._observer.removeValue(path, value); @@ -526,7 +526,7 @@ class Asset extends Events { /** * Returns JSON representation of entity data * - * @returns {object} - The data + * @returns - The data */ json() { return this._observer.json(); @@ -535,7 +535,7 @@ class Asset extends Events { /** * Returns the latest version of the Asset from the Assets API. * - * @returns {Asset} The asset + * @returns The asset */ latest() { return api.assets.get(this._observer.get('id')); @@ -619,15 +619,14 @@ class Asset extends Events { /** * Creates an instance of this template asset. Assumes this asset is a template asset. * - * @param {Entity} parent - The parent entity - * @param {object} options - Options - * @param {number} options.index - The desired index under the parent to instantiate the template. - * @param {boolean} options.history - Whether to record a history action. - * @param {boolean} options.select - Whether to select the new entity. - * @param {object} options.extraData - Extra data passed to the backend. Used by the Editor on specific cases. - * @returns {Promise} The new entity. + * @param parent - The parent entity + * @param options.index - The desired index under the parent to instantiate the template. + * @param options.history - Whether to record a history action. + * @param options.select - Whether to select the new entity. + * @param options.extraData - Extra data passed to the backend. Used by the Editor on specific cases. + * @returns The new entity. */ - async instantiateTemplate(parent: Entity, options: any) { + async instantiateTemplate(parent: Entity, options: { index?: number, history?: boolean, select?: boolean, extraData?: object } = {}) { const entities = await api.assets.instantiateTemplates([this], parent, options); return entities[0]; } @@ -635,11 +634,10 @@ class Asset extends Events { /** * Replaces any references to this asset with references to the new asset specified. * - * @param {Asset} asset - The new asset. - * @param {object} options - Options. - * @param {boolean} options.history - Whether to record a history action. + * @param asset - The new asset. + * @param options.history - Whether to record a history action. */ - replace(asset: Asset, options: any = {}) { + replace(asset: Asset, options: { history?: boolean } = {}) { replace(this, asset, options); } @@ -652,19 +650,17 @@ class Asset extends Events { /** * Gets observer history for this asset. - * - * @type {ObserverHistory} */ get history() { - return this._history; + return this._history as ObserverHistory; } /** * Gets the file URL for an asset file. * - * @param {number} id - The asset id - * @param {string} filename - The desired filename - * @returns {string} The file URL + * @param id - The asset id + * @param filename - The desired filename + * @returns The file URL */ static getFileUrl(id: number, filename: string) { return `/api/assets/${id}/file/${encodeURIComponent(filename)}?branchId=${api.branchId}`; diff --git a/src/assets.ts b/src/assets.ts index 266de83..131bae1 100644 --- a/src/assets.ts +++ b/src/assets.ts @@ -1,16 +1,16 @@ import { Events, ObserverList } from '@playcanvas/observer'; -import { Asset } from './asset'; -import { createScript } from './assets/createScript'; -import { createTemplate } from './assets/createTemplate'; -import { instantiateTemplates } from './assets/instantiateTemplates'; +import { Asset, AssetObserver } from './asset'; +import { createScript } from './assets/create-script'; +import { createTemplate } from './assets/create-template'; +import { instantiateTemplates } from './assets/instantiate-templates'; import { uploadFile } from './assets/upload'; import { Entity } from './entity'; import { globals as api } from './globals'; /** * Arguments passed when uploading an asset file. */ -type AssetUploadArguments = { +export type AssetUploadArguments = { /** * The parent folder asset where the asset should be placed. */ @@ -70,7 +70,7 @@ type AssetUploadArguments = { /** * Import settings used when uploading a texture asset. */ -type TextureImportSettings = { +export type TextureImportSettings = { /** * Whether to resize the texture to power of 2. */ @@ -85,7 +85,7 @@ type TextureImportSettings = { /** * Import settings used when uploading a scene (fbx etc.). */ -type SceneImportSettings = { +export type SceneImportSettings = { /** * Whether to search for target assets to update throughout the whole project instead of just the same folder. Defaults to true. */ @@ -150,13 +150,13 @@ class Assets extends Events { private _assets: ObserverList; - private _parseScriptCallback: Function; + private _parseScriptCallback: (asset: Asset) => any; - private _defaultUploadCompletedCallback: Function; + private _defaultUploadCompletedCallback: (uploadId: number, asset: Asset) => any; - private _defaultUploadProgressCallback: Function; + private _defaultUploadProgressCallback: (uploadId: number, progress: number) => any; - private _defaultUploadErrorCallback: Function; + private _defaultUploadErrorCallback: (uploadId: number, error: Error) => any; private _uploadId: number; @@ -165,10 +165,9 @@ class Assets extends Events { /** * Constructor * - * @param {object} options - Options - * @param {boolean} options.autoSubscribe - Whether to auto subscribe to asset changes when assets are loaded. + * @param options.autoSubscribe - Whether to auto subscribe to asset changes when assets are loaded. */ - constructor(options: any = {}) { + constructor(options: { autoSubscribe?: boolean } = {}) { super(); this._uniqueIdToItemId = {}; @@ -207,7 +206,7 @@ class Assets extends Events { } } - _onMessengerAddAsset(data: { asset: { branchId: string; id: string; source: boolean; status: string; type: any; source_asset_id: string; createdAt: any; }; }) { + private _onMessengerAddAsset(data: { asset: { branchId: string; id: string; source: boolean; status: string; type: any; source_asset_id: string; createdAt: any; }; }) { if (data.asset.branchId !== api.branchId) return; const uniqueId = parseInt(data.asset.id, 10); @@ -239,14 +238,14 @@ class Assets extends Events { } } - _onMessengerDeleteAsset(data: { asset: { id: any; }; }) { + private _onMessengerDeleteAsset(data: { asset: { id: any; }; }) { const asset = this.getUnique(data.asset.id); if (asset) { this.remove(asset); } } - _onMessengerDeleteAssets(data: { assets: string | any[]; }) { + private _onMessengerDeleteAssets(data: { assets: string | any[]; }) { for (let i = 0; i < data.assets.length; i++) { const asset = this.getUnique(parseInt(data.assets[i], 10)); if (asset) { @@ -258,10 +257,10 @@ class Assets extends Events { /** * Gets asset by id * - * @param {number} id - The asset id - * @returns {Asset} The asset + * @param id - The asset id + * @returns The asset */ - get(id: number) { + get(id: number): Asset | null { const a = this._assets.get(id); return a ? a.apiAsset : null; } @@ -269,10 +268,10 @@ class Assets extends Events { /** * Gets asset by its unique id * - * @param {number} uniqueId - The unique id - * @returns {Asset} The asset + * @param uniqueId - The unique id + * @returns The asset */ - getUnique(uniqueId: number) { + getUnique(uniqueId: number): Asset | null { const id = this._uniqueIdToItemId[uniqueId]; return id ? this.get(id) : null; } @@ -280,18 +279,18 @@ class Assets extends Events { /** * Returns array of all assets * - * @returns {Asset[]} The assets + * @returns The assets */ list() { - return this._assets.array().map((a: { apiAsset: any; }) => a.apiAsset); + return this._assets.array().map((a: AssetObserver) => a.apiAsset); } /** * Finds all assets with specified tags * - * @param {...string|...string[]} tags - The tags. If multiple tags are specified then assets that contain ANY of the specified + * @param tags - The tags. If multiple tags are specified then assets that contain ANY of the specified * tags will be included. If an argument is an array of tags then assets that contain ALL of the tags in the array will be included. - * @returns {Asset[]} The assets + * @returns The assets */ listByTag(...tags: any[]) { return this.filter((asset: Asset) => { @@ -325,10 +324,10 @@ class Assets extends Events { * Adds asset to the list * * @category Internal - * @param {Asset} asset - The asset + * @param asset - The asset */ add(asset: Asset) { - asset._initializeHistory(); + asset.initializeHistory(); const pos = this._assets.add(asset.observer); if (pos === null) return; @@ -381,7 +380,7 @@ class Assets extends Events { * Removes asset from the list * * @category Internal - * @param {Asset} asset - The asset + * @param asset - The asset */ remove(asset: Asset) { if (!this._assets.has(asset.observer)) return; @@ -421,8 +420,8 @@ class Assets extends Events { /** * Gets assets that satisfy function * - * @param {Function} fn - The function (takes an asset as an argument and returns boolean). - * @returns {Asset[]} The assets + * @param fn - The function (takes an asset as an argument and returns boolean). + * @returns The assets */ filter(fn: Function) { return this._assets.data @@ -433,8 +432,8 @@ class Assets extends Events { /** * Finds first asset that satisfies function * - * @param {Function} fn - A function that takes an asset as an argument and returns boolean. - * @returns {Asset} The asset + * @param fn - A function that takes an asset as an argument and returns boolean. + * @returns The asset */ findOne(fn: Function) { const result = this._assets.data.find((observer: { apiAsset: any; }) => fn(observer.apiAsset)); @@ -446,11 +445,10 @@ class Assets extends Events { * subscribe to realtime changes. * * @category Internal - * @param {object} options - Options - * @param {string} options.view - The desired view for the REST API e.g 'designer', 'shader-editor'. This might limit + * @param options.view - The desired view for the REST API e.g 'designer', 'shader-editor'. This might limit * the assets returned to a smaller subset depending on the view. */ - async loadAll(options: any = {}) { + async loadAll(options: { view?: string } = {}) { this.clear(); this.emit('load:progress', 0.1); @@ -498,12 +496,11 @@ class Assets extends Events { * Loads all assets in the current project / branch * and subscribes to changes. * - * @param {object} options - Options - * @param {string} options.view - The desired view for the REST API e.g 'designer', 'shader-editor'. This might limit + * @param options.view - The desired view for the REST API e.g 'designer', 'shader-editor'. This might limit * the assets returned to a smaller subset depending on the view. * @category Internal */ - async loadAllAndSubscribe(options: any = {}) { + async loadAllAndSubscribe(options: { view?: string } = {}) { this.clear(); this.emit('load:progress', 0.1); @@ -558,8 +555,8 @@ class Assets extends Events { /** * Gets the first script asset that contains the specified script * - * @param {string} script - The script name - * @returns {Asset} The script asset + * @param script - The script name + * @returns The script asset */ getAssetForScript(script: string) { return this.findOne((asset: Asset) => { @@ -571,11 +568,10 @@ class Assets extends Events { /** * Creates new asset * - * @private - * @param {AssetUploadArguments} data - The asset fields - * @param {TextureImportSettings|SceneImportSettings|} settings - Import settings - * @param {Function} onProgress - Function to report progress - * @returns {Promise} The new asset + * @param data - The asset fields + * @param settings - Import settings + * @param onProgress - Function to report progress + * @returns The new asset */ async upload(data: AssetUploadArguments, settings: TextureImportSettings | SceneImportSettings = {}, onProgress: Function | null = null) { if (data.folder) { @@ -617,15 +613,14 @@ class Assets extends Events { /** * Creates new anim state graph asset. * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {object} options.data - The asset data. See {@link Asset} for Animstategraph data. - * @param {Asset} options.folder - The parent folder asset - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.data - The asset data. See {@link Asset} for Animstategraph data. + * @param options.folder - The parent folder asset + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createAnimStateGraph(options: any) { + createAnimStateGraph(options: { name?: string; preload?: boolean; data?: object; folder?: Asset; onProgress?: Function; } = {}) { return this.upload({ name: options.name || 'New Anim State Graph', type: 'animstategraph', @@ -638,15 +633,14 @@ class Assets extends Events { /** * Creates new bundle asset * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {Asset[]} options.assets - The assets that the bundle will contain - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.assets - The assets that the bundle will contain + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createBundle(options: any) { + createBundle(options: { name?: string; assets?: any[]; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { return this.upload({ name: options.name || 'New Bundle', type: 'bundle', @@ -661,15 +655,14 @@ class Assets extends Events { /** * Creates new CSS asset * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {string} options.text - The CSS - * @param {string} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.text - The CSS + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createCss(options: any) { + createCss(options: { name?: string; text?: string; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { return this.upload({ name: options.name || 'New Css', type: 'css', @@ -683,19 +676,18 @@ class Assets extends Events { /** * Creates new cubemap asset * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {Asset[]} options.textures - The textures for each cubemap face in this order: + * @param options.name - The asset name + * @param options.textures - The textures for each cubemap face in this order: * right, left, up, down, front, back - * @param {number} options.minFilter - Cubemap minFilter value. Defaults to pc.FILTER_LINEAR_MIPMAP_LINEAR. - * @param {number} options.magFilter - Cubemap magFilter value. Defaults to pc.FILTER_LINEAR. - * @param {number} options.anisotropy - Cubemap anisotropy value. Defaults to 1. - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.minFilter - Cubemap minFilter value. Defaults to pc.FILTER_LINEAR_MIPMAP_LINEAR. + * @param options.magFilter - Cubemap magFilter value. Defaults to pc.FILTER_LINEAR. + * @param options.anisotropy - Cubemap anisotropy value. Defaults to 1. + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createCubemap(options: any) { + createCubemap(options: { name?: string; textures?: any[]; minFilter?: number; magFilter?: number; anisotropy?: number; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { const textures = (options.textures || new Array(6)).slice(0, 6); for (let i = 0; i < 6; i++) { textures[i] = (textures[i] ? textures[i].get('id') : null); @@ -719,13 +711,12 @@ class Assets extends Events { /** * Creates a new folder asset * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {Asset} options.folder - The parent folder asset - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.folder - The parent folder asset + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createFolder(options: any) { + createFolder(options: { name?: string; folder?: Asset; onProgress?: Function; }) { return this.upload({ name: options.name || 'New Folder', type: 'folder', @@ -736,15 +727,14 @@ class Assets extends Events { /** * Creates new HTML asset * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {string} options.text - The HTML - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.text - The HTML + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createHtml(options: any) { + createHtml(options: { name?: string; text?: string; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { return this.upload({ name: options.name || 'New Html', type: 'html', @@ -758,17 +748,16 @@ class Assets extends Events { /** * Creates new JSON asset * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {object} options.json - The JSON - * @param {number} options.spaces - The number of spaces used for indentation. Defaults to 0 + * @param options.name - The asset name + * @param options.json - The JSON + * @param options.spaces - The number of spaces used for indentation. Defaults to 0 * (tightly packed output). - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createJson(options: any) { + createJson(options: { name?: string; json?: object; spaces?: number; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { const spaces = options.spaces ?? 0; const str = JSON.stringify(options.json || {}, null, spaces); @@ -785,15 +774,14 @@ class Assets extends Events { /** * Creates new localization JSON asset * - * @param {object} options - The options - * @param {string} options.name - The asset name - * @param {object} options.localizationData - The localization data. If null then default data will be used. - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.localizationData - The localization data. If null then default data will be used. + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createI18n(options: any) { + createI18n(options: { name?: string; localizationData?: object; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { return this.createJson({ name: options.name, json: options.localizationData || { @@ -820,15 +808,14 @@ class Assets extends Events { /** * Creates new material asset * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {object} options.data - The material data. Default values will be used for missing fields. See {@link Asset} for material data. - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.data - The material data. Default values will be used for missing fields. See {@link Asset} for material data. + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createMaterial(options: any) { + createMaterial(options: { name?: string; data?: Record; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { const defaultData = api.schema.assets.getDefaultData('material') as any; if (options.data) { for (const key in defaultData) { @@ -850,17 +837,16 @@ class Assets extends Events { /** * Creates new script asset * - * @param {object} options - Options - * @param {string} options.filename - The filename of the script. This will also be the name of the script asset. If not defined it will be generated + * @param options.filename - The filename of the script. This will also be the name of the script asset. If not defined it will be generated * from the name of the script. - * @param {string} options.text - The contents of the script. If none then boilerplate code will be used. - * @param {object} options.data - The script data. See {@link Asset} for Script data. - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.text - The contents of the script. If none then boilerplate code will be used. + * @param options.data - The script data. See {@link Asset} for Script data. + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - async createScript(options: any) { + async createScript(options: { filename?: string; text?: string; data?: object; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { if (!options.filename) { throw new Error('createScript: missing required filename'); } @@ -912,15 +898,14 @@ class Assets extends Events { /** * Creates new shader asset * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {string} options.text - The GLSL - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.text - The GLSL + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createShader(options: any) { + createShader(options: { name?: string; text?: string; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { return this.upload({ name: options.name || 'New Shader', type: 'shader', @@ -934,18 +919,17 @@ class Assets extends Events { /** * Creates new sprite asset * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {number} options.pixelsPerUnit - The sprite's pixels per unit value. Defaults to 100. - * @param {number[]} options.frameKeys - The sprite's frame keys - * @param {Asset} options.textureAtlas - The sprite's texture atlas asset - * @param {number} options.renderMode - The sprite's render mode. Defaults to pc.SPRITE_RENDERMODE_SIMPLE. - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.pixelsPerUnit - The sprite's pixels per unit value. Defaults to 100. + * @param options.frameKeys - The sprite's frame keys + * @param options.textureAtlas - The sprite's texture atlas asset + * @param options.renderMode - The sprite's render mode. Defaults to pc.SPRITE_RENDERMODE_SIMPLE. + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createSprite(options: any) { + createSprite(options: { name?: string; pixelsPerUnit?: number; frameKeys?: any[]; textureAtlas?: Asset; renderMode?: number; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { const data: any = {}; data.pixelsPerUnit = options.pixelsPerUnit !== undefined ? options.pixelsPerUnit : 100; data.frameKeys = options.frameKeys ? options.frameKeys.map((val: any) => val.toString()) : []; @@ -964,15 +948,14 @@ class Assets extends Events { /** * Creates new text asset * - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {string} options.text - The text - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.text - The text + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - createText(options: any) { + createText(options: { name?: string; text?: string; folder?: Asset; preload?: boolean; onProgress?: Function; } = {}) { return this.upload({ name: options.name || 'New Text', type: 'text', @@ -986,16 +969,14 @@ class Assets extends Events { /** * Creates new template asset * - * @typedef {import("./entity").Entity} Entity - * @param {object} options - Options - * @param {string} options.name - The asset name - * @param {Entity} options.entity - The entity to create the template from - * @param {Asset} options.folder - The parent folder asset - * @param {boolean} options.preload - Whether to preload the asset. Defaults to true. - * @param {Function} options.onProgress - Function to report progress - * @returns {Promise} The new asset + * @param options.name - The asset name + * @param options.entity - The entity to create the template from + * @param options.folder - The parent folder asset + * @param options.preload - Whether to preload the asset. Defaults to true. + * @param options.onProgress - Function to report progress + * @returns The new asset */ - async createTemplate(options: any) { + async createTemplate(options: { name?: string; entity: Entity; folder?: Asset; preload?: boolean; onProgress?: Function; }) { const { entities, oldToNewIds @@ -1019,7 +1000,7 @@ class Assets extends Events { /** * Deletes specified assets * - * @param {Asset[]} assets - The assets + * @param assets - The assets */ async delete(assets: Asset[]) { const response = await fetch('/api/assets', { @@ -1044,24 +1025,25 @@ class Assets extends Events { * Instantiates the specified template assets under the specified * parent entity. * - * @param {Asset[]} assets - The template assets. - * @param {Entity} parent - The parent entity - * @param {object} options - Options - * @param {number} options.index - The desired index under the parent to instantiate the templates. - * @param {boolean} options.history - Whether to record a history action. - * @param {boolean} options.select - Whether to select the new entities. - * @param {object} options.extraData - Extra data passed to the backend. Used by the Editor on specific cases. - * @returns {Promise} The new entities + * @param assets - The template assets. + * @param parent - The parent entity + * @param options.index - The desired index under the parent to instantiate the templates. + * @param options.history - Whether to record a history action. + * @param options.select - Whether to select the new entities. + * @param options.extraData - Extra data passed to the backend. Used by the Editor on specific cases. + * @returns The new entities */ - instantiateTemplates(assets: Asset[], parent: Entity, options = {}) { + instantiateTemplates(assets: Asset[], parent: Entity, options: { index?: number; history?: boolean; select?: boolean; extraData?: object; } = {}) { return instantiateTemplates(assets, parent, options); } + get raw() { + return this._assets; + } + /** * Sets the default callback called when on asset upload succeeds. * The function takes 2 arguments: the upload id, and the new asset. - * - * @type {Function} */ set defaultUploadCompletedCallback(value) { this._defaultUploadCompletedCallback = value; @@ -1069,8 +1051,6 @@ class Assets extends Events { /** * Gets the default callback called when on asset upload succeeds. - * - * @type {Function} */ get defaultUploadCompletedCallback() { return this._defaultUploadCompletedCallback; @@ -1079,8 +1059,6 @@ class Assets extends Events { /** * Sets the default callback called when on asset upload progress. * The function takes 2 arguments: the upload id and the progress. - * - * @type {Function} */ set defaultUploadProgressCallback(value) { this._defaultUploadProgressCallback = value; @@ -1088,8 +1066,6 @@ class Assets extends Events { /** * Gets the default callback called when on asset upload progress. - * - * @type {Function} */ get defaultUploadProgressCallback() { return this._defaultUploadProgressCallback; @@ -1098,8 +1074,6 @@ class Assets extends Events { /** * Sets the default callback called when on asset upload progress. * The function takes 2 arguments: the upload id, and the error. - * - * @type {Function} */ set defaultUploadErrorCallback(value) { this._defaultUploadErrorCallback = value; @@ -1107,8 +1081,6 @@ class Assets extends Events { /** * Gets the default callback called when on asset upload fails. - * - * @type {Function} */ get defaultUploadErrorCallback() { return this._defaultUploadErrorCallback; @@ -1119,8 +1091,6 @@ class Assets extends Events { * callback is set, new script assets will be parsed after they * are created. The function takes the asset as a parameter and returns * a promise with a list of script names when it is done parsing. - * - * @type {Function} */ set parseScriptCallback(value) { this._parseScriptCallback = value; @@ -1128,8 +1098,6 @@ class Assets extends Events { /** * Gets the callback which parses script assets. - * - * @type {Function} */ get parseScriptCallback() { return this._parseScriptCallback; diff --git a/src/assets/createScript.ts b/src/assets/create-script.ts similarity index 95% rename from src/assets/createScript.ts rename to src/assets/create-script.ts index 52ec27b..a76bd2f 100644 --- a/src/assets/createScript.ts +++ b/src/assets/create-script.ts @@ -10,9 +10,9 @@ const validExtensions = Array.from(extensionToBoilerplateMap.keys()); * Creates filename and script content from provided arguments. If the provide filename contains a '.mjs' * suffix, it will generate an ESM based class syntax. * - * @param {string} filename - The desired filename. - * @param {string} text - The desired contents of the script. If not provided boilerplate code will be used. - * @returns {object} The filename and content of the script + * @param filename - The desired filename. + * @param text - The desired contents of the script. If not provided boilerplate code will be used. + * @returns The filename and content of the script */ function createScript(filename: string, text: string) { let className = ''; diff --git a/src/assets/createTemplate.ts b/src/assets/create-template.ts similarity index 100% rename from src/assets/createTemplate.ts rename to src/assets/create-template.ts diff --git a/src/assets/instantiateTemplates.ts b/src/assets/instantiate-templates.ts similarity index 93% rename from src/assets/instantiateTemplates.ts rename to src/assets/instantiate-templates.ts index 45e2b10..ebff4f1 100644 --- a/src/assets/instantiateTemplates.ts +++ b/src/assets/instantiate-templates.ts @@ -1,9 +1,10 @@ import { Asset } from '../asset'; +import { Entity } from '../entity'; import { globals as api } from '../globals'; let evtMessenger: any; -async function instantiateTemplates(assets: Asset[], parent: any, options: any) { +async function instantiateTemplates(assets: Asset[], parent: any, options: { index?: number, extraData?: any, history?: boolean, select?: boolean } = {}) { parent = parent || api.entities.root; if (!parent) { throw new Error('Invalid parent'); @@ -15,7 +16,7 @@ async function instantiateTemplates(assets: Asset[], parent: any, options: any) reject: null }; - const promise = new Promise((resolve, reject) => { + const promise = new Promise((resolve, reject) => { deferred.resolve = resolve; deferred.reject = reject; }); @@ -63,7 +64,7 @@ async function instantiateTemplates(assets: Asset[], parent: any, options: any) } }); - let entities = await promise as any; + let entities = await promise; // record history action if (api.history && (options.history || options.history === undefined)) { diff --git a/src/assets/replace.ts b/src/assets/replace.ts index bba5c12..b58dd39 100644 --- a/src/assets/replace.ts +++ b/src/assets/replace.ts @@ -139,7 +139,7 @@ function replaceSceneSettingsRefs(oldAsset: Asset, newAsset: Asset) { return records; } -function replace(oldAsset: Asset, newAsset: Asset, options: any) { +function replace(oldAsset: Asset, newAsset: Asset, options: { history?: boolean } = {}) { options = options || {}; if (options.history === undefined) { options.history = true; diff --git a/src/assets/upload.ts b/src/assets/upload.ts index 561ecf8..e62bd28 100644 --- a/src/assets/upload.ts +++ b/src/assets/upload.ts @@ -78,10 +78,10 @@ function appendCreateFields(form: FormData, data: any) { * Uploads an asset file in order to create a new asset * or update an existing asset. * - * @param {object} data - The data - * @param {object} settings - Import settings - * @param {Function} onProgress - Progress function - * @returns {object} The JSON response from the server + * @param data - The data + * @param settings - Import settings + * @param onProgress - Progress function + * @returns The JSON response from the server */ async function uploadFile(data: Record, settings: object = null, onProgress: Function = null) { let method; diff --git a/src/clipboard.ts b/src/clipboard.ts index 99c9acb..f70fcfe 100644 --- a/src/clipboard.ts +++ b/src/clipboard.ts @@ -14,7 +14,7 @@ class Clipboard { /** * Constructor * - * @param {string} name - The name of the clipboard. + * @param name - The name of the clipboard. */ constructor(name: string) { this._name = name; @@ -24,8 +24,6 @@ class Clipboard { /** * Gets whether the clipboard is empty - * - * @type {boolean} */ get empty() { return !this._storage.has(this._name); @@ -33,8 +31,6 @@ class Clipboard { /** * Sets the value to be stored in the clipboard. Pass null to clear the value from storage. - * - * @type {object | string} */ set value(value: object | string) { if (value !== null) { @@ -46,11 +42,9 @@ class Clipboard { /** * Gets the value stored in the clipboard. - * - * @type {object | string} */ get value() { - return this._storage.get(this._name); + return this._storage.get(this._name) as (object | string); } } diff --git a/src/entities.ts b/src/entities.ts index 9a5e782..a270831 100644 --- a/src/entities.ts +++ b/src/entities.ts @@ -113,14 +113,14 @@ class Entities extends Events { /** * Gets entity by resource id * - * @param {string} id - The entity's resource id - * @returns {Entity} The entity + * @param id - The entity's resource id + * @returns The entity * @example * ```javascript * const entity = editor.entities.get(resourceId); * ``` */ - get(id: string) { + get(id: string): Entity | null { const e = this._entities.get(id); return e ? e.apiEntity : null; } @@ -128,7 +128,7 @@ class Entities extends Events { /** * Returns array of all entities * - * @returns {Entity[]} The entities + * @returns The entities * @example * ```javascript * const entities = editor.entities.list(); @@ -143,7 +143,7 @@ class Entities extends Events { * Adds entity to list * * @category Internal - * @param {Entity} entity - The entity + * @param entity - The entity */ add(entity: Entity) { const id = entity.get('resource_id'); @@ -171,7 +171,7 @@ class Entities extends Events { * Called when an entity is added from the server * * @category Internal - * @param {object} entityData - The entity data + * @param entityData - The entity data */ serverAdd(entityData: { parent: Entity, children: Entity[] }) { const entity = new Entity(entityData as object); @@ -184,8 +184,8 @@ class Entities extends Events { * Removes entity from the list * * @category Internal - * @param {Entity} entity - The entity - * @param {object} entityReferences - A map of entity references to nullify + * @param entity - The entity + * @param entityReferences - A map of entity references to nullify * when this entity is removed */ remove(entity: Entity, entityReferences: object = null) { @@ -235,7 +235,7 @@ class Entities extends Events { * Called when an entity is removed from the server * * @category Internal - * @param {Entity} entity - The entity + * @param entity - The entity */ serverRemove(entity: Entity) { if (api.selection && api.selection.has(entity)) { @@ -284,12 +284,11 @@ class Entities extends Events { /** * Creates new entity and adds it to the hierarchy * - * @param {CreateEntityArguments} data - Initial data for the entity - * @param {object} options - Options - * @param {number} options.index - The child index that this entity will have under its parent. - * @param {boolean} options.history - Whether to record a history action. Defaults to true. - * @param {boolean} options.select - Whether to select new Entity. Defaults to false. - * @returns {Entity} The new entity + * @param data - Initial data for the entity + * @param options.index - The child index that this entity will have under its parent. + * @param options.history - Whether to record a history action. Defaults to true. + * @param options.select - Whether to select new Entity. Defaults to false. + * @returns The new entity * * @example * ```javascript @@ -303,33 +302,31 @@ class Entities extends Events { * }); *``` */ - create(data: CreateEntityArguments = null, options: any = {}) { + create(data: CreateEntityArguments = null, options: { index?: number, history?: boolean, select?: boolean } = {}) { return createEntity(data, options); } /** * Delete specified entities * - * @param {Entity[]|Entity} entities - The entities - * @param {object} options - Options - * @param {boolean} options.history - Whether to record a history action. Defaults to true. + * @param entities - The entities + * @param options.history - Whether to record a history action. Defaults to true. * * @example * ```javascript * await editor.entities.delete([entity1, entity2]); * ``` */ - async delete(entities: Entity[] | Entity, options: any = {}) { + async delete(entities: Entity[] | Entity, options: { history?: boolean } = {}) { await deleteEntities(entities, options); } /** * Reparents entities under new parent. * - * @param {ReparentArguments[]} data - The reparenting data - * @param {object} options - Options - * @param {boolean} options.preserveTransform - Whether to preserve the transform of the entities. Defaults to false. - * @param {boolean} options.history - Whether to record history. Defaults to true + * @param data - The reparenting data + * @param options.preserveTransform - Whether to preserve the transform of the entities. Defaults to false. + * @param options.history - Whether to record history. Defaults to true * @example * ```javascript * const child = editor.entities.create(); @@ -340,23 +337,22 @@ class Entities extends Events { * }]) * ``` */ - reparent(data: ReparentArguments[], options: any = {}) { + reparent(data: ReparentArguments[], options: { preserveTransform?: boolean, history?: boolean } = {}) { reparentEntities(data, options); } /** * Duplicates the specified entities under the same parent * - * @param {Entity[]} entities - The entities - * @param {object} [options] - Options - * @param {boolean} [options.history] - Whether to record a history action. Defaults to true. - * @param {boolean} [options.select] - Whether to select the new entities. Defaults to false. - * @param {boolean} [options.rename] - Whether to rename the duplicated entities. Defaults to false. - * @returns {Promise} The duplicated entities + * @param entities - The entities + * @param options.history - Whether to record a history action. Defaults to true. + * @param options.select - Whether to select the new entities. Defaults to false. + * @param options.rename - Whether to rename the duplicated entities. Defaults to false. + * @returns The duplicated entities * @example * const duplicated = await editor.entities.duplicate(entities); */ - async duplicate(entities: Entity[], options: any = {}) { + async duplicate(entities: Entity[], options: { history?: boolean, select?: boolean, rename?: boolean } = {}) { const result = await duplicateEntities(entities, options); return result; @@ -366,7 +362,7 @@ class Entities extends Events { * Copy specified entities to localStorage clipboard. Can be used * to paste these entities later on. * - * @param {Entity[]} entities - The entities + * @param entities - The entities */ copyToClipboard(entities: Entity[]) { copyEntities(entities); @@ -376,12 +372,11 @@ class Entities extends Events { * Paste entities copied into clipboard * under the specified parent. * - * @param {Entity} parent - The parent - * @param {object} options - Options - * @param {boolean} options.history - Whether to record a history action. Defaults to true. - * @returns {Promise} The new entities + * @param parent - The parent + * @param options.history - Whether to record a history action. Defaults to true. + * @returns The new entities */ - pasteFromClipboard(parent: Entity, options: any = {}) { + pasteFromClipboard(parent: Entity, options: { history?: boolean } = {}) { return pasteEntities(parent, options); } @@ -389,11 +384,11 @@ class Entities extends Events { * Waits for specified entity ids to be added to the scene. * Once they are the callback is called with the entities as its argument. * - * @param {string[]} entityIds - The ids of the entities to wait for - * @param {number} timeoutMs - Number of ms to wait before stopping to wait - * @param {Function} callback - The callback to call when all entities have been added. + * @param entityIds - The ids of the entities to wait for + * @param timeoutMs - Number of ms to wait before stopping to wait + * @param callback - The callback to call when all entities have been added. * The signature is (Entity[]) => void. - * @returns {Function} Returns a cancel function which can be called to cancel calling the + * @returns Returns a cancel function which can be called to cancel calling the * callback when the entities are added. */ waitToExist(entityIds: string[], timeoutMs: number, callback: (entities: Entity[]) => void) { @@ -404,17 +399,16 @@ class Entities extends Events { * Like {@link Entity.addScript} but works on multiple entities using * a single history action. * - * @param {Entity[]} entities - The entities. - * @param {string} scriptName - The name of the script. - * @param {object} options - Options - * @param {object} options.attributes - The values of attributes. Each key is the name + * @param entities - The entities. + * @param scriptName - The name of the script. + * @param options.attributes - The values of attributes. Each key is the name * of the attributes and each value is the value for that attribute. Leave undefined to * let the Editor set default values depending on the attribute types. - * @param {boolean} options.history - Whether to add a history action. Defaults to true. - * @param {number} options.index - The desired index in the entity's scripts order to add this script. - * @returns {Promise<>} A promise + * @param options.history - Whether to add a history action. Defaults to true. + * @param options.index - The desired index in the entity's scripts order to add this script. + * @returns A promise */ - addScript(entities: Entity[], scriptName: string, options: any = {}) { + addScript(entities: Entity[], scriptName: string, options: { attributes?: object, history?: boolean, index?: number } = {}) { return addScript(entities, scriptName, options); } @@ -422,17 +416,19 @@ class Entities extends Events { * Like {@link Entity.removeScript} but works on multiple entities using * a single history action. * - * @param {Entity[]} entities - The entities. - * @param {string} scriptName - The name of the script. - * @param {object} options - Options - * @param {boolean} options.history - Whether to record a history action. Defaults to true. + * @param entities - The entities. + * @param scriptName - The name of the script. + * @param options.history - Whether to record a history action. Defaults to true. */ - removeScript(entities: Entity[], scriptName: string, options: any = {}) { + removeScript(entities: Entity[], scriptName: string, options: { history?: boolean } = {}) { removeScript(entities, scriptName, options); } + get raw() { + return this._entities; + } + /** - * @type {Entity} * Gets the root Entity */ get root() { diff --git a/src/entities/copy.ts b/src/entities/copy.ts index 29b8a27..7dcf061 100644 --- a/src/entities/copy.ts +++ b/src/entities/copy.ts @@ -8,8 +8,8 @@ const REGEX_CONTAINS_STAR = /\.\*\./; * Stores asset paths in the assets dictionary by converting the array of * folder ids to an array of folder names. * - * @param {number[]} assetIds - The asset ids - * @param {object} assets - The assets dictionary + * @param assetIds - The asset ids + * @param assets - The assets dictionary */ function storeAssetPaths(assetIds: number[], assets: Record) { if (!Array.isArray(assetIds)) { @@ -47,8 +47,8 @@ function storeAssetPaths(assetIds: number[], assets: Record) { /** * Gathers all asset dependencies for this entity * - * @param {Entity} entity - The entity - * @param {object} data - The helper data + * @param entity - The entity + * @param data - The helper data */ function gatherDependencies(entity: Entity, data: Record) { if (!ASSET_PATHS) { @@ -213,7 +213,7 @@ function sortEntities(entities: Entity[]) { * Copy specified entities to localStorage clipboard. Can be used * to paste these entities later on. * - * @param {Entity[]} entities - The entities + * @param entities - The entities */ function copyEntities(entities: Entity[]) { const currentScene = api.realtime?.scenes?.current; diff --git a/src/entities/create.ts b/src/entities/create.ts index 0524b5d..4b54a39 100644 --- a/src/entities/create.ts +++ b/src/entities/create.ts @@ -4,16 +4,13 @@ import { globals as api } from '../globals'; /** * Creates new entity and adds it to the hierarchy * - * @private - * @typedef {import("../entities").Entities} Entities - * @param {object} [data] - Optional initial data for the entity - * @param {object} [options] - Options - * @param {number} [options.index] - The child index that this entity will have under its parent. - * @param {boolean} [options.history] - Whether to record a history action. Defaults to true. - * @param {boolean} [options.select] - Whether to select new Entity. Defaults to false. - * @returns {Entity} The new entity + * @param data - Optional initial data for the entity + * @param options.index - The child index that this entity will have under its parent. + * @param options.history - Whether to record a history action. Defaults to true. + * @param options.select - Whether to select new Entity. Defaults to false. + * @returns The new entity */ -function createEntity(data: any, options: any = {}): Entity { +function createEntity(data: any, options: { index?: number, history?: boolean, select?: boolean } = {}): Entity { data = data || {}; if (options.history === undefined) { diff --git a/src/entities/delete.ts b/src/entities/delete.ts index c95ae3a..a4dca0d 100644 --- a/src/entities/delete.ts +++ b/src/entities/delete.ts @@ -75,14 +75,11 @@ function rememberPrevious(entities: any[]) { /** * Delete specified entities * - * @private - * @typedef {import("../entity").Entity} Entity - * @param {Entity[]|Entity} entities - The entities - * @param {object} [options] - Options - * @param {boolean} [options.history] - Whether to record a history action. Defaults to true. - * @param {boolean} [options.waitSubmitted] - Whether to wait till ops submitted. + * @param entities - The entities + * @param options.history - Whether to record a history action. Defaults to true. + * @param options.waitSubmitted - Whether to wait till ops submitted. */ -async function deleteEntities(entities: Entity[] | Entity, options: any = {}) { +async function deleteEntities(entities: Entity[] | Entity, options: { history?: boolean; waitSubmitted?: boolean } = {}) { if (options.history === undefined) { options.history = true; } diff --git a/src/entities/duplicate.ts b/src/entities/duplicate.ts index 2148614..27458e9 100644 --- a/src/entities/duplicate.ts +++ b/src/entities/duplicate.ts @@ -15,10 +15,9 @@ const USE_BACKEND_LIMIT = 500; * within its subtree is duplicated, update the references to the corresponding entities within * the newly created duplicate subtree. * - * @private - * @param {Entity} newEntity - The new (duplicated) entity - * @param {Entity} oldEntity - The old entity - * @param {object} duplicatedIdsMap - Map of old id -> new id + * @param newEntity - The new (duplicated) entity + * @param oldEntity - The old entity + * @param duplicatedIdsMap - Map of old id -> new id */ function updateDuplicatedEntityReferences(newEntity: Entity, oldEntity: Entity, duplicatedIdsMap: Record) { // remap template_ent_ids for template instances @@ -110,13 +109,12 @@ function getUniqueNameForDuplicatedEntity(entityName: string, entities: Entity[] /** * Duplicates an entity in the scene * - * @private - * @param {Entity} entity - The entity - * @param {Entity} parent - The parent of the new entity - * @param {number} ind - The index in the parent's children array where we want to insert the new entity - * @param {object} duplicatedIdsMap - A guid->guid map that contains references from the source resource ids to the new resource ids - * @param {boolean} useUniqueName - Controls whether duplicated entity will have a unique name - * @returns {Entity} The new entity + * @param entity - The entity + * @param parent - The parent of the new entity + * @param ind - The index in the parent's children array where we want to insert the new entity + * @param duplicatedIdsMap - A guid->guid map that contains references from the source resource ids to the new resource ids + * @param useUniqueName - Controls whether duplicated entity will have a unique name + * @returns The new entity */ function duplicateEntity(entity: Entity, parent: Entity, ind: number, duplicatedIdsMap: Record, useUniqueName: boolean = false) { const originalResourceId = entity.get('resource_id'); @@ -155,7 +153,7 @@ function duplicateEntity(entity: Entity, parent: Entity, ind: number, duplicated return entity; } -function duplicateInBackend(entities: Entity[], options: any) { +function duplicateInBackend(entities: Entity[], options: { history?: boolean } = {}) { const originalEntities = entities; let cancelWaitForEntities: () => void; @@ -239,16 +237,14 @@ function duplicateInBackend(entities: Entity[], options: any) { /** * Duplicates entities under the same parent * - * @private - * @typedef {import("../entities").Entities} Entities - * @param {Entity[]} entities - The entities - * @param {object} [options] - Options - * @param {boolean} [options.history] - Whether to record a history action. Defaults to true. - * @param {boolean} [options.select] - Whether to select the new entities. Defaults to false. - * @param {boolean} [options.rename] - Whether to rename the duplicated entities. Defaults to false. - * @returns {Promise} The duplicated entities + * @param entities - The entities + * @param options - Options + * @param options.history - Whether to record a history action. Defaults to true. + * @param options.select - Whether to select the new entities. Defaults to false. + * @param options.rename - Whether to rename the duplicated entities. Defaults to false. + * @returns The duplicated entities */ -async function duplicateEntities(entities: Entity[], options: any = {}) { +async function duplicateEntities(entities: Entity[], options: { history?: boolean, select?: boolean, rename?: boolean } = {}) { // copy entities for safety in undo / redo entities = entities.slice(); diff --git a/src/entities/paste.ts b/src/entities/paste.ts index 1c5ab53..baf9e32 100644 --- a/src/entities/paste.ts +++ b/src/entities/paste.ts @@ -17,9 +17,9 @@ let evtMessenger: EventHandle; * corresponds to the specified assetId that may come from * a different project. * - * @param {number} assetId - The asset id we are trying to remap - * @param {object} assetsIndex - The assets index stored in localStorage that contains paths of assets - * @returns {number} The asset id in this project + * @param assetId - The asset id we are trying to remap + * @param assetsIndex - The assets index stored in localStorage that contains paths of assets + * @returns The asset id in this project */ function remapAsset(assetId: any, assetsIndex: Record): number { if (!assetId) return null; @@ -171,11 +171,11 @@ function remapScriptAttribute(assetAttr: any, componentAttr: any, entity: Entity * Remaps the resource ids of the entities and their entity references in localStorage * with new resource ids, also remaps asset ids. * - * @param {Observer} entity - The entity we are remapping - * @param {Entity} parent - The parent of the pasted entity - * @param {object} data - The data in localStorage - * @param {object} entityMapping - An index that maps old resource ids to new resource ids - * @param {object} assetMapping - An index that maps old asset ids to new asset ids + * @param entity - The entity we are remapping + * @param parent - The parent of the pasted entity + * @param data - The data in localStorage + * @param entityMapping - An index that maps old resource ids to new resource ids + * @param assetMapping - An index that maps old asset ids to new asset ids */ function remapEntitiesAndAssets(entity: Entity, parent: Entity, data: Record, entityMapping: Record, assetMapping: Record) { const sameProject = (data.project === api.projectId); @@ -340,12 +340,12 @@ function remapEntitiesAndAssets(entity: Entity, parent: Entity, data: Record} A promise + * @param data - The clipboard data + * @param parent - The parent entity + * @param options - The paste options + * @returns A promise that resolves to an array of pasted entities */ -function pasteInBackend(data: Record, parent: Entity, options: any = {}) { +function pasteInBackend(data: Record, parent: Entity, options: { history?: boolean }) { let entities: Entity[]; let cancelWaitForEntities: () => void; @@ -354,7 +354,7 @@ function pasteInBackend(data: Record, parent: Entity, options: any reject: null }; - const promise = new Promise((resolve, reject) => { + const promise: Promise = new Promise((resolve, reject) => { deferred.resolve = resolve; deferred.reject = reject; }); @@ -454,12 +454,12 @@ function pasteInBackend(data: Record, parent: Entity, options: any * Paste entities copied into clipboard * under the specified parent. * - * @param {Entity} parent - The parent - * @param {object} options - Options - * @param {boolean} options.history - Whether to record a history action. Defaults to true. - * @returns {Promise} The new entities + * @param parent - The parent entity + * @param options - Options + * @param options.history - Whether to record a history action. Defaults to true. + * @returns A promise that resolves to an array of new entities */ -async function pasteEntities(parent: Entity, options: any = {}) { +async function pasteEntities(parent: Entity, options: { history?: boolean } = {}) { if (options.history === undefined) { options.history = true; } diff --git a/src/entities/references.ts b/src/entities/references.ts index f2cffe2..450ca89 100644 --- a/src/entities/references.ts +++ b/src/entities/references.ts @@ -120,10 +120,8 @@ function findReferencesInComponents(entity: Entity, refType: string) { * Return a map of all entity reference properties in the graph. This will * include references of the entity and also references of its children * - * @private - * @typedef {import("../entity").Entity} Entity - * @param {Entity} entity - The entity - * @returns {object} The entity references + * @param entity - The entity + * @returns The entity references */ function findEntityReferencesInComponents(entity: Entity) { return findReferencesInComponents(entity, 'entity'); @@ -132,10 +130,8 @@ function findEntityReferencesInComponents(entity: Entity) { /** * Return a map of all asset reference properties in the graph. * - * @private - * @typedef {import("../entity").Entity} Entity - * @param {Entity} entity - The entity - * @returns {object} The asset references + * @param entity - The entity + * @returns The asset references */ function findAssetReferencesInComponents(entity: Entity) { return findReferencesInComponents(entity, 'asset'); @@ -144,11 +140,10 @@ function findAssetReferencesInComponents(entity: Entity) { /** * Updates references to the old value to point to the new value * - * @private - * @param {object} references - A map of references that we got + * @param references - A map of references that we got * from findEntityReferencesInComponents or findAssetReferencesInComponents. - * @param {string|number} oldValue - The value that we want to replace - * @param {string|number} newValue - The value that we want our references to point to + * @param oldValue - The value that we want to replace + * @param newValue - The value that we want our references to point to */ function updateReferences(references: Record, oldValue: string | number, newValue: string | number) { const referencesToEntity = references[oldValue]; diff --git a/src/entities/reparent.ts b/src/entities/reparent.ts index f218d35..3e19c49 100644 --- a/src/entities/reparent.ts +++ b/src/entities/reparent.ts @@ -6,14 +6,11 @@ import { globals as api } from '../globals'; /** * Reparents entities under new parent. * - * @private - * @typedef {import("../entities").ReparentArguments} ReparentArguments - * @param {ReparentArguments[]} data - The reparenting data - * @param {object} [options] - Options - * @param {boolean} [options.preserveTransform] - Whether to preserve the transform of the entities - * @param {boolean} [options.history] - Whether to record history. Defaults to true + * @param data - The reparenting data + * @param options.preserveTransform - Whether to preserve the transform of the entities + * @param options.history - Whether to record history. Defaults to true */ -function reparentEntities(data: ReparentArguments[], options: any = {}) { +function reparentEntities(data: ReparentArguments[], options: { preserveTransform?: boolean, history?: boolean } = {}) { if (options.history === undefined) { options.history = true; } diff --git a/src/entities/scripts.ts b/src/entities/scripts.ts index f45d6e4..7c0255f 100644 --- a/src/entities/scripts.ts +++ b/src/entities/scripts.ts @@ -1,7 +1,7 @@ import { Entity } from '../entity'; import { globals as api } from '../globals'; -async function addScript(entities: Entity[], scriptName: string, options: any = {}) { +async function addScript(entities: Entity[], scriptName: string, options: { enabled?: boolean, attributes?: any, index?: number, history?: boolean } = {}) { entities = entities.filter(e => !e.has(`components.script.scripts.${scriptName}`)); if (!entities.length) return; @@ -117,7 +117,7 @@ async function addScript(entities: Entity[], scriptName: string, options: any = await promise; } -function removeScript(entities: Entity[], scriptName: string, options: any = {}) { +function removeScript(entities: Entity[], scriptName: string, options: { history?: boolean } = {}) { const history = (options.history || options.history === undefined); let prev: Record = {}; diff --git a/src/entities/wait.ts b/src/entities/wait.ts index af7085a..3c5371d 100644 --- a/src/entities/wait.ts +++ b/src/entities/wait.ts @@ -7,11 +7,11 @@ import { globals as api } from '../globals'; * Waits for specified entity ids to be added to the scene. * Once they are the callback is called with the entities as its argument. * - * @param {string[]} entityIds - The ids of the entities to wait for - * @param {number} timeoutMs - Number of ms to wait before stopping to wait - * @param {Function} callback - The callback to call when all entities have been added. + * @param entityIds - The ids of the entities to wait for + * @param timeoutMs - Number of ms to wait before stopping to wait + * @param callback - The callback to call when all entities have been added. * The signature is (Entity[]) => void. - * @returns {Function} Returns a cancel function which can be called to cancel calling the + * @returns Returns a cancel function which can be called to cancel calling the * callback when the entities are added. */ function wait(entityIds: string[], timeoutMs: number, callback: Function) { diff --git a/src/entity.ts b/src/entity.ts index e86365e..0240b7c 100644 --- a/src/entity.ts +++ b/src/entity.ts @@ -21,6 +21,11 @@ export type EntityObserver = Observer & { * A function that returns the latest observer. */ latestFn: () => Observer; + + /** + * The Engine entity associated with this observer. + */ + entity: any; }; /** @@ -458,7 +463,7 @@ class Entity extends Events { * Creates new Entity * * @category Internal - * @param {any} data - Optional entity data + * @param data - Optional entity data */ constructor(data: any = {}) { super(); @@ -537,8 +542,8 @@ class Entity extends Events { /** * Checks if path exists. See {@link Entity} for a list of properties. * - * @param {string} path - The path - * @returns {boolean} True if path exists + * @param path - The path + * @returns True if path exists * @example * ```javascript * console.log(entity.has('components.model')); @@ -551,8 +556,8 @@ class Entity extends Events { /** * Gets value at path. See {@link Entity} for a list of properties. * - * @param {string} path - The path - * @returns {any} The value + * @param path - The path + * @returns The value * @example * ```javascript * console.log(entity.get('position')); @@ -565,9 +570,9 @@ class Entity extends Events { /** * Sets value at path. See {@link Entity} for a list of properties. * - * @param {string} path - The path - * @param {any} value - The value - * @returns {boolean} Whether the value was set + * @param path - The path + * @param value - The value + * @returns Whether the value was set * @example * ```javascript * entity.set('position', [1, 0, 0]); @@ -580,8 +585,8 @@ class Entity extends Events { /** * Unsets value at path. See {@link Entity} for a list of properties. * - * @param {string} path - The path - * @returns {boolean} Whether the value was unset + * @param path - The path + * @returns Whether the value was unset * @example * ```javascript * entity.unset('components.model'); @@ -594,10 +599,10 @@ class Entity extends Events { /** * Inserts value in array at path, at specified index. See {@link Entity} for a list of properties. * - * @param {string} path - The path - * @param {any} value - The value - * @param {number} index - The index (if undefined the value will be inserted in the end) - * @returns {boolean} Whether the value was inserted + * @param path - The path + * @param value - The value + * @param index - The index (if undefined the value will be inserted in the end) + * @returns Whether the value was inserted * @example * ```javascript * entity.insert('tags', 'a_tag'); @@ -610,9 +615,9 @@ class Entity extends Events { /** * Remove value from array at path. See {@link Entity} for a list of properties. * - * @param {string} path - The path - * @param {any} value - The value - * @returns {boolean} Whether the value was removed + * @param path - The path + * @param value - The value + * @returns Whether the value was removed * @example * ```javascript * entity.removeValue('tags', 'a_tag'); @@ -625,7 +630,7 @@ class Entity extends Events { /** * Returns JSON representation of entity data * - * @returns {object} - The data + * @returns - The data * ```javascript * console.log(entity.json()); * ``` @@ -639,7 +644,7 @@ class Entity extends Events { * of the entity gets recursively converted to an array of entity data * instead of containing children resource ids. * - * @returns {object} - The data + * @returns - The data * @example * ```javascript * const data = entity.jsonHierarchy(); @@ -659,8 +664,8 @@ class Entity extends Events { /** * Returns true if this entity is a descendant of the specified parent entity. * - * @param {Entity} parent - The parent - * @returns {boolean} True if it is + * @param parent - The parent + * @returns True if it is */ isDescendantOf(parent: Entity) { let p = this.parent; @@ -678,14 +683,14 @@ class Entity extends Events { /** * Finds first entity by name using depth-first search * - * @param {string} name - The name - * @returns {Entity} The entity + * @param name - The name + * @returns The entity * @example * ```javascript * const door = editor.entities.root.findByName('Door'); * ``` */ - findByName(name: string) { + findByName(name: string): Entity | null { if (this.get('name') === name) { return this; } @@ -707,9 +712,9 @@ class Entity extends Events { /** * Finds all entities with specified tags * - * @param {...string|...string[]} tags - The tags. If multiple tags are specified then entities that contain ANY of the specified + * @param tags - The tags. If multiple tags are specified then entities that contain ANY of the specified * tags will be included. If an argument is an array of tags then entities that contain ALL of the tags in the array will be included. - * @returns {Entity[]} The entities + * @returns The entities * @example * ```javascript * // entities that have the following tag @@ -721,7 +726,7 @@ class Entity extends Events { * ``` */ listByTag(...tags: any[]) { - return this.filter((entity: Observer) => { + return this.filter((entity: Entity) => { const t = entity.get('tags'); for (let i = 0; i < tags.length; i++) { if (Array.isArray(tags[i])) { @@ -751,16 +756,16 @@ class Entity extends Events { /** * Returns the entity and children that satisfy the function * - * @param {Function} fn - A function that takes an Entity and returns whether it should be included + * @param fn - A function that takes an Entity and returns whether it should be included * in the result - * @returns {Entity[]} The result + * @returns The result * @example * ```javascript * const doors = editor.entities.root.filter(entity => entity.get('name').startsWith('door')); * ``` */ - filter(fn: Function) { - let result = []; + filter(fn: (entity: Entity) => boolean): Entity[] { + let result: Entity[] = []; if (fn(this)) { result.push(this); @@ -780,7 +785,7 @@ class Entity extends Events { /** * Executes function for this entity and its children in depth first order. * - * @param {Function} fn - A function that takes an entity as an argument + * @param fn - A function that takes an entity as an argument * @example * ```javascript * // get a list of all entities in the graph in depth first order @@ -788,7 +793,7 @@ class Entity extends Events { * editor.entities.root.depthFirst(entity => entities.push(entity)); * ``` */ - depthFirst(fn: Function) { + depthFirst(fn: (entity: Entity) => void) { fn(this); const children = this.children; @@ -804,8 +809,8 @@ class Entity extends Events { /** * Adds a component to this Entity * - * @param {string} component - The component name - * @param {object} data - Default component data. Defaults values will be used for any missing fields. + * @param component - The component name + * @param data - Default component data. Defaults values will be used for any missing fields. * For details on component properties see {@link Entity}. * @example * ```javascript @@ -823,7 +828,7 @@ class Entity extends Events { /** * Removes a component from this Entity * - * @param {string} component - The component name + * @param component - The component name * @example * ```javascript * editor.entities.root.removeComponent('model'); @@ -837,8 +842,8 @@ class Entity extends Events { * Adds entity as a child * * @category Internal - * @param {Entity} entity - The entity - * @returns {boolean} Whether the child was added + * @param entity - The entity + * @returns Whether the child was added */ addChild(entity: Entity) { return this.insertChild(entity); @@ -848,9 +853,9 @@ class Entity extends Events { * Inserts entity as a child at specified index. * * @category Internal - * @param {Entity} entity - The entity - * @param {number} index - The index. If undefined the child will be added in the end. - * @returns {boolean} Whether the child was added + * @param entity - The entity + * @param index - The index. If undefined the child will be added in the end. + * @returns Whether the child was added */ insertChild(entity: Entity, index: number | undefined = undefined) { let history = this.history.enabled; @@ -879,7 +884,7 @@ class Entity extends Events { * Removes entity from children * * @category Internal - * @param {Entity} entity - The entity + * @param entity - The entity */ removeChild(entity: Entity) { let history = entity.history.enabled; @@ -906,27 +911,25 @@ class Entity extends Events { /** * Deletes entity (and its children) * - * @param {object} options - Options - * @param {boolean} options.history - Whether to record a history action. Defaults to true. - * @returns {Promise} A promise + * @param options.history - Whether to record a history action. Defaults to true. + * @returns A promise * @example * ```javascript * editor.entities.root.findByName('door').delete(); * ``` * */ - delete(options = {}) { + delete(options: { history?: boolean } = {}) { return api.entities.delete([this], options); } /** * Reparents entity under new parent * - * @param {Entity} parent - The new parent - * @param {number} index - The desired index. If undefined the entity will be added at the end of the parent's children. - * @param {object} options - Options - * @param {boolean} options.history - Whether to record a history action. Defaults to true. - * @param {boolean} options.preserveTransform - Whether to preserve the original transform after reparenting + * @param parent - The new parent + * @param index - The desired index. If undefined the entity will be added at the end of the parent's children. + * @param options.history - Whether to record a history action. Defaults to true. + * @param options.preserveTransform - Whether to preserve the original transform after reparenting * @example * ```javascript * const redHouse = editor.entities.root.findByName('red house'); @@ -935,7 +938,7 @@ class Entity extends Events { * door.reparent(greenHouse); * ``` */ - reparent(parent: Entity, index: number | null = null, options: any = {}) { + reparent(parent: Entity, index: number | null = null, options: { history?: boolean, preserveTransform?: boolean } = {}) { api.entities.reparent([{ entity: this, parent: parent, @@ -946,13 +949,12 @@ class Entity extends Events { /** * Duplicates entity under the same parent * - * @param {object} [options] - Options - * @param {boolean} [options.history] - Whether to record a history action. Defaults to true. - * @param {boolean} [options.select] - Whether to select the new entity. Defaults to false. - * @param {boolean} [options.rename] - Whether to rename the duplicated entity. Defaults to false. - * @returns {Promise} The new entity + * @param options.history - Whether to record a history action. Defaults to true. + * @param options.select - Whether to select the new entity. Defaults to false. + * @param options.rename - Whether to rename the duplicated entity. Defaults to false. + * @returns The new entity */ - async duplicate(options = {}) { + async duplicate(options: { history?: boolean, select?: boolean, rename?: boolean } = {}) { const result = await api.entities.duplicate([this], options); return result[0]; } @@ -960,7 +962,7 @@ class Entity extends Events { /** * Returns the latest version of the Entity from the Entities API. * - * @returns {Entity} The entity + * @returns The entity */ latest() { return api.entities.get(this._observer.get('resource_id')); @@ -971,27 +973,25 @@ class Entity extends Events { * If a script component does not exist, this method will add the script * component as well. * - * @param {string} scriptName - The name of the script. - * @param {object} options - Options - * @param {object} options.attributes - The values of attributes. Each key is the name + * @param scriptName - The name of the script. + * @param options.attributes - The values of attributes. Each key is the name * of the attributes and each value is the value for that attribute. Leave undefined to * let the Editor set default values depending on the attribute types. - * @param {boolean} options.history - Whether to add a history action. Defaults to true. - * @param {number} options.index - The desired index in the entity's scripts order to add this script. - * @returns {Promise<>} A promise + * @param options.history - Whether to add a history action. Defaults to true. + * @param options.index - The desired index in the entity's scripts order to add this script. + * @returns A promise */ - addScript(scriptName: string, options: object = {}) { + addScript(scriptName: string, options: { attributes?: object, history?: boolean, index?: number } = {}) { return api.entities.addScript([this], scriptName, options); } /** * Removes a script from the entity's script component. * - * @param {string} scriptName - The name of the script. - * @param {object} options - Options - * @param {boolean} options.history - Whether to record a history action. Defaults to true. + * @param scriptName - The name of the script. + * @param options.history - Whether to record a history action. Defaults to true. */ - removeScript(scriptName: string, options: object = {}) { + removeScript(scriptName: string, options: { history?: boolean } = {}) { api.entities.removeScript([this], scriptName, options); } @@ -1004,27 +1004,21 @@ class Entity extends Events { /** * The parent entity. - * - * @type {Entity} */ get parent() { const id = this.get('parent'); - return id ? api.entities.get(id) : null; + return (id ? api.entities.get(id) : null) as Entity; } /** * The children entities. Warning: this creates a new array every time it's called. - * - * @type {Entity[]} */ get children() { - return this.get('children').map((id: string) => api.entities.get(id)); + return this.get('children').map((id: string) => api.entities.get(id)) as Entity[]; } /** * The history object for this entity. - * - * @type {ObserverHistory} */ get history() { return this._history as ObserverHistory; @@ -1032,11 +1026,9 @@ class Entity extends Events { /** * The entity in the 3D viewport of the Editor. - * - * @type {pc.Entity} */ get viewportEntity() { - return this._observer ? (this._observer as any).entity : null; + return (this._observer ? (this._observer as any).entity : null) as any; } } diff --git a/src/globals.ts b/src/globals.ts index b23fc33..a07166c 100644 --- a/src/globals.ts +++ b/src/globals.ts @@ -94,12 +94,12 @@ class globals { * for an action. Defaults to the default browser popup but * can be overridden to show your custom popup instead. * - * @param {string} text - The confirm dialog text - * @param {object} options - Options for the popup - * @param {string} options.yesText - Text for 'yes' option - * @param {string} options.noText - Text for 'no' option - * @param {boolean} options.noDismiss - If true then user cannot dismiss the popup and will have to click yes or no - * @returns {Promise} True if the user confirmed, false otherwise + * @param text - The confirm dialog text + * @param options - Options for the popup + * @param options.yesText - Text for 'yes' option + * @param options.noText - Text for 'no' option + * @param options.noDismiss - If true then user cannot dismiss the popup and will have to click yes or no + * @returns True if the user confirmed, false otherwise */ static confirmFn(text: string, options: { yesText?: string, noText?: boolean, noDismiss?: boolean } = {}): Promise { return new Promise((resolve) => { diff --git a/src/guid.ts b/src/guid.ts index c13d943..2cdf51f 100644 --- a/src/guid.ts +++ b/src/guid.ts @@ -8,7 +8,7 @@ class Guid { /** * Create an RFC4122 version 4 compliant GUID. * - * @returns {string} A new GUID. + * @returns A new GUID. */ static create() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { diff --git a/src/history.ts b/src/history.ts index 5d5ef48..d5ed68e 100644 --- a/src/history.ts +++ b/src/history.ts @@ -25,7 +25,7 @@ class History extends Events { /** * Adds history action * - * @param {HistoryAction} action - The action + * @param action - The action * @example * ```javascript * const prevSelection = editor.selection.items; @@ -43,7 +43,7 @@ class History extends Events { /** * Adds history action and execute redo * - * @param {HistoryAction} action - The action + * @param action - The action * @example * ```javascript * const prevSelection = editor.selection.items; @@ -96,8 +96,6 @@ class History extends Events { /** * Gets the current action - * - * @type {HistoryAction} */ get currentAction() { return this._history.currentAction; @@ -105,8 +103,6 @@ class History extends Events { /** * Gets the last action - * - * @type {HistoryAction} */ get lastAction() { return this._history.lastAction; @@ -114,8 +110,6 @@ class History extends Events { /** * Sets whether there are actions to undo. - * - * @type {boolean} */ set canUndo(value) { this._history.canUndo = value; @@ -123,8 +117,6 @@ class History extends Events { /** * Gets whether there are actions to undo. - * - * @type {boolean} */ get canUndo() { return this._history.canUndo; @@ -132,8 +124,6 @@ class History extends Events { /** * Sets whether there are actions to redo. - * - * @type {boolean} */ set canRedo(value) { this._history.canRedo = value; @@ -141,8 +131,6 @@ class History extends Events { /** * Gets whether there are actions to redo. - * - * @type {boolean} */ get canRedo() { return this._history.canRedo; diff --git a/src/jobs.ts b/src/jobs.ts index e17b892..93e8c14 100644 --- a/src/jobs.ts +++ b/src/jobs.ts @@ -14,8 +14,8 @@ class Jobs extends Events { * Adds a new job. The specified function will be returned when the * job is finished. * - * @param {Function} fn - A function to be stored for this job. - * @returns {string} Returns a job id + * @param fn - A function to be stored for this job. + * @returns Returns a job id * @example * ```javascript * const jobId = editor.jobs.start(() => console.log('job was finished')); @@ -34,8 +34,8 @@ class Jobs extends Events { * id is removed and the callback stored when the job was * started is returned. * - * @param {string} jobId - The job id - * @returns {Function} The function stored when the job was started + * @param jobId - The job id + * @returns The function stored when the job was started * @example * ```javascript * const jobId = editor.jobs.start(() => console.log('job was finished')); diff --git a/src/localstorage.ts b/src/localstorage.ts index 6a4f045..0455e1a 100644 --- a/src/localstorage.ts +++ b/src/localstorage.ts @@ -9,8 +9,8 @@ class LocalStorage { /** * Gets a key from localStorage * - * @param {string} key - The key - * @returns {object} The value + * @param key - The key + * @returns The value */ get(key: string) { const value = localStorage.getItem(key); @@ -37,8 +37,8 @@ class LocalStorage { /** * Stores a key-value to localStorage * - * @param {string} key - The key - * @param {object | string} value - The value + * @param key - The key + * @param value - The value */ set(key: string, value: object | string) { const text = JSON.stringify(value); @@ -52,7 +52,7 @@ class LocalStorage { /** * Removes a key from localStorage * - * @param {string} key - The key + * @param key - The key */ unset(key: string) { localStorage.removeItem(key); @@ -61,8 +61,8 @@ class LocalStorage { /** * Checks if key exists in local storage * - * @param {string} key - The key - * @returns {boolean} True or false + * @param key - The key + * @returns True or false */ has(key: string) { return !!localStorage.getItem(key); diff --git a/src/messenger.ts b/src/messenger.ts index e109f4e..cecae6c 100644 --- a/src/messenger.ts +++ b/src/messenger.ts @@ -9,7 +9,7 @@ import { globals as api } from './globals'; export type MessagerClient = Events & { /** * Connects to the specified URL. - * @param {string} url - The URL to connect to. + * @param url - The URL to connect to. */ connect(url: string): void; @@ -20,14 +20,14 @@ export type MessagerClient = Events & { /** * Authenticates the client with the specified access token and role. - * @param {string} accessToken - The access token for authentication. - * @param {string} role - The role for authentication. + * @param accessToken - The access token for authentication. + * @param role - The role for authentication. */ authenticate(accessToken: string, role: string): void; /** * Watches the specified project. - * @param {string} projectId - The ID of the project to watch. + * @param projectId - The ID of the project to watch. */ projectWatch(projectId: string): void; }; @@ -47,7 +47,7 @@ class Messenger extends Events { /** * Constructor * - * @param {MessagerClient} messenger - The instance of the Messenger client - this is + * @param messenger - The instance of the Messenger client - this is * a different class which requires the Messenger client library to be downloaded. */ constructor(messenger: MessagerClient) { @@ -60,16 +60,16 @@ class Messenger extends Events { messenger.on('message', this._onMessage.bind(this)); } - _onConnect() { + private _onConnect() { this._messenger.authenticate(api.accessToken, 'designer'); this.emit('connected'); } - _onWelcome() { + private _onWelcome() { this._messenger.projectWatch(api.projectId as unknown as string); } - _onMessage(data: { name: string; data: any; }) { + private _onMessage(data: { name: string; data: any; }) { this.emit(data.name, data.data); this.emit('message', data.name, data.data); } @@ -77,7 +77,7 @@ class Messenger extends Events { /** * Connects to the messenger server. * - * @param {string} url - The server URL + * @param url - The server URL */ connect(url: string) { this._url = url; @@ -86,8 +86,6 @@ class Messenger extends Events { /** * Returns true if we are connected to the messenger server. - * - * @type {boolean} */ get isConnected() { return this._messenger.isConnected; diff --git a/src/realtime.ts b/src/realtime.ts index 81aaadf..a630fe5 100644 --- a/src/realtime.ts +++ b/src/realtime.ts @@ -25,8 +25,6 @@ class Realtime extends Events { /** * Gets the realtime connection - * - * @type {RealtimeConnection} */ get connection() { return this._connection; @@ -34,8 +32,6 @@ class Realtime extends Events { /** * Gets the realtime scenes API - * - * @type {RealtimeScenes} */ get scenes() { return this._scenes; @@ -43,8 +39,6 @@ class Realtime extends Events { /** * Gets the realtime assets API - * - * @type {RealtimeAssets} */ get assets() { return this._assets; diff --git a/src/realtime/asset.ts b/src/realtime/asset.ts index 630c265..db2f298 100644 --- a/src/realtime/asset.ts +++ b/src/realtime/asset.ts @@ -24,9 +24,9 @@ class RealtimeAsset extends Events { /** * Constructor * - * @param {number} uniqueId - The unique asset id - * @param {Realtime} realtime - The realtime API - * @param {RealtimeConnection} connection - The realtime connection + * @param uniqueId - The unique asset id + * @param realtime - The realtime API + * @param connection - The realtime connection * */ constructor(uniqueId: number, realtime: Realtime, connection: RealtimeConnection) { @@ -75,10 +75,10 @@ class RealtimeAsset extends Events { /** * Submits sharedb operation * - * @param {object} op - The operation - * @param {function} [callback] - The callback + * @param op - The operation + * @param callback - The callback */ - submitOp(op: object, callback: Function) { + submitOp(op: object, callback?: Function) { if (!this._loaded) return; try { @@ -93,7 +93,7 @@ class RealtimeAsset extends Events { * Calls the callback when there are no changes pending to be * sent to the server * - * @param {Function} callback - The callback + * @param callback - The callback */ whenNothingPending(callback: Function) { if (this._document) { @@ -138,8 +138,6 @@ class RealtimeAsset extends Events { /** * Whether the asset is loaded - * - * @type {boolean} */ get loaded() { return this._loaded; @@ -147,26 +145,20 @@ class RealtimeAsset extends Events { /** * The asset data - * - * @type {object} */ get data() { - return (this._loaded && this._document) ? this._document.data : null; + return ((this._loaded && this._document) ? this._document.data : null) as any; } /** * The asset id - used in combination with branch id - * - * @type {number} */ get id() { - return this.data?.item_id; + return this.data?.item_id as number; } /** * The asset's unique id - * - * @type {number} */ get uniqueId() { return this._uniqueId; diff --git a/src/realtime/assets.ts b/src/realtime/assets.ts index 2627642..209f779 100644 --- a/src/realtime/assets.ts +++ b/src/realtime/assets.ts @@ -19,8 +19,8 @@ class RealtimeAssets extends Events { /** * Constructor * - * @param {Realtime} realtime - The realtime API - * @param {RealtimeConnection} connection - The realtime connection + * @param realtime - The realtime API + * @param connection - The realtime connection */ constructor(realtime: Realtime, connection: RealtimeConnection) { super(); @@ -32,8 +32,8 @@ class RealtimeAssets extends Events { /** * Loads an asset * - * @param {number} id - The asset's unique id - * @returns {RealtimeAsset} The asset + * @param id - The asset's unique id + * @returns The asset */ load(id: number) { let asset = this._assets[id]; @@ -52,8 +52,8 @@ class RealtimeAssets extends Events { /** * Gets an already loaded asset * - * @param {number} id - The asset's unique id - * @returns {RealtimeAsset} The asset + * @param id - The asset's unique id + * @returns The asset */ get(id: number) { return this._assets[id] || null; @@ -62,7 +62,7 @@ class RealtimeAssets extends Events { /** * Unloads an asset * - * @param {number} id - The asset's unique id + * @param id - The asset's unique id */ unload(id: number) { if (this._assets[id]) { diff --git a/src/realtime/connection.ts b/src/realtime/connection.ts index 1667b7c..c6c4411 100644 --- a/src/realtime/connection.ts +++ b/src/realtime/connection.ts @@ -34,7 +34,7 @@ class RealtimeConnection extends Events { /** * Constructor * - * @param {Realtime} realtime - The realtime API + * @param realtime - The realtime API */ constructor(realtime: Realtime) { super(); @@ -53,7 +53,7 @@ class RealtimeConnection extends Events { /** * Connect to the realtime server * - * @param {string} url - The server URL + * @param url - The server URL */ connect(url: string) { this._url = url; @@ -104,8 +104,8 @@ class RealtimeConnection extends Events { /** * Send message to server * - * @param {string} name - The message name - * @param {object} data - The message data + * @param name - The message name + * @param data - The message data */ sendMessage(name: string, data: object) { this.send(name + JSON.stringify(data)); @@ -114,7 +114,7 @@ class RealtimeConnection extends Events { /** * Sends a string to the server * - * @param {string} data - The message data + * @param data - The message data */ send(data: string) { if (this._socket && this._socket.readyState === WebSocket.OPEN) { @@ -125,9 +125,9 @@ class RealtimeConnection extends Events { /** * Gets a sharedb document * - * @param {string} collection - The collection name - * @param {string} id - The document id - * @returns {object} The sharedb document + * @param collection - The collection name + * @param id - The document id + * @returns The sharedb document */ getDocument(collection: string, id: number) { return this._sharedb.get(collection, id.toString()); @@ -147,14 +147,14 @@ class RealtimeConnection extends Events { this._sharedb.endBulk(); } - _onVisibilityChange() { + private _onVisibilityChange() { if (document.hidden) return; if (!this.connected && this._url) { this.connect(this._url); } } - _onConnect() { + private _onConnect() { this._connected = true; this._reconnectAttempts = 0; this._reconnectInterval = RECONNECT_INTERVAL; @@ -162,16 +162,16 @@ class RealtimeConnection extends Events { this._realtime.emit('connected'); } - _onError(msg: any) { + private _onError(msg: any) { if (this._sharedb.state === 'connected') return; this._realtime.emit('error', msg); } - _onBulkSubscribeError(msg: any) { + private _onBulkSubscribeError(msg: any) { this._realtime.emit('error:bs', msg); } - _onClose(reason: CloseEvent, originalOnClose: () => void) { + private _onClose(reason: CloseEvent, originalOnClose: () => void) { this._connected = false; this._authenticated = false; @@ -187,7 +187,7 @@ class RealtimeConnection extends Events { } } - _onMessage(msg: MessageEvent) { + private _onMessage(msg: MessageEvent) { try { if (msg.data.startsWith('auth')) { return this._onMessageAuth(msg); @@ -201,7 +201,7 @@ class RealtimeConnection extends Events { } } - _onMessageAuth(_msg: MessageEvent) { + private _onMessageAuth(_msg: MessageEvent) { if (!this._authenticated) { this._authenticated = true; this._realtime.emit('authenticated'); @@ -210,13 +210,13 @@ class RealtimeConnection extends Events { return true; } - _onMessageSelection(msg: MessageEvent) { + private _onMessageSelection(msg: MessageEvent) { const data = msg.data.slice('selection:'.length); this._realtime.emit('selection', data); return true; } - _onMessageFs(msg: { data: any; }) { + private _onMessageFs(msg: { data: any; }) { let data = msg.data.slice('fs:'.length); const ind = data.indexOf(':'); if (ind !== -1) { @@ -232,7 +232,7 @@ class RealtimeConnection extends Events { return false; } - _sendAuth() { + private _sendAuth() { this.sendMessage('auth', { accessToken: api.accessToken }); @@ -241,8 +241,6 @@ class RealtimeConnection extends Events { /** * Whether the user is connected to the server - * - * @type {boolean} */ get connected() { return this._connected; @@ -250,8 +248,6 @@ class RealtimeConnection extends Events { /** * Whether the server has authenticated the user - * - * @type {boolean} */ get authenticated() { return this._authenticated; @@ -259,8 +255,6 @@ class RealtimeConnection extends Events { /** * Gets the sharedb instance - * - * @type {object} */ get sharedb() { return this._sharedb; diff --git a/src/realtime/scene.ts b/src/realtime/scene.ts index 219fe57..7edf3f5 100644 --- a/src/realtime/scene.ts +++ b/src/realtime/scene.ts @@ -25,9 +25,9 @@ class RealtimeScene extends Events { /** * Constructor * - * @param {number} uniqueId - The unique scene id - * @param {Realtime} realtime - The realtime API - * @param {RealtimeConnection} connection - The realtime connection + * @param uniqueId - The unique scene id + * @param realtime - The realtime API + * @param connection - The realtime connection */ constructor(uniqueId: number, realtime: Realtime, connection: RealtimeConnection) { super(); @@ -77,7 +77,7 @@ class RealtimeScene extends Events { /** * Add entity to scene * - * @param {Entity} entity - The entity + * @param entity - The entity */ addEntity(entity: Entity) { this.submitOp({ @@ -89,7 +89,7 @@ class RealtimeScene extends Events { /** * Removes entity from scene (not from children of another entity) * - * @param {Entity} entity - The entity + * @param entity - The entity */ removeEntity(entity: Entity) { this.submitOp({ @@ -101,7 +101,7 @@ class RealtimeScene extends Events { /** * Submits sharedb operation * - * @param {object} op - The operation + * @param op - The operation */ submitOp(op: object) { if (!this._loaded) return; @@ -118,7 +118,7 @@ class RealtimeScene extends Events { * Calls the callback when there are no changes pending to be * sent to the server * - * @param {Function} callback - The callback + * @param callback - The callback */ whenNothingPending(callback: Function) { if (this._document) { @@ -126,18 +126,18 @@ class RealtimeScene extends Events { } } - _onError(err: any) { + private _onError(err: any) { this._realtime.emit('error:scene', err, this._uniqueId); } - _onLoad() { + private _onLoad() { // notify of operations this._document.on('op', this._onOp.bind(this)); this._loaded = true; this.emit('load'); } - _onOp(ops: any, local: boolean) { + private _onOp(ops: any, local: boolean) { if (local) return; for (let i = 0; i < ops.length; i++) { @@ -149,8 +149,6 @@ class RealtimeScene extends Events { /** * Whether the scene is loaded - * - * @type {boolean} */ get loaded() { return this._loaded; @@ -158,26 +156,20 @@ class RealtimeScene extends Events { /** * The scene data - * - * @type {object} */ get data() { - return (this._loaded && this._document) ? this._document.data : null; + return ((this._loaded && this._document) ? this._document.data : null) as any; } /** * The scene id - used in combination with the branch id - * - * @type {number} */ get id() { - return this.data?.item_id; + return this.data?.item_id as number; } /** * The scene's unique id - * - * @type {number} */ get uniqueId() { return this._uniqueId; diff --git a/src/realtime/scenes.ts b/src/realtime/scenes.ts index b99e6fe..b5342eb 100644 --- a/src/realtime/scenes.ts +++ b/src/realtime/scenes.ts @@ -21,8 +21,8 @@ class RealtimeScenes extends Events { /** * Constructor * - * @param {Realtime} realtime - The realtime API - * @param {RealtimeConnection} connection - The realtime connection + * @param realtime - The realtime API + * @param connection - The realtime connection */ constructor(realtime: Realtime, connection: RealtimeConnection) { super(); @@ -35,8 +35,8 @@ class RealtimeScenes extends Events { /** * Loads a scene * - * @param {number} sceneId - The scene id - * @returns {RealtimeScene} The scene + * @param sceneId - The scene id + * @returns The scene */ load(sceneId: number) { this._currentScene = this._scenes[sceneId]; @@ -59,7 +59,7 @@ class RealtimeScenes extends Events { /** * Unloads a scene * - * @param {number} sceneId - The scene id + * @param sceneId - The scene id */ unload(sceneId: number) { if (this._scenes[sceneId]) { @@ -74,8 +74,6 @@ class RealtimeScenes extends Events { /** * The current scene - * - * @type {RealtimeScene} */ get current() { return this._currentScene; diff --git a/src/schema.ts b/src/schema.ts index a548551..cae4633 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -37,8 +37,6 @@ class Schema { /** * Gets the assets schema - * - * @type {AssetsSchema} */ get assets() { return this._assetsSchema; @@ -46,8 +44,6 @@ class Schema { /** * Gets the component schema - * - * @type {ComponentSchema} */ get components() { return this._componentSchema; @@ -55,8 +51,6 @@ class Schema { /** * Gets the scene schema - * - * @type {SceneSchema} */ get scene() { return this._sceneSchema; @@ -64,8 +58,6 @@ class Schema { /** * Gets the settings schema - * - * @type {SettingsSchema} */ get settings() { return this._settingsSchema; diff --git a/src/schema/assets.ts b/src/schema/assets.ts index 9fd05c9..a0a7a57 100644 --- a/src/schema/assets.ts +++ b/src/schema/assets.ts @@ -11,7 +11,7 @@ class AssetsSchema { /** * @category Internal - * @param {Schema} schema - The schema API + * @param schema - The schema API */ constructor(schema: Schema) { this._schemaApi = schema; @@ -21,8 +21,8 @@ class AssetsSchema { /** * Gets default data for asset type * - * @param {string} type - The asset type - * @returns {object} The default data + * @param type - The asset type + * @returns The default data */ getDefaultData(type: string) { const field = `${type}Data`; @@ -46,9 +46,9 @@ class AssetsSchema { /** * Gets a list of fields of a particular type for an asset type * - * @param {string} assetType - The type of the asset. - * @param {string} type - The desired type - * @returns {string[]} A list of fields + * @param assetType - The type of the asset. + * @param type - The desired type + * @returns A list of fields * @example * ```javascript * const materialAssetPaths = editor.schema.assets.getFieldsOfType('material', 'asset'); diff --git a/src/schema/components.ts b/src/schema/components.ts index 869e9a7..fedc821 100644 --- a/src/schema/components.ts +++ b/src/schema/components.ts @@ -13,7 +13,7 @@ class ComponentSchema { * Creates new instance of API * * @category Internal - * @param {Schema} schema - The schema API + * @param schema - The schema API */ constructor(schema: Schema) { this._schemaApi = schema; @@ -36,8 +36,8 @@ class ComponentSchema { /** * Gets default data for a component * - * @param {string} component - The component name - * @returns {object} The default data + * @param component - The component name + * @returns The default data * @example * ```javascript * const modelData = editor.schema.components.getDefaultData('model'); @@ -61,9 +61,9 @@ class ComponentSchema { /** * Gets a list of fields of a particular type for a component * - * @param {string} componentName - The component name - * @param {string} type - The desired type - * @returns {string[]} A list of fields + * @param componentName - The component name + * @param type - The desired type + * @returns A list of fields * @example * ```javascript * const buttonEntityFields = editor.schema.components.getFieldsOfType('button', 'entity'); @@ -101,7 +101,7 @@ class ComponentSchema { /** * Gets a list of all the available components * - * @returns {string[]} The components + * @returns The components */ list() { const result = Object.keys(this._schema); diff --git a/src/schema/scene.ts b/src/schema/scene.ts index 292b247..521f710 100644 --- a/src/schema/scene.ts +++ b/src/schema/scene.ts @@ -13,7 +13,7 @@ class SceneSchema { * Creates new instance of API * * @category Internal - * @param {Schema} schema - The schema API + * @param schema - The schema API */ constructor(schema: Schema) { this._schemaApi = schema; @@ -42,7 +42,7 @@ class SceneSchema { /** * Get the default physics scene settings for the project * - * @returns {*} The default physics scene settings + * @returns The default physics scene settings * @example * ```javascript * const scenePhysicsSettings = editor.schema.scene.getDefaultPhysicsSettings(); @@ -55,7 +55,7 @@ class SceneSchema { /** * Get the default render scene settings for the project * - * @returns {*} The default physics scene settings + * @returns The default physics scene settings * @example * ```javascript * const sceneRenderSettings = editor.schema.scene.getDefaultRenderSettings(); diff --git a/src/schema/settings.ts b/src/schema/settings.ts index 904cfe7..923aefa 100644 --- a/src/schema/settings.ts +++ b/src/schema/settings.ts @@ -13,7 +13,7 @@ class SettingsSchema { * Creates new instance of API * * @category Internal - * @param {Schema} schema - The schema API + * @param schema - The schema API */ constructor(schema: Schema) { this._schemaApi = schema; @@ -44,7 +44,7 @@ class SettingsSchema { /** * Get the default settings for the project * - * @returns {*} The default settings for the project + * @returns The default settings for the project * @example * ```javascript * const projectSettings = editor.schema.settings.getDefaultProjectSettings(); @@ -57,7 +57,7 @@ class SettingsSchema { /** * Get the default settings for the user * - * @returns {*} The default settings for the user + * @returns The default settings for the user * @example * ```javascript * const userSettings = editor.schema.settings.getDefaultUserSettings(); @@ -70,7 +70,7 @@ class SettingsSchema { /** * Get the default settings for the user in the project * - * @returns {*} The default settings for the user in the project + * @returns The default settings for the user in the project * @example * ```javascript * const projectUserSettings = editor.schema.settings.getDefaultProjectUserSettings(); diff --git a/src/selection.ts b/src/selection.ts index 00bb036..ab1bbfb 100644 --- a/src/selection.ts +++ b/src/selection.ts @@ -1,5 +1,7 @@ import { Events } from '@playcanvas/observer'; +import { Asset } from './asset'; +import { Entity } from './entity'; import { globals as api } from './globals'; /** @@ -40,8 +42,6 @@ class SelectionHistory { /** * Record history action after executing function. * The history action will restore the previous selection. - * - * @private */ wrapAction(name: any, fn: () => void) { if (!this._enabled || !api.history || this._executingAction) { @@ -80,7 +80,7 @@ class SelectionHistory { class Selection extends Events { private _history: SelectionHistory; - private _items: any[]; + private _items: (Asset | Entity)[]; private _enabled: boolean; @@ -120,7 +120,7 @@ class Selection extends Events { * editor.selection.add(editor.entities.root); * ``` */ - add(item: any, options: any = {}) { + add(item: any, options: { history?: boolean } = {}) { if (!this.enabled) return; if (this.has(item)) return; @@ -153,7 +153,7 @@ class Selection extends Events { * editor.selection.remove(editor.entities.root); * ``` */ - remove(item: any, options: any = {}) { + remove(item: any, options: { history?: boolean } = {}) { if (!this.enabled) return; if (options.history === undefined) { @@ -185,7 +185,7 @@ class Selection extends Events { * editor.selection.toggle(editor.entities.root); * ``` */ - toggle(item: any, options: any = {}) { + toggle(item: any, options: { history?: boolean } = {}) { if (!this.enabled) return; if (options.history === undefined) { @@ -231,7 +231,7 @@ class Selection extends Events { * editor.selection.clear(); * ``` */ - clear(options: any = {}) { + clear(options: { history?: boolean } = {}) { if (!this.enabled) return; const length = this._items.length; @@ -270,7 +270,7 @@ class Selection extends Events { * editor.selection.set([editor.entities.root]); * ``` */ - set(items: any[], options: any = {}) { + set(items: any[], options: { history?: boolean } = {}) { if (!this.enabled) return; if (options.history === undefined) { diff --git a/src/settings.ts b/src/settings.ts index 3128d9e..cddb4c5 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -19,8 +19,6 @@ class Settings extends Events { /** * Gets the settings for the currently loaded scene. - * - * @type {SceneSettings} */ get scene() { return this._sceneSettings; diff --git a/src/settings/scene.ts b/src/settings/scene.ts index 69ff81b..ce0c933 100644 --- a/src/settings/scene.ts +++ b/src/settings/scene.ts @@ -3,7 +3,10 @@ import { Events, Observer, ObserverHistory } from '@playcanvas/observer'; import { globals as api } from '../globals'; import type { RealtimeScene } from '../realtime/scene'; -type SceneSettingsObserver = Observer & { history: ObserverHistory }; +/** + * Represents an observer for the Scene Settings, extending the base Observer. + */ +export type SceneSettingsObserver = Observer & { history: ObserverHistory }; /** * Represents the settings for the currently loaded scene. @@ -39,8 +42,6 @@ class SceneSettings extends Events { /** * Creates new instance of the API - * - * @private */ constructor() { super(); @@ -54,10 +55,8 @@ class SceneSettings extends Events { /** * Initialize internal observer and history. - * - * @private */ - _initializeObserver() { + private _initializeObserver() { if (!this._observer) { this._observer = new Observer() as SceneSettingsObserver; } @@ -77,10 +76,9 @@ class SceneSettings extends Events { /** * Called when a scene is loaded. * - * @param {import("../realtime/scene.js").RealtimeScene} scene - The loaded scene - * @private + * @param scene - The loaded scene */ - _onLoadScene(scene: RealtimeScene) { + private _onLoadScene(scene: RealtimeScene) { this._initializeObserver(); this._history.enabled = false; @@ -93,8 +91,8 @@ class SceneSettings extends Events { /** * Checks if path exists. See the {@link SceneSettings} overview for a full list of properties. * - * @param {string} path - The path - * @returns {boolean} True if path exists + * @param path - The path + * @returns True if path exists * @example * ```javascript * console.log(editor.settings.scene.has('render.fog')); @@ -107,8 +105,8 @@ class SceneSettings extends Events { /** * Gets value at path. See the {@link SceneSettings} overview for a full list of properties. * - * @param {string} path - The path - * @returns {any} The value + * @param path - The path + * @returns The value * @example * ```javascript * console.log(editor.settings.scene.get('render.fog')); @@ -121,9 +119,9 @@ class SceneSettings extends Events { /** * Sets value at path. See the {@link SceneSettings} overview for a full list of properties. * - * @param {string} path - The path - * @param {any} value - The value - * @returns {boolean} Whether the value was set + * @param path - The path + * @param value - The value + * @returns Whether the value was set * @example * ```javascript * editor.settings.scene.set('render.fog', 'none'); @@ -136,7 +134,7 @@ class SceneSettings extends Events { /** * Returns JSON representation of scene settings data * - * @returns {object} - The data + * @returns - The data * @example * ```javascript * console.log(editor.settings.scene.json()); @@ -146,10 +144,12 @@ class SceneSettings extends Events { return this._observer.json(); } + get observer() { + return this._observer; + } + /** * Gets the history object for this entity - * - * @type {ObserverHistory} */ get history() { return this._history; diff --git a/src/utils.ts b/src/utils.ts index 70d019c..fbd6953 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -7,8 +7,8 @@ class utils { /** * Deep copy an object * - * @param {Record} data - The data to copy - * @returns {object} A copy of the data + * @param data - The data to copy + * @returns A copy of the data */ static deepCopy(data: Record): Record { if (data == null || typeof data !== 'object') {