Add function to AssetManager

This commit is contained in:
Bill 2024-07-13 14:52:08 -04:00
parent 8d9c11ff6e
commit 2b5b1fe6ab
2 changed files with 22 additions and 0 deletions

View File

@ -12,6 +12,7 @@ export interface IAssetManager
getAsset(name: string): IGraphicAsset;
getCollection(name: string): IGraphicAssetCollection;
createCollection(data: IAssetData, spritesheet: Spritesheet): IGraphicAssetCollection;
loadTextureFromUrl(url: string, name?: string): Promise<Texture>
downloadAssets(urls: string[]): Promise<boolean>;
downloadAsset(url: string): Promise<boolean>;
readonly collections: Map<string, IGraphicAssetCollection>;

View File

@ -74,6 +74,27 @@ export class AssetManager implements IAssetManager
return collection;
}
public async loadTextureFromUrl(url: string, name: string = null): Promise<Texture>
{
if(!url || !url.length) return null;
try
{
const texture = await Assets.load<Texture>(url);
if(!texture) return null;
this.setTexture(name ?? url, texture);
return texture;
}
catch (err)
{
NitroLogger.error(err);
}
}
public async downloadAssets(urls: string[]): Promise<boolean>
{
if(!urls || !urls.length) return Promise.resolve(true);