From d3c2eb5e517a017dc4099faafcc5bae17bbd377a Mon Sep 17 00:00:00 2001 From: waynemwashuma <94756970+waynemwashuma@users.noreply.github.com> Date: Sun, 7 Jun 2026 12:20:48 +0300 Subject: [PATCH 1/3] Add `AssetServer.loadUntyped` --- src/asset/resources/assetserver.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/asset/resources/assetserver.js b/src/asset/resources/assetserver.js index b00b6695..f9970393 100644 --- a/src/asset/resources/assetserver.js +++ b/src/asset/resources/assetserver.js @@ -235,22 +235,34 @@ export class AssetServer { */ load(type, path) { const typeId = typeid(type) + + return /** @type {Handle} */(this.loadUntyped(typeId, path, type.name)) + } + + + /** + * @param {TypeId} typeId + * @param {string} path + * @param {string} [typeName] + * @returns {import('../core/index.js').UntypedHandle} + */ + loadUntyped(typeId, path, typeName){ const baseUrl = this.basePaths.get(typeId) || '' const completePath = baseUrl + path const assets = this.assets.get(typeId) - assert(assets, `No assets registered for the asset type \`${type.name}\` on \`AssetServer\``) + assert(assets, `No assets registered for the asset type \`${typeName || ''}\` on \`AssetServer\``) const assetInfo = this.assetInfos.getByPath(completePath) if (assetInfo) { - // SAFETY: handle is generated from `Assets` backing `T` - return /** @type {Handle} */ (assets.upgrade(assetInfo.id)) + // SAFETY: handle is generated from `Assets` backing typeId + return assets.upgrade(assetInfo.id) } - // SAFETY: handle is generated from `Assets` backing `T` - const handle = /** @type {Handle} */ (assets.reserve()) + // SAFETY: handle is generated from `Assets` backing typeId + const handle = assets.reserve() const assetId = handle.id() const newAssetInfo = new AssetInfo(completePath, assetId) From 016eec9cc8dac89a2b5266d2e7262893e23e56ff Mon Sep 17 00:00:00 2001 From: waynemwashuma <94756970+waynemwashuma@users.noreply.github.com> Date: Sun, 7 Jun 2026 12:21:39 +0300 Subject: [PATCH 2/3] Change `HandleSnapshot.type` to a `TypeId` --- src/asset/core/handle.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/asset/core/handle.js b/src/asset/core/handle.js index 2f99f4ab..1bc1bf4e 100644 --- a/src/asset/core/handle.js +++ b/src/asset/core/handle.js @@ -108,7 +108,7 @@ export class HandleSnapshot { /** * @readonly - * @type {Constructor} + * @type {import('../../type/index.js').TypeId} */ type @@ -123,7 +123,7 @@ export class HandleSnapshot { * @param {AssetId | string} asset */ constructor(type, asset) { - this.type = type + this.type = typeid(type) this.asset = asset } @@ -140,10 +140,10 @@ export class HandleSnapshot { const server = world.getResource(AssetServer) if (typeof this.asset === 'string') { - return /** @type {Handle} */ (server.load(this.type, this.asset)) + return /** @type {Handle} */ (server.loadUntyped(this.type, this.asset)) } - const assets = /** @type {Assets} */ (server.getAssets(typeid(this.type))) + const assets = /** @type {Assets} */ (server.getAssets(this.type)) // TODO: This is inherently incorrect. When scene resources are added, // the assetid will point to the wrong asset in the scene due to desync between @@ -155,3 +155,7 @@ export class HandleSnapshot { return /** @type {Handle} */ (assets.upgrade(this.asset)) } } + +/** + * @typedef {Handle} UntypedHandle + */ \ No newline at end of file From 2a583e79d1dda6b365375607cc9597bfb633a3ef Mon Sep 17 00:00:00 2001 From: waynemwashuma <94756970+waynemwashuma@users.noreply.github.com> Date: Sun, 7 Jun 2026 12:32:46 +0300 Subject: [PATCH 3/3] Lint files --- src/asset/core/handle.js | 2 +- src/asset/resources/assetserver.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/asset/core/handle.js b/src/asset/core/handle.js index 1bc1bf4e..7e6d998d 100644 --- a/src/asset/core/handle.js +++ b/src/asset/core/handle.js @@ -158,4 +158,4 @@ export class HandleSnapshot { /** * @typedef {Handle} UntypedHandle - */ \ No newline at end of file + */ diff --git a/src/asset/resources/assetserver.js b/src/asset/resources/assetserver.js index f9970393..8fcc206e 100644 --- a/src/asset/resources/assetserver.js +++ b/src/asset/resources/assetserver.js @@ -239,14 +239,13 @@ export class AssetServer { return /** @type {Handle} */(this.loadUntyped(typeId, path, type.name)) } - /** * @param {TypeId} typeId * @param {string} path * @param {string} [typeName] * @returns {import('../core/index.js').UntypedHandle} */ - loadUntyped(typeId, path, typeName){ + loadUntyped(typeId, path, typeName) { const baseUrl = this.basePaths.get(typeId) || '' const completePath = baseUrl + path const assets = this.assets.get(typeId)