commit
92246df8b6
@ -32,10 +32,9 @@ export const loadCustomTexture = (load: LoaderPlugin, texture: CharacterTexture)
|
||||
export const lazyLoadPlayerCharacterTextures = (loadPlugin: LoaderPlugin, texturePlugin: TextureManager, texturekeys:Array<string|BodyResourceDescriptionInterface>): Promise<string[]> => {
|
||||
const promisesList:Promise<void>[] = [];
|
||||
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<LAYERS.length;i++) {
|
||||
const playerResource = LAYERS[i][textureKey];
|
||||
const playerResource = LAYERS[i][textureName];
|
||||
if (playerResource !== undefined) return playerResource;
|
||||
}
|
||||
throw 'Could not find a data for texture '+textureKey;
|
||||
throw 'Could not find a data for texture '+textureName;
|
||||
}
|
||||
|
||||
const createLoadingPromise = (loadPlugin: LoaderPlugin, playerResourceDescriptor: BodyResourceDescriptionInterface) => {
|
||||
|
28
front/tests/Phaser/Game/PlayerTexturesLoadingTest.ts
Normal file
28
front/tests/Phaser/Game/PlayerTexturesLoadingTest.ts
Normal file
@ -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");
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user