mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-10-23 05:25:58 +02:00
* Replace various `scene` pass-arounds with global scene variable * Modify tests * Add scene back to `fade[in|out]()` calls Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com> * Fix Bug Superfan ME test Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com> * Re-enable fixed test Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com> * Rename `gScene` to `globalScene` * Move `globalScene` to its own file to fix import/async issues * Fix `SelectModifierPhase` tests * Fix ME tests by removing `scene` from `expect()`s * Resolve merge issues * Remove tsdocs referencing `scene` params Remove missed instances of `.scene` * Remove unnecessary `globalScene` usage in `loading-scene.ts` * Fix merge conflicts * Attempt to fix circular import issue * Found the source of the import issue * Fix merge issues --------- Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>
105 lines
2.8 KiB
TypeScript
105 lines
2.8 KiB
TypeScript
import { globalScene } from "#app/global-scene";
|
|
import type Pokemon from "../field/pokemon";
|
|
import { TextStyle, addTextObject } from "./text";
|
|
|
|
export default class PartyExpBar extends Phaser.GameObjects.Container {
|
|
private bg: Phaser.GameObjects.NineSlice;
|
|
private pokemonIcon: Phaser.GameObjects.Container;
|
|
private expText: Phaser.GameObjects.Text;
|
|
|
|
private tween: Phaser.Tweens.Tween | null;
|
|
|
|
public shown: boolean;
|
|
|
|
constructor() {
|
|
super(globalScene, (globalScene.game.canvas.width / 6), -((globalScene.game.canvas.height) / 6) + 15);
|
|
}
|
|
|
|
setup(): void {
|
|
this.bg = globalScene.add.nineslice(0, 0, "party_exp_bar", undefined, 8, 18, 21, 5, 6, 4);
|
|
this.bg.setOrigin(0, 0);
|
|
|
|
this.add(this.bg);
|
|
|
|
this.expText = addTextObject(22, 4, "", TextStyle.BATTLE_INFO);
|
|
this.expText.setOrigin(0, 0);
|
|
this.add(this.expText);
|
|
|
|
this.setVisible(false);
|
|
this.shown = false;
|
|
}
|
|
|
|
showPokemonExp(pokemon: Pokemon, expValue: integer, showOnlyLevelUp: boolean, newLevel: number): Promise<void> {
|
|
return new Promise<void>(resolve => {
|
|
if (this.shown) {
|
|
return resolve();
|
|
}
|
|
|
|
this.pokemonIcon = globalScene.addPokemonIcon(pokemon, -8, 15, 0, 0.5);
|
|
this.pokemonIcon.setScale(0.5);
|
|
|
|
this.add(this.pokemonIcon);
|
|
|
|
// if we want to only display the level in the small frame
|
|
if (showOnlyLevelUp) {
|
|
if (newLevel > 200) { // if the level is greater than 200, we only display Lv. UP
|
|
this.expText.setText("Lv. UP");
|
|
} else { // otherwise we display Lv. Up and the new level
|
|
this.expText.setText(`Lv. UP: ${newLevel.toString()}`);
|
|
}
|
|
} else {
|
|
// if we want to display the exp
|
|
this.expText.setText(`+${expValue.toString()}`);
|
|
}
|
|
|
|
this.bg.width = this.expText.displayWidth + 28;
|
|
|
|
globalScene.fieldUI.bringToTop(this);
|
|
|
|
if (this.tween) {
|
|
this.tween.stop();
|
|
}
|
|
|
|
this.tween = globalScene.tweens.add({
|
|
targets: this,
|
|
x: (globalScene.game.canvas.width / 6) - (this.bg.width - 5),
|
|
duration: 500 / Math.pow(2, globalScene.expGainsSpeed),
|
|
ease: "Sine.easeOut",
|
|
onComplete: () => {
|
|
this.tween = null;
|
|
resolve();
|
|
}
|
|
});
|
|
|
|
this.setVisible(true);
|
|
this.shown = true;
|
|
});
|
|
}
|
|
|
|
hide(): Promise<void> {
|
|
return new Promise<void>(resolve => {
|
|
if (!this.shown) {
|
|
return resolve();
|
|
}
|
|
|
|
if (this.tween) {
|
|
this.tween.stop();
|
|
}
|
|
|
|
this.tween = globalScene.tweens.add({
|
|
targets: this,
|
|
x: (globalScene.game.canvas.width / 6),
|
|
duration: 500,
|
|
ease: "Sine.easeIn",
|
|
onComplete: () => {
|
|
this.tween = null;
|
|
this.shown = false;
|
|
this.setVisible(false);
|
|
this.pokemonIcon?.destroy();
|
|
resolve();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|