🆙 Lets change the way generic asset is loading WiP

This commit is contained in:
duckietm
2026-02-02 16:42:11 +01:00
parent 7b59a31b0f
commit 6a8dfc6c14
20 changed files with 25534 additions and 5 deletions
+23 -3
View File
@@ -121,6 +121,26 @@ export class AssetManager implements IAssetManager
if(texture) this.setTexture(url, texture);
}
}
else if(url.endsWith('.json'))
{
const response = await fetch(url);
if(!response || response.status !== 200) return false;
const data = await response.json() as IAssetData;
let texture: Texture = null;
const imagePath = data?.spritesheet?.meta?.image;
const fallbackImagePath = ((data?.name && data.name.length > 0)
? `${data.name}.png`
: url.replace(/\.json$/i, '.png'));
const resolvedImageUrl = (imagePath
? new URL(imagePath, url).toString()
: new URL(fallbackImagePath, url).toString());
texture = await Assets.load<Texture>(resolvedImageUrl);
await this.processAsset(texture, data);
}
else
{
const texture = await Assets.load<Texture>(url);
@@ -139,7 +159,7 @@ export class AssetManager implements IAssetManager
}
}
private async processAsset(texture: Texture, data: IAssetData): Promise<void>
private async processAsset(texture: Texture, data: IAssetData): Promise<IGraphicAssetCollection>
{
let spritesheet: Spritesheet<SpritesheetData> = null;
@@ -152,11 +172,11 @@ export class AssetManager implements IAssetManager
spritesheet.textureSource.label = data.name ?? null;
}
this.createCollection(data, spritesheet);
return this.createCollection(data, spritesheet);
}
public get collections(): Map<string, IGraphicAssetCollection>
{
return this._collections;
}
}
}
+6 -2
View File
@@ -522,7 +522,11 @@ export class RoomContentLoader implements IRoomContentLoader
private getAssetUrlWithGenericBase(assetName: string): string
{
return (GetConfiguration().getValue<string>('generic.asset.url').replace(/%libname%/gi, assetName));
const assetUrl = GetConfiguration().getValue<string>('generic.asset.url').replace(/%libname%/gi, assetName);
if(assetUrl.endsWith('.nitro')) return assetUrl.replace(/\.nitro$/i, '.json');
return assetUrl;
}
public getAssetUrlWithFurniBase(assetName: string): string
@@ -558,4 +562,4 @@ export class RoomContentLoader implements IRoomContentLoader
{
return this._pets;
}
}
}