[Bug] Fix type-hints for immunity (#3620)
* enable mock containers to be found by name * enable mock text to be found by name * add test coverage for type-hints Only for "immunity" and "status moves"
This commit is contained in:
parent
65af7a5699
commit
a97803b99b
|
@ -1210,11 +1210,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
||||||
*
|
*
|
||||||
* @param source - The Pokémon using the move.
|
* @param source - The Pokémon using the move.
|
||||||
* @param move - The move being used.
|
* @param move - The move being used.
|
||||||
* @returns The type damage multiplier or undefined if it's a status move
|
* @returns The type damage multiplier or 1 if it's a status move
|
||||||
*/
|
*/
|
||||||
getMoveEffectiveness(source: Pokemon, move: PokemonMove): TypeDamageMultiplier | undefined {
|
getMoveEffectiveness(source: Pokemon, move: PokemonMove): TypeDamageMultiplier {
|
||||||
if (move.getMove().category === MoveCategory.STATUS) {
|
if (move.getMove().category === MoveCategory.STATUS) {
|
||||||
return undefined;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.getAttackMoveEffectiveness(source, move, !this.battleData?.abilityRevealed);
|
return this.getAttackMoveEffectiveness(source, move, !this.battleData?.abilityRevealed);
|
||||||
|
|
|
@ -87,7 +87,6 @@ describe("UI - Transfer Items", () => {
|
||||||
handler.processInput(Button.ACTION); // select Pokemon
|
handler.processInput(Button.ACTION); // select Pokemon
|
||||||
|
|
||||||
expect(handler.optionsContainer.list.some((option) => (option as BBCodeText).text?.includes("Transfer"))).toBe(true);
|
expect(handler.optionsContainer.list.some((option) => (option as BBCodeText).text?.includes("Transfer"))).toBe(true);
|
||||||
|
|
||||||
game.phaseInterceptor.unlock();
|
game.phaseInterceptor.unlock();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
import { Button } from "#app/enums/buttons.js";
|
||||||
|
import { Moves } from "#app/enums/moves";
|
||||||
|
import { Species } from "#app/enums/species";
|
||||||
|
import { CommandPhase } from "#app/phases";
|
||||||
|
import FightUiHandler from "#app/ui/fight-ui-handler.js";
|
||||||
|
import { Mode } from "#app/ui/ui.js";
|
||||||
|
import GameManager from "#test/utils/gameManager";
|
||||||
|
import Phaser from "phaser";
|
||||||
|
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||||
|
import MockText from "../utils/mocks/mocksContainer/mockText";
|
||||||
|
import { SPLASH_ONLY } from "../utils/testUtils";
|
||||||
|
|
||||||
|
describe("UI - Type Hints", () => {
|
||||||
|
let phaserGame: Phaser.Game;
|
||||||
|
let game: GameManager;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
phaserGame = new Phaser.Game({
|
||||||
|
type: Phaser.HEADLESS,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
game.phaseInterceptor.restoreOg();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
game = new GameManager(phaserGame);
|
||||||
|
game.settings.typeHints(true); //activate type hints
|
||||||
|
game.override.battleType("single").startingLevel(100).startingWave(1).enemyMoveset(SPLASH_ONLY);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check immunity color", async () => {
|
||||||
|
game.override
|
||||||
|
.battleType("single")
|
||||||
|
.startingLevel(100)
|
||||||
|
.startingWave(1)
|
||||||
|
.enemySpecies(Species.FLORGES)
|
||||||
|
.enemyMoveset(SPLASH_ONLY)
|
||||||
|
.moveset([Moves.DRAGON_CLAW]);
|
||||||
|
game.settings.typeHints(true); //activate type hints
|
||||||
|
|
||||||
|
await game.startBattle([Species.RAYQUAZA]);
|
||||||
|
|
||||||
|
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
||||||
|
const { ui } = game.scene;
|
||||||
|
const handler = ui.getHandler<FightUiHandler>();
|
||||||
|
handler.processInput(Button.ACTION); // select "Fight"
|
||||||
|
game.phaseInterceptor.unlock();
|
||||||
|
});
|
||||||
|
|
||||||
|
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
|
||||||
|
const { ui } = game.scene;
|
||||||
|
const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME);
|
||||||
|
const dragonClawText = movesContainer
|
||||||
|
.getAll<Phaser.GameObjects.Text>()
|
||||||
|
.find((text) => text.text === "Dragon Claw")! as unknown as MockText;
|
||||||
|
|
||||||
|
expect.soft(dragonClawText.color).toBe("#929292");
|
||||||
|
ui.getHandler().processInput(Button.ACTION);
|
||||||
|
});
|
||||||
|
await game.phaseInterceptor.to(CommandPhase);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check status move color", async () => {
|
||||||
|
game.override.enemySpecies(Species.FLORGES).moveset([Moves.GROWL]);
|
||||||
|
|
||||||
|
await game.startBattle([Species.RAYQUAZA]);
|
||||||
|
|
||||||
|
game.onNextPrompt("CommandPhase", Mode.COMMAND, () => {
|
||||||
|
const { ui } = game.scene;
|
||||||
|
const handler = ui.getHandler<FightUiHandler>();
|
||||||
|
handler.processInput(Button.ACTION); // select "Fight"
|
||||||
|
game.phaseInterceptor.unlock();
|
||||||
|
});
|
||||||
|
|
||||||
|
game.onNextPrompt("CommandPhase", Mode.FIGHT, () => {
|
||||||
|
const { ui } = game.scene;
|
||||||
|
const movesContainer = ui.getByName<Phaser.GameObjects.Container>(FightUiHandler.MOVES_CONTAINER_NAME);
|
||||||
|
const growlText = movesContainer
|
||||||
|
.getAll<Phaser.GameObjects.Text>()
|
||||||
|
.find((text) => text.text === "Growl")! as unknown as MockText;
|
||||||
|
|
||||||
|
expect.soft(growlText.color).toBe(undefined);
|
||||||
|
ui.getHandler().processInput(Button.ACTION);
|
||||||
|
});
|
||||||
|
await game.phaseInterceptor.to(CommandPhase);
|
||||||
|
});
|
||||||
|
});
|
|
@ -30,6 +30,7 @@ import { MoveHelper } from "./helpers/moveHelper";
|
||||||
import { vi } from "vitest";
|
import { vi } from "vitest";
|
||||||
import { ClassicModeHelper } from "./helpers/classicModeHelper";
|
import { ClassicModeHelper } from "./helpers/classicModeHelper";
|
||||||
import { DailyModeHelper } from "./helpers/dailyModeHelper";
|
import { DailyModeHelper } from "./helpers/dailyModeHelper";
|
||||||
|
import { SettingsHelper } from "./helpers/settingsHelper";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to manage the game state and transitions between phases.
|
* Class to manage the game state and transitions between phases.
|
||||||
|
@ -44,6 +45,7 @@ export default class GameManager {
|
||||||
public readonly move: MoveHelper;
|
public readonly move: MoveHelper;
|
||||||
public readonly classicMode: ClassicModeHelper;
|
public readonly classicMode: ClassicModeHelper;
|
||||||
public readonly dailyMode: DailyModeHelper;
|
public readonly dailyMode: DailyModeHelper;
|
||||||
|
public readonly settings: SettingsHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of GameManager.
|
* Creates an instance of GameManager.
|
||||||
|
@ -63,6 +65,7 @@ export default class GameManager {
|
||||||
this.move = new MoveHelper(this);
|
this.move = new MoveHelper(this);
|
||||||
this.classicMode = new ClassicModeHelper(this);
|
this.classicMode = new ClassicModeHelper(this);
|
||||||
this.dailyMode = new DailyModeHelper(this);
|
this.dailyMode = new DailyModeHelper(this);
|
||||||
|
this.settings = new SettingsHelper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { GameManagerHelper } from "./gameManagerHelper";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to handle settings for tests
|
||||||
|
*/
|
||||||
|
export class SettingsHelper extends GameManagerHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable/Enable type hints settings
|
||||||
|
* @param enable true to enabled, false to disabled
|
||||||
|
*/
|
||||||
|
typeHints(enable: boolean) {
|
||||||
|
this.game.scene.typeHints = enable;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
import MockTextureManager from "#test/utils/mocks/mockTextureManager";
|
import MockTextureManager from "#test/utils/mocks/mockTextureManager";
|
||||||
|
import { vi } from "vitest";
|
||||||
import { MockGameObject } from "../mockGameObject";
|
import { MockGameObject } from "../mockGameObject";
|
||||||
|
|
||||||
export default class MockContainer implements MockGameObject {
|
export default class MockContainer implements MockGameObject {
|
||||||
|
@ -13,6 +14,7 @@ export default class MockContainer implements MockGameObject {
|
||||||
public frame;
|
public frame;
|
||||||
protected textureManager;
|
protected textureManager;
|
||||||
public list: MockGameObject[] = [];
|
public list: MockGameObject[] = [];
|
||||||
|
private name?: string;
|
||||||
|
|
||||||
constructor(textureManager: MockTextureManager, x, y) {
|
constructor(textureManager: MockTextureManager, x, y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
|
@ -159,9 +161,10 @@ export default class MockContainer implements MockGameObject {
|
||||||
// Moves this Game Object to be below the given Game Object in the display list.
|
// Moves this Game Object to be below the given Game Object in the display list.
|
||||||
}
|
}
|
||||||
|
|
||||||
setName(name) {
|
setName = vi.fn((name: string) => {
|
||||||
|
this.name = name;
|
||||||
// return this.phaserSprite.setName(name);
|
// return this.phaserSprite.setName(name);
|
||||||
}
|
});
|
||||||
|
|
||||||
bringToTop(obj) {
|
bringToTop(obj) {
|
||||||
// Brings this Game Object to the top of its parents display list.
|
// Brings this Game Object to the top of its parents display list.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import UI from "#app/ui/ui";
|
import UI from "#app/ui/ui";
|
||||||
|
import { vi } from "vitest";
|
||||||
import { MockGameObject } from "../mockGameObject";
|
import { MockGameObject } from "../mockGameObject";
|
||||||
|
|
||||||
export default class MockText implements MockGameObject {
|
export default class MockText implements MockGameObject {
|
||||||
|
@ -10,6 +11,8 @@ export default class MockText implements MockGameObject {
|
||||||
public list: MockGameObject[] = [];
|
public list: MockGameObject[] = [];
|
||||||
public style;
|
public style;
|
||||||
public text = "";
|
public text = "";
|
||||||
|
private name?: string;
|
||||||
|
public color?: string;
|
||||||
|
|
||||||
constructor(textureManager, x, y, content, styleOptions) {
|
constructor(textureManager, x, y, content, styleOptions) {
|
||||||
this.scene = textureManager.scene;
|
this.scene = textureManager.scene;
|
||||||
|
@ -190,10 +193,9 @@ export default class MockText implements MockGameObject {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
setColor(color) {
|
setColor = vi.fn((color: string) => {
|
||||||
// Sets the tint of this Game Object.
|
this.color = color;
|
||||||
// return this.phaserText.setColor(color);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
setShadowColor(color) {
|
setShadowColor(color) {
|
||||||
// Sets the shadow color.
|
// Sets the shadow color.
|
||||||
|
@ -219,9 +221,9 @@ export default class MockText implements MockGameObject {
|
||||||
// return this.phaserText.setAlpha(alpha);
|
// return this.phaserText.setAlpha(alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
setName(name) {
|
setName = vi.fn((name: string) => {
|
||||||
// return this.phaserText.setName(name);
|
this.name = name;
|
||||||
}
|
});
|
||||||
|
|
||||||
setAlign(align) {
|
setAlign(align) {
|
||||||
// return this.phaserText.setAlign(align);
|
// return this.phaserText.setAlign(align);
|
||||||
|
|
|
@ -12,6 +12,8 @@ import {Button} from "#enums/buttons";
|
||||||
import Pokemon, { PokemonMove } from "#app/field/pokemon.js";
|
import Pokemon, { PokemonMove } from "#app/field/pokemon.js";
|
||||||
|
|
||||||
export default class FightUiHandler extends UiHandler {
|
export default class FightUiHandler extends UiHandler {
|
||||||
|
public static readonly MOVES_CONTAINER_NAME = "moves";
|
||||||
|
|
||||||
private movesContainer: Phaser.GameObjects.Container;
|
private movesContainer: Phaser.GameObjects.Container;
|
||||||
private moveInfoContainer: Phaser.GameObjects.Container;
|
private moveInfoContainer: Phaser.GameObjects.Container;
|
||||||
private typeIcon: Phaser.GameObjects.Sprite;
|
private typeIcon: Phaser.GameObjects.Sprite;
|
||||||
|
@ -35,7 +37,7 @@ export default class FightUiHandler extends UiHandler {
|
||||||
const ui = this.getUi();
|
const ui = this.getUi();
|
||||||
|
|
||||||
this.movesContainer = this.scene.add.container(18, -38.7);
|
this.movesContainer = this.scene.add.container(18, -38.7);
|
||||||
this.movesContainer.setName("moves");
|
this.movesContainer.setName(FightUiHandler.MOVES_CONTAINER_NAME);
|
||||||
ui.add(this.movesContainer);
|
ui.add(this.movesContainer);
|
||||||
|
|
||||||
this.moveInfoContainer = this.scene.add.container(1, 0);
|
this.moveInfoContainer = this.scene.add.container(1, 0);
|
||||||
|
@ -271,11 +273,10 @@ export default class FightUiHandler extends UiHandler {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const moveColors = opponents.map((opponent) => {
|
const moveColors = opponents
|
||||||
return opponent.getMoveEffectiveness(pokemon, pokemonMove);
|
.map((opponent) => opponent.getMoveEffectiveness(pokemon, pokemonMove))
|
||||||
}).filter((eff) => !!eff).sort((a, b) => b - a).map((effectiveness) => {
|
.sort((a, b) => b - a)
|
||||||
return getTypeDamageMultiplierColor(effectiveness, "offense");
|
.map((effectiveness) => getTypeDamageMultiplierColor(effectiveness ?? 0, "offense"));
|
||||||
});
|
|
||||||
|
|
||||||
return moveColors[0];
|
return moveColors[0];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue