mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2025-01-19 06:46:28 +01:00
Wait for base texture to be valid
This commit is contained in:
parent
569bce07bf
commit
2021e22bb3
@ -172,20 +172,36 @@ export class AssetManager extends Disposable implements IAssetManager
|
|||||||
|
|
||||||
this.processAsset(nitroBundle.baseTexture, (nitroBundle.jsonFile as IAssetData), status =>
|
this.processAsset(nitroBundle.baseTexture, (nitroBundle.jsonFile as IAssetData), status =>
|
||||||
{
|
{
|
||||||
onDownloaded(true, resource.url);
|
onDownloaded(status, resource.url);
|
||||||
});
|
});
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(resourceType === 'image/png')
|
if((resourceType === 'image/png') || (resourceType === 'image/gif'))
|
||||||
{
|
{
|
||||||
const base64 = ArrayBufferToBase64(resource.data);
|
const base64 = ArrayBufferToBase64(resource.data);
|
||||||
const texture = new Texture(new BaseTexture('data:image/png;base64,' + base64));
|
const baseTexture = new BaseTexture(`data:${ resourceType };base64,${ base64 }`);
|
||||||
|
|
||||||
this.setTexture(resource.name, texture);
|
if(baseTexture.valid)
|
||||||
|
{
|
||||||
|
const texture = new Texture(baseTexture);
|
||||||
|
|
||||||
onDownloaded(true, resource.url);
|
this.setTexture(resource.name, texture);
|
||||||
|
|
||||||
|
onDownloaded(true, resource.url);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
baseTexture.once('update', () =>
|
||||||
|
{
|
||||||
|
const texture = new Texture(baseTexture);
|
||||||
|
|
||||||
|
this.setTexture(resource.name, texture);
|
||||||
|
|
||||||
|
onDownloaded(true, resource.url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -199,7 +215,16 @@ export class AssetManager extends Disposable implements IAssetManager
|
|||||||
{
|
{
|
||||||
const spritesheetData = data.spritesheet;
|
const spritesheetData = data.spritesheet;
|
||||||
|
|
||||||
if(spritesheetData && Object.keys(spritesheetData).length)
|
if(!baseTexture || !spritesheetData || !Object.keys(spritesheetData).length)
|
||||||
|
{
|
||||||
|
this.createCollection(data, null);
|
||||||
|
|
||||||
|
onDownloaded(true);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const createAsset = () =>
|
||||||
{
|
{
|
||||||
const spritesheet = new Spritesheet(baseTexture, spritesheetData);
|
const spritesheet = new Spritesheet(baseTexture, spritesheetData);
|
||||||
|
|
||||||
@ -209,13 +234,16 @@ export class AssetManager extends Disposable implements IAssetManager
|
|||||||
|
|
||||||
onDownloaded(true);
|
onDownloaded(true);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return;
|
if(baseTexture.valid)
|
||||||
|
{
|
||||||
|
createAsset();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
baseTexture.once('update', () => createAsset());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createCollection(data, null);
|
|
||||||
|
|
||||||
onDownloaded(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get collections(): Map<string, IGraphicAssetCollection>
|
public get collections(): Map<string, IGraphicAssetCollection>
|
||||||
|
@ -516,13 +516,14 @@ export class RoomContentLoader implements IFurnitureDataListener
|
|||||||
|
|
||||||
for(const url of assetUrls)
|
for(const url of assetUrls)
|
||||||
{
|
{
|
||||||
if(!url || !url.endsWith('.nitro')) continue;
|
if(!url || !url.length) continue;
|
||||||
|
|
||||||
loader
|
loader
|
||||||
.add({
|
.add({
|
||||||
url,
|
url,
|
||||||
crossOrigin: 'anonymous',
|
crossOrigin: 'anonymous',
|
||||||
xhrType: url.endsWith('.nitro') ? LoaderResource.XHR_RESPONSE_TYPE.BUFFER : LoaderResource.XHR_RESPONSE_TYPE.JSON
|
loadType: LoaderResource.LOAD_TYPE.XHR,
|
||||||
|
xhrType: LoaderResource.XHR_RESPONSE_TYPE.BUFFER
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,20 +564,22 @@ export class RoomContentLoader implements IFurnitureDataListener
|
|||||||
{
|
{
|
||||||
const resource = resources[key];
|
const resource = resources[key];
|
||||||
|
|
||||||
if(!resource || resource.error)
|
if(!resource || resource.error || !resource.xhr)
|
||||||
{
|
{
|
||||||
onDownloaded(false, resource.url);
|
onDownloaded(false, resource.url);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(resource.extension === 'nitro')
|
const resourceType = resource.xhr.getResponseHeader('Content-Type');
|
||||||
|
|
||||||
|
if(resourceType === 'application/octet-stream')
|
||||||
{
|
{
|
||||||
const nitroBundle = new NitroBundle(resource.data);
|
const nitroBundle = new NitroBundle(resource.data);
|
||||||
|
|
||||||
this.processAsset(nitroBundle.baseTexture, (nitroBundle.jsonFile as IAssetData), status =>
|
this.processAsset(nitroBundle.baseTexture, (nitroBundle.jsonFile as IAssetData), status =>
|
||||||
{
|
{
|
||||||
onDownloaded(true, resource.url);
|
onDownloaded(status, resource.url);
|
||||||
});
|
});
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -589,7 +592,16 @@ export class RoomContentLoader implements IFurnitureDataListener
|
|||||||
{
|
{
|
||||||
const spritesheetData = data.spritesheet;
|
const spritesheetData = data.spritesheet;
|
||||||
|
|
||||||
if(spritesheetData && Object.keys(spritesheetData).length)
|
if(!baseTexture || !spritesheetData || !Object.keys(spritesheetData).length)
|
||||||
|
{
|
||||||
|
this.createCollection(data, null);
|
||||||
|
|
||||||
|
onDownloaded(true);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const createAsset = () =>
|
||||||
{
|
{
|
||||||
const spritesheet = new Spritesheet(baseTexture, spritesheetData);
|
const spritesheet = new Spritesheet(baseTexture, spritesheetData);
|
||||||
|
|
||||||
@ -599,13 +611,16 @@ export class RoomContentLoader implements IFurnitureDataListener
|
|||||||
|
|
||||||
onDownloaded(true);
|
onDownloaded(true);
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return;
|
if(baseTexture.valid)
|
||||||
|
{
|
||||||
|
createAsset();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
baseTexture.once('update', () => createAsset());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createCollection(data, null);
|
|
||||||
|
|
||||||
onDownloaded(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setAssetAliasName(name: string, originalName: string): void
|
public setAssetAliasName(name: string, originalName: string): void
|
||||||
|
Loading…
Reference in New Issue
Block a user