Merge remote-tracking branch 'upstream/develop' into develop

This commit is contained in:
Thomas Basler 2021-01-14 20:21:29 +01:00
commit 572febea54
2 changed files with 39 additions and 9 deletions

View File

@ -32,10 +32,9 @@ export const loadCustomTexture = (load: LoaderPlugin, texture: CharacterTexture)
export const lazyLoadPlayerCharacterTextures = (loadPlugin: LoaderPlugin, texturePlugin: TextureManager, texturekeys:Array<string|BodyResourceDescriptionInterface>): Promise<string[]> => { export const lazyLoadPlayerCharacterTextures = (loadPlugin: LoaderPlugin, texturePlugin: TextureManager, texturekeys:Array<string|BodyResourceDescriptionInterface>): Promise<string[]> => {
const promisesList:Promise<void>[] = []; const promisesList:Promise<void>[] = [];
texturekeys.forEach((textureKey: string|BodyResourceDescriptionInterface) => { texturekeys.forEach((textureKey: string|BodyResourceDescriptionInterface) => {
const textureName = typeof textureKey === 'string' ? textureKey : textureKey.name; const playerResourceDescriptor = getRessourceDescriptor(textureKey);
if(!texturePlugin.exists(textureName)) { if(!texturePlugin.exists(playerResourceDescriptor.name)) {
console.log('Loading '+textureName) console.log('Loading '+playerResourceDescriptor.name)
const playerResourceDescriptor = typeof textureKey === 'string' ? getRessourceDescriptor(textureKey) : textureKey;
promisesList.push(createLoadingPromise(loadPlugin, playerResourceDescriptor)); promisesList.push(createLoadingPromise(loadPlugin, playerResourceDescriptor));
} }
}) })
@ -51,16 +50,19 @@ export const lazyLoadPlayerCharacterTextures = (loadPlugin: LoaderPlugin, textur
})) }))
} }
export const getRessourceDescriptor = (textureKey: string|BodyResourceDescriptionInterface): BodyResourceDescriptionInterface => {
const getRessourceDescriptor = (textureKey: string): BodyResourceDescriptionInterface => { if (typeof textureKey !== 'string' && textureKey.img) {
const playerResource = PLAYER_RESOURCES[textureKey]; return textureKey;
}
const textureName:string = typeof textureKey === 'string' ? textureKey : textureKey.name;
const playerResource = PLAYER_RESOURCES[textureName];
if (playerResource !== undefined) return playerResource; if (playerResource !== undefined) return playerResource;
for (let i=0; i<LAYERS.length;i++) { for (let i=0; i<LAYERS.length;i++) {
const playerResource = LAYERS[i][textureKey]; const playerResource = LAYERS[i][textureName];
if (playerResource !== undefined) return playerResource; 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) => { const createLoadingPromise = (loadPlugin: LoaderPlugin, playerResourceDescriptor: BodyResourceDescriptionInterface) => {

View 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");
});
});