Remove asset type check

This commit is contained in:
Bill 2021-12-25 17:11:37 -05:00
parent a1ae6a384f
commit 0ac8aac5fb
2 changed files with 5 additions and 143 deletions

View File

@ -1,4 +1,4 @@
import { BaseTexture, Resource, Texture } from '@pixi/core'; import { Resource, Texture } from '@pixi/core';
import { Loader, LoaderResource } from '@pixi/loaders'; import { Loader, LoaderResource } from '@pixi/loaders';
import { Spritesheet } from '@pixi/spritesheet'; import { Spritesheet } from '@pixi/spritesheet';
import { IGraphicAsset } from '../../room'; import { IGraphicAsset } from '../../room';
@ -170,7 +170,7 @@ export class AssetManager extends Disposable implements IAssetManager
const nitroBundle = new NitroBundle(resource.data); const nitroBundle = new NitroBundle(resource.data);
const assetData = (nitroBundle.jsonFile as IAssetData); const assetData = (nitroBundle.jsonFile as IAssetData);
if(!assetData || !assetData.type) if(!assetData)
{ {
onDownloaded(loader, resource, false); onDownloaded(loader, resource, false);
@ -231,77 +231,7 @@ export class AssetManager extends Disposable implements IAssetManager
onDownloaded(loader, resource, true); onDownloaded(loader, resource, true);
} }
else if(resource.type === LoaderResource.TYPE.JSON) else if(resource.type === LoaderResource.TYPE.IMAGE)
{
const assetData = (resource.data as IAssetData);
if(!assetData || !assetData.type)
{
onDownloaded(loader, resource, false);
return;
}
if(assetData.spritesheet && Object.keys(assetData.spritesheet).length)
{
const imageName = (assetData.spritesheet.meta && assetData.spritesheet.meta.image);
if(!imageName || !imageName.length)
{
onDownloaded(loader, resource, false);
return;
}
const imageUrl = (resource.url.substring(0, (resource.url.lastIndexOf('/') + 1)) + imageName);
const baseTexture = BaseTexture.from(imageUrl);
if(baseTexture.valid)
{
const spritesheet = new Spritesheet(baseTexture, assetData.spritesheet);
spritesheet.parse(() =>
{
this.createCollection(assetData, spritesheet);
onDownloaded(loader, resource, true);
});
}
else
{
baseTexture.once('loaded', () =>
{
baseTexture.removeAllListeners();
const spritesheet = new Spritesheet(baseTexture, assetData.spritesheet);
spritesheet.parse(() =>
{
this.createCollection(assetData, spritesheet);
onDownloaded(loader, resource, true);
});
});
baseTexture.once('error', () =>
{
baseTexture.removeAllListeners();
onDownloaded(loader, resource, false);
});
}
return;
}
this.createCollection(assetData, null);
onDownloaded(loader, resource, true);
return;
}
if(resource.type === LoaderResource.TYPE.IMAGE)
{ {
if(resource.texture.valid) if(resource.texture.valid)
{ {

View File

@ -1,4 +1,4 @@
import { BaseTexture, Resource, Texture } from '@pixi/core'; import { Resource, Texture } from '@pixi/core';
import { Loader, LoaderResource } from '@pixi/loaders'; import { Loader, LoaderResource } from '@pixi/loaders';
import { Spritesheet } from '@pixi/spritesheet'; import { Spritesheet } from '@pixi/spritesheet';
import { IAssetData } from '../../core/asset/interfaces'; import { IAssetData } from '../../core/asset/interfaces';
@ -559,7 +559,7 @@ export class RoomContentLoader implements IFurnitureDataListener
const nitroBundle = new NitroBundle(resource.data); const nitroBundle = new NitroBundle(resource.data);
const assetData = (nitroBundle.jsonFile as IAssetData); const assetData = (nitroBundle.jsonFile as IAssetData);
if(!assetData || !assetData.type) if(!assetData)
{ {
onDownloaded(loader, resource, false); onDownloaded(loader, resource, false);
@ -619,74 +619,6 @@ export class RoomContentLoader implements IFurnitureDataListener
onDownloaded(loader, resource, true); onDownloaded(loader, resource, true);
} }
else if(resource.type === LoaderResource.TYPE.JSON)
{
const assetData = (resource.data as IAssetData);
if(!assetData.type)
{
onDownloaded(loader, resource, false);
return;
}
if(assetData.spritesheet && Object.keys(assetData.spritesheet).length)
{
const imageName = (assetData.spritesheet.meta && assetData.spritesheet.meta.image);
if(!imageName || !imageName.length)
{
onDownloaded(loader, resource, false);
return;
}
const imageUrl = (resource.url.substring(0, (resource.url.lastIndexOf('/') + 1)) + imageName);
const baseTexture = BaseTexture.from(imageUrl);
if(baseTexture.valid)
{
const spritesheet = new Spritesheet(baseTexture, assetData.spritesheet);
spritesheet.parse(() =>
{
this.createCollection(assetData, spritesheet);
onDownloaded(loader, resource, true);
});
}
else
{
baseTexture.once('loaded', () =>
{
baseTexture.removeAllListeners();
const spritesheet = new Spritesheet(baseTexture, assetData.spritesheet);
spritesheet.parse(() =>
{
this.createCollection(assetData, spritesheet);
onDownloaded(loader, resource, true);
});
});
baseTexture.once('error', () =>
{
baseTexture.removeAllListeners();
onDownloaded(loader, resource, false);
});
}
return;
}
this.createCollection(assetData, null);
onDownloaded(loader, resource, true);
}
else else
{ {
onDownloaded(loader, resource, false); onDownloaded(loader, resource, false);