diff --git a/front/src/Phaser/Entity/PlayerTexturesLoadingManager.ts b/front/src/Phaser/Entity/PlayerTexturesLoadingManager.ts index c2a421e5..776d1f5c 100644 --- a/front/src/Phaser/Entity/PlayerTexturesLoadingManager.ts +++ b/front/src/Phaser/Entity/PlayerTexturesLoadingManager.ts @@ -32,10 +32,9 @@ export const loadCustomTexture = (load: LoaderPlugin, texture: CharacterTexture) export const lazyLoadPlayerCharacterTextures = (loadPlugin: LoaderPlugin, texturePlugin: TextureManager, texturekeys:Array): Promise => { const promisesList:Promise[] = []; texturekeys.forEach((textureKey: string|BodyResourceDescriptionInterface) => { - const textureName = typeof textureKey === 'string' ? textureKey : textureKey.name; - if(!texturePlugin.exists(textureName)) { - console.log('Loading '+textureName) - const playerResourceDescriptor = typeof textureKey === 'string' ? getRessourceDescriptor(textureKey) : textureKey; + const playerResourceDescriptor = getRessourceDescriptor(textureKey); + if(!texturePlugin.exists(playerResourceDescriptor.name)) { + console.log('Loading '+playerResourceDescriptor.name) promisesList.push(createLoadingPromise(loadPlugin, playerResourceDescriptor)); } }) @@ -51,16 +50,19 @@ export const lazyLoadPlayerCharacterTextures = (loadPlugin: LoaderPlugin, textur })) } - -const getRessourceDescriptor = (textureKey: string): BodyResourceDescriptionInterface => { - const playerResource = PLAYER_RESOURCES[textureKey]; +export const getRessourceDescriptor = (textureKey: string|BodyResourceDescriptionInterface): BodyResourceDescriptionInterface => { + if (typeof textureKey !== 'string' && textureKey.img) { + return textureKey; + } + const textureName:string = typeof textureKey === 'string' ? textureKey : textureKey.name; + const playerResource = PLAYER_RESOURCES[textureName]; if (playerResource !== undefined) return playerResource; for (let i=0; i { diff --git a/front/tests/Phaser/Game/PlayerTexturesLoadingTest.ts b/front/tests/Phaser/Game/PlayerTexturesLoadingTest.ts new file mode 100644 index 00000000..d58d55db --- /dev/null +++ b/front/tests/Phaser/Game/PlayerTexturesLoadingTest.ts @@ -0,0 +1,28 @@ +import "jasmine"; +import {getRessourceDescriptor} from "../../../src/Phaser/Entity/PlayerTexturesLoadingManager"; + +describe("getRessourceDescriptor()", () => { + it(", if given a valid descriptor as parameter, should return it", () => { + const desc = getRessourceDescriptor({name: 'name', img: 'url'}); + expect(desc.name).toEqual('name'); + expect(desc.img).toEqual('url'); + }); + + it(", if given a string as parameter, should search trough hardcoded values", () => { + const desc = getRessourceDescriptor('male1'); + expect(desc.name).toEqual('male1'); + expect(desc.img).toEqual("resources/characters/pipoya/Male 01-1.png"); + }); + + it(", if given a string as parameter, should search trough hardcoded values (bis)", () => { + const desc = getRessourceDescriptor('color_2'); + expect(desc.name).toEqual('color_2'); + expect(desc.img).toEqual("resources/customisation/character_color/character_color1.png"); + }); + + it(", if given a descriptor without url as parameter, should search trough hardcoded values", () => { + const desc = getRessourceDescriptor({name: 'male1', img: ''}); + expect(desc.name).toEqual('male1'); + expect(desc.img).toEqual("resources/characters/pipoya/Male 01-1.png"); + }); +}); \ No newline at end of file