getting textures urls from pusher

This commit is contained in:
Hanusiak Piotr
2022-02-22 14:32:47 +01:00
committed by David Négrier
parent 2161a40e05
commit 80761804a7
6 changed files with 112 additions and 437 deletions
@@ -1,6 +1,6 @@
import LoaderPlugin = Phaser.Loader.LoaderPlugin;
import type { CharacterTexture } from "../../Connexion/LocalUser";
import { BodyResourceDescriptionInterface, LAYERS, PLAYER_RESOURCES } from "./PlayerTextures";
import { BodyResourceDescriptionInterface, PlayerTextures } from "./PlayerTextures";
import CancelablePromise from "cancelable-promise";
export interface FrameConfig {
@@ -10,7 +10,7 @@ export interface FrameConfig {
export const loadAllLayers = (load: LoaderPlugin): BodyResourceDescriptionInterface[][] => {
const returnArray: BodyResourceDescriptionInterface[][] = [];
LAYERS.forEach((layer) => {
PlayerTextures.LAYERS.forEach((layer) => {
const layerArray: BodyResourceDescriptionInterface[] = [];
Object.values(layer).forEach((textureDescriptor) => {
layerArray.push(textureDescriptor);
@@ -21,7 +21,7 @@ export const loadAllLayers = (load: LoaderPlugin): BodyResourceDescriptionInterf
return returnArray;
};
export const loadAllDefaultModels = (load: LoaderPlugin): BodyResourceDescriptionInterface[] => {
const returnArray = Object.values(PLAYER_RESOURCES);
const returnArray = Object.values(PlayerTextures.PLAYER_RESOURCES);
returnArray.forEach((playerResource: BodyResourceDescriptionInterface) => {
load.spritesheet(playerResource.name, playerResource.img, { frameWidth: 32, frameHeight: 32 });
});
@@ -84,11 +84,11 @@ export const getRessourceDescriptor = (
return textureKey;
}
const textureName: string = typeof textureKey === "string" ? textureKey : textureKey.name;
const playerResource = PLAYER_RESOURCES[textureName];
const playerResource = PlayerTextures.PLAYER_RESOURCES[textureName];
if (playerResource !== undefined) return playerResource;
for (let i = 0; i < LAYERS.length; i++) {
const playerResource = LAYERS[i][textureName];
for (let i = 0; i < PlayerTextures.LAYERS.length; i++) {
const playerResource = PlayerTextures.LAYERS[i][textureName];
if (playerResource !== undefined) return playerResource;
}
throw new Error("Could not find a data for texture " + textureName);