You've already forked Nitro_Render_V3
mirror of
https://github.com/duckietm/Nitro_Render_V3.git
synced 2026-06-19 15:06:20 +00:00
🆙 Lets change the way generic asset is loading WiP
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user