diff --git a/src/asset/core/handle.js b/src/asset/core/handle.js index 2f99f4ab..7e6d998d 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 + */ diff --git a/src/asset/resources/assetserver.js b/src/asset/resources/assetserver.js index b00b6695..8fcc206e 100644 --- a/src/asset/resources/assetserver.js +++ b/src/asset/resources/assetserver.js @@ -235,22 +235,33 @@ 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)