don't fail if companion texture is not found
This commit is contained in:
parent
c07079051a
commit
fc3a503bcf
@ -36,10 +36,12 @@ export class Companion extends Container {
|
|||||||
|
|
||||||
this.companionName = name;
|
this.companionName = name;
|
||||||
|
|
||||||
lazyLoadResource(this.scene.load, this.companionName).then(resource => {
|
lazyLoadResource(this.scene.load, this.companionName)
|
||||||
this.addResource(resource);
|
.then(resource => {
|
||||||
this.invisible = false;
|
this.addResource(resource);
|
||||||
})
|
this.invisible = false;
|
||||||
|
})
|
||||||
|
.catch(error => console.error(error));
|
||||||
|
|
||||||
this.scene.physics.world.enableBody(this);
|
this.scene.physics.world.enableBody(this);
|
||||||
|
|
||||||
|
@ -13,17 +13,17 @@ export const loadAll = (loader: LoaderPlugin): CompanionResourceDescriptionInter
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const lazyLoadResource = (loader: LoaderPlugin, name: string): Promise<string> => {
|
export const lazyLoadResource = (loader: LoaderPlugin, name: string): Promise<string> => {
|
||||||
const resource = COMPANION_RESOURCES.find(item => item.name === name);
|
return new Promise((resolve, reject) => {
|
||||||
|
const resource = COMPANION_RESOURCES.find(item => item.name === name);
|
||||||
|
|
||||||
if (typeof resource === 'undefined') {
|
if (typeof resource === 'undefined') {
|
||||||
throw new TextureError(`Texture '${name}' not found!`);
|
return reject(`Texture '${name}' not found!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loader.textureManager.exists(resource.name)) {
|
if (loader.textureManager.exists(resource.name)) {
|
||||||
return Promise.resolve(resource.name);
|
return resolve(resource.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise(resolve => {
|
|
||||||
loader.spritesheet(resource.name, resource.img, { frameWidth: 32, frameHeight: 32, endFrame: 12 });
|
loader.spritesheet(resource.name, resource.img, { frameWidth: 32, frameHeight: 32, endFrame: 12 });
|
||||||
loader.once(`filecomplete-spritesheet-${resource.name}`, () => resolve(resource.name));
|
loader.once(`filecomplete-spritesheet-${resource.name}`, () => resolve(resource.name));
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user