Merge branch 'develop' into feature-options-menu

This commit is contained in:
Hanusiak Piotr 2022-02-02 09:31:10 +01:00
commit 0eaeaf7cfb
20 changed files with 104 additions and 26 deletions

View file

@ -16,6 +16,7 @@ import type { PictureStore } from "../../Stores/PictureStore";
import { Unsubscriber, Writable, writable } from "svelte/store";
import { createColorStore } from "../../Stores/OutlineColorStore";
import type { OutlineableInterface } from '../Game/OutlineableInterface';
import type CancelablePromise from "cancelable-promise";
const playerNameY = -25;
@ -45,12 +46,13 @@ export abstract class Character extends Container implements OutlineableInterfac
private readonly _pictureStore: Writable<string | undefined>;
private readonly outlineColorStore = createColorStore();
private readonly outlineColorStoreUnsubscribe: Unsubscriber;
private texturePromise: CancelablePromise<string[] | void> | undefined;
constructor(
scene: GameScene,
x: number,
y: number,
texturesPromise: Promise<string[]>,
texturesPromise: CancelablePromise<string[]>,
name: string,
direction: PlayerAnimationDirections,
moving: boolean,
@ -69,7 +71,7 @@ export abstract class Character extends Container implements OutlineableInterfac
this._pictureStore = writable(undefined);
//textures are inside a Promise in case they need to be lazyloaded before use.
texturesPromise
this.texturePromise = texturesPromise
.then((textures) => {
this.addTextures(textures, frame);
this.invisible = false;
@ -84,6 +86,9 @@ export abstract class Character extends Container implements OutlineableInterfac
this.invisible = false;
this.playAnimation(direction, moving);
});
})
.finally(() => {
this.texturePromise = undefined;
});
this.playerNameText = new Text(scene, 0, playerNameY, name, {
@ -344,6 +349,7 @@ export abstract class Character extends Container implements OutlineableInterfac
this.scene.sys.updateList.remove(sprite);
}
}
this.texturePromise?.cancel();
this.list.forEach((objectContaining) => objectContaining.destroy());
this.outlineColorStoreUnsubscribe();
super.destroy();