Verify existing texture

This commit is contained in:
Gregoire Parant 2021-01-26 09:16:39 +01:00
parent 803be36def
commit e2695c58af
1 changed files with 5 additions and 6 deletions

View File

@ -26,12 +26,7 @@ export const loadAllDefaultModels = (load: LoaderPlugin): BodyResourceDescriptio
export const loadCustomTexture = (loaderPlugin: LoaderPlugin, texture: CharacterTexture) : Promise<BodyResourceDescriptionInterface> => {
const name = 'customCharacterTexture'+texture.id;
const playerResourceDescriptor: BodyResourceDescriptionInterface = {name, img: texture.url, level: texture.level}
return new Promise<BodyResourceDescriptionInterface>((solve) => {
loaderPlugin.spritesheet(playerResourceDescriptor.name, playerResourceDescriptor.img, {frameWidth: 32, frameHeight: 32});
solve(playerResourceDescriptor);
});
//TODO refactor and use lasy loading
//return createLoadingPromise(loaderPlugin, {name, img: texture.url, level: texture.level});
return createLoadingPromise(loaderPlugin, playerResourceDescriptor);
}
export const lazyLoadPlayerCharacterTextures = (loadPlugin: LoaderPlugin, texturePlugin: TextureManager, texturekeys:Array<string|BodyResourceDescriptionInterface>): Promise<string[]> => {
@ -75,6 +70,10 @@ export const getRessourceDescriptor = (textureKey: string|BodyResourceDescriptio
const createLoadingPromise = (loadPlugin: LoaderPlugin, playerResourceDescriptor: BodyResourceDescriptionInterface) => {
return new Promise<BodyResourceDescriptionInterface>((res) => {
const texture = loadPlugin.textureManager.get(playerResourceDescriptor.name);
if(texture.key !== '__MISSING'){
return res(playerResourceDescriptor);
}
loadPlugin.spritesheet(playerResourceDescriptor.name, playerResourceDescriptor.img, {frameWidth: 32, frameHeight: 32});
loadPlugin.once('filecomplete-spritesheet-'+playerResourceDescriptor.name, () => res(playerResourceDescriptor));
});