Stop ShowAbilityPhase from ending until the bar has popped out

This commit is contained in:
Dean 2025-01-31 23:25:02 -08:00
parent db37dcc204
commit 2ab325c900
2 changed files with 37 additions and 49 deletions

View File

@ -17,13 +17,15 @@ export class ShowAbilityPhase extends PokemonPhase {
const pokemon = this.getPokemon(); const pokemon = this.getPokemon();
if (pokemon) { if (pokemon) {
globalScene.abilityBar.showAbility(pokemon, this.passive); globalScene.abilityBar.showAbility(pokemon, this.passive).then(() => {
if (pokemon?.battleData) {
pokemon.battleData.abilityRevealed = true;
}
if (pokemon?.battleData) { this.end();
pokemon.battleData.abilityRevealed = true; });
} } else {
this.end();
} }
this.end();
} }
} }

View File

@ -12,9 +12,6 @@ export default class AbilityBar extends Phaser.GameObjects.Container {
private bg: Phaser.GameObjects.Image; private bg: Phaser.GameObjects.Image;
private abilityBarText: Phaser.GameObjects.Text; private abilityBarText: Phaser.GameObjects.Text;
private tween: Phaser.Tweens.Tween | null;
private autoHideTimer: NodeJS.Timeout | null;
public shown: boolean; public shown: boolean;
constructor() { constructor() {
@ -36,66 +33,55 @@ export default class AbilityBar extends Phaser.GameObjects.Container {
this.shown = false; this.shown = false;
} }
showAbility(pokemon: Pokemon, passive: boolean = false): void { override setVisible(shown: boolean): this {
this.abilityBarText.setText(`${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: getPokemonNameWithAffix(pokemon), passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: !passive ? pokemon.getAbility().name : pokemon.getPassiveAbility().name })}`); this.shown = shown;
super.setVisible(shown);
return this;
}
if (this.shown) { startTween(config: any, text?: string): Promise<void> {
return; this.setVisible(true);
this.shown = true;
if (text) {
this.abilityBarText.setText(text);
} }
return new Promise((resolve) => {
globalScene.tweens.add({
...config,
onComplete: () => {
if (config.onComplete) {
config.onComplete();
}
resolve();
}
});
});
}
showAbility(pokemon: Pokemon, passive: boolean = false): Promise<void> {
const text = (`${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: getPokemonNameWithAffix(pokemon), passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: !passive ? pokemon.getAbility().name : pokemon.getPassiveAbility().name })}`);
globalScene.fieldUI.bringToTop(this); globalScene.fieldUI.bringToTop(this);
this.y = baseY + (globalScene.currentBattle.double ? 14 : 0); this.y = baseY + (globalScene.currentBattle.double ? 14 : 0);
this.tween = globalScene.tweens.add({ return this.startTween({
targets: this, targets: this,
x: shownX, x: shownX,
duration: 500, duration: 500,
ease: "Sine.easeOut", ease: "Sine.easeOut",
onComplete: () => { hold: 1000,
this.tween = null; }, text);
this.resetAutoHideTimer();
}
});
this.setVisible(true);
this.shown = true;
} }
hide(): void { hide(): void {
if (!this.shown) { this.startTween({
return;
}
if (this.autoHideTimer) {
clearInterval(this.autoHideTimer);
}
if (this.tween) {
this.tween.stop();
}
this.tween = globalScene.tweens.add({
targets: this, targets: this,
x: -91, x: -91,
duration: 500, duration: 500,
ease: "Sine.easeIn", ease: "Sine.easeIn",
onComplete: () => { onComplete: () => {
this.tween = null;
this.setVisible(false); this.setVisible(false);
} }
}); });
this.shown = false;
}
resetAutoHideTimer(): void {
if (this.autoHideTimer) {
clearInterval(this.autoHideTimer);
}
this.autoHideTimer = setTimeout(() => {
this.hide();
this.autoHideTimer = null;
}, 2500);
} }
} }