Make statOrder specific to subclass

This commit is contained in:
Sirz Benjie 2025-04-23 09:46:53 -05:00
parent 1f14325ac7
commit d69fc04188
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E
3 changed files with 29 additions and 21 deletions

View File

@ -13,7 +13,7 @@ import type BattleFlyout from "../battle-flyout";
import i18next from "i18next";
import { ExpGainsSpeed } from "#app/enums/exp-gains-speed";
export default class BattleInfo extends Phaser.GameObjects.Container {
export default abstract class BattleInfo extends Phaser.GameObjects.Container {
public static readonly EXP_GAINS_DURATION_BASE = 1650;
protected baseY: number;
@ -71,18 +71,9 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
public flyoutMenu?: BattleFlyout;
protected statOrder: Stat[];
protected readonly statOrderPlayer = [Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.ACC, Stat.EVA, Stat.SPD];
protected readonly statOrderEnemy = [
Stat.HP,
Stat.ATK,
Stat.DEF,
Stat.SPATK,
Stat.SPDEF,
Stat.ACC,
Stat.EVA,
Stat.SPD,
];
get statOrder(): Stat[] {
return [];
}
constructor(x: number, y: number, player: boolean) {
super(globalScene, x, y);
@ -201,9 +192,8 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
const startingX = this.player ? -this.statsBox.width + 8 : -this.statsBox.width + 5;
const paddingX = this.player ? 4 : 2;
const statOverflow = this.player ? 1 : 0;
this.statOrder = this.player ? this.statOrderPlayer : this.statOrderEnemy; // this tells us whether or not to use the player or enemy battle stat order
this.statOrder.map((s, i) => {
for (const [i, s] of this.statOrder.entries()) {
// we do a check for i > statOverflow to see when the stat labels go onto the next column
// For enemies, we have HP (i=0) by itself then a new column, so we check for i > 0
// For players, we don't have HP, so we start with i = 0 and i = 1 for our first column, and so need to check for i > 1
@ -241,7 +231,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
statLabel.setVisible(false);
statNumber.setVisible(false);
}
});
}
this.type1Icon = globalScene.add.sprite(
player ? -139 : -15,

View File

@ -3,8 +3,25 @@ import { globalScene } from "#app/global-scene";
import BattleFlyout from "../battle-flyout";
import { addTextObject, TextStyle } from "#app/ui/text";
import { addWindow, WindowVariant } from "#app/ui/ui-theme";
import { Stat } from "#enums/stat";
export class EnemyBattleInfo extends BattleInfo {
protected player: false = false;
protected championRibbon: Phaser.GameObjects.Sprite;
protected ownedIcon: Phaser.GameObjects.Sprite;
public flyoutMenu: BattleFlyout;
// #region Type effectiveness hint objects
protected effectivenessContainer: Phaser.GameObjects.Container;
protected effectivenessWindow: Phaser.GameObjects.NineSlice;
protected effectivenessText: Phaser.GameObjects.Text;
protected currentEffectiveness?: string;
// #endregion
override get statOrder(): Stat[] {
return [Stat.HP, Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.ACC, Stat.EVA, Stat.SPD];
}
constructor() {
super(140, -141, false);

View File

@ -1,17 +1,18 @@
import { globalScene } from "#app/global-scene";
import { Stat } from "#enums/stat";
import BattleInfo from "./battle-info";
export class PlayerBattleInfo extends BattleInfo {
override get statOrder(): Stat[] {
return [Stat.ATK, Stat.DEF, Stat.SPATK, Stat.SPDEF, Stat.ACC, Stat.EVA, Stat.SPD];
}
constructor() {
super(Math.floor(globalScene.game.canvas.width / 6) - 10, -72, true);
this.hpNumbersContainer = globalScene.add.container(-15, 10);
this.hpNumbersContainer.setName("container_hp");
this.hpNumbersContainer = globalScene.add.container(-15, 10).setName("container_hp");
this.add(this.hpNumbersContainer);
const expBar = globalScene.add.image(-98, 18, "overlay_exp");
expBar.setName("overlay_exp");
expBar.setOrigin(0);
const expBar = globalScene.add.image(-98, 18, "overlay_exp").setName("overlay_exp").setOrigin(0);
this.add(expBar);
const expMaskRect = globalScene.make