mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-10-23 05:25:58 +02:00
* Extract Mode enum out of UI and into its own file Reduces circular imports from 909 to 773 * Move around utility files Reduces cyclical dependencies from 773 to 765 * Remove starterColors and bypassLogin from battle-scene Reduces cyclical dependencies from 765 to 623 * Fix test runner error * Update import for bypassLogin in test * Update mocks for utils in tests * Fix broken tests * Update selectWithTera override * Update path for utils in ab-attr.ts * Update path for utils in ability-class.ts * Fix utils import path in healer.test.ts
113 lines
2.8 KiB
TypeScript
113 lines
2.8 KiB
TypeScript
import { globalScene } from "#app/global-scene";
|
|
import { MissingTextureKey } from "#app/utils/common";
|
|
|
|
export default class CharSprite extends Phaser.GameObjects.Container {
|
|
private sprite: Phaser.GameObjects.Sprite;
|
|
private transitionSprite: Phaser.GameObjects.Sprite;
|
|
|
|
public key: string;
|
|
public variant: string;
|
|
public shown: boolean;
|
|
|
|
constructor() {
|
|
super(globalScene, globalScene.game.canvas.width / 6 + 32, -42);
|
|
}
|
|
|
|
setup(): void {
|
|
[this.sprite, this.transitionSprite] = new Array(2).fill(null).map(() => {
|
|
const ret = globalScene.add.sprite(0, 0, "", "");
|
|
ret.setOrigin(0.5, 1);
|
|
this.add(ret);
|
|
return ret;
|
|
});
|
|
|
|
this.transitionSprite.setVisible(false);
|
|
|
|
this.setVisible(false);
|
|
this.shown = false;
|
|
}
|
|
|
|
showCharacter(key: string, variant: string): Promise<void> {
|
|
return new Promise(resolve => {
|
|
if (!key.startsWith("c_")) {
|
|
key = `c_${key}`;
|
|
}
|
|
if (this.shown) {
|
|
if (key === this.key && variant === this.variant) {
|
|
return resolve();
|
|
}
|
|
if (key !== this.key) {
|
|
return this.hide().then(() => this.showCharacter(key, variant));
|
|
}
|
|
this.setVariant(variant).then(() => resolve());
|
|
return;
|
|
}
|
|
|
|
this.sprite.setTexture(key, variant);
|
|
|
|
globalScene.fieldUI.bringToTop(this);
|
|
|
|
globalScene.tweens.add({
|
|
targets: this,
|
|
x: globalScene.game.canvas.width / 6 - 102,
|
|
duration: 750,
|
|
ease: "Cubic.easeOut",
|
|
onComplete: () => {
|
|
resolve();
|
|
},
|
|
});
|
|
|
|
this.setVisible(globalScene.textures.get(key).key !== MissingTextureKey);
|
|
this.shown = true;
|
|
|
|
this.key = key;
|
|
this.variant = variant;
|
|
});
|
|
}
|
|
|
|
setVariant(variant: string): Promise<void> {
|
|
return new Promise(resolve => {
|
|
globalScene.fieldUI.bringToTop(this);
|
|
|
|
this.transitionSprite.setTexture(this.key, variant);
|
|
this.transitionSprite.setAlpha(0);
|
|
this.transitionSprite.setVisible(true);
|
|
globalScene.tweens.add({
|
|
targets: this.transitionSprite,
|
|
alpha: 1,
|
|
duration: 250,
|
|
ease: "Sine.easeIn",
|
|
onComplete: () => {
|
|
this.sprite.setTexture(this.key, variant);
|
|
this.transitionSprite.setVisible(false);
|
|
resolve();
|
|
},
|
|
});
|
|
this.variant = variant;
|
|
});
|
|
}
|
|
|
|
hide(): Promise<void> {
|
|
return new Promise(resolve => {
|
|
if (!this.shown) {
|
|
return resolve();
|
|
}
|
|
|
|
globalScene.tweens.add({
|
|
targets: this,
|
|
x: globalScene.game.canvas.width / 6 + 32,
|
|
duration: 750,
|
|
ease: "Cubic.easeIn",
|
|
onComplete: () => {
|
|
if (!this.shown) {
|
|
this.setVisible(false);
|
|
}
|
|
resolve();
|
|
},
|
|
});
|
|
|
|
this.shown = false;
|
|
});
|
|
}
|
|
}
|