Fix custom character lazy loading
This commit is contained in:
parent
3d84a9c8cd
commit
d93a8da828
@ -23,21 +23,25 @@ export const loadAllDefaultModels = (load: LoaderPlugin): BodyResourceDescriptio
|
|||||||
});
|
});
|
||||||
return returnArray;
|
return returnArray;
|
||||||
}
|
}
|
||||||
export const loadCustomTexture = (load: LoaderPlugin, texture: CharacterTexture) => {
|
export const loadCustomTexture = (load: LoaderPlugin, texture: CharacterTexture) : Promise<BodyResourceDescriptionInterface> => {
|
||||||
const name = 'customCharacterTexture'+texture.id;
|
const name = 'customCharacterTexture'+texture.id;
|
||||||
load.spritesheet(name,texture.url,{frameWidth: 32, frameHeight: 32});
|
return createLoadingPromise(load, {name, img: texture.url}).then(() => {
|
||||||
return name;
|
return {name: name, img: texture.url}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {
|
||||||
|
try {
|
||||||
const playerResourceDescriptor = getRessourceDescriptor(textureKey);
|
const playerResourceDescriptor = getRessourceDescriptor(textureKey);
|
||||||
if(!texturePlugin.exists(playerResourceDescriptor.name)) {
|
if (playerResourceDescriptor && !texturePlugin.exists(playerResourceDescriptor.name)) {
|
||||||
console.log('Loading '+playerResourceDescriptor.name)
|
|
||||||
promisesList.push(createLoadingPromise(loadPlugin, playerResourceDescriptor));
|
promisesList.push(createLoadingPromise(loadPlugin, playerResourceDescriptor));
|
||||||
}
|
}
|
||||||
})
|
}catch (err){
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
let returnPromise:Promise<Array<string|BodyResourceDescriptionInterface>>;
|
let returnPromise:Promise<Array<string|BodyResourceDescriptionInterface>>;
|
||||||
if (promisesList.length > 0) {
|
if (promisesList.length > 0) {
|
||||||
loadPlugin.start();
|
loadPlugin.start();
|
||||||
|
@ -30,7 +30,7 @@ import {RemotePlayer} from "../Entity/RemotePlayer";
|
|||||||
import {Queue} from 'queue-typescript';
|
import {Queue} from 'queue-typescript';
|
||||||
import {SimplePeer, UserSimplePeerInterface} from "../../WebRtc/SimplePeer";
|
import {SimplePeer, UserSimplePeerInterface} from "../../WebRtc/SimplePeer";
|
||||||
import {ReconnectingSceneName} from "../Reconnecting/ReconnectingScene";
|
import {ReconnectingSceneName} from "../Reconnecting/ReconnectingScene";
|
||||||
import {lazyLoadPlayerCharacterTextures} from "../Entity/PlayerTexturesLoadingManager";
|
import {lazyLoadPlayerCharacterTextures, loadCustomTexture} from "../Entity/PlayerTexturesLoadingManager";
|
||||||
import {
|
import {
|
||||||
CenterListener,
|
CenterListener,
|
||||||
layoutManager,
|
layoutManager,
|
||||||
@ -67,6 +67,8 @@ import {SelectCharacterScene, SelectCharacterSceneName} from "../Login/SelectCha
|
|||||||
import {TextureError} from "../../Exception/TextureError";
|
import {TextureError} from "../../Exception/TextureError";
|
||||||
import {addLoader} from "../Components/Loader";
|
import {addLoader} from "../Components/Loader";
|
||||||
import {ErrorSceneName} from "../Reconnecting/ErrorScene";
|
import {ErrorSceneName} from "../Reconnecting/ErrorScene";
|
||||||
|
import {localUserStore} from "../../Connexion/LocalUserStore";
|
||||||
|
import {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures";
|
||||||
|
|
||||||
export interface GameSceneInitInterface {
|
export interface GameSceneInitInterface {
|
||||||
initPosition: PointInterface|null,
|
initPosition: PointInterface|null,
|
||||||
@ -182,6 +184,13 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||||||
//hook preload scene
|
//hook preload scene
|
||||||
preload(): void {
|
preload(): void {
|
||||||
addLoader(this);
|
addLoader(this);
|
||||||
|
const localUser = localUserStore.getLocalUser();
|
||||||
|
const textures = localUser?.textures;
|
||||||
|
if (textures) {
|
||||||
|
for (const texture of textures) {
|
||||||
|
loadCustomTexture(this.load, texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.load.image(openChatIconName, 'resources/objects/talk.png');
|
this.load.image(openChatIconName, 'resources/objects/talk.png');
|
||||||
this.load.on(FILE_LOAD_ERROR, (file: {src: string}) => {
|
this.load.on(FILE_LOAD_ERROR, (file: {src: string}) => {
|
||||||
|
@ -63,11 +63,8 @@ export class CustomizeScene extends ResizableScene {
|
|||||||
if(texture.level === -1){
|
if(texture.level === -1){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
loadCustomTexture(this.load, texture);
|
loadCustomTexture(this.load, texture).then((bodyResourceDescription: BodyResourceDescriptionInterface) => {
|
||||||
const name = 'customCharacterTexture'+texture.id;
|
this.layers[texture.level].unshift(bodyResourceDescription);
|
||||||
this.layers[texture.level].unshift({
|
|
||||||
name,
|
|
||||||
img: texture.url
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,8 +59,9 @@ export class SelectCharacterScene extends ResizableScene {
|
|||||||
if(texture.level !== -1){
|
if(texture.level !== -1){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const name = loadCustomTexture(this.load, texture);
|
loadCustomTexture(this.load, texture).then((bodyResourceDescription: BodyResourceDescriptionInterface) => {
|
||||||
this.playerModels.push({name: name, img: texture.url});
|
this.playerModels.push(bodyResourceDescription);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user